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

1802: Update contract addresses, token permit versions and add pre-approved token deposit to PufLocker #23

Merged
merged 3 commits into from
Jul 11, 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
4 changes: 2 additions & 2 deletions lib/contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const CHAIN_ADDRESSES = {
PufferDepositor: '0x824AC05aeb86A0aD770b8acDe0906d2d4a6c4A8c',
// TODO: Update the addresses once the contracts are deployed on chain.
// See https://dev.azure.com/pufferfi/Frontend/_workitems/edit/1797.
PufferL2Depositor: '0x03D8bE7CaAD9A95cef9800249eC663Aa28A2F776',
PufLocker: '0x3fc7a526de9fc3c5e3a28f33d24d4401a6a7b65d',
PufferL2Depositor: '0x300480bf80b1ad93a9f6349623646142776e9156',
PufLocker: '0x367551e0834c26e29e0a17ce3ed4dca87ff0c204',
},
};
9 changes: 2 additions & 7 deletions lib/contracts/handlers/erc20-permit-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { ERC20PERMIT_ABI } from '../abis/tokens-abis';
import { TOKENS_ADDRESSES, Token } from '../tokens';
import { TOKENS_ADDRESSES, TOKENS_PERMIT_VERSION, Token } from '../tokens';
import { getTimestampInSeconds } from '../../utils/time';

