@curvefi/api 2.31.1 → 2.33.0
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/boosting.js +385 -135
- package/lib/constants/abis/stable_calc.json +151 -0
- package/lib/constants/abis/wbeth/swap.json +1086 -0
- package/lib/constants/aliases.js +33 -11
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +10 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +26 -1
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/utils.d.ts +1 -1
- package/lib/constants/utils.js +19 -18
- package/lib/curve.js +507 -281
- package/lib/external-api.js +132 -45
- package/lib/factory/common.js +3 -3
- package/lib/factory/constants-crypto.js +21 -21
- package/lib/factory/constants.js +32 -31
- package/lib/factory/deploy.js +336 -176
- package/lib/factory/factory-api.js +256 -180
- package/lib/factory/factory-crypto.js +309 -163
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +336 -186
- package/lib/index.js +98 -44
- package/lib/interfaces.d.ts +1 -1
- package/lib/pools/PoolTemplate.js +2882 -1511
- package/lib/pools/mixins/common.js +106 -22
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
- package/lib/pools/mixins/depositMixins.js +413 -144
- package/lib/pools/mixins/depositWrappedMixins.js +223 -72
- package/lib/pools/mixins/poolBalancesMixin.js +98 -22
- package/lib/pools/mixins/swapMixins.js +347 -125
- package/lib/pools/mixins/swapWrappedMixins.js +270 -88
- package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
- package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
- package/lib/pools/mixins/withdrawMixins.js +385 -122
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
- package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
- package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
- package/lib/pools/poolConstructor.js +25 -5
- package/lib/pools/utils.js +488 -298
- package/lib/router.js +636 -378
- package/lib/utils.js +675 -354
- package/package.json +1 -1
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
1
57
|
import { curve } from "../curve.js";
|
|
2
58
|
import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
3
59
|
import cryptoFactorySwapABI from "../constants/abis/factory-crypto/factory-crypto-pool-2.json" assert { type: 'json' };
|
|
@@ -5,204 +61,294 @@ import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type
|
|
|
5
61
|
import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
|
|
6
62
|
import { setFactoryZapContracts } from "./common.js";
|
|
7
63
|
import { CRYPTO_FACTORY_CONSTANTS } from "./constants-crypto.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
64
|
+
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
65
|
+
function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var factoryContract, poolCount, _a, _b, _c, i, address;
|
|
68
|
+
return __generator(this, function (_e) {
|
|
69
|
+
switch (_e.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
72
|
+
_a = Number;
|
|
73
|
+
_c = (_b = curve).formatUnits;
|
|
74
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
75
|
+
case 1:
|
|
76
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
77
|
+
i = 1;
|
|
78
|
+
_e.label = 2;
|
|
79
|
+
case 2:
|
|
80
|
+
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
81
|
+
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
82
|
+
case 3:
|
|
83
|
+
address = _e.sent();
|
|
84
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
85
|
+
return [2 /*return*/, "factory-crypto-".concat(poolCount - i)];
|
|
86
|
+
_e.label = 4;
|
|
87
|
+
case 4:
|
|
88
|
+
i++;
|
|
89
|
+
return [3 /*break*/, 2];
|
|
90
|
+
case 5: throw Error("Unknown pool");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
18
94
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
95
|
+
function getCryptoFactoryIdsAndSwapAddresses(fromIdx) {
|
|
96
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
|
|
99
|
+
return __generator(this, function (_e) {
|
|
100
|
+
switch (_e.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
103
|
+
factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
|
|
104
|
+
_a = Number;
|
|
105
|
+
_c = (_b = curve).formatUnits;
|
|
106
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
107
|
+
case 1:
|
|
108
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
109
|
+
calls = [];
|
|
110
|
+
for (i = fromIdx; i < poolCount; i++) {
|
|
111
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
112
|
+
}
|
|
113
|
+
if (calls.length === 0)
|
|
114
|
+
return [2 /*return*/, [[], []]];
|
|
115
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
116
|
+
case 2:
|
|
117
|
+
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-crypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
|
|
118
|
+
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
119
|
+
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
|
|
120
|
+
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
33
124
|
}
|
|
34
125
|
function _handleCoinAddresses(coinAddresses) {
|
|
35
|
-
|
|
126
|
+
var _this = this;
|
|
127
|
+
return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
|
|
36
128
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
129
|
+
function getPoolsData(factorySwapAddresses) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, res, tokenAddresses, gaugeAddresses, coinAddresses;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
|
|
136
|
+
calls = [];
|
|
137
|
+
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
138
|
+
addr = factorySwapAddresses_1[_i];
|
|
139
|
+
calls.push(factoryMulticallContract.get_token(addr));
|
|
140
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
141
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
142
|
+
}
|
|
143
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
144
|
+
case 1:
|
|
145
|
+
res = _a.sent();
|
|
146
|
+
tokenAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
147
|
+
gaugeAddresses = res.filter(function (a, i) { return i % 3 == 1; }).map(function (a) { return a.toLowerCase(); });
|
|
148
|
+
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 2; }));
|
|
149
|
+
return [2 /*return*/, [tokenAddresses, gaugeAddresses, coinAddresses]];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
50
153
|
}
|
|
51
154
|
function setCryptoFactorySwapContracts(factorySwapAddresses) {
|
|
52
|
-
|
|
53
|
-
|
|
155
|
+
var _this = this;
|
|
156
|
+
factorySwapAddresses.forEach(function (addr) {
|
|
157
|
+
_this.setContract(addr, cryptoFactorySwapABI);
|
|
54
158
|
});
|
|
55
159
|
}
|
|
56
160
|
function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
57
|
-
|
|
58
|
-
|
|
161
|
+
var _this = this;
|
|
162
|
+
factoryTokenAddresses.forEach(function (addr) {
|
|
163
|
+
_this.setContract(addr, ERC20ABI);
|
|
59
164
|
});
|
|
60
165
|
}
|
|
61
166
|
function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
62
|
-
|
|
63
|
-
|
|
167
|
+
var _this = this;
|
|
168
|
+
factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
|
|
169
|
+
_this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
64
170
|
});
|
|
65
171
|
}
|
|
66
172
|
function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
67
|
-
|
|
68
|
-
for (
|
|
173
|
+
var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
174
|
+
for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
|
|
175
|
+
var addr = flattenedCoinAddresses_1[_i];
|
|
69
176
|
if (addr in this.contracts)
|
|
70
177
|
continue;
|
|
71
178
|
this.setContract(addr, ERC20ABI);
|
|
72
179
|
}
|
|
73
180
|
}
|
|
74
181
|
function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
75
|
-
|
|
182
|
+
var _this = this;
|
|
183
|
+
return coinAddresses.map(function (coins) { return coins.map(function (c) { return c === _this.constants.NATIVE_TOKEN.wrappedAddress ? _this.constants.NATIVE_TOKEN.address : c; }); });
|
|
76
184
|
}
|
|
77
185
|
function getExistingCoinAddressNameDict() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
poolData.wrapped_coin_addresses.forEach((addr, i)
|
|
186
|
+
var dict = {};
|
|
187
|
+
var _loop_1 = function (poolData) {
|
|
188
|
+
poolData.wrapped_coin_addresses.forEach(function (addr, i) {
|
|
81
189
|
if (!(addr.toLowerCase() in dict)) {
|
|
82
190
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
83
191
|
}
|
|
84
192
|
});
|
|
85
|
-
poolData.underlying_coin_addresses.forEach((addr, i)
|
|
193
|
+
poolData.underlying_coin_addresses.forEach(function (addr, i) {
|
|
86
194
|
if (!(addr.toLowerCase() in dict)) {
|
|
87
195
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
88
196
|
}
|
|
89
197
|
});
|
|
198
|
+
};
|
|
199
|
+
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
200
|
+
var poolData = _a[_i];
|
|
201
|
+
_loop_1(poolData);
|
|
90
202
|
}
|
|
91
203
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
92
204
|
return dict;
|
|
93
205
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
206
|
+
function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, coinAddrDecimalsDict, _i, flattenedCoinAddresses_2, addr, calls, _a, tokenAddresses_1, addr, _b, newCoinAddresses_1, addr, res, res1, tokenSymbols, tokenNames, res2, symbols, decimals;
|
|
209
|
+
return __generator(this, function (_c) {
|
|
210
|
+
switch (_c.label) {
|
|
211
|
+
case 0:
|
|
212
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
213
|
+
newCoinAddresses = [];
|
|
214
|
+
coinAddrNamesDict = {};
|
|
215
|
+
coinAddrDecimalsDict = {};
|
|
216
|
+
for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
|
|
217
|
+
addr = flattenedCoinAddresses_2[_i];
|
|
218
|
+
if (addr in existingCoinAddrNameDict) {
|
|
219
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
220
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
221
|
+
}
|
|
222
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
223
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
newCoinAddresses.push(addr);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
calls = [];
|
|
230
|
+
for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
|
|
231
|
+
addr = tokenAddresses_1[_a];
|
|
232
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
233
|
+
calls.push(this.contracts[addr].multicallContract.name());
|
|
234
|
+
}
|
|
235
|
+
for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
|
|
236
|
+
addr = newCoinAddresses_1[_b];
|
|
237
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
238
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
239
|
+
}
|
|
240
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
241
|
+
case 1:
|
|
242
|
+
res = _c.sent();
|
|
243
|
+
res1 = res.slice(0, tokenAddresses.length * 2);
|
|
244
|
+
tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
|
|
245
|
+
tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
|
|
246
|
+
res2 = res.slice(tokenAddresses.length * 2);
|
|
247
|
+
symbols = res2.filter(function (a, i) { return i % 2 == 0; });
|
|
248
|
+
decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
|
|
249
|
+
newCoinAddresses.forEach(function (addr, i) {
|
|
250
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
251
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
252
|
+
});
|
|
253
|
+
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
254
|
+
return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
130
257
|
});
|
|
131
|
-
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
132
|
-
return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
|
|
133
258
|
}
|
|
134
|
-
export
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
259
|
+
export function getCryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
260
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var _a, poolIds, swapAddresses, _b, _c, tokenAddresses, gaugeAddresses, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, _e, poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i, lpTokenBasePoolIdDict, basePoolIdZapDict, basePoolId, allPoolsData, basePoolCoinNames, basePoolCoinAddresses, basePoolDecimals, basePoolZap;
|
|
263
|
+
return __generator(this, function (_f) {
|
|
264
|
+
switch (_f.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
if (!swapAddress) return [3 /*break*/, 2];
|
|
267
|
+
return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
|
|
268
|
+
case 1:
|
|
269
|
+
_b = [[_f.sent()], [swapAddress.toLowerCase()]];
|
|
270
|
+
return [3 /*break*/, 4];
|
|
271
|
+
case 2: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx)];
|
|
272
|
+
case 3:
|
|
273
|
+
_b = _f.sent();
|
|
274
|
+
_f.label = 4;
|
|
275
|
+
case 4:
|
|
276
|
+
_a = _b, poolIds = _a[0], swapAddresses = _a[1];
|
|
277
|
+
if (poolIds.length === 0)
|
|
278
|
+
return [2 /*return*/, {}];
|
|
279
|
+
return [4 /*yield*/, getPoolsData.call(this, swapAddresses)];
|
|
280
|
+
case 5:
|
|
281
|
+
_c = _f.sent(), tokenAddresses = _c[0], gaugeAddresses = _c[1], coinAddresses = _c[2];
|
|
282
|
+
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
283
|
+
setCryptoFactoryTokenContracts.call(this, tokenAddresses);
|
|
284
|
+
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
285
|
+
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
286
|
+
setFactoryZapContracts.call(this, true);
|
|
287
|
+
underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
|
|
288
|
+
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
289
|
+
return [4 /*yield*/, getCoinsData.call(this, tokenAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS)];
|
|
290
|
+
case 6:
|
|
291
|
+
_e = _f.sent(), poolSymbols = _e[0], poolNames = _e[1], coinAddressNameDict = _e[2], coinAddressDecimalsDict = _e[3];
|
|
292
|
+
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
293
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
294
|
+
lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
|
|
295
|
+
basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
|
|
296
|
+
basePoolId = lpTokenBasePoolIdDict[coinAddresses[i][1].toLowerCase()];
|
|
297
|
+
if (basePoolId) { // isMeta
|
|
298
|
+
allPoolsData = __assign(__assign({}, this.constants.POOLS_DATA), CRYPTO_FACTORY_POOLS_DATA);
|
|
299
|
+
basePoolCoinNames = __spreadArray([], allPoolsData[basePoolId].underlying_coins, true);
|
|
300
|
+
basePoolCoinAddresses = __spreadArray([], allPoolsData[basePoolId].underlying_coin_addresses, true);
|
|
301
|
+
basePoolDecimals = __spreadArray([], allPoolsData[basePoolId].underlying_decimals, true);
|
|
302
|
+
basePoolZap = basePoolIdZapDict[basePoolId];
|
|
303
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
304
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
305
|
+
full_name: poolNames[i],
|
|
306
|
+
symbol: poolSymbols[i],
|
|
307
|
+
reference_asset: "CRYPTO",
|
|
308
|
+
swap_address: swapAddresses[i],
|
|
309
|
+
token_address: tokenAddresses[i],
|
|
310
|
+
gauge_address: gaugeAddresses[i],
|
|
311
|
+
deposit_address: basePoolZap.address,
|
|
312
|
+
is_meta: true,
|
|
313
|
+
is_crypto: true,
|
|
314
|
+
is_factory: true,
|
|
315
|
+
base_pool: basePoolId,
|
|
316
|
+
underlying_coins: __spreadArray([coinAddressNameDict[underlyingCoinAddresses[i][0]]], basePoolCoinNames, true),
|
|
317
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
318
|
+
underlying_coin_addresses: __spreadArray([underlyingCoinAddresses[i][0]], basePoolCoinAddresses, true),
|
|
319
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
320
|
+
underlying_decimals: __spreadArray([coinAddressDecimalsDict[underlyingCoinAddresses[i][0]]], basePoolDecimals, true),
|
|
321
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
322
|
+
swap_abi: cryptoFactorySwapABI,
|
|
323
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
324
|
+
deposit_abi: basePoolZap.ABI,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
329
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
330
|
+
full_name: poolNames[i],
|
|
331
|
+
symbol: poolSymbols[i],
|
|
332
|
+
reference_asset: "CRYPTO",
|
|
333
|
+
swap_address: swapAddresses[i],
|
|
334
|
+
token_address: tokenAddresses[i],
|
|
335
|
+
gauge_address: gaugeAddresses[i],
|
|
336
|
+
is_crypto: true,
|
|
337
|
+
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
338
|
+
is_factory: true,
|
|
339
|
+
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
340
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
341
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
342
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
343
|
+
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
344
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
345
|
+
swap_abi: cryptoFactorySwapABI,
|
|
346
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
});
|
|
208
354
|
}
|
package/lib/factory/factory.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IDict, IPoolData, ICurve } from "../interfaces";
|
|
2
|
-
export declare function getFactoryPoolData(this: ICurve, fromIdx?: number, swapAddress?: string): Promise<IDict<IPoolData>>;
|
|
2
|
+
export declare function getFactoryPoolData(this: ICurve, fromIdx?: number, swapAddress?: string, factoryAddress?: string): Promise<IDict<IPoolData>>;
|