From cb162b3fe28d282d67123ce4bca4c6bde757d9bc Mon Sep 17 00:00:00 2001 From: Bob Lu Date: Sat, 2 Dec 2023 22:19:25 +0800 Subject: [PATCH] fix: standardized import naming, corrected typos, and made various minor improvements --- packages/lending/src/adapter.test.ts | 2 +- packages/lending/src/adapter.ts | 114 +++++++++--------- packages/lending/src/adapter.type.ts | 6 +- packages/lending/src/flashloaner.ts | 9 +- packages/lending/src/index.ts | 4 +- .../src/protocols/aave-v2/lending-protocol.ts | 16 +-- .../src/protocols/aave-v3/lending-protocol.ts | 16 +-- .../protocols/compound-v3/lending-protocol.ts | 23 ++-- .../protocols/openocean-v2/lending-swaper.ts | 13 +- .../protocols/paraswap-v5/lending-swaper.ts | 13 +- .../protocols/radiant-v2/lending-protocol.ts | 16 +-- packages/lending/src/swaper.ts | 10 +- packages/lending/src/swaper.type.ts | 5 + .../test/transactions/collateral-swap.ts | 35 ++++-- .../lending/test/transactions/debt-swap.ts | 12 +- .../lending/test/transactions/deleverage.ts | 16 +-- .../test/transactions/leverage-long.ts | 10 +- .../test/transactions/leverage-short.ts | 6 +- .../lending/test/transactions/zap-borrow.ts | 10 +- .../lending/test/transactions/zap-repay.ts | 8 +- .../test/transactions/zap-supply-arbitrum.ts | 6 +- .../lending/test/transactions/zap-supply.ts | 32 ++--- .../lending/test/transactions/zap-withdraw.ts | 24 ++-- 23 files changed, 211 insertions(+), 195 deletions(-) diff --git a/packages/lending/src/adapter.test.ts b/packages/lending/src/adapter.test.ts index 757b3586..510b6a78 100644 --- a/packages/lending/src/adapter.test.ts +++ b/packages/lending/src/adapter.test.ts @@ -89,7 +89,7 @@ describe('Lending AaveV3 SDK', function () { Adapter.registerProtocol(LendingProtocol); Adapter.registerSwaper(LendingSwaper); const adapter = new Adapter(1, provider); - const protocolId = 'aavev3'; + const protocolId = 'aave-v3'; let portfolio: Portfolio; diff --git a/packages/lending/src/adapter.ts b/packages/lending/src/adapter.ts index fe99d438..7c17a692 100644 --- a/packages/lending/src/adapter.ts +++ b/packages/lending/src/adapter.ts @@ -2,7 +2,7 @@ import { BaseFields, BaseParams } from './adapter.type'; import { Portfolio } from './protocol.portfolio'; import { Protocol, ProtocolClass } from './protocol'; import { Swaper, SwaperClass } from './swaper'; -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import { defaultInterestRateMode, defaultSlippage } from './protocol.type'; import flatten from 'lodash/flatten'; @@ -10,7 +10,7 @@ import { providers } from 'ethers'; import { wrapToken } from './helper'; type Options = { - permitType: api.Permit2Type | undefined; + permitType: apisdk.Permit2Type | undefined; apiKey?: string | undefined; }; export class Adapter extends common.Web3Toolkit { @@ -26,7 +26,7 @@ export class Adapter extends common.Web3Toolkit { this.Swapers.push(swaper); } - permitType: api.Permit2Type | undefined = 'permit'; + permitType: apisdk.Permit2Type | undefined = 'permit'; apiKey: string | undefined; protocolMap: Record = {}; swapers: Swaper[] = []; @@ -122,21 +122,21 @@ export class Adapter extends common.Web3Toolkit { const destToken = common.classifying(params.destToken); const wrappedSrcToken = wrapToken(this.chainId, srcToken); const wrappedDestToken = wrapToken(this.chainId, destToken); - const collateralSwapLogics: api.Logic[] = []; + const collateralSwapLogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); const afterPortfolio = portfolio.clone(); // ---------- flashloan ---------- - const flashLoanAggregatorQuotation = await api.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { + const flashLoanAggregatorQuotation = await apisdk.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { repays: [{ token: wrappedSrcToken, amount: srcAmount }], protocolId: protocolId, }); const flashLoanTokenAmount = flashLoanAggregatorQuotation.loans.tokenAmountMap[wrappedSrcToken.address]; - const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.utility.newFlashLoanAggregatorLogicPair( + const [flashLoanLoanLogic, flashLoanRepayLogic] = apisdk.protocols.utility.newFlashLoanAggregatorLogicPair( flashLoanAggregatorQuotation.protocolId, flashLoanAggregatorQuotation.loans.toArray() ); @@ -168,14 +168,14 @@ export class Adapter extends common.Web3Toolkit { if (protocolId !== 'compoundv3') { if (!supplyLogic.fields.output) throw new Error('incorrect supply result'); // ---------- return funds ---------- - const returnLogic = api.protocols.utility.newSendTokenLogic({ + const returnLogic = apisdk.protocols.utility.newSendTokenLogic({ input: supplyLogic.fields.output, recipient: account, }); collateralSwapLogics.push(returnLogic); // ---------- add funds ---------- - const addLogic = api.protocols.permit2.newPullTokenLogic({ + const addLogic = apisdk.protocols.permit2.newPullTokenLogic({ input: new common.TokenAmount(protocol.toProtocolToken(wrappedSrcToken), srcAmount), }); collateralSwapLogics.push(addLogic); @@ -194,7 +194,7 @@ export class Adapter extends common.Web3Toolkit { collateralSwapLogics.push(flashLoanRepayLogic); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -204,10 +204,10 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit, + args?: Omit, apiKey?: string ): Promise => - api.buildRouterTransactionRequest( + apisdk.buildRouterTransactionRequest( { ...args, chainId: this.chainId, account, logics: collateralSwapLogics }, apiKey ? { 'x-api-key': apiKey } : undefined ); @@ -246,7 +246,7 @@ export class Adapter extends common.Web3Toolkit { const wrappedSrcToken = wrapToken(this.chainId, srcToken); const wrappedDestToken = wrapToken(this.chainId, destToken); - const debtSwapLogics: api.Logic[] = []; + const debtSwapLogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -264,10 +264,10 @@ export class Adapter extends common.Web3Toolkit { swapQuotation = await swaper.quote({ input: swapQuotation.input, tokenOut: srcToken, slippage: defaultSlippage }); // ---------- flashloan ---------- - const flashLoanAggregatorQuotation = await api.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { + const flashLoanAggregatorQuotation = await apisdk.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { loans: [swapQuotation.input], }); - const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.utility.newFlashLoanAggregatorLogicPair( + const [flashLoanLoanLogic, flashLoanRepayLogic] = apisdk.protocols.utility.newFlashLoanAggregatorLogicPair( flashLoanAggregatorQuotation.protocolId, flashLoanAggregatorQuotation.loans.toArray() ); @@ -300,7 +300,7 @@ export class Adapter extends common.Web3Toolkit { debtSwapLogics.push(flashLoanRepayLogic); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -310,9 +310,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: debtSwapLogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: debtSwapLogics }); return { fields: { @@ -361,7 +361,7 @@ export class Adapter extends common.Web3Toolkit { const wrappedSrcToken = wrapToken(this.chainId, srcToken); const wrappedDestToken = wrapToken(this.chainId, destToken); - const leverageLonglogics: api.Logic[] = []; + const leverageLonglogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -383,11 +383,11 @@ export class Adapter extends common.Web3Toolkit { }); // ---------- flashloan ---------- - const flashLoanAggregatorQuotation = await api.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { + const flashLoanAggregatorQuotation = await apisdk.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { loans: [swapQuotation.input], }); - const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.utility.newFlashLoanAggregatorLogicPair( + const [flashLoanLoanLogic, flashLoanRepayLogic] = apisdk.protocols.utility.newFlashLoanAggregatorLogicPair( flashLoanAggregatorQuotation.protocolId, flashLoanAggregatorQuotation.loans.toArray() ); @@ -405,7 +405,7 @@ export class Adapter extends common.Web3Toolkit { // ---------- return funds ---------- if (supplyLogic.fields.output) { - const returnLogic = api.protocols.utility.newSendTokenLogic({ + const returnLogic = apisdk.protocols.utility.newSendTokenLogic({ input: supplyLogic.fields.output, recipient: account, }); @@ -427,7 +427,7 @@ export class Adapter extends common.Web3Toolkit { leverageLonglogics.push(flashLoanRepayLogic); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -437,9 +437,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: leverageLonglogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: leverageLonglogics }); return { fields: { @@ -458,7 +458,7 @@ export class Adapter extends common.Web3Toolkit { // 1. flashloan WBTC // 2. swap WBTC to USDC // 3. deposit USDC, get aUSDC - // 4. return funds aWBTC to user + // 4. return funds aUSDC to user // 5. borrow WBTC // 6. flashloan repay WBTC // * srcToken => flashloanToken, borrowToken @@ -475,20 +475,20 @@ export class Adapter extends common.Web3Toolkit { const destToken = common.classifying(params.destToken); const wrappedSrcToken = wrapToken(this.chainId, srcToken); const wrappedDestToken = wrapToken(this.chainId, destToken); - const leverageShortlogics: api.Logic[] = []; + const leverageShortlogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); const afterPortfolio = portfolio.clone(); // ---------- flashloan ---------- - const flashLoanAggregatorQuotation = await api.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { + const flashLoanAggregatorQuotation = await apisdk.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { loans: [{ token: wrappedSrcToken, amount: srcAmount }], }); const flashLoanTokenAmount = flashLoanAggregatorQuotation.loans.tokenAmountMap[wrappedSrcToken.address]; - const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.utility.newFlashLoanAggregatorLogicPair( + const [flashLoanLoanLogic, flashLoanRepayLogic] = apisdk.protocols.utility.newFlashLoanAggregatorLogicPair( flashLoanAggregatorQuotation.protocolId, flashLoanAggregatorQuotation.loans.toArray() ); @@ -512,7 +512,7 @@ export class Adapter extends common.Web3Toolkit { // ---------- return funds ---------- if (supplyLogic.fields.output) { - const returnLogic = api.protocols.utility.newSendTokenLogic({ + const returnLogic = apisdk.protocols.utility.newSendTokenLogic({ input: supplyLogic.fields.output, recipient: account, }); @@ -534,7 +534,7 @@ export class Adapter extends common.Web3Toolkit { leverageShortlogics.push(flashLoanRepayLogic); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -544,9 +544,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: leverageShortlogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: leverageShortlogics }); return { fields: { @@ -582,7 +582,7 @@ export class Adapter extends common.Web3Toolkit { const destToken = common.classifying(params.destToken); const wrappedSrcToken = wrapToken(this.chainId, srcToken); const wrappedDestToken = wrapToken(this.chainId, destToken); - const deleveragelogics: api.Logic[] = []; + const deleveragelogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -599,16 +599,16 @@ export class Adapter extends common.Web3Toolkit { // convert swap type to exact in swapQuotation = await swaper.quote({ input: swapQuotation.input, - tokenOut: wrappedSrcToken, + tokenOut: wrappedDestToken, slippage: defaultSlippage, }); // ---------- flashloan ---------- - const flashLoanAggregatorQuotation = await api.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { + const flashLoanAggregatorQuotation = await apisdk.protocols.utility.getFlashLoanAggregatorQuotation(this.chainId, { loans: [swapQuotation.input], }); - const [flashLoanLoanLogic, flashLoanRepayLogic] = api.protocols.utility.newFlashLoanAggregatorLogicPair( + const [flashLoanLoanLogic, flashLoanRepayLogic] = apisdk.protocols.utility.newFlashLoanAggregatorLogicPair( flashLoanAggregatorQuotation.protocolId, flashLoanAggregatorQuotation.loans.toArray() ); @@ -630,7 +630,7 @@ export class Adapter extends common.Web3Toolkit { // ---------- add funds ---------- if (protocolId !== 'compoundv3') { - const addLogic = api.protocols.permit2.newPullTokenLogic({ + const addLogic = apisdk.protocols.permit2.newPullTokenLogic({ input: swapQuotation.input, }); deleveragelogics.push(addLogic); @@ -648,7 +648,7 @@ export class Adapter extends common.Web3Toolkit { deleveragelogics.push(flashLoanRepayLogic); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -658,9 +658,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: deleveragelogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: deleveragelogics }); return { fields: { @@ -687,7 +687,7 @@ export class Adapter extends common.Web3Toolkit { const { srcAmount } = params; const srcToken = common.classifying(params.srcToken); const destToken = common.classifying(params.destToken); - const zapSupplylogics: api.Logic[] = []; + const zapSupplylogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -719,7 +719,7 @@ export class Adapter extends common.Web3Toolkit { afterPortfolio.supply(supplyTokenAmount.token, supplyTokenAmount.amount); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -729,9 +729,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapSupplylogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapSupplylogics }); return { fields: { @@ -758,7 +758,7 @@ export class Adapter extends common.Web3Toolkit { const { srcAmount } = params; const srcToken = common.classifying(params.srcToken); const destToken = common.classifying(params.destToken); - const zapWithdrawlogics: api.Logic[] = []; + const zapWithdrawlogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -769,7 +769,7 @@ export class Adapter extends common.Web3Toolkit { // ---------- withdraw ---------- const withdrawLogic = await protocol.newWithdrawLogic({ - output: new common.TokenAmount(srcToken, srcAmount), + output: outputTokenAmount, marketId, }); zapWithdrawlogics.push(withdrawLogic); @@ -790,7 +790,7 @@ export class Adapter extends common.Web3Toolkit { } // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -800,9 +800,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapWithdrawlogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapWithdrawlogics }); return { fields: { @@ -829,7 +829,7 @@ export class Adapter extends common.Web3Toolkit { const { srcAmount } = params; const srcToken = common.classifying(params.srcToken); const destToken = common.classifying(params.destToken); - const zapBorrowlogics: api.Logic[] = []; + const zapBorrowlogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -861,7 +861,7 @@ export class Adapter extends common.Web3Toolkit { zapBorrowlogics.push(swapTokenLogic); } // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -871,9 +871,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapBorrowlogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapBorrowlogics }); return { fields: { @@ -901,7 +901,7 @@ export class Adapter extends common.Web3Toolkit { const { srcAmount } = params; const srcToken = common.classifying(params.srcToken); const destToken = common.classifying(params.destToken); - const zapRepaylogics: api.Logic[] = []; + const zapRepaylogics: apisdk.Logic[] = []; const protocol = this.getProtocol(protocolId); portfolio = portfolio || (await protocol.getPortfolio(account, marketId)); @@ -935,7 +935,7 @@ export class Adapter extends common.Web3Toolkit { afterPortfolio.repay(repayTokenAmount.token, repayTokenAmount.amount); // ---------- tx related ---------- - const estimateResult = await api.estimateRouterData( + const estimateResult = await apisdk.estimateRouterData( { chainId: this.chainId, account, @@ -945,9 +945,9 @@ export class Adapter extends common.Web3Toolkit { ); const buildRouterTransactionRequest = ( - args?: Omit + args?: Omit ): Promise => - api.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapRepaylogics }); + apisdk.buildRouterTransactionRequest({ ...args, chainId: this.chainId, account, logics: zapRepaylogics }); return { fields: { diff --git a/packages/lending/src/adapter.type.ts b/packages/lending/src/adapter.type.ts index 8c7a0472..fcb55d1c 100644 --- a/packages/lending/src/adapter.type.ts +++ b/packages/lending/src/adapter.type.ts @@ -1,6 +1,6 @@ import { Logic } from './protocol.type'; import { Portfolio } from './protocol.portfolio'; -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; export type BaseFields = { @@ -12,9 +12,9 @@ export type BaseFields = { portfolio?: Portfolio; afterPortfolio?: Portfolio; }; - estimateResult: api.RouterDataEstimateResult; + estimateResult: apisdk.RouterDataEstimateResult; buildRouterTransactionRequest: ( - args?: Omit, + args?: Omit, apiKey?: string ) => Promise; logics: Logic[]; diff --git a/packages/lending/src/flashloaner.ts b/packages/lending/src/flashloaner.ts index acfe4056..30149248 100644 --- a/packages/lending/src/flashloaner.ts +++ b/packages/lending/src/flashloaner.ts @@ -1,5 +1,4 @@ -import { FlashLoanFields, FlashLoanLogic } from '@protocolink/api'; -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import * as logics from '@protocolink/logics'; import { providers } from 'ethers'; @@ -31,9 +30,11 @@ export abstract class FlashLoaner extends common.Web3Toolkit { return !!this.tokenMap[token.address]; } - abstract quote(params: api.protocols.aavev3.FlashLoanParams): Promise; + abstract quote(params: apisdk.protocols.aavev3.FlashLoanParams): Promise; - abstract newFlashLoanLogicPair(loans: FlashLoanFields['loans']): [FlashLoanLogic, FlashLoanLogic]; + abstract newFlashLoanLogicPair( + loans: apisdk.FlashLoanFields['loans'] + ): [apisdk.FlashLoanLogic, apisdk.FlashLoanLogic]; } export interface FlashLoanerClass { diff --git a/packages/lending/src/index.ts b/packages/lending/src/index.ts index 3a17d42e..776e22aa 100644 --- a/packages/lending/src/index.ts +++ b/packages/lending/src/index.ts @@ -1,7 +1,7 @@ // TODO: BOOOB -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; -api.init({ baseURL: 'https://api-beta.protocolink.com' }); +apisdk.init({ baseURL: 'https://api-beta.protocolink.com' }); export * as adapter from './adapter'; export * as protocol from './protocol'; diff --git a/packages/lending/src/protocols/aave-v2/lending-protocol.ts b/packages/lending/src/protocols/aave-v2/lending-protocol.ts index 8fe4e3f2..f7710aea 100644 --- a/packages/lending/src/protocols/aave-v2/lending-protocol.ts +++ b/packages/lending/src/protocols/aave-v2/lending-protocol.ts @@ -28,9 +28,9 @@ import { PriceOracleInterface } from './contracts/PriceOracle'; import { Protocol } from 'src/protocol'; import { ProtocolDataProviderInterface } from './contracts/ProtocolDataProvider'; import { RAY_DECIMALS, SECONDS_PER_YEAR, calculateCompoundedRate, normalize } from '@aave/math-utils'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import { isWrappedNativeToken, wrapToken } from 'src/helper'; -import { protocols } from '@protocolink/api'; export class LendingProtocol extends Protocol { static readonly markets = supportedChainIds.map((chainId) => ({ @@ -330,34 +330,34 @@ export class LendingProtocol extends Protocol { } async newSupplyLogic(params: SupplyParams) { - const supplyQuotation = await protocols.aavev2.getDepositQuotation(this.chainId, { + const supplyQuotation = await apisdk.protocols.aavev2.getDepositQuotation(this.chainId, { input: params.input, tokenOut: toAToken(this.chainId, params.input.token), }); - return protocols.aavev2.newDepositLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); + return apisdk.protocols.aavev2.newDepositLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); } async newWithdrawLogic(params: WithdrawParams) { - const withdrawQuotation = await protocols.aavev2.getWithdrawQuotation(this.chainId, { + const withdrawQuotation = await apisdk.protocols.aavev2.getWithdrawQuotation(this.chainId, { input: { token: toAToken(this.chainId, params.output.token), amount: params.output.amount, }, tokenOut: params.output.token, }); - return protocols.aavev2.newWithdrawLogic(withdrawQuotation); + return apisdk.protocols.aavev2.newWithdrawLogic(withdrawQuotation); } - newBorrowLogic = protocols.aavev2.newBorrowLogic; + newBorrowLogic = apisdk.protocols.aavev2.newBorrowLogic; async newRepayLogic(params: RepayParams) { if (!params.borrower || !params.interestRateMode) throw new Error('missing requied params'); - const repayQuotation = await protocols.aavev2.getRepayQuotation(this.chainId, { + const repayQuotation = await apisdk.protocols.aavev2.getRepayQuotation(this.chainId, { tokenIn: params.input.token, borrower: params.borrower, interestRateMode: params.interestRateMode, }); repayQuotation.input.amount = params.input.amount; - return protocols.aavev2.newRepayLogic(repayQuotation); + return apisdk.protocols.aavev2.newRepayLogic(repayQuotation); } } diff --git a/packages/lending/src/protocols/aave-v3/lending-protocol.ts b/packages/lending/src/protocols/aave-v3/lending-protocol.ts index cf8ea1e3..c40ced6c 100644 --- a/packages/lending/src/protocols/aave-v3/lending-protocol.ts +++ b/packages/lending/src/protocols/aave-v3/lending-protocol.ts @@ -29,9 +29,9 @@ import { PoolDataProviderInterface } from './contracts/PoolDataProvider'; import { Portfolio } from 'src/protocol.portfolio'; import { Protocol } from 'src/protocol'; import { RAY_DECIMALS, SECONDS_PER_YEAR, calculateCompoundedRate, normalize } from '@aave/math-utils'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import { isWrappedNativeToken, wrapToken } from 'src/helper'; -import { protocols } from '@protocolink/api'; export class LendingProtocol extends Protocol { static readonly markets = supportedChainIds.map((chainId) => ({ @@ -334,34 +334,34 @@ export class LendingProtocol extends Protocol { } async newSupplyLogic(params: SupplyParams) { - const supplyQuotation = await protocols.aavev3.getSupplyQuotation(this.chainId, { + const supplyQuotation = await apisdk.protocols.aavev3.getSupplyQuotation(this.chainId, { input: params.input, tokenOut: toAToken(this.chainId, params.input.token), }); - return protocols.aavev3.newSupplyLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); + return apisdk.protocols.aavev3.newSupplyLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); } async newWithdrawLogic(params: WithdrawParams) { - const withdrawQuotation = await protocols.aavev3.getWithdrawQuotation(this.chainId, { + const withdrawQuotation = await apisdk.protocols.aavev3.getWithdrawQuotation(this.chainId, { input: { token: toAToken(this.chainId, params.output.token), amount: params.output.amount, }, tokenOut: params.output.token, }); - return protocols.aavev3.newWithdrawLogic(withdrawQuotation); + return apisdk.protocols.aavev3.newWithdrawLogic(withdrawQuotation); } - newBorrowLogic = protocols.aavev3.newBorrowLogic; + newBorrowLogic = apisdk.protocols.aavev3.newBorrowLogic; async newRepayLogic(params: RepayParams) { if (!params.borrower || !params.interestRateMode) throw new Error('missing requied params'); - const repayQuotation = await protocols.aavev3.getRepayQuotation(this.chainId, { + const repayQuotation = await apisdk.protocols.aavev3.getRepayQuotation(this.chainId, { tokenIn: params.input.token, borrower: params.borrower, interestRateMode: params.interestRateMode, }); repayQuotation.input.amount = params.input.amount; - return protocols.aavev3.newRepayLogic(repayQuotation); + return apisdk.protocols.aavev3.newRepayLogic(repayQuotation); } } diff --git a/packages/lending/src/protocols/compound-v3/lending-protocol.ts b/packages/lending/src/protocols/compound-v3/lending-protocol.ts index 5b1acdeb..53667d9b 100644 --- a/packages/lending/src/protocols/compound-v3/lending-protocol.ts +++ b/packages/lending/src/protocols/compound-v3/lending-protocol.ts @@ -13,10 +13,10 @@ import { } from './configs'; import { Portfolio } from 'src/protocol.portfolio'; import { Protocol } from 'src/protocol'; +import * as apisdk from '@protocolink/api'; import { calcAPR } from './utils'; import * as common from '@protocolink/common'; import * as logics from '@protocolink/logics'; -import { protocols } from '@protocolink/api'; import { unwrapToken, wrapToken } from 'src/helper'; export class LendingProtocol extends Protocol { @@ -307,14 +307,14 @@ export class LendingProtocol extends Protocol { const { cometAddress, baseToken } = getMarketBaseConfig(this.chainId, params.marketId); const cToken = await this.getToken(cometAddress); if (params.input.token.unwrapped.is(baseToken.unwrapped)) { - const supplyQuotation = await protocols.compoundv3.getSupplyBaseQuotation(this.chainId, { + const supplyQuotation = await apisdk.protocols.compoundv3.getSupplyBaseQuotation(this.chainId, { input: params.input, tokenOut: cToken, marketId: params.marketId, }); - return protocols.compoundv3.newSupplyBaseLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); + return apisdk.protocols.compoundv3.newSupplyBaseLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); } else { - return protocols.compoundv3.newSupplyCollateralLogic({ + return apisdk.protocols.compoundv3.newSupplyCollateralLogic({ input: params.input, marketId: params.marketId, balanceBps: common.BPS_BASE, @@ -329,7 +329,7 @@ export class LendingProtocol extends Protocol { const realAmount = new common.TokenAmount(params.output.token, params.output.amount); realAmount.subWei(2); if (params.output.token.wrapped.is(baseToken)) { - const withdrawBaseQuotation = await protocols.compoundv3.getWithdrawBaseQuotation(this.chainId, { + const withdrawBaseQuotation = await apisdk.protocols.compoundv3.getWithdrawBaseQuotation(this.chainId, { input: { token: cToken, amount: realAmount.amount, @@ -337,26 +337,29 @@ export class LendingProtocol extends Protocol { tokenOut: params.output.token, marketId: params.marketId, }); - const withdrawBaseLogic = await protocols.compoundv3.newWithdrawBaseLogic({ + const withdrawBaseLogic = await apisdk.protocols.compoundv3.newWithdrawBaseLogic({ ...withdrawBaseQuotation, balanceBps: common.BPS_BASE, }); withdrawBaseLogic.fields.output.amount = realAmount.subWei(1).amount; return withdrawBaseLogic; } else { - return protocols.compoundv3.newWithdrawCollateralLogic({ output: params.output, marketId: params.marketId }); + return apisdk.protocols.compoundv3.newWithdrawCollateralLogic({ + output: params.output, + marketId: params.marketId, + }); } } - newBorrowLogic = protocols.compoundv3.newBorrowLogic; + newBorrowLogic = apisdk.protocols.compoundv3.newBorrowLogic; async newRepayLogic(params: RepayParams): Promise { - const repayQuotation = await protocols.compoundv3.getRepayQuotation(this.chainId, { + const repayQuotation = await apisdk.protocols.compoundv3.getRepayQuotation(this.chainId, { tokenIn: params.input.token, borrower: params.borrower, marketId: params.marketId, }); repayQuotation.input.amount = params.input.amount; - return protocols.compoundv3.newRepayLogic(repayQuotation); + return apisdk.protocols.compoundv3.newRepayLogic(repayQuotation); } } diff --git a/packages/lending/src/protocols/openocean-v2/lending-swaper.ts b/packages/lending/src/protocols/openocean-v2/lending-swaper.ts index 49abb9a3..bdab8444 100644 --- a/packages/lending/src/protocols/openocean-v2/lending-swaper.ts +++ b/packages/lending/src/protocols/openocean-v2/lending-swaper.ts @@ -1,9 +1,8 @@ import { NAME } from './configs'; import { Swaper } from 'src/swaper'; -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import * as logics from '@protocolink/logics'; -import { quote } from '@protocolink/api'; export class LendingSwaper extends Swaper { static readonly supportedChainIds = [1088]; @@ -19,17 +18,17 @@ export class LendingSwaper extends Swaper { async tokens() { if (!this._tokens) { - this._tokens = await api.protocols.openoceanv2.getSwapTokenTokenList(this.chainId); + this._tokens = await apisdk.protocols.openoceanv2.getSwapTokenTokenList(this.chainId); } return this._tokens!; } - async quote(params: api.protocols.paraswapv5.SwapTokenParams): Promise { - return await quote(this.chainId, logics.openoceanv2.SwapTokenLogic.rid, params); + async quote(params: apisdk.protocols.openoceanv2.SwapTokenParams): Promise { + return await apisdk.quote(this.chainId, logics.openoceanv2.SwapTokenLogic.rid, params); } - newSwapTokenLogic(fields: api.protocols.openoceanv2.SwapTokenFields): api.protocols.openoceanv2.SwapTokenLogic { - return api.protocols.openoceanv2.newSwapTokenLogic(fields); + newSwapTokenLogic(fields: apisdk.protocols.openoceanv2.SwapTokenFields): apisdk.protocols.openoceanv2.SwapTokenLogic { + return apisdk.protocols.openoceanv2.newSwapTokenLogic(fields); } isExactIn() { diff --git a/packages/lending/src/protocols/paraswap-v5/lending-swaper.ts b/packages/lending/src/protocols/paraswap-v5/lending-swaper.ts index b6cf332f..2f34e910 100644 --- a/packages/lending/src/protocols/paraswap-v5/lending-swaper.ts +++ b/packages/lending/src/protocols/paraswap-v5/lending-swaper.ts @@ -1,9 +1,8 @@ import { NAME } from './configs'; import { Swaper } from 'src/swaper'; -import * as api from '@protocolink/api'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import * as logics from '@protocolink/logics'; -import { quote } from '@protocolink/api'; export class LendingSwaper extends Swaper { static readonly supportedChainIds = [1, 10, 137, 42161, 43114]; @@ -19,17 +18,17 @@ export class LendingSwaper extends Swaper { async tokens() { if (!this._tokens) { - this._tokens = await api.protocols.paraswapv5.getSwapTokenTokenList(this.chainId); + this._tokens = await apisdk.protocols.paraswapv5.getSwapTokenTokenList(this.chainId); } return this._tokens!; } - async quote(params: api.protocols.paraswapv5.SwapTokenParams): Promise { - return await quote(this.chainId, logics.paraswapv5.SwapTokenLogic.rid, params); + async quote(params: apisdk.protocols.paraswapv5.SwapTokenParams): Promise { + return await apisdk.quote(this.chainId, logics.paraswapv5.SwapTokenLogic.rid, params); } - newSwapTokenLogic(fields: api.protocols.paraswapv5.SwapTokenFields): api.protocols.paraswapv5.SwapTokenLogic { - return api.protocols.paraswapv5.newSwapTokenLogic(fields); + newSwapTokenLogic(fields: apisdk.protocols.paraswapv5.SwapTokenFields): apisdk.protocols.paraswapv5.SwapTokenLogic { + return apisdk.protocols.paraswapv5.newSwapTokenLogic(fields); } isExactIn() { diff --git a/packages/lending/src/protocols/radiant-v2/lending-protocol.ts b/packages/lending/src/protocols/radiant-v2/lending-protocol.ts index 609b833a..623928d6 100644 --- a/packages/lending/src/protocols/radiant-v2/lending-protocol.ts +++ b/packages/lending/src/protocols/radiant-v2/lending-protocol.ts @@ -24,9 +24,9 @@ import { PriceOracleInterface } from './contracts/PriceOracle'; import { Protocol } from 'src/protocol'; import { ProtocolDataProviderInterface } from './contracts/ProtocolDataProvider'; import { RAY_DECIMALS, SECONDS_PER_YEAR, calculateCompoundedRate, normalize } from '@aave/math-utils'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import { isWrappedNativeToken, wrapToken } from 'src/helper'; -import { protocols } from '@protocolink/api'; import { providers } from 'ethers'; export class LendingProtocol extends Protocol { @@ -280,34 +280,34 @@ export class LendingProtocol extends Protocol { } async newSupplyLogic(params: SupplyParams) { - const supplyQuotation = await protocols.radiantv2.getDepositQuotation(this.chainId, { + const supplyQuotation = await apisdk.protocols.radiantv2.getDepositQuotation(this.chainId, { input: params.input, tokenOut: toRToken(this.chainId, params.input.token), }); - return protocols.radiantv2.newDepositLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); + return apisdk.protocols.radiantv2.newDepositLogic({ ...supplyQuotation, balanceBps: common.BPS_BASE }); } async newWithdrawLogic(params: WithdrawParams) { - const withdrawQuotation = await protocols.radiantv2.getWithdrawQuotation(this.chainId, { + const withdrawQuotation = await apisdk.protocols.radiantv2.getWithdrawQuotation(this.chainId, { input: { token: toRToken(this.chainId, params.output.token), amount: params.output.amount, }, tokenOut: params.output.token, }); - return protocols.radiantv2.newWithdrawLogic(withdrawQuotation); + return apisdk.protocols.radiantv2.newWithdrawLogic(withdrawQuotation); } - newBorrowLogic = protocols.radiantv2.newBorrowLogic; + newBorrowLogic = apisdk.protocols.radiantv2.newBorrowLogic; async newRepayLogic(params: RepayParams) { if (!params.borrower || !params.interestRateMode) throw new Error('missing requied params'); - const repayQuotation = await protocols.radiantv2.getRepayQuotation(this.chainId, { + const repayQuotation = await apisdk.protocols.radiantv2.getRepayQuotation(this.chainId, { tokenIn: params.input.token, borrower: params.borrower, interestRateMode: params.interestRateMode, }); repayQuotation.input.amount = params.input.amount; - return protocols.radiantv2.newRepayLogic(repayQuotation); + return apisdk.protocols.radiantv2.newRepayLogic(repayQuotation); } } diff --git a/packages/lending/src/swaper.ts b/packages/lending/src/swaper.ts index 1049456f..dd0ca1ea 100644 --- a/packages/lending/src/swaper.ts +++ b/packages/lending/src/swaper.ts @@ -1,5 +1,5 @@ -import { TokenToTokenParams } from './swaper.type'; -import * as api from '@protocolink/api'; +import { SwapTokenLogicParams } from './swaper.type'; +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; import * as logics from '@protocolink/logics'; import { providers } from 'ethers'; @@ -20,11 +20,11 @@ export abstract class Swaper extends common.Web3Toolkit { return true; } - abstract quote(params: TokenToTokenParams): Promise; + abstract quote(params: SwapTokenLogicParams): Promise; - abstract newSwapTokenLogic(fields: any): api.protocols.paraswapv5.SwapTokenLogic; + abstract newSwapTokenLogic(fields: any): apisdk.protocols.paraswapv5.SwapTokenLogic; - abstract isExactIn(logic: api.protocols.paraswapv5.SwapTokenLogic): boolean; + abstract isExactIn(logic: apisdk.protocols.paraswapv5.SwapTokenLogic): boolean; } export interface SwaperClass { diff --git a/packages/lending/src/swaper.type.ts b/packages/lending/src/swaper.type.ts index 94fede20..6fb217f4 100644 --- a/packages/lending/src/swaper.type.ts +++ b/packages/lending/src/swaper.type.ts @@ -1,3 +1,4 @@ +import * as apisdk from '@protocolink/api'; import * as common from '@protocolink/common'; export enum TradeType { @@ -19,6 +20,10 @@ export interface TokenToTokenExactOutParams { export type TokenToTokenParams = TokenToTokenExactInParams | TokenToTokenExactOutParams; +export type SwapTokenLogicParams = + | apisdk.protocols.openoceanv2.SwapTokenParams + | apisdk.protocols.paraswapv5.SwapTokenParams; + export function isTokenToTokenExactInParams(v: any): v is TokenToTokenExactInParams { return !!v.input && !!v.tokenOut; } diff --git a/packages/lending/test/transactions/collateral-swap.ts b/packages/lending/test/transactions/collateral-swap.ts index b88c0bf3..78be27f9 100644 --- a/packages/lending/test/transactions/collateral-swap.ts +++ b/packages/lending/test/transactions/collateral-swap.ts @@ -3,7 +3,7 @@ import { Portfolio } from 'src/protocol.portfolio'; import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import * as aaveV2 from 'src/protocols/aave-v2/tokens'; import * as aaveV3 from 'src/protocols/aave-v3/tokens'; -import { claimToken } from '@protocolink/test-helpers'; +import { claimToken, getBalance } from '@protocolink/test-helpers'; import * as compoundV3 from 'src/protocols/compound-v3/tokens'; import { expect } from 'chai'; import hre from 'hardhat'; @@ -27,7 +27,7 @@ describe('Transaction: Collateral swap', function () { { skip: false, testingAccount: '0x06e4Cb4f3ba9A2916B6384aCbdeAa74dAAF91550', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.WBTC, @@ -38,13 +38,13 @@ describe('Transaction: Collateral swap', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { - skip: false, + skip: true, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v3', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.WBTC, @@ -55,13 +55,13 @@ describe('Transaction: Collateral swap', function () { funds: [], balances: [], apporveTimes: 0, - recieves: [], + receives: [], }, }, { - skip: false, + skip: true, testingAccount: '0x7F67F6A09bcb2159b094B64B4acc53D5193AEa2E', - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', params: { srcToken: aaveV2.mainnetTokens.WBTC, @@ -72,13 +72,13 @@ describe('Transaction: Collateral swap', function () { funds: [], balances: [], apporveTimes: 0, - recieves: [], + receives: [], }, }, { - skip: false, + skip: true, testingAccount: '0xA38D6E3Aa9f3E4F81D4cEf9B8bCdC58aB37d066A', - protocolId: 'radiantv2', + protocolId: 'radiant-v2', marketId: 'mainnet', params: { srcToken: radiantV2.mainnetTokens.WBTC, @@ -89,16 +89,21 @@ describe('Transaction: Collateral swap', function () { funds: [], balances: [], apporveTimes: 0, - recieves: [], + receives: [], }, }, ]; for (const [i, { skip, testingAccount, protocolId, marketId, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); + // before balance + const beforeBalance = await getBalance(user.address, aaveV3.mainnetTokens.aEthWBTC); + console.log('before balance', JSON.stringify(beforeBalance.amount.toString(), null, 2)); + const { estimateResult, buildRouterTransactionRequest } = await adapter.getCollateralSwap( protocolId, marketId, @@ -120,6 +125,10 @@ describe('Transaction: Collateral swap', function () { const tx = await user.sendTransaction(transactionRequest); expect(tx).to.not.be.reverted; + + // after balance + const afterBalance = await getBalance(user.address, aaveV3.mainnetTokens.aEthWBTC); + console.log('after balance', JSON.stringify(afterBalance.amount.toString(), null, 2)); }); } }); diff --git a/packages/lending/test/transactions/debt-swap.ts b/packages/lending/test/transactions/debt-swap.ts index b5b21dae..4470f0ec 100644 --- a/packages/lending/test/transactions/debt-swap.ts +++ b/packages/lending/test/transactions/debt-swap.ts @@ -22,7 +22,7 @@ describe('Transaction: Debt swap', function () { { skip: false, testingAccount: '0x06e4Cb4f3ba9A2916B6384aCbdeAa74dAAF91550', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.USDC, @@ -33,13 +33,13 @@ describe('Transaction: Debt swap', function () { funds: [], balances: [], apporveTimes: 1, // approveDelegation - recieves: [], + receives: [], }, }, { skip: false, testingAccount: '0x7F67F6A09bcb2159b094B64B4acc53D5193AEa2E', - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', params: { srcToken: aaveV2.mainnetTokens.USDC, @@ -50,7 +50,7 @@ describe('Transaction: Debt swap', function () { funds: [], balances: [], apporveTimes: 1, // approveDelegation - recieves: [], + receives: [], }, }, { @@ -67,14 +67,14 @@ describe('Transaction: Debt swap', function () { funds: [], balances: [], apporveTimes: 1, // approveDelegation - recieves: [], + receives: [], }, }, ]; for (const [i, { skip, testingAccount, protocolId, marketId, params, expects }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getDebtSwap( diff --git a/packages/lending/test/transactions/deleverage.ts b/packages/lending/test/transactions/deleverage.ts index 60c32783..7ba8ac9d 100644 --- a/packages/lending/test/transactions/deleverage.ts +++ b/packages/lending/test/transactions/deleverage.ts @@ -23,7 +23,7 @@ describe('Transaction: Deleverage', function () { { skip: true, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.USDC, @@ -34,13 +34,13 @@ describe('Transaction: Deleverage', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { skip: true, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.USDC, @@ -51,13 +51,13 @@ describe('Transaction: Deleverage', function () { funds: [], balances: [], apporveTimes: 0, - recieves: [], + receives: [], }, }, { skip: true, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', params: { srcToken: aaveV2.mainnetTokens.DAI, @@ -68,7 +68,7 @@ describe('Transaction: Deleverage', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { @@ -85,14 +85,14 @@ describe('Transaction: Deleverage', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, ]; for (const [i, { skip, testingAccount, protocolId, marketId, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getDeleverage( diff --git a/packages/lending/test/transactions/leverage-long.ts b/packages/lending/test/transactions/leverage-long.ts index daa770f9..b14e0216 100644 --- a/packages/lending/test/transactions/leverage-long.ts +++ b/packages/lending/test/transactions/leverage-long.ts @@ -23,7 +23,7 @@ describe('Transaction: Leverage Long', function () { { skip: false, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.ETH, @@ -34,13 +34,13 @@ describe('Transaction: Leverage Long', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { skip: false, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.ETH, @@ -51,7 +51,7 @@ describe('Transaction: Leverage Long', function () { funds: [], balances: [], apporveTimes: 0, - recieves: [], + receives: [], }, }, ]; @@ -59,7 +59,7 @@ describe('Transaction: Leverage Long', function () { for (const [i, { skip, testingAccount, protocolId, marketId, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getLeverageLong( diff --git a/packages/lending/test/transactions/leverage-short.ts b/packages/lending/test/transactions/leverage-short.ts index bc9b3ddb..bc70742e 100644 --- a/packages/lending/test/transactions/leverage-short.ts +++ b/packages/lending/test/transactions/leverage-short.ts @@ -23,7 +23,7 @@ describe('Transaction: Leverage Short', function () { { skip: false, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.USDC, @@ -34,7 +34,7 @@ describe('Transaction: Leverage Short', function () { funds: [], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, ]; @@ -42,7 +42,7 @@ describe('Transaction: Leverage Short', function () { for (const [i, { skip, testingAccount, protocolId, marketId, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getLeverageShort( diff --git a/packages/lending/test/transactions/zap-borrow.ts b/packages/lending/test/transactions/zap-borrow.ts index 02151fb7..882ff9a4 100644 --- a/packages/lending/test/transactions/zap-borrow.ts +++ b/packages/lending/test/transactions/zap-borrow.ts @@ -23,7 +23,7 @@ describe('Transaction: Zap Borrow', function () { { skip: false, testingAccount: '0x06e4Cb4f3ba9A2916B6384aCbdeAa74dAAF91550', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.USDC, @@ -34,7 +34,7 @@ describe('Transaction: Zap Borrow', function () { { skip: false, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.USDC, @@ -45,7 +45,7 @@ describe('Transaction: Zap Borrow', function () { { skip: false, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.USDC, @@ -55,7 +55,7 @@ describe('Transaction: Zap Borrow', function () { }, { skip: false, - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', testingAccount: '0x7F67F6A09bcb2159b094B64B4acc53D5193AEa2E', params: { @@ -79,7 +79,7 @@ describe('Transaction: Zap Borrow', function () { for (const [i, { skip, testingAccount, protocolId, marketId, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getZapBorrow( diff --git a/packages/lending/test/transactions/zap-repay.ts b/packages/lending/test/transactions/zap-repay.ts index 1812a8fd..83876fa7 100644 --- a/packages/lending/test/transactions/zap-repay.ts +++ b/packages/lending/test/transactions/zap-repay.ts @@ -27,7 +27,7 @@ describe('Transaction: Zap Repay', function () { const testCases = [ { skip: false, - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', testingAccount: '0x06e4Cb4f3ba9A2916B6384aCbdeAa74dAAF91550', params: { @@ -38,7 +38,7 @@ describe('Transaction: Zap Repay', function () { }, { skip: false, - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', params: { @@ -49,7 +49,7 @@ describe('Transaction: Zap Repay', function () { }, { skip: false, - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', testingAccount: '0x7F67F6A09bcb2159b094B64B4acc53D5193AEa2E', params: { @@ -73,7 +73,7 @@ describe('Transaction: Zap Repay', function () { for (const [i, { skip, protocolId, marketId, testingAccount, params }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); portfolio = await adapter.getPortfolio(user.address, protocolId, marketId); diff --git a/packages/lending/test/transactions/zap-supply-arbitrum.ts b/packages/lending/test/transactions/zap-supply-arbitrum.ts index 7003a9ed..a663d137 100644 --- a/packages/lending/test/transactions/zap-supply-arbitrum.ts +++ b/packages/lending/test/transactions/zap-supply-arbitrum.ts @@ -39,14 +39,14 @@ describe.skip('Transaction: Zap Supply Arbitrum', function () { funds: [radiantV2ArbitrumTokens.USDC], balances: [radiantV2ArbitrumTokens.rWBTC], apporveTimes: 2, - recieves: [radiantV2ArbitrumTokens.rWBTC], + receives: [radiantV2ArbitrumTokens.rWBTC], }, }, ]; for (const [i, { skip, protocolId, marketId, params, expects }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { const zapDepositInfo = await adapter.getZapSupply(protocolId, marketId, params, user.address); const estimateResult = zapDepositInfo.estimateResult; @@ -66,7 +66,7 @@ describe.skip('Transaction: Zap Supply Arbitrum', function () { const tx = await user.sendTransaction(transactionRequest); expect(tx).to.not.be.reverted; - for (const recv of expects.recieves) { + for (const recv of expects.receives) { const balance = await getBalance(user.address, recv); expect(balance.gt('0')).to.be.true; } diff --git a/packages/lending/test/transactions/zap-supply.ts b/packages/lending/test/transactions/zap-supply.ts index d5a0050c..ddd64284 100644 --- a/packages/lending/test/transactions/zap-supply.ts +++ b/packages/lending/test/transactions/zap-supply.ts @@ -28,7 +28,7 @@ describe('Transaction: Zap Supply', function () { const testCases = [ { skip: false, - protocolId: 'radiantv2', + protocolId: 'radiant-v2', marketId: 'mainnet', params: { srcToken: radiantV2.mainnetTokens.USDC, @@ -39,12 +39,12 @@ describe('Transaction: Zap Supply', function () { funds: [radiantV2.mainnetTokens.USDC], balances: [radiantV2.mainnetTokens.rWBTC], apporveTimes: 2, - recieves: [radiantV2.mainnetTokens.rWBTC], + receives: [radiantV2.mainnetTokens.rWBTC], }, }, { skip: false, - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.USDC, @@ -55,12 +55,12 @@ describe('Transaction: Zap Supply', function () { funds: [aaveV3.mainnetTokens.USDC], balances: [aaveV3.mainnetTokens.aEthWBTC], apporveTimes: 2, - recieves: [aaveV3.mainnetTokens.aEthWBTC], + receives: [aaveV3.mainnetTokens.aEthWBTC], }, }, { skip: false, - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.WETH, @@ -71,12 +71,12 @@ describe('Transaction: Zap Supply', function () { funds: [compoundV3.mainnetTokens.WETH], balances: [compoundV3.mainnetTokens.cUSDCv3], apporveTimes: 2, - recieves: [compoundV3.mainnetTokens.cUSDCv3], + receives: [compoundV3.mainnetTokens.cUSDCv3], }, }, { skip: false, - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.WETH, @@ -87,12 +87,12 @@ describe('Transaction: Zap Supply', function () { funds: [compoundV3.mainnetTokens.WETH], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { skip: false, - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.WETH, @@ -103,12 +103,12 @@ describe('Transaction: Zap Supply', function () { funds: [compoundV3.mainnetTokens.WETH], balances: [], apporveTimes: 2, - recieves: [], + receives: [], }, }, { skip: false, - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'ETH', params: { srcToken: compoundV3.mainnetTokens.WETH, @@ -119,12 +119,12 @@ describe('Transaction: Zap Supply', function () { funds: [compoundV3.mainnetTokens.WETH], balances: [compoundV3.mainnetTokens.cWETHv3], apporveTimes: 2, - recieves: [compoundV3.mainnetTokens.cWETHv3], + receives: [compoundV3.mainnetTokens.cWETHv3], }, }, { skip: false, - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', params: { srcToken: aaveV2.mainnetTokens.USDC, @@ -135,7 +135,7 @@ describe('Transaction: Zap Supply', function () { funds: [aaveV2.mainnetTokens.USDC], balances: [aaveV2.mainnetTokens.aWBTC], apporveTimes: 2, - recieves: [aaveV2.mainnetTokens.aWBTC], + receives: [aaveV2.mainnetTokens.aWBTC], }, }, ]; @@ -143,7 +143,7 @@ describe('Transaction: Zap Supply', function () { for (const [i, { skip, protocolId, marketId, params, expects }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { const zapDepositInfo = await adapter.getZapSupply(protocolId, marketId, params, user.address); const estimateResult = zapDepositInfo.estimateResult; @@ -162,7 +162,7 @@ describe('Transaction: Zap Supply', function () { const tx = await user.sendTransaction(transactionRequest); expect(tx).to.not.be.reverted; - for (const recv of expects.recieves) { + for (const recv of expects.receives) { const balance = await getBalance(user.address, recv); expect(balance.gt('0')).to.be.true; diff --git a/packages/lending/test/transactions/zap-withdraw.ts b/packages/lending/test/transactions/zap-withdraw.ts index 4e40bc77..c4fc363e 100644 --- a/packages/lending/test/transactions/zap-withdraw.ts +++ b/packages/lending/test/transactions/zap-withdraw.ts @@ -23,7 +23,7 @@ describe('Transaction: Zap Withdraw', function () { { skip: false, testingAccount: '0x06e4Cb4f3ba9A2916B6384aCbdeAa74dAAF91550', - protocolId: 'aavev3', + protocolId: 'aave-v3', marketId: 'mainnet', params: { srcToken: aaveV3.mainnetTokens.WBTC, @@ -34,13 +34,13 @@ describe('Transaction: Zap Withdraw', function () { funds: [aaveV3.mainnetTokens.aEthWBTC], balances: [aaveV3.mainnetTokens.USDC], apporveTimes: 2, - recieves: [aaveV3.mainnetTokens.USDC], + receives: [aaveV3.mainnetTokens.USDC], }, }, { skip: false, testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'ETH', params: { srcToken: compoundV3.mainnetTokens.ETH, @@ -51,13 +51,13 @@ describe('Transaction: Zap Withdraw', function () { funds: [compoundV3.mainnetTokens.cWETHv3], balances: [compoundV3.mainnetTokens.USDC], apporveTimes: 2, - recieves: [compoundV3.mainnetTokens.USDC], + receives: [compoundV3.mainnetTokens.USDC], }, }, { skip: false, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.ETH, @@ -68,13 +68,13 @@ describe('Transaction: Zap Withdraw', function () { funds: [], balances: [compoundV3.mainnetTokens.USDC], apporveTimes: 1, - recieves: [compoundV3.mainnetTokens.USDC], + receives: [compoundV3.mainnetTokens.USDC], }, }, { skip: false, testingAccount: '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB', - protocolId: 'compoundv3', + protocolId: 'compound-v2', marketId: 'USDC', params: { srcToken: compoundV3.mainnetTokens.ETH, @@ -85,13 +85,13 @@ describe('Transaction: Zap Withdraw', function () { funds: [], balances: [compoundV3.mainnetTokens.USDC], apporveTimes: 1, - recieves: [compoundV3.mainnetTokens.ETH], + receives: [compoundV3.mainnetTokens.ETH], }, }, { skip: false, testingAccount: '0x7F67F6A09bcb2159b094B64B4acc53D5193AEa2E', - protocolId: 'aavev2', + protocolId: 'aave-v2', marketId: 'mainnet', params: { srcToken: aaveV2.mainnetTokens.WBTC, @@ -102,7 +102,7 @@ describe('Transaction: Zap Withdraw', function () { funds: [aaveV2.mainnetTokens.aWBTC], balances: [aaveV2.mainnetTokens.USDC], apporveTimes: 2, - recieves: [aaveV2.mainnetTokens.USDC], + receives: [aaveV2.mainnetTokens.USDC], }, }, { @@ -119,14 +119,14 @@ describe('Transaction: Zap Withdraw', function () { funds: [radiantV2.mainnetTokens.rWBTC], balances: [radiantV2.mainnetTokens.USDC], apporveTimes: 2, - recieves: [radiantV2.mainnetTokens.USDC], + receives: [radiantV2.mainnetTokens.USDC], }, }, ]; for (const [i, { skip, testingAccount, protocolId, marketId, params, expects }] of testCases.entries()) { if (skip) continue; - it.only(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { + it(`case ${i + 1} - ${protocolId}:${marketId}`, async function () { user = await hre.ethers.getImpersonatedSigner(testingAccount); const { estimateResult, buildRouterTransactionRequest } = await adapter.getZapWithdraw(