Skip to content

Commit

Permalink
new lst template
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Aug 9, 2024
1 parent dfa1ad7 commit f6ffa56
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 101 deletions.
1 change: 0 additions & 1 deletion components/governance/ListToken/ListToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,6 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
onClose={closeCreateOracleModal}
isSolPool={isSolPool}
stakePoolAddress={lstStakePoolAddress}
tokenDecimals={currentTokenInfo.decimals}
tokenPrice={baseTokenPrice}
></CreateSwitchboardOracleModal>
</li>
Expand Down
23 changes: 4 additions & 19 deletions components/modals/CreateSwitchboardOracleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import {
tierToSwitchboardJobSwapValue,
} from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import { WRAPPED_SOL_MINT } from '@metaplex-foundation/js'
import {
createComputeBudgetIx,
toNative,
} from '@blockworks-foundation/mango-v4'
import { createComputeBudgetIx } from '@blockworks-foundation/mango-v4'
import { LSTExactIn, LSTExactOut } from 'utils/switchboardTemplates/templates'
import {
SequenceType,
Expand Down Expand Up @@ -60,7 +57,6 @@ type BaseProps = ModalProps & {
isSolPool: boolean
stakePoolAddress: string
tokenPrice: number
tokenDecimals: number
onClose: (oraclePk?: PublicKey) => void
}

Expand All @@ -82,7 +78,6 @@ const CreateSwitchboardOracleModal = ({
raydiumPoolAddress,
orcaPoolAddress,
tierKey,
tokenDecimals,
tokenPrice,
isSolPool,
stakePoolAddress,
Expand Down Expand Up @@ -298,7 +293,7 @@ const CreateSwitchboardOracleModal = ({
authority: payer,
crankDataBuffer: crankAccount.dataBuffer?.publicKey,
crankPubkey: crankAccount.publicKey,
fundAmount: settingFromLib.fundAmount,
fundAmount: 0.1,
slidingWindow: true,
disableCrank: false,
maxPriorityFeeMultiplier: 5,
Expand All @@ -313,11 +308,7 @@ const CreateSwitchboardOracleModal = ({
? OracleJob.fromYaml(
LSTExactIn(
baseTokenPk,
toNative(
Math.ceil(Number(swapValue) / tokenPrice),
tokenDecimals,
).toString(),
stakePoolAddress,
Math.ceil(Number(swapValue) / tokenPrice).toString(),
),
)
: OracleJob.fromObject({
Expand Down Expand Up @@ -396,11 +387,7 @@ const CreateSwitchboardOracleModal = ({
? OracleJob.fromYaml(
LSTExactOut(
baseTokenPk,
toNative(
Math.ceil(Number(swapValue) / tokenPrice),
tokenDecimals,
).toString(),
stakePoolAddress,
Math.ceil(Number(swapValue) / tokenPrice).toString(),
),
)
: OracleJob.fromObject({
Expand Down Expand Up @@ -587,8 +574,6 @@ const CreateSwitchboardOracleModal = ({
raydiumPoolAddress,
stakePoolAddress,
tierKey,
tierSwitchboardSettings,
tokenDecimals,
tokenPrice,
wallet,
])
Expand Down
139 changes: 58 additions & 81 deletions utils/switchboardTemplates/templates.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,73 @@
export const LSTExactIn = (
inMint: string,
nativeInAmount: string,
stakePoolAddress: string,
) => {
export 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}
- multiplyTask:
- conditionalTask:
attempt:
- sanctumLstPriceTask:
lstMint: ${inMint}
- conditionalTask:
attempt:
- valueTask:
big: ${uiAmountIn}
- divideTask:
job:
tasks:
- oracleTask:
pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10`
- jupiterSwapTask:
inTokenAddress: So11111111111111111111111111111111111111112
outTokenAddress: ${inMint}
baseAmountString: ${uiAmountIn}
- conditionalTask:
attempt:
- multiplyTask:
job:
tasks:
- oracleTask:
pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10
onFailure:
- multiplyTask:
job:
tasks:
- oracleTask:
switchboardAddress: AEcJSgRBkU9WnKCBELj66TPFfzhKWBWa4tL7JugnonUa`
return template
}

export const LSTExactOut = (
inMint: string,
nativeOutSolAmount: string,
stakePoolAddress: string,
) => {
export const LSTExactOut = (inMint: string, uiOutSolAmount: string): string => {
const template = `tasks:
- conditionalTask:
attempt:
- cacheTask:
cacheItems:
- sanctumLstPriceTask:
lstMint: ${inMint}
- 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}
- jupiterSwapTask:
inTokenAddress: So11111111111111111111111111111111111111112
outTokenAddress: ${inMint}
baseAmountString: ${uiOutSolAmount}
- jupiterSwapTask:
inTokenAddress: ${inMint}
outTokenAddress: So11111111111111111111111111111111111111112
baseAmountString: \${QTY}
- divideTask:
big: \${poolTokenSupply}
- multiplyTask:
job:
tasks:
- oracleTask:
pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10`
big: \${QTY}
- conditionalTask:
attempt:
- multiplyTask:
job:
tasks:
- oracleTask:
pythAddress: ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d
pythAllowedConfidenceInterval: 10
onFailure:
- multiplyTask:
job:
tasks:
- oracleTask:
switchboardAddress: AEcJSgRBkU9WnKCBELj66TPFfzhKWBWa4tL7JugnonUa`
return template
}

0 comments on commit f6ffa56

Please sign in to comment.