diff --git a/ts-sdk/whirlpool/src/createPool.ts b/ts-sdk/whirlpool/src/createPool.ts index 18a49048..cf7368e5 100644 --- a/ts-sdk/whirlpool/src/createPool.ts +++ b/ts-sdk/whirlpool/src/createPool.ts @@ -11,7 +11,6 @@ import { import type { Address, GetAccountInfoApi, - GetMinimumBalanceForRentExemptionApi, GetMultipleAccountsApi, IInstruction, Lamports, @@ -19,7 +18,6 @@ import type { TransactionSigner, } from "@solana/web3.js"; import { generateKeyPairSigner, lamports } from "@solana/web3.js"; -import { fetchSysvarRent } from "@solana/sysvars" import { DEFAULT_ADDRESS, FUNDER, @@ -252,10 +250,12 @@ export async function createConcentratedLiquidityPoolInstructions( stateSpaces.map(async (space) => { const rentExemption = await calculateMinimumBalance(rpc, space); return rentExemption; - }) + }), + ); + + const nonRefundableRent = lamports( + nonRefundableRents.reduce((a, b) => a + b, 0n), ); - - const nonRefundableRent = lamports(nonRefundableRents.reduce((a, b) => a + b, 0n)); return { instructions, diff --git a/ts-sdk/whirlpool/src/sysvar.ts b/ts-sdk/whirlpool/src/sysvar.ts index 73312933..c551ee3e 100644 --- a/ts-sdk/whirlpool/src/sysvar.ts +++ b/ts-sdk/whirlpool/src/sysvar.ts @@ -1,6 +1,6 @@ -import { fetchSysvarRent } from "@solana/sysvars" -import { GetAccountInfoApi, lamports, Rpc } from "@solana/web3.js"; -import type { Lamports } from "@solana/web3.js"; +import { fetchSysvarRent } from "@solana/sysvars"; +import { lamports } from "@solana/web3.js"; +import type { Lamports, GetAccountInfoApi, Rpc } from "@solana/web3.js"; /** * The overhead storage size for accounts. @@ -14,11 +14,15 @@ const ACCOUNT_STORAGE_OVERHEAD = 128; * @param {number} dataSize - The size of the account data in bytes. * @returns {Promise} The minimum balance required for rent exemption in lamports. */ -export async function calculateMinimumBalance(rpc: Rpc, dataSize: number): Promise { +export async function calculateMinimumBalance( + rpc: Rpc, + dataSize: number, +): Promise { const rent = await fetchSysvarRent(rpc); const actualDataLen = BigInt(dataSize + ACCOUNT_STORAGE_OVERHEAD); const rentLamportsPerYear = rent.lamportsPerByteYear * actualDataLen; - const minimumBalance = rentLamportsPerYear * BigInt(Math.floor(rent.exemptionThreshold)); - - return lamports(minimumBalance) -} \ No newline at end of file + const minimumBalance = + rentLamportsPerYear * BigInt(Math.floor(rent.exemptionThreshold)); + + return lamports(minimumBalance); +} diff --git a/ts-sdk/whirlpool/src/token.ts b/ts-sdk/whirlpool/src/token.ts index 4e06a577..3aeae0e6 100644 --- a/ts-sdk/whirlpool/src/token.ts +++ b/ts-sdk/whirlpool/src/token.ts @@ -33,7 +33,7 @@ import { getTransferSolInstruction, } from "@solana-program/system"; import { getTokenSize } from "@solana-program/token"; -import { TOKEN_2022_PROGRAM_ADDRESS, getTokenSize as getToken22Size } from "@solana-program/token-2022" +import { getTokenSize as getToken22Size } from "@solana-program/token-2022"; import type { ExtensionArgs, Mint } from "@solana-program/token-2022"; import type { TransferFee } from "@orca-so/whirlpools-core"; import assert from "assert"; diff --git a/ts-sdk/whirlpool/tests/createPool.test.ts b/ts-sdk/whirlpool/tests/createPool.test.ts index 33a63e1d..6d98100a 100644 --- a/ts-sdk/whirlpool/tests/createPool.test.ts +++ b/ts-sdk/whirlpool/tests/createPool.test.ts @@ -9,19 +9,14 @@ import { SPLASH_POOL_TICK_SPACING, } from "../src/config"; import { setupMint } from "./utils/token"; -import { setupMintTE, setupMintTEFee } from "./utils/tokenExtensions"; +import { setupMintTEFee } from "./utils/tokenExtensions"; import { orderMints } from "../src/token"; import { rpc, sendTransaction, signer } from "./utils/mockRpc"; -import { - fetchMaybeWhirlpool, -} from "@orca-so/whirlpools-client"; +import { fetchMaybeWhirlpool } from "@orca-so/whirlpools-client"; import assert from "assert"; import type { Address } from "@solana/web3.js"; import { assertAccountExists, lamports } from "@solana/web3.js"; -import { - _TICK_ARRAY_SIZE, - priceToSqrtPrice, -} from "@orca-so/whirlpools-core"; +import { _TICK_ARRAY_SIZE, priceToSqrtPrice } from "@orca-so/whirlpools-core"; describe("Create Pool", () => { let mintA: Address; @@ -54,15 +49,11 @@ describe("Create Pool", () => { let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createSplashPoolInstructions( - rpc, - mintA, - mintB, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createSplashPoolInstructions(rpc, mintA, mintB, price); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); @@ -92,15 +83,11 @@ describe("Create Pool", () => { let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createSplashPoolInstructions( - rpc, - mintC, - mintD, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createSplashPoolInstructions(rpc, mintC, mintD, price); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); @@ -130,15 +117,11 @@ describe("Create Pool", () => { let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createSplashPoolInstructions( - rpc, - mintC, - mintD, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createSplashPoolInstructions(rpc, mintC, mintD, price); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); @@ -159,23 +142,24 @@ describe("Create Pool", () => { }); it("Should create concentrated liquidity pool", async () => { - const tickSpacing = 64 + const tickSpacing = 64; const price = 10; const sqrtPrice = priceToSqrtPrice(price, 6, 6); let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createConcentratedLiquidityPoolInstructions( - rpc, - mintA, - mintB, - tickSpacing, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createConcentratedLiquidityPoolInstructions( + rpc, + mintA, + mintB, + tickSpacing, + price, + ); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); @@ -206,16 +190,17 @@ describe("Create Pool", () => { let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createConcentratedLiquidityPoolInstructions( - rpc, - mintC, - mintD, - tickSpacing, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createConcentratedLiquidityPoolInstructions( + rpc, + mintC, + mintD, + tickSpacing, + price, + ); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); @@ -246,16 +231,17 @@ describe("Create Pool", () => { let signerAccount = await rpc.getAccountInfo(signer.address).send(); const balanceBefore = signerAccount.value?.lamports ?? lamports(0n); - const { instructions, poolAddress, estInitializationCost } = await createConcentratedLiquidityPoolInstructions( - rpc, - mintC, - mintD, - tickSpacing, - price, - ); + const { instructions, poolAddress, estInitializationCost } = + await createConcentratedLiquidityPoolInstructions( + rpc, + mintC, + mintD, + tickSpacing, + price, + ); const maybePool = await fetchMaybeWhirlpool(rpc, poolAddress); - assert.strictEqual(maybePool.exists, false) + assert.strictEqual(maybePool.exists, false); await sendTransaction(instructions); diff --git a/ts-sdk/whirlpool/tests/token.test.ts b/ts-sdk/whirlpool/tests/token.test.ts index af788126..f04684cd 100644 --- a/ts-sdk/whirlpool/tests/token.test.ts +++ b/ts-sdk/whirlpool/tests/token.test.ts @@ -479,21 +479,21 @@ describe("Token Account Creation", () => { }); it("Should get the correct token size for TOKEN_PROGRAM mint", async () => { - const mintAccount = await fetchMint(rpc, mintA) - const tokenSize = getTokenSizeForMint(mintAccount) + const mintAccount = await fetchMint(rpc, mintA); + const tokenSize = getTokenSizeForMint(mintAccount); assert.strictEqual(tokenSize, 165); }); it("Should get the correct token size for TOKEN_2022_PROGRAM mint", async () => { const mint = await setupMintTE(); - const mintAccount = await fetchMint(rpc, mint) - const tokenSize = getTokenSizeForMint(mintAccount) + const mintAccount = await fetchMint(rpc, mint); + const tokenSize = getTokenSizeForMint(mintAccount); assert.strictEqual(tokenSize, 165); }); it("Should get the correct token size for TOKEN_2022_PROGRAM mint with", async () => { - const mintAccount = await fetchMint(rpc, mintTE) - const tokenSize = getTokenSizeForMint(mintAccount) + const mintAccount = await fetchMint(rpc, mintTE); + const tokenSize = getTokenSizeForMint(mintAccount); assert.strictEqual(tokenSize, 178); }); }); diff --git a/ts-sdk/whirlpool/tests/utils/mockRpc.ts b/ts-sdk/whirlpool/tests/utils/mockRpc.ts index d8e53719..2ac02dea 100644 --- a/ts-sdk/whirlpool/tests/utils/mockRpc.ts +++ b/ts-sdk/whirlpool/tests/utils/mockRpc.ts @@ -236,7 +236,7 @@ async function mockTransport( slotsInEpoch: 32n, transactionCount: 0n, }); - } + } return Promise.reject( `Method ${config.payload.method} not supported in mock transport`, );