/**
Expand Down Expand Up @@ -117,12 +117,7 @@ export class ERC20PermitHandler {
}

private getPermitVersion(token: Token): string {
// stETH and USDC have permit version 2.
if (token === Token.stETH) {
return '2';
}

return '1';
return TOKENS_PERMIT_VERSION[token];
}

/**
Expand Down
17 changes: 17 additions & 0 deletions lib/contracts/handlers/puf-locker-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 58 additions & 3 deletions lib/contracts/handlers/puf-locker-handler.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<Address>` - Used to make the
* transaction.
*
* `estimate: () => Promise<bigint>` - Gas estimate of the
* transaction.
*/
public async depositPreApproved(
pufToken: PufToken,
walletAddress: Address,
value: bigint,
lockPeriod: bigint,
) {
const depositArgs = <const>[
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<Address>` - Used to make the
* transaction.
*
* `estimate: () => Promise<bigint>` - Gas estimate of the
* transaction.
*/
public async deposit(
pufToken: PufToken,
Expand Down
2 changes: 1 addition & 1 deletion lib/contracts/handlers/puffer-l2-depositor-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions lib/contracts/handlers/puffer-l2-depositor-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -68,15 +68,15 @@ export class PufferL2DepositorHandler {
* `estimate: () => Promise<bigint>` - Gas estimate of the
* transaction.
*/
public depositAfterApproval(
public depositPreApproved(
token: NonPufToken,
walletAddress: Address,
value: bigint,
) {
const depositArgs = <const>[
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 }),
Expand All @@ -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.
Expand Down
67 changes: 53 additions & 14 deletions lib/contracts/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { Address } from 'viem';
import { Chain } from '../chains/constants';

export enum Token {
USDT = 'USDT',
USDC = 'USDC',
DAI = 'DAI',
ETH = 'ETH',
WETH = 'wETH',
stETH = 'stETH',
wstETH = 'wstETH',
pufETH = 'pufETH',
// Wrapped PufTokens.

// Wrapped PufTokens
pufUSDT = 'pufUSDT',
pufUSDC = 'pufUSDC',
pufDAI = 'pufDAI',
pufpufETH = 'pufpufETH',
Expand All @@ -22,11 +25,12 @@ export enum Token {

export type NonPufToken = Extract<
Token,
'USDC' | 'DAI' | 'ETH' | 'WETH' | 'stETH' | 'wstETH' | 'pufETH'
'USDT' | 'USDC' | 'DAI' | 'ETH' | 'WETH' | 'stETH' | 'wstETH' | 'pufETH'
>;

export type PufToken = Extract<
Token,
| 'pufUSDT'
| 'pufUSDC'
| 'pufDAI'
| 'pufpufETH'
Expand All @@ -40,19 +44,23 @@ export type PufToken = Extract<
export const TOKENS_ADDRESSES: {
[key in Token]: { [chain in Chain]: Address };
} = {
[Token.USDT]: {
[Chain.Mainnet]: '0xdac17f958d2ee523a2206206994597c13d831ec7',
[Chain.Holesky]: '0xd5bef2c64f418fd460319521d37862327122e3bc',
},
[Token.USDC]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Mainnet]: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
[Chain.Holesky]: '0x64Cc0de0429bcb87e875905a0c313ec88f6d1d3E',
},
[Token.DAI]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Mainnet]: '0x6b175474e89094c44da98b954eedeac495271d0f',
[Chain.Holesky]: '0x4478905505ddfb7eA1c8A9f46eAEC3695cE542ac',
},
[Token.ETH]: {},
// Does not support permit signatures (ERC20Permit).
// WETH does not support permit signatures (ERC20Permit).
[Token.WETH]: {
[Chain.Mainnet]: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
[Chain.Holesky]: '0x94373a4919b3240d86ea41593d5eba789fef3848',
[Chain.Holesky]: '0x35B1167b4D37931540F4e5189004d1756d1381B0',
},
[Token.stETH]: {
[Chain.Mainnet]: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
Expand All @@ -64,26 +72,32 @@ export const TOKENS_ADDRESSES: {
},
[Token.pufETH]: {
[Chain.Mainnet]: '0xd9a442856c234a39a81a089c06451ebaa4306a72',
[Chain.Holesky]: '0x9196830bB4c05504E0A8475A0aD566AceEB6BeC9',
[Chain.Holesky]: '0x9196830bb4c05504e0a8475a0ad566aceeb6bec9',
},

// TODO: Update the addresses once the contracts are deployed on chain.
// See https://dev.azure.com/pufferfi/Frontend/_workitems/edit/1797.

// Wrapped PufTokens.
[Token.pufUSDT]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x61e7C87c387178D6e0aE6c04748b7FF753fC9b81',
},
[Token.pufUSDC]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x6D900a9f5784A2cA0004B5c3D3e08D7A9cE4A1b3',
[Chain.Holesky]: '0xC4731029b6F4fEd5930A56F0FFa3E8Ae688f9dA8',
},
[Token.pufDAI]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x3aDeeC5151FA881e76A3F42256CD78052372b362',
[Chain.Holesky]: '0xcA1C3DBC6Ea41f018B8d91C3AbE6FacDBDd4F63e',
},
[Token.pufpufETH]: {
[Token.pufEETH]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x083b6321F213C993B81a54BF4D6Cb38e175EFE68',
[Chain.Holesky]: '0x0000000000000000000000000000000000000000',
},
[Token.pufWETH]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0xfcF6c4e0387A523b73691D5604e5a6dA1607C8A0',
[Chain.Holesky]: '0x2207119500757bDD269F98d86Dca6356535b876E',
},
[Token.pufStETH]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
Expand All @@ -97,8 +111,33 @@ export const TOKENS_ADDRESSES: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x0000000000000000000000000000000000000000',
},
[Token.pufEETH]: {
[Token.pufpufETH]: {
[Chain.Mainnet]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0x0000000000000000000000000000000000000000',
[Chain.Holesky]: '0xECa244cBBe52A68EB6c4fdC266c2c50D568bcd22',
},
};

export const TOKENS_PERMIT_VERSION = {
[Token.USDT]: '2',
// USDC does not support permit signatures (ERC20Permit).
[Token.USDC]: '2',
[Token.DAI]: '1',
[Token.ETH]: '',
// WETH does not support permit signatures (ERC20Permit).
[Token.WETH]: '',
[Token.stETH]: '2',
// Puffer Quest v1 uses version 1 for wstETH.
[Token.wstETH]: '1',
[Token.pufETH]: '1',

// Wrapped PufTokens
[Token.pufUSDT]: '1',
[Token.pufUSDC]: '1',
[Token.pufDAI]: '1',
[Token.pufEETH]: '1',
[Token.pufWETH]: '1',
[Token.pufStETH]: '1',
[Token.pufWstETH]: '1',
[Token.pufALT]: '1',
[Token.pufpufETH]: '1',
};
Loading