@@ -68,7 +68,7 @@ async function addCustody(
6868 let oracleConfig = {
6969 maxPriceError : new BN ( 10000 ) ,
7070 maxPriceAgeSec : 60 ,
71- oracleType : { pyth : { } } ,
71+ oracleType : { custom : { } } ,
7272 oracleAccount : tokenOracle ,
7373 } ;
7474 let pricingConfig = {
@@ -159,6 +159,58 @@ async function upgradeCustody(poolName: string, tokenMint: PublicKey) {
159159 client . upgradeCustody ( poolName , tokenMint ) ;
160160}
161161
162+ async function setCustomOraclePrice (
163+ poolName : string ,
164+ tokenMint : PublicKey ,
165+ price : number ,
166+ exponent : number ,
167+ confidence : number ,
168+ ema : number
169+ ) {
170+ let priceConfig = {
171+ price : new BN ( price ) ,
172+ expo : exponent ,
173+ conf : new BN ( confidence ) ,
174+ ema : new BN ( ema ) ,
175+ publishTime : new BN ( client . getTime ( ) ) ,
176+ } ;
177+ client . setCustomOraclePrice ( poolName , tokenMint , priceConfig ) ;
178+ }
179+
180+ async function addLiquidity (
181+ poolName : string ,
182+ tokenMint : PublicKey ,
183+ amountIn : number ,
184+ minLpAmountOut : number
185+ ) {
186+ client . addLiquidity (
187+ poolName ,
188+ tokenMint ,
189+ new BN ( amountIn ) ,
190+ new BN ( minLpAmountOut )
191+ ) ;
192+ }
193+
194+ async function openPosition (
195+ poolName : string ,
196+ tokenMint : PublicKey ,
197+ collateralMint : PublicKey ,
198+ side : string ,
199+ price : number ,
200+ collateral : number ,
201+ size : number
202+ ) {
203+ client . openPosition (
204+ poolName ,
205+ tokenMint ,
206+ collateralMint ,
207+ side ,
208+ new BN ( price ) ,
209+ new BN ( collateral ) ,
210+ new BN ( size )
211+ ) ;
212+ }
213+
162214async function getUserPosition (
163215 wallet : PublicKey ,
164216 poolName : string ,
@@ -241,6 +293,16 @@ async function getOraclePrice(
241293 client . prettyPrint ( await client . getOraclePrice ( poolName , tokenMint , useEma ) ) ;
242294}
243295
296+ async function getCustomOracleAccount ( poolName : string , tokenMint : PublicKey ) {
297+ client . prettyPrint (
298+ await client . getCustodyCustomOracleAccountKey ( poolName , tokenMint )
299+ ) ;
300+ }
301+
302+ async function getLpTokenMint ( poolName : string ) {
303+ client . prettyPrint ( await client . getPoolLpTokenKey ( poolName ) ) ;
304+ }
305+
244306async function getLiquidationPrice (
245307 wallet : PublicKey ,
246308 poolName : string ,
@@ -461,6 +523,67 @@ async function getAum(poolName: string) {
461523 await upgradeCustody ( poolName , new PublicKey ( tokenMint ) ) ;
462524 } ) ;
463525
526+ program
527+ . command ( "set-oracle-price" )
528+ . description ( "Set custom oracle price" )
529+ . argument ( "<string>" , "Pool name" )
530+ . argument ( "<pubkey>" , "Token mint" )
531+ . requiredOption ( "-p, --price <int>" , "Current price as integer" )
532+ . requiredOption ( "-e, --exponent <int>" , "Price exponent" )
533+ . requiredOption ( "-c, --confidence <int>" , "Confidence" )
534+ . requiredOption ( "-m, --ema <int>" , "EMA price as integer" )
535+ . action ( async ( poolName , tokenMint , options ) => {
536+ await setCustomOraclePrice (
537+ poolName ,
538+ new PublicKey ( tokenMint ) ,
539+ options . price ,
540+ options . exponent ,
541+ options . confidence ,
542+ options . ema
543+ ) ;
544+ } ) ;
545+
546+ program
547+ . command ( "add-liquidity" )
548+ . description ( "Deposit liquidity to the custody" )
549+ . argument ( "<string>" , "Pool name" )
550+ . argument ( "<pubkey>" , "Token mint" )
551+ . requiredOption ( "-i, --amount-in <int>" , "Amount to deposit" )
552+ . requiredOption (
553+ "-o, --min-amount-out <int>" ,
554+ "Minimum LP amount to receive"
555+ )
556+ . action ( async ( poolName , tokenMint , options ) => {
557+ await addLiquidity (
558+ poolName ,
559+ new PublicKey ( tokenMint ) ,
560+ options . amountIn ,
561+ options . minAmountOut
562+ ) ;
563+ } ) ;
564+
565+ program
566+ . command ( "open-position" )
567+ . description ( "Open a new perpetuals position" )
568+ . argument ( "<string>" , "Pool name" )
569+ . argument ( "<pubkey>" , "Token mint" )
570+ . argument ( "<pubkey>" , "Collateral mint" )
571+ . argument ( "<string>" , "Position side (long / short)" )
572+ . requiredOption ( "-p, --price <int>" , "Entry price" )
573+ . requiredOption ( "-c, --collateral <int>" , "Collateral amount" )
574+ . requiredOption ( "-s, --size <int>" , "Position size" )
575+ . action ( async ( poolName , tokenMint , collateralMint , side , options ) => {
576+ await openPosition (
577+ poolName ,
578+ new PublicKey ( tokenMint ) ,
579+ new PublicKey ( collateralMint ) ,
580+ side ,
581+ options . price ,
582+ options . collateral ,
583+ options . size
584+ ) ;
585+ } ) ;
586+
464587 program
465588 . command ( "get-user-position" )
466589 . description ( "Print user position metadata" )
@@ -575,6 +698,23 @@ async function getAum(poolName: string) {
575698 await getOraclePrice ( poolName , new PublicKey ( tokenMint ) , options . ema ) ;
576699 } ) ;
577700
701+ program
702+ . command ( "get-custom-oracle-account" )
703+ . description ( "Get custom oracle account address for the token" )
704+ . argument ( "<string>" , "Pool name" )
705+ . argument ( "<pubkey>" , "Token mint" )
706+ . action ( async ( poolName , tokenMint , options ) => {
707+ await getCustomOracleAccount ( poolName , new PublicKey ( tokenMint ) ) ;
708+ } ) ;
709+
710+ program
711+ . command ( "get-lp-token-mint" )
712+ . description ( "Get LP token mint address for the pool" )
713+ . argument ( "<string>" , "Pool name" )
714+ . action ( async ( poolName , options ) => {
715+ await getLpTokenMint ( poolName ) ;
716+ } ) ;
717+
578718 program
579719 . command ( "get-liquidation-price" )
580720 . description ( "Compute liquidation price for the position" )
0 commit comments