@gearbox-protocol/sdk 0.0.102 → 0.0.103
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/.eslintignore +4 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +3 -3
- package/lib/contracts/contracts.js +2 -2
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +18 -15
- package/lib/strategies/curve.d.ts +6 -60
- package/lib/strategies/curve.js +6 -0
- package/lib/strategies/uniswapV2.js +3 -19
- package/lib/strategies/uniswapV3.js +1 -1
- package/lib/strategies/yearn.js +15 -11
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +26 -8
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +8 -7
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +1 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +217 -210
- package/src/strategies/creditFacade.ts +70 -53
- package/src/strategies/curve.ts +263 -194
- package/src/strategies/lido.ts +33 -37
- package/src/strategies/uniswapV2.ts +90 -112
- package/src/strategies/uniswapV3.ts +114 -91
- package/src/strategies/yearn.ts +58 -62
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +170 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +126 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/lib/core/price.js
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calcTotalPrice = void 0;
|
|
4
4
|
var ethers_1 = require("ethers");
|
|
5
|
+
var constants_1 = require("./constants");
|
|
5
6
|
var calcTotalPrice = function (price, amount, decimals) {
|
|
6
7
|
if (decimals === void 0) { decimals = 18; }
|
|
7
|
-
return amount
|
|
8
|
+
return amount
|
|
9
|
+
.mul(constants_1.WAD)
|
|
10
|
+
.mul(price)
|
|
11
|
+
.div(ethers_1.BigNumber.from(10).pow(decimals))
|
|
12
|
+
.div(constants_1.PRICE_DECIMALS);
|
|
8
13
|
};
|
|
9
14
|
exports.calcTotalPrice = calcTotalPrice;
|
package/lib/core/strategy.d.ts
CHANGED
|
@@ -26,11 +26,9 @@ export declare class Strategy {
|
|
|
26
26
|
leveragableCollateral: Array<string>;
|
|
27
27
|
baseAssets: Array<string>;
|
|
28
28
|
constructor(payload: StrategyPayload);
|
|
29
|
-
maxAPY(
|
|
29
|
+
maxAPY(maxLeverage: number, poolApy: PoolList): number;
|
|
30
30
|
overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
|
|
31
31
|
liquidationPrice(borrowed: TokenDescription, collateral: TokenDescription, lp: TokenDescription, ltCollateral: BigNumber): BigNumber;
|
|
32
|
-
private roi;
|
|
33
|
-
private minBorrowApy;
|
|
34
32
|
private farmLev;
|
|
35
33
|
private inBaseAssets;
|
|
36
34
|
private inLeveragableAssets;
|
package/lib/core/strategy.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Strategy = void 0;
|
|
4
4
|
var ethers_1 = require("ethers");
|
|
5
|
-
var constants_1 = require("
|
|
6
|
-
var price_1 = require("
|
|
5
|
+
var constants_1 = require("./constants");
|
|
6
|
+
var price_1 = require("./price");
|
|
7
7
|
var Strategy = /** @class */ (function () {
|
|
8
8
|
function Strategy(payload) {
|
|
9
9
|
this.apy = payload.apy;
|
|
@@ -14,14 +14,15 @@ var Strategy = /** @class */ (function () {
|
|
|
14
14
|
this.leveragableCollateral = payload.leveragableCollateral;
|
|
15
15
|
this.baseAssets = payload.baseAssets;
|
|
16
16
|
}
|
|
17
|
-
Strategy.prototype.maxAPY = function (
|
|
18
|
-
var minApy =
|
|
19
|
-
return this.
|
|
17
|
+
Strategy.prototype.maxAPY = function (maxLeverage, poolApy) {
|
|
18
|
+
var minApy = minBorrowApy(poolApy);
|
|
19
|
+
return roi(this.apy || 0, maxLeverage, maxLeverage - constants_1.LEVERAGE_DECIMALS, minApy);
|
|
20
20
|
};
|
|
21
21
|
Strategy.prototype.overallAPY = function (apy, leverage, depositCollateral, borrowAPY) {
|
|
22
22
|
var farmLev = this.farmLev(leverage, depositCollateral);
|
|
23
|
-
return
|
|
23
|
+
return roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
24
24
|
};
|
|
25
|
+
// eslint-disable-next-line class-methods-use-this
|
|
25
26
|
Strategy.prototype.liquidationPrice = function (borrowed, collateral, lp, ltCollateral) {
|
|
26
27
|
var borrowedMoney = (0, price_1.calcTotalPrice)(borrowed.price, borrowed.amount, borrowed.decimals);
|
|
27
28
|
var collateralMoney = (0, price_1.calcTotalPrice)(collateral.price, collateral.amount, collateral.decimals)
|
|
@@ -32,13 +33,6 @@ var Strategy = /** @class */ (function () {
|
|
|
32
33
|
? borrowedMoney.sub(collateralMoney).mul(constants_1.WAD).div(lpMoney)
|
|
33
34
|
: ethers_1.BigNumber.from(0);
|
|
34
35
|
};
|
|
35
|
-
Strategy.prototype.roi = function (apy, farmLev, debtLev, borrowAPY) {
|
|
36
|
-
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
|
37
|
-
};
|
|
38
|
-
Strategy.prototype.minBorrowApy = function (poolApy) {
|
|
39
|
-
var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
|
|
40
|
-
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
41
|
-
};
|
|
42
36
|
Strategy.prototype.farmLev = function (leverage, depositCollateral) {
|
|
43
37
|
return this.inBaseAssets(depositCollateral) ||
|
|
44
38
|
this.inLeveragableAssets(depositCollateral)
|
|
@@ -54,3 +48,10 @@ var Strategy = /** @class */ (function () {
|
|
|
54
48
|
return Strategy;
|
|
55
49
|
}());
|
|
56
50
|
exports.Strategy = Strategy;
|
|
51
|
+
function roi(apy, farmLev, debtLev, borrowAPY) {
|
|
52
|
+
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
|
53
|
+
}
|
|
54
|
+
function minBorrowApy(poolApy) {
|
|
55
|
+
var apys = Object.values(poolApy).sort(function (a, b) { return a.borrowRate - b.borrowRate; });
|
|
56
|
+
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
57
|
+
}
|
|
@@ -5,5 +5,5 @@ var VotingPower;
|
|
|
5
5
|
(function (VotingPower) {
|
|
6
6
|
VotingPower[VotingPower["A"] = 0] = "A";
|
|
7
7
|
VotingPower[VotingPower["B"] = 1] = "B";
|
|
8
|
-
VotingPower[VotingPower["ZERO_VOTING_POWER"] = 2] = "ZERO_VOTING_POWER";
|
|
8
|
+
VotingPower[VotingPower["ZERO_VOTING_POWER"] = 2] = "ZERO_VOTING_POWER"; // zero voting power & B-type vesting parameters
|
|
9
9
|
})(VotingPower = exports.VotingPower || (exports.VotingPower = {}));
|
|
@@ -2,7 +2,7 @@ import { BigNumber } from "ethers";
|
|
|
2
2
|
import { TokenData } from "../tokens/tokenData";
|
|
3
3
|
import { EVMTx, EVMTxProps } from "./eventOrTx";
|
|
4
4
|
export interface TxSerialized {
|
|
5
|
-
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove";
|
|
5
|
+
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount";
|
|
6
6
|
content: string;
|
|
7
7
|
}
|
|
8
8
|
export declare class TxSerializer {
|
|
@@ -97,13 +97,28 @@ export declare class TxOpenAccount extends EVMTx {
|
|
|
97
97
|
toString(tokenData: Record<string, TokenData>): string;
|
|
98
98
|
serialize(): TxSerialized;
|
|
99
99
|
}
|
|
100
|
+
interface TxOpenMultitokenAccountProps extends EVMTxProps {
|
|
101
|
+
borrowedAmount: BigNumber;
|
|
102
|
+
creditManager: string;
|
|
103
|
+
underlyingToken: string;
|
|
104
|
+
assets: Array<string>;
|
|
105
|
+
}
|
|
106
|
+
export declare class TxOpenMultitokenAccount extends EVMTx {
|
|
107
|
+
readonly borrowedAmount: BigNumber;
|
|
108
|
+
readonly creditManager: string;
|
|
109
|
+
readonly underlyingToken: string;
|
|
110
|
+
readonly assets: Array<string>;
|
|
111
|
+
constructor(opts: TxOpenMultitokenAccountProps);
|
|
112
|
+
toString(tokenData: Record<string, TokenData>): string;
|
|
113
|
+
serialize(): TxSerialized;
|
|
114
|
+
}
|
|
100
115
|
interface RepayAccountProps extends EVMTxProps {
|
|
101
116
|
creditManager: string;
|
|
102
117
|
}
|
|
103
118
|
export declare class TxRepayAccount extends EVMTx {
|
|
104
119
|
readonly creditManager: string;
|
|
105
120
|
constructor(opts: RepayAccountProps);
|
|
106
|
-
toString(
|
|
121
|
+
toString(): string;
|
|
107
122
|
serialize(): TxSerialized;
|
|
108
123
|
}
|
|
109
124
|
interface CloseAccountProps extends EVMTxProps {
|
|
@@ -112,7 +127,7 @@ interface CloseAccountProps extends EVMTxProps {
|
|
|
112
127
|
export declare class TxCloseAccount extends EVMTx {
|
|
113
128
|
readonly creditManager: string;
|
|
114
129
|
constructor(opts: CloseAccountProps);
|
|
115
|
-
toString(
|
|
130
|
+
toString(): string;
|
|
116
131
|
serialize(): TxSerialized;
|
|
117
132
|
}
|
|
118
133
|
interface ApproveProps extends EVMTxProps {
|
package/lib/core/transactions.js
CHANGED
|
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxOpenAccount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
|
|
18
|
+
exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxOpenMultitokenAccount = exports.TxOpenAccount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
|
|
19
19
|
var ethers_1 = require("ethers");
|
|
20
20
|
var formatter_1 = require("../utils/formatter");
|
|
21
21
|
var eventOrTx_1 = require("./eventOrTx");
|
|
@@ -49,6 +49,8 @@ var TxSerializer = /** @class */ (function () {
|
|
|
49
49
|
return new TxCloseAccount(params);
|
|
50
50
|
case "TxApprove":
|
|
51
51
|
return new TxApprove(params);
|
|
52
|
+
case "TxOpenMultitokenAccount":
|
|
53
|
+
return new TxOpenMultitokenAccount(params);
|
|
52
54
|
default:
|
|
53
55
|
throw new Error("Unknown transaction for parsing");
|
|
54
56
|
}
|
|
@@ -231,6 +233,40 @@ var TxOpenAccount = /** @class */ (function (_super) {
|
|
|
231
233
|
return TxOpenAccount;
|
|
232
234
|
}(eventOrTx_1.EVMTx));
|
|
233
235
|
exports.TxOpenAccount = TxOpenAccount;
|
|
236
|
+
var TxOpenMultitokenAccount = /** @class */ (function (_super) {
|
|
237
|
+
__extends(TxOpenMultitokenAccount, _super);
|
|
238
|
+
function TxOpenMultitokenAccount(opts) {
|
|
239
|
+
var _this = _super.call(this, {
|
|
240
|
+
block: opts.block,
|
|
241
|
+
txHash: opts.txHash,
|
|
242
|
+
txStatus: opts.txStatus,
|
|
243
|
+
timestamp: opts.timestamp
|
|
244
|
+
}) || this;
|
|
245
|
+
_this.borrowedAmount = ethers_1.BigNumber.from(opts.borrowedAmount);
|
|
246
|
+
_this.underlyingToken = opts.underlyingToken;
|
|
247
|
+
_this.creditManager = opts.creditManager;
|
|
248
|
+
_this.assets = opts.assets;
|
|
249
|
+
return _this;
|
|
250
|
+
}
|
|
251
|
+
TxOpenMultitokenAccount.prototype.toString = function (tokenData) {
|
|
252
|
+
var underlyingToken = tokenData[this.underlyingToken.toLowerCase()];
|
|
253
|
+
var assetSymbols = this.assets.reduce(function (acc, assetAddress) {
|
|
254
|
+
var token = tokenData[assetAddress.toLowerCase()];
|
|
255
|
+
if (token)
|
|
256
|
+
acc.push(token.symbol);
|
|
257
|
+
return acc;
|
|
258
|
+
}, []);
|
|
259
|
+
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": opening. Borrowed amount: ").concat((0, formatter_1.formatBN)(this.borrowedAmount, (underlyingToken === null || underlyingToken === void 0 ? void 0 : underlyingToken.decimals) || 18), " ").concat(underlyingToken === null || underlyingToken === void 0 ? void 0 : underlyingToken.symbol, "; assets: ").concat(assetSymbols.join(", "));
|
|
260
|
+
};
|
|
261
|
+
TxOpenMultitokenAccount.prototype.serialize = function () {
|
|
262
|
+
return {
|
|
263
|
+
type: "TxOpenMultitokenAccount",
|
|
264
|
+
content: JSON.stringify(this)
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
return TxOpenMultitokenAccount;
|
|
268
|
+
}(eventOrTx_1.EVMTx));
|
|
269
|
+
exports.TxOpenMultitokenAccount = TxOpenMultitokenAccount;
|
|
234
270
|
var TxRepayAccount = /** @class */ (function (_super) {
|
|
235
271
|
__extends(TxRepayAccount, _super);
|
|
236
272
|
function TxRepayAccount(opts) {
|
|
@@ -243,7 +279,7 @@ var TxRepayAccount = /** @class */ (function (_super) {
|
|
|
243
279
|
_this.creditManager = opts.creditManager;
|
|
244
280
|
return _this;
|
|
245
281
|
}
|
|
246
|
-
TxRepayAccount.prototype.toString = function (
|
|
282
|
+
TxRepayAccount.prototype.toString = function () {
|
|
247
283
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Repaying account");
|
|
248
284
|
};
|
|
249
285
|
TxRepayAccount.prototype.serialize = function () {
|
|
@@ -267,7 +303,7 @@ var TxCloseAccount = /** @class */ (function (_super) {
|
|
|
267
303
|
_this.creditManager = opts.creditManager;
|
|
268
304
|
return _this;
|
|
269
305
|
}
|
|
270
|
-
TxCloseAccount.prototype.toString = function (
|
|
306
|
+
TxCloseAccount.prototype.toString = function () {
|
|
271
307
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Closing account");
|
|
272
308
|
};
|
|
273
309
|
TxCloseAccount.prototype.serialize = function () {
|
package/lib/index.d.ts
CHANGED
|
@@ -23,12 +23,10 @@ export * from "./payload/token";
|
|
|
23
23
|
export * from "./utils/formatter";
|
|
24
24
|
export * from "./utils/loading";
|
|
25
25
|
export * from "./utils/validate";
|
|
26
|
-
export * from "./utils/events";
|
|
27
26
|
export * from "./utils/math";
|
|
28
27
|
export * from "./payload/graphPayload";
|
|
29
28
|
export * from "./types/index";
|
|
30
29
|
export * from "./core/strategy";
|
|
31
|
-
export type { IDataCompressor, IWETHGateway } from "./types";
|
|
32
30
|
export { TokenType } from "./tokens/tokenType";
|
|
33
31
|
export * from "./tokens/token";
|
|
34
32
|
export * from "./tokens/tokenData";
|
|
@@ -43,6 +41,7 @@ export * from "./apy/convexAPY";
|
|
|
43
41
|
export * from "./core/history";
|
|
44
42
|
export * from "./utils/multicall";
|
|
45
43
|
export * from "./utils/types";
|
|
44
|
+
export * from "./utils/errors";
|
|
46
45
|
export { callRepeater } from "./utils/repeater";
|
|
47
46
|
export { getContractName } from "./contracts/contractsRegister";
|
|
48
47
|
export { AdapterInterface } from "./contracts/adapters";
|
package/lib/index.js
CHANGED
|
@@ -40,7 +40,6 @@ __exportStar(require("./payload/token"), exports);
|
|
|
40
40
|
__exportStar(require("./utils/formatter"), exports);
|
|
41
41
|
__exportStar(require("./utils/loading"), exports);
|
|
42
42
|
__exportStar(require("./utils/validate"), exports);
|
|
43
|
-
__exportStar(require("./utils/events"), exports);
|
|
44
43
|
__exportStar(require("./utils/math"), exports);
|
|
45
44
|
__exportStar(require("./payload/graphPayload"), exports);
|
|
46
45
|
__exportStar(require("./types/index"), exports);
|
|
@@ -61,6 +60,7 @@ __exportStar(require("./apy/convexAPY"), exports);
|
|
|
61
60
|
__exportStar(require("./core/history"), exports);
|
|
62
61
|
__exportStar(require("./utils/multicall"), exports);
|
|
63
62
|
__exportStar(require("./utils/types"), exports);
|
|
63
|
+
__exportStar(require("./utils/errors"), exports);
|
|
64
64
|
var repeater_1 = require("./utils/repeater");
|
|
65
65
|
Object.defineProperty(exports, "callRepeater", { enumerable: true, get: function () { return repeater_1.callRepeater; } });
|
|
66
66
|
var contractsRegister_1 = require("./contracts/contractsRegister");
|
|
@@ -38,40 +38,37 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.ConvexLPPathFinder = void 0;
|
|
40
40
|
var convex_1 = require("../tokens/convex");
|
|
41
|
+
var mappers_1 = require("../utils/mappers");
|
|
41
42
|
var ConvexLPPathFinder = /** @class */ (function () {
|
|
42
43
|
function ConvexLPPathFinder() {
|
|
43
44
|
}
|
|
45
|
+
// eslint-disable-next-line class-methods-use-this
|
|
44
46
|
ConvexLPPathFinder.prototype.findWithdrawPaths = function (p) {
|
|
45
47
|
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var pids
|
|
47
|
-
return __generator(this, function (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// balance.balance
|
|
71
|
-
// );
|
|
72
|
-
// }
|
|
73
|
-
return [2 /*return*/, _c.sent()];
|
|
74
|
-
}
|
|
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()];
|
|
75
72
|
});
|
|
76
73
|
});
|
|
77
74
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LPWithdrawPathFinder, Path } from "./path";
|
|
1
|
+
import type { LPWithdrawPathFinder, Path } from "./path";
|
|
2
2
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
3
3
|
import { CurvePoolContract } from "../contracts/contracts";
|
|
4
4
|
export declare class CurvePathFinder implements LPWithdrawPathFinder {
|
|
@@ -45,12 +45,11 @@ var types_1 = require("../types");
|
|
|
45
45
|
var CurvePathFinder = /** @class */ (function () {
|
|
46
46
|
function CurvePathFinder(token) {
|
|
47
47
|
this.lpToken = token;
|
|
48
|
-
var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type
|
|
48
|
+
var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type === tradeTypes_1.TradeType.CurveWithdrawLP; });
|
|
49
49
|
if (curvePools.length !== 1)
|
|
50
50
|
throw new Error("Cant find Withdrawer");
|
|
51
51
|
this.contract = curvePools[0].contract;
|
|
52
|
-
var wrapper = contracts_1.contractParams[curvePools[0].contract]
|
|
53
|
-
.wrapper;
|
|
52
|
+
var wrapper = contracts_1.contractParams[curvePools[0].contract].wrapper;
|
|
54
53
|
if (wrapper) {
|
|
55
54
|
this.contract = wrapper;
|
|
56
55
|
}
|
|
@@ -66,9 +65,8 @@ var CurvePathFinder = /** @class */ (function () {
|
|
|
66
65
|
lpBalance = p.popBalance(this.lpToken);
|
|
67
66
|
multiCallContract = new multicall_1.MultiCallContract(contracts_1.contractsByAddress[this.contract], types_1.ICurvePool__factory.createInterface(), p.provider);
|
|
68
67
|
data = [];
|
|
69
|
-
for (i = 0; i < nCoins; i
|
|
68
|
+
for (i = 0; i < nCoins; i += 1) {
|
|
70
69
|
data.push({
|
|
71
|
-
// @ts-ignore
|
|
72
70
|
method: "calc_withdraw_one_coin(uint256,int128)",
|
|
73
71
|
params: [lpBalance, i]
|
|
74
72
|
});
|
|
@@ -76,9 +74,9 @@ var CurvePathFinder = /** @class */ (function () {
|
|
|
76
74
|
return [4 /*yield*/, multiCallContract.call(data)];
|
|
77
75
|
case 1:
|
|
78
76
|
balances = _a.sent();
|
|
79
|
-
console.
|
|
77
|
+
console.debug(balances);
|
|
80
78
|
paths = [];
|
|
81
|
-
for (i = 0; i < nCoins; i
|
|
79
|
+
for (i = 0; i < nCoins; i += 1) {
|
|
82
80
|
newPath = p.clone();
|
|
83
81
|
// newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
|
|
84
82
|
// newPath.calls.push({
|
package/lib/pathfinder/path.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare class Path {
|
|
|
24
24
|
totalGasLimit: number;
|
|
25
25
|
});
|
|
26
26
|
popBalance(token: SupportedToken): BigNumber;
|
|
27
|
-
private comparedByPriority;
|
|
27
|
+
private static comparedByPriority;
|
|
28
28
|
static findBestPath(creditAccount: CreditAccountData, creditManager: CreditManagerData, provider: ethers.providers.Provider): Promise<void>;
|
|
29
29
|
withdrawTokens(): Promise<Array<Path>>;
|
|
30
30
|
clone(): Path;
|
package/lib/pathfinder/path.js
CHANGED
|
@@ -76,15 +76,15 @@ var Path = /** @class */ (function () {
|
|
|
76
76
|
this.balances[token] = ethers_1.BigNumber.from(1);
|
|
77
77
|
return currentBalance.sub(1);
|
|
78
78
|
};
|
|
79
|
-
Path.
|
|
80
|
-
var tokenA = _a[0]
|
|
81
|
-
var tokenB = _b[0]
|
|
79
|
+
Path.comparedByPriority = function (_a, _b) {
|
|
80
|
+
var tokenA = _a[0];
|
|
81
|
+
var tokenB = _b[0];
|
|
82
82
|
var priorityTokenA = priority_1.priority[token_1.supportedTokens[tokenA].type];
|
|
83
83
|
var priorityTokenB = priority_1.priority[token_1.supportedTokens[tokenB].type];
|
|
84
84
|
if (priorityTokenA > priorityTokenB) {
|
|
85
85
|
return -1;
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
if (priorityTokenA < priorityTokenB) {
|
|
88
88
|
return 1;
|
|
89
89
|
}
|
|
90
90
|
return 0;
|
|
@@ -123,8 +123,8 @@ var Path = /** @class */ (function () {
|
|
|
123
123
|
case 2:
|
|
124
124
|
lpPaths = _a.sent();
|
|
125
125
|
pathFinder = types_1.PathFinder__factory.connect(contracts_1.pathFindersByNetwork[networkType].PATH_FINDER, provider);
|
|
126
|
-
console.
|
|
127
|
-
console.
|
|
126
|
+
console.debug(lpPaths);
|
|
127
|
+
console.debug(pathFinder);
|
|
128
128
|
return [2 /*return*/];
|
|
129
129
|
}
|
|
130
130
|
});
|
|
@@ -134,43 +134,39 @@ var Path = /** @class */ (function () {
|
|
|
134
134
|
return __awaiter(this, void 0, void 0, function () {
|
|
135
135
|
var existingTokens, nextToken, lpPathFinder;
|
|
136
136
|
return __generator(this, function (_a) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
default:
|
|
169
|
-
throw new Error("Token type not supported yet");
|
|
170
|
-
}
|
|
171
|
-
return [4 /*yield*/, lpPathFinder.findWithdrawPaths(this)];
|
|
172
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
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");
|
|
173
168
|
}
|
|
169
|
+
return [2 /*return*/, lpPathFinder.findWithdrawPaths(this)];
|
|
174
170
|
});
|
|
175
171
|
});
|
|
176
172
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract } from "../contracts/contracts";
|
|
2
|
-
import { NormalToken } from "../tokens/normal";
|
|
3
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
4
|
-
import { YearnLPToken } from "../tokens/yearn";
|
|
5
|
-
import { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
|
|
1
|
+
import type { ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract } from "../contracts/contracts";
|
|
2
|
+
import type { NormalToken } from "../tokens/normal";
|
|
3
|
+
import type { CurveLPToken } from "../tokens/curveLP";
|
|
4
|
+
import type { YearnLPToken } from "../tokens/yearn";
|
|
5
|
+
import type { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
|
|
6
6
|
export declare enum TradeType {
|
|
7
7
|
UniswapV2Swap = 0,
|
|
8
8
|
UniswapV3Swap = 1,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Path, LPWithdrawPathFinder } from "./path";
|
|
2
1
|
import { YearnLPToken } from "../tokens/yearn";
|
|
3
2
|
import { NormalToken } from "../tokens/normal";
|
|
4
3
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
4
|
+
import type { Path, LPWithdrawPathFinder } from "./path";
|
|
5
5
|
export declare class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
6
6
|
_vault: YearnLPToken;
|
|
7
7
|
token: NormalToken | CurveLPToken;
|
|
8
8
|
constructor(vault: YearnLPToken);
|
|
9
|
-
findWithdrawPaths(
|
|
9
|
+
findWithdrawPaths(path: Path): Promise<Array<Path>>;
|
|
10
10
|
}
|
package/lib/pathfinder/yVault.js
CHANGED
|
@@ -38,10 +38,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.YearnVaultPathFinder = void 0;
|
|
40
40
|
var ethers_1 = require("ethers");
|
|
41
|
-
var types_1 = require("../types");
|
|
42
41
|
var yearn_1 = require("../tokens/yearn");
|
|
43
42
|
var token_1 = require("../tokens/token");
|
|
44
43
|
var multicall_1 = require("../utils/multicall");
|
|
44
|
+
var mappers_1 = require("../utils/mappers");
|
|
45
|
+
var types_1 = require("../types");
|
|
45
46
|
var YearnVaultPathFinder = /** @class */ (function () {
|
|
46
47
|
function YearnVaultPathFinder(vault) {
|
|
47
48
|
this._vault = vault;
|
|
@@ -49,23 +50,26 @@ var YearnVaultPathFinder = /** @class */ (function () {
|
|
|
49
50
|
// Yearn Vault only has one lp action
|
|
50
51
|
this.token = currentTokenData.underlying;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
+
// eslint-disable-next-line class-methods-use-this
|
|
54
|
+
YearnVaultPathFinder.prototype.findWithdrawPaths = function (path) {
|
|
53
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var
|
|
55
|
-
return __generator(this, function (
|
|
56
|
-
switch (
|
|
56
|
+
var p, vaultBalances, vaultList, multicallData, prices, i, vault, vb, tokenAddress, adapterAddress, callData;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
57
59
|
case 0:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
p = Object.assign(Object.create(Object.getPrototypeOf(path)), path);
|
|
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);
|
|
62
65
|
if (currentBalance.gt(1)) {
|
|
63
|
-
|
|
66
|
+
acc[typedVault] = {
|
|
64
67
|
token: tokenData.underlying,
|
|
65
68
|
balance: currentBalance
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
|
-
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
69
73
|
vaultList = Object.keys(vaultBalances);
|
|
70
74
|
multicallData = vaultList
|
|
71
75
|
.map(function (t) { return token_1.tokenDataByNetwork[p.networkType][t]; })
|
|
@@ -76,8 +80,8 @@ var YearnVaultPathFinder = /** @class */ (function () {
|
|
|
76
80
|
}); });
|
|
77
81
|
return [4 /*yield*/, (0, multicall_1.multicall)(multicallData, p.provider)];
|
|
78
82
|
case 1:
|
|
79
|
-
prices =
|
|
80
|
-
for (i = 0; i < vaultList.length; i
|
|
83
|
+
prices = _a.sent();
|
|
84
|
+
for (i = 0; i < vaultList.length; i += 1) {
|
|
81
85
|
vault = vaultList[i];
|
|
82
86
|
vb = vaultBalances[vault];
|
|
83
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]));
|
|
@@ -86,8 +90,7 @@ var YearnVaultPathFinder = /** @class */ (function () {
|
|
|
86
90
|
callData = types_1.IYVault__factory.createInterface().encodeFunctionData("withdraw()");
|
|
87
91
|
p.calls.push({ target: adapterAddress, callData: callData });
|
|
88
92
|
}
|
|
89
|
-
return [
|
|
90
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
93
|
+
return [2 /*return*/, p.withdrawTokens()];
|
|
91
94
|
}
|
|
92
95
|
});
|
|
93
96
|
});
|