Skip to content

Commit

Permalink
feat: adjust reserve tokens, supply tokens, borrow tokens from logics (
Browse files Browse the repository at this point in the history
…#75)

* feat(lending): adjust reserve tokens, supply tokens, borrow tokens

---------

Co-authored-by: Bob Lu <[email protected]>
Co-authored-by: Jeff Huang <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent 44ea67d commit ca67262
Show file tree
Hide file tree
Showing 21 changed files with 2,738 additions and 2,317 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-toys-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/lending': patch
---

adjust reserve tokens, supply tokens, borrow tokens
8 changes: 4 additions & 4 deletions packages/lending/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
},
"dependencies": {
"@aave/math-utils": "^1.21.0",
"@protocolink/api": "^1.1.1",
"@protocolink/common": "^0.3.11",
"@protocolink/core": "^0.4.13",
"@protocolink/logics": "^1.3.0",
"@protocolink/api": "^1.2.0",
"@protocolink/common": "^0.5.1",
"@protocolink/core": "^0.6.1",
"@protocolink/logics": "^1.5.1",
"bignumber.js": "^9.1.1",
"decimal.js-light": "^2.5.1"
},
Expand Down
2,312 changes: 1,288 additions & 1,024 deletions packages/lending/src/adapter.test.ts

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions packages/lending/src/protocols/aave-v2/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Test Adapter for Aave V2', function () {

