From 89b8eca7faf9e11372b9a6485713bcc805af6d09 Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Tue, 22 Aug 2023 03:29:30 +0100 Subject: [PATCH 01/24] feat: added tests --- .../contract-helpers/src/commons/types.ts | 20 ++- .../contract-helpers/src/commons/utils.ts | 12 +- .../src/lendingPool-contract-bundle/index.ts | 42 +++++ .../lendingPoolBundle.test.ts | 51 +++++++ .../src/v3-pool-contract-bundle/index.ts | 104 +++++++++++++ .../pool-bundle.test.ts | 144 ++++++++++++++++++ .../src/v3-pool-rollups/poolTypes.ts | 2 + .../src/wethgateway-contract/index.ts | 30 ++++ .../wethgateway-contract/wethGateway.test.ts | 40 +++++ 9 files changed, 440 insertions(+), 5 deletions(-) diff --git a/packages/contract-helpers/src/commons/types.ts b/packages/contract-helpers/src/commons/types.ts index b868eaca..298f0d0d 100644 --- a/packages/contract-helpers/src/commons/types.ts +++ b/packages/contract-helpers/src/commons/types.ts @@ -1,5 +1,10 @@ import { BigNumber, BytesLike, PopulatedTransaction } from 'ethers'; -import { LPBorrowParamsType } from '../v3-pool-contract/lendingPoolTypes'; +import { + LPBorrowParamsType, + LPRepayParamsType, + LPRepayWithATokensType, + LPRepayWithPermitParamsType, +} from '../v3-pool-contract/lendingPoolTypes'; export type tEthereumAddress = string; export type ENS = string; // something.eth @@ -109,6 +114,8 @@ export enum ProtocolAction { liquidationCall = 'liquidationCall', liquidationFlash = 'liquidationFlash', repay = 'repay', + repayETH = 'repayETH', + repayWithATokens = 'repayWithATokens', swapCollateral = 'swapCollateral', repayCollateral = 'repayCollateral', withdrawETH = 'withdrawETH', @@ -338,3 +345,14 @@ export type BorrowTxBuilder = { encodedTxData, }: LPBorrowParamsType) => PopulatedTransaction; }; + +export type RepayTxBuilder = { + generateTxData: (params: LPRepayParamsType) => PopulatedTransaction; + generateSignedTxData: ( + params: LPRepayWithPermitParamsType, + ) => PopulatedTransaction; +}; + +export type RepayWithATokensTxBuilder = { + generateTxData: (params: LPRepayWithATokensType) => PopulatedTransaction; +}; diff --git a/packages/contract-helpers/src/commons/utils.ts b/packages/contract-helpers/src/commons/utils.ts index f563c105..bf887eb1 100644 --- a/packages/contract-helpers/src/commons/utils.ts +++ b/packages/contract-helpers/src/commons/utils.ts @@ -78,6 +78,10 @@ export const gasLimitRecommendations: GasRecommendationType = { limit: '300000', recommended: '300000', }, + [ProtocolAction.repayETH]: { + limit: '350000', + recommended: '300000', + }, [ProtocolAction.borrowETH]: { limit: '450000', recommended: '450000', @@ -118,10 +122,6 @@ export const gasLimitRecommendations: GasRecommendationType = { limit: '125000', recommended: '125000', }, - [ProtocolAction.stake]: { - limit: '395000', - recommended: '395000', - }, [ProtocolAction.claimRewards]: { limit: '275000', recommended: '275000', @@ -130,6 +130,10 @@ export const gasLimitRecommendations: GasRecommendationType = { limit: '138000', recommended: '138000', }, + [ProtocolAction.repayWithATokens]: { + limit: '300000', + recommended: '300000', + }, }; export const mintAmountsPerToken: Record = { diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts index 6ae6a64d..741b544a 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts @@ -20,6 +20,7 @@ import { import { LPBorrowParamsType, LPDepositParamsType, + LPRepayParamsType, } from '../lendingPool-contract/lendingPoolTypes'; import { ILendingPool, @@ -43,6 +44,10 @@ export type DepositTxBuilder = { getApprovedAmount: ({ user, token }: TokenOwner) => Promise; }; +export type LPRepayTxBuilder = { + generateTxData: (args: LPRepayParamsType) => PopulatedTransaction; +}; + export interface LendingPoolBundleInterface { depositTxBuilder: DepositTxBuilder; } @@ -65,6 +70,7 @@ export class LendingPoolBundle depositTxBuilder: DepositTxBuilder; borrowTxBuilder: Omit; + repayTxBuilder: LPRepayTxBuilder; constructor( provider: providers.Provider, @@ -191,5 +197,41 @@ export class LendingPoolBundle return actionTx; }, }; + this.repayTxBuilder = { + generateTxData: ({ + user, + reserve, + onBehalfOf, + interestRateMode, + amount, + }) => { + const actionTx: PopulatedTransaction = {}; + if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) { + return this.wethGatewayService.generateRepayEthTxData({ + lendingPool: this.lendingPoolAddress, + user, + amount, + interestRateMode, + onBehalfOf, + }); + } + + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + const txData = this.contractInterface.encodeFunctionData('repay', [ + reserve, + amount, + numericRateMode, + onBehalfOf ?? user, + ]); + actionTx.to = this.lendingPoolAddress; + actionTx.from = user; + actionTx.data = txData; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repay].recommended, + ); + return actionTx; + }, + }; } } diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts index 3c7e4466..7221b700 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts @@ -237,4 +237,55 @@ describe('LendingPoolBundle', () => { ); }); }); + + describe('RepayTxBuilder', () => { + const config = { + LENDING_POOL, + WETH_GATEWAY, + }; + + const instance = new LendingPoolBundle(provider, config); + + it('generates repay tx data with generateTxData', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + }); + + const differentParamsSameResult = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + }); + + expect(result.to).toEqual(LENDING_POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + expect(differentParamsSameResult.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); + + it('generates repay tx for WETHGateway data with generateTxData', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: API_ETH_MOCK_ADDRESS.toLowerCase(), + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + }); + expect(result.to).toEqual(WETH_GATEWAY); + expect(result.from).toEqual(USER); + expect(result.value).toEqual(BigNumber.from('1')); + expect(result.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); + }); }); diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts index 171c353c..fc1f4b3a 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts @@ -5,6 +5,8 @@ import { BorrowTxBuilder, InterestRate, ProtocolAction, + RepayTxBuilder, + RepayWithATokensTxBuilder, tEthereumAddress, } from '../commons/types'; import { @@ -96,6 +98,8 @@ export class PoolBundle supplyTxBuilder: SupplyTxBuilder; borrowTxBuilder: BorrowTxBuilder; + repayTxBuilder: RepayTxBuilder; + repayWithATokensTxBuilder: RepayWithATokensTxBuilder; constructor( provider: providers.Provider, @@ -329,5 +333,105 @@ export class PoolBundle return actionTx; }, }; + + this.repayTxBuilder = { + generateTxData: ({ + user, + reserve, + amount, + interestRateMode, + onBehalfOf, + }) => { + let actionTx: PopulatedTransaction = {}; + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + const onBehalfOfParam = onBehalfOf ?? user; + if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) { + actionTx = this.wethGatewayService.generateRepayEthTxData({ + lendingPool: this.poolAddress, + user, + amount, + interestRateMode, + onBehalfOf: onBehalfOfParam, + }); + } else { + const txData = this.contractInterface.encodeFunctionData('repay', [ + reserve, + amount, + numericRateMode, + onBehalfOfParam, + ]); + actionTx.to = this.poolAddress; + actionTx.from = user; + actionTx.data = txData; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repay].recommended, + ); + } + + return actionTx; + }, + generateSignedTxData: ({ + onBehalfOf, + signature, + deadline, + user, + reserve, + amount, + interestRateMode, + }) => { + const decomposedSignature: Signature = splitSignature(signature); + const populatedTx: PopulatedTransaction = {}; + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + const onBehalfOfParam = onBehalfOf ?? user; + const txData = this.contractInterface.encodeFunctionData( + 'repayWithPermit', + [ + reserve, + amount, + numericRateMode, + onBehalfOfParam, + deadline, + decomposedSignature.v, + decomposedSignature.r, + decomposedSignature.s, + ], + ); + populatedTx.to = this.poolAddress; + populatedTx.from = user; + populatedTx.data = txData; + populatedTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayWithPermit].recommended, + ); + return populatedTx; + }, + }; + + this.repayWithATokensTxBuilder = { + generateTxData: ({ rateMode, user, amount, reserve }) => { + const actionTx: PopulatedTransaction = {}; + const numericRateMode = rateMode === InterestRate.Variable ? 2 : 1; + if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) { + throw new Error( + 'Can not repay with aTokens with eth. Should be WETH instead', + ); + } else { + const txData = this.contractInterface.encodeFunctionData( + 'repayWithATokens', + [reserve, amount, numericRateMode], + ); + actionTx.to = this.poolAddress; + actionTx.from = user; + actionTx.data = txData; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayWithATokens] + .recommended, + ); + } + + return actionTx; + }, + }; } } diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 5473e791..d8407455 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -524,4 +524,148 @@ describe('PoolBundle', () => { expect(resultStable.data).toEqual(txData); }); }); + + describe('RepayTxBuilder', () => { + const config = { + POOL, + FLASH_LIQUIDATION_ADAPTER, + REPAY_WITH_COLLATERAL_ADAPTER, + SWAP_COLLATERAL_ADAPTER, + WETH_GATEWAY, + L2_ENCODER, + }; + + const instance = new PoolBundle(provider, config); + + it('generates repay tx data with generateTxData', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + onBehalfOf: USER, + }); + + const differentParamsSameResult = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + expect(differentParamsSameResult.to).toEqual(POOL); + expect(differentParamsSameResult.from).toEqual(USER); + expect(differentParamsSameResult.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); + + it('generates repay tx for WETHGateway data with generateTxData', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: API_ETH_MOCK_ADDRESS.toLowerCase(), + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + }); + + const differentParamsSameResult = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: API_ETH_MOCK_ADDRESS.toLowerCase(), + amount: '1', + interestRateMode: InterestRate.Variable, + }); + expect(result.to).toEqual(WETH_GATEWAY); + expect(result.from).toEqual(USER); + expect(result.value).toEqual(BigNumber.from('1')); + expect(result.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + expect(differentParamsSameResult.to).toEqual(WETH_GATEWAY); + expect(differentParamsSameResult.from).toEqual(USER); + expect(differentParamsSameResult.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); + + it('generates signed tx with generateSignedTxData', () => { + const result = instance.repayTxBuilder.generateSignedTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + deadline: '10000', + }); + + const differentParamsSameResult = + instance.repayTxBuilder.generateSignedTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + deadline: '10000', + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + expect(differentParamsSameResult.to).toEqual(POOL); + expect(differentParamsSameResult.from).toEqual(USER); + expect(differentParamsSameResult.data).toEqual( + '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + }); + + describe('RepayWithATokenTxBuilder', () => { + const config = { + POOL, + FLASH_LIQUIDATION_ADAPTER, + REPAY_WITH_COLLATERAL_ADAPTER, + SWAP_COLLATERAL_ADAPTER, + WETH_GATEWAY, + L2_ENCODER, + }; + + const instance = new PoolBundle(provider, config); + + it('generates repayWithAToken tx data with generateTxData', () => { + const result = instance.repayWithATokensTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + rateMode: InterestRate.Variable, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x2dad97d4000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002', + ); + }); + + it('should throw error if ETH mock address is passed', () => { + const generateData = () => + instance.repayWithATokensTxBuilder.generateTxData({ + user: USER, + reserve: API_ETH_MOCK_ADDRESS, + amount: '1', + rateMode: InterestRate.Variable, + }); + + expect(generateData).toThrow(); + }); + }); }); diff --git a/packages/contract-helpers/src/v3-pool-rollups/poolTypes.ts b/packages/contract-helpers/src/v3-pool-rollups/poolTypes.ts index 7f93ea16..034eba55 100644 --- a/packages/contract-helpers/src/v3-pool-rollups/poolTypes.ts +++ b/packages/contract-helpers/src/v3-pool-rollups/poolTypes.ts @@ -28,6 +28,7 @@ export type LPRepayParamsType = { reserve: tEthereumAddress; amount: string; numericRateMode: number; + onBehalfOf?: string; }; export type LPSupplyWithPermitType = { @@ -51,6 +52,7 @@ export type LPRepayWithPermitParamsType = { permitV: BigNumberish; permitR: BytesLike; permitS: BytesLike; + onBehalfOf?: string; }; export type LPRepayWithATokensType = { diff --git a/packages/contract-helpers/src/wethgateway-contract/index.ts b/packages/contract-helpers/src/wethgateway-contract/index.ts index 72f7fcb6..d3c262c9 100644 --- a/packages/contract-helpers/src/wethgateway-contract/index.ts +++ b/packages/contract-helpers/src/wethgateway-contract/index.ts @@ -62,6 +62,7 @@ export interface WETHGatewayInterface { args: WETHDepositParamsType, ) => PopulatedTransaction; generateBorrowEthTxData: (args: WETHBorrowParamsType) => PopulatedTransaction; + generateRepayEthTxData: (args: WETHRepayParamsType) => PopulatedTransaction; depositETH: ( args: WETHDepositParamsType, ) => EthereumTransactionTypeExtended[]; @@ -92,6 +93,8 @@ export class WETHGatewayService generateBorrowEthTxData: (args: WETHBorrowParamsType) => PopulatedTransaction; + generateRepayEthTxData: (args: WETHRepayParamsType) => PopulatedTransaction; + constructor( provider: providers.Provider, erc20Service: IERC20ServiceInterface, @@ -153,6 +156,33 @@ export class WETHGatewayService }; return actionTx; }; + + this.generateRepayEthTxData = ({ + interestRateMode, + lendingPool, + amount, + user, + onBehalfOf, + }) => { + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + const txData = this.wethGatewayInstance.encodeFunctionData('repayETH', [ + lendingPool, + amount, + numericRateMode, + onBehalfOf ?? user, + ]); + const actionTx: PopulatedTransaction = { + data: txData, + to: this.wethGatewayAddress, + from: user, + value: BigNumber.from(amount), + gasLimit: BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayETH].limit, + ), + }; + return actionTx; + }; } @WETHValidator diff --git a/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts b/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts index 9bf43fef..87a1a7d2 100644 --- a/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts +++ b/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts @@ -113,6 +113,46 @@ describe('WethGatewayService', () => { ); }); }); + describe('generateRepayEthTxData', () => { + it('generates repayETH tx data', () => { + const provider: providers.Provider = new providers.JsonRpcProvider(); + const erc20Service = new ERC20Service(provider); + const weth = new WETHGatewayService( + provider, + erc20Service, + wethGatewayAddress, + ); + const user = '0x0000000000000000000000000000000000000003'; + const txData = weth.generateRepayEthTxData({ + lendingPool, + user, + amount: '1', + interestRateMode: InterestRate.Variable, + }); + + expect(txData.to).toEqual(wethGatewayAddress); + expect(txData.from).toEqual(user); + expect(txData.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + + const onBehalfOf = '0x0000000000000000000000000000000000000004'; + + const txDataUpdatedParams = weth.generateRepayEthTxData({ + lendingPool, + user, + amount: '1', + onBehalfOf, + interestRateMode: InterestRate.Variable, + }); + + expect(txDataUpdatedParams.to).toEqual(wethGatewayAddress); + expect(txDataUpdatedParams.from).toEqual(user); + expect(txDataUpdatedParams.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004', + ); + }); + }); describe('depositETH', () => { const user = '0x0000000000000000000000000000000000000003'; const onBehalfOf = '0x0000000000000000000000000000000000000004'; From 45458494b8e59c90f88fae315d34749099213262 Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Tue, 22 Aug 2023 03:36:45 +0100 Subject: [PATCH 02/24] feat: added test for stable debt --- .../lendingPoolBundle.test.ts | 20 ++++++- .../pool-bundle.test.ts | 56 ++++++++++++++++++- .../wethgateway-contract/wethGateway.test.ts | 25 ++++++++- 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts index 7221b700..cfc4051a 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts @@ -246,7 +246,7 @@ describe('LendingPoolBundle', () => { const instance = new LendingPoolBundle(provider, config); - it('generates repay tx data with generateTxData', () => { + it('generates repay tx data with generateTxData with variable debt', () => { const result = instance.repayTxBuilder.generateTxData({ user: USER, reserve: TOKEN, @@ -272,7 +272,23 @@ describe('LendingPoolBundle', () => { ); }); - it('generates repay tx for WETHGateway data with generateTxData', () => { + it('generates repay tx data with generateTxData with stable debt', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Stable, + }); + + expect(result.to).toEqual(LENDING_POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003', + ); + }); + + it('generates repay tx for WETHGateway data with generateTxData with variable debt', () => { const result = instance.repayTxBuilder.generateTxData({ user: USER, reserve: API_ETH_MOCK_ADDRESS.toLowerCase(), diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index d8407455..39db5697 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -537,7 +537,7 @@ describe('PoolBundle', () => { const instance = new PoolBundle(provider, config); - it('generates repay tx data with generateTxData', () => { + it('generates repay tx data with generateTxData with variable debt', () => { const result = instance.repayTxBuilder.generateTxData({ user: USER, reserve: TOKEN, @@ -565,6 +565,22 @@ describe('PoolBundle', () => { ); }); + it('generates repay tx data with generateTxData with stable debt', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Stable, + onBehalfOf: USER, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003', + ); + }); + it('generates repay tx for WETHGateway data with generateTxData', () => { const result = instance.repayTxBuilder.generateTxData({ user: USER, @@ -593,7 +609,7 @@ describe('PoolBundle', () => { ); }); - it('generates signed tx with generateSignedTxData', () => { + it('generates signed tx with generateSignedTxData with variable debt', () => { const result = instance.repayTxBuilder.generateSignedTxData({ user: USER, reserve: TOKEN, @@ -627,6 +643,25 @@ describe('PoolBundle', () => { '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', ); }); + + it('generates signed tx with generateSignedTxData with stable debt', () => { + const result = instance.repayTxBuilder.generateSignedTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Stable, + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + deadline: '10000', + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); }); describe('RepayWithATokenTxBuilder', () => { @@ -641,7 +676,7 @@ describe('PoolBundle', () => { const instance = new PoolBundle(provider, config); - it('generates repayWithAToken tx data with generateTxData', () => { + it('generates repayWithAToken tx data with generateTxData with variable rate', () => { const result = instance.repayWithATokensTxBuilder.generateTxData({ user: USER, reserve: TOKEN, @@ -656,6 +691,21 @@ describe('PoolBundle', () => { ); }); + it('generates repayWithAToken tx data with generateTxData with stable debt', () => { + const result = instance.repayWithATokensTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + rateMode: InterestRate.Stable, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x2dad97d4000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001', + ); + }); + it('should throw error if ETH mock address is passed', () => { const generateData = () => instance.repayWithATokensTxBuilder.generateTxData({ diff --git a/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts b/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts index 87a1a7d2..5b6ef6db 100644 --- a/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts +++ b/packages/contract-helpers/src/wethgateway-contract/wethGateway.test.ts @@ -114,7 +114,7 @@ describe('WethGatewayService', () => { }); }); describe('generateRepayEthTxData', () => { - it('generates repayETH tx data', () => { + it('generates repayETH tx data with variable debt', () => { const provider: providers.Provider = new providers.JsonRpcProvider(); const erc20Service = new ERC20Service(provider); const weth = new WETHGatewayService( @@ -152,6 +152,29 @@ describe('WethGatewayService', () => { '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004', ); }); + + it('generates repayETH tx data with stable debt', () => { + const provider: providers.Provider = new providers.JsonRpcProvider(); + const erc20Service = new ERC20Service(provider); + const weth = new WETHGatewayService( + provider, + erc20Service, + wethGatewayAddress, + ); + const user = '0x0000000000000000000000000000000000000003'; + const txData = weth.generateRepayEthTxData({ + lendingPool, + user, + amount: '1', + interestRateMode: InterestRate.Stable, + }); + + expect(txData.to).toEqual(wethGatewayAddress); + expect(txData.from).toEqual(user); + expect(txData.data).toEqual( + '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003', + ); + }); }); describe('depositETH', () => { const user = '0x0000000000000000000000000000000000000003'; From 9a9b6935eb38067043d6773ef5b53be01fc9b667 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 6 Sep 2023 16:08:16 -0500 Subject: [PATCH 03/24] fix: bad merge --- packages/contract-helpers/src/commons/utils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/contract-helpers/src/commons/utils.ts b/packages/contract-helpers/src/commons/utils.ts index 39cf3aa9..e711ac9b 100644 --- a/packages/contract-helpers/src/commons/utils.ts +++ b/packages/contract-helpers/src/commons/utils.ts @@ -110,6 +110,10 @@ export const gasLimitRecommendations: GasRecommendationType = { limit: '350000', recommended: '350000', }, + [ProtocolAction.stake]: { + limit: '350000', + recommended: '350000', + }, [ProtocolAction.stakeWithPermit]: { limit: '400000', recommended: '400000', From 30c68cc735a2c682c7aae2862921cb484aa81adf Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Fri, 15 Sep 2023 17:51:45 +0100 Subject: [PATCH 04/24] feat: added encoded tx data --- .../contract-helpers/src/commons/types.ts | 4 +- .../src/lendingPool-contract-bundle/index.ts | 4 +- .../lendingPoolBundle.test.ts | 16 ++++ .../src/v3-pool-contract-bundle/index.ts | 87 +++++++++++++------ .../pool-bundle.test.ts | 57 ++++++++++++ .../src/v3-pool-contract/lendingPoolTypes.ts | 8 ++ .../src/v3-pool-rollups/index.ts | 81 +++++++++++++++++ .../src/v3-pool-rollups/pool-rollups.test.ts | 78 +++++++++++++++++ 8 files changed, 303 insertions(+), 32 deletions(-) diff --git a/packages/contract-helpers/src/commons/types.ts b/packages/contract-helpers/src/commons/types.ts index 1ab680f7..5ce69546 100644 --- a/packages/contract-helpers/src/commons/types.ts +++ b/packages/contract-helpers/src/commons/types.ts @@ -3,7 +3,7 @@ import { LPBorrowParamsType, LPRepayParamsType, LPRepayWithATokensType, - LPRepayWithPermitParamsType, + LPSignedRepayParamsType, } from '../v3-pool-contract/lendingPoolTypes'; export type tEthereumAddress = string; @@ -356,7 +356,7 @@ export type BorrowTxBuilder = { export type RepayTxBuilder = { generateTxData: (params: LPRepayParamsType) => PopulatedTransaction; generateSignedTxData: ( - params: LPRepayWithPermitParamsType, + params: LPSignedRepayParamsType, ) => PopulatedTransaction; }; diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts index 741b544a..5ce2be98 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts @@ -1,4 +1,4 @@ -import { providers, PopulatedTransaction, BigNumber } from 'ethers'; +import { providers, PopulatedTransaction, BigNumber, constants } from 'ethers'; import BaseService from '../commons/BaseService'; import { BorrowTxBuilder, @@ -220,7 +220,7 @@ export class LendingPoolBundle interestRateMode === InterestRate.Variable ? 2 : 1; const txData = this.contractInterface.encodeFunctionData('repay', [ reserve, - amount, + amount === '-1' ? constants.MaxUint256.toString() : amount, numericRateMode, onBehalfOf ?? user, ]); diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts index cfc4051a..104a41ef 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/lendingPoolBundle.test.ts @@ -303,5 +303,21 @@ describe('LendingPoolBundle', () => { '0x02c5fcf80000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', ); }); + + it('generates repay tx data with generateTxData with variable debt and max repay', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '-1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + }); + + expect(result.to).toEqual(LENDING_POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); }); }); diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts index fc1f4b3a..c2f6b674 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts @@ -341,34 +341,42 @@ export class PoolBundle amount, interestRateMode, onBehalfOf, + useOptimizedPath, + encodedTxData, }) => { - let actionTx: PopulatedTransaction = {}; const numericRateMode = interestRateMode === InterestRate.Variable ? 2 : 1; const onBehalfOfParam = onBehalfOf ?? user; if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) { - actionTx = this.wethGatewayService.generateRepayEthTxData({ + return this.wethGatewayService.generateRepayEthTxData({ lendingPool: this.poolAddress, user, amount, interestRateMode, onBehalfOf: onBehalfOfParam, }); - } else { - const txData = this.contractInterface.encodeFunctionData('repay', [ - reserve, - amount, - numericRateMode, - onBehalfOfParam, - ]); - actionTx.to = this.poolAddress; - actionTx.from = user; - actionTx.data = txData; - actionTx.gasLimit = BigNumber.from( - gasLimitRecommendations[ProtocolAction.repay].recommended, - ); } + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedRepayTxData({ + encodedTxData, + user, + }); + } + + const actionTx: PopulatedTransaction = {}; + const txData = this.contractInterface.encodeFunctionData('repay', [ + reserve, + amount, + numericRateMode, + onBehalfOfParam, + ]); + actionTx.to = this.poolAddress; + actionTx.from = user; + actionTx.data = txData; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repay].recommended, + ); return actionTx; }, generateSignedTxData: ({ @@ -379,12 +387,22 @@ export class PoolBundle reserve, amount, interestRateMode, + useOptimizedPath, + encodedTxData, }) => { const decomposedSignature: Signature = splitSignature(signature); const populatedTx: PopulatedTransaction = {}; const numericRateMode = interestRateMode === InterestRate.Variable ? 2 : 1; const onBehalfOfParam = onBehalfOf ?? user; + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedRepayWithPermitTxData({ + encodedTxData, + user, + signature, + }); + } + const txData = this.contractInterface.encodeFunctionData( 'repayWithPermit', [ @@ -409,27 +427,40 @@ export class PoolBundle }; this.repayWithATokensTxBuilder = { - generateTxData: ({ rateMode, user, amount, reserve }) => { + generateTxData: ({ + rateMode, + user, + amount, + reserve, + useOptimizedPath, + encodedTxData, + }) => { const actionTx: PopulatedTransaction = {}; const numericRateMode = rateMode === InterestRate.Variable ? 2 : 1; if (reserve.toLowerCase() === API_ETH_MOCK_ADDRESS.toLowerCase()) { throw new Error( 'Can not repay with aTokens with eth. Should be WETH instead', ); - } else { - const txData = this.contractInterface.encodeFunctionData( - 'repayWithATokens', - [reserve, amount, numericRateMode], - ); - actionTx.to = this.poolAddress; - actionTx.from = user; - actionTx.data = txData; - actionTx.gasLimit = BigNumber.from( - gasLimitRecommendations[ProtocolAction.repayWithATokens] - .recommended, - ); } + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedRepayWithATokensTxData({ + encodedTxData, + user, + }); + } + + const txData = this.contractInterface.encodeFunctionData( + 'repayWithATokens', + [reserve, amount, numericRateMode], + ); + actionTx.to = this.poolAddress; + actionTx.from = user; + actionTx.data = txData; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayWithATokens].recommended, + ); + return actionTx; }, }; diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 39db5697..790c4994 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -609,6 +609,45 @@ describe('PoolBundle', () => { ); }); + it('generates repay tx data with generateTxData and L2POOL with encoded txData', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + useOptimizedPath: true, + encodedTxData: + '0x0000000000000000000000000000000000000000000000000000006d6168616d', + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x563dd6130000000000000000000000000000000000000000000000000000006d6168616d', + ); + }); + + it('generates signed repay tx data with generateSignedTxData and L2POOL with encoded txData', () => { + const result = instance.repayTxBuilder.generateSignedTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + deadline: '10000', + useOptimizedPath: true, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + it('generates signed tx with generateSignedTxData with variable debt', () => { const result = instance.repayTxBuilder.generateSignedTxData({ user: USER, @@ -717,5 +756,23 @@ describe('PoolBundle', () => { expect(generateData).toThrow(); }); + + it('generates repay tx data with generateTxData and L2POOL with encoded txData', () => { + const result = instance.repayWithATokensTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '1', + rateMode: InterestRate.Variable, + useOptimizedPath: true, + encodedTxData: + '0x0000000000000000000000000000000000000000000000000000006d6168616d', + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0xdc7c0bff0000000000000000000000000000000000000000000000000000006d6168616d', + ); + }); }); }); diff --git a/packages/contract-helpers/src/v3-pool-contract/lendingPoolTypes.ts b/packages/contract-helpers/src/v3-pool-contract/lendingPoolTypes.ts index 1058f7e4..42b948f5 100644 --- a/packages/contract-helpers/src/v3-pool-contract/lendingPoolTypes.ts +++ b/packages/contract-helpers/src/v3-pool-contract/lendingPoolTypes.ts @@ -50,6 +50,12 @@ export type LPRepayParamsType = { interestRateMode: InterestRate; onBehalfOf?: tEthereumAddress; useOptimizedPath?: boolean; + encodedTxData?: string; +}; + +export type LPSignedRepayParamsType = LPRepayParamsType & { + signature: string; + deadline: string; }; export type LPSwapBorrowRateMode = { @@ -147,6 +153,7 @@ export type LPRepayWithPermitParamsType = { signature: SignatureLike; useOptimizedPath?: boolean; deadline: string; + encodedTxData?: string; }; export type LPSignERC20ApprovalType = { @@ -167,6 +174,7 @@ export type LPRepayWithATokensType = { amount: string; rateMode: InterestRate; useOptimizedPath?: boolean; + encodedTxData?: string; }; export type LPReserveData = { diff --git a/packages/contract-helpers/src/v3-pool-rollups/index.ts b/packages/contract-helpers/src/v3-pool-rollups/index.ts index 95428671..95e6d1f1 100644 --- a/packages/contract-helpers/src/v3-pool-rollups/index.ts +++ b/packages/contract-helpers/src/v3-pool-rollups/index.ts @@ -53,6 +53,19 @@ export interface L2PoolInterface { user: string; signature: string; }) => PopulatedTransaction; + generateEncodedRepayTxData: (args: { + encodedTxData: string; + user: string; + }) => PopulatedTransaction; + generateEncodedRepayWithPermitTxData: (args: { + encodedTxData: string; + user: string; + signature: string; + }) => PopulatedTransaction; + generateEncodedRepayWithATokensTxData: (args: { + encodedTxData: string; + user: string; + }) => PopulatedTransaction; supplyWithPermit: ( args: LPSupplyWithPermitType, txs: EthereumTransactionTypeExtended[], @@ -126,6 +139,22 @@ export class L2Pool extends BaseService implements L2PoolInterface { signature: string; }) => PopulatedTransaction; + generateEncodedRepayTxData: (args: { + encodedTxData: string; + user: string; + }) => PopulatedTransaction; + + generateEncodedRepayWithPermitTxData: (args: { + encodedTxData: string; + user: string; + signature: string; + }) => PopulatedTransaction; + + generateEncodedRepayWithATokensTxData: (args: { + encodedTxData: string; + user: string; + }) => PopulatedTransaction; + constructor(provider: providers.Provider, l2PoolConfig?: L2PoolConfigType) { super(provider, IL2Pool__factory); @@ -283,6 +312,58 @@ export class L2Pool extends BaseService implements L2PoolInterface { ); return actionTx; }; + + this.generateEncodedRepayTxData = ({ encodedTxData, user }) => { + const actionTx: PopulatedTransaction = {}; + const txData = this.l2PoolContractInstance.encodeFunctionData('repay', [ + encodedTxData, + ]); + + actionTx.to = this.l2PoolAddress; + actionTx.data = txData; + actionTx.from = user; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repay].limit, + ); + return actionTx; + }; + + this.generateEncodedRepayWithPermitTxData = ({ + encodedTxData, + user, + signature, + }) => { + const actionTx: PopulatedTransaction = {}; + const decomposedSignature: Signature = splitSignature(signature); + const txData = this.l2PoolContractInstance.encodeFunctionData( + 'repayWithPermit', + [encodedTxData, decomposedSignature.r, decomposedSignature.s], + ); + + actionTx.to = this.l2PoolAddress; + actionTx.data = txData; + actionTx.from = user; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayWithPermit].limit, + ); + return actionTx; + }; + + this.generateEncodedRepayWithATokensTxData = ({ encodedTxData, user }) => { + const actionTx: PopulatedTransaction = {}; + const txData = this.l2PoolContractInstance.encodeFunctionData( + 'repayWithATokens', + [encodedTxData], + ); + + actionTx.to = this.l2PoolAddress; + actionTx.data = txData; + actionTx.from = user; + actionTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.repayWithATokens].limit, + ); + return actionTx; + }; } @L2PValidator diff --git a/packages/contract-helpers/src/v3-pool-rollups/pool-rollups.test.ts b/packages/contract-helpers/src/v3-pool-rollups/pool-rollups.test.ts index 8896694c..5ef173d7 100644 --- a/packages/contract-helpers/src/v3-pool-rollups/pool-rollups.test.ts +++ b/packages/contract-helpers/src/v3-pool-rollups/pool-rollups.test.ts @@ -287,6 +287,84 @@ describe('L2Pool', () => { expect(txData.from).toEqual(user); expect(txData.data).toEqual(encodedBorrowTxData); }); + + it('Generate repay tx data with encoded parameter', async () => { + const instance: L2PoolInterface = new L2Pool(provider, config); + + const encoder = instance.getEncoder(); + + const encodedTxData = await encoder.encodeRepayParams(reserve, 1, '0'); + + const txData = instance.generateEncodedSupplyTxData({ + user, + encodedTxData, + }); + + const encodedRepayTxData = + '0xf7a738400000000000000000000000000000000000000000000000000000006d6168616d'; + expect(txData.to).toEqual(l2PoolAddress); + expect(txData.from).toEqual(user); + expect(txData.data).toEqual(encodedRepayTxData); + }); + + it('Generate repayWithATokens tx data with encoded parameter', async () => { + const instance: L2PoolInterface = new L2Pool(provider, config); + + const encoder = instance.getEncoder(); + + const encodedTxData = await encoder.encodeRepayWithATokensParams( + reserve, + 1, + '0', + ); + + const txData = instance.generateEncodedRepayWithATokensTxData({ + user, + encodedTxData, + }); + + const encodedRepayTxData = + '0xdc7c0bff0000000000000000000000000000000000000000000000000000006d6168616d'; + expect(txData.to).toEqual(l2PoolAddress); + expect(txData.from).toEqual(user); + expect(txData.data).toEqual(encodedRepayTxData); + }); + + it('Generate repayWithPermit tx data with encoded parameter', async () => { + const instance: L2PoolInterface = new L2Pool(provider, config); + + const encoder = instance.getEncoder(); + + const signature = + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c'; + const decomposedSignature = splitSignature(signature); + expect(instance).toBeDefined(); + expect(encoder).toBeDefined(); + + const encodedTxData = await encoder.encodeRepayWithPermitParams( + reserve, + 1, + '0', + '10000', + decomposedSignature.v, + decomposedSignature.r, + decomposedSignature.s, + ); + + expect(encodedTxData).toBeDefined(); + + const txData = instance.generateEncodedRepayWithPermitTxData({ + user, + encodedTxData: encodedTxData[0], + signature, + }); + + const encodedRepayWithPermitTxData = + '0x94b576de0000000000000000000000000000000000000000000000000000006d6168616d532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4'; + expect(txData.to).toEqual(l2PoolAddress); + expect(txData.from).toEqual(user); + expect(txData.data).toEqual(encodedRepayWithPermitTxData); + }); }); describe('getEncoder', () => { const instance: L2PoolInterface = new L2Pool(provider, config); From 718b1e357d29b466a55feee9e3587908a543de37 Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Fri, 15 Sep 2023 17:57:03 +0100 Subject: [PATCH 05/24] feat: added test for signed repay with l2 pool --- .../src/v3-pool-contract-bundle/pool-bundle.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 790c4994..41360448 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -639,12 +639,14 @@ describe('PoolBundle', () => { '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', deadline: '10000', useOptimizedPath: true, + encodedTxData: + '0x0000000000000000000000000000000000000000000000000000006d6168616d', }); expect(result.to).toEqual(POOL); expect(result.from).toEqual(USER); expect(result.data).toEqual( - '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + '0x94b576de0000000000000000000000000000000000000000000000000000006d6168616d532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', ); }); From 529ca8b427ce366f5f5b03df8d3088c7c522e8b3 Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Fri, 15 Sep 2023 18:08:13 +0100 Subject: [PATCH 06/24] feat: -1 handle --- .../src/v3-pool-contract-bundle/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts index c2f6b674..891246d3 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts @@ -1,5 +1,5 @@ import { Signature, splitSignature } from '@ethersproject/bytes'; -import { BigNumber, PopulatedTransaction, providers } from 'ethers'; +import { BigNumber, PopulatedTransaction, constants, providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { BorrowTxBuilder, @@ -367,7 +367,7 @@ export class PoolBundle const actionTx: PopulatedTransaction = {}; const txData = this.contractInterface.encodeFunctionData('repay', [ reserve, - amount, + amount === '-1' ? constants.MaxUint256.toString() : amount, numericRateMode, onBehalfOfParam, ]); @@ -407,7 +407,7 @@ export class PoolBundle 'repayWithPermit', [ reserve, - amount, + amount === '-1' ? constants.MaxUint256.toString() : amount, numericRateMode, onBehalfOfParam, deadline, @@ -452,7 +452,11 @@ export class PoolBundle const txData = this.contractInterface.encodeFunctionData( 'repayWithATokens', - [reserve, amount, numericRateMode], + [ + reserve, + amount === '-1' ? constants.MaxUint256.toString() : amount, + numericRateMode, + ], ); actionTx.to = this.poolAddress; actionTx.from = user; From 8d191bf193b4e5f74af4086481eb6f23a17f39e5 Mon Sep 17 00:00:00 2001 From: Joaquin Battilana Date: Fri, 15 Sep 2023 18:15:03 +0100 Subject: [PATCH 07/24] feat: added test for repay with max input (-1) --- .../pool-bundle.test.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 41360448..302491a5 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -565,6 +565,22 @@ describe('PoolBundle', () => { ); }); + it('generates repay tx data with generateTxData with variable debt and max input', () => { + const result = instance.repayTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '-1', + interestRateMode: InterestRate.Variable, + onBehalfOf: USER, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x573ade810000000000000000000000000000000000000000000000000000000000000004ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003', + ); + }); + it('generates repay tx data with generateTxData with stable debt', () => { const result = instance.repayTxBuilder.generateTxData({ user: USER, @@ -685,6 +701,24 @@ describe('PoolBundle', () => { ); }); + it('generates signed tx with generateSignedTxData with variable debt and max input', () => { + const result = instance.repayTxBuilder.generateSignedTxData({ + user: USER, + reserve: TOKEN, + amount: '-1', + onBehalfOf: USER, + interestRateMode: InterestRate.Variable, + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + deadline: '10000', + }); + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0xee3e210b0000000000000000000000000000000000000000000000000000000000000004ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + it('generates signed tx with generateSignedTxData with stable debt', () => { const result = instance.repayTxBuilder.generateSignedTxData({ user: USER, @@ -732,6 +766,21 @@ describe('PoolBundle', () => { ); }); + it('generates repayWithAToken tx data with generateTxData with variable rate and max input', () => { + const result = instance.repayWithATokensTxBuilder.generateTxData({ + user: USER, + reserve: TOKEN, + amount: '-1', + rateMode: InterestRate.Variable, + }); + + expect(result.to).toEqual(POOL); + expect(result.from).toEqual(USER); + expect(result.data).toEqual( + '0x2dad97d40000000000000000000000000000000000000000000000000000000000000004ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000002', + ); + }); + it('generates repayWithAToken tx data with generateTxData with stable debt', () => { const result = instance.repayWithATokensTxBuilder.generateTxData({ user: USER, From f5b8cfb0abc843ccf7510df0fb747b8138430dfe Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 24 Oct 2023 10:44:24 -0500 Subject: [PATCH 08/24] feat: added encode functions for using optimized path --- .../contract-helpers/src/commons/types.ts | 26 +++ .../src/lendingPool-contract-bundle/index.ts | 12 +- .../src/v3-pool-contract-bundle/index.ts | 216 +++++++++++------- .../pool-bundle.test.ts | 116 ++++++++++ 4 files changed, 280 insertions(+), 90 deletions(-) diff --git a/packages/contract-helpers/src/commons/types.ts b/packages/contract-helpers/src/commons/types.ts index 5ce69546..0c12eff7 100644 --- a/packages/contract-helpers/src/commons/types.ts +++ b/packages/contract-helpers/src/commons/types.ts @@ -351,6 +351,12 @@ export type BorrowTxBuilder = { useOptimizedPath, encodedTxData, }: LPBorrowParamsType) => PopulatedTransaction; + encodeBorrowParams: ({ + reserve, + amount, + interestRateMode, + referralCode, + }: Omit) => Promise; }; export type RepayTxBuilder = { @@ -358,8 +364,28 @@ export type RepayTxBuilder = { generateSignedTxData: ( params: LPSignedRepayParamsType, ) => PopulatedTransaction; + encodeRepayParams: ({ + reserve, + amount, + interestRateMode, + }: Omit) => Promise; + encodeRepayWithPermitParams: ({ + reserve, + amount, + interestRateMode, + deadline, + signature, + }: Pick< + LPSignedRepayParamsType, + 'reserve' | 'amount' | 'interestRateMode' | 'signature' | 'deadline' + >) => Promise<[string, string, string]>; }; export type RepayWithATokensTxBuilder = { generateTxData: (params: LPRepayWithATokensType) => PopulatedTransaction; + encodeRepayWithATokensParams: ({ + reserve, + amount, + rateMode, + }: Omit) => Promise; }; diff --git a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts index 5ce2be98..e3a19f88 100644 --- a/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/lendingPool-contract-bundle/index.ts @@ -5,6 +5,7 @@ import { InterestRate, LendingPoolMarketConfig, ProtocolAction, + RepayTxBuilder, tEthereumAddress, } from '../commons/types'; import { @@ -20,7 +21,6 @@ import { import { LPBorrowParamsType, LPDepositParamsType, - LPRepayParamsType, } from '../lendingPool-contract/lendingPoolTypes'; import { ILendingPool, @@ -44,12 +44,10 @@ export type DepositTxBuilder = { getApprovedAmount: ({ user, token }: TokenOwner) => Promise; }; -export type LPRepayTxBuilder = { - generateTxData: (args: LPRepayParamsType) => PopulatedTransaction; -}; - export interface LendingPoolBundleInterface { depositTxBuilder: DepositTxBuilder; + borrowTxBuilder: Pick; + repayTxBuilder: Pick; } export class LendingPoolBundle @@ -69,8 +67,8 @@ export class LendingPoolBundle readonly wethGatewayAddress: tEthereumAddress; depositTxBuilder: DepositTxBuilder; - borrowTxBuilder: Omit; - repayTxBuilder: LPRepayTxBuilder; + borrowTxBuilder: Pick; + repayTxBuilder: Pick; constructor( provider: providers.Provider, diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts index 891246d3..2dfd3c82 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts @@ -34,10 +34,6 @@ import { import { IPool, IPoolInterface } from '../v3-pool-contract/typechain/IPool'; import { IPool__factory } from '../v3-pool-contract/typechain/IPool__factory'; import { L2Pool, L2PoolInterface } from '../v3-pool-rollups'; -import { - LPSupplyWithPermitType as LPSupplyWithPermitTypeL2, - LPBorrowParamsType as LPBorrowParamsTypeL2, -} from '../v3-pool-rollups/poolTypes'; import { WETHGatewayInterface, WETHGatewayService, @@ -64,6 +60,23 @@ export type SupplyTxBuilder = { encodedTxData, }: LPSignedSupplyParamsType) => PopulatedTransaction; getApprovedAmount: ({ user, token }: TokenOwner) => Promise; + encodeSupplyParams: ({ + reserve, + amount, + referralCode, + }: Pick< + LPSupplyParamsType, + 'reserve' | 'amount' | 'referralCode' + >) => Promise; + encodeSupplyWithPermitParams: ({ + reserve, + amount, + referralCode, + signature, + }: Pick< + LPSignedSupplyParamsType, + 'reserve' | 'amount' | 'referralCode' | 'signature' | 'deadline' + >) => Promise<[string, string, string]>; }; export interface PoolBundleInterface { @@ -156,6 +169,13 @@ export class PoolBundle useOptimizedPath, encodedTxData, }: LPSupplyParamsType): PopulatedTransaction => { + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedSupplyTxData({ + encodedTxData, + user, + }); + } + let actionTx: PopulatedTransaction = {}; const onBehalfOfParam = onBehalfOf ?? user; const referralCodeParam = referralCode ?? '0'; @@ -167,22 +187,6 @@ export class PoolBundle onBehalfOf: onBehalfOfParam, referralCode: referralCodeParam, }); - } else if (useOptimizedPath) { - if (encodedTxData) { - actionTx = this.l2PoolService.generateEncodedSupplyTxData({ - encodedTxData, - user, - }); - } else { - const args: LPSupplyParamsType = { - user, - reserve, - amount, - onBehalfOf: onBehalfOfParam, - referralCode: referralCodeParam, - }; - actionTx = this.l2PoolService.generateSupplyTxData(args); - } } else { const txData = this.contractInterface.encodeFunctionData('supply', [ reserve, @@ -211,58 +215,69 @@ export class PoolBundle deadline, encodedTxData, }: LPSignedSupplyParamsType): PopulatedTransaction => { + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedSupplyWithPermitTxData({ + encodedTxData, + user, + signature, + }); + } + const decomposedSignature: Signature = splitSignature(signature); - let populatedTx: PopulatedTransaction = {}; + const populatedTx: PopulatedTransaction = {}; const onBehalfOfParam = onBehalfOf ?? user; const referralCodeParam = referralCode ?? '0'; - if (useOptimizedPath) { - if (encodedTxData) { - populatedTx = - this.l2PoolService.generateEncodedSupplyWithPermitTxData({ - encodedTxData, - user, - signature, - }); - } else { - const args: LPSupplyWithPermitTypeL2 = { - user, - reserve, - amount, - referralCode: referralCodeParam, - onBehalfOf: onBehalfOfParam, - permitR: decomposedSignature.r, - permitS: decomposedSignature.s, - permitV: decomposedSignature.v, - deadline: Number(deadline), - }; - populatedTx = - this.l2PoolService.generateSupplyWithPermitTxData(args); - } - } else { - const txData = this.contractInterface.encodeFunctionData( - 'supplyWithPermit', - [ - reserve, - amount, - onBehalfOfParam, - referralCodeParam, - deadline, - decomposedSignature.v, - decomposedSignature.r, - decomposedSignature.s, - ], - ); - populatedTx.to = this.poolAddress; - populatedTx.from = user; - populatedTx.data = txData; - populatedTx.gasLimit = BigNumber.from( - gasLimitRecommendations[ProtocolAction.supplyWithPermit] - .recommended, - ); - } + const txData = this.contractInterface.encodeFunctionData( + 'supplyWithPermit', + [ + reserve, + amount, + onBehalfOfParam, + referralCodeParam, + deadline, + decomposedSignature.v, + decomposedSignature.r, + decomposedSignature.s, + ], + ); + populatedTx.to = this.poolAddress; + populatedTx.from = user; + populatedTx.data = txData; + populatedTx.gasLimit = BigNumber.from( + gasLimitRecommendations[ProtocolAction.supplyWithPermit].recommended, + ); return populatedTx; }, + encodeSupplyParams: async ({ + reserve, + amount, + referralCode, + }): Promise => { + return this.l2PoolService + .getEncoder() + .encodeSupplyParams(reserve, amount, referralCode ?? '0'); + }, + encodeSupplyWithPermitParams: async ({ + reserve, + amount, + signature, + deadline, + referralCode, + }): Promise<[string, string, string]> => { + const decomposedSignature: Signature = splitSignature(signature); + return this.l2PoolService + .getEncoder() + .encodeSupplyWithPermitParams( + reserve, + amount, + referralCode ?? '0', + deadline, + decomposedSignature.v, + decomposedSignature.r, + decomposedSignature.s, + ); + }, }; this.borrowTxBuilder = { @@ -277,6 +292,13 @@ export class PoolBundle useOptimizedPath, encodedTxData, }: LPBorrowParamsType): PopulatedTransaction => { + if (useOptimizedPath && encodedTxData) { + return this.l2PoolService.generateEncodedBorrowTxData({ + encodedTxData, + user, + }); + } + let actionTx: PopulatedTransaction = {}; const referralCodeParam = referralCode ?? '0'; const onBehalfOfParam = onBehalfOf ?? user; @@ -297,23 +319,6 @@ export class PoolBundle interestRateMode, referralCode: referralCodeParam, }); - } else if (useOptimizedPath) { - if (encodedTxData) { - actionTx = this.l2PoolService.generateEncodedBorrowTxData({ - encodedTxData, - user, - }); - } else { - const args: LPBorrowParamsTypeL2 = { - user, - reserve, - amount, - onBehalfOf: onBehalfOfParam, - referralCode: referralCodeParam, - numericRateMode, - }; - actionTx = this.l2PoolService.generateBorrowTxData(args); - } } else { const txData = this.contractInterface.encodeFunctionData('borrow', [ reserve, @@ -332,6 +337,21 @@ export class PoolBundle return actionTx; }, + encodeBorrowParams: async ({ + reserve, + amount, + interestRateMode, + referralCode, + }): Promise => { + return this.l2PoolService + .getEncoder() + .encodeBorrowParams( + reserve, + amount, + interestRateMode, + referralCode ?? '0', + ); + }, }; this.repayTxBuilder = { @@ -424,6 +444,31 @@ export class PoolBundle ); return populatedTx; }, + encodeRepayParams: async ({ reserve, amount, interestRateMode }) => { + return this.l2PoolService + .getEncoder() + .encodeRepayParams(reserve, amount, interestRateMode); + }, + encodeRepayWithPermitParams: async ({ + reserve, + amount, + interestRateMode, + signature, + deadline, + }) => { + const decomposedSignature: Signature = splitSignature(signature); + return this.l2PoolService + .getEncoder() + .encodeRepayWithPermitParams( + reserve, + amount, + interestRateMode, + deadline, + decomposedSignature.v, + decomposedSignature.r, + decomposedSignature.s, + ); + }, }; this.repayWithATokensTxBuilder = { @@ -467,6 +512,11 @@ export class PoolBundle return actionTx; }, + encodeRepayWithATokensParams: async ({ reserve, amount, rateMode }) => { + return this.l2PoolService + .getEncoder() + .encodeRepayWithATokensParams(reserve, amount, rateMode); + }, }; } } diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 302491a5..62182946 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -1,6 +1,8 @@ import { BigNumber, providers } from 'ethers'; import { InterestRate } from '../commons/types'; import { API_ETH_MOCK_ADDRESS } from '../commons/utils'; +import { L2Encoder } from '../v3-pool-rollups/typechain/L2Encoder'; +import { L2Encoder__factory } from '../v3-pool-rollups/typechain/L2Encoder__factory'; import { PoolBundle } from './index'; jest.mock('../commons/gasStation', () => { @@ -28,6 +30,31 @@ describe('PoolBundle', () => { '0x0000000000000000000000000000000000000004'; const SWAP_COLLATERAL_ADAPTER = '0x0000000000000000000000000000000000000005'; const L2_ENCODER = '0x0000000000000000000000000000000000000020'; + + const encodedArg = + '0x0000000000000000000000000000000000000000000000000000006d6168616d'; + const permitR = + '0x0000000000000000000000000000000000000000000000000000000000000000'; + const permitS = + '0x0000000000000000000000000000000000000000000000000000000000000000'; + + const encoderSpy = jest.spyOn(L2Encoder__factory, 'connect').mockReturnValue({ + encodeSupplyParams: async () => Promise.resolve(encodedArg), + encodeSupplyWithPermitParams: async () => + Promise.resolve([encodedArg, permitR, permitS]), + encodeWithdrawParams: async () => Promise.resolve(encodedArg), + encodeBorrowParams: async () => Promise.resolve(encodedArg), + encodeRepayParams: async () => Promise.resolve(encodedArg), + encodeRepayWithPermitParams: async () => + Promise.resolve([encodedArg, permitR, permitS]), + encodeRepayWithATokensParams: async () => Promise.resolve(encodedArg), + encodeSwapBorrowRateMode: async () => Promise.resolve(encodedArg), + encodeSetUserUseReserveAsCollateral: async () => + Promise.resolve(encodedArg), + encodeLiquidationCall: async () => + Promise.resolve([encodedArg, encodedArg]), + } as unknown as L2Encoder); + describe('Initialization', () => { const config = { POOL, @@ -326,6 +353,46 @@ describe('PoolBundle', () => { '0x680dd47c0000000000000000000000000000000000000000000000000000006d6168616d532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', ); }); + + it('encodes supply params for L2', async () => { + await instance.supplyTxBuilder.encodeSupplyParams({ + reserve: TOKEN, + amount: '1', + referralCode: '1', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); + + it('encodes supply params for L2 without referral code', async () => { + await instance.supplyTxBuilder.encodeSupplyParams({ + reserve: TOKEN, + amount: '1', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); + + it('encodes supply with permit parmas for L2', async () => { + await instance.supplyTxBuilder.encodeSupplyWithPermitParams({ + reserve: TOKEN, + amount: '1', + referralCode: '1', + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); + + it('encodes supply with permit parmas for L2 without referral code', async () => { + await instance.supplyTxBuilder.encodeSupplyWithPermitParams({ + reserve: TOKEN, + amount: '1', + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); }); describe('BorrowTxBuilder', () => { @@ -523,6 +590,25 @@ describe('PoolBundle', () => { // Will be identical to variable, since tx data is pre-encoded, rate mode has no effect expect(resultStable.data).toEqual(txData); }); + + it('encodes borrow params for L2', async () => { + await instance.borrowTxBuilder.encodeBorrowParams({ + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + referralCode: '1', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); + + it('encodes borrow params for L2 without referral code', async () => { + await instance.borrowTxBuilder.encodeBorrowParams({ + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + }); + expect(encoderSpy).toHaveBeenCalled(); + }); }); describe('RepayTxBuilder', () => { @@ -737,6 +823,27 @@ describe('PoolBundle', () => { '0xee3e210b00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', ); }); + + it('encodes repay params for L2', async () => { + await instance.repayTxBuilder.encodeRepayParams({ + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + }); + expect(encoderSpy).toHaveBeenCalled(); + }); + + it('encodes repay with permit params for L2', async () => { + await instance.repayTxBuilder.encodeRepayWithPermitParams({ + reserve: TOKEN, + amount: '1', + interestRateMode: InterestRate.Variable, + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(encoderSpy).toHaveBeenCalled(); + }); }); describe('RepayWithATokenTxBuilder', () => { @@ -825,5 +932,14 @@ describe('PoolBundle', () => { '0xdc7c0bff0000000000000000000000000000000000000000000000000000006d6168616d', ); }); + + it('encodes repay with aToken params for L2', async () => { + await instance.repayWithATokensTxBuilder.encodeRepayWithATokensParams({ + reserve: TOKEN, + amount: '1', + rateMode: InterestRate.Variable, + }); + expect(encoderSpy).toHaveBeenCalled(); + }); }); }); From 46fe68f5b8a10b1f0b37da82a16a1a49e203076a Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 24 Oct 2023 14:21:06 -0500 Subject: [PATCH 09/24] fix: rate mode and max repay --- .../src/v3-pool-contract-bundle/index.ts | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts index 2dfd3c82..767957aa 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/index.ts @@ -343,12 +343,15 @@ export class PoolBundle interestRateMode, referralCode, }): Promise => { + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + return this.l2PoolService .getEncoder() .encodeBorrowParams( reserve, amount, - interestRateMode, + numericRateMode, referralCode ?? '0', ); }, @@ -445,9 +448,15 @@ export class PoolBundle return populatedTx; }, encodeRepayParams: async ({ reserve, amount, interestRateMode }) => { + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + + const repayAmount = + amount === '-1' ? constants.MaxUint256.toString() : amount; + return this.l2PoolService .getEncoder() - .encodeRepayParams(reserve, amount, interestRateMode); + .encodeRepayParams(reserve, repayAmount, numericRateMode); }, encodeRepayWithPermitParams: async ({ reserve, @@ -457,12 +466,17 @@ export class PoolBundle deadline, }) => { const decomposedSignature: Signature = splitSignature(signature); + const numericRateMode = + interestRateMode === InterestRate.Variable ? 2 : 1; + const repayAmount = + amount === '-1' ? constants.MaxUint256.toString() : amount; + return this.l2PoolService .getEncoder() .encodeRepayWithPermitParams( reserve, - amount, - interestRateMode, + repayAmount, + numericRateMode, deadline, decomposedSignature.v, decomposedSignature.r, @@ -513,9 +527,13 @@ export class PoolBundle return actionTx; }, encodeRepayWithATokensParams: async ({ reserve, amount, rateMode }) => { + const numericRateMode = rateMode === InterestRate.Variable ? 2 : 1; + const repayAmount = + amount === '-1' ? constants.MaxUint256.toString() : amount; + return this.l2PoolService .getEncoder() - .encodeRepayWithATokensParams(reserve, amount, rateMode); + .encodeRepayWithATokensParams(reserve, repayAmount, numericRateMode); }, }; } From 0efe71955bfd19d178a3edef77416ca0612598b9 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 24 Oct 2023 14:47:44 -0500 Subject: [PATCH 10/24] test: repay amount and interest rate mode --- .../pool-bundle.test.ts | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts index 62182946..2224aae3 100644 --- a/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts +++ b/packages/contract-helpers/src/v3-pool-contract-bundle/pool-bundle.test.ts @@ -591,22 +591,31 @@ describe('PoolBundle', () => { expect(resultStable.data).toEqual(txData); }); - it('encodes borrow params for L2', async () => { + it('encodes variable borrow params for L2', async () => { await instance.borrowTxBuilder.encodeBorrowParams({ reserve: TOKEN, amount: '1', interestRateMode: InterestRate.Variable, referralCode: '1', }); + + expect(encoderSpy).toHaveBeenCalled(); + + await instance.borrowTxBuilder.encodeBorrowParams({ + reserve: TOKEN, + amount: '-1', + interestRateMode: InterestRate.Stable, + referralCode: '1', + }); + expect(encoderSpy).toHaveBeenCalled(); - }); - it('encodes borrow params for L2 without referral code', async () => { await instance.borrowTxBuilder.encodeBorrowParams({ reserve: TOKEN, amount: '1', interestRateMode: InterestRate.Variable, }); + expect(encoderSpy).toHaveBeenCalled(); }); }); @@ -831,9 +840,14 @@ describe('PoolBundle', () => { interestRateMode: InterestRate.Variable, }); expect(encoderSpy).toHaveBeenCalled(); - }); - it('encodes repay with permit params for L2', async () => { + await instance.repayTxBuilder.encodeRepayParams({ + reserve: TOKEN, + amount: '-1', + interestRateMode: InterestRate.Stable, + }); + expect(encoderSpy).toHaveBeenCalled(); + await instance.repayTxBuilder.encodeRepayWithPermitParams({ reserve: TOKEN, amount: '1', @@ -843,6 +857,16 @@ describe('PoolBundle', () => { '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', }); expect(encoderSpy).toHaveBeenCalled(); + + await instance.repayTxBuilder.encodeRepayWithPermitParams({ + reserve: TOKEN, + amount: '-1', + interestRateMode: InterestRate.Stable, + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(encoderSpy).toHaveBeenCalled(); }); }); @@ -936,10 +960,17 @@ describe('PoolBundle', () => { it('encodes repay with aToken params for L2', async () => { await instance.repayWithATokensTxBuilder.encodeRepayWithATokensParams({ reserve: TOKEN, - amount: '1', + amount: '-1', rateMode: InterestRate.Variable, }); expect(encoderSpy).toHaveBeenCalled(); + + await instance.repayWithATokensTxBuilder.encodeRepayWithATokensParams({ + reserve: TOKEN, + amount: '1', + rateMode: InterestRate.Stable, + }); + expect(encoderSpy).toHaveBeenCalled(); }); }); }); From c7a445331d5c8d987b6aed3a1cf389a6b228c0f4 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Thu, 31 Aug 2023 14:00:17 -0500 Subject: [PATCH 11/24] feat: sdai token wrapper --- .../src/sdai-wrapper/index.ts | 176 ++++++ .../src/sdai-wrapper/sdai-wrapper.test.ts | 0 .../typechain/SavingsDaiTokenWrapper.d.ts | 523 ++++++++++++++++++ .../SavingsDaiTokenWrapper_factory.ts | 389 +++++++++++++ 4 files changed, 1088 insertions(+) create mode 100644 packages/contract-helpers/src/sdai-wrapper/index.ts create mode 100644 packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts create mode 100644 packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts create mode 100644 packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts diff --git a/packages/contract-helpers/src/sdai-wrapper/index.ts b/packages/contract-helpers/src/sdai-wrapper/index.ts new file mode 100644 index 00000000..4a9d2199 --- /dev/null +++ b/packages/contract-helpers/src/sdai-wrapper/index.ts @@ -0,0 +1,176 @@ +import { Signature, SignatureLike, splitSignature } from '@ethersproject/bytes'; +import { PopulatedTransaction, providers } from 'ethers'; +import BaseService from '../commons/BaseService'; +import { + BaseTokenWrapper, + SavingsDaiTokenWrapper, + SavingsDaiTokenWrapperInterface, +} from './typechain/SavingsDaiTokenWrapper'; +import { SavingsDaiTokenWrapper__factory } from './typechain/SavingsDaiTokenWrapper_factory'; + +interface SupplyTokenWithPermitParams { + amount: string; + onBehalfOf: string; + referralCode: string; + deadline: string; + signature: SignatureLike; +} + +export interface SavingsDaiTokenWrapperServiceInterface { + getTokenInForTokenOut: (amount: string, user: string) => PopulatedTransaction; + getTokenOutForTokenIn: (amount: string, user: string) => PopulatedTransaction; + supplyToken: ( + amount: string, + onBehalfOf: string, + referralCode: string, + ) => PopulatedTransaction; + supplyTokenWithPermit: ({ + amount, + onBehalfOf, + referralCode, + deadline, + signature, + }: SupplyTokenWithPermitParams) => PopulatedTransaction; + withdrawToken: (amount: string, user: string) => PopulatedTransaction; + withdrawTokenWithPermit: ( + amount: string, + user: string, + deadline: string, + signature: SignatureLike, + ) => PopulatedTransaction; +} + +export class SavingsDaiTokenWrapperService + extends BaseService + implements SavingsDaiTokenWrapperServiceInterface +{ + readonly savingsDaiTokenWrapperAddress: string; + readonly contractInterface: SavingsDaiTokenWrapperInterface; + + constructor( + provider: providers.Provider, + savingsDaiTokenWrapperAddress: string, + ) { + super(provider, SavingsDaiTokenWrapper__factory); + this.savingsDaiTokenWrapperAddress = savingsDaiTokenWrapperAddress; + this.contractInterface = SavingsDaiTokenWrapper__factory.createInterface(); + + this.getTokenInForTokenOut = this.getTokenInForTokenOut.bind(this); + this.getTokenOutForTokenIn = this.getTokenOutForTokenIn.bind(this); + this.supplyToken = this.supplyToken.bind(this); + this.supplyTokenWithPermit = this.supplyTokenWithPermit.bind(this); + this.withdrawToken = this.withdrawToken.bind(this); + this.withdrawTokenWithPermit = this.withdrawTokenWithPermit.bind(this); + } + + public getTokenInForTokenOut( + amount: string, + user: string, + ): PopulatedTransaction { + const data = this.contractInterface.encodeFunctionData( + 'getTokenInForTokenOut', + [amount], + ); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: user, + data, + }; + } + + public getTokenOutForTokenIn(amount: string, user: string) { + const data = this.contractInterface.encodeFunctionData( + 'getTokenOutForTokenIn', + [amount], + ); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: user, + data, + }; + } + + public supplyToken(amount: string, onBehalfOf: string, referralCode: string) { + const data = this.contractInterface.encodeFunctionData('supplyToken', [ + amount, + onBehalfOf, + referralCode, + ]); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: onBehalfOf, + data, + }; + } + + public supplyTokenWithPermit({ + amount, + onBehalfOf, + referralCode, + deadline, + signature, + }: SupplyTokenWithPermitParams) { + const sig: Signature = splitSignature(signature); + + const permitStruct: BaseTokenWrapper.PermitSignatureStruct = { + deadline, + v: sig.v, + r: sig.r, + s: sig.s, + }; + + const data = this.contractInterface.encodeFunctionData( + 'supplyTokenWithPermit', + [amount, onBehalfOf, referralCode, permitStruct], + ); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: onBehalfOf, + data, + }; + } + + public withdrawToken(amount: string, user: string) { + const data = this.contractInterface.encodeFunctionData('withdrawToken', [ + amount, + user, + ]); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: user, + data, + }; + } + + public withdrawTokenWithPermit( + amount: string, + user: string, + deadline: string, + signature: SignatureLike, + ) { + const sig: Signature = splitSignature(signature); + + const permitStruct: BaseTokenWrapper.PermitSignatureStruct = { + deadline, + v: sig.v, + r: sig.r, + s: sig.s, + }; + + const data = this.contractInterface.encodeFunctionData( + 'withdrawTokenWithPermit', + [amount, user, permitStruct], + ); + + return { + to: this.savingsDaiTokenWrapperAddress, + from: user, + data, + }; + } +} diff --git a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts new file mode 100644 index 00000000..acb0521d --- /dev/null +++ b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts @@ -0,0 +1,523 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { + FunctionFragment, + Result, + EventFragment, +} from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from './common'; + +export declare namespace BaseTokenWrapper { + export type PermitSignatureStruct = { + deadline: BigNumberish; + v: BigNumberish; + r: BytesLike; + s: BytesLike; + }; + + export type PermitSignatureStructOutput = [ + BigNumber, + number, + string, + string, + ] & { deadline: BigNumber; v: number; r: string; s: string }; +} + +export interface SavingsDaiTokenWrapperInterface extends utils.Interface { + functions: { + 'POOL()': FunctionFragment; + 'TOKEN_IN()': FunctionFragment; + 'TOKEN_OUT()': FunctionFragment; + 'getTokenInForTokenOut(uint256)': FunctionFragment; + 'getTokenOutForTokenIn(uint256)': FunctionFragment; + 'owner()': FunctionFragment; + 'renounceOwnership()': FunctionFragment; + 'rescueTokens(address)': FunctionFragment; + 'supplyToken(uint256,address,uint16)': FunctionFragment; + 'supplyTokenWithPermit(uint256,address,uint16,(uint256,uint8,bytes32,bytes32))': FunctionFragment; + 'transferOwnership(address)': FunctionFragment; + 'withdrawToken(uint256,address)': FunctionFragment; + 'withdrawTokenWithPermit(uint256,address,(uint256,uint8,bytes32,bytes32))': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'POOL' + | 'TOKEN_IN' + | 'TOKEN_OUT' + | 'getTokenInForTokenOut' + | 'getTokenOutForTokenIn' + | 'owner' + | 'renounceOwnership' + | 'rescueTokens' + | 'supplyToken' + | 'supplyTokenWithPermit' + | 'transferOwnership' + | 'withdrawToken' + | 'withdrawTokenWithPermit', + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'POOL', values?: undefined): string; + encodeFunctionData(functionFragment: 'TOKEN_IN', values?: undefined): string; + encodeFunctionData(functionFragment: 'TOKEN_OUT', values?: undefined): string; + encodeFunctionData( + functionFragment: 'getTokenInForTokenOut', + values: [BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'getTokenOutForTokenIn', + values: [BigNumberish], + ): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData( + functionFragment: 'renounceOwnership', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'rescueTokens', + values: [string], + ): string; + encodeFunctionData( + functionFragment: 'supplyToken', + values: [BigNumberish, string, BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'supplyTokenWithPermit', + values: [ + BigNumberish, + string, + BigNumberish, + BaseTokenWrapper.PermitSignatureStruct, + ], + ): string; + encodeFunctionData( + functionFragment: 'transferOwnership', + values: [string], + ): string; + encodeFunctionData( + functionFragment: 'withdrawToken', + values: [BigNumberish, string], + ): string; + encodeFunctionData( + functionFragment: 'withdrawTokenWithPermit', + values: [BigNumberish, string, BaseTokenWrapper.PermitSignatureStruct], + ): string; + + decodeFunctionResult(functionFragment: 'POOL', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'TOKEN_IN', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'TOKEN_OUT', data: BytesLike): Result; + decodeFunctionResult( + functionFragment: 'getTokenInForTokenOut', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'getTokenOutForTokenIn', + data: BytesLike, + ): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult( + functionFragment: 'renounceOwnership', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'rescueTokens', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'supplyToken', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'supplyTokenWithPermit', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'transferOwnership', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'withdrawToken', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'withdrawTokenWithPermit', + data: BytesLike, + ): Result; + + events: { + 'OwnershipTransferred(address,address)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; +} + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent< + [string, string], + OwnershipTransferredEventObject +>; + +export type OwnershipTransferredEventFilter = + TypedEventFilter; + +export interface SavingsDaiTokenWrapper extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: SavingsDaiTokenWrapperInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter, + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter, + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + POOL(overrides?: CallOverrides): Promise<[string]>; + + TOKEN_IN(overrides?: CallOverrides): Promise<[string]>; + + TOKEN_OUT(overrides?: CallOverrides): Promise<[string]>; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; + + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + callStatic: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + rescueTokens(token: string, overrides?: CallOverrides): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: CallOverrides, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: CallOverrides, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: CallOverrides, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: CallOverrides, + ): Promise; + }; + + filters: { + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null, + ): OwnershipTransferredEventFilter; + OwnershipTransferred( + previousOwner?: string | null, + newOwner?: string | null, + ): OwnershipTransferredEventFilter; + }; + + estimateGas: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; + + populateTransaction: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: BaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; +} diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts new file mode 100644 index 00000000..7ffee0db --- /dev/null +++ b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts @@ -0,0 +1,389 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import { Signer, utils, Contract, ContractFactory, Overrides } from 'ethers'; +import type { Provider, TransactionRequest } from '@ethersproject/providers'; +import type { + SavingsDaiTokenWrapper, + SavingsDaiTokenWrapperInterface, +} from './SavingsDaiTokenWrapper'; + +const _abi = [ + { + inputs: [ + { + internalType: 'address', + name: 'tokenIn', + type: 'address', + }, + { + internalType: 'address', + name: 'tokenOut', + type: 'address', + }, + { + internalType: 'address', + name: 'pool', + type: 'address', + }, + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'POOL', + outputs: [ + { + internalType: 'contract IPool', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'TOKEN_IN', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'TOKEN_OUT', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'getTokenInForTokenOut', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'getTokenOutForTokenIn', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + ], + name: 'rescueTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + { + internalType: 'uint16', + name: 'referralCode', + type: 'uint16', + }, + ], + name: 'supplyToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + { + internalType: 'uint16', + name: 'referralCode', + type: 'uint16', + }, + { + components: [ + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + internalType: 'struct BaseTokenWrapper.PermitSignature', + name: 'signature', + type: 'tuple', + }, + ], + name: 'supplyTokenWithPermit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + ], + name: 'withdrawToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + components: [ + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + internalType: 'struct BaseTokenWrapper.PermitSignature', + name: 'signature', + type: 'tuple', + }, + ], + name: 'withdrawTokenWithPermit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; + +const _bytecode = + '0x60e06040523480156200001157600080fd5b506040516200174d3803806200174d8339810160408190526200003491620002bb565b600080546001600160a01b031916339081178255604051869286928692869282916000805160206200172d833981519152908290a3506001600160a01b0380851660805283811660a052821660c0526200008e816200018d565b60405163095ea7b360e01b81526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016020604051808303816000875af1158015620000df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000105919062000318565b505060405163095ea7b360e01b81526001600160a01b03878116600483015260001960248301528816935063095ea7b3925060440190506020604051808303816000875af11580156200015c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000182919062000318565b505050505062000343565b6000546001600160a01b03163314620001ed5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b6001600160a01b038116620002545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401620001e4565b600080546040516001600160a01b03808516939216916000805160206200172d83398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620002b657600080fd5b919050565b60008060008060808587031215620002d257600080fd5b620002dd856200029e565b9350620002ed602086016200029e565b9250620002fd604086016200029e565b91506200030d606086016200029e565b905092959194509250565b6000602082840312156200032b57600080fd5b815180151581146200033c57600080fd5b9392505050565b60805160a05160c051611352620003db6000396000818161015f0152818161046301528181610525015281816109c50152610bb001526000818160ed01528181610438015281816104fa0152818161072a015281816107bd0152818161098401528181610b7b01528181610e270152610e9f0152600081816101bd01528181610304015281816108dc0152610c9601526113526000f3fe608060405234801561001057600080fd5b50600436106100ce5760003560e01c80638da5cb5b1161008c578063f00c202a11610066578063f00c202a146101b8578063f2fde38b146101df578063f823b07b146101f2578063fe6568501461021357600080fd5b80638da5cb5b14610181578063be4b177214610192578063e94875ca146101a557600080fd5b8062ae3bf8146100d35780630392ef94146100e85780631461e2161461012c5780634f4663a11461013f578063715018a6146101525780637535d2461461015a575b600080fd5b6100e66100e1366004610eeb565b610226565b005b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6100e661013a366004610f1f565b6102ea565b6100e661014d366004610f73565b6102fa565b6100e66103ad565b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6000546001600160a01b031661010f565b6100e66101a0366004610fc5565b610421565b6100e66101b3366004610ff5565b6104e3565b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6100e66101ed366004610eeb565b610627565b610205610200366004611034565b610711565b604051908152602001610123565b610205610221366004611034565b6107a4565b6000546001600160a01b031633146102595760405162461bcd60e51b81526004016102509061104d565b60405180910390fd5b6102e761026e6000546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156102b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102d69190611082565b6001600160a01b03841691906107f4565b50565b6102f583838361087f565b505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663d505accf333087853561033e604088016020890161109b565b876040013588606001356040518863ffffffff1660e01b815260040161036a97969594939291906110be565b600060405180830381600087803b15801561038457600080fd5b505af1158015610398573d6000803e3d6000fd5b505050506103a784848461087f565b50505050565b6000546001600160a01b031633146103d75760405162461bcd60e51b81526004016102509061104d565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6040516335ea6a7560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906335ea6a75906024016101e060405180830381865afa1580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d191906111d7565b610100015190506102f5838383610a27565b6040516335ea6a7560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906335ea6a75906024016101e060405180830381865afa15801561056f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059391906111d7565b610100015190506001600160a01b03811663d505accf33308786356105be6040890160208a0161109b565b886040013589606001356040518863ffffffff1660e01b81526004016105ea97969594939291906110be565b600060405180830381600087803b15801561060457600080fd5b505af1158015610618573d6000803e3d6000fd5b505050506103a7848483610a27565b6000546001600160a01b031633146106515760405162461bcd60e51b81526004016102509061104d565b6001600160a01b0381166106b65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610250565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60405163266d6a8360e11b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634cdad506906024015b602060405180830381865afa15801561077a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079e9190611082565b92915050565b60405163ef8b30f760e01b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ef8b30f79060240161075d565b60405163a9059cbb60e01b8082526001600160a01b0384166004830152602482018390529060008060448382895af1610831573d6000803e3d6000fd5b5061083b84610cbd565b6103a75760405162461bcd60e51b815260206004820152601560248201527423a83b191d103330b4b632b2103a3930b739b332b960591b6044820152606401610250565b600083116108cf5760405162461bcd60e51b815260206004820152601d60248201527f494e53554646494349454e545f414d4f554e545f544f5f535550504c590000006044820152606401610250565b6109046001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086610d66565b600061090f84610e08565b90506000811161096d5760405162461bcd60e51b815260206004820152602360248201527f494e53554646494349454e545f575241505045445f544f4b454e5f524543454960448201526215915160ea1b6064820152608401610250565b60405163617ba03760e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201839052848116604483015261ffff841660648301527f0000000000000000000000000000000000000000000000000000000000000000169063617ba03790608401600060405180830381600087803b158015610a0957600080fd5b505af1158015610a1d573d6000803e3d6000fd5b5050505050505050565b60008311610a775760405162461bcd60e51b815260206004820152601f60248201527f494e53554646494349454e545f414d4f554e545f544f5f5749544844524157006044820152606401610250565b600019831415610aec576040516370a0823160e01b81523360048201526001600160a01b038216906370a0823190602401602060405180830381865afa158015610ac5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae99190611082565b92505b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038216906323b872dd906064016020604051808303816000875af1158015610b3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6391906112fa565b50604051631a4ca37b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018590523060448301527f000000000000000000000000000000000000000000000000000000000000000016906369328dec906064016020604051808303816000875af1158015610bf9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1d9190611082565b506000610c2984610e79565b905060008111610c895760405162461bcd60e51b815260206004820152602560248201527f494e53554646494349454e545f554e575241505045445f544f4b454e5f524543604482015264115255915160da1b6064820152608401610250565b6103a76001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684836107f4565b6000610ce3565b62461bcd60e51b60005260206004528060245250806044525060646000fd5b3d8015610d225760208114610d5357610d1d7f475076323a206d616c666f726d6564207472616e7366657220726573756c7400601f610cc4565b610d60565b823b610d4a57610d4a7311d41d8c8e881b9bdd08184818dbdb9d1c9858dd60621b6014610cc4565b60019150610d60565b3d6000803e600051151591505b50919050565b6040516323b872dd60e01b8082526001600160a01b038581166004840152841660248301526044820183905290600080606483828a5af1610dab573d6000803e3d6000fd5b50610db585610cbd565b610e015760405162461bcd60e51b815260206004820152601960248201527f475076323a206661696c6564207472616e7366657246726f6d000000000000006044820152606401610250565b5050505050565b604051636e553f6560e01b8152600481018290523060248201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636e553f65906044015b6020604051808303816000875af115801561077a573d6000803e3d6000fd5b604051635d043b2960e11b815260048101829052306024820181905260448201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ba08765290606401610e5a565b6001600160a01b03811681146102e757600080fd5b600060208284031215610efd57600080fd5b8135610f0881610ed6565b9392505050565b61ffff811681146102e757600080fd5b600080600060608486031215610f3457600080fd5b833592506020840135610f4681610ed6565b91506040840135610f5681610f0f565b809150509250925092565b600060808284031215610d6057600080fd5b60008060008060e08587031215610f8957600080fd5b843593506020850135610f9b81610ed6565b92506040850135610fab81610f0f565b9150610fba8660608701610f61565b905092959194509250565b60008060408385031215610fd857600080fd5b823591506020830135610fea81610ed6565b809150509250929050565b600080600060c0848603121561100a57600080fd5b83359250602084013561101c81610ed6565b915061102b8560408601610f61565b90509250925092565b60006020828403121561104657600080fd5b5035919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60006020828403121561109457600080fd5b5051919050565b6000602082840312156110ad57600080fd5b813560ff81168114610f0857600080fd5b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6040516101e0810167ffffffffffffffff8111828210171561113157634e487b7160e01b600052604160045260246000fd5b60405290565b60006020828403121561114957600080fd5b6040516020810181811067ffffffffffffffff8211171561117a57634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff811681146111a757600080fd5b919050565b805164ffffffffff811681146111a757600080fd5b80516111a781610f0f565b80516111a781610ed6565b60006101e082840312156111ea57600080fd5b6111f26110ff565b6111fc8484611137565b815261120a60208401611187565b602082015261121b60408401611187565b604082015261122c60608401611187565b606082015261123d60808401611187565b608082015261124e60a08401611187565b60a082015261125f60c084016111ac565b60c082015261127060e084016111c1565b60e08201526101006112838185016111cc565b908201526101206112958482016111cc565b908201526101406112a78482016111cc565b908201526101606112b98482016111cc565b908201526101806112cb848201611187565b908201526101a06112dd848201611187565b908201526101c06112ef848201611187565b908201529392505050565b60006020828403121561130c57600080fd5b81518015158114610f0857600080fdfea264697066735822122090c962aecc83de52649c62f483ff77097f4cbcf9263327fa78e149da38db8f2364736f6c634300080a00338be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0'; + +type SavingsDaiTokenWrapperConstructorParams = + | [signer?: Signer] + | ConstructorParameters; + +const isSuperArgs = ( + xs: SavingsDaiTokenWrapperConstructorParams, +): xs is ConstructorParameters => xs.length > 1; + +export class SavingsDaiTokenWrapper__factory extends ContractFactory { + constructor(...args: SavingsDaiTokenWrapperConstructorParams) { + if (isSuperArgs(args)) { + super(...args); + } else { + super(_abi, _bytecode, args[0]); + } + } + + override deploy( + tokenIn: string, + tokenOut: string, + pool: string, + owner: string, + overrides?: Overrides & { from?: string }, + ): Promise { + return super.deploy( + tokenIn, + tokenOut, + pool, + owner, + overrides || {}, + ) as Promise; + } + override getDeployTransaction( + tokenIn: string, + tokenOut: string, + pool: string, + owner: string, + overrides?: Overrides & { from?: string }, + ): TransactionRequest { + return super.getDeployTransaction( + tokenIn, + tokenOut, + pool, + owner, + overrides || {}, + ); + } + override attach(address: string): SavingsDaiTokenWrapper { + return super.attach(address) as SavingsDaiTokenWrapper; + } + override connect(signer: Signer): SavingsDaiTokenWrapper__factory { + return super.connect(signer) as SavingsDaiTokenWrapper__factory; + } + + static readonly bytecode = _bytecode; + static readonly abi = _abi; + static createInterface(): SavingsDaiTokenWrapperInterface { + return new utils.Interface(_abi) as SavingsDaiTokenWrapperInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider, + ): SavingsDaiTokenWrapper { + return new Contract( + address, + _abi, + signerOrProvider, + ) as SavingsDaiTokenWrapper; + } +} From e9c9a46b6b38bdc642111127663589a5fc18dcd1 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Thu, 31 Aug 2023 14:56:14 -0500 Subject: [PATCH 12/24] test: sdai wrapper --- packages/contract-helpers/src/index.ts | 1 + .../src/sdai-wrapper/sdai-wrapper.test.ts | 120 ++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index 4d8d94ef..a3bfc24c 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -30,6 +30,7 @@ export * from './v3-migration-contract'; export * from './erc20-2612'; export * from './paraswap-debtSwitch-contract'; export * from './paraswap-withdrawAndSwitchAdapter-contract'; +export * from './sdai-wrapper'; // commons export * from './commons/types'; diff --git a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts index e69de29b..3c378194 100644 --- a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts +++ b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts @@ -0,0 +1,120 @@ +import { providers } from 'ethers'; +import { SavingsDaiTokenWrapperService } from './index'; + +describe('SavingsDaiTokenWrapperService', () => { + const savingsDaiTokenWrapperAddress = + '0x0000000000000000000000000000000000000001'; + const provider = new providers.JsonRpcProvider(); + describe('Initialization', () => { + it('should initialize SavingsDaiTokenWrapperService', () => { + expect( + () => + new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ), + ).not.toThrow(); + }); + it('generates token in for token out preview tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.getTokenInForTokenOut( + '10000000000000000000', + user, + ); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.data).toEqual( + '0xf823b07b0000000000000000000000000000000000000000000000008ac7230489e80000', + ); + }); + it('generates token out for token in preview tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.getTokenOutForTokenIn( + '10000000000000000000', + user, + ); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.data).toEqual( + '0xfe6568500000000000000000000000000000000000000000000000008ac7230489e80000', + ); + }); + it('generates supply token tx', () => { + const onBehalfOf = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.supplyToken( + '10000000000000000000', + onBehalfOf, + '0', + ); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.from).toEqual(onBehalfOf); + expect(tx.data).toEqual( + '0x1461e2160000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000', + ); + }); + it('generates supply with permit tx', () => { + const onBehalfOf = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.supplyTokenWithPermit({ + amount: '10000000000000000000', + onBehalfOf, + referralCode: '0', + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.from).toEqual(onBehalfOf); + expect(tx.data).toEqual( + '0x4f4663a10000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + it('generates withdraw token tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.withdrawToken( + '10000000000000000000', + user, + ); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.from).toEqual(user); + expect(tx.data).toEqual( + '0xbe4b17720000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000000000000000000004', + ); + }); + it('generates withdraw token with permit tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + const tx = savingsDaiTokenWrapperService.withdrawTokenWithPermit( + '10000000000000000000', + user, + '10000', + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + ); + expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + expect(tx.from).toEqual(user); + expect(tx.data).toEqual( + '0xe94875ca0000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + }); +}); From ab88fdfdb45e1980f2bcdf983d3d2acfcf410a3c Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Thu, 31 Aug 2023 16:07:29 -0500 Subject: [PATCH 13/24] fix: sdai token preview --- .../src/sdai-wrapper/index.ts | 41 +++------- .../src/sdai-wrapper/sdai-wrapper.test.ts | 80 ++++++++++++------- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/packages/contract-helpers/src/sdai-wrapper/index.ts b/packages/contract-helpers/src/sdai-wrapper/index.ts index 4a9d2199..ce3151e2 100644 --- a/packages/contract-helpers/src/sdai-wrapper/index.ts +++ b/packages/contract-helpers/src/sdai-wrapper/index.ts @@ -1,5 +1,5 @@ import { Signature, SignatureLike, splitSignature } from '@ethersproject/bytes'; -import { PopulatedTransaction, providers } from 'ethers'; +import { BigNumber, PopulatedTransaction, providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { BaseTokenWrapper, @@ -17,8 +17,8 @@ interface SupplyTokenWithPermitParams { } export interface SavingsDaiTokenWrapperServiceInterface { - getTokenInForTokenOut: (amount: string, user: string) => PopulatedTransaction; - getTokenOutForTokenIn: (amount: string, user: string) => PopulatedTransaction; + getTokenInForTokenOut: (amount: string) => Promise; + getTokenOutForTokenIn: (amount: string) => Promise; supplyToken: ( amount: string, onBehalfOf: string, @@ -47,6 +47,8 @@ export class SavingsDaiTokenWrapperService readonly savingsDaiTokenWrapperAddress: string; readonly contractInterface: SavingsDaiTokenWrapperInterface; + private readonly _contract: SavingsDaiTokenWrapper; + constructor( provider: providers.Provider, savingsDaiTokenWrapperAddress: string, @@ -54,6 +56,10 @@ export class SavingsDaiTokenWrapperService super(provider, SavingsDaiTokenWrapper__factory); this.savingsDaiTokenWrapperAddress = savingsDaiTokenWrapperAddress; this.contractInterface = SavingsDaiTokenWrapper__factory.createInterface(); + this._contract = SavingsDaiTokenWrapper__factory.connect( + savingsDaiTokenWrapperAddress, + provider, + ); this.getTokenInForTokenOut = this.getTokenInForTokenOut.bind(this); this.getTokenOutForTokenIn = this.getTokenOutForTokenIn.bind(this); @@ -63,33 +69,12 @@ export class SavingsDaiTokenWrapperService this.withdrawTokenWithPermit = this.withdrawTokenWithPermit.bind(this); } - public getTokenInForTokenOut( - amount: string, - user: string, - ): PopulatedTransaction { - const data = this.contractInterface.encodeFunctionData( - 'getTokenInForTokenOut', - [amount], - ); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: user, - data, - }; + public async getTokenInForTokenOut(amount: string): Promise { + return this._contract.getTokenInForTokenOut(amount); } - public getTokenOutForTokenIn(amount: string, user: string) { - const data = this.contractInterface.encodeFunctionData( - 'getTokenOutForTokenIn', - [amount], - ); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: user, - data, - }; + public async getTokenOutForTokenIn(amount: string): Promise { + return this._contract.getTokenOutForTokenIn(amount); } public supplyToken(amount: string, onBehalfOf: string, referralCode: string) { diff --git a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts index 3c378194..ca452464 100644 --- a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts +++ b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts @@ -15,36 +15,36 @@ describe('SavingsDaiTokenWrapperService', () => { ), ).not.toThrow(); }); - it('generates token in for token out preview tx', () => { - const user = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.getTokenInForTokenOut( - '10000000000000000000', - user, - ); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.data).toEqual( - '0xf823b07b0000000000000000000000000000000000000000000000008ac7230489e80000', - ); - }); - it('generates token out for token in preview tx', () => { - const user = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.getTokenOutForTokenIn( - '10000000000000000000', - user, - ); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.data).toEqual( - '0xfe6568500000000000000000000000000000000000000000000000008ac7230489e80000', - ); - }); + // it('generates token in for token out preview tx', () => { + // const user = '0x0000000000000000000000000000000000000004'; + // const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + // provider, + // savingsDaiTokenWrapperAddress, + // ); + // const tx = savingsDaiTokenWrapperService.getTokenInForTokenOut( + // '10000000000000000000', + // user, + // ); + // expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + // expect(tx.data).toEqual( + // '0xf823b07b0000000000000000000000000000000000000000000000008ac7230489e80000', + // ); + // }); + // it('generates token out for token in preview tx', () => { + // const user = '0x0000000000000000000000000000000000000004'; + // const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( + // provider, + // savingsDaiTokenWrapperAddress, + // ); + // const tx = savingsDaiTokenWrapperService.getTokenOutForTokenIn( + // '10000000000000000000', + // user, + // ); + // expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); + // expect(tx.data).toEqual( + // '0xfe6568500000000000000000000000000000000000000000000000008ac7230489e80000', + // ); + // }); it('generates supply token tx', () => { const onBehalfOf = '0x0000000000000000000000000000000000000004'; const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( @@ -117,4 +117,24 @@ describe('SavingsDaiTokenWrapperService', () => { ); }); }); + // describe('get token preview', () => { + // it('should not throw for token in', async () => { + // const service = new SavingsDaiTokenWrapperService( + // provider, + // savingsDaiTokenWrapperAddress, + // ); + // await expect( + // service.getTokenInForTokenOut('10000000000000000000'), + // ).resolves.not.toThrow(); + // }); + // it('should not throw for token out', async () => { + // const service = new SavingsDaiTokenWrapperService( + // provider, + // savingsDaiTokenWrapperAddress, + // ); + // await expect( + // service.getTokenOutForTokenIn('10000000000000000000'), + // ).resolves.not.toThrow(); + // }); + // }); }); From 3858435c6c597ee5c1305384287cc31a298fbf79 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Fri, 1 Sep 2023 14:41:14 -0500 Subject: [PATCH 14/24] test: coverage --- .../src/sdai-wrapper/sdai-wrapper.test.ts | 70 ++++++------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts index ca452464..f048a379 100644 --- a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts +++ b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts @@ -15,36 +15,6 @@ describe('SavingsDaiTokenWrapperService', () => { ), ).not.toThrow(); }); - // it('generates token in for token out preview tx', () => { - // const user = '0x0000000000000000000000000000000000000004'; - // const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - // provider, - // savingsDaiTokenWrapperAddress, - // ); - // const tx = savingsDaiTokenWrapperService.getTokenInForTokenOut( - // '10000000000000000000', - // user, - // ); - // expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - // expect(tx.data).toEqual( - // '0xf823b07b0000000000000000000000000000000000000000000000008ac7230489e80000', - // ); - // }); - // it('generates token out for token in preview tx', () => { - // const user = '0x0000000000000000000000000000000000000004'; - // const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - // provider, - // savingsDaiTokenWrapperAddress, - // ); - // const tx = savingsDaiTokenWrapperService.getTokenOutForTokenIn( - // '10000000000000000000', - // user, - // ); - // expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - // expect(tx.data).toEqual( - // '0xfe6568500000000000000000000000000000000000000000000000008ac7230489e80000', - // ); - // }); it('generates supply token tx', () => { const onBehalfOf = '0x0000000000000000000000000000000000000004'; const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( @@ -117,24 +87,24 @@ describe('SavingsDaiTokenWrapperService', () => { ); }); }); - // describe('get token preview', () => { - // it('should not throw for token in', async () => { - // const service = new SavingsDaiTokenWrapperService( - // provider, - // savingsDaiTokenWrapperAddress, - // ); - // await expect( - // service.getTokenInForTokenOut('10000000000000000000'), - // ).resolves.not.toThrow(); - // }); - // it('should not throw for token out', async () => { - // const service = new SavingsDaiTokenWrapperService( - // provider, - // savingsDaiTokenWrapperAddress, - // ); - // await expect( - // service.getTokenOutForTokenIn('10000000000000000000'), - // ).resolves.not.toThrow(); - // }); - // }); + describe('get token preview', () => { + it('should not throw for token in', async () => { + const service = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + await expect( + service.getTokenInForTokenOut('10000000000000000000'), + ).rejects.toThrow(); + }); + it('should not throw for token out', async () => { + const service = new SavingsDaiTokenWrapperService( + provider, + savingsDaiTokenWrapperAddress, + ); + await expect( + service.getTokenOutForTokenIn('10000000000000000000'), + ).rejects.toThrow(); + }); + }); }); From 3eefd8884086b62a62395db7612b64551aaec858 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 25 Oct 2023 09:28:36 -0500 Subject: [PATCH 15/24] feat: updated typings --- .../typechain/SavingsDaiTokenWrapper.d.ts | 86 +++++++++++++++---- .../SavingsDaiTokenWrapper_factory.ts | 50 +++++++++-- 2 files changed, 113 insertions(+), 23 deletions(-) diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts index acb0521d..ef4bad99 100644 --- a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts +++ b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts @@ -25,7 +25,7 @@ import type { OnEvent, } from './common'; -export declare namespace BaseTokenWrapper { +export declare namespace IBaseTokenWrapper { export type PermitSignatureStruct = { deadline: BigNumberish; v: BigNumberish; @@ -50,7 +50,8 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { 'getTokenOutForTokenIn(uint256)': FunctionFragment; 'owner()': FunctionFragment; 'renounceOwnership()': FunctionFragment; - 'rescueTokens(address)': FunctionFragment; + 'rescueETH(address,uint256)': FunctionFragment; + 'rescueTokens(address,address,uint256)': FunctionFragment; 'supplyToken(uint256,address,uint16)': FunctionFragment; 'supplyTokenWithPermit(uint256,address,uint16,(uint256,uint8,bytes32,bytes32))': FunctionFragment; 'transferOwnership(address)': FunctionFragment; @@ -67,6 +68,7 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { | 'getTokenOutForTokenIn' | 'owner' | 'renounceOwnership' + | 'rescueETH' | 'rescueTokens' | 'supplyToken' | 'supplyTokenWithPermit' @@ -91,9 +93,13 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { functionFragment: 'renounceOwnership', values?: undefined, ): string; + encodeFunctionData( + functionFragment: 'rescueETH', + values: [string, BigNumberish], + ): string; encodeFunctionData( functionFragment: 'rescueTokens', - values: [string], + values: [string, string, BigNumberish], ): string; encodeFunctionData( functionFragment: 'supplyToken', @@ -105,7 +111,7 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { BigNumberish, string, BigNumberish, - BaseTokenWrapper.PermitSignatureStruct, + IBaseTokenWrapper.PermitSignatureStruct, ], ): string; encodeFunctionData( @@ -118,7 +124,7 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { ): string; encodeFunctionData( functionFragment: 'withdrawTokenWithPermit', - values: [BigNumberish, string, BaseTokenWrapper.PermitSignatureStruct], + values: [BigNumberish, string, IBaseTokenWrapper.PermitSignatureStruct], ): string; decodeFunctionResult(functionFragment: 'POOL', data: BytesLike): Result; @@ -137,6 +143,7 @@ export interface SavingsDaiTokenWrapperInterface extends utils.Interface { functionFragment: 'renounceOwnership', data: BytesLike, ): Result; + decodeFunctionResult(functionFragment: 'rescueETH', data: BytesLike): Result; decodeFunctionResult( functionFragment: 'rescueTokens', data: BytesLike, @@ -230,8 +237,16 @@ export interface SavingsDaiTokenWrapper extends BaseContract { overrides?: Overrides & { from?: string }, ): Promise; + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + rescueTokens( token: string, + to: string, + amount: BigNumberish, overrides?: Overrides & { from?: string }, ): Promise; @@ -246,7 +261,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, onBehalfOf: string, referralCode: BigNumberish, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; @@ -264,7 +279,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { withdrawTokenWithPermit( amount: BigNumberish, to: string, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; }; @@ -291,8 +306,16 @@ export interface SavingsDaiTokenWrapper extends BaseContract { overrides?: Overrides & { from?: string }, ): Promise; + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + rescueTokens( token: string, + to: string, + amount: BigNumberish, overrides?: Overrides & { from?: string }, ): Promise; @@ -307,7 +330,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, onBehalfOf: string, referralCode: BigNumberish, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; @@ -325,7 +348,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { withdrawTokenWithPermit( amount: BigNumberish, to: string, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; @@ -350,7 +373,18 @@ export interface SavingsDaiTokenWrapper extends BaseContract { renounceOwnership(overrides?: CallOverrides): Promise; - rescueTokens(token: string, overrides?: CallOverrides): Promise; + rescueETH( + to: string, + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; supplyToken( amount: BigNumberish, @@ -363,7 +397,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, onBehalfOf: string, referralCode: BigNumberish, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: CallOverrides, ): Promise; @@ -376,14 +410,14 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, to: string, overrides?: CallOverrides, - ): Promise; + ): Promise; withdrawTokenWithPermit( amount: BigNumberish, to: string, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: CallOverrides, - ): Promise; + ): Promise; }; filters: { @@ -420,8 +454,16 @@ export interface SavingsDaiTokenWrapper extends BaseContract { overrides?: Overrides & { from?: string }, ): Promise; + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + rescueTokens( token: string, + to: string, + amount: BigNumberish, overrides?: Overrides & { from?: string }, ): Promise; @@ -436,7 +478,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, onBehalfOf: string, referralCode: BigNumberish, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; @@ -454,7 +496,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { withdrawTokenWithPermit( amount: BigNumberish, to: string, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; }; @@ -482,8 +524,16 @@ export interface SavingsDaiTokenWrapper extends BaseContract { overrides?: Overrides & { from?: string }, ): Promise; + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + rescueTokens( token: string, + to: string, + amount: BigNumberish, overrides?: Overrides & { from?: string }, ): Promise; @@ -498,7 +548,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { amount: BigNumberish, onBehalfOf: string, referralCode: BigNumberish, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; @@ -516,7 +566,7 @@ export interface SavingsDaiTokenWrapper extends BaseContract { withdrawTokenWithPermit( amount: BigNumberish, to: string, - signature: BaseTokenWrapper.PermitSignatureStruct, + signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: Overrides & { from?: string }, ): Promise; }; diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts index 7ffee0db..5cd12a21 100644 --- a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts +++ b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts @@ -150,6 +150,24 @@ const _abi = [ stateMutability: 'nonpayable', type: 'function', }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'rescueETH', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, { inputs: [ { @@ -157,6 +175,16 @@ const _abi = [ name: 'token', type: 'address', }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, ], name: 'rescueTokens', outputs: [], @@ -226,7 +254,7 @@ const _abi = [ type: 'bytes32', }, ], - internalType: 'struct BaseTokenWrapper.PermitSignature', + internalType: 'struct IBaseTokenWrapper.PermitSignature', name: 'signature', type: 'tuple', }, @@ -263,7 +291,13 @@ const _abi = [ }, ], name: 'withdrawToken', - outputs: [], + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], stateMutability: 'nonpayable', type: 'function', }, @@ -302,20 +336,26 @@ const _abi = [ type: 'bytes32', }, ], - internalType: 'struct BaseTokenWrapper.PermitSignature', + internalType: 'struct IBaseTokenWrapper.PermitSignature', name: 'signature', type: 'tuple', }, ], name: 'withdrawTokenWithPermit', - outputs: [], + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], stateMutability: 'nonpayable', type: 'function', }, ] as const; const _bytecode = - '0x60e06040523480156200001157600080fd5b506040516200174d3803806200174d8339810160408190526200003491620002bb565b600080546001600160a01b031916339081178255604051869286928692869282916000805160206200172d833981519152908290a3506001600160a01b0380851660805283811660a052821660c0526200008e816200018d565b60405163095ea7b360e01b81526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016020604051808303816000875af1158015620000df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000105919062000318565b505060405163095ea7b360e01b81526001600160a01b03878116600483015260001960248301528816935063095ea7b3925060440190506020604051808303816000875af11580156200015c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000182919062000318565b505050505062000343565b6000546001600160a01b03163314620001ed5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b6001600160a01b038116620002545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401620001e4565b600080546040516001600160a01b03808516939216916000805160206200172d83398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620002b657600080fd5b919050565b60008060008060808587031215620002d257600080fd5b620002dd856200029e565b9350620002ed602086016200029e565b9250620002fd604086016200029e565b91506200030d606086016200029e565b905092959194509250565b6000602082840312156200032b57600080fd5b815180151581146200033c57600080fd5b9392505050565b60805160a05160c051611352620003db6000396000818161015f0152818161046301528181610525015281816109c50152610bb001526000818160ed01528181610438015281816104fa0152818161072a015281816107bd0152818161098401528181610b7b01528181610e270152610e9f0152600081816101bd01528181610304015281816108dc0152610c9601526113526000f3fe608060405234801561001057600080fd5b50600436106100ce5760003560e01c80638da5cb5b1161008c578063f00c202a11610066578063f00c202a146101b8578063f2fde38b146101df578063f823b07b146101f2578063fe6568501461021357600080fd5b80638da5cb5b14610181578063be4b177214610192578063e94875ca146101a557600080fd5b8062ae3bf8146100d35780630392ef94146100e85780631461e2161461012c5780634f4663a11461013f578063715018a6146101525780637535d2461461015a575b600080fd5b6100e66100e1366004610eeb565b610226565b005b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6100e661013a366004610f1f565b6102ea565b6100e661014d366004610f73565b6102fa565b6100e66103ad565b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6000546001600160a01b031661010f565b6100e66101a0366004610fc5565b610421565b6100e66101b3366004610ff5565b6104e3565b61010f7f000000000000000000000000000000000000000000000000000000000000000081565b6100e66101ed366004610eeb565b610627565b610205610200366004611034565b610711565b604051908152602001610123565b610205610221366004611034565b6107a4565b6000546001600160a01b031633146102595760405162461bcd60e51b81526004016102509061104d565b60405180910390fd5b6102e761026e6000546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156102b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102d69190611082565b6001600160a01b03841691906107f4565b50565b6102f583838361087f565b505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663d505accf333087853561033e604088016020890161109b565b876040013588606001356040518863ffffffff1660e01b815260040161036a97969594939291906110be565b600060405180830381600087803b15801561038457600080fd5b505af1158015610398573d6000803e3d6000fd5b505050506103a784848461087f565b50505050565b6000546001600160a01b031633146103d75760405162461bcd60e51b81526004016102509061104d565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6040516335ea6a7560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906335ea6a75906024016101e060405180830381865afa1580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d191906111d7565b610100015190506102f5838383610a27565b6040516335ea6a7560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526000917f0000000000000000000000000000000000000000000000000000000000000000909116906335ea6a75906024016101e060405180830381865afa15801561056f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059391906111d7565b610100015190506001600160a01b03811663d505accf33308786356105be6040890160208a0161109b565b886040013589606001356040518863ffffffff1660e01b81526004016105ea97969594939291906110be565b600060405180830381600087803b15801561060457600080fd5b505af1158015610618573d6000803e3d6000fd5b505050506103a7848483610a27565b6000546001600160a01b031633146106515760405162461bcd60e51b81526004016102509061104d565b6001600160a01b0381166106b65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610250565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60405163266d6a8360e11b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634cdad506906024015b602060405180830381865afa15801561077a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061079e9190611082565b92915050565b60405163ef8b30f760e01b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ef8b30f79060240161075d565b60405163a9059cbb60e01b8082526001600160a01b0384166004830152602482018390529060008060448382895af1610831573d6000803e3d6000fd5b5061083b84610cbd565b6103a75760405162461bcd60e51b815260206004820152601560248201527423a83b191d103330b4b632b2103a3930b739b332b960591b6044820152606401610250565b600083116108cf5760405162461bcd60e51b815260206004820152601d60248201527f494e53554646494349454e545f414d4f554e545f544f5f535550504c590000006044820152606401610250565b6109046001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086610d66565b600061090f84610e08565b90506000811161096d5760405162461bcd60e51b815260206004820152602360248201527f494e53554646494349454e545f575241505045445f544f4b454e5f524543454960448201526215915160ea1b6064820152608401610250565b60405163617ba03760e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201839052848116604483015261ffff841660648301527f0000000000000000000000000000000000000000000000000000000000000000169063617ba03790608401600060405180830381600087803b158015610a0957600080fd5b505af1158015610a1d573d6000803e3d6000fd5b5050505050505050565b60008311610a775760405162461bcd60e51b815260206004820152601f60248201527f494e53554646494349454e545f414d4f554e545f544f5f5749544844524157006044820152606401610250565b600019831415610aec576040516370a0823160e01b81523360048201526001600160a01b038216906370a0823190602401602060405180830381865afa158015610ac5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae99190611082565b92505b6040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b038216906323b872dd906064016020604051808303816000875af1158015610b3f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6391906112fa565b50604051631a4ca37b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018590523060448301527f000000000000000000000000000000000000000000000000000000000000000016906369328dec906064016020604051808303816000875af1158015610bf9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1d9190611082565b506000610c2984610e79565b905060008111610c895760405162461bcd60e51b815260206004820152602560248201527f494e53554646494349454e545f554e575241505045445f544f4b454e5f524543604482015264115255915160da1b6064820152608401610250565b6103a76001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684836107f4565b6000610ce3565b62461bcd60e51b60005260206004528060245250806044525060646000fd5b3d8015610d225760208114610d5357610d1d7f475076323a206d616c666f726d6564207472616e7366657220726573756c7400601f610cc4565b610d60565b823b610d4a57610d4a7311d41d8c8e881b9bdd08184818dbdb9d1c9858dd60621b6014610cc4565b60019150610d60565b3d6000803e600051151591505b50919050565b6040516323b872dd60e01b8082526001600160a01b038581166004840152841660248301526044820183905290600080606483828a5af1610dab573d6000803e3d6000fd5b50610db585610cbd565b610e015760405162461bcd60e51b815260206004820152601960248201527f475076323a206661696c6564207472616e7366657246726f6d000000000000006044820152606401610250565b5050505050565b604051636e553f6560e01b8152600481018290523060248201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636e553f65906044015b6020604051808303816000875af115801561077a573d6000803e3d6000fd5b604051635d043b2960e11b815260048101829052306024820181905260448201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ba08765290606401610e5a565b6001600160a01b03811681146102e757600080fd5b600060208284031215610efd57600080fd5b8135610f0881610ed6565b9392505050565b61ffff811681146102e757600080fd5b600080600060608486031215610f3457600080fd5b833592506020840135610f4681610ed6565b91506040840135610f5681610f0f565b809150509250925092565b600060808284031215610d6057600080fd5b60008060008060e08587031215610f8957600080fd5b843593506020850135610f9b81610ed6565b92506040850135610fab81610f0f565b9150610fba8660608701610f61565b905092959194509250565b60008060408385031215610fd857600080fd5b823591506020830135610fea81610ed6565b809150509250929050565b600080600060c0848603121561100a57600080fd5b83359250602084013561101c81610ed6565b915061102b8560408601610f61565b90509250925092565b60006020828403121561104657600080fd5b5035919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60006020828403121561109457600080fd5b5051919050565b6000602082840312156110ad57600080fd5b813560ff81168114610f0857600080fd5b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6040516101e0810167ffffffffffffffff8111828210171561113157634e487b7160e01b600052604160045260246000fd5b60405290565b60006020828403121561114957600080fd5b6040516020810181811067ffffffffffffffff8211171561117a57634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff811681146111a757600080fd5b919050565b805164ffffffffff811681146111a757600080fd5b80516111a781610f0f565b80516111a781610ed6565b60006101e082840312156111ea57600080fd5b6111f26110ff565b6111fc8484611137565b815261120a60208401611187565b602082015261121b60408401611187565b604082015261122c60608401611187565b606082015261123d60808401611187565b608082015261124e60a08401611187565b60a082015261125f60c084016111ac565b60c082015261127060e084016111c1565b60e08201526101006112838185016111cc565b908201526101206112958482016111cc565b908201526101406112a78482016111cc565b908201526101606112b98482016111cc565b908201526101806112cb848201611187565b908201526101a06112dd848201611187565b908201526101c06112ef848201611187565b908201529392505050565b60006020828403121561130c57600080fd5b81518015158114610f0857600080fdfea264697066735822122090c962aecc83de52649c62f483ff77097f4cbcf9263327fa78e149da38db8f2364736f6c634300080a00338be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0'; + '0x60e06040523480156200001157600080fd5b5060405162001a0938038062001a098339810160408190526200003491620002bb565b600080546001600160a01b03191633908117825560405186928692869286928291600080516020620019e9833981519152908290a3506001600160a01b0380851660805283811660a052821660c0526200008e816200018d565b60405163095ea7b360e01b81526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016020604051808303816000875af1158015620000df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000105919062000318565b505060405163095ea7b360e01b81526001600160a01b03878116600483015260001960248301528816935063095ea7b3925060440190506020604051808303816000875af11580156200015c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000182919062000318565b505050505062000343565b6000546001600160a01b03163314620001ed5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b6001600160a01b038116620002545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401620001e4565b600080546040516001600160a01b0380851693921691600080516020620019e983398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620002b657600080fd5b919050565b60008060008060808587031215620002d257600080fd5b620002dd856200029e565b9350620002ed602086016200029e565b9250620002fd604086016200029e565b91506200030d606086016200029e565b905092959194509250565b6000602082840312156200032b57600080fd5b815180151581146200033c57600080fd5b9392505050565b60805160a05160c05161160e620003db6000396000818161017b015281816104b6015281816105be015281816109da0152610d0401526000818160f40152818161048901528181610591015281816107ca0152818161085d0152818161099901528181610ccc01528181610f6a0152610fe20152600081816101fa01528181610355015281816108f10152610dec015261160e6000f3fe608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063be4b17721161008c578063f00c202a11610066578063f00c202a146101f5578063f2fde38b1461021c578063f823b07b1461022f578063fe6568501461024257600080fd5b8063be4b1772146101ae578063cea9d26f146101cf578063e94875ca146101e257600080fd5b80634f4663a1116100c85780634f4663a11461015b578063715018a61461016e5780637535d246146101765780638da5cb5b1461019d57600080fd5b80630392ef94146100ef578063099a04e5146101335780631461e21614610148575b600080fd5b6101167f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6101466101413660046110da565b610255565b005b610146610156366004611116565b610340565b61014661016936600461116a565b61034b565b6101466103fe565b6101167f000000000000000000000000000000000000000000000000000000000000000081565b6000546001600160a01b0316610116565b6101c16101bc3660046111bc565b610472565b60405190815260200161012a565b6101466101dd3660046111ec565b61053c565b6101c16101f036600461122d565b61057a565b6101167f000000000000000000000000000000000000000000000000000000000000000081565b61014661022a36600461126c565b6106c7565b6101c161023d366004611290565b6107b1565b6101c1610250366004611290565b610844565b6000546001600160a01b031633146102885760405162461bcd60e51b815260040161027f906112a9565b60405180910390fd5b604080516000808252602082019092526001600160a01b0384169083906040516102b291906112de565b60006040518083038185875af1925050503d80600081146102ef576040519150601f19603f3d011682016040523d82523d6000602084013e6102f4565b606091505b505090508061033b5760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b604482015260640161027f565b505050565b61033b838383610894565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663d505accf333087853561038f6040880160208901611319565b876040013588606001356040518863ffffffff1660e01b81526004016103bb979695949392919061133c565b600060405180830381600087803b1580156103d557600080fd5b505af11580156103e9573d6000803e3d6000fd5b505050506103f8848484610894565b50505050565b6000546001600160a01b031633146104285760405162461bcd60e51b815260040161027f906112a9565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6040516335ea6a7560e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906335ea6a75906024016101e060405180830381865afa1580156104fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105229190611455565b61010001519050610534848483610a3c565b949350505050565b6000546001600160a01b031633146105665760405162461bcd60e51b815260040161027f906112a9565b61033b6001600160a01b0384168383610e1e565b6040516335ea6a7560e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906335ea6a75906024016101e060405180830381865afa158015610606573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061062a9190611455565b610100015190506001600160a01b03811663d505accf333088873561065560408a0160208b01611319565b89604001358a606001356040518863ffffffff1660e01b8152600401610681979695949392919061133c565b600060405180830381600087803b15801561069b57600080fd5b505af11580156106af573d6000803e3d6000fd5b505050506106be858583610a3c565b95945050505050565b6000546001600160a01b031633146106f15760405162461bcd60e51b815260040161027f906112a9565b6001600160a01b0381166107565760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161027f565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60405163266d6a8360e11b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634cdad506906024015b602060405180830381865afa15801561081a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083e9190611578565b92915050565b60405163ef8b30f760e01b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ef8b30f7906024016107fd565b600083116108e45760405162461bcd60e51b815260206004820152601d60248201527f494e53554646494349454e545f414d4f554e545f544f5f535550504c59000000604482015260640161027f565b6109196001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086610ea9565b600061092484610f4b565b9050600081116109825760405162461bcd60e51b815260206004820152602360248201527f494e53554646494349454e545f575241505045445f544f4b454e5f524543454960448201526215915160ea1b606482015260840161027f565b60405163617ba03760e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201839052848116604483015261ffff841660648301527f0000000000000000000000000000000000000000000000000000000000000000169063617ba03790608401600060405180830381600087803b158015610a1e57600080fd5b505af1158015610a32573d6000803e3d6000fd5b5050505050505050565b6000808411610a8d5760405162461bcd60e51b815260206004820152601f60248201527f494e53554646494349454e545f414d4f554e545f544f5f574954484452415700604482015260640161027f565b6040516370a0823160e01b81523360048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ad4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af89190611578565b9050600019851415610b08578094505b80851115610b585760405162461bcd60e51b815260206004820181905260248201527f494e53554646494349454e545f42414c414e43455f544f5f5749544844524157604482015260640161027f565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015610b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc39190611578565b6040516323b872dd60e01b8152336004820152306024820152604481018890529091506001600160a01b038516906323b872dd906064016020604051808303816000875af1158015610c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3d9190611591565b506040516370a0823160e01b815230600482015260009082906001600160a01b038716906370a0823190602401602060405180830381865afa158015610c87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cab9190611578565b610cb591906115b3565b604051631a4ca37b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018390523060448301529192507f0000000000000000000000000000000000000000000000000000000000000000909116906369328dec906064016020604051808303816000875af1158015610d4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d739190611578565b506000610d7f82610fbc565b905060008111610ddf5760405162461bcd60e51b815260206004820152602560248201527f494e53554646494349454e545f554e575241505045445f544f4b454e5f524543604482015264115255915160da1b606482015260840161027f565b610e136001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168883610e1e565b979650505050505050565b60405163a9059cbb60e01b8082526001600160a01b0384166004830152602482018390529060008060448382895af1610e5b573d6000803e3d6000fd5b50610e6584611019565b6103f85760405162461bcd60e51b815260206004820152601560248201527423a83b191d103330b4b632b2103a3930b739b332b960591b604482015260640161027f565b6040516323b872dd60e01b8082526001600160a01b038581166004840152841660248301526044820183905290600080606483828a5af1610eee573d6000803e3d6000fd5b50610ef885611019565b610f445760405162461bcd60e51b815260206004820152601960248201527f475076323a206661696c6564207472616e7366657246726f6d00000000000000604482015260640161027f565b5050505050565b604051636e553f6560e01b8152600481018290523060248201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636e553f65906044015b6020604051808303816000875af115801561081a573d6000803e3d6000fd5b604051635d043b2960e11b815260048101829052306024820181905260448201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ba08765290606401610f9d565b600061103f565b62461bcd60e51b60005260206004528060245250806044525060646000fd5b3d801561107e57602081146110af576110797f475076323a206d616c666f726d6564207472616e7366657220726573756c7400601f611020565b6110bc565b823b6110a6576110a67311d41d8c8e881b9bdd08184818dbdb9d1c9858dd60621b6014611020565b600191506110bc565b3d6000803e600051151591505b50919050565b6001600160a01b03811681146110d757600080fd5b50565b600080604083850312156110ed57600080fd5b82356110f8816110c2565b946020939093013593505050565b61ffff811681146110d757600080fd5b60008060006060848603121561112b57600080fd5b83359250602084013561113d816110c2565b9150604084013561114d81611106565b809150509250925092565b6000608082840312156110bc57600080fd5b60008060008060e0858703121561118057600080fd5b843593506020850135611192816110c2565b925060408501356111a281611106565b91506111b18660608701611158565b905092959194509250565b600080604083850312156111cf57600080fd5b8235915060208301356111e1816110c2565b809150509250929050565b60008060006060848603121561120157600080fd5b833561120c816110c2565b9250602084013561121c816110c2565b929592945050506040919091013590565b600080600060c0848603121561124257600080fd5b833592506020840135611254816110c2565b91506112638560408601611158565b90509250925092565b60006020828403121561127e57600080fd5b8135611289816110c2565b9392505050565b6000602082840312156112a257600080fd5b5035919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000825160005b818110156112ff57602081860181015185830152016112e5565b8181111561130e576000828501525b509190910192915050565b60006020828403121561132b57600080fd5b813560ff8116811461128957600080fd5b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6040516101e0810167ffffffffffffffff811182821017156113af57634e487b7160e01b600052604160045260246000fd5b60405290565b6000602082840312156113c757600080fd5b6040516020810181811067ffffffffffffffff821117156113f857634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff8116811461142557600080fd5b919050565b805164ffffffffff8116811461142557600080fd5b805161142581611106565b8051611425816110c2565b60006101e0828403121561146857600080fd5b61147061137d565b61147a84846113b5565b815261148860208401611405565b602082015261149960408401611405565b60408201526114aa60608401611405565b60608201526114bb60808401611405565b60808201526114cc60a08401611405565b60a08201526114dd60c0840161142a565b60c08201526114ee60e0840161143f565b60e082015261010061150181850161144a565b9082015261012061151384820161144a565b9082015261014061152584820161144a565b9082015261016061153784820161144a565b90820152610180611549848201611405565b908201526101a061155b848201611405565b908201526101c061156d848201611405565b908201529392505050565b60006020828403121561158a57600080fd5b5051919050565b6000602082840312156115a357600080fd5b8151801515811461128957600080fd5b6000828210156115d357634e487b7160e01b600052601160045260246000fd5b50039056fea26469706673582212205320d4cc032d032dd4cecc8ece4248d6c4ab4f9302229682d954ce7a460baacf64736f6c634300080a00338be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0'; type SavingsDaiTokenWrapperConstructorParams = | [signer?: Signer] From 08ab6cda33917a4478d8985cad171e7b885f4a72 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 25 Oct 2023 09:30:50 -0500 Subject: [PATCH 16/24] fix: compile errors --- packages/contract-helpers/src/sdai-wrapper/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contract-helpers/src/sdai-wrapper/index.ts b/packages/contract-helpers/src/sdai-wrapper/index.ts index ce3151e2..1745b87c 100644 --- a/packages/contract-helpers/src/sdai-wrapper/index.ts +++ b/packages/contract-helpers/src/sdai-wrapper/index.ts @@ -2,7 +2,7 @@ import { Signature, SignatureLike, splitSignature } from '@ethersproject/bytes'; import { BigNumber, PopulatedTransaction, providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { - BaseTokenWrapper, + IBaseTokenWrapper, SavingsDaiTokenWrapper, SavingsDaiTokenWrapperInterface, } from './typechain/SavingsDaiTokenWrapper'; @@ -100,7 +100,7 @@ export class SavingsDaiTokenWrapperService }: SupplyTokenWithPermitParams) { const sig: Signature = splitSignature(signature); - const permitStruct: BaseTokenWrapper.PermitSignatureStruct = { + const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { deadline, v: sig.v, r: sig.r, @@ -140,7 +140,7 @@ export class SavingsDaiTokenWrapperService ) { const sig: Signature = splitSignature(signature); - const permitStruct: BaseTokenWrapper.PermitSignatureStruct = { + const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { deadline, v: sig.v, r: sig.r, From a629bd5e8485a52119407f14f0f1edd8f0e5e41f Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 25 Oct 2023 15:35:22 -0500 Subject: [PATCH 17/24] feat: generic token wrapping service --- .../src/token-wrapper/index.ts | 158 +++++ .../src/token-wrapper/token-wrapper.test.ts | 99 +++ .../token-wrapper/typechain/TokenWrapper.d.ts | 573 ++++++++++++++++++ .../typechain/TokenWrapper_factory.ts | 343 +++++++++++ 4 files changed, 1173 insertions(+) create mode 100644 packages/contract-helpers/src/token-wrapper/index.ts create mode 100644 packages/contract-helpers/src/token-wrapper/token-wrapper.test.ts create mode 100644 packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts create mode 100644 packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts diff --git a/packages/contract-helpers/src/token-wrapper/index.ts b/packages/contract-helpers/src/token-wrapper/index.ts new file mode 100644 index 00000000..ba1d59ef --- /dev/null +++ b/packages/contract-helpers/src/token-wrapper/index.ts @@ -0,0 +1,158 @@ +import { Signature, SignatureLike, splitSignature } from '@ethersproject/bytes'; +import { BigNumber, PopulatedTransaction, providers } from 'ethers'; +import BaseService from '../commons/BaseService'; +import { + BaseTokenWrapper, + BaseTokenWrapperInterface, + IBaseTokenWrapper, +} from './typechain/TokenWrapper'; +import { BaseTokenWrapper__factory } from './typechain/TokenWrapper_factory'; + +interface SupplyTokenWithPermitParams { + amount: string; + onBehalfOf: string; + referralCode: string; + deadline: string; + signature: SignatureLike; +} + +export interface TokenWrapperServiceInterface { + getTokenInForTokenOut: (amount: string) => Promise; + getTokenOutForTokenIn: (amount: string) => Promise; + supplyToken: ( + amount: string, + onBehalfOf: string, + referralCode: string, + ) => PopulatedTransaction; + supplyTokenWithPermit: ({ + amount, + onBehalfOf, + referralCode, + deadline, + signature, + }: SupplyTokenWithPermitParams) => PopulatedTransaction; + withdrawToken: (amount: string, user: string) => PopulatedTransaction; + withdrawTokenWithPermit: ( + amount: string, + user: string, + deadline: string, + signature: SignatureLike, + ) => PopulatedTransaction; +} + +export class TokenWrapperService + extends BaseService + implements TokenWrapperServiceInterface +{ + readonly tokenWrapperAddress: string; + readonly contractInterface: BaseTokenWrapperInterface; + + private readonly _contract: BaseTokenWrapper; + + constructor(provider: providers.Provider, tokenWrapperAddress: string) { + super(provider, BaseTokenWrapper__factory); + this.tokenWrapperAddress = tokenWrapperAddress; + this.contractInterface = BaseTokenWrapper__factory.createInterface(); + this._contract = BaseTokenWrapper__factory.connect( + tokenWrapperAddress, + provider, + ); + + this.getTokenInForTokenOut = this.getTokenInForTokenOut.bind(this); + this.getTokenOutForTokenIn = this.getTokenOutForTokenIn.bind(this); + this.supplyToken = this.supplyToken.bind(this); + this.supplyTokenWithPermit = this.supplyTokenWithPermit.bind(this); + this.withdrawToken = this.withdrawToken.bind(this); + this.withdrawTokenWithPermit = this.withdrawTokenWithPermit.bind(this); + } + + public async getTokenInForTokenOut(amount: string): Promise { + return this._contract.getTokenInForTokenOut(amount); + } + + public async getTokenOutForTokenIn(amount: string): Promise { + return this._contract.getTokenOutForTokenIn(amount); + } + + public supplyToken(amount: string, onBehalfOf: string, referralCode: string) { + const data = this.contractInterface.encodeFunctionData('supplyToken', [ + amount, + onBehalfOf, + referralCode, + ]); + + return { + to: this.tokenWrapperAddress, + from: onBehalfOf, + data, + }; + } + + public supplyTokenWithPermit({ + amount, + onBehalfOf, + referralCode, + deadline, + signature, + }: SupplyTokenWithPermitParams) { + const sig: Signature = splitSignature(signature); + + const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { + deadline, + v: sig.v, + r: sig.r, + s: sig.s, + }; + + const data = this.contractInterface.encodeFunctionData( + 'supplyTokenWithPermit', + [amount, onBehalfOf, referralCode, permitStruct], + ); + + return { + to: this.tokenWrapperAddress, + from: onBehalfOf, + data, + }; + } + + public withdrawToken(amount: string, user: string) { + const data = this.contractInterface.encodeFunctionData('withdrawToken', [ + amount, + user, + ]); + + return { + to: this.tokenWrapperAddress, + from: user, + data, + }; + } + + public withdrawTokenWithPermit( + amount: string, + user: string, + deadline: string, + signature: SignatureLike, + ) { + const sig: Signature = splitSignature(signature); + + const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { + deadline, + v: sig.v, + r: sig.r, + s: sig.s, + }; + + const data = this.contractInterface.encodeFunctionData( + 'withdrawTokenWithPermit', + [amount, user, permitStruct], + ); + + return { + to: this.tokenWrapperAddress, + from: user, + data, + }; + } +} diff --git a/packages/contract-helpers/src/token-wrapper/token-wrapper.test.ts b/packages/contract-helpers/src/token-wrapper/token-wrapper.test.ts new file mode 100644 index 00000000..5a73df95 --- /dev/null +++ b/packages/contract-helpers/src/token-wrapper/token-wrapper.test.ts @@ -0,0 +1,99 @@ +import { providers } from 'ethers'; +import { TokenWrapperService } from './index'; + +describe('SavingsDaiTokenWrapperService', () => { + const tokenWrapperAddress = '0x0000000000000000000000000000000000000001'; + const provider = new providers.JsonRpcProvider(); + describe('Initialization', () => { + it('should initialize SavingsDaiTokenWrapperService', () => { + expect( + () => new TokenWrapperService(provider, tokenWrapperAddress), + ).not.toThrow(); + }); + it('generates supply token tx', () => { + const onBehalfOf = '0x0000000000000000000000000000000000000004'; + const tokenWrapperService = new TokenWrapperService( + provider, + tokenWrapperAddress, + ); + const tx = tokenWrapperService.supplyToken( + '10000000000000000000', + onBehalfOf, + '0', + ); + expect(tx.to).toEqual(tokenWrapperAddress); + expect(tx.from).toEqual(onBehalfOf); + expect(tx.data).toEqual( + '0x1461e2160000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000', + ); + }); + it('generates supply with permit tx', () => { + const onBehalfOf = '0x0000000000000000000000000000000000000004'; + const tokenWrapperService = new TokenWrapperService( + provider, + tokenWrapperAddress, + ); + const tx = tokenWrapperService.supplyTokenWithPermit({ + amount: '10000000000000000000', + onBehalfOf, + referralCode: '0', + deadline: '10000', + signature: + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + }); + expect(tx.to).toEqual(tokenWrapperAddress); + expect(tx.from).toEqual(onBehalfOf); + expect(tx.data).toEqual( + '0x4f4663a10000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + it('generates withdraw token tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const tokenWrapperService = new TokenWrapperService( + provider, + tokenWrapperAddress, + ); + const tx = tokenWrapperService.withdrawToken( + '10000000000000000000', + user, + ); + expect(tx.to).toEqual(tokenWrapperAddress); + expect(tx.from).toEqual(user); + expect(tx.data).toEqual( + '0xbe4b17720000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000000000000000000004', + ); + }); + it('generates withdraw token with permit tx', () => { + const user = '0x0000000000000000000000000000000000000004'; + const tokenWrapperService = new TokenWrapperService( + provider, + tokenWrapperAddress, + ); + const tx = tokenWrapperService.withdrawTokenWithPermit( + '10000000000000000000', + user, + '10000', + '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', + ); + expect(tx.to).toEqual(tokenWrapperAddress); + expect(tx.from).toEqual(user); + expect(tx.data).toEqual( + '0xe94875ca0000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', + ); + }); + }); + describe('get token preview', () => { + it('should not throw for token in', async () => { + const service = new TokenWrapperService(provider, tokenWrapperAddress); + await expect( + service.getTokenInForTokenOut('10000000000000000000'), + ).rejects.toThrow(); + }); + it('should not throw for token out', async () => { + const service = new TokenWrapperService(provider, tokenWrapperAddress); + await expect( + service.getTokenOutForTokenIn('10000000000000000000'), + ).rejects.toThrow(); + }); + }); +}); diff --git a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts new file mode 100644 index 00000000..b5f72bcb --- /dev/null +++ b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts @@ -0,0 +1,573 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { + FunctionFragment, + Result, + EventFragment, +} from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from './common'; + +export declare namespace IBaseTokenWrapper { + export type PermitSignatureStruct = { + deadline: BigNumberish; + v: BigNumberish; + r: BytesLike; + s: BytesLike; + }; + + export type PermitSignatureStructOutput = [ + BigNumber, + number, + string, + string, + ] & { deadline: BigNumber; v: number; r: string; s: string }; +} + +export interface BaseTokenWrapperInterface extends utils.Interface { + functions: { + 'POOL()': FunctionFragment; + 'TOKEN_IN()': FunctionFragment; + 'TOKEN_OUT()': FunctionFragment; + 'getTokenInForTokenOut(uint256)': FunctionFragment; + 'getTokenOutForTokenIn(uint256)': FunctionFragment; + 'owner()': FunctionFragment; + 'renounceOwnership()': FunctionFragment; + 'rescueETH(address,uint256)': FunctionFragment; + 'rescueTokens(address,address,uint256)': FunctionFragment; + 'supplyToken(uint256,address,uint16)': FunctionFragment; + 'supplyTokenWithPermit(uint256,address,uint16,(uint256,uint8,bytes32,bytes32))': FunctionFragment; + 'transferOwnership(address)': FunctionFragment; + 'withdrawToken(uint256,address)': FunctionFragment; + 'withdrawTokenWithPermit(uint256,address,(uint256,uint8,bytes32,bytes32))': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'POOL' + | 'TOKEN_IN' + | 'TOKEN_OUT' + | 'getTokenInForTokenOut' + | 'getTokenOutForTokenIn' + | 'owner' + | 'renounceOwnership' + | 'rescueETH' + | 'rescueTokens' + | 'supplyToken' + | 'supplyTokenWithPermit' + | 'transferOwnership' + | 'withdrawToken' + | 'withdrawTokenWithPermit', + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'POOL', values?: undefined): string; + encodeFunctionData(functionFragment: 'TOKEN_IN', values?: undefined): string; + encodeFunctionData(functionFragment: 'TOKEN_OUT', values?: undefined): string; + encodeFunctionData( + functionFragment: 'getTokenInForTokenOut', + values: [BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'getTokenOutForTokenIn', + values: [BigNumberish], + ): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData( + functionFragment: 'renounceOwnership', + values?: undefined, + ): string; + encodeFunctionData( + functionFragment: 'rescueETH', + values: [string, BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'rescueTokens', + values: [string, string, BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'supplyToken', + values: [BigNumberish, string, BigNumberish], + ): string; + encodeFunctionData( + functionFragment: 'supplyTokenWithPermit', + values: [ + BigNumberish, + string, + BigNumberish, + IBaseTokenWrapper.PermitSignatureStruct, + ], + ): string; + encodeFunctionData( + functionFragment: 'transferOwnership', + values: [string], + ): string; + encodeFunctionData( + functionFragment: 'withdrawToken', + values: [BigNumberish, string], + ): string; + encodeFunctionData( + functionFragment: 'withdrawTokenWithPermit', + values: [BigNumberish, string, IBaseTokenWrapper.PermitSignatureStruct], + ): string; + + decodeFunctionResult(functionFragment: 'POOL', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'TOKEN_IN', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'TOKEN_OUT', data: BytesLike): Result; + decodeFunctionResult( + functionFragment: 'getTokenInForTokenOut', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'getTokenOutForTokenIn', + data: BytesLike, + ): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult( + functionFragment: 'renounceOwnership', + data: BytesLike, + ): Result; + decodeFunctionResult(functionFragment: 'rescueETH', data: BytesLike): Result; + decodeFunctionResult( + functionFragment: 'rescueTokens', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'supplyToken', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'supplyTokenWithPermit', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'transferOwnership', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'withdrawToken', + data: BytesLike, + ): Result; + decodeFunctionResult( + functionFragment: 'withdrawTokenWithPermit', + data: BytesLike, + ): Result; + + events: { + 'OwnershipTransferred(address,address)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; +} + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent< + [string, string], + OwnershipTransferredEventObject +>; + +export type OwnershipTransferredEventFilter = + TypedEventFilter; + +export interface BaseTokenWrapper extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: BaseTokenWrapperInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter, + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter, + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + POOL(overrides?: CallOverrides): Promise<[string]>; + + TOKEN_IN(overrides?: CallOverrides): Promise<[string]>; + + TOKEN_OUT(overrides?: CallOverrides): Promise<[string]>; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber]>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; + + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + callStatic: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + rescueETH( + to: string, + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: CallOverrides, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: CallOverrides, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: CallOverrides, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: CallOverrides, + ): Promise; + }; + + filters: { + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null, + ): OwnershipTransferredEventFilter; + OwnershipTransferred( + previousOwner?: string | null, + newOwner?: string | null, + ): OwnershipTransferredEventFilter; + }; + + estimateGas: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; + + populateTransaction: { + POOL(overrides?: CallOverrides): Promise; + + TOKEN_IN(overrides?: CallOverrides): Promise; + + TOKEN_OUT(overrides?: CallOverrides): Promise; + + getTokenInForTokenOut( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + getTokenOutForTokenIn( + amount: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + owner(overrides?: CallOverrides): Promise; + + renounceOwnership( + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueETH( + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + rescueTokens( + token: string, + to: string, + amount: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyToken( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + overrides?: Overrides & { from?: string }, + ): Promise; + + supplyTokenWithPermit( + amount: BigNumberish, + onBehalfOf: string, + referralCode: BigNumberish, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawToken( + amount: BigNumberish, + to: string, + overrides?: Overrides & { from?: string }, + ): Promise; + + withdrawTokenWithPermit( + amount: BigNumberish, + to: string, + signature: IBaseTokenWrapper.PermitSignatureStruct, + overrides?: Overrides & { from?: string }, + ): Promise; + }; +} diff --git a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts new file mode 100644 index 00000000..ad60a6b8 --- /dev/null +++ b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts @@ -0,0 +1,343 @@ +/* Autogenerated file. Do not edit manually. */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { + BaseTokenWrapper, + BaseTokenWrapperInterface, +} from './TokenWrapper'; + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'POOL', + outputs: [ + { + internalType: 'contract IPool', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'TOKEN_IN', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'TOKEN_OUT', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'getTokenInForTokenOut', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'getTokenOutForTokenIn', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'rescueETH', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'rescueTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + { + internalType: 'uint16', + name: 'referralCode', + type: 'uint16', + }, + ], + name: 'supplyToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'onBehalfOf', + type: 'address', + }, + { + internalType: 'uint16', + name: 'referralCode', + type: 'uint16', + }, + { + components: [ + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + internalType: 'struct IBaseTokenWrapper.PermitSignature', + name: 'signature', + type: 'tuple', + }, + ], + name: 'supplyTokenWithPermit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + ], + name: 'withdrawToken', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + components: [ + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + internalType: 'struct IBaseTokenWrapper.PermitSignature', + name: 'signature', + type: 'tuple', + }, + ], + name: 'withdrawTokenWithPermit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; + +export class BaseTokenWrapper__factory { + static readonly abi = _abi; + static createInterface(): BaseTokenWrapperInterface { + return new utils.Interface(_abi) as BaseTokenWrapperInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider, + ): BaseTokenWrapper { + return new Contract(address, _abi, signerOrProvider) as BaseTokenWrapper; + } +} From 7dfe3445869b56db03f29f7bc516d23c540bc98e Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 25 Oct 2023 15:42:11 -0500 Subject: [PATCH 18/24] fix: export --- packages/contract-helpers/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index a3bfc24c..02edb0c0 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -31,6 +31,7 @@ export * from './erc20-2612'; export * from './paraswap-debtSwitch-contract'; export * from './paraswap-withdrawAndSwitchAdapter-contract'; export * from './sdai-wrapper'; +export * from './token-wrapper'; // commons export * from './commons/types'; From 3c5fc7ba506d4aceaf433900344ace2f391e397b Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Wed, 25 Oct 2023 15:48:50 -0500 Subject: [PATCH 19/24] fix: explicit return types --- packages/contract-helpers/src/token-wrapper/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/contract-helpers/src/token-wrapper/index.ts b/packages/contract-helpers/src/token-wrapper/index.ts index ba1d59ef..5dabc168 100644 --- a/packages/contract-helpers/src/token-wrapper/index.ts +++ b/packages/contract-helpers/src/token-wrapper/index.ts @@ -74,7 +74,11 @@ export class TokenWrapperService return this._contract.getTokenOutForTokenIn(amount); } - public supplyToken(amount: string, onBehalfOf: string, referralCode: string) { + public supplyToken( + amount: string, + onBehalfOf: string, + referralCode: string, + ): PopulatedTransaction { const data = this.contractInterface.encodeFunctionData('supplyToken', [ amount, onBehalfOf, @@ -94,7 +98,7 @@ export class TokenWrapperService referralCode, deadline, signature, - }: SupplyTokenWithPermitParams) { + }: SupplyTokenWithPermitParams): PopulatedTransaction { const sig: Signature = splitSignature(signature); const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { @@ -116,7 +120,7 @@ export class TokenWrapperService }; } - public withdrawToken(amount: string, user: string) { + public withdrawToken(amount: string, user: string): PopulatedTransaction { const data = this.contractInterface.encodeFunctionData('withdrawToken', [ amount, user, @@ -134,7 +138,7 @@ export class TokenWrapperService user: string, deadline: string, signature: SignatureLike, - ) { + ): PopulatedTransaction { const sig: Signature = splitSignature(signature); const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { From c8b03e9731a7d5b362e28af3eba6de7d9ba106ba Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 21 Nov 2023 21:23:00 -0600 Subject: [PATCH 20/24] fix: cleanup --- packages/contract-helpers/src/index.ts | 1 - .../src/sdai-wrapper/index.ts | 161 ----- .../src/sdai-wrapper/sdai-wrapper.test.ts | 110 ---- .../typechain/SavingsDaiTokenWrapper.d.ts | 573 ------------------ .../SavingsDaiTokenWrapper_factory.ts | 429 ------------- 5 files changed, 1274 deletions(-) delete mode 100644 packages/contract-helpers/src/sdai-wrapper/index.ts delete mode 100644 packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts delete mode 100644 packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts delete mode 100644 packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index 02edb0c0..c0198350 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -30,7 +30,6 @@ export * from './v3-migration-contract'; export * from './erc20-2612'; export * from './paraswap-debtSwitch-contract'; export * from './paraswap-withdrawAndSwitchAdapter-contract'; -export * from './sdai-wrapper'; export * from './token-wrapper'; // commons diff --git a/packages/contract-helpers/src/sdai-wrapper/index.ts b/packages/contract-helpers/src/sdai-wrapper/index.ts deleted file mode 100644 index 1745b87c..00000000 --- a/packages/contract-helpers/src/sdai-wrapper/index.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { Signature, SignatureLike, splitSignature } from '@ethersproject/bytes'; -import { BigNumber, PopulatedTransaction, providers } from 'ethers'; -import BaseService from '../commons/BaseService'; -import { - IBaseTokenWrapper, - SavingsDaiTokenWrapper, - SavingsDaiTokenWrapperInterface, -} from './typechain/SavingsDaiTokenWrapper'; -import { SavingsDaiTokenWrapper__factory } from './typechain/SavingsDaiTokenWrapper_factory'; - -interface SupplyTokenWithPermitParams { - amount: string; - onBehalfOf: string; - referralCode: string; - deadline: string; - signature: SignatureLike; -} - -export interface SavingsDaiTokenWrapperServiceInterface { - getTokenInForTokenOut: (amount: string) => Promise; - getTokenOutForTokenIn: (amount: string) => Promise; - supplyToken: ( - amount: string, - onBehalfOf: string, - referralCode: string, - ) => PopulatedTransaction; - supplyTokenWithPermit: ({ - amount, - onBehalfOf, - referralCode, - deadline, - signature, - }: SupplyTokenWithPermitParams) => PopulatedTransaction; - withdrawToken: (amount: string, user: string) => PopulatedTransaction; - withdrawTokenWithPermit: ( - amount: string, - user: string, - deadline: string, - signature: SignatureLike, - ) => PopulatedTransaction; -} - -export class SavingsDaiTokenWrapperService - extends BaseService - implements SavingsDaiTokenWrapperServiceInterface -{ - readonly savingsDaiTokenWrapperAddress: string; - readonly contractInterface: SavingsDaiTokenWrapperInterface; - - private readonly _contract: SavingsDaiTokenWrapper; - - constructor( - provider: providers.Provider, - savingsDaiTokenWrapperAddress: string, - ) { - super(provider, SavingsDaiTokenWrapper__factory); - this.savingsDaiTokenWrapperAddress = savingsDaiTokenWrapperAddress; - this.contractInterface = SavingsDaiTokenWrapper__factory.createInterface(); - this._contract = SavingsDaiTokenWrapper__factory.connect( - savingsDaiTokenWrapperAddress, - provider, - ); - - this.getTokenInForTokenOut = this.getTokenInForTokenOut.bind(this); - this.getTokenOutForTokenIn = this.getTokenOutForTokenIn.bind(this); - this.supplyToken = this.supplyToken.bind(this); - this.supplyTokenWithPermit = this.supplyTokenWithPermit.bind(this); - this.withdrawToken = this.withdrawToken.bind(this); - this.withdrawTokenWithPermit = this.withdrawTokenWithPermit.bind(this); - } - - public async getTokenInForTokenOut(amount: string): Promise { - return this._contract.getTokenInForTokenOut(amount); - } - - public async getTokenOutForTokenIn(amount: string): Promise { - return this._contract.getTokenOutForTokenIn(amount); - } - - public supplyToken(amount: string, onBehalfOf: string, referralCode: string) { - const data = this.contractInterface.encodeFunctionData('supplyToken', [ - amount, - onBehalfOf, - referralCode, - ]); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: onBehalfOf, - data, - }; - } - - public supplyTokenWithPermit({ - amount, - onBehalfOf, - referralCode, - deadline, - signature, - }: SupplyTokenWithPermitParams) { - const sig: Signature = splitSignature(signature); - - const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { - deadline, - v: sig.v, - r: sig.r, - s: sig.s, - }; - - const data = this.contractInterface.encodeFunctionData( - 'supplyTokenWithPermit', - [amount, onBehalfOf, referralCode, permitStruct], - ); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: onBehalfOf, - data, - }; - } - - public withdrawToken(amount: string, user: string) { - const data = this.contractInterface.encodeFunctionData('withdrawToken', [ - amount, - user, - ]); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: user, - data, - }; - } - - public withdrawTokenWithPermit( - amount: string, - user: string, - deadline: string, - signature: SignatureLike, - ) { - const sig: Signature = splitSignature(signature); - - const permitStruct: IBaseTokenWrapper.PermitSignatureStruct = { - deadline, - v: sig.v, - r: sig.r, - s: sig.s, - }; - - const data = this.contractInterface.encodeFunctionData( - 'withdrawTokenWithPermit', - [amount, user, permitStruct], - ); - - return { - to: this.savingsDaiTokenWrapperAddress, - from: user, - data, - }; - } -} diff --git a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts b/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts deleted file mode 100644 index f048a379..00000000 --- a/packages/contract-helpers/src/sdai-wrapper/sdai-wrapper.test.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { providers } from 'ethers'; -import { SavingsDaiTokenWrapperService } from './index'; - -describe('SavingsDaiTokenWrapperService', () => { - const savingsDaiTokenWrapperAddress = - '0x0000000000000000000000000000000000000001'; - const provider = new providers.JsonRpcProvider(); - describe('Initialization', () => { - it('should initialize SavingsDaiTokenWrapperService', () => { - expect( - () => - new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ), - ).not.toThrow(); - }); - it('generates supply token tx', () => { - const onBehalfOf = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.supplyToken( - '10000000000000000000', - onBehalfOf, - '0', - ); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.from).toEqual(onBehalfOf); - expect(tx.data).toEqual( - '0x1461e2160000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000', - ); - }); - it('generates supply with permit tx', () => { - const onBehalfOf = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.supplyTokenWithPermit({ - amount: '10000000000000000000', - onBehalfOf, - referralCode: '0', - deadline: '10000', - signature: - '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', - }); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.from).toEqual(onBehalfOf); - expect(tx.data).toEqual( - '0x4f4663a10000000000000000000000000000000000000000000000008ac7230489e80000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', - ); - }); - it('generates withdraw token tx', () => { - const user = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.withdrawToken( - '10000000000000000000', - user, - ); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.from).toEqual(user); - expect(tx.data).toEqual( - '0xbe4b17720000000000000000000000000000000000000000000000008ac7230489e800000000000000000000000000000000000000000000000000000000000000000004', - ); - }); - it('generates withdraw token with permit tx', () => { - const user = '0x0000000000000000000000000000000000000004'; - const savingsDaiTokenWrapperService = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - const tx = savingsDaiTokenWrapperService.withdrawTokenWithPermit( - '10000000000000000000', - user, - '10000', - '0x532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb41c', - ); - expect(tx.to).toEqual(savingsDaiTokenWrapperAddress); - expect(tx.from).toEqual(user); - expect(tx.data).toEqual( - '0xe94875ca0000000000000000000000000000000000000000000000008ac7230489e8000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000001c532f8df4e2502bd869fb35e9301156f9b307380afdcc25cfbc87b2e939f16f7e47c326dc26eb918d327358797ee67ad7415d871ef7eaf0d4f6352d3ad021fbb4', - ); - }); - }); - describe('get token preview', () => { - it('should not throw for token in', async () => { - const service = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - await expect( - service.getTokenInForTokenOut('10000000000000000000'), - ).rejects.toThrow(); - }); - it('should not throw for token out', async () => { - const service = new SavingsDaiTokenWrapperService( - provider, - savingsDaiTokenWrapperAddress, - ); - await expect( - service.getTokenOutForTokenIn('10000000000000000000'), - ).rejects.toThrow(); - }); - }); -}); diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts deleted file mode 100644 index ef4bad99..00000000 --- a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper.d.ts +++ /dev/null @@ -1,573 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* eslint-disable */ -import type { - BaseContract, - BigNumber, - BigNumberish, - BytesLike, - CallOverrides, - ContractTransaction, - Overrides, - PopulatedTransaction, - Signer, - utils, -} from 'ethers'; -import type { - FunctionFragment, - Result, - EventFragment, -} from '@ethersproject/abi'; -import type { Listener, Provider } from '@ethersproject/providers'; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from './common'; - -export declare namespace IBaseTokenWrapper { - export type PermitSignatureStruct = { - deadline: BigNumberish; - v: BigNumberish; - r: BytesLike; - s: BytesLike; - }; - - export type PermitSignatureStructOutput = [ - BigNumber, - number, - string, - string, - ] & { deadline: BigNumber; v: number; r: string; s: string }; -} - -export interface SavingsDaiTokenWrapperInterface extends utils.Interface { - functions: { - 'POOL()': FunctionFragment; - 'TOKEN_IN()': FunctionFragment; - 'TOKEN_OUT()': FunctionFragment; - 'getTokenInForTokenOut(uint256)': FunctionFragment; - 'getTokenOutForTokenIn(uint256)': FunctionFragment; - 'owner()': FunctionFragment; - 'renounceOwnership()': FunctionFragment; - 'rescueETH(address,uint256)': FunctionFragment; - 'rescueTokens(address,address,uint256)': FunctionFragment; - 'supplyToken(uint256,address,uint16)': FunctionFragment; - 'supplyTokenWithPermit(uint256,address,uint16,(uint256,uint8,bytes32,bytes32))': FunctionFragment; - 'transferOwnership(address)': FunctionFragment; - 'withdrawToken(uint256,address)': FunctionFragment; - 'withdrawTokenWithPermit(uint256,address,(uint256,uint8,bytes32,bytes32))': FunctionFragment; - }; - - getFunction( - nameOrSignatureOrTopic: - | 'POOL' - | 'TOKEN_IN' - | 'TOKEN_OUT' - | 'getTokenInForTokenOut' - | 'getTokenOutForTokenIn' - | 'owner' - | 'renounceOwnership' - | 'rescueETH' - | 'rescueTokens' - | 'supplyToken' - | 'supplyTokenWithPermit' - | 'transferOwnership' - | 'withdrawToken' - | 'withdrawTokenWithPermit', - ): FunctionFragment; - - encodeFunctionData(functionFragment: 'POOL', values?: undefined): string; - encodeFunctionData(functionFragment: 'TOKEN_IN', values?: undefined): string; - encodeFunctionData(functionFragment: 'TOKEN_OUT', values?: undefined): string; - encodeFunctionData( - functionFragment: 'getTokenInForTokenOut', - values: [BigNumberish], - ): string; - encodeFunctionData( - functionFragment: 'getTokenOutForTokenIn', - values: [BigNumberish], - ): string; - encodeFunctionData(functionFragment: 'owner', values?: undefined): string; - encodeFunctionData( - functionFragment: 'renounceOwnership', - values?: undefined, - ): string; - encodeFunctionData( - functionFragment: 'rescueETH', - values: [string, BigNumberish], - ): string; - encodeFunctionData( - functionFragment: 'rescueTokens', - values: [string, string, BigNumberish], - ): string; - encodeFunctionData( - functionFragment: 'supplyToken', - values: [BigNumberish, string, BigNumberish], - ): string; - encodeFunctionData( - functionFragment: 'supplyTokenWithPermit', - values: [ - BigNumberish, - string, - BigNumberish, - IBaseTokenWrapper.PermitSignatureStruct, - ], - ): string; - encodeFunctionData( - functionFragment: 'transferOwnership', - values: [string], - ): string; - encodeFunctionData( - functionFragment: 'withdrawToken', - values: [BigNumberish, string], - ): string; - encodeFunctionData( - functionFragment: 'withdrawTokenWithPermit', - values: [BigNumberish, string, IBaseTokenWrapper.PermitSignatureStruct], - ): string; - - decodeFunctionResult(functionFragment: 'POOL', data: BytesLike): Result; - decodeFunctionResult(functionFragment: 'TOKEN_IN', data: BytesLike): Result; - decodeFunctionResult(functionFragment: 'TOKEN_OUT', data: BytesLike): Result; - decodeFunctionResult( - functionFragment: 'getTokenInForTokenOut', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'getTokenOutForTokenIn', - data: BytesLike, - ): Result; - decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; - decodeFunctionResult( - functionFragment: 'renounceOwnership', - data: BytesLike, - ): Result; - decodeFunctionResult(functionFragment: 'rescueETH', data: BytesLike): Result; - decodeFunctionResult( - functionFragment: 'rescueTokens', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'supplyToken', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'supplyTokenWithPermit', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'transferOwnership', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'withdrawToken', - data: BytesLike, - ): Result; - decodeFunctionResult( - functionFragment: 'withdrawTokenWithPermit', - data: BytesLike, - ): Result; - - events: { - 'OwnershipTransferred(address,address)': EventFragment; - }; - - getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; -} - -export interface OwnershipTransferredEventObject { - previousOwner: string; - newOwner: string; -} -export type OwnershipTransferredEvent = TypedEvent< - [string, string], - OwnershipTransferredEventObject ->; - -export type OwnershipTransferredEventFilter = - TypedEventFilter; - -export interface SavingsDaiTokenWrapper extends BaseContract { - connect(signerOrProvider: Signer | Provider | string): this; - attach(addressOrName: string): this; - deployed(): Promise; - - interface: SavingsDaiTokenWrapperInterface; - - queryFilter( - event: TypedEventFilter, - fromBlockOrBlockhash?: string | number | undefined, - toBlock?: string | number | undefined, - ): Promise>; - - listeners( - eventFilter?: TypedEventFilter, - ): Array>; - listeners(eventName?: string): Array; - removeAllListeners( - eventFilter: TypedEventFilter, - ): this; - removeAllListeners(eventName?: string): this; - off: OnEvent; - on: OnEvent; - once: OnEvent; - removeListener: OnEvent; - - functions: { - POOL(overrides?: CallOverrides): Promise<[string]>; - - TOKEN_IN(overrides?: CallOverrides): Promise<[string]>; - - TOKEN_OUT(overrides?: CallOverrides): Promise<[string]>; - - getTokenInForTokenOut( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise<[BigNumber]>; - - getTokenOutForTokenIn( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise<[BigNumber]>; - - owner(overrides?: CallOverrides): Promise<[string]>; - - renounceOwnership( - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueETH( - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueTokens( - token: string, - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyToken( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyTokenWithPermit( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - - transferOwnership( - newOwner: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawToken( - amount: BigNumberish, - to: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawTokenWithPermit( - amount: BigNumberish, - to: string, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - }; - - POOL(overrides?: CallOverrides): Promise; - - TOKEN_IN(overrides?: CallOverrides): Promise; - - TOKEN_OUT(overrides?: CallOverrides): Promise; - - getTokenInForTokenOut( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - getTokenOutForTokenIn( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - owner(overrides?: CallOverrides): Promise; - - renounceOwnership( - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueETH( - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueTokens( - token: string, - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyToken( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyTokenWithPermit( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - - transferOwnership( - newOwner: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawToken( - amount: BigNumberish, - to: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawTokenWithPermit( - amount: BigNumberish, - to: string, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - - callStatic: { - POOL(overrides?: CallOverrides): Promise; - - TOKEN_IN(overrides?: CallOverrides): Promise; - - TOKEN_OUT(overrides?: CallOverrides): Promise; - - getTokenInForTokenOut( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - getTokenOutForTokenIn( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - owner(overrides?: CallOverrides): Promise; - - renounceOwnership(overrides?: CallOverrides): Promise; - - rescueETH( - to: string, - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - rescueTokens( - token: string, - to: string, - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - supplyToken( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - supplyTokenWithPermit( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: CallOverrides, - ): Promise; - - transferOwnership( - newOwner: string, - overrides?: CallOverrides, - ): Promise; - - withdrawToken( - amount: BigNumberish, - to: string, - overrides?: CallOverrides, - ): Promise; - - withdrawTokenWithPermit( - amount: BigNumberish, - to: string, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: CallOverrides, - ): Promise; - }; - - filters: { - 'OwnershipTransferred(address,address)'( - previousOwner?: string | null, - newOwner?: string | null, - ): OwnershipTransferredEventFilter; - OwnershipTransferred( - previousOwner?: string | null, - newOwner?: string | null, - ): OwnershipTransferredEventFilter; - }; - - estimateGas: { - POOL(overrides?: CallOverrides): Promise; - - TOKEN_IN(overrides?: CallOverrides): Promise; - - TOKEN_OUT(overrides?: CallOverrides): Promise; - - getTokenInForTokenOut( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - getTokenOutForTokenIn( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - owner(overrides?: CallOverrides): Promise; - - renounceOwnership( - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueETH( - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueTokens( - token: string, - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyToken( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyTokenWithPermit( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - - transferOwnership( - newOwner: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawToken( - amount: BigNumberish, - to: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawTokenWithPermit( - amount: BigNumberish, - to: string, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - }; - - populateTransaction: { - POOL(overrides?: CallOverrides): Promise; - - TOKEN_IN(overrides?: CallOverrides): Promise; - - TOKEN_OUT(overrides?: CallOverrides): Promise; - - getTokenInForTokenOut( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - getTokenOutForTokenIn( - amount: BigNumberish, - overrides?: CallOverrides, - ): Promise; - - owner(overrides?: CallOverrides): Promise; - - renounceOwnership( - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueETH( - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - rescueTokens( - token: string, - to: string, - amount: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyToken( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - overrides?: Overrides & { from?: string }, - ): Promise; - - supplyTokenWithPermit( - amount: BigNumberish, - onBehalfOf: string, - referralCode: BigNumberish, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - - transferOwnership( - newOwner: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawToken( - amount: BigNumberish, - to: string, - overrides?: Overrides & { from?: string }, - ): Promise; - - withdrawTokenWithPermit( - amount: BigNumberish, - to: string, - signature: IBaseTokenWrapper.PermitSignatureStruct, - overrides?: Overrides & { from?: string }, - ): Promise; - }; -} diff --git a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts b/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts deleted file mode 100644 index 5cd12a21..00000000 --- a/packages/contract-helpers/src/sdai-wrapper/typechain/SavingsDaiTokenWrapper_factory.ts +++ /dev/null @@ -1,429 +0,0 @@ -/* Autogenerated file. Do not edit manually. */ -/* eslint-disable */ -import { Signer, utils, Contract, ContractFactory, Overrides } from 'ethers'; -import type { Provider, TransactionRequest } from '@ethersproject/providers'; -import type { - SavingsDaiTokenWrapper, - SavingsDaiTokenWrapperInterface, -} from './SavingsDaiTokenWrapper'; - -const _abi = [ - { - inputs: [ - { - internalType: 'address', - name: 'tokenIn', - type: 'address', - }, - { - internalType: 'address', - name: 'tokenOut', - type: 'address', - }, - { - internalType: 'address', - name: 'pool', - type: 'address', - }, - { - internalType: 'address', - name: 'owner', - type: 'address', - }, - ], - stateMutability: 'nonpayable', - type: 'constructor', - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: 'address', - name: 'previousOwner', - type: 'address', - }, - { - indexed: true, - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'OwnershipTransferred', - type: 'event', - }, - { - inputs: [], - name: 'POOL', - outputs: [ - { - internalType: 'contract IPool', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'TOKEN_IN', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'TOKEN_OUT', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'getTokenInForTokenOut', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'getTokenOutForTokenIn', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'owner', - outputs: [ - { - internalType: 'address', - name: '', - type: 'address', - }, - ], - stateMutability: 'view', - type: 'function', - }, - { - inputs: [], - name: 'renounceOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'to', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'rescueETH', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'contract IERC20', - name: 'token', - type: 'address', - }, - { - internalType: 'address', - name: 'to', - type: 'address', - }, - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - ], - name: 'rescueTokens', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - { - internalType: 'address', - name: 'onBehalfOf', - type: 'address', - }, - { - internalType: 'uint16', - name: 'referralCode', - type: 'uint16', - }, - ], - name: 'supplyToken', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - { - internalType: 'address', - name: 'onBehalfOf', - type: 'address', - }, - { - internalType: 'uint16', - name: 'referralCode', - type: 'uint16', - }, - { - components: [ - { - internalType: 'uint256', - name: 'deadline', - type: 'uint256', - }, - { - internalType: 'uint8', - name: 'v', - type: 'uint8', - }, - { - internalType: 'bytes32', - name: 'r', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 's', - type: 'bytes32', - }, - ], - internalType: 'struct IBaseTokenWrapper.PermitSignature', - name: 'signature', - type: 'tuple', - }, - ], - name: 'supplyTokenWithPermit', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'address', - name: 'newOwner', - type: 'address', - }, - ], - name: 'transferOwnership', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - { - internalType: 'address', - name: 'to', - type: 'address', - }, - ], - name: 'withdrawToken', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, - { - inputs: [ - { - internalType: 'uint256', - name: 'amount', - type: 'uint256', - }, - { - internalType: 'address', - name: 'to', - type: 'address', - }, - { - components: [ - { - internalType: 'uint256', - name: 'deadline', - type: 'uint256', - }, - { - internalType: 'uint8', - name: 'v', - type: 'uint8', - }, - { - internalType: 'bytes32', - name: 'r', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: 's', - type: 'bytes32', - }, - ], - internalType: 'struct IBaseTokenWrapper.PermitSignature', - name: 'signature', - type: 'tuple', - }, - ], - name: 'withdrawTokenWithPermit', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'nonpayable', - type: 'function', - }, -] as const; - -const _bytecode = - '0x60e06040523480156200001157600080fd5b5060405162001a0938038062001a098339810160408190526200003491620002bb565b600080546001600160a01b03191633908117825560405186928692869286928291600080516020620019e9833981519152908290a3506001600160a01b0380851660805283811660a052821660c0526200008e816200018d565b60405163095ea7b360e01b81526001600160a01b038381166004830152600019602483015284169063095ea7b3906044016020604051808303816000875af1158015620000df573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000105919062000318565b505060405163095ea7b360e01b81526001600160a01b03878116600483015260001960248301528816935063095ea7b3925060440190506020604051808303816000875af11580156200015c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000182919062000318565b505050505062000343565b6000546001600160a01b03163314620001ed5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b6001600160a01b038116620002545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401620001e4565b600080546040516001600160a01b0380851693921691600080516020620019e983398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620002b657600080fd5b919050565b60008060008060808587031215620002d257600080fd5b620002dd856200029e565b9350620002ed602086016200029e565b9250620002fd604086016200029e565b91506200030d606086016200029e565b905092959194509250565b6000602082840312156200032b57600080fd5b815180151581146200033c57600080fd5b9392505050565b60805160a05160c05161160e620003db6000396000818161017b015281816104b6015281816105be015281816109da0152610d0401526000818160f40152818161048901528181610591015281816107ca0152818161085d0152818161099901528181610ccc01528181610f6a0152610fe20152600081816101fa01528181610355015281816108f10152610dec015261160e6000f3fe608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063be4b17721161008c578063f00c202a11610066578063f00c202a146101f5578063f2fde38b1461021c578063f823b07b1461022f578063fe6568501461024257600080fd5b8063be4b1772146101ae578063cea9d26f146101cf578063e94875ca146101e257600080fd5b80634f4663a1116100c85780634f4663a11461015b578063715018a61461016e5780637535d246146101765780638da5cb5b1461019d57600080fd5b80630392ef94146100ef578063099a04e5146101335780631461e21614610148575b600080fd5b6101167f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6101466101413660046110da565b610255565b005b610146610156366004611116565b610340565b61014661016936600461116a565b61034b565b6101466103fe565b6101167f000000000000000000000000000000000000000000000000000000000000000081565b6000546001600160a01b0316610116565b6101c16101bc3660046111bc565b610472565b60405190815260200161012a565b6101466101dd3660046111ec565b61053c565b6101c16101f036600461122d565b61057a565b6101167f000000000000000000000000000000000000000000000000000000000000000081565b61014661022a36600461126c565b6106c7565b6101c161023d366004611290565b6107b1565b6101c1610250366004611290565b610844565b6000546001600160a01b031633146102885760405162461bcd60e51b815260040161027f906112a9565b60405180910390fd5b604080516000808252602082019092526001600160a01b0384169083906040516102b291906112de565b60006040518083038185875af1925050503d80600081146102ef576040519150601f19603f3d011682016040523d82523d6000602084013e6102f4565b606091505b505090508061033b5760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b604482015260640161027f565b505050565b61033b838383610894565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663d505accf333087853561038f6040880160208901611319565b876040013588606001356040518863ffffffff1660e01b81526004016103bb979695949392919061133c565b600060405180830381600087803b1580156103d557600080fd5b505af11580156103e9573d6000803e3d6000fd5b505050506103f8848484610894565b50505050565b6000546001600160a01b031633146104285760405162461bcd60e51b815260040161027f906112a9565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6040516335ea6a7560e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906335ea6a75906024016101e060405180830381865afa1580156104fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105229190611455565b61010001519050610534848483610a3c565b949350505050565b6000546001600160a01b031633146105665760405162461bcd60e51b815260040161027f906112a9565b61033b6001600160a01b0384168383610e1e565b6040516335ea6a7560e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009182917f000000000000000000000000000000000000000000000000000000000000000016906335ea6a75906024016101e060405180830381865afa158015610606573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061062a9190611455565b610100015190506001600160a01b03811663d505accf333088873561065560408a0160208b01611319565b89604001358a606001356040518863ffffffff1660e01b8152600401610681979695949392919061133c565b600060405180830381600087803b15801561069b57600080fd5b505af11580156106af573d6000803e3d6000fd5b505050506106be858583610a3c565b95945050505050565b6000546001600160a01b031633146106f15760405162461bcd60e51b815260040161027f906112a9565b6001600160a01b0381166107565760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161027f565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60405163266d6a8360e11b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634cdad506906024015b602060405180830381865afa15801561081a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061083e9190611578565b92915050565b60405163ef8b30f760e01b8152600481018290526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ef8b30f7906024016107fd565b600083116108e45760405162461bcd60e51b815260206004820152601d60248201527f494e53554646494349454e545f414d4f554e545f544f5f535550504c59000000604482015260640161027f565b6109196001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086610ea9565b600061092484610f4b565b9050600081116109825760405162461bcd60e51b815260206004820152602360248201527f494e53554646494349454e545f575241505045445f544f4b454e5f524543454960448201526215915160ea1b606482015260840161027f565b60405163617ba03760e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260248201839052848116604483015261ffff841660648301527f0000000000000000000000000000000000000000000000000000000000000000169063617ba03790608401600060405180830381600087803b158015610a1e57600080fd5b505af1158015610a32573d6000803e3d6000fd5b5050505050505050565b6000808411610a8d5760405162461bcd60e51b815260206004820152601f60248201527f494e53554646494349454e545f414d4f554e545f544f5f574954484452415700604482015260640161027f565b6040516370a0823160e01b81523360048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610ad4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610af89190611578565b9050600019851415610b08578094505b80851115610b585760405162461bcd60e51b815260206004820181905260248201527f494e53554646494349454e545f42414c414e43455f544f5f5749544844524157604482015260640161027f565b6040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015610b9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc39190611578565b6040516323b872dd60e01b8152336004820152306024820152604481018890529091506001600160a01b038516906323b872dd906064016020604051808303816000875af1158015610c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3d9190611591565b506040516370a0823160e01b815230600482015260009082906001600160a01b038716906370a0823190602401602060405180830381865afa158015610c87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cab9190611578565b610cb591906115b3565b604051631a4ca37b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018390523060448301529192507f0000000000000000000000000000000000000000000000000000000000000000909116906369328dec906064016020604051808303816000875af1158015610d4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d739190611578565b506000610d7f82610fbc565b905060008111610ddf5760405162461bcd60e51b815260206004820152602560248201527f494e53554646494349454e545f554e575241505045445f544f4b454e5f524543604482015264115255915160da1b606482015260840161027f565b610e136001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168883610e1e565b979650505050505050565b60405163a9059cbb60e01b8082526001600160a01b0384166004830152602482018390529060008060448382895af1610e5b573d6000803e3d6000fd5b50610e6584611019565b6103f85760405162461bcd60e51b815260206004820152601560248201527423a83b191d103330b4b632b2103a3930b739b332b960591b604482015260640161027f565b6040516323b872dd60e01b8082526001600160a01b038581166004840152841660248301526044820183905290600080606483828a5af1610eee573d6000803e3d6000fd5b50610ef885611019565b610f445760405162461bcd60e51b815260206004820152601960248201527f475076323a206661696c6564207472616e7366657246726f6d00000000000000604482015260640161027f565b5050505050565b604051636e553f6560e01b8152600481018290523060248201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636e553f65906044015b6020604051808303816000875af115801561081a573d6000803e3d6000fd5b604051635d043b2960e11b815260048101829052306024820181905260448201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ba08765290606401610f9d565b600061103f565b62461bcd60e51b60005260206004528060245250806044525060646000fd5b3d801561107e57602081146110af576110797f475076323a206d616c666f726d6564207472616e7366657220726573756c7400601f611020565b6110bc565b823b6110a6576110a67311d41d8c8e881b9bdd08184818dbdb9d1c9858dd60621b6014611020565b600191506110bc565b3d6000803e600051151591505b50919050565b6001600160a01b03811681146110d757600080fd5b50565b600080604083850312156110ed57600080fd5b82356110f8816110c2565b946020939093013593505050565b61ffff811681146110d757600080fd5b60008060006060848603121561112b57600080fd5b83359250602084013561113d816110c2565b9150604084013561114d81611106565b809150509250925092565b6000608082840312156110bc57600080fd5b60008060008060e0858703121561118057600080fd5b843593506020850135611192816110c2565b925060408501356111a281611106565b91506111b18660608701611158565b905092959194509250565b600080604083850312156111cf57600080fd5b8235915060208301356111e1816110c2565b809150509250929050565b60008060006060848603121561120157600080fd5b833561120c816110c2565b9250602084013561121c816110c2565b929592945050506040919091013590565b600080600060c0848603121561124257600080fd5b833592506020840135611254816110c2565b91506112638560408601611158565b90509250925092565b60006020828403121561127e57600080fd5b8135611289816110c2565b9392505050565b6000602082840312156112a257600080fd5b5035919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6000825160005b818110156112ff57602081860181015185830152016112e5565b8181111561130e576000828501525b509190910192915050565b60006020828403121561132b57600080fd5b813560ff8116811461128957600080fd5b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6040516101e0810167ffffffffffffffff811182821017156113af57634e487b7160e01b600052604160045260246000fd5b60405290565b6000602082840312156113c757600080fd5b6040516020810181811067ffffffffffffffff821117156113f857634e487b7160e01b600052604160045260246000fd5b6040529151825250919050565b80516fffffffffffffffffffffffffffffffff8116811461142557600080fd5b919050565b805164ffffffffff8116811461142557600080fd5b805161142581611106565b8051611425816110c2565b60006101e0828403121561146857600080fd5b61147061137d565b61147a84846113b5565b815261148860208401611405565b602082015261149960408401611405565b60408201526114aa60608401611405565b60608201526114bb60808401611405565b60808201526114cc60a08401611405565b60a08201526114dd60c0840161142a565b60c08201526114ee60e0840161143f565b60e082015261010061150181850161144a565b9082015261012061151384820161144a565b9082015261014061152584820161144a565b9082015261016061153784820161144a565b90820152610180611549848201611405565b908201526101a061155b848201611405565b908201526101c061156d848201611405565b908201529392505050565b60006020828403121561158a57600080fd5b5051919050565b6000602082840312156115a357600080fd5b8151801515811461128957600080fd5b6000828210156115d357634e487b7160e01b600052601160045260246000fd5b50039056fea26469706673582212205320d4cc032d032dd4cecc8ece4248d6c4ab4f9302229682d954ce7a460baacf64736f6c634300080a00338be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0'; - -type SavingsDaiTokenWrapperConstructorParams = - | [signer?: Signer] - | ConstructorParameters; - -const isSuperArgs = ( - xs: SavingsDaiTokenWrapperConstructorParams, -): xs is ConstructorParameters => xs.length > 1; - -export class SavingsDaiTokenWrapper__factory extends ContractFactory { - constructor(...args: SavingsDaiTokenWrapperConstructorParams) { - if (isSuperArgs(args)) { - super(...args); - } else { - super(_abi, _bytecode, args[0]); - } - } - - override deploy( - tokenIn: string, - tokenOut: string, - pool: string, - owner: string, - overrides?: Overrides & { from?: string }, - ): Promise { - return super.deploy( - tokenIn, - tokenOut, - pool, - owner, - overrides || {}, - ) as Promise; - } - override getDeployTransaction( - tokenIn: string, - tokenOut: string, - pool: string, - owner: string, - overrides?: Overrides & { from?: string }, - ): TransactionRequest { - return super.getDeployTransaction( - tokenIn, - tokenOut, - pool, - owner, - overrides || {}, - ); - } - override attach(address: string): SavingsDaiTokenWrapper { - return super.attach(address) as SavingsDaiTokenWrapper; - } - override connect(signer: Signer): SavingsDaiTokenWrapper__factory { - return super.connect(signer) as SavingsDaiTokenWrapper__factory; - } - - static readonly bytecode = _bytecode; - static readonly abi = _abi; - static createInterface(): SavingsDaiTokenWrapperInterface { - return new utils.Interface(_abi) as SavingsDaiTokenWrapperInterface; - } - static connect( - address: string, - signerOrProvider: Signer | Provider, - ): SavingsDaiTokenWrapper { - return new Contract( - address, - _abi, - signerOrProvider, - ) as SavingsDaiTokenWrapper; - } -} From ae08eed57075da8f317ca22a319d6b8bab624d55 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 12 Feb 2024 13:46:03 -0600 Subject: [PATCH 21/24] fix: tests --- jest.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index d17ec125..90fff561 100644 --- a/jest.config.js +++ b/jest.config.js @@ -41,7 +41,6 @@ module.exports = { 'packages/contract-helpers/src/v3-migration-contract/typechain', 'packages/contract-helpers/src/index.ts', 'packages/math-utils/src/formatters/reserve/index.ts', - 'packages/contract-helpers/src/V3-uiStakeDataProvider-contract/index.ts', ], modulePathIgnorePatterns: ['node_modules'], testEnvironment: 'node', From b0d1f63019ec091d1653805fd1898faa4066245a Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 13 Feb 2024 08:46:50 -0600 Subject: [PATCH 22/24] test: ci --- packages/contract-helpers/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index 82be851e..95aa1ed4 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -39,6 +39,7 @@ export * from './governance-v3/governance-core'; export * from './governance-v3/aave-token-v3'; export * from './governance-v3/payloads-data-helper'; export * from './governance-v3/delegate-helper'; + export * from './abpt-migration'; // commons From 4197d703188c9a175f4ae576b0f67c96d3d397bf Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 13 Feb 2024 10:13:30 -0600 Subject: [PATCH 23/24] chore: cleanup --- packages/contract-helpers/src/index.ts | 1 - packages/contract-helpers/src/token-wrapper/index.ts | 7 ------- 2 files changed, 8 deletions(-) diff --git a/packages/contract-helpers/src/index.ts b/packages/contract-helpers/src/index.ts index 95aa1ed4..82be851e 100644 --- a/packages/contract-helpers/src/index.ts +++ b/packages/contract-helpers/src/index.ts @@ -39,7 +39,6 @@ export * from './governance-v3/governance-core'; export * from './governance-v3/aave-token-v3'; export * from './governance-v3/payloads-data-helper'; export * from './governance-v3/delegate-helper'; - export * from './abpt-migration'; // commons diff --git a/packages/contract-helpers/src/token-wrapper/index.ts b/packages/contract-helpers/src/token-wrapper/index.ts index 5dabc168..a99d7088 100644 --- a/packages/contract-helpers/src/token-wrapper/index.ts +++ b/packages/contract-helpers/src/token-wrapper/index.ts @@ -57,13 +57,6 @@ export class TokenWrapperService tokenWrapperAddress, provider, ); - - this.getTokenInForTokenOut = this.getTokenInForTokenOut.bind(this); - this.getTokenOutForTokenIn = this.getTokenOutForTokenIn.bind(this); - this.supplyToken = this.supplyToken.bind(this); - this.supplyTokenWithPermit = this.supplyTokenWithPermit.bind(this); - this.withdrawToken = this.withdrawToken.bind(this); - this.withdrawTokenWithPermit = this.withdrawTokenWithPermit.bind(this); } public async getTokenInForTokenOut(amount: string): Promise { From 82a145b79d35bde0f05a1a82a3548eaaed18812b Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Tue, 13 Feb 2024 10:32:10 -0600 Subject: [PATCH 24/24] fix: types --- .../token-wrapper/typechain/TokenWrapper.d.ts | 4 ++-- .../typechain/TokenWrapper_factory.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts index b5f72bcb..35144495 100644 --- a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts +++ b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper.d.ts @@ -391,7 +391,7 @@ export interface BaseTokenWrapper extends BaseContract { onBehalfOf: string, referralCode: BigNumberish, overrides?: CallOverrides, - ): Promise; + ): Promise; supplyTokenWithPermit( amount: BigNumberish, @@ -399,7 +399,7 @@ export interface BaseTokenWrapper extends BaseContract { referralCode: BigNumberish, signature: IBaseTokenWrapper.PermitSignatureStruct, overrides?: CallOverrides, - ): Promise; + ): Promise; transferOwnership( newOwner: string, diff --git a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts index ad60a6b8..a476763e 100644 --- a/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts +++ b/packages/contract-helpers/src/token-wrapper/typechain/TokenWrapper_factory.ts @@ -185,7 +185,13 @@ const _abi = [ }, ], name: 'supplyToken', - outputs: [], + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], stateMutability: 'nonpayable', type: 'function', }, @@ -235,7 +241,13 @@ const _abi = [ }, ], name: 'supplyTokenWithPermit', - outputs: [], + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], stateMutability: 'nonpayable', type: 'function', },