Skip to content

Commit

Permalink
Merge pull request #47 from PufferFinance/2684/add-converttoassets-me…
Browse files Browse the repository at this point in the history
…thod

2684 Add convertToAssets method to pufferVaultHandler
  • Loading branch information
guestn authored Oct 8, 2024
2 parents 4064c1c + f92e41f commit ac895ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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]);
}
}

0 comments on commit ac895ed

Please sign in to comment.