Created
May 13, 2024 21:43
-
-
Save sunguru98/6e11344c3788d40d6b8ac1ea5b8379ad to your computer and use it in GitHub Desktop.
NAVI Dev Race Round 6 - Task 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"; | |
import { decodeSuiPrivateKey } from "@mysten/sui.js/cryptography"; | |
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; | |
import { TransactionBlock } from "@mysten/sui.js/transactions"; | |
import { MIST_PER_SUI } from "@mysten/sui.js/utils"; | |
/* NAVI addresses */ | |
const NAVI_PACKAGE_ID = | |
"0xc6374c7da60746002bfee93014aeb607e023b2d6b25c9e55a152b826dbc8c1ce"; | |
const STORAGE_ID = | |
"0xbb4e2f4b6205c2e2a2db47aeb4f830796ec7c005f88537ee775986639bc442fe"; | |
const SUI_POOL_ID = | |
"0x96df0fce3c471489f4debaaa762cf960b3d97820bd1f3f025ff8190730e958c5"; | |
const SUI_ASSET_ID = 0; | |
const INCENTIVE_ID = | |
"0xaaf735bf83ff564e1b219a0d644de894ef5bdc4b2250b126b2a46dd002331821"; | |
const INCENTIVE_V2_ID = | |
"0xf87a8acb8b81d14307894d12595541a73f19933f88e1326d5be349c7a6f7559c"; | |
/**/ | |
/* Token Addresses*/ | |
const SUI_COIN_TYPE = "0x2::sui::SUI"; | |
const VSUI_COIN_TYPE = | |
"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"; | |
/**/ | |
/** KRIYA Addresses */ | |
const KRIYA_PACKAGE_ID = | |
"0xa0eba10b173538c8fecca1dff298e488402cc9ff374f8a12ca7758eebe830b66"; | |
const VSUI_SUI_POOL = | |
"0xf385dee283495bb70500f5f8491047cd5a2ef1b7ff5f410e6dfe8a3c3ba58716"; | |
/**/ | |
(async function () { | |
try { | |
const mainnetRPC = getFullnodeUrl("mainnet"); | |
const client = new SuiClient({ url: mainnetRPC }); | |
const { secretKey } = decodeSuiPrivateKey("privatekey"); | |
const keypair = Ed25519Keypair.fromSecretKey(secretKey); | |
const account = keypair.getPublicKey(); | |
const vSuiObjects = ( | |
await client.getAllCoins({ owner: account.toSuiAddress() }) | |
).data | |
.filter((d) => d.coinType.includes("CERT")) | |
.map((o) => o.coinObjectId); | |
const swapAmount = 10.5 * Number(MIST_PER_SUI); | |
const transactionBlock = new TransactionBlock(); | |
// 1. Merge all vSUI coins together | |
transactionBlock.mergeCoins( | |
transactionBlock.object(vSuiObjects[0]), | |
vSuiObjects.slice(1).map((v) => transactionBlock.object(v)) | |
); | |
// 2. Split the necessary amount of swap | |
const vSuiCoin = transactionBlock.splitCoins( | |
transactionBlock.object(vSuiObjects[0]), | |
[transactionBlock.pure(swapAmount)] | |
); | |
// 3. Swap 10.5 vSUI to SUI | |
const suiCoin = transactionBlock.moveCall({ | |
target: `${KRIYA_PACKAGE_ID}::spot_dex::swap_token_x`, | |
arguments: [ | |
transactionBlock.object(VSUI_SUI_POOL), | |
vSuiCoin, | |
transactionBlock.pure(swapAmount), | |
transactionBlock.pure(0), | |
], | |
typeArguments: [VSUI_COIN_TYPE, SUI_COIN_TYPE], | |
}); | |
// 4. Get suiCoin amount | |
const suiCoinAmount = transactionBlock.moveCall({ | |
target: `0x02::coin::value`, | |
arguments: [suiCoin], | |
typeArguments: [SUI_COIN_TYPE], | |
}); | |
// 5. Deposit, received SUI to NAVI | |
transactionBlock.moveCall({ | |
target: `${NAVI_PACKAGE_ID}::incentive_v2::entry_deposit`, | |
arguments: [ | |
transactionBlock.object("0x06"), | |
transactionBlock.object(STORAGE_ID), | |
transactionBlock.object(SUI_POOL_ID), | |
transactionBlock.pure(SUI_ASSET_ID), | |
suiCoin, | |
suiCoinAmount, | |
transactionBlock.object(INCENTIVE_ID), | |
transactionBlock.object(INCENTIVE_V2_ID), | |
], | |
typeArguments: [SUI_COIN_TYPE], | |
}); | |
const response = await client.signAndExecuteTransactionBlock({ | |
signer: keypair, | |
transactionBlock, | |
options: { | |
showBalanceChanges: true, | |
showObjectChanges: true, | |
}, | |
}); | |
console.log(response); | |
} catch (err) { | |
console.error(err); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment