@gearbox-protocol/sdk 0.0.53 → 0.0.56
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/core/contracts.d.ts +29 -16
- package/lib/core/contracts.js +45 -4
- package/lib/core/contractsRegister.js +24 -6
- package/lib/core/creditAccount.js +26 -20
- package/lib/core/events.d.ts +10 -10
- package/lib/core/events.js +22 -22
- package/lib/core/pathfinder.d.ts +35 -5
- package/lib/core/pathfinder.js +547 -67
- package/lib/core/priceFeeds.js +61 -0
- package/lib/core/token.d.ts +47 -15
- package/lib/core/token.js +204 -36
- package/lib/core/tradeTypes.d.ts +2 -0
- package/lib/core/transactions.d.ts +2 -2
- package/lib/core/transactions.js +10 -10
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -1
- package/lib/pathfinder/connectorPathAsset.d.ts +7 -0
- package/lib/pathfinder/connectorPathAsset.js +144 -0
- package/lib/pathfinder/convexLPTokenPathAsset.d.ts +5 -0
- package/lib/pathfinder/convexLPTokenPathAsset.js +77 -0
- package/lib/pathfinder/curveLPPathAsset.d.ts +5 -0
- package/lib/pathfinder/curveLPPathAsset.js +72 -0
- package/lib/pathfinder/metaCurveLPPathAsset.d.ts +5 -0
- package/lib/pathfinder/metaCurveLPPathAsset.js +72 -0
- package/lib/pathfinder/normalTokenPathAsset.d.ts +5 -0
- package/lib/pathfinder/normalTokenPathAsset.js +136 -0
- package/lib/pathfinder/path.d.ts +41 -0
- package/lib/pathfinder/path.js +302 -0
- package/lib/pathfinder/pathfinder.d.ts +28 -0
- package/lib/pathfinder/pathfinder.js +519 -0
- package/lib/pathfinder/yearnVaultOfCurveLPPathAsset.d.ts +5 -0
- package/lib/pathfinder/yearnVaultOfCurveLPPathAsset.js +87 -0
- package/lib/pathfinder/yearnVaultOfMetaCurveLPPathAsset.d.ts +5 -0
- package/lib/pathfinder/yearnVaultOfMetaCurveLPPathAsset.js +87 -0
- package/lib/pathfinder/yearnVaultPathAsset.d.ts +5 -0
- package/lib/pathfinder/yearnVaultPathAsset.js +87 -0
- package/lib/utils/mappers.d.ts +6 -0
- package/lib/utils/mappers.js +33 -0
- package/lib/utils/types.d.ts +3 -0
- package/lib/utils/types.js +2 -0
- package/package.json +1 -1
- package/src/core/adapters.ts +13 -15
- package/src/core/contracts.ts +111 -44
- package/src/core/contractsRegister.ts +16 -8
- package/src/core/creditAccount.ts +33 -19
- package/src/core/events.ts +30 -22
- package/src/core/priceFeeds.ts +66 -0
- package/src/core/token.ts +645 -370
- package/src/core/tradeTypes.ts +2 -0
- package/src/core/transactions.ts +10 -10
- package/src/index.ts +2 -0
- package/src/pathfinder/connectorPathAsset.ts +69 -0
- package/src/pathfinder/convexLPTokenPathAsset.ts +33 -0
- package/src/pathfinder/curveLPPathAsset.ts +10 -0
- package/src/pathfinder/metaCurveLPPathAsset.ts +12 -0
- package/src/pathfinder/normalTokenPathAsset.ts +68 -0
- package/src/pathfinder/path.ts +259 -0
- package/src/pathfinder/yearnVaultOfCurveLPPathAsset.ts +22 -0
- package/src/pathfinder/yearnVaultOfMetaCurveLPPathAsset.ts +22 -0
- package/src/pathfinder/yearnVaultPathAsset.ts +27 -0
- package/src/utils/mappers.ts +23 -0
- package/src/utils/types.ts +3 -0
- package/src/core/pathfinder.ts +0 -115
package/lib/core/transactions.js
CHANGED
|
@@ -72,7 +72,7 @@ var TxAddLiquidity = /** @class */ (function (_super) {
|
|
|
72
72
|
return _this;
|
|
73
73
|
}
|
|
74
74
|
TxAddLiquidity.prototype.toString = function (tokenData) {
|
|
75
|
-
var token = tokenData[this.underlyingToken];
|
|
75
|
+
var token = tokenData[this.underlyingToken.toLowerCase()];
|
|
76
76
|
return "".concat((0, contractsRegister_1.getContractName)(this.pool), ": Deposit ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat((token === null || token === void 0 ? void 0 : token.symbol) || "");
|
|
77
77
|
};
|
|
78
78
|
TxAddLiquidity.prototype.serialize = function () {
|
|
@@ -99,7 +99,7 @@ var TxRemoveLiquidity = /** @class */ (function (_super) {
|
|
|
99
99
|
return _this;
|
|
100
100
|
}
|
|
101
101
|
TxRemoveLiquidity.prototype.toString = function (tokenData) {
|
|
102
|
-
var dtoken = tokenData[this.dieselToken];
|
|
102
|
+
var dtoken = tokenData[this.dieselToken.toLowerCase()];
|
|
103
103
|
return "".concat((0, contractsRegister_1.getContractName)(this.pool), ": Withdraw ").concat((0, formatter_1.formatBN)(this.amount, (dtoken === null || dtoken === void 0 ? void 0 : dtoken.decimals) || 18), " ").concat((dtoken === null || dtoken === void 0 ? void 0 : dtoken.symbol) || "");
|
|
104
104
|
};
|
|
105
105
|
TxRemoveLiquidity.prototype.serialize = function () {
|
|
@@ -130,10 +130,10 @@ var TXSwap = /** @class */ (function (_super) {
|
|
|
130
130
|
return _this;
|
|
131
131
|
}
|
|
132
132
|
TXSwap.prototype.toString = function (tokenData) {
|
|
133
|
-
var tokenFrom = tokenData[this.tokenFrom];
|
|
133
|
+
var tokenFrom = tokenData[this.tokenFrom.toLowerCase()];
|
|
134
134
|
var toPart = "";
|
|
135
135
|
if (this.tokenTo && this.amountTo) {
|
|
136
|
-
var tokenTo = tokenData[this.tokenTo];
|
|
136
|
+
var tokenTo = tokenData[this.tokenTo.toLowerCase()];
|
|
137
137
|
toPart = " \u21D2 ".concat((0, formatter_1.formatBN)(this.amountTo, (tokenTo === null || tokenTo === void 0 ? void 0 : tokenTo.decimals) || 18), " ").concat((tokenTo === null || tokenTo === void 0 ? void 0 : tokenTo.symbol) || "");
|
|
138
138
|
}
|
|
139
139
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": ").concat(this.operation, " ").concat((0, formatter_1.formatBN)(this.amountFrom, (tokenFrom === null || tokenFrom === void 0 ? void 0 : tokenFrom.decimals) || 18), " ").concat((tokenFrom === null || tokenFrom === void 0 ? void 0 : tokenFrom.symbol) || "", " ").concat(toPart, " on ").concat((0, contractsRegister_1.getContractName)(this.protocol));
|
|
@@ -162,7 +162,7 @@ var TxAddCollateral = /** @class */ (function (_super) {
|
|
|
162
162
|
return _this;
|
|
163
163
|
}
|
|
164
164
|
TxAddCollateral.prototype.toString = function (tokenData) {
|
|
165
|
-
var addedToken = tokenData[this.addedToken];
|
|
165
|
+
var addedToken = tokenData[this.addedToken.toLowerCase()];
|
|
166
166
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Added ").concat((0, formatter_1.formatBN)(this.amount, addedToken.decimals), " ").concat(addedToken.symbol, " as collateral");
|
|
167
167
|
};
|
|
168
168
|
TxAddCollateral.prototype.serialize = function () {
|
|
@@ -189,7 +189,7 @@ var TxIncreaseBorrowAmount = /** @class */ (function (_super) {
|
|
|
189
189
|
return _this;
|
|
190
190
|
}
|
|
191
191
|
TxIncreaseBorrowAmount.prototype.toString = function (tokenData) {
|
|
192
|
-
var token = tokenData[this.underlyingToken];
|
|
192
|
+
var token = tokenData[this.underlyingToken.toLowerCase()];
|
|
193
193
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Borrowed amount was increased for ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol);
|
|
194
194
|
};
|
|
195
195
|
TxIncreaseBorrowAmount.prototype.serialize = function () {
|
|
@@ -217,7 +217,7 @@ var TxOpenAccount = /** @class */ (function (_super) {
|
|
|
217
217
|
return _this;
|
|
218
218
|
}
|
|
219
219
|
TxOpenAccount.prototype.toString = function (tokenData) {
|
|
220
|
-
var token = tokenData[this.underlyingToken];
|
|
220
|
+
var token = tokenData[this.underlyingToken.toLowerCase()];
|
|
221
221
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": opening ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol, " x ").concat(this.leverage.toFixed(2), " \u21D2 \n ").concat((0, formatter_1.formatBN)(this.amount
|
|
222
222
|
.mul(Math.floor(this.leverage * constants_1.LEVERAGE_DECIMALS))
|
|
223
223
|
.div(constants_1.LEVERAGE_DECIMALS), (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol);
|
|
@@ -243,7 +243,7 @@ var TxRepayAccount = /** @class */ (function (_super) {
|
|
|
243
243
|
_this.creditManager = opts.creditManager;
|
|
244
244
|
return _this;
|
|
245
245
|
}
|
|
246
|
-
TxRepayAccount.prototype.toString = function (
|
|
246
|
+
TxRepayAccount.prototype.toString = function (_) {
|
|
247
247
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Repaying account");
|
|
248
248
|
};
|
|
249
249
|
TxRepayAccount.prototype.serialize = function () {
|
|
@@ -267,7 +267,7 @@ var TxCloseAccount = /** @class */ (function (_super) {
|
|
|
267
267
|
_this.creditManager = opts.creditManager;
|
|
268
268
|
return _this;
|
|
269
269
|
}
|
|
270
|
-
TxCloseAccount.prototype.toString = function (
|
|
270
|
+
TxCloseAccount.prototype.toString = function (_) {
|
|
271
271
|
return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Closing account");
|
|
272
272
|
};
|
|
273
273
|
TxCloseAccount.prototype.serialize = function () {
|
|
@@ -292,7 +292,7 @@ var TxApprove = /** @class */ (function (_super) {
|
|
|
292
292
|
return _this;
|
|
293
293
|
}
|
|
294
294
|
TxApprove.prototype.toString = function (tokenData) {
|
|
295
|
-
var token = tokenData[this.token];
|
|
295
|
+
var token = tokenData[this.token.toLowerCase()];
|
|
296
296
|
return "Approve ".concat(token === null || token === void 0 ? void 0 : token.symbol);
|
|
297
297
|
};
|
|
298
298
|
TxApprove.prototype.serialize = function () {
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./core/contracts";
|
|
|
6
6
|
export * from "./core/events";
|
|
7
7
|
export * from "./core/errors";
|
|
8
8
|
export * from "./core/pool";
|
|
9
|
+
export * from "./core/protocols";
|
|
9
10
|
export * from "./core/priceFeeds";
|
|
10
11
|
export * from "./core/operations";
|
|
11
12
|
export * from "./core/oracles";
|
|
@@ -34,3 +35,4 @@ export { MultiCallContract } from "./utils/multicall";
|
|
|
34
35
|
export { callRepeater } from "./utils/repeater";
|
|
35
36
|
export { getContractName } from "./core/contractsRegister";
|
|
36
37
|
export { AdapterInterface } from "./core/adapters";
|
|
38
|
+
export { objectEntries, swapKeyValue, keyToLowercase } from "./utils/mappers";
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.MultiCallContract = void 0;
|
|
17
|
+
exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.MultiCallContract = void 0;
|
|
18
18
|
__exportStar(require("./core/constants"), exports);
|
|
19
19
|
__exportStar(require("./core/creditAccount"), exports);
|
|
20
20
|
__exportStar(require("./core/creditManager"), exports);
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./core/contracts"), exports);
|
|
|
23
23
|
__exportStar(require("./core/events"), exports);
|
|
24
24
|
__exportStar(require("./core/errors"), exports);
|
|
25
25
|
__exportStar(require("./core/pool"), exports);
|
|
26
|
+
__exportStar(require("./core/protocols"), exports);
|
|
26
27
|
__exportStar(require("./core/priceFeeds"), exports);
|
|
27
28
|
__exportStar(require("./core/operations"), exports);
|
|
28
29
|
__exportStar(require("./core/oracles"), exports);
|
|
@@ -54,3 +55,7 @@ var contractsRegister_1 = require("./core/contractsRegister");
|
|
|
54
55
|
Object.defineProperty(exports, "getContractName", { enumerable: true, get: function () { return contractsRegister_1.getContractName; } });
|
|
55
56
|
var adapters_1 = require("./core/adapters");
|
|
56
57
|
Object.defineProperty(exports, "AdapterInterface", { enumerable: true, get: function () { return adapters_1.AdapterInterface; } });
|
|
58
|
+
var mappers_1 = require("./utils/mappers");
|
|
59
|
+
Object.defineProperty(exports, "objectEntries", { enumerable: true, get: function () { return mappers_1.objectEntries; } });
|
|
60
|
+
Object.defineProperty(exports, "swapKeyValue", { enumerable: true, get: function () { return mappers_1.swapKeyValue; } });
|
|
61
|
+
Object.defineProperty(exports, "keyToLowercase", { enumerable: true, get: function () { return mappers_1.keyToLowercase; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { SupportedToken } from "../core/token";
|
|
3
|
+
import { Path, PathAsset } from "./path";
|
|
4
|
+
export declare class ConnectorPathAsset extends PathAsset {
|
|
5
|
+
getBestPath(currentToken: SupportedToken, p: Path): Promise<Path>;
|
|
6
|
+
getMaxPoolAmount(currentToken: SupportedToken, currentBalance: BigNumber, p: Path): Promise<BigNumber>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.ConnectorPathAsset = void 0;
|
|
55
|
+
var ethers_1 = require("ethers");
|
|
56
|
+
var token_1 = require("../core/token");
|
|
57
|
+
var path_1 = require("./path");
|
|
58
|
+
var ConnectorPathAsset = /** @class */ (function (_super) {
|
|
59
|
+
__extends(ConnectorPathAsset, _super);
|
|
60
|
+
function ConnectorPathAsset() {
|
|
61
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
62
|
+
}
|
|
63
|
+
ConnectorPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var currentBalance, currentTokenAddress, currentTokenData, nextToken, nextTokenAddress, actionData, _i, _a, swapAction, tmpActionData;
|
|
66
|
+
return __generator(this, function (_b) {
|
|
67
|
+
switch (_b.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
currentBalance = p.balances[currentToken].sub(1);
|
|
70
|
+
currentTokenAddress = token_1.tokenDataByNetwork[p.networkType][currentToken];
|
|
71
|
+
currentTokenData = token_1.supportedTokens[currentToken];
|
|
72
|
+
nextToken = p.pool;
|
|
73
|
+
nextTokenAddress = token_1.tokenDataByNetwork[p.networkType][nextToken];
|
|
74
|
+
actionData = {
|
|
75
|
+
callData: {
|
|
76
|
+
targetContract: "",
|
|
77
|
+
callData: ""
|
|
78
|
+
},
|
|
79
|
+
amountOut: ethers_1.BigNumber.from(0),
|
|
80
|
+
gasLimit: ethers_1.BigNumber.from(0),
|
|
81
|
+
};
|
|
82
|
+
_i = 0, _a = currentTokenData.swapActions;
|
|
83
|
+
_b.label = 1;
|
|
84
|
+
case 1:
|
|
85
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
86
|
+
swapAction = _a[_i];
|
|
87
|
+
return [4 /*yield*/, this.getActionData(swapAction, currentTokenAddress, currentToken, currentBalance, nextTokenAddress, nextToken, p)];
|
|
88
|
+
case 2:
|
|
89
|
+
tmpActionData = _b.sent();
|
|
90
|
+
if (tmpActionData.amountOut > actionData.amountOut) {
|
|
91
|
+
actionData = tmpActionData;
|
|
92
|
+
}
|
|
93
|
+
_b.label = 3;
|
|
94
|
+
case 3:
|
|
95
|
+
_i++;
|
|
96
|
+
return [3 /*break*/, 1];
|
|
97
|
+
case 4:
|
|
98
|
+
if (actionData.callData.targetContract != "") {
|
|
99
|
+
p.balances[nextToken].add(actionData.amountOut);
|
|
100
|
+
p.balances[currentToken] = ethers_1.BigNumber.from(1);
|
|
101
|
+
p.totalGasLimit.add(actionData.gasLimit);
|
|
102
|
+
p.calls.push(actionData.callData);
|
|
103
|
+
}
|
|
104
|
+
return [4 /*yield*/, p.getBestPath()];
|
|
105
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
// Only compute the maximum amount of pool token output, will not modify path.
|
|
111
|
+
ConnectorPathAsset.prototype.getMaxPoolAmount = function (currentToken, currentBalance, p) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var currentTokenAddress, currentTokenData, nextToken, nextTokenAddress, maxAmountOut, _i, _a, swapAction, actionData;
|
|
114
|
+
return __generator(this, function (_b) {
|
|
115
|
+
switch (_b.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
currentTokenAddress = token_1.tokenDataByNetwork[p.networkType][currentToken];
|
|
118
|
+
currentTokenData = token_1.supportedTokens[currentToken];
|
|
119
|
+
nextToken = p.pool;
|
|
120
|
+
nextTokenAddress = token_1.tokenDataByNetwork[p.networkType][nextToken];
|
|
121
|
+
maxAmountOut = ethers_1.BigNumber.from(0);
|
|
122
|
+
_i = 0, _a = currentTokenData.swapActions;
|
|
123
|
+
_b.label = 1;
|
|
124
|
+
case 1:
|
|
125
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
126
|
+
swapAction = _a[_i];
|
|
127
|
+
return [4 /*yield*/, this.getActionData(swapAction, currentTokenAddress, currentToken, currentBalance, nextTokenAddress, nextToken, p)];
|
|
128
|
+
case 2:
|
|
129
|
+
actionData = _b.sent();
|
|
130
|
+
if (actionData.amountOut > maxAmountOut) {
|
|
131
|
+
maxAmountOut = actionData.amountOut;
|
|
132
|
+
}
|
|
133
|
+
_b.label = 3;
|
|
134
|
+
case 3:
|
|
135
|
+
_i++;
|
|
136
|
+
return [3 /*break*/, 1];
|
|
137
|
+
case 4: return [2 /*return*/, maxAmountOut];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
return ConnectorPathAsset;
|
|
143
|
+
}(path_1.PathAsset));
|
|
144
|
+
exports.ConnectorPathAsset = ConnectorPathAsset;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.ConvexLPTokenPathAsset = void 0;
|
|
55
|
+
var token_1 = require("../core/token");
|
|
56
|
+
var contracts_1 = require("../core/contracts");
|
|
57
|
+
var tradeTypes_1 = require("../core/tradeTypes");
|
|
58
|
+
var path_1 = require("./path");
|
|
59
|
+
var ConvexLPTokenPathAsset = /** @class */ (function (_super) {
|
|
60
|
+
__extends(ConvexLPTokenPathAsset, _super);
|
|
61
|
+
function ConvexLPTokenPathAsset() {
|
|
62
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
63
|
+
}
|
|
64
|
+
ConvexLPTokenPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var currentBalance, currentTokenData, _i, _a, lpAction, actionContractAddress, adapterAddress, outputToken;
|
|
67
|
+
return __generator(this, function (_b) {
|
|
68
|
+
switch (_b.label) {
|
|
69
|
+
case 0: throw Error("Implementation not finished!");
|
|
70
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
return ConvexLPTokenPathAsset;
|
|
76
|
+
}(path_1.PathAsset));
|
|
77
|
+
exports.ConvexLPTokenPathAsset = ConvexLPTokenPathAsset;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.CurveLPPathAsset = void 0;
|
|
55
|
+
var path_1 = require("./path");
|
|
56
|
+
var CurveLPPathAsset = /** @class */ (function (_super) {
|
|
57
|
+
__extends(CurveLPPathAsset, _super);
|
|
58
|
+
function CurveLPPathAsset() {
|
|
59
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
60
|
+
}
|
|
61
|
+
CurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
console.log(currentToken);
|
|
65
|
+
console.log(p);
|
|
66
|
+
throw Error("Not implemented yet.");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return CurveLPPathAsset;
|
|
71
|
+
}(path_1.PathAsset));
|
|
72
|
+
exports.CurveLPPathAsset = CurveLPPathAsset;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.MetaCurveLPPathAsset = void 0;
|
|
55
|
+
var path_1 = require("./path");
|
|
56
|
+
var MetaCurveLPPathAsset = /** @class */ (function (_super) {
|
|
57
|
+
__extends(MetaCurveLPPathAsset, _super);
|
|
58
|
+
function MetaCurveLPPathAsset() {
|
|
59
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
60
|
+
}
|
|
61
|
+
MetaCurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
console.log(currentToken);
|
|
65
|
+
console.log(p);
|
|
66
|
+
throw Error("Not implemented yet.");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return MetaCurveLPPathAsset;
|
|
71
|
+
}(path_1.PathAsset));
|
|
72
|
+
exports.MetaCurveLPPathAsset = MetaCurveLPPathAsset;
|