diff --git a/packages/contract-helpers/src/commons/types.ts b/packages/contract-helpers/src/commons/types.ts index 2af09d2d..e50ca481 100644 --- a/packages/contract-helpers/src/commons/types.ts +++ b/packages/contract-helpers/src/commons/types.ts @@ -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', diff --git a/packages/contract-helpers/src/v3-pool-contract/index.ts b/packages/contract-helpers/src/v3-pool-contract/index.ts index 3673ed9e..3675c7d3 100644 --- a/packages/contract-helpers/src/v3-pool-contract/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract/index.ts @@ -486,7 +486,6 @@ export class Pool extends BaseService implements PoolInterface { onBehalfOf, amount, referralCode, - signature, useOptimizedPath, deadline, }: LPSupplyWithPermitType, @@ -496,8 +495,6 @@ export class Pool extends BaseService 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, @@ -508,6 +505,12 @@ export class Pool extends BaseService 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( { @@ -516,17 +519,15 @@ export class Pool extends BaseService implements PoolInterface { amount: convertedAmount, referralCode, deadline, - permitV: sig.v, - permitR: sig.r, - permitS: sig.s, }, txs, ); } const txCallback: () => Promise = this.generateTxCallback({ - rawTxMethod: async () => - poolContract.populateTransaction.supplyWithPermit( + rawTxMethod: async (signature?: SignatureLike) => { + const sig: Signature = splitSignature(signature); + return poolContract.populateTransaction.supplyWithPermit( reserve, convertedAmount, onBehalfOf ?? user, @@ -535,7 +536,8 @@ export class Pool extends BaseService implements PoolInterface { sig.v, sig.r, sig.s, - ), + ); + }, from: user, }); diff --git a/packages/contract-helpers/src/v3-pool-rollups/index.ts b/packages/contract-helpers/src/v3-pool-rollups/index.ts index aa362b13..2502c6b9 100644 --- a/packages/contract-helpers/src/v3-pool-rollups/index.ts +++ b/packages/contract-helpers/src/v3-pool-rollups/index.ts @@ -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, @@ -126,41 +127,34 @@ export class L2Pool extends BaseService 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 { 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 = 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, });