Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for close position, decrease liquidity, and harvest position #653

Conversation

pauldragonfly
Copy link
Contributor

  • Add tests for close position
  • Add tests for decrease liquidity
  • Add tests for harvest position

@pauldragonfly pauldragonfly force-pushed the paul/DX_100-101_add_harvest_tests_and_close_position_decrease_liquidity_tests branch from 5df0e68 to bdd067f Compare January 14, 2025 14:26
@pauldragonfly pauldragonfly force-pushed the paul/DX_100-101_add_harvest_tests_and_close_position_decrease_liquidity_tests branch from bdd067f to 6010ba3 Compare January 14, 2025 16:39
const tokenAAfter = await fetchToken(rpc, ataAAddress);
const tokenBAfter = await fetchToken(rpc, ataBAddress);

assert.strictEqual(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything to harvest in this case? Since the pool has no swaps the feesOwed would just be 0 I think.

One swap A->B and a swap B->A for each pool after the position is set up should do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added testHarvestPositionInstructionsWithoutSwaps().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I believe now there are only swaps from A->B which would only generate fees for token A. I think if you do the following 4 swaps you'll cover all cases:

{ inputAmount: 100n, mint: mintAAddress },
{ outputAmount: 100n, mint: mintAAddress },
{ inputAmount: 100n, mint: mintBAddress },
{ outputAmount: 100n, mint: mintBAddress },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified testHarvestPositionInstructions() to test after the above 4 swaps

Copy link
Member

@wjthieme wjthieme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Two small remarks

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 () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: without fees

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

assert.strictEqual(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I believe now there are only swaps from A->B which would only generate fees for token A. I think if you do the following 4 swaps you'll cover all cases:

{ inputAmount: 100n, mint: mintAAddress },
{ outputAmount: 100n, mint: mintAAddress },
{ inputAmount: 100n, mint: mintBAddress },
{ outputAmount: 100n, mint: mintBAddress },

@pauldragonfly pauldragonfly force-pushed the paul/DX_100-101_add_harvest_tests_and_close_position_decrease_liquidity_tests branch from e778c6d to 7ff8403 Compare January 16, 2025 21:17
@pauldragonfly pauldragonfly force-pushed the paul/DX_100-101_add_harvest_tests_and_close_position_decrease_liquidity_tests branch from 7ff8403 to 41655b6 Compare January 16, 2025 21:20
Copy link
Member

@wjthieme wjthieme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@pauldragonfly pauldragonfly merged commit 06d3c68 into main Jan 19, 2025
5 checks passed
@pauldragonfly pauldragonfly deleted the paul/DX_100-101_add_harvest_tests_and_close_position_decrease_liquidity_tests branch January 19, 2025 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants