@curvefi/api 2.32.0 → 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/aliases.js +22 -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 +1 -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.js +19 -18
- package/lib/curve.js +506 -282
- 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 +5 -0
- package/lib/pools/PoolTemplate.js +2879 -1468
- 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 -299
- package/lib/router.js +675 -212
- package/lib/utils.js +675 -354
- package/package.json +1 -2
package/lib/factory/factory.js
CHANGED
|
@@ -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 { Contract as MulticallContract } from "ethcall";
|
|
2
58
|
import { curve } from "../curve.js";
|
|
3
59
|
import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
@@ -5,7 +61,7 @@ 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 { FACTORY_CONSTANTS } from "./constants.js";
|
|
8
|
-
|
|
64
|
+
var BLACK_LIST = {
|
|
9
65
|
1: [
|
|
10
66
|
"0x066b6e1e93fa7dcd3f0eb7f8bac7d5a747ce0bf9",
|
|
11
67
|
],
|
|
@@ -15,35 +71,72 @@ const BLACK_LIST = {
|
|
|
15
71
|
"0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
|
|
16
72
|
],
|
|
17
73
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
74
|
+
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
75
|
+
function getRecentlyCreatedPoolId(swapAddress) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var factoryContract, poolCount, _a, _b, _c, i, address;
|
|
78
|
+
return __generator(this, function (_e) {
|
|
79
|
+
switch (_e.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
|
|
82
|
+
_a = Number;
|
|
83
|
+
_c = (_b = curve).formatUnits;
|
|
84
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
85
|
+
case 1:
|
|
86
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
87
|
+
i = 1;
|
|
88
|
+
_e.label = 2;
|
|
89
|
+
case 2:
|
|
90
|
+
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
91
|
+
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
92
|
+
case 3:
|
|
93
|
+
address = _e.sent();
|
|
94
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
95
|
+
return [2 /*return*/, "factory-v2-".concat(poolCount - i)];
|
|
96
|
+
_e.label = 4;
|
|
97
|
+
case 4:
|
|
98
|
+
i++;
|
|
99
|
+
return [3 /*break*/, 2];
|
|
100
|
+
case 5: throw Error("Unknown pool");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
28
104
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
105
|
+
function getFactoryIdsAndSwapAddresses(fromIdx, factoryAddress) {
|
|
106
|
+
var _a;
|
|
107
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var factoryContract, factoryMulticallContract, poolCount, _b, _c, _e, calls, i, prefix, factories, swapAddresses, blacklist;
|
|
110
|
+
return __generator(this, function (_f) {
|
|
111
|
+
switch (_f.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
factoryContract = this.contracts[factoryAddress].contract;
|
|
114
|
+
factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
|
|
115
|
+
_b = Number;
|
|
116
|
+
_e = (_c = curve).formatUnits;
|
|
117
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
118
|
+
case 1:
|
|
119
|
+
poolCount = _b.apply(void 0, [_e.apply(_c, [_f.sent(), 0])]);
|
|
120
|
+
calls = [];
|
|
121
|
+
for (i = fromIdx; i < poolCount; i++) {
|
|
122
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
123
|
+
}
|
|
124
|
+
if (calls.length === 0)
|
|
125
|
+
return [2 /*return*/, [[], []]];
|
|
126
|
+
prefix = factoryAddress === this.constants.ALIASES.factory ? "factory-v2-" : "factory-crvusd-";
|
|
127
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
128
|
+
case 2:
|
|
129
|
+
factories = (_f.sent()).map(function (addr, i) { return ({ id: prefix + (fromIdx + i), address: addr.toLowerCase() }); });
|
|
130
|
+
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
131
|
+
blacklist = (_a = BLACK_LIST[this.chainId]) !== null && _a !== void 0 ? _a : [];
|
|
132
|
+
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address) && !blacklist.includes(f.address); });
|
|
133
|
+
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
44
137
|
}
|
|
45
138
|
function _handleReferenceAssets(referenceAssets) {
|
|
46
|
-
return referenceAssets.map((t)
|
|
139
|
+
return referenceAssets.map(function (t) {
|
|
47
140
|
return {
|
|
48
141
|
0: "USD",
|
|
49
142
|
1: "ETH",
|
|
@@ -52,192 +145,249 @@ function _handleReferenceAssets(referenceAssets) {
|
|
|
52
145
|
});
|
|
53
146
|
}
|
|
54
147
|
function _handleCoinAddresses(coinAddresses) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
.
|
|
148
|
+
var _this = this;
|
|
149
|
+
return coinAddresses.map(function (addresses) { return addresses
|
|
150
|
+
.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; })
|
|
151
|
+
.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.address : addr.toLowerCase(); }); });
|
|
58
152
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
153
|
+
function getPoolsData(factorySwapAddresses, factoryAddress) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, tempSwapContract, res, implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
|
|
160
|
+
calls = [];
|
|
161
|
+
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
162
|
+
addr = factorySwapAddresses_1[_i];
|
|
163
|
+
tempSwapContract = new MulticallContract(addr, ERC20ABI);
|
|
164
|
+
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
165
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
166
|
+
calls.push(factoryMulticallContract.get_pool_asset_type(addr));
|
|
167
|
+
calls.push(tempSwapContract.symbol());
|
|
168
|
+
calls.push(tempSwapContract.name());
|
|
169
|
+
calls.push(factoryMulticallContract.is_meta(addr));
|
|
170
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
171
|
+
}
|
|
172
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
173
|
+
case 1:
|
|
174
|
+
res = _a.sent();
|
|
175
|
+
implememntationAddresses = res.filter(function (a, i) { return i % 7 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
176
|
+
gaugeAddresses = res.filter(function (a, i) { return i % 7 == 1; }).map(function (a) { return a.toLowerCase(); });
|
|
177
|
+
referenceAssets = _handleReferenceAssets(res.filter(function (a, i) { return i % 7 == 2; }));
|
|
178
|
+
symbols = res.filter(function (a, i) { return i % 7 == 3; });
|
|
179
|
+
names = res.filter(function (a, i) { return i % 7 == 4; });
|
|
180
|
+
isMeta = res.filter(function (a, i) { return i % 7 == 5; });
|
|
181
|
+
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 7 == 6; }));
|
|
182
|
+
return [2 /*return*/, [implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses]];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
81
186
|
}
|
|
82
187
|
function setFactorySwapContracts(factorySwapAddresses, factorySwapABIs) {
|
|
83
|
-
|
|
84
|
-
|
|
188
|
+
var _this = this;
|
|
189
|
+
factorySwapAddresses.forEach(function (addr, i) {
|
|
190
|
+
_this.setContract(addr, factorySwapABIs[i]);
|
|
85
191
|
});
|
|
86
192
|
}
|
|
87
193
|
function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
88
|
-
|
|
89
|
-
|
|
194
|
+
var _this = this;
|
|
195
|
+
factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
|
|
196
|
+
_this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
90
197
|
});
|
|
91
198
|
}
|
|
92
199
|
function setFactoryCoinsContracts(coinAddresses) {
|
|
93
|
-
|
|
94
|
-
for (
|
|
200
|
+
var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
201
|
+
for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
|
|
202
|
+
var addr = flattenedCoinAddresses_1[_i];
|
|
95
203
|
if (addr in this.contracts)
|
|
96
204
|
continue;
|
|
97
205
|
this.setContract(addr, ERC20ABI);
|
|
98
206
|
}
|
|
99
207
|
}
|
|
100
208
|
function getExistingCoinAddressNameDict() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
poolData.wrapped_coin_addresses.forEach((addr, i)
|
|
209
|
+
var dict = {};
|
|
210
|
+
var _loop_1 = function (poolData) {
|
|
211
|
+
poolData.wrapped_coin_addresses.forEach(function (addr, i) {
|
|
104
212
|
if (!(addr.toLowerCase() in dict)) {
|
|
105
213
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
106
214
|
}
|
|
107
215
|
});
|
|
108
|
-
poolData.underlying_coin_addresses.forEach((addr, i)
|
|
216
|
+
poolData.underlying_coin_addresses.forEach(function (addr, i) {
|
|
109
217
|
if (!(addr.toLowerCase() in dict)) {
|
|
110
218
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
111
219
|
}
|
|
112
220
|
});
|
|
221
|
+
};
|
|
222
|
+
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
223
|
+
var poolData = _a[_i];
|
|
224
|
+
_loop_1(poolData);
|
|
113
225
|
}
|
|
114
226
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
115
227
|
return dict;
|
|
116
228
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
229
|
+
function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, coinAddrDecimalsDict, _i, flattenedCoinAddresses_2, addr, calls, _a, newCoinAddresses_1, addr, res, symbols, decimals;
|
|
232
|
+
return __generator(this, function (_b) {
|
|
233
|
+
switch (_b.label) {
|
|
234
|
+
case 0:
|
|
235
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
236
|
+
newCoinAddresses = [];
|
|
237
|
+
coinAddrNamesDict = {};
|
|
238
|
+
coinAddrDecimalsDict = {};
|
|
239
|
+
for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
|
|
240
|
+
addr = flattenedCoinAddresses_2[_i];
|
|
241
|
+
if (addr in existingCoinAddrNameDict) {
|
|
242
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
243
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
newCoinAddresses.push(addr);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
calls = [];
|
|
250
|
+
for (_a = 0, newCoinAddresses_1 = newCoinAddresses; _a < newCoinAddresses_1.length; _a++) {
|
|
251
|
+
addr = newCoinAddresses_1[_a];
|
|
252
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
253
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
254
|
+
}
|
|
255
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
256
|
+
case 1:
|
|
257
|
+
res = _b.sent();
|
|
258
|
+
symbols = res.filter(function (a, i) { return i % 2 == 0; });
|
|
259
|
+
decimals = res.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
|
|
260
|
+
newCoinAddresses.forEach(function (addr, i) {
|
|
261
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
262
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
263
|
+
});
|
|
264
|
+
return [2 /*return*/, [coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
142
267
|
});
|
|
143
|
-
return [coinAddrNamesDict, coinAddrDecimalsDict];
|
|
144
268
|
}
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return {
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
269
|
+
export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
|
|
270
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
271
|
+
if (factoryAddress === void 0) { factoryAddress = curve.constants.ALIASES.factory; }
|
|
272
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
273
|
+
var _a, rawPoolIds, rawSwapAddresses, _b, _c, rawImplementations, rawGauges, rawReferenceAssets, rawPoolSymbols, rawPoolNames, rawIsMeta, rawCoinAddresses, poolIds, swapAddresses, implementations, gaugeAddresses, referenceAssets, poolSymbols, poolNames, isMeta, coinAddresses, implementationABIDict, i, swapABIs, _e, coinAddressNameDict, coinAddressDecimalsDict, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
|
|
274
|
+
return __generator(this, function (_f) {
|
|
275
|
+
switch (_f.label) {
|
|
276
|
+
case 0:
|
|
277
|
+
if (!swapAddress) return [3 /*break*/, 2];
|
|
278
|
+
return [4 /*yield*/, getRecentlyCreatedPoolId.call(this, swapAddress)];
|
|
279
|
+
case 1:
|
|
280
|
+
_b = [[_f.sent()], [swapAddress.toLowerCase()]];
|
|
281
|
+
return [3 /*break*/, 4];
|
|
282
|
+
case 2: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this, fromIdx, factoryAddress)];
|
|
283
|
+
case 3:
|
|
284
|
+
_b = _f.sent();
|
|
285
|
+
_f.label = 4;
|
|
286
|
+
case 4:
|
|
287
|
+
_a = _b, rawPoolIds = _a[0], rawSwapAddresses = _a[1];
|
|
288
|
+
if (rawPoolIds.length === 0)
|
|
289
|
+
return [2 /*return*/, {}];
|
|
290
|
+
return [4 /*yield*/, getPoolsData.call(this, rawSwapAddresses, factoryAddress)];
|
|
291
|
+
case 5:
|
|
292
|
+
_c = _f.sent(), rawImplementations = _c[0], rawGauges = _c[1], rawReferenceAssets = _c[2], rawPoolSymbols = _c[3], rawPoolNames = _c[4], rawIsMeta = _c[5], rawCoinAddresses = _c[6];
|
|
293
|
+
poolIds = [];
|
|
294
|
+
swapAddresses = [];
|
|
295
|
+
implementations = [];
|
|
296
|
+
gaugeAddresses = [];
|
|
297
|
+
referenceAssets = [];
|
|
298
|
+
poolSymbols = [];
|
|
299
|
+
poolNames = [];
|
|
300
|
+
isMeta = [];
|
|
301
|
+
coinAddresses = [];
|
|
302
|
+
implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
|
|
303
|
+
for (i = 0; i < rawPoolIds.length; i++) {
|
|
304
|
+
if (rawImplementations[i] in implementationABIDict) {
|
|
305
|
+
poolIds.push(rawPoolIds[i]);
|
|
306
|
+
swapAddresses.push(rawSwapAddresses[i]);
|
|
307
|
+
implementations.push(rawImplementations[i]);
|
|
308
|
+
gaugeAddresses.push(rawGauges[i]);
|
|
309
|
+
referenceAssets.push(rawReferenceAssets[i]);
|
|
310
|
+
poolSymbols.push(rawPoolSymbols[i]);
|
|
311
|
+
poolNames.push(rawPoolNames[i]);
|
|
312
|
+
isMeta.push(rawIsMeta[i]);
|
|
313
|
+
coinAddresses.push(rawCoinAddresses[i]);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
swapABIs = implementations.map(function (addr) { return implementationABIDict[addr]; });
|
|
317
|
+
setFactorySwapContracts.call(this, swapAddresses, swapABIs);
|
|
318
|
+
setFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
319
|
+
setFactoryCoinsContracts.call(this, coinAddresses);
|
|
320
|
+
setFactoryZapContracts.call(this, false);
|
|
321
|
+
return [4 /*yield*/, getCoinsData.call(this, coinAddresses, getExistingCoinAddressNameDict.call(this), this.constants.DECIMALS)];
|
|
322
|
+
case 6:
|
|
323
|
+
_e = _f.sent(), coinAddressNameDict = _e[0], coinAddressDecimalsDict = _e[1];
|
|
324
|
+
implementationBasePoolIdDict = FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
|
|
325
|
+
basePoolIds = implementations.map(function (addr) { return implementationBasePoolIdDict[addr]; });
|
|
326
|
+
FACTORY_POOLS_DATA = {};
|
|
327
|
+
_loop_2 = function (i) {
|
|
328
|
+
if (!isMeta[i]) {
|
|
329
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
330
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
331
|
+
full_name: poolNames[i],
|
|
332
|
+
symbol: poolSymbols[i],
|
|
333
|
+
reference_asset: referenceAssets[i],
|
|
334
|
+
swap_address: swapAddresses[i],
|
|
335
|
+
token_address: swapAddresses[i],
|
|
336
|
+
gauge_address: gaugeAddresses[i],
|
|
337
|
+
implementation_address: implementations[i],
|
|
338
|
+
is_plain: true,
|
|
339
|
+
is_factory: true,
|
|
340
|
+
underlying_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
341
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
342
|
+
underlying_coin_addresses: coinAddresses[i],
|
|
343
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
344
|
+
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
345
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
346
|
+
swap_abi: swapABIs[i],
|
|
347
|
+
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
var allPoolsData_1 = __assign(__assign({}, this_1.constants.POOLS_DATA), FACTORY_POOLS_DATA);
|
|
352
|
+
// @ts-ignore
|
|
353
|
+
var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coins]; }));
|
|
354
|
+
// @ts-ignore
|
|
355
|
+
var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coin_addresses]; }));
|
|
356
|
+
// @ts-ignore
|
|
357
|
+
var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_decimals]; }));
|
|
358
|
+
var basePoolIdZapDict = FACTORY_CONSTANTS[this_1.chainId].basePoolIdZapDict;
|
|
359
|
+
var basePoolZap = basePoolIdZapDict[basePoolIds[i]];
|
|
360
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
361
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
362
|
+
full_name: poolNames[i],
|
|
363
|
+
symbol: poolSymbols[i],
|
|
364
|
+
reference_asset: referenceAssets[i],
|
|
365
|
+
swap_address: swapAddresses[i],
|
|
366
|
+
token_address: swapAddresses[i],
|
|
367
|
+
gauge_address: gaugeAddresses[i],
|
|
368
|
+
deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
|
|
369
|
+
implementation_address: implementations[i],
|
|
370
|
+
is_meta: true,
|
|
371
|
+
is_factory: true,
|
|
372
|
+
base_pool: basePoolIds[i],
|
|
373
|
+
underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolIdCoinsDict[basePoolIds[i]], true),
|
|
374
|
+
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
375
|
+
underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolIdCoinAddressesDict[basePoolIds[i]], true),
|
|
376
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
377
|
+
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
|
|
378
|
+
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
379
|
+
swap_abi: swapABIs[i],
|
|
380
|
+
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
381
|
+
deposit_abi: basePoolZap.ABI,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
this_1 = this;
|
|
386
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
387
|
+
_loop_2(i);
|
|
388
|
+
}
|
|
389
|
+
return [2 /*return*/, FACTORY_POOLS_DATA];
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
});
|
|
243
393
|
}
|