Skip to content

Commit

Permalink
lsts template
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Jul 31, 2024
1 parent 697f40e commit 5958845
Showing 1 changed file with 65 additions and 96 deletions.
161 changes: 65 additions & 96 deletions ts/client/scripts/sb-on-demand-create-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10
onFailure:
- multiplyTask:
job:
tasks:
- oracleTask:
pythAddress: H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG
pythAllowedConfidenceInterval: 10`;
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: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10
onFailure:
- multiplyTask:
job:
tasks:
- oracleTask:
pythAddress: H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG
pythAllowedConfidenceInterval: 10`;
- oracleTask:
switchboardAddress: AEcJSgRBkU9WnKCBELj66TPFfzhKWBWa4tL7JugnonUa`;
return template;
};

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 5958845

Please sign in to comment.