@gearbox-protocol/sdk 0.0.65 → 0.0.68
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/contracts/adapters.d.ts +15 -0
- package/lib/contracts/adapters.js +19 -0
- package/lib/contracts/contracts.d.ts +60 -0
- package/lib/contracts/contracts.js +242 -0
- package/lib/contracts/contractsRegister.d.ts +2 -0
- package/lib/contracts/contractsRegister.js +58 -0
- package/lib/contracts/protocols.d.ts +13 -0
- package/lib/contracts/protocols.js +39 -0
- package/lib/core/contracts.js +3 -3
- package/lib/core/events.js +1 -1
- package/lib/core/tradeTypes.d.ts +1 -1
- package/lib/core/transactions.js +1 -1
- package/lib/index.d.ts +8 -9
- package/lib/index.js +10 -10
- package/lib/oracles/oracles.d.ts +38 -0
- package/lib/oracles/oracles.js +12 -0
- package/lib/oracles/priceFeeds.d.ts +3 -0
- package/lib/oracles/priceFeeds.js +492 -0
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +2 -20
- package/lib/pathfinder/curveLP.d.ts +2 -2
- package/lib/pathfinder/curveLP.js +8 -27
- package/lib/pathfinder/path.d.ts +2 -8
- package/lib/pathfinder/path.js +27 -34
- package/lib/pathfinder/trade.d.ts +35 -0
- package/lib/pathfinder/trade.js +62 -0
- package/lib/pathfinder/tradeTypes.d.ts +83 -0
- package/lib/pathfinder/tradeTypes.js +26 -0
- package/lib/pathfinder/yVault.d.ts +1 -1
- package/lib/pathfinder/yVault.js +4 -23
- package/lib/tokens/convex.d.ts +2 -2
- package/lib/tokens/convex.js +1 -1
- package/lib/tokens/curveLP.d.ts +1 -1
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/normal.js +1 -1
- package/lib/tokens/token.d.ts +1 -1
- package/lib/tokens/token.js +5 -5
- package/lib/tokens/yearn.d.ts +2 -2
- package/lib/tokens/yearn.js +3 -3
- package/package.json +1 -1
- package/src/{core → contracts}/adapters.ts +0 -0
- package/src/{core → contracts}/contracts.ts +6 -6
- package/src/{core → contracts}/contractsRegister.ts +0 -0
- package/src/{core → contracts}/protocols.ts +0 -0
- package/src/core/events.ts +932 -915
- package/src/core/transactions.ts +360 -352
- package/src/index.ts +8 -9
- package/src/{core → oracles}/oracles.ts +0 -0
- package/src/oracles/priceFeeds.ts +528 -0
- package/src/pathfinder/convexLP.ts +1 -1
- package/src/pathfinder/curveLP.ts +3 -4
- package/src/pathfinder/path.ts +23 -53
- package/src/pathfinder/trade.ts +83 -0
- package/src/{core → pathfinder}/tradeTypes.ts +6 -6
- package/src/pathfinder/yVault.ts +1 -2
- package/src/tokens/convex.ts +2 -2
- package/src/tokens/curveLP.ts +1 -1
- package/src/tokens/gear.ts +1 -1
- package/src/tokens/normal.ts +1 -1
- package/src/tokens/token.ts +17 -7
- package/src/tokens/yearn.ts +4 -4
- package/src/core/creditCard.ts +0 -15
- package/src/core/priceFeeds.ts +0 -528
- package/src/core/swap.ts +0 -4
- package/src/core/trade.ts +0 -83
package/src/pathfinder/path.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {BigNumber, ethers} from "ethers";
|
|
2
2
|
import {CreditManagerData} from "../core/creditManager";
|
|
3
3
|
import {MultiCall} from "../core/multicall";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
SupportedToken,
|
|
6
|
+
supportedTokens,
|
|
7
|
+
tokenSymbolByAddress
|
|
8
|
+
} from "../tokens/token";
|
|
5
9
|
import {NetworkType} from "../core/constants";
|
|
6
10
|
import {CreditAccountData} from "../core/creditAccount";
|
|
7
11
|
|
|
8
|
-
import {PathFinder__factory
|
|
12
|
+
import {PathFinder__factory} from "../types";
|
|
9
13
|
import {priority} from "./priority";
|
|
10
14
|
import {YearnLPToken} from "../tokens/yearn";
|
|
11
15
|
import {YearnVaultPathFinder} from "./yVault";
|
|
@@ -77,9 +81,21 @@ export class Path {
|
|
|
77
81
|
creditManager: CreditManagerData,
|
|
78
82
|
provider: ethers.providers.Provider
|
|
79
83
|
) {
|
|
80
|
-
const networkType = await detectNetwork(provider)
|
|
84
|
+
const networkType = await detectNetwork(provider);
|
|
85
|
+
|
|
86
|
+
const balances = Object.entries(creditAccount.balances)
|
|
87
|
+
.map(([address, balance]) => ({
|
|
88
|
+
token: tokenSymbolByAddress[address.toLowerCase()],
|
|
89
|
+
balance
|
|
90
|
+
}))
|
|
91
|
+
.filter(t => t.balance.gt(1))
|
|
92
|
+
.reduce(
|
|
93
|
+
(obj, curValue) => ({...obj, [curValue.token]: curValue.balance}),
|
|
94
|
+
{}
|
|
95
|
+
);
|
|
96
|
+
|
|
81
97
|
const initialPath = new Path({
|
|
82
|
-
balances
|
|
98
|
+
balances,
|
|
83
99
|
creditAccount,
|
|
84
100
|
creditManager,
|
|
85
101
|
networkType,
|
|
@@ -94,7 +110,7 @@ export class Path {
|
|
|
94
110
|
provider
|
|
95
111
|
);
|
|
96
112
|
|
|
97
|
-
console.log(lpPaths)
|
|
113
|
+
console.log(lpPaths);
|
|
98
114
|
console.log(pathFinder);
|
|
99
115
|
// const bestPath = await pathFinder.bestPath();
|
|
100
116
|
}
|
|
@@ -145,52 +161,6 @@ export class Path {
|
|
|
145
161
|
}
|
|
146
162
|
}
|
|
147
163
|
|
|
148
|
-
export interface
|
|
149
|
-
|
|
150
|
-
amountOut: BigNumber;
|
|
151
|
-
gasLimit: BigNumber;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export abstract class LPWithdrawPathFinder {
|
|
155
|
-
abstract findWithdrawPaths(p: Path): Promise<Array<Path>>;
|
|
156
|
-
|
|
157
|
-
async getUniswapV2SwapData(
|
|
158
|
-
adapterAddress: string,
|
|
159
|
-
currentTokenAddress: string,
|
|
160
|
-
currentBalance: BigNumber,
|
|
161
|
-
nextTokenAddress: string,
|
|
162
|
-
p: Path
|
|
163
|
-
): Promise<ActionData> {
|
|
164
|
-
const deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
165
|
-
const uniswapV2Adapter = UniswapV2Adapter__factory.connect(
|
|
166
|
-
adapterAddress,
|
|
167
|
-
p.provider
|
|
168
|
-
);
|
|
169
|
-
const path: Array<string> = [currentTokenAddress, nextTokenAddress];
|
|
170
|
-
const amountsOut: Array<BigNumber> = await uniswapV2Adapter.getAmountsOut(
|
|
171
|
-
currentBalance,
|
|
172
|
-
path
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const amountOut: BigNumber = amountsOut[amountsOut.length - 1];
|
|
176
|
-
const gasLimit: BigNumber =
|
|
177
|
-
await uniswapV2Adapter.estimateGas.swapExactTokensForTokens(
|
|
178
|
-
currentBalance,
|
|
179
|
-
amountOut,
|
|
180
|
-
path,
|
|
181
|
-
p.creditAccount.addr,
|
|
182
|
-
deadline
|
|
183
|
-
);
|
|
184
|
-
const call: MultiCall = {
|
|
185
|
-
targetContract: adapterAddress,
|
|
186
|
-
callData: UniswapV2Adapter__factory.createInterface().encodeFunctionData(
|
|
187
|
-
"swapExactTokensForTokens",
|
|
188
|
-
[currentBalance, amountOut, path, p.creditAccount.addr, deadline]
|
|
189
|
-
)
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
return {callData: call, amountOut: amountOut, gasLimit: gasLimit};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
164
|
+
export interface LPWithdrawPathFinder {
|
|
165
|
+
findWithdrawPaths(p: Path): Promise<Array<Path>>;
|
|
196
166
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {BigNumber} from "ethers";
|
|
2
|
+
import {BytesLike} from "@ethersproject/bytes";
|
|
3
|
+
import {PERCENTAGE_FACTOR, WAD} from "../core/constants";
|
|
4
|
+
import {SwapType} from "./tradeTypes";
|
|
5
|
+
|
|
6
|
+
export interface CloseTradePath {
|
|
7
|
+
path: Array<string>;
|
|
8
|
+
amountOutMin: BigNumber;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class TradePath {
|
|
12
|
+
public readonly swapType: SwapType;
|
|
13
|
+
public readonly amount: BigNumber;
|
|
14
|
+
public readonly rate: BigNumber;
|
|
15
|
+
public readonly path: Array<string>;
|
|
16
|
+
public readonly expectedAmount: BigNumber;
|
|
17
|
+
public readonly pathUniV3: BytesLike | undefined;
|
|
18
|
+
public readonly i: number | undefined;
|
|
19
|
+
public readonly j: number | undefined;
|
|
20
|
+
public readonly operationName: string | undefined;
|
|
21
|
+
|
|
22
|
+
constructor(params: {
|
|
23
|
+
swapType: SwapType;
|
|
24
|
+
amount: BigNumber;
|
|
25
|
+
path: Array<string>;
|
|
26
|
+
expectedAmount: BigNumber;
|
|
27
|
+
pathUniV3?: BytesLike;
|
|
28
|
+
i?: number;
|
|
29
|
+
j?: number;
|
|
30
|
+
operationName?: string;
|
|
31
|
+
}) {
|
|
32
|
+
this.swapType = params.swapType;
|
|
33
|
+
this.amount = params.amount;
|
|
34
|
+
this.path = params.path;
|
|
35
|
+
this.expectedAmount = params.expectedAmount;
|
|
36
|
+
this.pathUniV3 = params.pathUniV3;
|
|
37
|
+
this.rate =
|
|
38
|
+
params.swapType !== SwapType.ExactInput
|
|
39
|
+
? params.expectedAmount.mul(WAD).div(params.amount)
|
|
40
|
+
: WAD.mul(params.amount).div(params.expectedAmount);
|
|
41
|
+
this.i = params.i;
|
|
42
|
+
this.j = params.j;
|
|
43
|
+
this.operationName = params.operationName;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getExpectedAmountWithSlippage(slippage: number): BigNumber {
|
|
47
|
+
return this.swapType === SwapType.ExactInput
|
|
48
|
+
? this.getAmountOutMin(slippage)
|
|
49
|
+
: this.getAmountInMax(slippage);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getAmountInMax(slippage: number): BigNumber {
|
|
53
|
+
return this.expectedAmount
|
|
54
|
+
.mul(PERCENTAGE_FACTOR + slippage)
|
|
55
|
+
.div(PERCENTAGE_FACTOR);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getAmountOutMin(slippage: number): BigNumber {
|
|
59
|
+
return this.expectedAmount
|
|
60
|
+
.mul(PERCENTAGE_FACTOR)
|
|
61
|
+
.div(PERCENTAGE_FACTOR + slippage);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get from(): string {
|
|
65
|
+
return this.path[0];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get to(): string {
|
|
69
|
+
return this.path[this.path.length - 1];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getFromAmount(slippage: number): BigNumber {
|
|
73
|
+
return this.swapType === SwapType.ExactInput
|
|
74
|
+
? this.amount
|
|
75
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getToAmount(slippage: number): BigNumber {
|
|
79
|
+
return this.swapType === SwapType.ExactOutput
|
|
80
|
+
? this.amount
|
|
81
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConvexPoolContract,
|
|
3
|
-
CurvePoolContract,
|
|
4
|
-
UniswapV2Contract,
|
|
5
|
-
YearnVaultContract
|
|
6
|
-
} from "./contracts";
|
|
1
|
+
import {ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract} from "../contracts/contracts";
|
|
7
2
|
import {NormalToken} from "../tokens/normal";
|
|
8
3
|
import {CurveLPToken} from "../tokens/curveLP";
|
|
9
4
|
import {YearnLPToken} from "../tokens/yearn";
|
|
@@ -99,3 +94,8 @@ export type TradeAction =
|
|
|
99
94
|
contract: ConvexPoolContract;
|
|
100
95
|
tokenOut: CurveLPToken;
|
|
101
96
|
};
|
|
97
|
+
|
|
98
|
+
export enum SwapType {
|
|
99
|
+
ExactInput = 1,
|
|
100
|
+
ExactOutput = 2,
|
|
101
|
+
}
|
package/src/pathfinder/yVault.ts
CHANGED
|
@@ -14,12 +14,11 @@ interface WithdrawBalance {
|
|
|
14
14
|
balance: BigNumber;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export class YearnVaultPathFinder
|
|
17
|
+
export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
18
18
|
_vault: YearnLPToken;
|
|
19
19
|
token: NormalToken | CurveLPToken;
|
|
20
20
|
|
|
21
21
|
constructor(vault: YearnLPToken) {
|
|
22
|
-
super();
|
|
23
22
|
this._vault = vault;
|
|
24
23
|
|
|
25
24
|
const currentTokenData = yearnTokens[vault];
|
package/src/tokens/convex.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {TradeAction, TradeType} from "../
|
|
1
|
+
import {TradeAction, TradeType} from "../pathfinder/tradeTypes";
|
|
2
2
|
import {TokenBase} from "./token";
|
|
3
|
-
import {ConvexPoolContract} from "../
|
|
3
|
+
import {ConvexPoolContract} from "../contracts/contracts";
|
|
4
4
|
import {CurveLPToken} from "./curveLP";
|
|
5
5
|
import {TokenType} from "./tokenType";
|
|
6
6
|
|
package/src/tokens/curveLP.ts
CHANGED
package/src/tokens/gear.ts
CHANGED
package/src/tokens/normal.ts
CHANGED
package/src/tokens/token.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {keyToLowercase, objectEntries, swapKeyValue} from "../utils/mappers";
|
|
2
2
|
import {NetworkType} from "../core/constants";
|
|
3
3
|
import {NormalToken, NormalTokenData, normalTokens} from "./normal";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
CurveLPToken,
|
|
6
|
+
CurveLPTokenData,
|
|
7
|
+
curveTokens,
|
|
8
|
+
MetaCurveLPTokenData
|
|
9
|
+
} from "./curveLP";
|
|
5
10
|
import {
|
|
6
11
|
YearnLPToken,
|
|
7
12
|
yearnTokens,
|
|
@@ -16,8 +21,13 @@ import {
|
|
|
16
21
|
ConvexStakedPhantomToken,
|
|
17
22
|
convexTokens
|
|
18
23
|
} from "./convex";
|
|
19
|
-
import {
|
|
20
|
-
|
|
24
|
+
import {
|
|
25
|
+
DieselTokenData,
|
|
26
|
+
DieselTokenTypes,
|
|
27
|
+
GearboxToken,
|
|
28
|
+
GearboxTokenData,
|
|
29
|
+
gearTokens
|
|
30
|
+
} from "./gear";
|
|
21
31
|
|
|
22
32
|
export type SupportedToken =
|
|
23
33
|
| NormalToken
|
|
@@ -120,7 +130,7 @@ export const tokenDataByNetwork: Record<NetworkType,
|
|
|
120
130
|
|
|
121
131
|
// YEARN- CURVE TOKENS
|
|
122
132
|
yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
|
|
123
|
-
|
|
133
|
+
yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139",
|
|
124
134
|
|
|
125
135
|
//GEARBOX
|
|
126
136
|
dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
|
|
@@ -177,7 +187,7 @@ export const tokenDataByNetwork: Record<NetworkType,
|
|
|
177
187
|
"3Crv": "0x8eA3677599d5199c2c93c468fD2Fa6F102d3605b",
|
|
178
188
|
steCRV: "0x6636910D55D34505c08d53932Da526FB18D3869C",
|
|
179
189
|
FRAX3CRV: "0x76508F5398E50EFEC53d5Afd4B506990B43AdBFB",
|
|
180
|
-
LUSD3CRV: "
|
|
190
|
+
LUSD3CRV: "0x2b72b528723DEe00e9BB02839f0794A66594922E",
|
|
181
191
|
crvPlain3andSUSD: "0x540f5ea2A0601e27368661CB231AE04c23A14C24",
|
|
182
192
|
gusd3CRV: "0x428A500D8209fef5a1b5a0A35C9412b71F03aAdA",
|
|
183
193
|
|
|
@@ -197,7 +207,7 @@ export const tokenDataByNetwork: Record<NetworkType,
|
|
|
197
207
|
|
|
198
208
|
// YEARN- CURVE TOKENS
|
|
199
209
|
yvCurve_stETH: "",
|
|
200
|
-
|
|
210
|
+
yvCurve_FRAX: "",
|
|
201
211
|
|
|
202
212
|
//GEARBOX
|
|
203
213
|
dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
|
|
@@ -209,6 +219,6 @@ export const tokenDataByNetwork: Record<NetworkType,
|
|
|
209
219
|
}
|
|
210
220
|
};
|
|
211
221
|
|
|
212
|
-
export const
|
|
222
|
+
export const tokenSymbolByAddress = objectEntries(tokenDataByNetwork).reduce<Record<string, SupportedToken>>((sum, [_, tokens]) => {
|
|
213
223
|
return {...sum, ...keyToLowercase(swapKeyValue(tokens))};
|
|
214
224
|
}, {});
|
package/src/tokens/yearn.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {TradeAction, TradeType} from "../
|
|
1
|
+
import {TradeAction, TradeType} from "../pathfinder/tradeTypes";
|
|
2
2
|
import {TokenBase} from "./token";
|
|
3
3
|
import {CurveLPToken} from "./curveLP";
|
|
4
4
|
import {NormalToken} from "./normal";
|
|
@@ -10,7 +10,7 @@ export type YearnLPToken =
|
|
|
10
10
|
| "yvWETH"
|
|
11
11
|
| "yvWBTC"
|
|
12
12
|
| "yvCurve_stETH"
|
|
13
|
-
| "
|
|
13
|
+
| "yvCurve_FRAX";
|
|
14
14
|
|
|
15
15
|
export type YearnVaultTokenData = {
|
|
16
16
|
symbol: YearnLPToken;
|
|
@@ -119,11 +119,11 @@ export const yearnTokens: Record<YearnLPToken,
|
|
|
119
119
|
]
|
|
120
120
|
},
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
yvCurve_FRAX: {
|
|
123
123
|
name: "yvCurve-FRAX",
|
|
124
124
|
decimals: 18,
|
|
125
125
|
|
|
126
|
-
symbol: "
|
|
126
|
+
symbol: "yvCurve_FRAX",
|
|
127
127
|
type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
|
|
128
128
|
underlying: "FRAX3CRV",
|
|
129
129
|
lpActions: [
|
package/src/core/creditCard.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface CardCustomisation {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
background: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface CardBackground {
|
|
8
|
-
id: string;
|
|
9
|
-
background: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface CardCollection {
|
|
13
|
-
id: string;
|
|
14
|
-
backgrounds: Array<CardBackground>;
|
|
15
|
-
}
|