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

2684 Add convertToAssets method to pufferVaultHandler #47

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/contracts/handlers/puffer-vault-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,15 @@ describe('PufferVaultHandler', () => {
expect(typeof (await estimate())).toBe('bigint');
expect(isHash(await transact())).toBe(true);
});

it('should convert pufETH to WETH', async () => {
const mockPufETH = 10n;
const mockWETH = 20n;

vaultTestingUtils.mockCall('convertToAssets', [mockWETH]);

const wethAmount = await handler.convertToAssets(mockPufETH);

expect(wethAmount).toBe(mockWETH);
});
});
11 changes: 11 additions & 0 deletions lib/contracts/handlers/puffer-vault-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,15 @@ export class PufferVaultHandler {

return { transact, estimate };
}

/**
* Gives exchange rate of pufETH relative to WETH.
* This does not include any fees, as compared to previewRedeem method.
*
* @param amount Amount of pufETH to convert.
* @returns Amount of equivalent WETH.
*/
public convertToAssets(amount: bigint) {
return this.getContract().read.convertToAssets([amount]);
}
}
Loading