diff --git a/lib/contracts/handlers/puf-locker-handler.test.ts b/lib/contracts/handlers/puf-locker-handler.test.ts
index 62be451..2cd4f32 100644
--- a/lib/contracts/handlers/puf-locker-handler.test.ts
+++ b/lib/contracts/handlers/puf-locker-handler.test.ts
@@ -59,6 +59,23 @@ describe('PufTokenHandler', () => {
expect(maxLock).toBe(lockPeriods[1]);
});
+ it('should deposit the given pre-approved token into the locker', async () => {
+ contractTestingUtils.mockTransaction('deposit');
+ jest
+ .spyOn((handler as any).erc20PermitHandler, 'getPermitSignature')
+ .mockReturnValue(Promise.resolve(mockPermitSignature));
+
+ const { transact, estimate } = await handler.depositPreApproved(
+ Token.pufWETH,
+ mockAccount,
+ 1n,
+ 10n,
+ );
+
+ expect(typeof (await estimate())).toBe('bigint');
+ expect(isHash(await transact())).toBe(true);
+ });
+
it('should deposit the given token into the locker', async () => {
contractTestingUtils.mockTransaction('deposit');
jest
diff --git a/lib/contracts/handlers/puf-locker-handler.ts b/lib/contracts/handlers/puf-locker-handler.ts
index 60845bb..3821429 100644
--- a/lib/contracts/handlers/puf-locker-handler.ts
+++ b/lib/contracts/handlers/puf-locker-handler.ts
@@ -1,4 +1,4 @@
-import { WalletClient, PublicClient, getContract, Address } from 'viem';
+import { WalletClient, PublicClient, getContract, Address, padHex } from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { PUF_LOCKER_ABIS } from '../abis/puf-locker-abis';
import { CHAIN_ADDRESSES } from '../addresses';
@@ -101,13 +101,68 @@ export class PufLockerHandler {
}
/**
- * Deposit the given PufToken into the locker.
+ * Deposit the given pre-approved PufToken into the locker. A token
+ * can be pre-approved using `Token.approve()`, This doesn't make the
+ * transaction but returns two methods namely `transact` and
+ * `estimate`.
*
* @param pufToken PufToken to deposit.
* @param walletAddress Wallet address of the depositor.
* @param value Amount of the deposit.
* @param lockPeriod The period for the deposit in seconds.
- * @returns The transaction hash of the deposit.
+ * @returns `transact: () => Promise
` - Used to make the
+ * transaction.
+ *
+ * `estimate: () => Promise` - Gas estimate of the
+ * transaction.
+ */
+ public async depositPreApproved(
+ pufToken: PufToken,
+ walletAddress: Address,
+ value: bigint,
+ lockPeriod: bigint,
+ ) {
+ const depositArgs = [
+ TOKENS_ADDRESSES[pufToken][this.chain],
+ lockPeriod,
+ // Only `amount` is needed if `Token.approve()` is already called.
+ // So using mock values for other properties.
+ {
+ r: padHex('0x', { size: 32 }),
+ s: padHex('0x', { size: 32 }),
+ v: 0,
+ deadline: 0n,
+ amount: value,
+ },
+ ];
+
+ const transact = () =>
+ this.getContract().write.deposit(depositArgs, {
+ account: walletAddress,
+ chain: this.viemChain,
+ });
+ const estimate = () =>
+ this.getContract().estimateGas.deposit(depositArgs, {
+ account: walletAddress,
+ });
+
+ return { transact, estimate };
+ }
+
+ /**
+ * Deposit the given PufToken into the locker. This doesn't make the
+ * transaction but returns two methods namely `transact` and
+ * `estimate`.
+ *
+ * @param pufToken PufToken to deposit.
+ * @param walletAddress Wallet address of the depositor.
+ * @param value Amount of the deposit.
+ * @param lockPeriod The period for the deposit in seconds.
+ * @returns `transact: () => Promise` - Used to make the
+ * transaction.
+ *
+ * `estimate: () => Promise` - Gas estimate of the
+ * transaction.
*/
public async deposit(
pufToken: PufToken,
diff --git a/lib/contracts/handlers/puffer-l2-depositor-handler.test.ts b/lib/contracts/handlers/puffer-l2-depositor-handler.test.ts
index 3e25848..73506e6 100644
--- a/lib/contracts/handlers/puffer-l2-depositor-handler.test.ts
+++ b/lib/contracts/handlers/puffer-l2-depositor-handler.test.ts
@@ -30,7 +30,7 @@ describe('PufferL2DepositorHandler', () => {
it('should deposit pre-approved token', async () => {
contractTestingUtils.mockTransaction('deposit');
- const { transact, estimate } = handler.depositAfterApproval(
+ const { transact, estimate } = handler.depositPreApproved(
Token.stETH,
mockAccount,
10n,
diff --git a/lib/contracts/handlers/puffer-l2-depositor-handler.ts b/lib/contracts/handlers/puffer-l2-depositor-handler.ts
index 2db5c1f..d4ba6e4 100644
--- a/lib/contracts/handlers/puffer-l2-depositor-handler.ts
+++ b/lib/contracts/handlers/puffer-l2-depositor-handler.ts
@@ -55,8 +55,8 @@ export class PufferL2DepositorHandler {
/**
* Deposit the given token which is pre-approved using
- * `token.approve()` in exchange for pufETH. This doesn't make the
- * transaction but returns two methods namely `transact` and
+ * `Token.approve()` in exchange for wrapped PufToken. This doesn't
+ * make the transaction but returns two methods namely `transact` and
* `estimate`.
*
* @param token Token to deposit.
@@ -68,7 +68,7 @@ export class PufferL2DepositorHandler {
* `estimate: () => Promise` - Gas estimate of the
* transaction.
*/
- public depositAfterApproval(
+ public depositPreApproved(
token: NonPufToken,
walletAddress: Address,
value: bigint,
@@ -76,7 +76,7 @@ export class PufferL2DepositorHandler {
const depositArgs = [
TOKENS_ADDRESSES[token][this.chain],
walletAddress,
- // Only `amount` is needed if `token.approve()` is already called.
+ // Only `amount` is needed if `Token.approve()` is already called.
// So using mock values for other properties.
{
r: padHex('0x', { size: 32 }),
@@ -102,13 +102,13 @@ export class PufferL2DepositorHandler {
}
/**
- * Deposit the given token in exchange for pufETH. This doesn't make
- * the transaction but returns two methods namely `transact` and
- * `estimate`.
+ * Deposit the given token in exchange for the wrapped PufToken. This
+ * doesn't make the transaction but returns two methods namely
+ * `transact` and `estimate`.
*
* Note that not all token contracts support permit signatures (e.g.
* USDC). If a token's contract doesn't support permit signatures, use
- * `Token.approve()` and call `depositAfterApproval()` instead.
+ * `Token.approve()` and call `this.depositPreApproved()` instead.
*
* @param token Token to deposit.
* @param walletAddress Wallet address to take the token from.