From 8cb3cfbf64d6d3d9322ba943c899fee56b297c27 Mon Sep 17 00:00:00 2001 From: Nick Guest Date: Tue, 8 Oct 2024 16:09:22 +0200 Subject: [PATCH 1/2] Add convertToAssets method to PufferVaultHandler --- lib/contracts/handlers/puffer-vault-handler.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/contracts/handlers/puffer-vault-handler.ts b/lib/contracts/handlers/puffer-vault-handler.ts index 8ace75b..0f8ddd8 100644 --- a/lib/contracts/handlers/puffer-vault-handler.ts +++ b/lib/contracts/handlers/puffer-vault-handler.ts @@ -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]); + } } From f92e41f32827e7a342c6d6b7f9a16eedf7667b11 Mon Sep 17 00:00:00 2001 From: Nick Guest Date: Tue, 8 Oct 2024 16:09:51 +0200 Subject: [PATCH 2/2] Add convertToAssets test to PufferVaultHandler tests --- lib/contracts/handlers/puffer-vault-handler.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/contracts/handlers/puffer-vault-handler.test.ts b/lib/contracts/handlers/puffer-vault-handler.test.ts index 020d24c..99ba95d 100644 --- a/lib/contracts/handlers/puffer-vault-handler.test.ts +++ b/lib/contracts/handlers/puffer-vault-handler.test.ts @@ -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); + }); });