context('Test openByDebt', function () {
const account = '0xc94680947CF2114ec8eE43725898EAA7269a98c5';
const blockTag = 19167450;
const blockTag = 20370000;

let portfolio: Portfolio;

Expand Down Expand Up @@ -167,10 +167,10 @@ describe('Test Adapter for Aave V2', function () {

it('success', async function () {
const zapToken = mainnetTokens.ETH;
const zapAmount = '1';
const zapAmount = '0.5';
const collateralToken = mainnetTokens.USDC;
const debtToken = mainnetTokens.ETH;
const debtAmount = '0.1';
const debtAmount = '0.8';

const { destAmount, afterPortfolio, error, logics } = await adapter.openByDebt({
account,
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('Test Adapter for Aave V2', function () {
});

it('success', async function () {
const account = '0x624698bb841f344a200fe6adb695e8ff695bcad7';
const account = '0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB';
portfolio = await protocol.getPortfolio(account);

const withdrawalToken = mainnetTokens.USDC;
Expand All @@ -243,16 +243,17 @@ describe('Test Adapter for Aave V2', function () {
expect(afterPortfolio.totalBorrowUSD).to.be.eq(0);
expect(afterPortfolio.totalSupplyUSD).to.be.eq(0);

expect(logics).has.length(7);
expect(logics).has.length(8);
expect(logics[0].rid).to.eq('utility:flash-loan-aggregator');
expect(logics[1].rid).to.contain('swap-token');
expect(logics[2].rid).to.eq('aave-v2:repay');
expect(logics[2].fields.balanceBps).to.eq(common.BPS_BASE);
expect(logics[3].rid).to.eq('permit2:pull-token');
expect(logics[4].rid).to.eq('aave-v2:withdraw');
expect(logics[4].fields.balanceBps).to.eq(common.BPS_BASE);
expect(logics[5].rid).to.contain('swap-token');
expect(logics[6].rid).to.eq('utility:flash-loan-aggregator');
expect(logics[3].rid).to.eq('aave-v2:repay');
expect(logics[4].rid).to.eq('permit2:pull-token');
expect(logics[5].rid).to.eq('aave-v2:withdraw');
expect(logics[5].fields.balanceBps).to.eq(common.BPS_BASE);
expect(logics[6].rid).to.contain('swap-token');
expect(logics[7].rid).to.eq('utility:flash-loan-aggregator');
});

it('success - collateral positions only', async function () {
Expand Down Expand Up @@ -759,7 +760,7 @@ describe('Test Adapter for Aave V2', function () {

it('success - src token is not equal to dest token', async function () {
const srcToken = mainnetTokens.USDC;
const srcAmount = '10000';
const srcAmount = '1';
const destToken = mainnetTokens.stETH;

const { destAmount, afterPortfolio, error, logics } = await adapter.deleverage({
Expand Down
26 changes: 2 additions & 24 deletions packages/lending/src/protocols/aave-v2/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import * as logics from '@protocolink/logics';
export const ID = 'aave-v2';
export const DISPLAY_NAME = 'Aave V2';

export interface Reserve {
asset: common.Token;
aToken: common.Token;
}
export type ReserveTokens = logics.aavev2.ReserveTokens;
export type ReserveMap = Record<string, ReserveTokens>;

type ContractName = 'ProtocolDataProvider' | 'PriceOracle' | 'ETHPriceFeed';

Expand Down Expand Up @@ -52,23 +50,3 @@ export function getContractAddress(chainId: number, name: ContractName) {
const { contractMap } = configs.find((configs) => configs.chainId === chainId)!;
return contractMap[name];
}

const supplyDisabledMap: Record<number, string[]> = {
[common.ChainId.mainnet]: [],
[common.ChainId.polygon]: [],
[common.ChainId.avalanche]: [],
};

const borrowDisabledMap: Record<number, string[]> = {
[common.ChainId.mainnet]: [common.mainnetTokens.stETH.address],
[common.ChainId.polygon]: [],
[common.ChainId.avalanche]: [],
};

export const isSupplyEnabled = (chainId: number, token: common.Token) => {
return !supplyDisabledMap[chainId].includes(token.address);
};

export const isBorrowEnabled = (chainId: number, token: common.Token) => {
return !borrowDisabledMap[chainId].includes(token.address);
};
118 changes: 66 additions & 52 deletions packages/lending/src/protocols/aave-v2/lending-protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,74 +412,45 @@ describe('Test Aave V2 LendingProtocol', function () {
marketId: 'polygon',
utilization: '0.3685856393576075793',
healthRate: '2.92177166424606475501',
netAPY: '0.01824959837903616669',
totalSupplyUSD: '6187.63383963095020048012547096',
totalBorrowUSD: '181.29530249474694',
supplies: [
{
token: {
chainId: 137,
address: '0xD6DF932A45C0f255f85145f286eA0b292B21C90B',
decimals: 18,
symbol: 'AAVE',
name: 'Aave (PoS)',
},
price: '105.25610147',
balance: '0',
apy: '0',
usageAsCollateralEnabled: true,
ltv: '0.5',
liquidationThreshold: '0.65',
isNotCollateral: false,
supplyCap: '0',
totalSupply: '22611.10243785446899109',
},
{
token: {
chainId: 137,
address: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063',
decimals: 18,
symbol: 'DAI',
name: '(PoS) Dai Stablecoin',
logoUri: 'https://cdn.furucombo.app/assets/img/token/DAI.png',
},
price: '0.99679794',
balance: '0',
apy: '0.12710541004444977537',
lstApy: '0',
grossApy: '0.12710541004444977537',
usageAsCollateralEnabled: true,
ltv: '0.75',
liquidationThreshold: '0.8',
isNotCollateral: false,
supplyCap: '0',
totalSupply: '10041889.244136207665022938',
},
{
token: {
chainId: 137,
address: '0x0000000000000000000000000000000000001010',
decimals: 18,
symbol: 'MATIC',
name: 'Matic Token',
},
price: '0.85300841',
balance: '887.118163164367700056',
apy: '0.00015134820365801307',
usageAsCollateralEnabled: true,
ltv: '0.65',
liquidationThreshold: '0.7',
isNotCollateral: false,
supplyCap: '0',
totalSupply: '9730349.206340911556404886',
},
{
token: {
chainId: 137,
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
decimals: 6,
symbol: 'USDC.e',
name: 'USD Coin (PoS)',
logoUri: 'https://cdn.furucombo.app/assets/img/token/USDC.svg',
},
price: '0.99664591',
balance: '0',
apy: '0.10613890696322769932',
lstApy: '0',
grossApy: '0.10613890696322769932',
usageAsCollateralEnabled: true,
ltv: '0.8',
liquidationThreshold: '0.85',
Expand All @@ -494,10 +465,13 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 6,
symbol: 'USDT',
name: '(PoS) Tether USD',
logoUri: 'https://cdn.furucombo.app/assets/img/token/USDT.svg',
},
price: '1.00213471',
balance: '5419.345854',
apy: '0.02085841506259266721',
lstApy: '0',
grossApy: '0.02085841506259266721',
usageAsCollateralEnabled: false,
ltv: '0',
liquidationThreshold: '0',
Expand All @@ -512,10 +486,13 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 8,
symbol: 'WBTC',
name: '(PoS) Wrapped BTC',
logoUri: 'https://cdn.furucombo.app/assets/img/token/WBTC.svg',
},
price: '42314.45587845',
balance: '0',
apy: '0.00000380199312269635',
lstApy: '0',
grossApy: '0.00000380199312269635',
usageAsCollateralEnabled: true,
ltv: '0.7',
liquidationThreshold: '0.75',
Expand All @@ -530,17 +507,41 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 18,
symbol: 'WETH',
name: 'Wrapped Ether',
logoUri: 'https://cdn.furucombo.app/assets/img/token/WETH.svg',
},
price: '2247.22899356',
balance: '0',
apy: '0.00011636207541797941',
lstApy: '0',
grossApy: '0.00011636207541797941',
usageAsCollateralEnabled: true,
ltv: '0.8',
liquidationThreshold: '0.825',
isNotCollateral: false,
supplyCap: '0',
totalSupply: '24612.744802960406826559',
},
{
token: {
chainId: 137,
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
symbol: 'MATIC',
name: 'Matic Token',
logoUri: 'https://cdn.furucombo.app/assets/img/token/MATIC.png',
},
price: '0.85300841',
balance: '887.118163164367700056',
apy: '0.00015134820365801307',
lstApy: '0',
grossApy: '0.00015134820365801307',
usageAsCollateralEnabled: true,
ltv: '0.65',
liquidationThreshold: '0.7',
isNotCollateral: false,
supplyCap: '0',
totalSupply: '9730349.206340911556404886',
},
],
borrows: [
{
Expand All @@ -550,42 +551,30 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 18,
symbol: 'DAI',
name: '(PoS) Dai Stablecoin',
logoUri: 'https://cdn.furucombo.app/assets/img/token/DAI.png',
},
price: '0.99679794',
balance: '0',
apy: '0.12710541004444977537',
lstApy: '0',
grossApy: '0.12710541004444977537',
borrowMin: '0',
borrowCap: '0',
totalBorrow: '7856725.927159881562061903',
},
{
token: {
chainId: 137,
address: '0x0000000000000000000000000000000000001010',
decimals: 18,
symbol: 'MATIC',
name: 'Matic Token',
},
price: '0.85300841',
balance: '0',
apy: '0.00015134820365801307',
grossApy: '0.00015134820365801307',
borrowMin: '0',
borrowCap: '0',
totalBorrow: '628705.023975555466478558',
},
{
token: {
chainId: 137,
address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
decimals: 6,
symbol: 'USDC.e',
name: 'USD Coin (PoS)',
logoUri: 'https://cdn.furucombo.app/assets/img/token/USDC.svg',
},
price: '0.99664591',
balance: '0',
apy: '0.10613890696322769932',
lstApy: '0',
grossApy: '0.10613890696322769932',
borrowMin: '0',
borrowCap: '0',
Expand All @@ -598,10 +587,12 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 6,
symbol: 'USDT',
name: '(PoS) Tether USD',
logoUri: 'https://cdn.furucombo.app/assets/img/token/USDT.svg',
},
price: '1.00213471',
balance: '180.909114',
apy: '0.02085841506259266721',
lstApy: '0',
grossApy: '0.02085841506259266721',
borrowMin: '0',
borrowCap: '0',
Expand All @@ -614,10 +605,12 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 8,
symbol: 'WBTC',
name: '(PoS) Wrapped BTC',
logoUri: 'https://cdn.furucombo.app/assets/img/token/WBTC.svg',
},
price: '42314.45587845',
balance: '0',
apy: '0.00000380199312269635',
lstApy: '0',
grossApy: '0.00000380199312269635',
borrowMin: '0',
borrowCap: '0',
Expand All @@ -630,15 +623,35 @@ describe('Test Aave V2 LendingProtocol', function () {
decimals: 18,
symbol: 'WETH',
name: 'Wrapped Ether',
logoUri: 'https://cdn.furucombo.app/assets/img/token/WETH.svg',
},
price: '2247.22899356',
balance: '0',
apy: '0.00011636207541797941',
lstApy: '0',
grossApy: '0.00011636207541797941',
borrowMin: '0',
borrowCap: '0',
totalBorrow: '1679.126787526099215032',
},
{
token: {
chainId: 137,
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
symbol: 'MATIC',
name: 'Matic Token',
logoUri: 'https://cdn.furucombo.app/assets/img/token/MATIC.png',
},
price: '0.85300841',
balance: '0',
apy: '0.00015134820365801307',
lstApy: '0',
grossApy: '0.00015134820365801307',
borrowMin: '0',
borrowCap: '0',
totalBorrow: '628705.023975555466478558',
},
],
},
},
Expand All @@ -650,6 +663,7 @@ describe('Test Aave V2 LendingProtocol', function () {

protocol.setBlockTag(blockTag);
const _portfolio = await protocol.getPortfolio(account);

const portfolio: Portfolio = JSON.parse(JSON.stringify(_portfolio));

const filteredPortfolio = filterPortfolio(portfolio);
Expand Down
Loading

0 comments on commit ca67262

Please sign in to comment.