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

feat: permit prototype #458

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/contract-helpers/src/commons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type LendingPoolConfig = Record<

export enum eEthereumTxType {
ERC20_APPROVAL = 'ERC20_APPROVAL',
ERC20_PERMIT = 'ERC20_PERMIT',
DLP_ACTION = 'DLP_ACTION',
GOVERNANCE_ACTION = 'GOVERNANCE_ACTION',
GOV_DELEGATION_ACTION = 'GOV_DELEGATION_ACTION',
Expand Down
20 changes: 11 additions & 9 deletions packages/contract-helpers/src/v3-pool-contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ export class Pool extends BaseService<IPool> implements PoolInterface {
onBehalfOf,
amount,
referralCode,
signature,
useOptimizedPath,
deadline,
}: LPSupplyWithPermitType,
Expand All @@ -496,8 +495,6 @@ export class Pool extends BaseService<IPool> implements PoolInterface {
const poolContract: IPool = this.getContractInstance(this.poolAddress);
const stakedTokenDecimals: number = await decimalsOf(reserve);
const convertedAmount: string = valueToWei(amount, stakedTokenDecimals);
// const sig: Signature = utils.splitSignature(signature);
const sig: Signature = splitSignature(signature);
const fundsAvailable: boolean =
await this.synthetixService.synthetixValidation({
user,
Expand All @@ -508,6 +505,12 @@ export class Pool extends BaseService<IPool> implements PoolInterface {
throw new Error('Not enough funds to execute operation');
}

txs.push({
tx: this.signERC20Approval({ user, reserve, amount, deadline }),
txType: eEthereumTxType.ERC20_PERMIT,
gas: async () => ({ gasLimit: '0', gasPrice: '0' }),
});

if (useOptimizedPath) {
return this.l2PoolService.supplyWithPermit(
{
Expand All @@ -516,17 +519,15 @@ export class Pool extends BaseService<IPool> implements PoolInterface {
amount: convertedAmount,
referralCode,
deadline,
permitV: sig.v,
permitR: sig.r,
permitS: sig.s,
},
txs,
);
}

const txCallback: () => Promise<transactionType> = this.generateTxCallback({
rawTxMethod: async () =>
poolContract.populateTransaction.supplyWithPermit(
rawTxMethod: async (signature?: SignatureLike) => {
const sig: Signature = splitSignature(signature);
return poolContract.populateTransaction.supplyWithPermit(
reserve,
convertedAmount,
onBehalfOf ?? user,
Expand All @@ -535,7 +536,8 @@ export class Pool extends BaseService<IPool> implements PoolInterface {
sig.v,
sig.r,
sig.s,
),
);
},
from: user,
});

Expand Down
46 changes: 20 additions & 26 deletions packages/contract-helpers/src/v3-pool-rollups/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { providers } from 'ethers';
import { providers, Signature } from 'ethers';
import { splitSignature } from 'ethers/lib/utils';
import BaseService from '../commons/BaseService';
import {
eEthereumTxType,
Expand Down Expand Up @@ -126,41 +127,34 @@ export class L2Pool extends BaseService<IL2Pool> implements L2PoolInterface {
@L2PValidator
public async supplyWithPermit(
@isDeadline32Bytes('deadline')
{
user,
reserve,
amount,
deadline,
referralCode,
permitR,
permitS,
permitV,
}: LPSupplyWithPermitType,
{ user, reserve, amount, deadline, referralCode }: LPSupplyWithPermitType,
txs: EthereumTransactionTypeExtended[],
): Promise<EthereumTransactionTypeExtended[]> {
const encoder = this.getEncoder();

const encodedParams: string[] = await encoder.encodeSupplyWithPermitParams(
reserve,
amount,
referralCode ?? 0,
deadline,
permitV,
permitR,
permitS,
);

const l2PoolContract: IL2Pool = this.getContractInstance(
this.l2PoolAddress,
);

const txCallback: () => Promise<transactionType> = this.generateTxCallback({
rawTxMethod: async () =>
l2PoolContract.populateTransaction.supplyWithPermit(
rawTxMethod: async (signature?: SignatureLike) => {
const sig: Signature = splitSignature(signature);
const encodedParams: string[] =
await encoder.encodeSupplyWithPermitParams(
reserve,
amount,
referralCode ?? 0,
deadline,
sig.v,
sig.r,
sig.s,
);
return l2PoolContract.populateTransaction.supplyWithPermit(
encodedParams[0],
permitR,
permitS,
),
sig.r,
sig.s,
);
},
from: user,
});

Expand Down