From 4fef10e6087c291230b67000a40741fcc722c1b1 Mon Sep 17 00:00:00 2001 From: avernikoz Date: Thu, 9 May 2024 03:01:05 +0300 Subject: [PATCH] exampls upgrade --- ...nit-secondary-market-with-custom-params.ts | 8 +++--- ...-and-create-custom-params-bonding-curve.ts | 6 ++-- .../is-memecoin-ready-to-live-phase.ts | 10 +++---- .../trading/swap-sui-for-ticket.ts | 10 +++---- .../trading/swap-ticket-for-sui.ts | 17 +++++++---- examples/live/swap.ts | 28 +++++++++---------- examples/staking-pool/collect-fees.ts | 12 ++++---- .../get-available-fees-to-withdraw.ts | 2 +- examples/staking-pool/unstake-from-pool.ts | 6 +++- .../staking-pool/withdraw-fees-from-pool.ts | 5 ++-- 10 files changed, 56 insertions(+), 48 deletions(-) diff --git a/examples/admin/init-secondary-market-with-custom-params.ts b/examples/admin/init-secondary-market-with-custom-params.ts index 27a49ac..ccca903 100644 --- a/examples/admin/init-secondary-market-with-custom-params.ts +++ b/examples/admin/init-secondary-market-with-custom-params.ts @@ -12,11 +12,11 @@ export const initSecondaryMarketExample = async ({ transaction }: { transaction? // get all pools const { pools, poolsByMemeCoinTypeMap } = await bondingCurveInstance.getAllPools(); + const memecoinCointype = + "0x232bcf980b826ab7bba1629c807b756e7fc507d0e84f009bfdd31caffa175365::meme_08_05_2024_06::MEME_08_05_2024_06"; + // get random pool - const pool = - poolsByMemeCoinTypeMap[ - "0xd7436c4c051caf789cc80901a22a97bb59c44fbd0f7f55e2470ac3dec375e8b0::meme_06_05_2024_02::MEME_06_05_2024_02" - ]; + const pool = poolsByMemeCoinTypeMap[memecoinCointype]; if (!pool) { throw new Error("Pool doesn't exists"); diff --git a/examples/bonding-curve/create/create-coins-and-create-custom-params-bonding-curve.ts b/examples/bonding-curve/create/create-coins-and-create-custom-params-bonding-curve.ts index 2d87688..2051f33 100644 --- a/examples/bonding-curve/create/create-coins-and-create-custom-params-bonding-curve.ts +++ b/examples/bonding-curve/create/create-coins-and-create-custom-params-bonding-curve.ts @@ -67,9 +67,9 @@ export const createCustomBondingCurveAndCoins = async (params: CreateCoinTransac }; createCustomBondingCurveAndCoins({ - description: "07 May 2024 first", - name: "meme0705202401", + description: "08 May 2024 six", + name: "meme0805202406", signerAddress: user, - symbol: "MEME_07_05_2024_01", + symbol: "MEME_08_05_2024_06", url: "", }); diff --git a/examples/bonding-curve/is-memecoin-ready-to-live-phase.ts b/examples/bonding-curve/is-memecoin-ready-to-live-phase.ts index 281dd4b..484954a 100644 --- a/examples/bonding-curve/is-memecoin-ready-to-live-phase.ts +++ b/examples/bonding-curve/is-memecoin-ready-to-live-phase.ts @@ -6,11 +6,11 @@ export const isMemecoinReadyToLivePhase = async () => { const bondingCurveInstance = BondingPoolSingleton.getInstance(suiProviderUrl); const { pools, poolsByMemeCoinTypeMap } = await bondingCurveInstance.getAllPools(); - // get random pool - const pool = - poolsByMemeCoinTypeMap[ - "0xd7436c4c051caf789cc80901a22a97bb59c44fbd0f7f55e2470ac3dec375e8b0::meme_06_05_2024_02::MEME_06_05_2024_02" - ]; + + const memecoinCointype = + "0x232bcf980b826ab7bba1629c807b756e7fc507d0e84f009bfdd31caffa175365::meme_08_05_2024_06::MEME_08_05_2024_06"; + + const pool = poolsByMemeCoinTypeMap[memecoinCointype]; if (!pool) { throw new Error("Pool doesn't exists"); diff --git a/examples/bonding-curve/trading/swap-sui-for-ticket.ts b/examples/bonding-curve/trading/swap-sui-for-ticket.ts index 70688f4..2091282 100644 --- a/examples/bonding-curve/trading/swap-sui-for-ticket.ts +++ b/examples/bonding-curve/trading/swap-sui-for-ticket.ts @@ -8,12 +8,12 @@ export const swapSuiForTicketExample = async () => { // get all pools const { pools, poolsByMemeCoinTypeMap } = await bondingCurveInstance.getAllPools(); + const memecoinCointype = + "0x232bcf980b826ab7bba1629c807b756e7fc507d0e84f009bfdd31caffa175365::meme_08_05_2024_06::MEME_08_05_2024_06"; + // get random pool - const pool = - poolsByMemeCoinTypeMap[ - "0xb09db619ab3cd89355c259660ef4c686b416cd6319332ef41be4dcfd5f4bfe4d::meme_07_05_2024_01::MEME_07_05_2024_01" - ]; - const inputAmount = "0.05"; + const pool = poolsByMemeCoinTypeMap[memecoinCointype]; + const inputAmount = "1.2"; // const inputAmount = "30000"; if (!pool) { throw new Error("Pool doesn't exists"); diff --git a/examples/bonding-curve/trading/swap-ticket-for-sui.ts b/examples/bonding-curve/trading/swap-ticket-for-sui.ts index eb3f797..a4b9abd 100644 --- a/examples/bonding-curve/trading/swap-ticket-for-sui.ts +++ b/examples/bonding-curve/trading/swap-ticket-for-sui.ts @@ -8,21 +8,28 @@ export const swapTicketForSuiExample = async () => { // get all pools const { pools, poolsByMemeCoinTypeMap } = await bondingCurveInstance.getAllPools(); + const memecoinCointype = + "0xd57bf62c5f214ca3f68ddf0abbb645f222e21c322156e2f32538707826a52388::meme_08_05_2024_02::MEME_08_05_2024_02"; + // get random pool - const pool = - poolsByMemeCoinTypeMap[ - "0xbbd380a1ac2e03b7b56f429c1abd660a2db16ef019fc6366c1b43dc6b5450979::meme_04_05_2024_01::MEME_04_05_2024_01" - ]; + const pool = poolsByMemeCoinTypeMap[memecoinCointype]; if (!pool) { throw new Error("Pool doesn't exists"); } // const inputTicketAmount = "848476175.625"; - const inputTicketAmount = "1"; + const inputTicketAmount = "257505502.5"; console.debug("pool: ", pool); + const { stakedLpObjectsByMemeCoinTypeMap } = await BondingPoolSingleton.getAllStakedLPObjectsByOwner({ + owner: user, + provider, + }); + const ticketsByMemecoin = stakedLpObjectsByMemeCoinTypeMap[memecoinCointype]; + console.debug("allStakedLpObjects: ", ticketsByMemecoin); + const outputAmount = await bondingCurveInstance.getSwapOutputAmountForTicketInput({ bondingCurvePoolObjectId: pool.objectId, inputTicketAmount, diff --git a/examples/live/swap.ts b/examples/live/swap.ts index 8c35e84..54c45ce 100644 --- a/examples/live/swap.ts +++ b/examples/live/swap.ts @@ -3,17 +3,15 @@ import { keypair, provider, signAndExecuteTransaction, user } from "../common"; // yarn tsx examples/live/swap.ts export const swapLive = async () => { - const memeCoinType = - "0xf8a2ba07ec67b0f4ad7458a6d58af6fa7b00374e21d6ae45e3dbe0cab0f78865::meme_06_05_2024_03::MEME_06_05_2024_03"; - const inputAmount = "0.5"; + const memecoinCointype = + "0x5552f2e8989762bc65cd0b62b97999a8d6865a5a56cbe12890a883a88c527148::meme_08_05_2024_05::MEME_08_05_2024_05"; - const liveInstance = new LiveCLMM({ + // const inputAmount = "0.2"; + const inputAmount = "137101879"; + + const liveInstance = await LiveCLMM.fromGoLiveDefaultTx({ + txDigest: "4v8DoaJze4s2dpNKS9cLyKQafTS4tQNpKVMwg4uneRbf", provider, - data: { - memeCoin: { - coinType: memeCoinType, - }, - }, }); const pool = await liveInstance.getPool(); @@ -21,23 +19,23 @@ export const swapLive = async () => { const quoteResult = await liveInstance.quoteSwap({ inputAmount, - SuiToMeme: true, - memeCoin: { coinType: memeCoinType }, + SuiToMeme: false, + memeCoin: { coinType: memecoinCointype }, slippagePercentage: 0.01, }); console.debug("quoteResult:", quoteResult); const swap = await liveInstance.swap({ inputAmount, - memeCoin: { coinType: memeCoinType }, + memeCoin: { coinType: memecoinCointype }, minOutputAmount: quoteResult, signerAddress: user, slippagePercentage: 0.01, - SuiToMeme: true, + SuiToMeme: false, }); - const res = await provider.devInspectTransactionBlock({ sender: user, transactionBlock: swap }); - // const res = await signAndExecuteTransaction(swap, keypair); + // const res = await provider.devInspectTransactionBlock({ sender: user, transactionBlock: swap }); + const res = await signAndExecuteTransaction(swap, keypair); console.debug("res:", res); }; diff --git a/examples/staking-pool/collect-fees.ts b/examples/staking-pool/collect-fees.ts index ec212d5..8099297 100644 --- a/examples/staking-pool/collect-fees.ts +++ b/examples/staking-pool/collect-fees.ts @@ -1,24 +1,24 @@ -import { TransactionBlock } from "@mysten/sui.js/transactions"; import { LiveCLMM, StakingPool } from "../../src"; import { keypair, provider, signAndExecuteTransaction } from "../common"; // yarn tsx examples/staking-pool/collect-fees.ts export const collectFees = async () => { const stakingPool = await StakingPool.fromGoLiveDefaultTx({ - txDigest: "12aZ8vaZFS4eJULP7hbeEdzRfQuAaEUrPbt75F1oz2tY", + txDigest: "Bp4X158y53Y1aJ4iy6vDJFBpfFq38tZskN3wsFGpNJJg", provider, }); const interestPoolInstance = await LiveCLMM.fromGoLiveDefaultTx({ - txDigest: "12aZ8vaZFS4eJULP7hbeEdzRfQuAaEUrPbt75F1oz2tY", + txDigest: "Bp4X158y53Y1aJ4iy6vDJFBpfFq38tZskN3wsFGpNJJg", provider, }); const interestPool = await interestPoolInstance.getPool(); - const tx = new TransactionBlock(); - - stakingPool.collectFees(tx, { pool: interestPool.poolObjectId, stakingPool: stakingPool.data.address }); + const { tx } = stakingPool.collectFees({ + clmmPool: interestPool.poolObjectId, + stakingPool: stakingPool.data.address, + }); const res = await signAndExecuteTransaction(tx, keypair); console.debug("res:", res); diff --git a/examples/staking-pool/get-available-fees-to-withdraw.ts b/examples/staking-pool/get-available-fees-to-withdraw.ts index ef635be..dc4d28d 100644 --- a/examples/staking-pool/get-available-fees-to-withdraw.ts +++ b/examples/staking-pool/get-available-fees-to-withdraw.ts @@ -4,7 +4,7 @@ import { provider, user } from "../common"; // yarn tsx examples/staking-pool/get-available-fees-to-withdraw.ts export const getAvailableFeesToWithdraw = async () => { const stakingPool = await StakingPool.fromGoLiveDefaultTx({ - txDigest: "12aZ8vaZFS4eJULP7hbeEdzRfQuAaEUrPbt75F1oz2tY", + txDigest: "4v8DoaJze4s2dpNKS9cLyKQafTS4tQNpKVMwg4uneRbf", provider, }); diff --git a/examples/staking-pool/unstake-from-pool.ts b/examples/staking-pool/unstake-from-pool.ts index e90c7e0..6d306b1 100644 --- a/examples/staking-pool/unstake-from-pool.ts +++ b/examples/staking-pool/unstake-from-pool.ts @@ -6,12 +6,14 @@ import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"; // yarn tsx examples/staking-pool/unstake-from-pool.ts export const unstakeFromPool = async () => { const stakingPool = await StakingPool.fromGoLiveDefaultTx({ - txDigest: "12aZ8vaZFS4eJULP7hbeEdzRfQuAaEUrPbt75F1oz2tY", + txDigest: "4v8DoaJze4s2dpNKS9cLyKQafTS4tQNpKVMwg4uneRbf", provider, }); // Input amount that user wants to unstake from the staking pool, ticket coin const { availableMemeAmountToUnstake } = await stakingPool.getAvailableAmountToUnstake({ owner: user }); + console.debug("availableMemeAmountToUnstake: ", availableMemeAmountToUnstake); + const tx = new TransactionBlock(); const unstakeFromStakingPoolTx = await stakingPool.getUnstakeTransaction({ transaction: tx, @@ -33,6 +35,8 @@ export const unstakeFromPool = async () => { // }, // }); + console.debug("tx.serialize: ", JSON.stringify(JSON.parse(tx.serialize()), null, 2)); + const res = await provider.devInspectTransactionBlock({ transactionBlock: tx, sender: user, diff --git a/examples/staking-pool/withdraw-fees-from-pool.ts b/examples/staking-pool/withdraw-fees-from-pool.ts index 403ffa2..cbe325a 100644 --- a/examples/staking-pool/withdraw-fees-from-pool.ts +++ b/examples/staking-pool/withdraw-fees-from-pool.ts @@ -6,12 +6,11 @@ import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"; // yarn tsx examples/staking-pool/withdraw-fees-from-pool.ts export const withdrawFromPool = async () => { const stakingPool = await StakingPool.fromGoLiveDefaultTx({ - txDigest: "9nC4RG4ma6mLf9GciXSn2fHi4SPuKrGsieGyqvAc6EY3", + txDigest: "4v8DoaJze4s2dpNKS9cLyKQafTS4tQNpKVMwg4uneRbf", provider: new SuiClient({ url: getFullnodeUrl("mainnet") }), }); - const tx = new TransactionBlock(); - stakingPool.withdrawFees(tx, user); + const { tx } = stakingPool.withdrawFees({ signerAddress: user }); console.debug("withdrawFromStakingPoolTx: ", JSON.stringify(JSON.parse(tx.serialize()), null, 2));