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 e778c6d
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 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 @@ -109,9 +109,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 +146,73 @@ describe("Harvest", () => {
);
};

const testHarvestPositionInstructionsWithoutSwaps = async (
poolName: string,
positionName: string,
) => {
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)!;

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 tokenABefore = await fetchToken(rpc, ataAAddress);
const tokenBBefore = await fetchToken(rpc, ataBAddress);

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

const tokenAAfter = await fetchToken(rpc, ataAAddress);
const tokenBAfter = await fetchToken(rpc, ataBAddress);

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 e778c6d

Please sign in to comment.