@gearbox-protocol/sdk 1.3.0 → 1.3.3
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/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/oracles/oracles.d.ts +6 -6
- package/lib/oracles/oracles.js +3 -3
- package/lib/oracles/priceFeeds.js +20 -20
- package/lib/strategies/yearn.js +4 -6
- package/lib/tokens/convex.d.ts +1 -1
- package/lib/tokens/convex.js +6 -6
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +6 -6
- package/lib/tokens/gear.d.ts +1 -1
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/normal.js +4 -4
- package/lib/tokens/tokenType.d.ts +9 -10
- package/lib/tokens/tokenType.js +9 -10
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/tokens/yearn.js +6 -6
- package/package.json +1 -1
- package/lib/pathfinder/contracts.d.ts +0 -3
- package/lib/pathfinder/contracts.js +0 -15
- package/lib/pathfinder/convexLP.d.ts +0 -4
- package/lib/pathfinder/convexLP.js +0 -77
- package/lib/pathfinder/curveLP.d.ts +0 -9
- package/lib/pathfinder/curveLP.js +0 -95
- package/lib/pathfinder/path.d.ts +0 -34
- package/lib/pathfinder/path.js +0 -178
- package/lib/pathfinder/priority.d.ts +0 -2
- package/lib/pathfinder/priority.js +0 -17
- package/lib/pathfinder/trade.d.ts +0 -34
- package/lib/pathfinder/trade.js +0 -62
- package/lib/pathfinder/yVault.d.ts +0 -10
- package/lib/pathfinder/yVault.js +0 -100
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export * from "./core/tokenDistributor";
|
|
|
14
14
|
export * from "./core/transactions";
|
|
15
15
|
export * from "./oracles/oracles";
|
|
16
16
|
export * from "./oracles/priceFeeds";
|
|
17
|
-
export * from "./pathfinder/trade";
|
|
18
17
|
export * from "./payload/creditAccount";
|
|
19
18
|
export * from "./payload/creditManager";
|
|
20
19
|
export * from "./payload/creditSession";
|
package/lib/index.js
CHANGED
|
@@ -31,7 +31,6 @@ __exportStar(require("./core/tokenDistributor"), exports);
|
|
|
31
31
|
__exportStar(require("./core/transactions"), exports);
|
|
32
32
|
__exportStar(require("./oracles/oracles"), exports);
|
|
33
33
|
__exportStar(require("./oracles/priceFeeds"), exports);
|
|
34
|
-
__exportStar(require("./pathfinder/trade"), exports);
|
|
35
34
|
__exportStar(require("./payload/creditAccount"), exports);
|
|
36
35
|
__exportStar(require("./payload/creditManager"), exports);
|
|
37
36
|
__exportStar(require("./payload/creditSession"), exports);
|
package/lib/oracles/oracles.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export interface PriceFeed {
|
|
|
7
7
|
export declare enum OracleType {
|
|
8
8
|
CHAINLINK_ORACLE = 0,
|
|
9
9
|
YEARN_TOKEN_ORACLE = 1,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
CURVE_LP_TOKEN_ORACLE = 2,
|
|
11
|
+
YEARN_CURVE_LP_TOKEN_ORACLE = 3,
|
|
12
12
|
ZERO_ORACLE = 4,
|
|
13
|
-
|
|
13
|
+
LIKE_CURVE_LP_TOKEN_ORACLE = 5
|
|
14
14
|
}
|
|
15
15
|
export declare type PriceFeedData = {
|
|
16
16
|
type: OracleType.CHAINLINK_ORACLE;
|
|
@@ -20,15 +20,15 @@ export declare type PriceFeedData = {
|
|
|
20
20
|
token: SupportedToken;
|
|
21
21
|
address: Record<NetworkType, string>;
|
|
22
22
|
} | {
|
|
23
|
-
type: OracleType.
|
|
23
|
+
type: OracleType.CURVE_LP_TOKEN_ORACLE;
|
|
24
24
|
assets: Array<SupportedToken>;
|
|
25
25
|
} | {
|
|
26
|
-
type: OracleType.
|
|
26
|
+
type: OracleType.YEARN_CURVE_LP_TOKEN_ORACLE;
|
|
27
27
|
curveSymbol: SupportedToken;
|
|
28
28
|
} | {
|
|
29
29
|
type: OracleType.ZERO_ORACLE;
|
|
30
30
|
} | {
|
|
31
|
-
type: OracleType.
|
|
31
|
+
type: OracleType.LIKE_CURVE_LP_TOKEN_ORACLE;
|
|
32
32
|
curveSymbol: SupportedToken;
|
|
33
33
|
};
|
|
34
34
|
export interface TokenPriceFeedData {
|
package/lib/oracles/oracles.js
CHANGED
|
@@ -5,8 +5,8 @@ var OracleType;
|
|
|
5
5
|
(function (OracleType) {
|
|
6
6
|
OracleType[OracleType["CHAINLINK_ORACLE"] = 0] = "CHAINLINK_ORACLE";
|
|
7
7
|
OracleType[OracleType["YEARN_TOKEN_ORACLE"] = 1] = "YEARN_TOKEN_ORACLE";
|
|
8
|
-
OracleType[OracleType["
|
|
9
|
-
OracleType[OracleType["
|
|
8
|
+
OracleType[OracleType["CURVE_LP_TOKEN_ORACLE"] = 2] = "CURVE_LP_TOKEN_ORACLE";
|
|
9
|
+
OracleType[OracleType["YEARN_CURVE_LP_TOKEN_ORACLE"] = 3] = "YEARN_CURVE_LP_TOKEN_ORACLE";
|
|
10
10
|
OracleType[OracleType["ZERO_ORACLE"] = 4] = "ZERO_ORACLE";
|
|
11
|
-
OracleType[OracleType["
|
|
11
|
+
OracleType[OracleType["LIKE_CURVE_LP_TOKEN_ORACLE"] = 5] = "LIKE_CURVE_LP_TOKEN_ORACLE";
|
|
12
12
|
})(OracleType = exports.OracleType || (exports.OracleType = {}));
|
|
@@ -433,124 +433,124 @@ exports.priceFeedsByNetwork = {
|
|
|
433
433
|
// CURVE LP TOKENS
|
|
434
434
|
"3Crv": {
|
|
435
435
|
priceFeedUSD: {
|
|
436
|
-
type: oracles_1.OracleType.
|
|
436
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
437
437
|
assets: ["DAI", "USDC", "USDT"],
|
|
438
438
|
},
|
|
439
439
|
},
|
|
440
440
|
steCRV: {
|
|
441
441
|
priceFeedUSD: {
|
|
442
|
-
type: oracles_1.OracleType.
|
|
442
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
443
443
|
assets: ["STETH", "WETH"],
|
|
444
444
|
},
|
|
445
445
|
},
|
|
446
446
|
FRAX3CRV: {
|
|
447
447
|
priceFeedUSD: {
|
|
448
|
-
type: oracles_1.OracleType.
|
|
448
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
449
449
|
assets: ["FRAX", "DAI", "USDC", "USDT"],
|
|
450
450
|
},
|
|
451
451
|
},
|
|
452
452
|
LUSD3CRV: {
|
|
453
453
|
priceFeedUSD: {
|
|
454
|
-
type: oracles_1.OracleType.
|
|
454
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
455
455
|
assets: ["LUSD", "DAI", "USDC", "USDT"],
|
|
456
456
|
},
|
|
457
457
|
},
|
|
458
458
|
crvPlain3andSUSD: {
|
|
459
459
|
priceFeedUSD: {
|
|
460
|
-
type: oracles_1.OracleType.
|
|
460
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
461
461
|
assets: ["DAI", "USDC", "USDT", "sUSD"],
|
|
462
462
|
},
|
|
463
463
|
},
|
|
464
464
|
gusd3CRV: {
|
|
465
465
|
priceFeedUSD: {
|
|
466
|
-
type: oracles_1.OracleType.
|
|
466
|
+
type: oracles_1.OracleType.CURVE_LP_TOKEN_ORACLE,
|
|
467
467
|
assets: ["GUSD", "DAI", "USDC", "USDT"],
|
|
468
468
|
},
|
|
469
469
|
},
|
|
470
470
|
// YEARN- CURVE TOKENS
|
|
471
471
|
yvCurve_stETH: {
|
|
472
472
|
priceFeedUSD: {
|
|
473
|
-
type: oracles_1.OracleType.
|
|
473
|
+
type: oracles_1.OracleType.YEARN_CURVE_LP_TOKEN_ORACLE,
|
|
474
474
|
curveSymbol: "steCRV",
|
|
475
475
|
},
|
|
476
476
|
},
|
|
477
477
|
yvCurve_FRAX: {
|
|
478
478
|
priceFeedUSD: {
|
|
479
|
-
type: oracles_1.OracleType.
|
|
479
|
+
type: oracles_1.OracleType.YEARN_CURVE_LP_TOKEN_ORACLE,
|
|
480
480
|
curveSymbol: "FRAX3CRV",
|
|
481
481
|
},
|
|
482
482
|
},
|
|
483
483
|
// CVX tokens
|
|
484
484
|
cvx3Crv: {
|
|
485
485
|
priceFeedUSD: {
|
|
486
|
-
type: oracles_1.OracleType.
|
|
486
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
487
487
|
curveSymbol: "3Crv",
|
|
488
488
|
},
|
|
489
489
|
},
|
|
490
490
|
cvxsteCRV: {
|
|
491
491
|
priceFeedUSD: {
|
|
492
|
-
type: oracles_1.OracleType.
|
|
492
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
493
493
|
curveSymbol: "steCRV",
|
|
494
494
|
},
|
|
495
495
|
},
|
|
496
496
|
cvxFRAX3CRV: {
|
|
497
497
|
priceFeedUSD: {
|
|
498
|
-
type: oracles_1.OracleType.
|
|
498
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
499
499
|
curveSymbol: "FRAX3CRV",
|
|
500
500
|
},
|
|
501
501
|
},
|
|
502
502
|
cvxLUSD3CRV: {
|
|
503
503
|
priceFeedUSD: {
|
|
504
|
-
type: oracles_1.OracleType.
|
|
504
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
505
505
|
curveSymbol: "LUSD3CRV",
|
|
506
506
|
},
|
|
507
507
|
},
|
|
508
508
|
cvxcrvPlain3andSUSD: {
|
|
509
509
|
priceFeedUSD: {
|
|
510
|
-
type: oracles_1.OracleType.
|
|
510
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
511
511
|
curveSymbol: "crvPlain3andSUSD",
|
|
512
512
|
},
|
|
513
513
|
},
|
|
514
514
|
cvxgusd3CRV: {
|
|
515
515
|
priceFeedUSD: {
|
|
516
|
-
type: oracles_1.OracleType.
|
|
516
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
517
517
|
curveSymbol: "gusd3CRV",
|
|
518
518
|
},
|
|
519
519
|
},
|
|
520
520
|
// CVX tokens
|
|
521
521
|
stkcvx3Crv: {
|
|
522
522
|
priceFeedUSD: {
|
|
523
|
-
type: oracles_1.OracleType.
|
|
523
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
524
524
|
curveSymbol: "3Crv",
|
|
525
525
|
},
|
|
526
526
|
},
|
|
527
527
|
stkcvxsteCRV: {
|
|
528
528
|
priceFeedUSD: {
|
|
529
|
-
type: oracles_1.OracleType.
|
|
529
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
530
530
|
curveSymbol: "steCRV",
|
|
531
531
|
},
|
|
532
532
|
},
|
|
533
533
|
stkcvxFRAX3CRV: {
|
|
534
534
|
priceFeedUSD: {
|
|
535
|
-
type: oracles_1.OracleType.
|
|
535
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
536
536
|
curveSymbol: "FRAX3CRV",
|
|
537
537
|
},
|
|
538
538
|
},
|
|
539
539
|
stkcvxLUSD3CRV: {
|
|
540
540
|
priceFeedUSD: {
|
|
541
|
-
type: oracles_1.OracleType.
|
|
541
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
542
542
|
curveSymbol: "LUSD3CRV",
|
|
543
543
|
},
|
|
544
544
|
},
|
|
545
545
|
stkcvxcrvPlain3andSUSD: {
|
|
546
546
|
priceFeedUSD: {
|
|
547
|
-
type: oracles_1.OracleType.
|
|
547
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
548
548
|
curveSymbol: "crvPlain3andSUSD",
|
|
549
549
|
},
|
|
550
550
|
},
|
|
551
551
|
stkcvxgusd3CRV: {
|
|
552
552
|
priceFeedUSD: {
|
|
553
|
-
type: oracles_1.OracleType.
|
|
553
|
+
type: oracles_1.OracleType.LIKE_CURVE_LP_TOKEN_ORACLE,
|
|
554
554
|
curveSymbol: "gusd3CRV",
|
|
555
555
|
},
|
|
556
556
|
},
|
package/lib/strategies/yearn.js
CHANGED
|
@@ -84,7 +84,7 @@ var YearnV2Strategies = /** @class */ (function () {
|
|
|
84
84
|
var vaultParams = contracts_1.contractParams[yearnVault];
|
|
85
85
|
var yearnToken = vaultParams.shareToken;
|
|
86
86
|
var yearnParams = token_1.supportedTokens[yearnToken];
|
|
87
|
-
if (yearnParams.type === tokenType_1.TokenType.
|
|
87
|
+
if (yearnParams.type === tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN) {
|
|
88
88
|
if (data.underlyingToken.toLowerCase() !==
|
|
89
89
|
token_1.tokenDataByNetwork[network][yearnParams.underlying].toLowerCase()) {
|
|
90
90
|
// This should be a pathfinder call
|
|
@@ -98,8 +98,7 @@ var YearnV2Strategies = /** @class */ (function () {
|
|
|
98
98
|
return calls;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
else if (yearnParams.type === tokenType_1.TokenType.
|
|
102
|
-
yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP) {
|
|
101
|
+
else if (yearnParams.type === tokenType_1.TokenType.YEARN_ON_CURVE_TOKEN) {
|
|
103
102
|
var curveTokenParams = token_1.supportedTokens[yearnParams.underlying];
|
|
104
103
|
var curvePool = curveTokenParams.pool;
|
|
105
104
|
calls = curve_1.CurveStrategies.underlyingToCurveLP(data, network, curvePool, underlyingAmount);
|
|
@@ -116,7 +115,7 @@ var YearnV2Strategies = /** @class */ (function () {
|
|
|
116
115
|
var yearnToken = vaultParams.shareToken;
|
|
117
116
|
var yearnParams = token_1.supportedTokens[yearnToken];
|
|
118
117
|
calls.push(YearnV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network][yearnVault].toLowerCase()]).withdraw(yearnSharesAmount));
|
|
119
|
-
if (yearnParams.type === tokenType_1.TokenType.
|
|
118
|
+
if (yearnParams.type === tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN) {
|
|
120
119
|
if (data.underlyingToken.toLowerCase() !==
|
|
121
120
|
token_1.tokenDataByNetwork[network][yearnParams.underlying].toLowerCase()) {
|
|
122
121
|
// This should be a pathfinder call
|
|
@@ -126,8 +125,7 @@ var YearnV2Strategies = /** @class */ (function () {
|
|
|
126
125
|
], Math.floor(new Date().getTime() / 1000) + 3600));
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
|
-
else if (yearnParams.type === tokenType_1.TokenType.
|
|
130
|
-
yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP) {
|
|
128
|
+
else if (yearnParams.type === tokenType_1.TokenType.YEARN_ON_CURVE_TOKEN) {
|
|
131
129
|
var curveTokenParams = token_1.supportedTokens[yearnParams.underlying];
|
|
132
130
|
var curvePool = curveTokenParams.pool;
|
|
133
131
|
calls = __spreadArray(__spreadArray([], calls, true), curve_1.CurveStrategies.allCurveLPToUnderlying(data, network, curvePool), true);
|
package/lib/tokens/convex.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare type ConvexLPTokenData = {
|
|
|
18
18
|
} & BaseConvexToken;
|
|
19
19
|
export declare type ConvexPhantomTokenData = {
|
|
20
20
|
symbol: ConvexStakedPhantomToken;
|
|
21
|
-
type: TokenType.
|
|
21
|
+
type: TokenType.CONVEX_STAKED_TOKEN;
|
|
22
22
|
lpToken: ConvexLPToken;
|
|
23
23
|
} & BaseConvexToken;
|
|
24
24
|
export declare const convexTokens: Record<ConvexLPToken | ConvexStakedPhantomToken, ConvexLPTokenData | ConvexPhantomTokenData>;
|
package/lib/tokens/convex.js
CHANGED
|
@@ -153,7 +153,7 @@ var convexStakedPhantomTokens = {
|
|
|
153
153
|
name: "Convex stkcvx3Crv",
|
|
154
154
|
decimals: 18,
|
|
155
155
|
symbol: "stkcvx3Crv",
|
|
156
|
-
type: tokenType_1.TokenType.
|
|
156
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
157
157
|
pool: "CONVEX_3CRV_POOL",
|
|
158
158
|
pid: 9,
|
|
159
159
|
underlying: "3Crv",
|
|
@@ -175,7 +175,7 @@ var convexStakedPhantomTokens = {
|
|
|
175
175
|
name: "Convex stkcvxsteCRV",
|
|
176
176
|
decimals: 18,
|
|
177
177
|
symbol: "stkcvxsteCRV",
|
|
178
|
-
type: tokenType_1.TokenType.
|
|
178
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
179
179
|
pool: "CONVEX_STECRV_POOL",
|
|
180
180
|
pid: 25,
|
|
181
181
|
underlying: "steCRV",
|
|
@@ -197,7 +197,7 @@ var convexStakedPhantomTokens = {
|
|
|
197
197
|
name: "Convex stkcvxFRAX3CRV-f",
|
|
198
198
|
decimals: 18,
|
|
199
199
|
symbol: "stkcvxFRAX3CRV",
|
|
200
|
-
type: tokenType_1.TokenType.
|
|
200
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
201
201
|
pool: "CONVEX_FRAX3CRV_POOL",
|
|
202
202
|
pid: 32,
|
|
203
203
|
underlying: "FRAX3CRV",
|
|
@@ -219,7 +219,7 @@ var convexStakedPhantomTokens = {
|
|
|
219
219
|
name: "Convex stkcvxLUSD3CRV-f",
|
|
220
220
|
decimals: 18,
|
|
221
221
|
symbol: "stkcvxLUSD3CRV",
|
|
222
|
-
type: tokenType_1.TokenType.
|
|
222
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
223
223
|
pool: "CONVEX_LUSD3CRV_POOL",
|
|
224
224
|
pid: 33,
|
|
225
225
|
underlying: "LUSD3CRV",
|
|
@@ -241,7 +241,7 @@ var convexStakedPhantomTokens = {
|
|
|
241
241
|
name: "Convex stkcvxcrvPlain3andSUSD",
|
|
242
242
|
decimals: 18,
|
|
243
243
|
symbol: "stkcvxcrvPlain3andSUSD",
|
|
244
|
-
type: tokenType_1.TokenType.
|
|
244
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
245
245
|
pool: "CONVEX_SUSD_POOL",
|
|
246
246
|
pid: 4,
|
|
247
247
|
underlying: "crvPlain3andSUSD",
|
|
@@ -263,7 +263,7 @@ var convexStakedPhantomTokens = {
|
|
|
263
263
|
name: "Convex stkcvxgusd3CRV",
|
|
264
264
|
decimals: 18,
|
|
265
265
|
symbol: "stkcvxgusd3CRV",
|
|
266
|
-
type: tokenType_1.TokenType.
|
|
266
|
+
type: tokenType_1.TokenType.CONVEX_STAKED_TOKEN,
|
|
267
267
|
pool: "CONVEX_GUSD_POOL",
|
|
268
268
|
pid: 10,
|
|
269
269
|
underlying: "gusd3CRV",
|
package/lib/tokens/curveLP.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { TokenType } from "./tokenType";
|
|
|
7
7
|
export declare type CurveLPToken = "3Crv" | "steCRV" | "FRAX3CRV" | "LUSD3CRV" | "crvPlain3andSUSD" | "gusd3CRV";
|
|
8
8
|
export declare type CurveLPTokenData = {
|
|
9
9
|
symbol: CurveLPToken;
|
|
10
|
-
type: TokenType.
|
|
10
|
+
type: TokenType.CURVE_LP_TOKEN;
|
|
11
11
|
swapActions?: Array<TradeAction>;
|
|
12
12
|
lpActions: Array<TradeAction>;
|
|
13
13
|
pool: CurvePoolContract;
|
|
@@ -15,7 +15,7 @@ export declare type CurveLPTokenData = {
|
|
|
15
15
|
} & TokenBase;
|
|
16
16
|
export declare type MetaCurveLPTokenData = {
|
|
17
17
|
symbol: CurveLPToken;
|
|
18
|
-
type: TokenType.
|
|
18
|
+
type: TokenType.CURVE_LP_TOKEN;
|
|
19
19
|
lpActions: Array<TradeAction>;
|
|
20
20
|
pool: CurvePoolContract;
|
|
21
21
|
wrapper?: CurvePoolContract;
|
package/lib/tokens/curveLP.js
CHANGED
|
@@ -15,7 +15,7 @@ exports.curveTokens = {
|
|
|
15
15
|
name: "Curve 3Crv",
|
|
16
16
|
decimals: 18,
|
|
17
17
|
symbol: "3Crv",
|
|
18
|
-
type: tokenType_1.TokenType.
|
|
18
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
19
19
|
pool: "CURVE_3CRV_POOL",
|
|
20
20
|
lpActions: [
|
|
21
21
|
{
|
|
@@ -39,7 +39,7 @@ exports.curveTokens = {
|
|
|
39
39
|
name: "Curve steCRV",
|
|
40
40
|
decimals: 18,
|
|
41
41
|
symbol: "steCRV",
|
|
42
|
-
type: tokenType_1.TokenType.
|
|
42
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
43
43
|
pool: "CURVE_STETH_GATEWAY",
|
|
44
44
|
lpActions: [
|
|
45
45
|
{
|
|
@@ -63,7 +63,7 @@ exports.curveTokens = {
|
|
|
63
63
|
name: "Curve crvPlain3andSUSD",
|
|
64
64
|
decimals: 18,
|
|
65
65
|
symbol: "crvPlain3andSUSD",
|
|
66
|
-
type: tokenType_1.TokenType.
|
|
66
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
67
67
|
pool: "CURVE_SUSD_POOL",
|
|
68
68
|
wrapper: "CURVE_SUSD_DEPOSIT",
|
|
69
69
|
lpActions: [
|
|
@@ -89,7 +89,7 @@ exports.curveTokens = {
|
|
|
89
89
|
name: "Curve FRAX3CRV-f",
|
|
90
90
|
decimals: 18,
|
|
91
91
|
symbol: "FRAX3CRV",
|
|
92
|
-
type: tokenType_1.TokenType.
|
|
92
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
93
93
|
pool: "CURVE_FRAX_POOL",
|
|
94
94
|
lpActions: [
|
|
95
95
|
{
|
|
@@ -113,7 +113,7 @@ exports.curveTokens = {
|
|
|
113
113
|
name: "Curve LUSD3CRV-f",
|
|
114
114
|
decimals: 18,
|
|
115
115
|
symbol: "LUSD3CRV",
|
|
116
|
-
type: tokenType_1.TokenType.
|
|
116
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
117
117
|
pool: "CURVE_LUSD_POOL",
|
|
118
118
|
lpActions: [
|
|
119
119
|
{
|
|
@@ -127,7 +127,7 @@ exports.curveTokens = {
|
|
|
127
127
|
name: "Curve gusd3CRV",
|
|
128
128
|
decimals: 18,
|
|
129
129
|
symbol: "gusd3CRV",
|
|
130
|
-
type: tokenType_1.TokenType.
|
|
130
|
+
type: tokenType_1.TokenType.CURVE_LP_TOKEN,
|
|
131
131
|
pool: "CURVE_GUSD_POOL",
|
|
132
132
|
lpActions: [
|
|
133
133
|
{
|
package/lib/tokens/gear.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export declare type DieselTokenData = {
|
|
|
10
10
|
export declare type GearboxTokenData = {
|
|
11
11
|
symbol: GearboxToken;
|
|
12
12
|
swapActions?: Array<TradeAction>;
|
|
13
|
-
type: TokenType.
|
|
13
|
+
type: TokenType.GEAR_TOKEN;
|
|
14
14
|
} & TokenBase;
|
|
15
15
|
export declare const gearTokens: Record<DieselTokenTypes | GearboxToken, DieselTokenData | GearboxTokenData>;
|
package/lib/tokens/gear.js
CHANGED
package/lib/tokens/normal.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { TokenType } from "./tokenType";
|
|
|
4
4
|
export declare type NormalToken = "1INCH" | "AAVE" | "COMP" | "CRV" | "DPI" | "FEI" | "LINK" | "SNX" | "SUSHI" | "UNI" | "USDT" | "USDC" | "DAI" | "WETH" | "WBTC" | "YFI" | "STETH" | "FTM" | "CVX" | "FRAX" | "FXS" | "LDO" | "SPELL" | "LUSD" | "sUSD" | "GUSD" | "LUNA" | "LQTY";
|
|
5
5
|
export declare type NormalTokenData = {
|
|
6
6
|
symbol: NormalToken;
|
|
7
|
-
type: TokenType.
|
|
7
|
+
type: TokenType.NORMAL_TOKEN;
|
|
8
8
|
swapActions: Array<TradeAction>;
|
|
9
9
|
lpActions?: Array<TradeAction>;
|
|
10
10
|
} & TokenBase;
|
package/lib/tokens/normal.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.normalTokens = {
|
|
|
88
88
|
name: "DAI",
|
|
89
89
|
decimals: 18,
|
|
90
90
|
symbol: "DAI",
|
|
91
|
-
type: tokenType_1.TokenType.
|
|
91
|
+
type: tokenType_1.TokenType.NORMAL_TOKEN,
|
|
92
92
|
swapActions: [
|
|
93
93
|
{
|
|
94
94
|
type: tradeTypes_1.TradeType.UniswapV3Swap,
|
|
@@ -243,7 +243,7 @@ exports.normalTokens = {
|
|
|
243
243
|
name: "USDC",
|
|
244
244
|
decimals: 6,
|
|
245
245
|
symbol: "USDC",
|
|
246
|
-
type: tokenType_1.TokenType.
|
|
246
|
+
type: tokenType_1.TokenType.NORMAL_TOKEN,
|
|
247
247
|
swapActions: [
|
|
248
248
|
{
|
|
249
249
|
type: tradeTypes_1.TradeType.UniswapV3Swap,
|
|
@@ -332,7 +332,7 @@ exports.normalTokens = {
|
|
|
332
332
|
name: "WBTC",
|
|
333
333
|
decimals: 8,
|
|
334
334
|
symbol: "WBTC",
|
|
335
|
-
type: tokenType_1.TokenType.
|
|
335
|
+
type: tokenType_1.TokenType.NORMAL_TOKEN,
|
|
336
336
|
swapActions: [
|
|
337
337
|
{
|
|
338
338
|
type: tradeTypes_1.TradeType.UniswapV3Swap,
|
|
@@ -359,7 +359,7 @@ exports.normalTokens = {
|
|
|
359
359
|
name: "WETH",
|
|
360
360
|
decimals: 18,
|
|
361
361
|
symbol: "WETH",
|
|
362
|
-
type: tokenType_1.TokenType.
|
|
362
|
+
type: tokenType_1.TokenType.NORMAL_TOKEN,
|
|
363
363
|
swapActions: [
|
|
364
364
|
{
|
|
365
365
|
type: tradeTypes_1.TradeType.UniswapV3Swap,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export declare enum TokenType {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
DIESEL_LP_TOKEN = 9
|
|
2
|
+
NORMAL_TOKEN = 0,
|
|
3
|
+
CURVE_LP_TOKEN = 1,
|
|
4
|
+
YEARN_ON_NORMAL_TOKEN = 2,
|
|
5
|
+
YEARN_ON_CURVE_TOKEN = 3,
|
|
6
|
+
CONVEX_LP_TOKEN = 4,
|
|
7
|
+
CONVEX_STAKED_TOKEN = 5,
|
|
8
|
+
DIESEL_LP_TOKEN = 6,
|
|
9
|
+
GEAR_TOKEN = 7,
|
|
10
|
+
C_TOKEN = 8
|
|
12
11
|
}
|
package/lib/tokens/tokenType.js
CHANGED
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TokenType = void 0;
|
|
4
4
|
var TokenType;
|
|
5
5
|
(function (TokenType) {
|
|
6
|
-
TokenType[TokenType["
|
|
7
|
-
TokenType[TokenType["
|
|
8
|
-
TokenType[TokenType["
|
|
9
|
-
TokenType[TokenType["
|
|
10
|
-
TokenType[TokenType["
|
|
11
|
-
TokenType[TokenType["
|
|
12
|
-
TokenType[TokenType["
|
|
13
|
-
TokenType[TokenType["
|
|
14
|
-
TokenType[TokenType["
|
|
15
|
-
TokenType[TokenType["DIESEL_LP_TOKEN"] = 9] = "DIESEL_LP_TOKEN";
|
|
6
|
+
TokenType[TokenType["NORMAL_TOKEN"] = 0] = "NORMAL_TOKEN";
|
|
7
|
+
TokenType[TokenType["CURVE_LP_TOKEN"] = 1] = "CURVE_LP_TOKEN";
|
|
8
|
+
TokenType[TokenType["YEARN_ON_NORMAL_TOKEN"] = 2] = "YEARN_ON_NORMAL_TOKEN";
|
|
9
|
+
TokenType[TokenType["YEARN_ON_CURVE_TOKEN"] = 3] = "YEARN_ON_CURVE_TOKEN";
|
|
10
|
+
TokenType[TokenType["CONVEX_LP_TOKEN"] = 4] = "CONVEX_LP_TOKEN";
|
|
11
|
+
TokenType[TokenType["CONVEX_STAKED_TOKEN"] = 5] = "CONVEX_STAKED_TOKEN";
|
|
12
|
+
TokenType[TokenType["DIESEL_LP_TOKEN"] = 6] = "DIESEL_LP_TOKEN";
|
|
13
|
+
TokenType[TokenType["GEAR_TOKEN"] = 7] = "GEAR_TOKEN";
|
|
14
|
+
TokenType[TokenType["C_TOKEN"] = 8] = "C_TOKEN";
|
|
16
15
|
})(TokenType = exports.TokenType || (exports.TokenType = {}));
|
package/lib/tokens/yearn.d.ts
CHANGED
|
@@ -7,21 +7,21 @@ import { TokenType } from "./tokenType";
|
|
|
7
7
|
export declare type YearnLPToken = "yvDAI" | "yvUSDC" | "yvWETH" | "yvWBTC" | "yvCurve_stETH" | "yvCurve_FRAX";
|
|
8
8
|
export declare type YearnVaultTokenData = {
|
|
9
9
|
symbol: YearnLPToken;
|
|
10
|
-
type: TokenType.
|
|
10
|
+
type: TokenType.YEARN_ON_NORMAL_TOKEN;
|
|
11
11
|
underlying: NormalToken;
|
|
12
12
|
lpActions: Array<TradeAction>;
|
|
13
13
|
vault: YearnVaultContract;
|
|
14
14
|
} & TokenBase;
|
|
15
15
|
export declare type YearnVaultOfCurveLPTokenData = {
|
|
16
16
|
symbol: YearnLPToken;
|
|
17
|
-
type: TokenType.
|
|
17
|
+
type: TokenType.YEARN_ON_CURVE_TOKEN;
|
|
18
18
|
underlying: CurveLPToken;
|
|
19
19
|
lpActions: Array<TradeAction>;
|
|
20
20
|
vault: YearnVaultContract;
|
|
21
21
|
} & TokenBase;
|
|
22
22
|
export declare type YearnVaultOfMetaCurveLPTokenData = {
|
|
23
23
|
symbol: YearnLPToken;
|
|
24
|
-
type: TokenType.
|
|
24
|
+
type: TokenType.YEARN_ON_CURVE_TOKEN;
|
|
25
25
|
underlying: CurveLPToken;
|
|
26
26
|
lpActions: Array<TradeAction>;
|
|
27
27
|
vault: YearnVaultContract;
|
package/lib/tokens/yearn.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.yearnTokens = {
|
|
|
9
9
|
name: "Yearn yvDAI",
|
|
10
10
|
decimals: 18,
|
|
11
11
|
symbol: "yvDAI",
|
|
12
|
-
type: tokenType_1.TokenType.
|
|
12
|
+
type: tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN,
|
|
13
13
|
underlying: "DAI",
|
|
14
14
|
vault: "YEARN_DAI_VAULT",
|
|
15
15
|
lpActions: [
|
|
@@ -24,7 +24,7 @@ exports.yearnTokens = {
|
|
|
24
24
|
name: "Yearn yvUSDC",
|
|
25
25
|
decimals: 6,
|
|
26
26
|
symbol: "yvUSDC",
|
|
27
|
-
type: tokenType_1.TokenType.
|
|
27
|
+
type: tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN,
|
|
28
28
|
underlying: "USDC",
|
|
29
29
|
vault: "YEARN_USDC_VAULT",
|
|
30
30
|
lpActions: [
|
|
@@ -39,7 +39,7 @@ exports.yearnTokens = {
|
|
|
39
39
|
name: "Yearn yvWETH",
|
|
40
40
|
decimals: 18,
|
|
41
41
|
symbol: "yvWETH",
|
|
42
|
-
type: tokenType_1.TokenType.
|
|
42
|
+
type: tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN,
|
|
43
43
|
underlying: "WETH",
|
|
44
44
|
vault: "YEARN_WETH_VAULT",
|
|
45
45
|
lpActions: [
|
|
@@ -54,7 +54,7 @@ exports.yearnTokens = {
|
|
|
54
54
|
name: "Yearn yvWBTC",
|
|
55
55
|
decimals: 8,
|
|
56
56
|
symbol: "yvWBTC",
|
|
57
|
-
type: tokenType_1.TokenType.
|
|
57
|
+
type: tokenType_1.TokenType.YEARN_ON_NORMAL_TOKEN,
|
|
58
58
|
underlying: "WBTC",
|
|
59
59
|
vault: "YEARN_WBTC_VAULT",
|
|
60
60
|
lpActions: [
|
|
@@ -70,7 +70,7 @@ exports.yearnTokens = {
|
|
|
70
70
|
name: "Yearn yvCurve-stETH",
|
|
71
71
|
decimals: 18,
|
|
72
72
|
symbol: "yvCurve_stETH",
|
|
73
|
-
type: tokenType_1.TokenType.
|
|
73
|
+
type: tokenType_1.TokenType.YEARN_ON_CURVE_TOKEN,
|
|
74
74
|
underlying: "steCRV",
|
|
75
75
|
vault: "YEARN_CURVE_STETH_VAULT",
|
|
76
76
|
lpActions: [
|
|
@@ -85,7 +85,7 @@ exports.yearnTokens = {
|
|
|
85
85
|
name: "Yearn yvCurve-FRAX",
|
|
86
86
|
decimals: 18,
|
|
87
87
|
symbol: "yvCurve_FRAX",
|
|
88
|
-
type: tokenType_1.TokenType.
|
|
88
|
+
type: tokenType_1.TokenType.YEARN_ON_CURVE_TOKEN,
|
|
89
89
|
underlying: "FRAX3CRV",
|
|
90
90
|
vault: "YEARN_CURVE_FRAX_VAULT",
|
|
91
91
|
lpActions: [
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pathFindersByNetwork = void 0;
|
|
4
|
-
exports.pathFindersByNetwork = {
|
|
5
|
-
Mainnet: {
|
|
6
|
-
// PATH_FINDER
|
|
7
|
-
PATH_FINDER: "",
|
|
8
|
-
CONVEX_PATH_FINDER: "",
|
|
9
|
-
},
|
|
10
|
-
Goerli: {
|
|
11
|
-
// PATH_FINDER
|
|
12
|
-
PATH_FINDER: "",
|
|
13
|
-
CONVEX_PATH_FINDER: "",
|
|
14
|
-
},
|
|
15
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ConvexLPPathFinder = void 0;
|
|
40
|
-
var convex_1 = require("../tokens/convex");
|
|
41
|
-
var mappers_1 = require("../utils/mappers");
|
|
42
|
-
var ConvexLPPathFinder = /** @class */ (function () {
|
|
43
|
-
function ConvexLPPathFinder() {
|
|
44
|
-
}
|
|
45
|
-
// eslint-disable-next-line class-methods-use-this
|
|
46
|
-
ConvexLPPathFinder.prototype.findWithdrawPaths = function (p) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var pids;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
pids = (0, mappers_1.objectEntries)(convex_1.convexTokens).reduce(function (acc, _a) {
|
|
51
|
-
var cvxToken = _a[0], tokenData = _a[1];
|
|
52
|
-
var currentBalance = p.popBalance(cvxToken);
|
|
53
|
-
if (currentBalance.gt(1)) {
|
|
54
|
-
pids.add(tokenData.pid);
|
|
55
|
-
}
|
|
56
|
-
return acc;
|
|
57
|
-
}, new Set());
|
|
58
|
-
// const convexPathFinder = ConvexPathFinder__factory.connect(
|
|
59
|
-
// pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
|
|
60
|
-
// p.provider
|
|
61
|
-
// );
|
|
62
|
-
// const tokenBalances = await convexPathFinder.calcRewards(
|
|
63
|
-
// p.creditAccount.addr,
|
|
64
|
-
// Array.from(pids)
|
|
65
|
-
// );
|
|
66
|
-
// for (let balance of tokenBalances) {
|
|
67
|
-
// p.balances[balance.token] = p.balances[balance.token].add(
|
|
68
|
-
// balance.balance
|
|
69
|
-
// );
|
|
70
|
-
// }
|
|
71
|
-
return [2 /*return*/, p.withdrawTokens()];
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
return ConvexLPPathFinder;
|
|
76
|
-
}());
|
|
77
|
-
exports.ConvexLPPathFinder = ConvexLPPathFinder;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CurvePoolContract } from "../contracts/contracts";
|
|
2
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
3
|
-
import type { LPWithdrawPathFinder, Path } from "./path";
|
|
4
|
-
export declare class CurvePathFinder implements LPWithdrawPathFinder {
|
|
5
|
-
lpToken: CurveLPToken;
|
|
6
|
-
contract: CurvePoolContract;
|
|
7
|
-
constructor(token: CurveLPToken);
|
|
8
|
-
findWithdrawPaths(p: Path): Promise<Array<Path>>;
|
|
9
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.CurvePathFinder = void 0;
|
|
40
|
-
var contracts_1 = require("../contracts/contracts");
|
|
41
|
-
var curveLP_1 = require("../tokens/curveLP");
|
|
42
|
-
var types_1 = require("../types");
|
|
43
|
-
var multicall_1 = require("../utils/multicall");
|
|
44
|
-
var tradeTypes_1 = require("./tradeTypes");
|
|
45
|
-
var CurvePathFinder = /** @class */ (function () {
|
|
46
|
-
function CurvePathFinder(token) {
|
|
47
|
-
this.lpToken = token;
|
|
48
|
-
var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type === tradeTypes_1.TradeType.CurveWithdrawLP; });
|
|
49
|
-
if (curvePools.length !== 1)
|
|
50
|
-
throw new Error("Cant find Withdrawer");
|
|
51
|
-
this.contract = curvePools[0].contract;
|
|
52
|
-
var wrapper = contracts_1.contractParams[curvePools[0].contract].wrapper;
|
|
53
|
-
if (wrapper) {
|
|
54
|
-
this.contract = wrapper;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
CurvePathFinder.prototype.findWithdrawPaths = function (p) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
-
var coins, nCoins, lpBalance, multiCallContract, data, i, balances, paths, i, newPath;
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
switch (_a.label) {
|
|
62
|
-
case 0:
|
|
63
|
-
coins = contracts_1.contractParams[this.contract].tokens;
|
|
64
|
-
nCoins = coins.length;
|
|
65
|
-
lpBalance = p.popBalance(this.lpToken);
|
|
66
|
-
multiCallContract = new multicall_1.MultiCallContract(contracts_1.contractsByAddress[this.contract], types_1.ICurvePool__factory.createInterface(), p.provider);
|
|
67
|
-
data = [];
|
|
68
|
-
for (i = 0; i < nCoins; i += 1) {
|
|
69
|
-
data.push({
|
|
70
|
-
method: "calc_withdraw_one_coin(uint256,int128)",
|
|
71
|
-
params: [lpBalance, i],
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return [4 /*yield*/, multiCallContract.call(data)];
|
|
75
|
-
case 1:
|
|
76
|
-
balances = _a.sent();
|
|
77
|
-
console.debug(balances);
|
|
78
|
-
paths = [];
|
|
79
|
-
for (i = 0; i < nCoins; i += 1) {
|
|
80
|
-
newPath = p.clone();
|
|
81
|
-
// newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
|
|
82
|
-
// newPath.calls.push({
|
|
83
|
-
// targetContract: contractsByNetwork[p.networkType][this.contract],
|
|
84
|
-
// callData: ICurveV1Adapter__factory.createInterface().encodeFunctionData("remove_all_liquidity_one_coin", [i])
|
|
85
|
-
// })
|
|
86
|
-
paths.push(newPath);
|
|
87
|
-
}
|
|
88
|
-
return [2 /*return*/, paths];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
return CurvePathFinder;
|
|
94
|
-
}());
|
|
95
|
-
exports.CurvePathFinder = CurvePathFinder;
|
package/lib/pathfinder/path.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BigNumber, ethers } from "ethers";
|
|
2
|
-
import { NetworkType } from "../core/constants";
|
|
3
|
-
import { CreditAccountData } from "../core/creditAccount";
|
|
4
|
-
import { CreditManagerData } from "../core/creditManager";
|
|
5
|
-
import { MultiCall } from "../core/multicall";
|
|
6
|
-
import { SupportedToken } from "../tokens/token";
|
|
7
|
-
import { PartialRecord } from "../utils/types";
|
|
8
|
-
export declare class Path {
|
|
9
|
-
readonly calls: Array<MultiCall>;
|
|
10
|
-
readonly balances: PartialRecord<SupportedToken, BigNumber>;
|
|
11
|
-
readonly underlying: SupportedToken;
|
|
12
|
-
readonly creditManager: CreditManagerData;
|
|
13
|
-
readonly creditAccount: CreditAccountData;
|
|
14
|
-
readonly networkType: NetworkType;
|
|
15
|
-
readonly provider: ethers.providers.Provider;
|
|
16
|
-
totalGasLimit: number;
|
|
17
|
-
constructor(opts: {
|
|
18
|
-
balances: PartialRecord<SupportedToken, BigNumber>;
|
|
19
|
-
underlying: SupportedToken;
|
|
20
|
-
creditManager: CreditManagerData;
|
|
21
|
-
creditAccount: CreditAccountData;
|
|
22
|
-
networkType: NetworkType;
|
|
23
|
-
provider: ethers.providers.Provider;
|
|
24
|
-
totalGasLimit: number;
|
|
25
|
-
});
|
|
26
|
-
popBalance(token: SupportedToken): BigNumber;
|
|
27
|
-
private static comparedByPriority;
|
|
28
|
-
static findBestPath(creditAccount: CreditAccountData, creditManager: CreditManagerData, provider: ethers.providers.Provider): Promise<void>;
|
|
29
|
-
withdrawTokens(): Promise<Array<Path>>;
|
|
30
|
-
clone(): Path;
|
|
31
|
-
}
|
|
32
|
-
export interface LPWithdrawPathFinder {
|
|
33
|
-
findWithdrawPaths: (p: Path) => Promise<Array<Path>>;
|
|
34
|
-
}
|
package/lib/pathfinder/path.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.Path = void 0;
|
|
51
|
-
var ethers_1 = require("ethers");
|
|
52
|
-
var token_1 = require("../tokens/token");
|
|
53
|
-
var tokenType_1 = require("../tokens/tokenType");
|
|
54
|
-
var network_1 = require("../utils/network");
|
|
55
|
-
var convexLP_1 = require("./convexLP");
|
|
56
|
-
var curveLP_1 = require("./curveLP");
|
|
57
|
-
var priority_1 = require("./priority");
|
|
58
|
-
var yVault_1 = require("./yVault");
|
|
59
|
-
var Path = /** @class */ (function () {
|
|
60
|
-
function Path(opts) {
|
|
61
|
-
this.calls = [];
|
|
62
|
-
this.balances = opts.balances;
|
|
63
|
-
this.underlying = opts.underlying;
|
|
64
|
-
this.creditManager = opts.creditManager;
|
|
65
|
-
this.creditAccount = opts.creditAccount;
|
|
66
|
-
this.networkType = opts.networkType;
|
|
67
|
-
this.provider = opts.provider;
|
|
68
|
-
this.totalGasLimit = opts.totalGasLimit;
|
|
69
|
-
}
|
|
70
|
-
Path.prototype.popBalance = function (token) {
|
|
71
|
-
var currentBalance = this.balances[token];
|
|
72
|
-
if (currentBalance === undefined || currentBalance.gt(1))
|
|
73
|
-
return ethers_1.BigNumber.from(0);
|
|
74
|
-
this.balances[token] = ethers_1.BigNumber.from(1);
|
|
75
|
-
return currentBalance.sub(1);
|
|
76
|
-
};
|
|
77
|
-
Path.comparedByPriority = function (_a, _b) {
|
|
78
|
-
var tokenA = _a[0];
|
|
79
|
-
var tokenB = _b[0];
|
|
80
|
-
var priorityTokenA = priority_1.priority[token_1.supportedTokens[tokenA].type];
|
|
81
|
-
var priorityTokenB = priority_1.priority[token_1.supportedTokens[tokenB].type];
|
|
82
|
-
if (priorityTokenA > priorityTokenB) {
|
|
83
|
-
return -1;
|
|
84
|
-
}
|
|
85
|
-
if (priorityTokenA < priorityTokenB) {
|
|
86
|
-
return 1;
|
|
87
|
-
}
|
|
88
|
-
return 0;
|
|
89
|
-
};
|
|
90
|
-
Path.findBestPath = function (creditAccount, creditManager, provider) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
-
var networkType, balances, initialPath, lpPaths;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0: return [4 /*yield*/, (0, network_1.detectNetwork)(provider)];
|
|
96
|
-
case 1:
|
|
97
|
-
networkType = _a.sent();
|
|
98
|
-
balances = Object.entries(creditAccount.balances)
|
|
99
|
-
.map(function (_a) {
|
|
100
|
-
var address = _a[0], balance = _a[1];
|
|
101
|
-
return ({
|
|
102
|
-
token: token_1.tokenSymbolByAddress[address.toLowerCase()],
|
|
103
|
-
balance: balance,
|
|
104
|
-
});
|
|
105
|
-
})
|
|
106
|
-
.filter(function (t) { return t.balance.gt(1); })
|
|
107
|
-
.reduce(function (obj, curValue) {
|
|
108
|
-
var _a;
|
|
109
|
-
return (__assign(__assign({}, obj), (_a = {}, _a[curValue.token] = curValue.balance, _a)));
|
|
110
|
-
}, {});
|
|
111
|
-
initialPath = new Path({
|
|
112
|
-
balances: balances,
|
|
113
|
-
creditAccount: creditAccount,
|
|
114
|
-
creditManager: creditManager,
|
|
115
|
-
networkType: networkType,
|
|
116
|
-
provider: provider,
|
|
117
|
-
underlying: "DAI",
|
|
118
|
-
totalGasLimit: 0,
|
|
119
|
-
});
|
|
120
|
-
return [4 /*yield*/, initialPath.withdrawTokens()];
|
|
121
|
-
case 2:
|
|
122
|
-
lpPaths = _a.sent();
|
|
123
|
-
// const pathFinder = ISwapAggregator__factory.connect(
|
|
124
|
-
// pathFindersByNetwork[networkType].PATH_FINDER,
|
|
125
|
-
// provider,
|
|
126
|
-
// );
|
|
127
|
-
console.debug(lpPaths);
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
Path.prototype.withdrawTokens = function () {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
-
var existingTokens, nextToken, lpPathFinder;
|
|
136
|
-
return __generator(this, function (_a) {
|
|
137
|
-
existingTokens = Object.entries(this.balances)
|
|
138
|
-
.filter(function (_a) {
|
|
139
|
-
var balance = _a[1];
|
|
140
|
-
return balance.gt(1);
|
|
141
|
-
})
|
|
142
|
-
.sort(Path.comparedByPriority);
|
|
143
|
-
// TODO: Add checks for lenght
|
|
144
|
-
if (existingTokens.length === 0)
|
|
145
|
-
throw new Error("No tokens with balance >1");
|
|
146
|
-
nextToken = existingTokens[0][0];
|
|
147
|
-
// Get balances and keep non-zero only
|
|
148
|
-
// Find token with highest priority
|
|
149
|
-
// Get token type of this token
|
|
150
|
-
switch (token_1.supportedTokens[nextToken].type) {
|
|
151
|
-
case tokenType_1.TokenType.NORMAL_TOKEN:
|
|
152
|
-
case tokenType_1.TokenType.CONNECTOR:
|
|
153
|
-
return [2 /*return*/, [this]];
|
|
154
|
-
case tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP:
|
|
155
|
-
case tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP:
|
|
156
|
-
case tokenType_1.TokenType.YEARN_VAULT:
|
|
157
|
-
lpPathFinder = new yVault_1.YearnVaultPathFinder(nextToken);
|
|
158
|
-
break;
|
|
159
|
-
case tokenType_1.TokenType.CONVEX_LP_TOKEN:
|
|
160
|
-
lpPathFinder = new convexLP_1.ConvexLPPathFinder();
|
|
161
|
-
break;
|
|
162
|
-
case tokenType_1.TokenType.META_CURVE_LP:
|
|
163
|
-
case tokenType_1.TokenType.CURVE_LP:
|
|
164
|
-
lpPathFinder = new curveLP_1.CurvePathFinder(nextToken);
|
|
165
|
-
break;
|
|
166
|
-
default:
|
|
167
|
-
throw new Error("Token type not supported yet");
|
|
168
|
-
}
|
|
169
|
-
return [2 /*return*/, lpPathFinder.findWithdrawPaths(this)];
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
Path.prototype.clone = function () {
|
|
174
|
-
return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
175
|
-
};
|
|
176
|
-
return Path;
|
|
177
|
-
}());
|
|
178
|
-
exports.Path = Path;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.priority = void 0;
|
|
5
|
-
var tokenType_1 = require("../tokens/tokenType");
|
|
6
|
-
exports.priority = (_a = {},
|
|
7
|
-
_a[tokenType_1.TokenType.CONNECTOR] = 1,
|
|
8
|
-
_a[tokenType_1.TokenType.NORMAL_TOKEN] = 2,
|
|
9
|
-
_a[tokenType_1.TokenType.CURVE_LP] = 3,
|
|
10
|
-
_a[tokenType_1.TokenType.YEARN_VAULT] = 3,
|
|
11
|
-
_a[tokenType_1.TokenType.META_CURVE_LP] = 4,
|
|
12
|
-
_a[tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP] = 4,
|
|
13
|
-
_a[tokenType_1.TokenType.CONVEX_LP_TOKEN] = 5,
|
|
14
|
-
_a[tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP] = 5,
|
|
15
|
-
_a[tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN] = 5,
|
|
16
|
-
_a[tokenType_1.TokenType.DIESEL_LP_TOKEN] = 6,
|
|
17
|
-
_a);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BigNumber, BytesLike } from "ethers";
|
|
2
|
-
import { SwapType } from "./tradeTypes";
|
|
3
|
-
export interface CloseTradePath {
|
|
4
|
-
path: Array<string>;
|
|
5
|
-
amountOutMin: BigNumber;
|
|
6
|
-
}
|
|
7
|
-
export declare class TradePath {
|
|
8
|
-
readonly swapType: SwapType;
|
|
9
|
-
readonly amount: BigNumber;
|
|
10
|
-
readonly rate: BigNumber;
|
|
11
|
-
readonly path: Array<string>;
|
|
12
|
-
readonly expectedAmount: BigNumber;
|
|
13
|
-
readonly pathUniV3: BytesLike | undefined;
|
|
14
|
-
readonly i: number | undefined;
|
|
15
|
-
readonly j: number | undefined;
|
|
16
|
-
readonly operationName: string | undefined;
|
|
17
|
-
constructor(params: {
|
|
18
|
-
swapType: SwapType;
|
|
19
|
-
amount: BigNumber;
|
|
20
|
-
path: Array<string>;
|
|
21
|
-
expectedAmount: BigNumber;
|
|
22
|
-
pathUniV3?: BytesLike;
|
|
23
|
-
i?: number;
|
|
24
|
-
j?: number;
|
|
25
|
-
operationName?: string;
|
|
26
|
-
});
|
|
27
|
-
getExpectedAmountWithSlippage(slippage: number): BigNumber;
|
|
28
|
-
getAmountInMax(slippage: number): BigNumber;
|
|
29
|
-
getAmountOutMin(slippage: number): BigNumber;
|
|
30
|
-
get from(): string;
|
|
31
|
-
get to(): string;
|
|
32
|
-
getFromAmount(slippage: number): BigNumber;
|
|
33
|
-
getToAmount(slippage: number): BigNumber;
|
|
34
|
-
}
|
package/lib/pathfinder/trade.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TradePath = void 0;
|
|
4
|
-
var constants_1 = require("../core/constants");
|
|
5
|
-
var tradeTypes_1 = require("./tradeTypes");
|
|
6
|
-
var TradePath = /** @class */ (function () {
|
|
7
|
-
function TradePath(params) {
|
|
8
|
-
this.swapType = params.swapType;
|
|
9
|
-
this.amount = params.amount;
|
|
10
|
-
this.path = params.path;
|
|
11
|
-
this.expectedAmount = params.expectedAmount;
|
|
12
|
-
this.pathUniV3 = params.pathUniV3;
|
|
13
|
-
this.rate =
|
|
14
|
-
params.swapType !== tradeTypes_1.SwapType.ExactInput
|
|
15
|
-
? params.expectedAmount.mul(constants_1.WAD).div(params.amount)
|
|
16
|
-
: constants_1.WAD.mul(params.amount).div(params.expectedAmount);
|
|
17
|
-
this.i = params.i;
|
|
18
|
-
this.j = params.j;
|
|
19
|
-
this.operationName = params.operationName;
|
|
20
|
-
}
|
|
21
|
-
TradePath.prototype.getExpectedAmountWithSlippage = function (slippage) {
|
|
22
|
-
return this.swapType === tradeTypes_1.SwapType.ExactInput
|
|
23
|
-
? this.getAmountOutMin(slippage)
|
|
24
|
-
: this.getAmountInMax(slippage);
|
|
25
|
-
};
|
|
26
|
-
TradePath.prototype.getAmountInMax = function (slippage) {
|
|
27
|
-
return this.expectedAmount
|
|
28
|
-
.mul(constants_1.PERCENTAGE_FACTOR + slippage)
|
|
29
|
-
.div(constants_1.PERCENTAGE_FACTOR);
|
|
30
|
-
};
|
|
31
|
-
TradePath.prototype.getAmountOutMin = function (slippage) {
|
|
32
|
-
return this.expectedAmount
|
|
33
|
-
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
34
|
-
.div(constants_1.PERCENTAGE_FACTOR + slippage);
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(TradePath.prototype, "from", {
|
|
37
|
-
get: function () {
|
|
38
|
-
return this.path[0];
|
|
39
|
-
},
|
|
40
|
-
enumerable: false,
|
|
41
|
-
configurable: true
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(TradePath.prototype, "to", {
|
|
44
|
-
get: function () {
|
|
45
|
-
return this.path[this.path.length - 1];
|
|
46
|
-
},
|
|
47
|
-
enumerable: false,
|
|
48
|
-
configurable: true
|
|
49
|
-
});
|
|
50
|
-
TradePath.prototype.getFromAmount = function (slippage) {
|
|
51
|
-
return this.swapType === tradeTypes_1.SwapType.ExactInput
|
|
52
|
-
? this.amount
|
|
53
|
-
: this.getExpectedAmountWithSlippage(slippage);
|
|
54
|
-
};
|
|
55
|
-
TradePath.prototype.getToAmount = function (slippage) {
|
|
56
|
-
return this.swapType === tradeTypes_1.SwapType.ExactOutput
|
|
57
|
-
? this.amount
|
|
58
|
-
: this.getExpectedAmountWithSlippage(slippage);
|
|
59
|
-
};
|
|
60
|
-
return TradePath;
|
|
61
|
-
}());
|
|
62
|
-
exports.TradePath = TradePath;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
2
|
-
import { NormalToken } from "../tokens/normal";
|
|
3
|
-
import { YearnLPToken } from "../tokens/yearn";
|
|
4
|
-
import type { LPWithdrawPathFinder, Path } from "./path";
|
|
5
|
-
export declare class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
6
|
-
_vault: YearnLPToken;
|
|
7
|
-
token: NormalToken | CurveLPToken;
|
|
8
|
-
constructor(vault: YearnLPToken);
|
|
9
|
-
findWithdrawPaths(path: Path): Promise<Array<Path>>;
|
|
10
|
-
}
|
package/lib/pathfinder/yVault.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.YearnVaultPathFinder = void 0;
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
41
|
-
var token_1 = require("../tokens/token");
|
|
42
|
-
var yearn_1 = require("../tokens/yearn");
|
|
43
|
-
var types_1 = require("../types");
|
|
44
|
-
var mappers_1 = require("../utils/mappers");
|
|
45
|
-
var multicall_1 = require("../utils/multicall");
|
|
46
|
-
var YearnVaultPathFinder = /** @class */ (function () {
|
|
47
|
-
function YearnVaultPathFinder(vault) {
|
|
48
|
-
this._vault = vault;
|
|
49
|
-
var currentTokenData = yearn_1.yearnTokens[vault];
|
|
50
|
-
// Yearn Vault only has one lp action
|
|
51
|
-
this.token = currentTokenData.underlying;
|
|
52
|
-
}
|
|
53
|
-
// eslint-disable-next-line class-methods-use-this
|
|
54
|
-
YearnVaultPathFinder.prototype.findWithdrawPaths = function (path) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var p, vaultBalances, vaultList, multicallData, prices, i, vault, vb, tokenAddress, adapterAddress, callData;
|
|
57
|
-
return __generator(this, function (_a) {
|
|
58
|
-
switch (_a.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
p = path.clone();
|
|
61
|
-
vaultBalances = (0, mappers_1.objectEntries)(yearn_1.yearnTokens).reduce(function (acc, _a) {
|
|
62
|
-
var yVault = _a[0], tokenData = _a[1];
|
|
63
|
-
var typedVault = yVault;
|
|
64
|
-
var currentBalance = p.popBalance(typedVault);
|
|
65
|
-
if (currentBalance.gt(1)) {
|
|
66
|
-
acc[typedVault] = {
|
|
67
|
-
token: tokenData.underlying,
|
|
68
|
-
balance: currentBalance,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
return acc;
|
|
72
|
-
}, {});
|
|
73
|
-
vaultList = Object.keys(vaultBalances);
|
|
74
|
-
multicallData = vaultList
|
|
75
|
-
.map(function (t) { return token_1.tokenDataByNetwork[p.networkType][t]; })
|
|
76
|
-
.map(function (addr) { return ({
|
|
77
|
-
address: addr,
|
|
78
|
-
interface: types_1.IYVault__factory.createInterface(),
|
|
79
|
-
method: "pricePerShare()",
|
|
80
|
-
}); });
|
|
81
|
-
return [4 /*yield*/, (0, multicall_1.multicall)(multicallData, p.provider)];
|
|
82
|
-
case 1:
|
|
83
|
-
prices = _a.sent();
|
|
84
|
-
for (i = 0; i < vaultList.length; i += 1) {
|
|
85
|
-
vault = vaultList[i];
|
|
86
|
-
vb = vaultBalances[vault];
|
|
87
|
-
p.balances[vb.token] = (p.balances[vb.token] || ethers_1.BigNumber.from(0)).add(ethers_1.BigNumber.from((vb === null || vb === void 0 ? void 0 : vb.balance) || 0).mul(prices[i]));
|
|
88
|
-
tokenAddress = token_1.tokenDataByNetwork[p.networkType][vault];
|
|
89
|
-
adapterAddress = p.creditManager.adapters[tokenAddress];
|
|
90
|
-
callData = types_1.IYVault__factory.createInterface().encodeFunctionData("withdraw()");
|
|
91
|
-
p.calls.push({ target: adapterAddress, callData: callData });
|
|
92
|
-
}
|
|
93
|
-
return [2 /*return*/, p.withdrawTokens()];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
return YearnVaultPathFinder;
|
|
99
|
-
}());
|
|
100
|
-
exports.YearnVaultPathFinder = YearnVaultPathFinder;
|