Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
calintje committed Nov 14, 2024
1 parent 51bc3a0 commit e8902bc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 75 deletions.
10 changes: 5 additions & 5 deletions ts-sdk/whirlpool/src/createPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import {
import type {
Address,
GetAccountInfoApi,
GetMinimumBalanceForRentExemptionApi,
GetMultipleAccountsApi,
IInstruction,
Lamports,
Rpc,
TransactionSigner,
} from "@solana/web3.js";
import { generateKeyPairSigner, lamports } from "@solana/web3.js";
import { fetchSysvarRent } from "@solana/sysvars"
import {
DEFAULT_ADDRESS,
FUNDER,
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions ts-sdk/whirlpool/src/sysvar.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,11 +14,15 @@ const ACCOUNT_STORAGE_OVERHEAD = 128;
* @param {number} dataSize - The size of the account data in bytes.
* @returns {Promise<BigInt>} The minimum balance required for rent exemption in lamports.
*/
export async function calculateMinimumBalance(rpc: Rpc<GetAccountInfoApi>, dataSize: number): Promise<Lamports> {
export async function calculateMinimumBalance(
rpc: Rpc<GetAccountInfoApi>,
dataSize: number,
): Promise<Lamports> {
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)
}
const minimumBalance =
rentLamportsPerYear * BigInt(Math.floor(rent.exemptionThreshold));

return lamports(minimumBalance);
}
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
94 changes: 40 additions & 54 deletions ts-sdk/whirlpool/tests/createPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions ts-sdk/whirlpool/tests/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion ts-sdk/whirlpool/tests/utils/mockRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async function mockTransport<T>(
slotsInEpoch: 32n,
transactionCount: 0n,
});
}
}
return Promise.reject(
`Method ${config.payload.method} not supported in mock transport`,
);
Expand Down

0 comments on commit e8902bc

Please sign in to comment.