diff --git a/.changeset/silent-rockets-move.md b/.changeset/silent-rockets-move.md new file mode 100644 index 00000000..4c3e3356 --- /dev/null +++ b/.changeset/silent-rockets-move.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': patch +--- + +balancer v2 flash loan logic add quote func diff --git a/src/logics/aave-v2/logic.flash-loan.ts b/src/logics/aave-v2/logic.flash-loan.ts index aae35182..d294edec 100644 --- a/src/logics/aave-v2/logic.flash-loan.ts +++ b/src/logics/aave-v2/logic.flash-loan.ts @@ -11,6 +11,13 @@ export type FlashLoanLogicTokenList = common.Token[]; export type FlashLoanLogicParams = core.TokensOutFields; +export type FlashLoanLogicQuotation = { + loans: common.TokenAmounts; + repays: common.TokenAmounts; + fees: common.TokenAmounts; + feeBps: number; +}; + export type FlashLoanLogicFields = core.FlashLoanFields<{ referralCode?: number }>; @core.LogicDefinitionDecorator() @@ -45,8 +52,9 @@ export class FlashLoanLogic extends core.Logic implements core.LogicTokenListInt const repay = loan.clone().add(fee); repays.add(repay); } + const quotation: FlashLoanLogicQuotation = { loans, repays, fees, feeBps }; - return { loans, repays, fees, feeBps }; + return quotation; } async build(fields: FlashLoanLogicFields) { diff --git a/src/logics/aave-v3/logic.flash-loan.ts b/src/logics/aave-v3/logic.flash-loan.ts index 5a4ea30d..6f5d2747 100644 --- a/src/logics/aave-v3/logic.flash-loan.ts +++ b/src/logics/aave-v3/logic.flash-loan.ts @@ -11,6 +11,13 @@ export type FlashLoanLogicTokenList = common.Token[]; export type FlashLoanLogicParams = core.TokensOutFields; +export type FlashLoanLogicQuotation = { + loans: common.TokenAmounts; + repays: common.TokenAmounts; + fees: common.TokenAmounts; + feeBps: number; +}; + export type FlashLoanLogicFields = core.FlashLoanFields<{ referralCode?: number }>; @core.LogicDefinitionDecorator() @@ -50,8 +57,9 @@ export class FlashLoanLogic const repay = loan.clone().add(fee); repays.add(repay); } + const quotation: FlashLoanLogicQuotation = { loans, repays, fees, feeBps }; - return { loans, repays, fees, feeBps }; + return quotation; } async build(fields: FlashLoanLogicFields) { diff --git a/src/logics/balancer-v2/logic.flash-loan.ts b/src/logics/balancer-v2/logic.flash-loan.ts index ba566e7e..9b2e47a7 100644 --- a/src/logics/balancer-v2/logic.flash-loan.ts +++ b/src/logics/balancer-v2/logic.flash-loan.ts @@ -5,9 +5,19 @@ import { axios } from 'src/utils'; import * as common from '@protocolink/common'; import * as core from '@protocolink/core'; import { getContractAddress, supportedChainIds } from './configs'; +import invariant from 'tiny-invariant'; export type FlashLoanLogicTokenList = common.Token[]; +export type FlashLoanLogicParams = core.TokensOutFields; + +export type FlashLoanLogicQuotation = { + loans: common.TokenAmounts; + repays: common.TokenAmounts; + fees: common.TokenAmounts; + feeBps: number; +}; + export type FlashLoanLogicFields = core.FlashLoanFields; @core.LogicDefinitionDecorator() @@ -30,6 +40,32 @@ export class FlashLoanLogic extends core.Logic implements core.LogicTokenListInt return tokenList; } + async quote(params: FlashLoanLogicParams) { + const { outputs: loans } = params; + + const vaultAddress = getContractAddress(this.chainId, 'Vault'); + const calls: common.Multicall2.CallStruct[] = loans.map((loan) => ({ + target: loan.token.address, + callData: this.erc20Iface.encodeFunctionData('balanceOf', [vaultAddress]), + })); + const { returnData } = await this.multicall2.callStatic.aggregate(calls); + + const repays = new common.TokenAmounts(); + const fees = new common.TokenAmounts(); + for (let i = 0; i < loans.length; i++) { + const loan = loans.at(i); + const [balance] = this.erc20Iface.decodeFunctionResult('balanceOf', returnData[i]); + const avaliableToBorrow = new common.TokenAmount(loan.token).setWei(balance); + invariant(avaliableToBorrow.gte(loan), `insufficient borrowing capacity for the asset: ${loan.token.address}`); + + repays.add(loan.token, loan.amount); + fees.add(loan.token, '0'); + } + const quotation: FlashLoanLogicQuotation = { loans, repays, fees, feeBps: 0 }; + + return quotation; + } + async build(fields: FlashLoanLogicFields) { const { outputs, params } = fields; diff --git a/test/logics/aave-v2/borrow.test.ts b/test/logics/aave-v2/borrow.test.ts index dc298291..16c0f2f5 100644 --- a/test/logics/aave-v2/borrow.test.ts +++ b/test/logics/aave-v2/borrow.test.ts @@ -72,8 +72,8 @@ describe('Test AaveV2 Borrow Logic', function () { // 3. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - const logicAaveV2Borrow = new aavev2.BorrowLogic(chainId); - routerLogics.push(await logicAaveV2Borrow.build({ output, interestRateMode }, { account: user.address })); + const aaveV2BorrowLogic = new aavev2.BorrowLogic(chainId); + routerLogics.push(await aaveV2BorrowLogic.build({ output, interestRateMode }, { account: user.address })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/aave-v2/deposit.test.ts b/test/logics/aave-v2/deposit.test.ts index 0011e4d7..3872badf 100644 --- a/test/logics/aave-v2/deposit.test.ts +++ b/test/logics/aave-v2/deposit.test.ts @@ -53,8 +53,8 @@ describe('Test AaveV2 Deposit Logic', function () { testCases.forEach(({ input, tokenOut, balanceBps }, i) => { it(`case ${i + 1}`, async function () { // 1. get output - const logicAaveV2Deposit = new aavev2.DepositLogic(chainId); - const { output } = await logicAaveV2Deposit.quote({ input, tokenOut }); + const aaveV2DepositLogic = new aavev2.DepositLogic(chainId); + const { output } = await aaveV2DepositLogic.quote({ input, tokenOut }); // 2. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -69,7 +69,7 @@ describe('Test AaveV2 Deposit Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAaveV2Deposit.build({ input, output, balanceBps }, { account: user.address })); + routerLogics.push(await aaveV2DepositLogic.build({ input, output, balanceBps }, { account: user.address })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/aave-v2/flash-loan.test.ts b/test/logics/aave-v2/flash-loan.test.ts index 20bccaf1..3ea00f80 100644 --- a/test/logics/aave-v2/flash-loan.test.ts +++ b/test/logics/aave-v2/flash-loan.test.ts @@ -31,8 +31,8 @@ describe('Test AaveV2 FlashLoan Logic', function () { testCases.forEach(({ outputs }, i) => { it(`case ${i + 1}`, async function () { // 1. get flash loan quotation - const logicAaveV3FlashLoan = new aavev2.FlashLoanLogic(chainId); - const { loans, repays, fees } = await logicAaveV3FlashLoan.quote({ outputs }); + const aaveV2FlashLoanLogic = new aavev2.FlashLoanLogic(chainId); + const { loans, repays, fees } = await aaveV2FlashLoanLogic.quote({ outputs }); // 2. build funds and router logics for flash loan by flash loan fee const funds = new common.TokenAmounts(); @@ -53,8 +53,7 @@ describe('Test AaveV2 FlashLoan Logic', function () { const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); const params = core.newCallbackParams(flashLoanRouterLogics); - const logicAaveV2FlashLoan = new aavev2.FlashLoanLogic(chainId); - routerLogics.push(await logicAaveV2FlashLoan.build({ outputs: loans, params })); + routerLogics.push(await aaveV2FlashLoanLogic.build({ outputs: loans, params })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics }); diff --git a/test/logics/aave-v2/repay.test.ts b/test/logics/aave-v2/repay.test.ts index a6628e30..1aa26800 100644 --- a/test/logics/aave-v2/repay.test.ts +++ b/test/logics/aave-v2/repay.test.ts @@ -113,8 +113,8 @@ describe('Test AaveV2 Repay Logic', function () { await helpers.borrow(chainId, user, borrow, interestRateMode); // 2. get user debt - const logicAaveV2Repay = new aavev2.RepayLogic(chainId, hre.ethers.provider); - let quotation = await logicAaveV2Repay.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); + const aaveV2RepayLogic = new aavev2.RepayLogic(chainId, hre.ethers.provider); + let quotation = await aaveV2RepayLogic.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); const { input } = quotation; // 3. build funds and tokensReturn @@ -130,7 +130,7 @@ describe('Test AaveV2 Repay Logic', function () { const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAaveV2Repay.build({ input, interestRateMode, borrower: user.address, balanceBps })); + routerLogics.push(await aaveV2RepayLogic.build({ input, interestRateMode, borrower: user.address, balanceBps })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ @@ -143,7 +143,7 @@ describe('Test AaveV2 Repay Logic', function () { await expect(user.address).to.changeBalance(input.token, -input.amount, 200); // 6. check user's debt should be zero - quotation = await logicAaveV2Repay.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); + quotation = await aaveV2RepayLogic.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); expect(quotation.input.amountWei).to.eq(0); }); }); diff --git a/test/logics/aave-v2/withdraw.test.ts b/test/logics/aave-v2/withdraw.test.ts index 903b6d66..4b3347a9 100644 --- a/test/logics/aave-v2/withdraw.test.ts +++ b/test/logics/aave-v2/withdraw.test.ts @@ -58,8 +58,8 @@ describe('Test AaveV2 Withdraw Logic', function () { await helpers.deposit(chainId, user, assetsAmount); // 2. get output - const logicAaveV2Withdraw = new aavev2.WithdrawLogic(chainId); - const { output } = await logicAaveV2Withdraw.quote({ input, tokenOut }); + const aaveV2WithdrawLogic = new aavev2.WithdrawLogic(chainId); + const { output } = await aaveV2WithdrawLogic.quote({ input, tokenOut }); // 3. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -74,7 +74,7 @@ describe('Test AaveV2 Withdraw Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAaveV2Withdraw.build({ input, output, balanceBps }, { account: user.address })); + routerLogics.push(await aaveV2WithdrawLogic.build({ input, output, balanceBps }, { account: user.address })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/aave-v3/borrow.test.ts b/test/logics/aave-v3/borrow.test.ts index 6c056d37..289a1787 100644 --- a/test/logics/aave-v3/borrow.test.ts +++ b/test/logics/aave-v3/borrow.test.ts @@ -55,8 +55,8 @@ describe('Test AaveV3 Borrow Logic', function () { // 3. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - const logicAaveV3Borrow = new aavev3.BorrowLogic(chainId); - routerLogics.push(await logicAaveV3Borrow.build({ output, interestRateMode }, { account: user.address })); + const aaveV3BorrowLogic = new aavev3.BorrowLogic(chainId); + routerLogics.push(await aaveV3BorrowLogic.build({ output, interestRateMode }, { account: user.address })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/aave-v3/flash-loan.test.ts b/test/logics/aave-v3/flash-loan.test.ts index 66ceff92..a2fd755a 100644 --- a/test/logics/aave-v3/flash-loan.test.ts +++ b/test/logics/aave-v3/flash-loan.test.ts @@ -31,8 +31,8 @@ describe('Test AaveV3 FlashLoan Logic', function () { testCases.forEach(({ outputs }, i) => { it(`case ${i + 1}`, async function () { // 1. get flash loan quotation - const logicAaveV3FlashLoan = new aavev3.FlashLoanLogic(chainId); - const { loans, repays, fees } = await logicAaveV3FlashLoan.quote({ outputs }); + const aaveV3FlashLoanLogic = new aavev3.FlashLoanLogic(chainId); + const { loans, repays, fees } = await aaveV3FlashLoanLogic.quote({ outputs }); // 2. build funds and router logics for flash loan by flash loan fee const funds = new common.TokenAmounts(); @@ -53,7 +53,7 @@ describe('Test AaveV3 FlashLoan Logic', function () { const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); const params = core.newCallbackParams(flashLoanRouterLogics); - routerLogics.push(await logicAaveV3FlashLoan.build({ outputs: loans, params })); + routerLogics.push(await aaveV3FlashLoanLogic.build({ outputs: loans, params })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics }); diff --git a/test/logics/aave-v3/repay.test.ts b/test/logics/aave-v3/repay.test.ts index 7e5cd179..6b26c09c 100644 --- a/test/logics/aave-v3/repay.test.ts +++ b/test/logics/aave-v3/repay.test.ts @@ -74,8 +74,8 @@ describe('Test AaveV3 Repay Logic', function () { await helpers.borrow(chainId, user, borrow, interestRateMode); // 2. get user debt - const logicAaveV3Repay = new aavev3.RepayLogic(chainId, hre.ethers.provider); - let quotation = await logicAaveV3Repay.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); + const aaveV3RepayLogic = new aavev3.RepayLogic(chainId, hre.ethers.provider); + let quotation = await aaveV3RepayLogic.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); const { input } = quotation; // 3. build funds and tokensReturn @@ -91,7 +91,7 @@ describe('Test AaveV3 Repay Logic', function () { const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAaveV3Repay.build({ input, interestRateMode, borrower: user.address, balanceBps })); + routerLogics.push(await aaveV3RepayLogic.build({ input, interestRateMode, borrower: user.address, balanceBps })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ @@ -104,7 +104,7 @@ describe('Test AaveV3 Repay Logic', function () { await expect(user.address).to.changeBalance(input.token, -input.amount, 200); // 6. check user's debt should be zero - quotation = await logicAaveV3Repay.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); + quotation = await aaveV3RepayLogic.quote({ borrower: user.address, tokenIn: borrow.token, interestRateMode }); expect(quotation.input.amountWei).to.eq(0); }); }); diff --git a/test/logics/aave-v3/supply.test.ts b/test/logics/aave-v3/supply.test.ts index cf4ff06c..9830c21c 100644 --- a/test/logics/aave-v3/supply.test.ts +++ b/test/logics/aave-v3/supply.test.ts @@ -53,8 +53,8 @@ describe('Test AaveV3 Supply Logic', function () { testCases.forEach(({ input, tokenOut, balanceBps }, i) => { it(`case ${i + 1}`, async function () { // 1. get output - const logicAavev3Supply = new aavev3.SupplyLogic(chainId); - const { output } = await logicAavev3Supply.quote({ input, tokenOut }); + const aavev3SupplyLogic = new aavev3.SupplyLogic(chainId); + const { output } = await aavev3SupplyLogic.quote({ input, tokenOut }); // 2. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -69,7 +69,7 @@ describe('Test AaveV3 Supply Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAavev3Supply.build({ input, output, balanceBps }, { account: user.address })); + routerLogics.push(await aavev3SupplyLogic.build({ input, output, balanceBps }, { account: user.address })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/aave-v3/withdraw.test.ts b/test/logics/aave-v3/withdraw.test.ts index 7a28f43f..7ca6c74b 100644 --- a/test/logics/aave-v3/withdraw.test.ts +++ b/test/logics/aave-v3/withdraw.test.ts @@ -58,8 +58,8 @@ describe('Test AaveV3 Withdraw Logic', function () { await helpers.supply(chainId, user, assetsAmount); // 2. get output - const logicAaveV3Withdraw = new aavev3.WithdrawLogic(chainId); - const { output } = await logicAaveV3Withdraw.quote({ input, tokenOut }); + const aaveV3WithdrawLogic = new aavev3.WithdrawLogic(chainId); + const { output } = await aaveV3WithdrawLogic.quote({ input, tokenOut }); // 3. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -74,7 +74,7 @@ describe('Test AaveV3 Withdraw Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicAaveV3Withdraw.build({ input, output, balanceBps }, { account: user.address })); + routerLogics.push(await aaveV3WithdrawLogic.build({ input, output, balanceBps }, { account: user.address })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/balancer-v2/flash-loan.test.ts b/test/logics/balancer-v2/flash-loan.test.ts index 5496b969..42f9c9f4 100644 --- a/test/logics/balancer-v2/flash-loan.test.ts +++ b/test/logics/balancer-v2/flash-loan.test.ts @@ -25,26 +25,32 @@ describe('Test BalancerV2 FlashLoan Logic', function () { testCases.forEach(({ outputs }, i) => { it(`case ${i + 1}`, async function () { - // 1. build funds and router logics for flash loan + // 1. get flash loan quotation + const aaveV3FlashLoanLogic = new balancerv2.FlashLoanLogic(chainId); + const { loans, repays, fees } = await aaveV3FlashLoanLogic.quote({ outputs }); + + // 2. build funds and router logics for flash loan + const funds = new common.TokenAmounts(); const flashLoanRouterLogics: core.IParam.LogicStruct[] = []; const utilitySendTokenLogic = new utility.SendTokenLogic(chainId); - for (const output of outputs.toArray()) { + for (let i = 0; i < fees.length; i++) { + funds.add(fees.at(i).clone()); flashLoanRouterLogics.push( await utilitySendTokenLogic.build({ - input: output, + input: repays.at(i), recipient: balancerv2.getContractAddress(chainId, 'BalancerV2FlashLoanCallback'), }) ); } - // 2. build router logics + // 3. build router logics const routerLogics: core.IParam.LogicStruct[] = []; const userData = core.newCallbackParams(flashLoanRouterLogics); - const logicBalancerV2FlashLoan = new balancerv2.FlashLoanLogic(chainId); - routerLogics.push(await logicBalancerV2FlashLoan.build({ outputs, params: userData })); + const balancerV2FlashLoanLogic = new balancerv2.FlashLoanLogic(chainId); + routerLogics.push(await balancerV2FlashLoanLogic.build({ outputs: loans, params: userData })); - // 3. send router tx + // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics }); await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; }); diff --git a/test/logics/compound-v2/claim.test.ts b/test/logics/compound-v2/claim.test.ts index bc7aebb2..c5181f20 100644 --- a/test/logics/compound-v2/claim.test.ts +++ b/test/logics/compound-v2/claim.test.ts @@ -61,13 +61,13 @@ describe('Test CompoundV2 Claim Logic', function () { // 2. get allocated COMP amount after 1000 blocks await hrehelpers.mine(1000); - const logicCompoundV2Claim = new compoundv2.ClaimLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV2Claim.quote({ owner: owner.address }); + const compoundV2ClaimLogic = new compoundv2.ClaimLogic(chainId, hre.ethers.provider); + const { output } = await compoundV2ClaimLogic.quote({ owner: owner.address }); expect(output.amountWei).to.be.gt(0); // 3. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - routerLogics.push(await logicCompoundV2Claim.build({ owner: owner.address, output })); + routerLogics.push(await compoundV2ClaimLogic.build({ owner: owner.address, output })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics }); diff --git a/test/logics/compound-v2/repay.test.ts b/test/logics/compound-v2/repay.test.ts index effdb294..c0166a79 100644 --- a/test/logics/compound-v2/repay.test.ts +++ b/test/logics/compound-v2/repay.test.ts @@ -51,8 +51,8 @@ describe('Test CompoundV2 Repay Logic', function () { // 2. get borrow balance after 1000 blocks await hrehelpers.mine(1000); - const logicCompoundV2Repay = new compoundv2.RepayLogic(chainId, hre.ethers.provider); - const { input } = await logicCompoundV2Repay.quote({ borrower: user.address, tokenIn: borrow.token }); + const compoundV2RepayLogic = new compoundv2.RepayLogic(chainId, hre.ethers.provider); + const { input } = await compoundV2RepayLogic.quote({ borrower: user.address, tokenIn: borrow.token }); expect(input.amountWei).to.be.gt(borrow.amountWei); // 3. build input, funds, tokensReturn @@ -67,7 +67,7 @@ describe('Test CompoundV2 Repay Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicCompoundV2Repay.build({ input, balanceBps, borrower: user.address })); + routerLogics.push(await compoundV2RepayLogic.build({ input, balanceBps, borrower: user.address })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v2/supply.test.ts b/test/logics/compound-v2/supply.test.ts index 5e00a850..ece0937e 100644 --- a/test/logics/compound-v2/supply.test.ts +++ b/test/logics/compound-v2/supply.test.ts @@ -43,8 +43,8 @@ describe('Test CompoundV2 Supply Logic', function () { testCases.forEach(({ input, tokenOut, balanceBps }, i) => { it(`case ${i + 1}`, async function () { // 1. get output - const logicCompoundV2Supply = new compoundv2.SupplyLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV2Supply.quote({ input, tokenOut }); + const compoundV2SupplyLogic = new compoundv2.SupplyLogic(chainId, hre.ethers.provider); + const { output } = await compoundV2SupplyLogic.quote({ input, tokenOut }); // 2. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -59,7 +59,7 @@ describe('Test CompoundV2 Supply Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicCompoundV2Supply.build({ input, output, balanceBps })); + routerLogics.push(await compoundV2SupplyLogic.build({ input, output, balanceBps })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v2/withdraw.test.ts b/test/logics/compound-v2/withdraw.test.ts index 5bde80ca..2af62106 100644 --- a/test/logics/compound-v2/withdraw.test.ts +++ b/test/logics/compound-v2/withdraw.test.ts @@ -44,8 +44,8 @@ describe('Test CompoundV2 Withdraw Logic', function () { testCases.forEach(({ input, tokenOut, balanceBps }, i) => { it(`case ${i + 1}`, async function () { // 1. get output - const logicCompoundV2Withdraw = new compoundv2.WithdrawLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV2Withdraw.quote({ input, tokenOut }); + const compoundV2WithdrawLogic = new compoundv2.WithdrawLogic(chainId, hre.ethers.provider); + const { output } = await compoundV2WithdrawLogic.quote({ input, tokenOut }); // 2. supply const underlyingToken = output.token; @@ -65,7 +65,7 @@ describe('Test CompoundV2 Withdraw Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicCompoundV2Withdraw.build({ input, output, balanceBps })); + routerLogics.push(await compoundV2WithdrawLogic.build({ input, output, balanceBps })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/compound-v3/borrow.test.ts b/test/logics/compound-v3/borrow.test.ts index 8ff0d1d2..b7d14032 100644 --- a/test/logics/compound-v3/borrow.test.ts +++ b/test/logics/compound-v3/borrow.test.ts @@ -80,8 +80,8 @@ describe('Test CompoundV3 Borrow Logic', function () { // 5. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - const logicCompoundV3Borrow = new compoundv3.BorrowLogic(chainId, hre.ethers.provider); - routerLogics.push(await logicCompoundV3Borrow.build({ marketId, output }, { account: user.address })); + const compoundV3BorrowLogic = new compoundv3.BorrowLogic(chainId, hre.ethers.provider); + routerLogics.push(await compoundV3BorrowLogic.build({ marketId, output }, { account: user.address })); // 6. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v3/claim.test.ts b/test/logics/compound-v3/claim.test.ts index 2cf0c731..41c5f950 100644 --- a/test/logics/compound-v3/claim.test.ts +++ b/test/logics/compound-v3/claim.test.ts @@ -66,8 +66,8 @@ describe('Test CompoundV3 Claim Logic', function () { // 2. get rewards amount after 1000 blocks await hrehelpers.mine(1000); - const logicCompoundV3Claim = new compoundv3.ClaimLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV3Claim.quote({ marketId, owner: owner.address }); + const compoundV3ClaimLogic = new compoundv3.ClaimLogic(chainId, hre.ethers.provider); + const { output } = await compoundV3ClaimLogic.quote({ marketId, owner: owner.address }); expect(output.amountWei).to.be.gt(0); // 2. allow userAgent help user to claim @@ -83,7 +83,7 @@ describe('Test CompoundV3 Claim Logic', function () { // 4. build router logics const routerLogics: core.IParam.LogicStruct[] = []; routerLogics.push( - await logicCompoundV3Claim.build({ marketId, owner: owner.address, output }, { account: claimer.address }) + await compoundV3ClaimLogic.build({ marketId, owner: owner.address, output }, { account: claimer.address }) ); // 5. send router tx diff --git a/test/logics/compound-v3/repay.test.ts b/test/logics/compound-v3/repay.test.ts index a613ae68..77b191c7 100644 --- a/test/logics/compound-v3/repay.test.ts +++ b/test/logics/compound-v3/repay.test.ts @@ -272,8 +272,8 @@ describe('Test CompoundV3 Repay Logic', function () { await helpers.borrow(chainId, borrower, marketId, borrow); // 3. get quotation - const logicCompoundV3Repay = new compoundv3.RepayLogic(chainId, hre.ethers.provider); - const quotation = await logicCompoundV3Repay.quote({ + const compoundV3RepayLogic = new compoundv3.RepayLogic(chainId, hre.ethers.provider); + const quotation = await compoundV3RepayLogic.quote({ marketId, borrower: borrower.address, tokenIn: repay.token, @@ -292,7 +292,7 @@ describe('Test CompoundV3 Repay Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, repayer, erc20Funds); - routerLogics.push(await logicCompoundV3Repay.build({ marketId, borrower: borrower.address, input: repay })); + routerLogics.push(await compoundV3RepayLogic.build({ marketId, borrower: borrower.address, input: repay })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v3/supply-base.test.ts b/test/logics/compound-v3/supply-base.test.ts index 3aedb037..e12dcc70 100644 --- a/test/logics/compound-v3/supply-base.test.ts +++ b/test/logics/compound-v3/supply-base.test.ts @@ -59,8 +59,8 @@ describe('Test CompoundV3 SupplyBase Logic', function () { testCases.forEach(({ marketId, input, tokenOut, balanceBps }, i) => { it(`case ${i + 1}`, async function () { // 1. get quotation - const logicCompoundV3SupplyBase = new compoundv3.SupplyBaseLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV3SupplyBase.quote({ marketId, input, tokenOut }); + const compoundV3SupplyBaseLogic = new compoundv3.SupplyBaseLogic(chainId, hre.ethers.provider); + const { output } = await compoundV3SupplyBaseLogic.quote({ marketId, input, tokenOut }); // 2. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -75,7 +75,7 @@ describe('Test CompoundV3 SupplyBase Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicCompoundV3SupplyBase.build({ marketId, input, output, balanceBps })); + routerLogics.push(await compoundV3SupplyBaseLogic.build({ marketId, input, output, balanceBps })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v3/supply-collateral.test.ts b/test/logics/compound-v3/supply-collateral.test.ts index e30c5d33..1b3e0fb5 100644 --- a/test/logics/compound-v3/supply-collateral.test.ts +++ b/test/logics/compound-v3/supply-collateral.test.ts @@ -91,9 +91,9 @@ describe('Test CompoundV3 SupplyCollateral Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - const logicCompoundV3SupplyCollateral = new compoundv3.SupplyCollateralLogic(chainId, hre.ethers.provider); + const compoundV3SupplyCollateralLogic = new compoundv3.SupplyCollateralLogic(chainId, hre.ethers.provider); routerLogics.push( - await logicCompoundV3SupplyCollateral.build({ marketId, input, balanceBps }, { account: user.address }) + await compoundV3SupplyCollateralLogic.build({ marketId, input, balanceBps }, { account: user.address }) ); // 4. send router tx diff --git a/test/logics/compound-v3/withdraw-base.test.ts b/test/logics/compound-v3/withdraw-base.test.ts index 39a04a27..eb2f5509 100644 --- a/test/logics/compound-v3/withdraw-base.test.ts +++ b/test/logics/compound-v3/withdraw-base.test.ts @@ -65,8 +65,8 @@ describe('Test CompoundV3 WithdrawBase Logic', function () { await expect(user.address).to.changeBalance(supply.token, supply.amount, 1); // 2. get quotation - const logicCompoundV3WithdrawBase = new compoundv3.WithdrawBaseLogic(chainId, hre.ethers.provider); - const { output } = await logicCompoundV3WithdrawBase.quote({ marketId, input, tokenOut }); + const compoundV3WithdrawBaseLogic = new compoundv3.WithdrawBaseLogic(chainId, hre.ethers.provider); + const { output } = await compoundV3WithdrawBaseLogic.quote({ marketId, input, tokenOut }); // 3. build funds, tokensReturn const tokensReturn = [output.token.elasticAddress]; @@ -81,7 +81,7 @@ describe('Test CompoundV3 WithdrawBase Logic', function () { // 4. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicCompoundV3WithdrawBase.build({ marketId, input, output, balanceBps })); + routerLogics.push(await compoundV3WithdrawBaseLogic.build({ marketId, input, output, balanceBps })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/compound-v3/withdraw-collateral.test.ts b/test/logics/compound-v3/withdraw-collateral.test.ts index b267fbfb..64b52ffc 100644 --- a/test/logics/compound-v3/withdraw-collateral.test.ts +++ b/test/logics/compound-v3/withdraw-collateral.test.ts @@ -69,8 +69,8 @@ describe('Test CompoundV3 WithdrawCollateral Logic', function () { // 5. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - const logicCompoundV3WithdrawCollateral = new compoundv3.WithdrawCollateralLogic(chainId, hre.ethers.provider); - routerLogics.push(await logicCompoundV3WithdrawCollateral.build({ marketId, output }, { account: user.address })); + const compoundV3WithdrawCollateralLogic = new compoundv3.WithdrawCollateralLogic(chainId, hre.ethers.provider); + routerLogics.push(await compoundV3WithdrawCollateralLogic.build({ marketId, output }, { account: user.address })); // 6. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics, tokensReturn }); diff --git a/test/logics/paraswap-v5/swap-token.test.ts b/test/logics/paraswap-v5/swap-token.test.ts index db631c34..5377c10e 100644 --- a/test/logics/paraswap-v5/swap-token.test.ts +++ b/test/logics/paraswap-v5/swap-token.test.ts @@ -68,8 +68,8 @@ describe('Test ParaswapV5 SwapToken Logic', function () { testCases.forEach(({ params }, i) => { it(`case ${i + 1}`, async function () { // 1. get output - const logicParaswapV5SwapToken = new paraswapv5.SwapTokenLogic(chainId); - const quotation = await logicParaswapV5SwapToken.quote(params); + const paraswapV5SwapTokenLogic = new paraswapv5.SwapTokenLogic(chainId); + const quotation = await paraswapV5SwapTokenLogic.quote(params); const { input, output } = quotation; // 2. build funds, tokensReturn @@ -79,7 +79,7 @@ describe('Test ParaswapV5 SwapToken Logic', function () { // 3. build router logics const erc20Funds = funds.erc20; const routerLogics = await utils.getPermitAndPullTokenRouterLogics(chainId, user, erc20Funds); - routerLogics.push(await logicParaswapV5SwapToken.build(quotation, { account: user.address })); + routerLogics.push(await paraswapV5SwapTokenLogic.build(quotation, { account: user.address })); // 4. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ diff --git a/test/logics/permit2/permit-token.test.ts b/test/logics/permit2/permit-token.test.ts index b7ef87a3..62ade978 100644 --- a/test/logics/permit2/permit-token.test.ts +++ b/test/logics/permit2/permit-token.test.ts @@ -59,15 +59,15 @@ describe('Test Permit2 PermitToken Logic', function () { } // 3. get user permit sig - const logicPermit2PermitToken = new permit2.PermitTokenLogic(chainId, hre.ethers.provider); - let permitData = await logicPermit2PermitToken.getPermitData(user.address, erc20Funds); + const permit2PermitTokenLogic = new permit2.PermitTokenLogic(chainId, hre.ethers.provider); + let permitData = await permit2PermitTokenLogic.getPermitData(user.address, erc20Funds); expect(permitData).to.not.be.undefined; let permit = permitData!.values; const permitSig = await user._signTypedData(permitData!.domain, permitData!.types, permitData!.values); // 4. build router logics const routerLogics: core.IParam.LogicStruct[] = []; - routerLogics.push(await logicPermit2PermitToken.build({ permit, sig: permitSig }, { account: user.address })); + routerLogics.push(await permit2PermitTokenLogic.build({ permit, sig: permitSig }, { account: user.address })); // 5. send router tx const transactionRequest = core.newRouterExecuteTransactionRequest({ chainId, routerLogics }); @@ -91,12 +91,12 @@ describe('Test Permit2 PermitToken Logic', function () { } // 7. get permit details again, and should be empty. - permitData = await logicPermit2PermitToken.getPermitData(user.address, erc20Funds); + permitData = await permit2PermitTokenLogic.getPermitData(user.address, erc20Funds); expect(permitData).to.be.undefined; // 8. get permit details again after 30d, and should be permit again. clock.tick(30 * 86400 * 1000); - permitData = await logicPermit2PermitToken.getPermitData(user.address, erc20Funds); + permitData = await permit2PermitTokenLogic.getPermitData(user.address, erc20Funds); expect(permitData).to.not.be.undefined; permit = permitData!.values; if (permit2.isPermitSingle(permit)) { diff --git a/test/utils/router.ts b/test/utils/router.ts index 7fcc43fc..63d4261f 100644 --- a/test/utils/router.ts +++ b/test/utils/router.ts @@ -30,18 +30,18 @@ export async function getPermitAndPullTokenRouterLogics( await approves(user, permit2Address, erc20Funds); // 2. get permit2 permit token logic - const logicPermit2PermitToken = new permit2.PermitTokenLogic(chainId, hre.ethers.provider); - const permitData = await logicPermit2PermitToken.getPermitData(user.address, erc20Funds); + const permit2PermitTokenLogic = new permit2.PermitTokenLogic(chainId, hre.ethers.provider); + const permitData = await permit2PermitTokenLogic.getPermitData(user.address, erc20Funds); if (permitData) { const permitSig = await user._signTypedData(permitData.domain, permitData.types, permitData.values); routerLogics.push( - await logicPermit2PermitToken.build({ permit: permitData.values, sig: permitSig }, { account: user.address }) + await permit2PermitTokenLogic.build({ permit: permitData.values, sig: permitSig }, { account: user.address }) ); } // 3. get permit2 pull token logic - const logicPermit2PullToken = new permit2.PullTokenLogic(chainId, hre.ethers.provider); - routerLogics.push(await logicPermit2PullToken.build({ inputs: erc20Funds }, { account: user.address })); + const permit2PullTokenLogic = new permit2.PullTokenLogic(chainId, hre.ethers.provider); + routerLogics.push(await permit2PullTokenLogic.build({ inputs: erc20Funds }, { account: user.address })); } return routerLogics;