Skip to content

Commit

Permalink
Add testHarvestPositionInstructionsWithoutSwaps()
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldragonfly committed Jan 16, 2025
1 parent 6010ba3 commit 7ff8403
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions ts-sdk/whirlpool/tests/harvest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const poolTypes = new Map([
const positionTypes = new Map([
["equally centered", { tickLower: -100, tickUpper: 100 }],
["one sided A", { tickLower: -100, tickUpper: -1 }],
["one sided B", { tickLower: 1, tickUpper: 100 }],
// ["one sided B", { tickLower: 1, tickUpper: 100 }], //
]);

describe("Harvest", () => {
Expand Down Expand Up @@ -95,7 +95,6 @@ describe("Harvest", () => {
) => {
const [mintAName, mintBName] = poolName.split("-");
const mintAAddress = mints.get(mintAName)!;
const mintBAddress = mints.get(mintBName)!;
const ataAAddress = atas.get(mintAName)!;
const ataBAddress = atas.get(mintBName)!;

Expand All @@ -109,9 +108,18 @@ describe("Harvest", () => {
);
await sendTransaction(swap_instructions);

// Do another swap to generate more fees
({ instructions: swap_instructions } = await swapInstructions(
rpc,
{ outputAmount: 100n, mint: mintBAddress },
{ inputAmount: 100n, mint: mintAAddress },
poolAddress,
));
await sendTransaction(swap_instructions);

// Do another swap to generate more fees
({ instructions: swap_instructions } = await swapInstructions(
rpc,
{ inputAmount: 100n, mint: mintAAddress },
poolAddress,
));
await sendTransaction(swap_instructions);
Expand All @@ -137,17 +145,64 @@ describe("Harvest", () => {
);
};

const testHarvestPositionInstructionsWithoutSwaps = async (
poolName: string,
positionName: string,
) => {
const [mintAName, _mintBName] = poolName.split("-");
const mintAAddress = mints.get(mintAName)!;

const poolAddress = pools.get(poolName)!;
const positionMintAddress = positions.get(positionName)!;

const { instructions: swap_instructions1 } = await swapInstructions(
rpc,
{ inputAmount: 100n, mint: mintAAddress },
poolAddress,
);

const { instructions: swap_instructions2 } = await swapInstructions(
rpc,
{ outputAmount: 100n, mint: mintAAddress },
poolAddress,
);

await sendTransaction([...swap_instructions1, ...swap_instructions2]);

const { instructions: harvest_instructions, feesQuote } =
await harvestPositionInstructions(rpc, positionMintAddress);
await sendTransaction(harvest_instructions);

assert.strictEqual(feesQuote.feeOwedA, 0n);

assert.strictEqual(feesQuote.feeOwedB, 0n);
};

for (const poolName of poolTypes.keys()) {
for (const positionTypeName of positionTypes.keys()) {
const positionName = `${poolName} ${positionTypeName}`;
it(`Should harvest a position for ${positionName}`, async () => {
await testHarvestPositionInstructions(poolName, positionName);
});

it(`Should harvest a position without swaps for ${positionName}`, async () => {
await testHarvestPositionInstructionsWithoutSwaps(
poolName,
positionName,
);
});

const positionNameTE = `TE ${poolName} ${positionTypeName}`;
it(`Should harvest a position for ${positionNameTE}`, async () => {
await testHarvestPositionInstructions(poolName, positionNameTE);
});

it(`Should harvest a position without swaps for ${positionName}`, async () => {
await testHarvestPositionInstructionsWithoutSwaps(
poolName,
positionName,
);
});
}
}
});

0 comments on commit 7ff8403

Please sign in to comment.