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

1907: Handle tokens and puf tokens separately #25

Merged
merged 2 commits into from
Jul 12, 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
2 changes: 1 addition & 1 deletion lib/contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Chain } from '../chains/constants';

// Source of truth:
// https://github.com/PufferFinance/Deployments-and-ACL/tree/main/docs/deployments
export const CHAIN_ADDRESSES = {
export const CONTRACT_ADDRESSES = {
[Chain.Mainnet]: {
PufferVault: '0xD9A442856C234a39a81a089C06451EBAa4306a72',
PufferDepositor: '0x4aa799c5dfc01ee7d790e3bf1a7c2257ce1dceff',
Expand Down
15 changes: 10 additions & 5 deletions lib/contracts/handlers/erc20-permit-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import {
} from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { ERC20PERMIT_ABI } from '../abis/tokens-abis';
import { TOKENS_ADDRESSES, TOKENS_PERMIT_VERSION, Token } from '../tokens';
import {
AnyToken,
TOKENS_ADDRESSES,
TOKENS_PERMIT_VERSION,
Token,
} from '../tokens';
import { getTimestampInSeconds } from '../../utils/time';

/**
* Handler for performing operations for and with ERC20Permit tokens.
*/
export class ERC20PermitHandler {
private viemChain: ViemChain;
private token: Token;
private token: AnyToken;

/**
* Create the handler for processing tokens.
Expand All @@ -41,7 +46,7 @@ export class ERC20PermitHandler {
* @param token Token to use for the handler.
* @returns The handler.
*/
public withToken(token: Token) {
public withToken(token: AnyToken) {
this.token = token;
return this;
}
Expand All @@ -67,7 +72,7 @@ export class ERC20PermitHandler {
* Process and get permit signature for the given token to perform
* transactions through the `PufferDepositor` contract.
*
* @param ownerAddress Address of the token awner.
* @param ownerAddress Address of the token owner.
* @param spenderAddress Address of the spender who needs the permit.
* @param value Value of the transaction.
* @returns Permit signature in the form `{ r, s, v?, yParity }`.
Expand Down Expand Up @@ -116,7 +121,7 @@ export class ERC20PermitHandler {
return { ...parseSignature(signature), deadline };
}

private getPermitVersion(token: Token): string {
private getPermitVersion(token: AnyToken): string {
return TOKENS_PERMIT_VERSION[token];
}

Expand Down
12 changes: 6 additions & 6 deletions lib/contracts/handlers/puf-locker-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { mockAccount, testingUtils } from '../../../test/setup-tests';
import { Chain } from '../../chains/constants';
import { PUF_LOCKER_ABIS } from '../abis/puf-locker-abis';
import { Token } from '../tokens';
import { PufToken } from '../tokens';
import { PufLockerHandler } from './puf-locker-handler';

describe('PufTokenHandler', () => {
Expand All @@ -28,7 +28,7 @@ describe('PufTokenHandler', () => {
contractTestingUtils.mockCall('getAllDeposits', [[mockDeposit]]);

const allDeposits = await handler.getAllDeposits(
Token.pufWETH,
PufToken.pufWETH,
mockAccount,
);

Expand All @@ -40,7 +40,7 @@ describe('PufTokenHandler', () => {
contractTestingUtils.mockCall('getDeposits', [[mockDeposit]]);

const allDeposits = await handler.getDeposits(
Token.pufWETH,
PufToken.pufWETH,
mockAccount,
0n,
1n,
Expand All @@ -66,7 +66,7 @@ describe('PufTokenHandler', () => {
.mockReturnValue(Promise.resolve(mockPermitSignature));

const { transact, estimate } = await handler.depositPreApproved(
Token.pufWETH,
PufToken.pufWETH,
mockAccount,
1n,
10n,
Expand All @@ -83,7 +83,7 @@ describe('PufTokenHandler', () => {
.mockReturnValue(Promise.resolve(mockPermitSignature));

const { transact, estimate } = await handler.deposit(
Token.pufWETH,
PufToken.pufWETH,
mockAccount,
1n,
10n,
Expand All @@ -97,7 +97,7 @@ describe('PufTokenHandler', () => {
contractTestingUtils.mockTransaction('withdraw');

const { transact, estimate } = handler.withdraw(
Token.pufWETH,
PufToken.pufWETH,
mockAccount,
mockAccount,
[0n],
Expand Down
6 changes: 3 additions & 3 deletions lib/contracts/handlers/puf-locker-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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';
import { CONTRACT_ADDRESSES } from '../addresses';
import { PufToken, TOKENS_ADDRESSES } from '../tokens';
import { ERC20PermitHandler } from './erc20-permit-handler';

Expand Down Expand Up @@ -44,7 +44,7 @@ export class PufLockerHandler {
*/
public getContract() {
return getContract({
address: CHAIN_ADDRESSES[this.chain].PufLocker as Address,
address: CONTRACT_ADDRESSES[this.chain].PufLocker as Address,
abi: PUF_LOCKER_ABIS[this.chain].PufLocker,
client: {
wallet: this.walletClient,
Expand Down Expand Up @@ -174,7 +174,7 @@ export class PufLockerHandler {
.withToken(pufToken)
.getPermitSignature(
walletAddress,
CHAIN_ADDRESSES[this.chain].PufLocker as Address,
CONTRACT_ADDRESSES[this.chain].PufLocker as Address,
value,
);
/* istanbul ignore next */
Expand Down
6 changes: 3 additions & 3 deletions lib/contracts/handlers/puf-token-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mockAccount, testingUtils } from '../../../test/setup-tests';
import { Chain } from '../../chains/constants';
import { PUF_TOKEN_ABIS } from '../abis/puf-token-abis';
import { PufTokenHandler } from './puf-token-handler';
import { TOKENS_ADDRESSES, Token } from '../tokens';
import { PufToken, TOKENS_ADDRESSES } from '../tokens';

describe('PufTokenHandler', () => {
const contractTestingUtils = testingUtils.generateContractUtils(
Expand Down Expand Up @@ -102,10 +102,10 @@ describe('PufTokenHandler', () => {
});

it('should use the contract of the selected token', () => {
const contract = handler.withPufToken(Token.pufALT).getContract();
const contract = handler.withPufToken(PufToken.pufALT).getContract();

expect(contract.address).toBe(
TOKENS_ADDRESSES[Token.pufALT][Chain.Holesky],
TOKENS_ADDRESSES[PufToken.pufALT][Chain.Holesky],
);
});
});
4 changes: 2 additions & 2 deletions lib/contracts/handlers/puf-token-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WalletClient, PublicClient, getContract, Address } from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { PUF_TOKEN_ABIS } from '../abis/puf-token-abis';
import { PufToken, Token, TOKENS_ADDRESSES } from '../tokens';
import { PufToken, TOKENS_ADDRESSES } from '../tokens';

/**
* Handler for the `PufToken` contract exposing methods to interact with
Expand All @@ -27,7 +27,7 @@ export class PufTokenHandler {
private walletClient: WalletClient,
private publicClient: PublicClient,
) {
this.pufToken = Token.pufWETH;
this.pufToken = PufToken.pufWETH;
this.viemChain = VIEM_CHAINS[chain];
}

Expand Down
8 changes: 4 additions & 4 deletions lib/contracts/handlers/puffer-depositor-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, PublicClient, WalletClient, getContract } from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { PUFFER_DEPOSITOR_ABIS } from '../abis/puffer-depositor-abis';
import { CHAIN_ADDRESSES } from '../addresses';
import { CONTRACT_ADDRESSES } from '../addresses';
import { ERC20PermitHandler } from './erc20-permit-handler';
import { Token } from '../tokens';

Expand Down Expand Up @@ -44,7 +44,7 @@ export class PufferDepositorHandler {
*/
public getContract() {
return getContract({
address: CHAIN_ADDRESSES[this.chain].PufferDepositor as Address,
address: CONTRACT_ADDRESSES[this.chain].PufferDepositor as Address,
abi: PUFFER_DEPOSITOR_ABIS[this.chain].PufferDepositor,
client: {
wallet: this.walletClient,
Expand All @@ -71,7 +71,7 @@ export class PufferDepositorHandler {
.withToken(Token.stETH)
.getPermitSignature(
walletAddress,
CHAIN_ADDRESSES[this.chain].PufferDepositor as Address,
CONTRACT_ADDRESSES[this.chain].PufferDepositor as Address,
value,
);
/* istanbul ignore next */
Expand Down Expand Up @@ -115,7 +115,7 @@ export class PufferDepositorHandler {
.withToken(Token.wstETH)
.getPermitSignature(
walletAddress,
CHAIN_ADDRESSES[this.chain].PufferDepositor as Address,
CONTRACT_ADDRESSES[this.chain].PufferDepositor as Address,
value,
);
/* istanbul ignore next */
Expand Down
12 changes: 6 additions & 6 deletions lib/contracts/handlers/puffer-l2-depositor-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WalletClient, PublicClient, getContract, Address, padHex } from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { PUFFER_L2_DEPOSITOR_ABIS } from '../abis/puffer-depositor-abis';
import { CHAIN_ADDRESSES } from '../addresses';
import { NonPufToken, TOKENS_ADDRESSES } from '../tokens';
import { CONTRACT_ADDRESSES } from '../addresses';
import { TOKENS_ADDRESSES, Token } from '../tokens';
import { ERC20PermitHandler } from './erc20-permit-handler';

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ export class PufferL2DepositorHandler {
*/
public getContract() {
return getContract({
address: CHAIN_ADDRESSES[this.chain].PufferL2Depositor as Address,
address: CONTRACT_ADDRESSES[this.chain].PufferL2Depositor as Address,
abi: PUFFER_L2_DEPOSITOR_ABIS[this.chain].PufferL2Depositor,
client: {
wallet: this.walletClient,
Expand All @@ -69,7 +69,7 @@ export class PufferL2DepositorHandler {
* transaction.
*/
public depositPreApproved(
token: NonPufToken,
token: Token,
walletAddress: Address,
value: bigint,
) {
Expand Down Expand Up @@ -121,7 +121,7 @@ export class PufferL2DepositorHandler {
* transaction.
*/
public async deposit(
token: NonPufToken,
token: Token,
walletAddress: Address,
value: bigint,
referralCode: bigint = 0n,
Expand All @@ -130,7 +130,7 @@ export class PufferL2DepositorHandler {
.withToken(token)
.getPermitSignature(
walletAddress,
CHAIN_ADDRESSES[this.chain].PufferL2Depositor as Address,
CONTRACT_ADDRESSES[this.chain].PufferL2Depositor as Address,
value,
);
/* istanbul ignore next */
Expand Down
4 changes: 2 additions & 2 deletions lib/contracts/handlers/puffer-vault-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient, WalletClient, getContract } from 'viem';
import { Chain, VIEM_CHAINS, ViemChain } from '../../chains/constants';
import { CHAIN_ADDRESSES } from '../addresses';
import { CONTRACT_ADDRESSES } from '../addresses';
import { PUFFER_VAULT_ABIS } from '../abis/puffer-vault-abis';

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ export class PufferVaultHandler {
*/
public getContract() {
return getContract({
address: CHAIN_ADDRESSES[this.chain].PufferVault as Address,
address: CONTRACT_ADDRESSES[this.chain].PufferVault as Address,
abi: PUFFER_VAULT_ABIS[this.chain].PufferVaultV2,
client: {
wallet: this.walletClient,
Expand Down
Loading
Loading