Skip to content

Commit

Permalink
fix: rename swaper to swapper, add base token to portfolio, fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Lu committed Dec 10, 2023
1 parent cb162b3 commit 1282772
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 109 deletions.
4 changes: 2 additions & 2 deletions packages/lending/src/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Adapter } from './adapter';
import { BaseParams } from './adapter.type';
import { LendingProtocol } from './protocols/aave-v3/lending-protocol';
import { LendingSwaper } from './protocols/paraswap-v5/lending-swaper';
import { LendingSwapper } from './protocols/paraswap-v5/lending-swapper';
import { Portfolio } from './protocol.portfolio';
import { expect } from 'chai';
import { mainnetTokens } from '@protocolink/test-helpers';
Expand Down Expand Up @@ -87,7 +87,7 @@ const zapRepayTestCases: BaseParams[] = [

describe('Lending AaveV3 SDK', function () {
Adapter.registerProtocol(LendingProtocol);
Adapter.registerSwaper(LendingSwaper);
Adapter.registerSwapper(LendingSwapper);
const adapter = new Adapter(1, provider);
const protocolId = 'aave-v3';

Expand Down
154 changes: 80 additions & 74 deletions packages/lending/src/adapter.ts

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions packages/lending/src/protocol.portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class Portfolio {
chainId: number;
protocolId: string;
marketId: string;
baseToken?: common.Token;
supplies: Supply[] = [];
supplyMap: { [key in string]?: Supply } = {};
borrows: Borrow[] = [];
Expand All @@ -154,11 +155,13 @@ export class Portfolio {
protocolId: string,
marketId: string,
supplies: SupplyObject[],
borrows: BorrowObject[]
borrows: BorrowObject[],
baseToken?: common.Token
) {
this.chainId = chainId;
this.protocolId = protocolId;
this.marketId = marketId;
if (baseToken) this.baseToken = baseToken;

for (let i = 0; i < supplies.length; i++) {
const supply = new Supply(supplies[i]);
Expand Down Expand Up @@ -271,13 +274,11 @@ export class Portfolio {
}

findSupply(token: common.Token) {
return this.supplyMap[token.address] ?? this.supplyMap[token.address];
// return this.supplyMap[unwrapToken(this.chainId, token).address] ?? this.supplyMap[token.address];
return this.supplyMap[token.unwrapped.address] ?? this.supplyMap[token.address];
}

findBorrow(token: common.Token) {
return this.borrowMap[token.address] ?? this.borrowMap[token.address];
// return this.borrowMap[unwrapToken(this.chainId, token).address] ?? this.borrowMap[token.address];
return this.borrowMap[token.unwrapped.address] ?? this.borrowMap[token.address];
}

calcLeverageTimes(leverageToken: common.Token, afterPortfolio: Portfolio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class LendingProtocol extends Protocol {
},
];

const portfolio = new Portfolio(this.chainId, this.id, marketId, supplies, borrows);
const portfolio = new Portfolio(this.chainId, this.id, marketId, supplies, borrows, baseToken);

return portfolio;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/lending/src/protocols/openocean-v2/configs.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import * as logics from '@protocolink/logics';

export const NAME = 'openocean-v2';

export const supportedChainIds = logics.openoceanv2.SwapTokenLogic.supportedChainIds;
3 changes: 2 additions & 1 deletion packages/lending/src/protocols/openocean-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lending-swaper';
export * from './configs';
export * from './lending-swapper';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NAME } from './configs';
import { Swaper } from 'src/swaper';
import { NAME, supportedChainIds } from './configs';
import { Swapper } from 'src/swapper';
import * as apisdk from '@protocolink/api';
import * as common from '@protocolink/common';
import * as logics from '@protocolink/logics';

export class LendingSwaper extends Swaper {
static readonly supportedChainIds = [1088];
export class LendingSwapper extends Swapper {
static readonly supportedChainIds = supportedChainIds;

readonly id = NAME;
readonly canCustomToken = false;
Expand All @@ -30,8 +30,4 @@ export class LendingSwaper extends Swaper {
newSwapTokenLogic(fields: apisdk.protocols.openoceanv2.SwapTokenFields): apisdk.protocols.openoceanv2.SwapTokenLogic {
return apisdk.protocols.openoceanv2.newSwapTokenLogic(fields);
}

isExactIn() {
return true;
}
}
4 changes: 4 additions & 0 deletions packages/lending/src/protocols/paraswap-v5/configs.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import * as logics from '@protocolink/logics';

export const NAME = 'paraswap-v5';

export const supportedChainIds = logics.paraswapv5.SwapTokenLogic.supportedChainIds;
2 changes: 1 addition & 1 deletion packages/lending/src/protocols/paraswap-v5/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './configs';
export * from './lending-swaper';
export * from './lending-swapper';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NAME } from './configs';
import { Swaper } from 'src/swaper';
import { NAME, supportedChainIds } from './configs';
import { Swapper } from 'src/swapper';
import * as apisdk from '@protocolink/api';
import * as common from '@protocolink/common';
import * as logics from '@protocolink/logics';

export class LendingSwaper extends Swaper {
static readonly supportedChainIds = [1, 10, 137, 42161, 43114];
export class LendingSwapper extends Swapper {
static readonly supportedChainIds = supportedChainIds;

readonly id = NAME;
readonly canCustomToken = false;
Expand All @@ -30,8 +30,4 @@ export class LendingSwaper extends Swaper {
newSwapTokenLogic(fields: apisdk.protocols.paraswapv5.SwapTokenFields): apisdk.protocols.paraswapv5.SwapTokenLogic {
return apisdk.protocols.paraswapv5.newSwapTokenLogic(fields);
}

isExactIn() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SwapTokenLogicParams } from './swaper.type';
import { SwapTokenLogicParams } from './swapper.type';
import * as apisdk from '@protocolink/api';
import * as common from '@protocolink/common';
import * as logics from '@protocolink/logics';
import { providers } from 'ethers';

export abstract class Swaper extends common.Web3Toolkit {
export abstract class Swapper extends common.Web3Toolkit {
static readonly supportedChainIds: number[];

static isSupported(chainId: number) {
Expand All @@ -23,12 +23,10 @@ export abstract class Swaper extends common.Web3Toolkit {
abstract quote(params: SwapTokenLogicParams): Promise<logics.paraswapv5.SwapTokenLogicFields>;

abstract newSwapTokenLogic(fields: any): apisdk.protocols.paraswapv5.SwapTokenLogic;

abstract isExactIn(logic: apisdk.protocols.paraswapv5.SwapTokenLogic): boolean;
}

export interface SwaperClass {
new (chainId: number, library: providers.Provider): Swaper;
export interface SwapperClass {
new (chainId: number, library: providers.Provider): Swapper;
readonly supportedChainIds: number[];
isSupported: (chainId: number) => boolean;
}
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/lending/test/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { LendingProtocol as AaveV2Lending } from 'src/protocols/aave-v2/lending-
import { LendingProtocol as AaveV3Lending } from 'src/protocols/aave-v3/lending-protocol';
import { Adapter } from 'src/adapter';
import { LendingProtocol as CompoundV3Lending } from 'src/protocols/compound-v3/lending-protocol';
import { LendingSwaper } from 'src/protocols/paraswap-v5/lending-swaper';
import { LendingSwapper } from 'src/protocols/paraswap-v5/lending-swapper';
import { LendingProtocol as RadiantV2Lending } from 'src/protocols/radiant-v2/lending-protocol';

export async function setup() {
Adapter.registerProtocol(AaveV2Lending);
Adapter.registerProtocol(AaveV3Lending);
Adapter.registerProtocol(CompoundV3Lending);
Adapter.registerProtocol(RadiantV2Lending);
Adapter.registerSwaper(LendingSwaper);
Adapter.registerSwapper(LendingSwapper);
}
2 changes: 1 addition & 1 deletion packages/lending/test/transactions/collateral-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Transaction: Collateral swap', function () {
},
},
{
skip: true,
skip: false,
testingAccount: '0x53fb0162bC8d5EEc2fB1532923C4f8997BAce111',
protocolId: 'compound-v3',
marketId: 'USDC',
Expand Down

0 comments on commit 1282772

Please sign in to comment.