@gearbox-protocol/sdk 0.0.107 → 0.0.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apy/convexAPY copy.d.ts +6 -0
- package/lib/apy/convexAPY copy.js +201 -0
- package/lib/apy/convexAPY.d.ts +9 -5
- package/lib/apy/convexAPY.js +29 -69
- package/lib/apy/curveAPY.d.ts +4 -0
- package/lib/apy/curveAPY.js +94 -0
- package/lib/apy/index.d.ts +6 -0
- package/lib/apy/index.js +20 -0
- package/lib/apy/lidoAPY.d.ts +1 -1
- package/lib/apy/lidoAPY.js +3 -3
- package/lib/apy/yearnAPY.d.ts +4 -0
- package/lib/apy/yearnAPY.js +90 -0
- package/lib/contracts/contractsRegister.js +2 -1
- package/lib/core/creditAccount.d.ts +2 -1
- package/lib/core/creditAccount.js +19 -12
- package/lib/core/creditManager.d.ts +3 -1
- package/lib/core/creditManager.js +25 -9
- package/lib/core/errors.d.ts +1 -1
- package/lib/core/pool.js +4 -4
- package/lib/core/strategy.d.ts +5 -3
- package/lib/core/strategy.js +6 -4
- package/lib/index.d.ts +4 -4
- package/lib/index.js +7 -6
- package/lib/strategies/curve.js +8 -10
- package/lib/strategies/yearn.js +8 -4
- package/lib/tokens/convex.d.ts +3 -0
- package/lib/tokens/convex.js +44 -18
- package/lib/tokens/curveLP.d.ts +1 -0
- package/lib/tokens/curveLP.js +11 -7
- package/lib/tokens/normal.d.ts +1 -0
- package/lib/tokens/normal.js +5 -1
- package/lib/tokens/token.d.ts +7 -2
- package/lib/tokens/token.js +10 -1
- package/lib/tokens/tokenData.js +2 -3
- package/lib/tokens/yearn.d.ts +1 -0
- package/lib/tokens/yearn.js +11 -7
- package/lib/utils/extracter.d.ts +11 -0
- package/lib/utils/extracter.js +19 -0
- package/lib/utils/mappers.d.ts +2 -2
- package/lib/utils/price.d.ts +8 -0
- package/lib/utils/price.js +26 -0
- package/package.json +1 -1
- package/src/apy/convexAPY.ts +47 -96
- package/src/apy/curveAPY.ts +68 -0
- package/src/apy/index.ts +8 -0
- package/src/apy/lidoAPY.ts +1 -1
- package/src/apy/yearnAPY.ts +66 -0
- package/src/contracts/contractsRegister.ts +2 -1
- package/src/core/creditAccount.ts +20 -12
- package/src/core/creditManager.ts +38 -11
- package/src/core/errors.ts +1 -0
- package/src/core/pool.ts +4 -4
- package/src/core/strategy.ts +16 -10
- package/src/index.ts +4 -4
- package/src/strategies/convex.ts +9 -3
- package/src/strategies/curve.ts +26 -18
- package/src/strategies/lido.ts +6 -2
- package/src/strategies/yearn.ts +17 -6
- package/src/tokens/convex.ts +43 -20
- package/src/tokens/curveLP.ts +9 -6
- package/src/tokens/normal.ts +3 -0
- package/src/tokens/token.ts +24 -6
- package/src/tokens/tokenData.ts +2 -4
- package/src/tokens/yearn.ts +9 -6
- package/src/utils/extracter.ts +30 -0
- package/src/utils/mappers.ts +2 -2
- package/src/utils/price.ts +33 -0
- package/lib/core/price.d.ts +0 -2
- package/lib/core/price.js +0 -14
- package/lib/types/@chainlink/contracts/src/v0.6/index.d.ts +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/index.js +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.d.ts +0 -146
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.js +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -2
- package/lib/types/contracts/integrations/lido/IstETH.d.ts +0 -154
- package/lib/types/contracts/integrations/lido/IstETH.js +0 -2
- package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.d.ts +0 -50
- package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.js +0 -2
- package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.d.ts +0 -27
- package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.js +0 -2
- package/lib/types/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
- package/lib/types/contracts/pathfinder/Balances.sol/index.js +0 -2
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.d.ts +0 -269
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.js +0 -2
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -2
- package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.d.ts +0 -58
- package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.js +0 -2
- package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.d.ts +0 -528
- package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.js +0 -2
- package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.d.ts +0 -528
- package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.js +0 -2
- package/lib/types/factories/@chainlink/contracts/src/v0.6/index.d.ts +0 -1
- package/lib/types/factories/@chainlink/contracts/src/v0.6/index.js +0 -30
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.d.ts +0 -22
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.js +0 -133
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -8
- package/lib/types/factories/contracts/integrations/lido/IstETH__factory.d.ts +0 -35
- package/lib/types/factories/contracts/integrations/lido/IstETH__factory.js +0 -224
- package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.d.ts +0 -18
- package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.js +0 -40
- package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.d.ts +0 -28
- package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.js +0 -76
- package/lib/types/factories/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
- package/lib/types/factories/contracts/pathfinder/Balances.sol/index.js +0 -8
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.d.ts +0 -144
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.js +0 -522
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -8
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.d.ts +0 -34
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.js +0 -110
- package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.d.ts +0 -65
- package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.js +0 -775
- package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.d.ts +0 -65
- package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.js +0 -775
- package/src/core/price.ts +0 -13
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
CreditAccountDataExtendedPayload,
|
|
4
4
|
CreditAccountDataPayload
|
|
5
5
|
} from "../payload/creditAccount";
|
|
6
|
+
import { calcTotalPrice } from "../utils/price";
|
|
7
|
+
|
|
6
8
|
import {
|
|
7
9
|
PERCENTAGE_FACTOR,
|
|
8
10
|
RAY,
|
|
@@ -10,7 +12,6 @@ import {
|
|
|
10
12
|
PRICE_DECIMALS
|
|
11
13
|
} from "./constants";
|
|
12
14
|
import { TokenData } from "../tokens/tokenData";
|
|
13
|
-
import { calcTotalPrice } from "./price";
|
|
14
15
|
|
|
15
16
|
export type Balance = { address: string; balance: BigNumber };
|
|
16
17
|
|
|
@@ -48,12 +49,12 @@ export class CreditAccountData {
|
|
|
48
49
|
public readonly version: number = 1;
|
|
49
50
|
|
|
50
51
|
constructor(payload: CreditAccountDataPayload) {
|
|
51
|
-
this.id = payload.creditManager;
|
|
52
|
-
this.addr = payload.addr;
|
|
53
|
-
this.borrower = payload.borrower;
|
|
52
|
+
this.id = payload.creditManager.toLowerCase();
|
|
53
|
+
this.addr = payload.addr.toLowerCase();
|
|
54
|
+
this.borrower = payload.borrower.toLowerCase();
|
|
54
55
|
this.inUse = payload.inUse;
|
|
55
|
-
this.creditManager = payload.creditManager;
|
|
56
|
-
this.underlyingToken = payload.underlying;
|
|
56
|
+
this.creditManager = payload.creditManager.toLowerCase();
|
|
57
|
+
this.underlyingToken = payload.underlying.toLowerCase();
|
|
57
58
|
this.borrowedAmountPlusInterest = BigNumber.from(
|
|
58
59
|
payload.borrowedAmountPlusInterest
|
|
59
60
|
);
|
|
@@ -68,13 +69,14 @@ export class CreditAccountData {
|
|
|
68
69
|
.toNumber() / PERCENTAGE_FACTOR;
|
|
69
70
|
|
|
70
71
|
(payload.balances || []).forEach(b => {
|
|
72
|
+
const tokenLC = b.token.toLowerCase();
|
|
71
73
|
if (b.isAllowed) {
|
|
72
|
-
this.balances[
|
|
73
|
-
this.allowedTokens.push(
|
|
74
|
+
this.balances[tokenLC] = BigNumber.from(b.balance);
|
|
75
|
+
this.allowedTokens.push(tokenLC);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
this.allBalances[
|
|
77
|
-
this.allTokens.push(
|
|
78
|
+
this.allBalances[tokenLC] = BigNumber.from(b.balance);
|
|
79
|
+
this.allTokens.push(tokenLC);
|
|
78
80
|
});
|
|
79
81
|
|
|
80
82
|
this.isDeleting = false;
|
|
@@ -94,7 +96,7 @@ export function sortBalances(
|
|
|
94
96
|
balances: Record<string, BigNumber>,
|
|
95
97
|
prices: Record<string, BigNumber>,
|
|
96
98
|
tokens: Record<string, TokenData>
|
|
97
|
-
) {
|
|
99
|
+
): Array<[string, BigNumber]> {
|
|
98
100
|
return Object.entries(balances).sort(([addr1, amount1], [addr2, amount2]) => {
|
|
99
101
|
const addr1Lc = addr1.toLowerCase();
|
|
100
102
|
const addr2Lc = addr2.toLowerCase();
|
|
@@ -109,7 +111,9 @@ export function sortBalances(
|
|
|
109
111
|
const totalPrice2 = calcTotalPrice(price2, amount2, token2?.decimals);
|
|
110
112
|
|
|
111
113
|
if (totalPrice1.eq(totalPrice2)) {
|
|
112
|
-
return
|
|
114
|
+
return amount1.eq(amount2)
|
|
115
|
+
? tokensAbcComparator(token1, token2)
|
|
116
|
+
: amountAbcComparator(amount1, amount2);
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
if (totalPrice1.gt(totalPrice2)) {
|
|
@@ -127,6 +131,10 @@ export function tokensAbcComparator(t1?: TokenData, t2?: TokenData) {
|
|
|
127
131
|
return symbol1 > symbol2 ? 1 : -1;
|
|
128
132
|
}
|
|
129
133
|
|
|
134
|
+
export function amountAbcComparator(t1: BigNumber, t2: BigNumber) {
|
|
135
|
+
return t1?.gt(t2) ? -1 : 1;
|
|
136
|
+
}
|
|
137
|
+
|
|
130
138
|
export class CreditAccountDataExtended extends CreditAccountData {
|
|
131
139
|
public readonly repayAmount: BigNumber;
|
|
132
140
|
|
|
@@ -84,7 +84,9 @@ export class CreditManagerData {
|
|
|
84
84
|
).toNumber();
|
|
85
85
|
this.availableLiquidity = BigNumber.from(payload.availableLiquidity || 0);
|
|
86
86
|
|
|
87
|
-
this.allowedTokens = (payload.collateralTokens || []).map(t =>
|
|
87
|
+
this.allowedTokens = (payload.collateralTokens || []).map(t =>
|
|
88
|
+
t.toLowerCase()
|
|
89
|
+
);
|
|
88
90
|
this.adapters = (payload.adapters || []).reduce<Record<string, string>>(
|
|
89
91
|
(acc, { allowedContract, adapter }) => ({
|
|
90
92
|
...acc,
|
|
@@ -98,7 +100,7 @@ export class CreditManagerData {
|
|
|
98
100
|
>((acc, threshold, index) => {
|
|
99
101
|
const address = payload.collateralTokens[index];
|
|
100
102
|
|
|
101
|
-
if (address) acc[address] = BigNumber.from(threshold);
|
|
103
|
+
if (address) acc[address.toLowerCase()] = BigNumber.from(threshold);
|
|
102
104
|
|
|
103
105
|
return acc;
|
|
104
106
|
}, {});
|
|
@@ -159,25 +161,50 @@ export class CreditManagerData {
|
|
|
159
161
|
};
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
validateOpenAccount(
|
|
163
|
-
|
|
164
|
+
validateOpenAccount(collateral: BigNumber, debt: BigNumber): true {
|
|
165
|
+
return this.version === 2
|
|
166
|
+
? this.validateOpenAccountV2(debt)
|
|
167
|
+
: this.validateOpenAccountV1(collateral, debt);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
protected validateOpenAccountV1(
|
|
171
|
+
collateral: BigNumber,
|
|
172
|
+
debt: BigNumber
|
|
173
|
+
): true {
|
|
174
|
+
if (collateral.lt(this.minAmount))
|
|
164
175
|
throw new OpenAccountError("amountLessMin", this.minAmount);
|
|
165
176
|
|
|
166
|
-
if (
|
|
177
|
+
if (collateral.gt(this.maxAmount))
|
|
167
178
|
throw new OpenAccountError("amountGreaterMax", this.maxAmount);
|
|
168
179
|
|
|
180
|
+
const leverage = debt.mul(LEVERAGE_DECIMALS).div(collateral).toNumber();
|
|
181
|
+
|
|
182
|
+
if (!leverage || leverage < 0)
|
|
183
|
+
throw new OpenAccountError("wrongLeverage", BigNumber.from(0));
|
|
184
|
+
|
|
169
185
|
if (leverage > this.maxLeverageFactor)
|
|
170
186
|
throw new OpenAccountError(
|
|
171
187
|
"leverageGreaterMax",
|
|
172
188
|
BigNumber.from(this.maxLeverageFactor)
|
|
173
189
|
);
|
|
174
190
|
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
191
|
+
if (debt.gt(this.availableLiquidity))
|
|
192
|
+
throw new OpenAccountError(
|
|
193
|
+
"insufficientPoolLiquidity",
|
|
194
|
+
BigNumber.from(this.availableLiquidity)
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
protected validateOpenAccountV2(debt: BigNumber): true {
|
|
201
|
+
if (debt.lt(this.minAmount))
|
|
202
|
+
throw new OpenAccountError("amountLessMin", this.minAmount);
|
|
203
|
+
|
|
204
|
+
if (debt.gt(this.maxAmount))
|
|
205
|
+
throw new OpenAccountError("amountGreaterMax", this.maxAmount);
|
|
206
|
+
|
|
207
|
+
if (debt.gt(this.availableLiquidity))
|
|
181
208
|
throw new OpenAccountError(
|
|
182
209
|
"insufficientPoolLiquidity",
|
|
183
210
|
BigNumber.from(this.availableLiquidity)
|
package/src/core/errors.ts
CHANGED
package/src/core/pool.ts
CHANGED
|
@@ -46,10 +46,10 @@ export class PoolData {
|
|
|
46
46
|
public readonly isPaused: boolean = false;
|
|
47
47
|
|
|
48
48
|
constructor(payload: PoolDataPayload) {
|
|
49
|
-
this.id = payload.addr;
|
|
50
|
-
this.address = payload.addr;
|
|
51
|
-
this.underlyingToken = payload.underlying
|
|
52
|
-
this.dieselToken = payload.dieselToken
|
|
49
|
+
this.id = payload.addr.toLowerCase();
|
|
50
|
+
this.address = payload.addr.toLowerCase();
|
|
51
|
+
this.underlyingToken = payload.underlying.toLowerCase();
|
|
52
|
+
this.dieselToken = payload.dieselToken.toLowerCase();
|
|
53
53
|
|
|
54
54
|
this.isWETH = payload.isWETH || false;
|
|
55
55
|
|
package/src/core/strategy.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
+
import { calcTotalPrice } from "../utils/price";
|
|
3
|
+
import { TokensWithAPY } from "../apy";
|
|
2
4
|
import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "./constants";
|
|
3
|
-
import { calcTotalPrice } from "./price";
|
|
4
5
|
|
|
5
6
|
export interface StrategyPayload {
|
|
6
7
|
apy?: number;
|
|
8
|
+
apyTokenSymbol: TokensWithAPY;
|
|
7
9
|
|
|
8
10
|
name: string;
|
|
9
11
|
lpToken: string;
|
|
@@ -53,7 +55,7 @@ export class Strategy {
|
|
|
53
55
|
this.baseAssets = payload.baseAssets;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
maxAPY(maxLeverage: number, poolApy: PoolList) {
|
|
57
59
|
const minApy = minBorrowApy(poolApy);
|
|
58
60
|
|
|
59
61
|
return roi(
|
|
@@ -64,7 +66,7 @@ export class Strategy {
|
|
|
64
66
|
);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
overallAPY(
|
|
68
70
|
apy: number,
|
|
69
71
|
leverage: number,
|
|
70
72
|
depositCollateral: string,
|
|
@@ -76,7 +78,7 @@ export class Strategy {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// eslint-disable-next-line class-methods-use-this
|
|
79
|
-
|
|
81
|
+
liquidationPrice(
|
|
80
82
|
borrowed: TokenDescription,
|
|
81
83
|
collateral: TokenDescription,
|
|
82
84
|
lp: TokenDescription,
|
|
@@ -96,25 +98,29 @@ export class Strategy {
|
|
|
96
98
|
.div(PERCENTAGE_FACTOR);
|
|
97
99
|
const lpMoney = calcTotalPrice(lp.price, lp.amount, lp.decimals);
|
|
98
100
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
if (lpMoney.gt(0)) {
|
|
102
|
+
const lqPrice = borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney);
|
|
103
|
+
|
|
104
|
+
return lqPrice.gte(0) ? lqPrice : BigNumber.from(0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return BigNumber.from(0);
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
protected farmLev(leverage: number, depositCollateral: string) {
|
|
105
111
|
return this.inBaseAssets(depositCollateral) ||
|
|
106
112
|
this.inLeveragableAssets(depositCollateral)
|
|
107
113
|
? leverage
|
|
108
114
|
: leverage - LEVERAGE_DECIMALS;
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
|
|
117
|
+
protected inBaseAssets(depositCollateral: string) {
|
|
112
118
|
return this.baseAssets.some(
|
|
113
119
|
c => c.toLowerCase() === depositCollateral.toLowerCase()
|
|
114
120
|
);
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
|
|
123
|
+
protected inLeveragableAssets(depositCollateral: string) {
|
|
118
124
|
return this.leveragableCollateral.some(
|
|
119
125
|
c => c.toLowerCase() === depositCollateral.toLowerCase()
|
|
120
126
|
);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from "./core/constants";
|
|
2
|
-
export * from "./core/price";
|
|
3
2
|
export * from "./core/creditAccount";
|
|
4
3
|
export * from "./core/creditManager";
|
|
5
4
|
export * from "./core/creditSession";
|
|
@@ -40,13 +39,13 @@ export * from "./tokens/gear";
|
|
|
40
39
|
export * from "./tokens/normal";
|
|
41
40
|
export * from "./tokens/yearn";
|
|
42
41
|
|
|
43
|
-
export * from "./apy
|
|
44
|
-
export * from "./apy/convexAPY";
|
|
42
|
+
export * from "./apy";
|
|
45
43
|
|
|
46
44
|
export * from "./core/history";
|
|
47
45
|
export * from "./utils/multicall";
|
|
48
46
|
export * from "./utils/types";
|
|
49
47
|
export * from "./utils/errors";
|
|
48
|
+
export * from "./utils/price";
|
|
50
49
|
|
|
51
50
|
export * from "./strategies/convex";
|
|
52
51
|
export * from "./strategies/creditFacade";
|
|
@@ -60,5 +59,6 @@ export { callRepeater } from "./utils/repeater";
|
|
|
60
59
|
export { getContractName } from "./contracts/contractsRegister";
|
|
61
60
|
export { AdapterInterface } from "./contracts/adapters";
|
|
62
61
|
export { objectEntries, swapKeyValue, keyToLowercase } from "./utils/mappers";
|
|
62
|
+
export { getPoolTokens, getUnderlyingToken } from "./utils/extracter";
|
|
63
63
|
|
|
64
|
-
export
|
|
64
|
+
export * from "./pathfinder/tradeTypes";
|
package/src/strategies/convex.ts
CHANGED
|
@@ -375,14 +375,18 @@ export class ConvexStrategies {
|
|
|
375
375
|
|
|
376
376
|
calls.push(
|
|
377
377
|
UniswapV2Multicaller.connect(
|
|
378
|
-
data.adapters[
|
|
378
|
+
data.adapters[
|
|
379
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
380
|
+
]
|
|
379
381
|
).swapAllTokensForTokens(
|
|
380
382
|
0,
|
|
381
383
|
[tokenDataByNetwork[network].CRV, data.underlyingToken],
|
|
382
384
|
Math.floor(new Date().getTime() / 1000) + 3600
|
|
383
385
|
),
|
|
384
386
|
UniswapV2Multicaller.connect(
|
|
385
|
-
data.adapters[
|
|
387
|
+
data.adapters[
|
|
388
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
389
|
+
]
|
|
386
390
|
).swapAllTokensForTokens(
|
|
387
391
|
0,
|
|
388
392
|
[tokenDataByNetwork[network].CVX, data.underlyingToken],
|
|
@@ -392,7 +396,9 @@ export class ConvexStrategies {
|
|
|
392
396
|
|
|
393
397
|
convexParams.extraRewards.forEach(extraReward => {
|
|
394
398
|
UniswapV2Multicaller.connect(
|
|
395
|
-
data.adapters[
|
|
399
|
+
data.adapters[
|
|
400
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
401
|
+
]
|
|
396
402
|
).swapAllTokensForTokens(
|
|
397
403
|
0,
|
|
398
404
|
[
|
package/src/strategies/curve.ts
CHANGED
|
@@ -344,31 +344,31 @@ export class CurveStrategies {
|
|
|
344
344
|
const curveParams = contractParams[curvePool] as CurveParams;
|
|
345
345
|
const tokenToDeposit = curveParams.tokens[0];
|
|
346
346
|
|
|
347
|
-
if (
|
|
347
|
+
if (
|
|
348
|
+
data.underlyingToken.toLowerCase() !==
|
|
349
|
+
tokenDataByNetwork[network][tokenToDeposit].toLowerCase()
|
|
350
|
+
) {
|
|
348
351
|
calls.push(
|
|
349
352
|
UniswapV2Multicaller.connect(
|
|
350
|
-
data.adapters[
|
|
353
|
+
data.adapters[
|
|
354
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
355
|
+
]
|
|
351
356
|
).swapExactTokensForTokens(
|
|
352
357
|
underlyingAmount,
|
|
353
358
|
0,
|
|
354
359
|
[data.underlyingToken, tokenDataByNetwork[network][tokenToDeposit]],
|
|
355
360
|
ADDRESS_0X0,
|
|
356
361
|
Math.floor(new Date().getTime() / 1000) + 3600
|
|
357
|
-
)
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (data.underlyingToken === tokenDataByNetwork[network][tokenToDeposit]) {
|
|
362
|
-
calls.push(
|
|
362
|
+
),
|
|
363
363
|
CurveMulticaller.connect(
|
|
364
364
|
data.adapters[contractsByNetwork[network][curvePool].toLowerCase()]
|
|
365
|
-
).
|
|
365
|
+
).add_all_liquidity_one_coin(0, 0)
|
|
366
366
|
);
|
|
367
367
|
} else {
|
|
368
368
|
calls.push(
|
|
369
369
|
CurveMulticaller.connect(
|
|
370
370
|
data.adapters[contractsByNetwork[network][curvePool].toLowerCase()]
|
|
371
|
-
).
|
|
371
|
+
).add_liquidity_one_coin(underlyingAmount, 0, 0)
|
|
372
372
|
);
|
|
373
373
|
}
|
|
374
374
|
|
|
@@ -388,7 +388,9 @@ export class CurveStrategies {
|
|
|
388
388
|
|
|
389
389
|
if (curveParams.wrapper) {
|
|
390
390
|
curveContractAddress =
|
|
391
|
-
data.adapters[
|
|
391
|
+
data.adapters[
|
|
392
|
+
contractsByNetwork[network][curveParams.wrapper].toLowerCase()
|
|
393
|
+
];
|
|
392
394
|
} else {
|
|
393
395
|
curveContractAddress =
|
|
394
396
|
data.adapters[contractsByNetwork[network][curvePool].toLowerCase()];
|
|
@@ -403,12 +405,14 @@ export class CurveStrategies {
|
|
|
403
405
|
);
|
|
404
406
|
|
|
405
407
|
if (
|
|
406
|
-
tokenDataByNetwork[network][curveParams.tokens[0]] !==
|
|
407
|
-
data.underlyingToken
|
|
408
|
+
tokenDataByNetwork[network][curveParams.tokens[0]].toLowerCase() !==
|
|
409
|
+
data.underlyingToken.toLowerCase()
|
|
408
410
|
) {
|
|
409
411
|
calls.push(
|
|
410
412
|
UniswapV2Multicaller.connect(
|
|
411
|
-
data.adapters[
|
|
413
|
+
data.adapters[
|
|
414
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
415
|
+
]
|
|
412
416
|
).swapAllTokensForTokens(
|
|
413
417
|
0,
|
|
414
418
|
[
|
|
@@ -435,7 +439,9 @@ export class CurveStrategies {
|
|
|
435
439
|
|
|
436
440
|
if (curveParams.wrapper) {
|
|
437
441
|
curveContractAddress =
|
|
438
|
-
data.adapters[
|
|
442
|
+
data.adapters[
|
|
443
|
+
contractsByNetwork[network][curveParams.wrapper].toLowerCase()
|
|
444
|
+
];
|
|
439
445
|
} else {
|
|
440
446
|
curveContractAddress =
|
|
441
447
|
data.adapters[contractsByNetwork[network][curvePool].toLowerCase()];
|
|
@@ -448,12 +454,14 @@ export class CurveStrategies {
|
|
|
448
454
|
);
|
|
449
455
|
|
|
450
456
|
if (
|
|
451
|
-
tokenDataByNetwork[network][curveParams.tokens[0]] !==
|
|
452
|
-
data.underlyingToken
|
|
457
|
+
tokenDataByNetwork[network][curveParams.tokens[0]].toLowerCase() !==
|
|
458
|
+
data.underlyingToken.toLowerCase()
|
|
453
459
|
) {
|
|
454
460
|
calls.push(
|
|
455
461
|
UniswapV2Multicaller.connect(
|
|
456
|
-
data.adapters[
|
|
462
|
+
data.adapters[
|
|
463
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
464
|
+
]
|
|
457
465
|
).swapAllTokensForTokens(
|
|
458
466
|
0,
|
|
459
467
|
[
|
package/src/strategies/lido.ts
CHANGED
|
@@ -62,7 +62,9 @@ export class LidoStrategies {
|
|
|
62
62
|
if (!data.isWETH) {
|
|
63
63
|
calls.push(
|
|
64
64
|
UniswapV2Multicaller.connect(
|
|
65
|
-
data.adapters[
|
|
65
|
+
data.adapters[
|
|
66
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
67
|
+
]
|
|
66
68
|
).swapExactTokensForTokens(
|
|
67
69
|
underlyingAmount,
|
|
68
70
|
0,
|
|
@@ -75,7 +77,9 @@ export class LidoStrategies {
|
|
|
75
77
|
|
|
76
78
|
calls.push(
|
|
77
79
|
LidoMulticaller.connect(
|
|
78
|
-
data.adapters[
|
|
80
|
+
data.adapters[
|
|
81
|
+
contractsByNetwork[network].LIDO_STETH_GATEWAY.toLowerCase()
|
|
82
|
+
]
|
|
79
83
|
).submitAll()
|
|
80
84
|
);
|
|
81
85
|
|
package/src/strategies/yearn.ts
CHANGED
|
@@ -103,13 +103,15 @@ export class YearnV2Strategies {
|
|
|
103
103
|
|
|
104
104
|
if (yearnParams.type === TokenType.YEARN_VAULT) {
|
|
105
105
|
if (
|
|
106
|
-
data.underlyingToken !==
|
|
107
|
-
tokenDataByNetwork[network][yearnParams.underlying]
|
|
106
|
+
data.underlyingToken.toLowerCase() !==
|
|
107
|
+
tokenDataByNetwork[network][yearnParams.underlying].toLowerCase()
|
|
108
108
|
) {
|
|
109
109
|
// This should be a pathfinder call
|
|
110
110
|
calls.push(
|
|
111
111
|
UniswapV2Multicaller.connect(
|
|
112
|
-
data.adapters[
|
|
112
|
+
data.adapters[
|
|
113
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
114
|
+
]
|
|
113
115
|
).swapExactTokensForTokens(
|
|
114
116
|
underlyingAmount,
|
|
115
117
|
0,
|
|
@@ -121,6 +123,13 @@ export class YearnV2Strategies {
|
|
|
121
123
|
Math.floor(new Date().getTime() / 1000) + 3600
|
|
122
124
|
)
|
|
123
125
|
);
|
|
126
|
+
} else {
|
|
127
|
+
calls.push(
|
|
128
|
+
YearnV2Multicaller.connect(
|
|
129
|
+
data.adapters[contractsByNetwork[network][yearnVault].toLowerCase()]
|
|
130
|
+
).deposit(underlyingAmount)
|
|
131
|
+
);
|
|
132
|
+
return calls;
|
|
124
133
|
}
|
|
125
134
|
} else if (
|
|
126
135
|
yearnParams.type === TokenType.YEARN_VAULT_OF_CURVE_LP ||
|
|
@@ -169,13 +178,15 @@ export class YearnV2Strategies {
|
|
|
169
178
|
|
|
170
179
|
if (yearnParams.type === TokenType.YEARN_VAULT) {
|
|
171
180
|
if (
|
|
172
|
-
data.underlyingToken !==
|
|
173
|
-
tokenDataByNetwork[network][yearnParams.underlying]
|
|
181
|
+
data.underlyingToken.toLowerCase() !==
|
|
182
|
+
tokenDataByNetwork[network][yearnParams.underlying].toLowerCase()
|
|
174
183
|
) {
|
|
175
184
|
// This should be a pathfinder call
|
|
176
185
|
calls.push(
|
|
177
186
|
UniswapV2Multicaller.connect(
|
|
178
|
-
data.adapters[
|
|
187
|
+
data.adapters[
|
|
188
|
+
contractsByNetwork[network].UNISWAP_V2_ROUTER.toLowerCase()
|
|
189
|
+
]
|
|
179
190
|
).swapAllTokensForTokens(
|
|
180
191
|
0,
|
|
181
192
|
[
|
package/src/tokens/convex.ts
CHANGED
|
@@ -39,13 +39,9 @@ export type ConvexPhantomTokenData = {
|
|
|
39
39
|
lpToken: ConvexLPToken;
|
|
40
40
|
} & BaseConvexToken;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
ConvexLPToken | ConvexStakedPhantomToken,
|
|
44
|
-
ConvexLPTokenData | ConvexPhantomTokenData
|
|
45
|
-
> = {
|
|
46
|
-
// CONVEX LP TOKENS
|
|
42
|
+
const convexLpTokens: Record<ConvexLPToken, ConvexLPTokenData> = {
|
|
47
43
|
cvx3Crv: {
|
|
48
|
-
name: "cvx3Crv",
|
|
44
|
+
name: "Convex cvx3Crv",
|
|
49
45
|
decimals: 18,
|
|
50
46
|
|
|
51
47
|
symbol: "cvx3Crv",
|
|
@@ -69,7 +65,7 @@ export const convexTokens: Record<
|
|
|
69
65
|
},
|
|
70
66
|
|
|
71
67
|
cvxsteCRV: {
|
|
72
|
-
name: "cvxsteCRV",
|
|
68
|
+
name: "Convex cvxsteCRV",
|
|
73
69
|
decimals: 18,
|
|
74
70
|
|
|
75
71
|
symbol: "cvxsteCRV",
|
|
@@ -93,7 +89,7 @@ export const convexTokens: Record<
|
|
|
93
89
|
},
|
|
94
90
|
|
|
95
91
|
cvxFRAX3CRV: {
|
|
96
|
-
name: "cvxFRAX3CRV-f",
|
|
92
|
+
name: "Convex cvxFRAX3CRV-f",
|
|
97
93
|
decimals: 18,
|
|
98
94
|
|
|
99
95
|
symbol: "cvxFRAX3CRV",
|
|
@@ -117,7 +113,7 @@ export const convexTokens: Record<
|
|
|
117
113
|
},
|
|
118
114
|
|
|
119
115
|
cvxLUSD3CRV: {
|
|
120
|
-
name: "cvxLUSD3CRV-f",
|
|
116
|
+
name: "Convex cvxLUSD3CRV-f",
|
|
121
117
|
decimals: 18,
|
|
122
118
|
|
|
123
119
|
symbol: "cvxLUSD3CRV",
|
|
@@ -141,7 +137,7 @@ export const convexTokens: Record<
|
|
|
141
137
|
},
|
|
142
138
|
|
|
143
139
|
cvxcrvPlain3andSUSD: {
|
|
144
|
-
name: "cvxcrvPlain3andSUSD",
|
|
140
|
+
name: "Convex cvxcrvPlain3andSUSD",
|
|
145
141
|
decimals: 18,
|
|
146
142
|
|
|
147
143
|
symbol: "cvxcrvPlain3andSUSD",
|
|
@@ -165,7 +161,7 @@ export const convexTokens: Record<
|
|
|
165
161
|
},
|
|
166
162
|
|
|
167
163
|
cvxgusd3CRV: {
|
|
168
|
-
name: "cvxgusd3CRV",
|
|
164
|
+
name: "Convex cvxgusd3CRV",
|
|
169
165
|
decimals: 18,
|
|
170
166
|
|
|
171
167
|
symbol: "cvxgusd3CRV",
|
|
@@ -186,11 +182,15 @@ export const convexTokens: Record<
|
|
|
186
182
|
tokenOut: "stkcvxgusd3CRV"
|
|
187
183
|
}
|
|
188
184
|
]
|
|
189
|
-
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
190
187
|
|
|
191
|
-
|
|
188
|
+
const convexStakedPhantomTokens: Record<
|
|
189
|
+
ConvexStakedPhantomToken,
|
|
190
|
+
ConvexPhantomTokenData
|
|
191
|
+
> = {
|
|
192
192
|
stkcvx3Crv: {
|
|
193
|
-
name: "stkcvx3Crv",
|
|
193
|
+
name: "Convex stkcvx3Crv",
|
|
194
194
|
decimals: 18,
|
|
195
195
|
|
|
196
196
|
symbol: "stkcvx3Crv",
|
|
@@ -214,7 +214,7 @@ export const convexTokens: Record<
|
|
|
214
214
|
},
|
|
215
215
|
|
|
216
216
|
stkcvxsteCRV: {
|
|
217
|
-
name: "stkcvxsteCRV",
|
|
217
|
+
name: "Convex stkcvxsteCRV",
|
|
218
218
|
decimals: 18,
|
|
219
219
|
|
|
220
220
|
symbol: "stkcvxsteCRV",
|
|
@@ -238,7 +238,7 @@ export const convexTokens: Record<
|
|
|
238
238
|
},
|
|
239
239
|
|
|
240
240
|
stkcvxFRAX3CRV: {
|
|
241
|
-
name: "stkcvxFRAX3CRV-f",
|
|
241
|
+
name: "Convex stkcvxFRAX3CRV-f",
|
|
242
242
|
decimals: 18,
|
|
243
243
|
|
|
244
244
|
symbol: "stkcvxFRAX3CRV",
|
|
@@ -262,13 +262,13 @@ export const convexTokens: Record<
|
|
|
262
262
|
},
|
|
263
263
|
|
|
264
264
|
stkcvxLUSD3CRV: {
|
|
265
|
-
name: "stkcvxLUSD3CRV-f",
|
|
265
|
+
name: "Convex stkcvxLUSD3CRV-f",
|
|
266
266
|
decimals: 18,
|
|
267
267
|
|
|
268
268
|
symbol: "stkcvxLUSD3CRV",
|
|
269
269
|
type: TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
|
|
270
270
|
pool: "CONVEX_LUSD3CRV_POOL",
|
|
271
|
-
pid:
|
|
271
|
+
pid: 33,
|
|
272
272
|
underlying: "LUSD3CRV",
|
|
273
273
|
lpToken: "cvxLUSD3CRV",
|
|
274
274
|
lpActions: [
|
|
@@ -286,7 +286,7 @@ export const convexTokens: Record<
|
|
|
286
286
|
},
|
|
287
287
|
|
|
288
288
|
stkcvxcrvPlain3andSUSD: {
|
|
289
|
-
name: "stkcvxcrvPlain3andSUSD",
|
|
289
|
+
name: "Convex stkcvxcrvPlain3andSUSD",
|
|
290
290
|
decimals: 18,
|
|
291
291
|
|
|
292
292
|
symbol: "stkcvxcrvPlain3andSUSD",
|
|
@@ -310,7 +310,7 @@ export const convexTokens: Record<
|
|
|
310
310
|
},
|
|
311
311
|
|
|
312
312
|
stkcvxgusd3CRV: {
|
|
313
|
-
name: "stkcvxgusd3CRV",
|
|
313
|
+
name: "Convex stkcvxgusd3CRV",
|
|
314
314
|
decimals: 18,
|
|
315
315
|
|
|
316
316
|
symbol: "stkcvxgusd3CRV",
|
|
@@ -333,3 +333,26 @@ export const convexTokens: Record<
|
|
|
333
333
|
]
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
|
+
|
|
337
|
+
export const convexTokens: Record<
|
|
338
|
+
ConvexLPToken | ConvexStakedPhantomToken,
|
|
339
|
+
ConvexLPTokenData | ConvexPhantomTokenData
|
|
340
|
+
> = {
|
|
341
|
+
...convexLpTokens,
|
|
342
|
+
...convexStakedPhantomTokens
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
export const isConvexToken = (
|
|
346
|
+
t: unknown
|
|
347
|
+
): t is ConvexLPToken | ConvexStakedPhantomToken =>
|
|
348
|
+
typeof t === "string" &&
|
|
349
|
+
!!convexTokens[t as ConvexLPToken | ConvexStakedPhantomToken];
|
|
350
|
+
|
|
351
|
+
export const isConvexLPToken = (t: unknown): t is ConvexLPToken =>
|
|
352
|
+
typeof t === "string" && !!convexLpTokens[t as ConvexLPToken];
|
|
353
|
+
|
|
354
|
+
export const isConvexStakedPhantomToken = (
|
|
355
|
+
t: unknown
|
|
356
|
+
): t is ConvexStakedPhantomToken =>
|
|
357
|
+
typeof t === "string" &&
|
|
358
|
+
!!convexStakedPhantomTokens[t as ConvexStakedPhantomToken];
|