Skip to content

Commit

Permalink
exampls upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
avernikoz committed May 9, 2024
1 parent 0e2852f commit 4fef10e
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 48 deletions.
8 changes: 4 additions & 4 deletions examples/admin/init-secondary-market-with-custom-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
});
10 changes: 5 additions & 5 deletions examples/bonding-curve/is-memecoin-ready-to-live-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions examples/bonding-curve/trading/swap-sui-for-ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
17 changes: 12 additions & 5 deletions examples/bonding-curve/trading/swap-ticket-for-sui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 13 additions & 15 deletions examples/live/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,39 @@ 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();
console.debug("pool:", pool);

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);
};

Expand Down
12 changes: 6 additions & 6 deletions examples/staking-pool/collect-fees.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/staking-pool/get-available-fees-to-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
6 changes: 5 additions & 1 deletion examples/staking-pool/unstake-from-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions examples/staking-pool/withdraw-fees-from-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 4fef10e

Please sign in to comment.