From 59588451b65b33595e6b0730590bdb2ff5c9d224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 31 Jul 2024 14:09:21 +0200 Subject: [PATCH] lsts template --- ts/client/scripts/sb-on-demand-create-feed.ts | 161 +++++++----------- 1 file changed, 65 insertions(+), 96 deletions(-) diff --git a/ts/client/scripts/sb-on-demand-create-feed.ts b/ts/client/scripts/sb-on-demand-create-feed.ts index 601c7438c..8d8749667 100644 --- a/ts/client/scripts/sb-on-demand-create-feed.ts +++ b/ts/client/scripts/sb-on-demand-create-feed.ts @@ -230,100 +230,77 @@ const getLstStakePool = async ( } }; -const LSTExactIn = ( - inMint: string, - nativeInAmount: string, - stakePoolAddress: string, -): string => { +const LSTExactIn = (inMint: string, uiAmountIn: string): string => { const template = `tasks: - - conditionalTask: - attempt: - - httpTask: - url: https://api.sanctum.so/v1/swap/quote?input=${inMint}&outputLstMint=So11111111111111111111111111111111111111112&amount=${nativeInAmount}&mode=ExactIn - - jsonParseTask: - path: $.outAmount - - divideTask: - scalar: ${nativeInAmount} - onFailure: - - splStakePoolTask: - pubkey: ${stakePoolAddress} - - cacheTask: - cacheItems: - - variableName: poolTokenSupply - job: - tasks: - - jsonParseTask: - path: $.uiPoolTokenSupply - aggregationMethod: NONE - - variableName: totalStakeLamports - job: - tasks: - - jsonParseTask: - path: $.uiTotalLamports - aggregationMethod: NONE - - valueTask: - big: \${totalStakeLamports} - - divideTask: - big: \${poolTokenSupply} +- conditionalTask: + attempt: + - sanctumLstPriceTask: + lstMint: ${inMint} + - conditionalTask: + attempt: + - valueTask: + big: ${uiAmountIn} + - divideTask: + job: + tasks: + - jupiterSwapTask: + inTokenAddress: So11111111111111111111111111111111111111112 + outTokenAddress: ${inMint} + baseAmountString: ${uiAmountIn} + - conditionalTask: + attempt: - multiplyTask: - job: - tasks: - - oracleTask: - pythAddress: H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG - pythAllowedConfidenceInterval: 10`; + job: + tasks: + - oracleTask: + pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d + pythAllowedConfidenceInterval: 10 + onFailure: + - multiplyTask: + job: + tasks: + - oracleTask: + switchboardAddress: AEcJSgRBkU9WnKCBELj66TPFfzhKWBWa4tL7JugnonUa`; return template; }; -const LSTExactOut = ( - inMint: string, - nativeOutSolAmount: string, - stakePoolAddress: string, -): string => { +const LSTExactOut = (inMint: string, uiOutSolAmount: string): string => { const template = `tasks: - - conditionalTask: - attempt: - - cacheTask: - cacheItems: - - variableName: QTY - job: - tasks: - - httpTask: - url: https://api.sanctum.so/v1/swap/quote?input=${inMint}&outputLstMint=So11111111111111111111111111111111111111112&amount=${nativeOutSolAmount}&mode=ExactOut - - jsonParseTask: - path: $.inAmount - - httpTask: - url: https://api.sanctum.so/v1/swap/quote?input=${inMint}&outputLstMint=So11111111111111111111111111111111111111112&amount=\${QTY}&mode=ExactIn - - jsonParseTask: - path: $.outAmount - - divideTask: - big: \${QTY} - onFailure: - - splStakePoolTask: - pubkey: ${stakePoolAddress} - - cacheTask: - cacheItems: - - variableName: poolTokenSupply - job: - tasks: - - jsonParseTask: - path: $.uiPoolTokenSupply - aggregationMethod: NONE - - variableName: totalStakeLamports - job: - tasks: - - jsonParseTask: - path: $.uiTotalLamports - aggregationMethod: NONE - - valueTask: - big: \${totalStakeLamports} - - divideTask: - big: \${poolTokenSupply} - - multiplyTask: +- conditionalTask: + attempt: + - sanctumLstPriceTask: + lstMint: ${inMint} + - conditionalTask: + attempt: + - cacheTask: + cacheItems: + - variableName: QTY + job: + tasks: + - jupiterSwapTask: + inTokenAddress: So11111111111111111111111111111111111111112 + outTokenAddress: ${inMint} + baseAmountString: ${uiOutSolAmount} + - jupiterSwapTask: + inTokenAddress: ${inMint} + outTokenAddress: So11111111111111111111111111111111111111112 + baseAmountString: \${QTY} + - divideTask: + big: \${QTY} + - conditionalTask: + attempt: + - multiplyTask: job: tasks: - - oracleTask: - pythAddress: H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG - pythAllowedConfidenceInterval: 10`; + - oracleTask: + pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d + pythAllowedConfidenceInterval: 10 + onFailure: + - multiplyTask: + job: + tasks: + - oracleTask: + switchboardAddress: AEcJSgRBkU9WnKCBELj66TPFfzhKWBWa4tL7JugnonUa`; return template; }; @@ -459,11 +436,7 @@ async function setupSwitchboard(userProvider: AnchorProvider) { ? OracleJob.fromYaml( LSTExactIn( TOKEN_MINT, - toNative( - Math.ceil(Number(swapValue) / price), - tokeninfo!.decimals, - ).toString(), - lstPool, + Math.ceil(Number(swapValue) / price).toString(), ), ) : OracleJob.fromObject({ @@ -536,11 +509,7 @@ async function setupSwitchboard(userProvider: AnchorProvider) { ? OracleJob.fromYaml( LSTExactOut( TOKEN_MINT, - toNative( - Math.ceil(Number(swapValue) / price), - tokeninfo!.decimals, - ).toString(), - lstPool, + Math.ceil(Number(swapValue) / price).toString(), ), ) : OracleJob.fromObject({