@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.
Files changed (62) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/abis/stable_calc.json +151 -0
  3. package/lib/constants/abis/wbeth/swap.json +1086 -0
  4. package/lib/constants/aliases.js +33 -11
  5. package/lib/constants/coins/arbitrum.js +5 -5
  6. package/lib/constants/coins/aurora.js +5 -5
  7. package/lib/constants/coins/avalanche.js +6 -6
  8. package/lib/constants/coins/celo.js +5 -5
  9. package/lib/constants/coins/ethereum.js +10 -9
  10. package/lib/constants/coins/fantom.js +7 -7
  11. package/lib/constants/coins/kava.js +5 -5
  12. package/lib/constants/coins/moonbeam.js +5 -5
  13. package/lib/constants/coins/optimism.js +5 -5
  14. package/lib/constants/coins/polygon.js +6 -6
  15. package/lib/constants/coins/xdai.js +5 -5
  16. package/lib/constants/pools/arbitrum.js +1 -1
  17. package/lib/constants/pools/aurora.js +1 -1
  18. package/lib/constants/pools/avalanche.js +1 -1
  19. package/lib/constants/pools/celo.js +1 -1
  20. package/lib/constants/pools/ethereum.js +26 -1
  21. package/lib/constants/pools/fantom.js +1 -1
  22. package/lib/constants/pools/kava.js +1 -1
  23. package/lib/constants/pools/moonbeam.js +1 -1
  24. package/lib/constants/pools/optimism.js +1 -1
  25. package/lib/constants/pools/polygon.js +1 -1
  26. package/lib/constants/pools/xdai.js +1 -1
  27. package/lib/constants/utils.d.ts +1 -1
  28. package/lib/constants/utils.js +19 -18
  29. package/lib/curve.js +507 -281
  30. package/lib/external-api.js +132 -45
  31. package/lib/factory/common.js +3 -3
  32. package/lib/factory/constants-crypto.js +21 -21
  33. package/lib/factory/constants.js +32 -31
  34. package/lib/factory/deploy.js +336 -176
  35. package/lib/factory/factory-api.js +256 -180
  36. package/lib/factory/factory-crypto.js +309 -163
  37. package/lib/factory/factory.d.ts +1 -1
  38. package/lib/factory/factory.js +336 -186
  39. package/lib/index.js +98 -44
  40. package/lib/interfaces.d.ts +1 -1
  41. package/lib/pools/PoolTemplate.js +2882 -1511
  42. package/lib/pools/mixins/common.js +106 -22
  43. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  44. package/lib/pools/mixins/depositMixins.js +413 -144
  45. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  46. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  47. package/lib/pools/mixins/swapMixins.js +347 -125
  48. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  49. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  50. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  51. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  52. package/lib/pools/mixins/withdrawMixins.js +385 -122
  53. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  54. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  55. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  56. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  57. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  58. package/lib/pools/poolConstructor.js +25 -5
  59. package/lib/pools/utils.js +488 -298
  60. package/lib/router.js +636 -378
  61. package/lib/utils.js +675 -354
  62. 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
- const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
9
- async function getRecentlyCreatedCryptoPoolId(swapAddress) {
10
- const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
11
- const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
12
- for (let i = 1; i <= poolCount; i++) {
13
- const address = await factoryContract.pool_list(poolCount - i);
14
- if (address.toLowerCase() === swapAddress.toLowerCase())
15
- return `factory-crypto-${poolCount - i}`;
16
- }
17
- throw Error("Unknown pool");
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
- async function getCryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
20
- const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
21
- const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
22
- const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
23
- const calls = [];
24
- for (let i = fromIdx; i < poolCount; i++) {
25
- calls.push(factoryMulticallContract.pool_list(i));
26
- }
27
- if (calls.length === 0)
28
- return [[], []];
29
- let factories = (await this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-crypto-${fromIdx + i}`, address: addr.toLowerCase() }));
30
- const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
31
- factories = factories.filter((f) => !swapAddresses.includes(f.address));
32
- return [factories.map((f) => f.id), factories.map((f) => f.address)];
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
- return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
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
- async function getPoolsData(factorySwapAddresses) {
38
- const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
39
- const calls = [];
40
- for (const addr of factorySwapAddresses) {
41
- calls.push(factoryMulticallContract.get_token(addr));
42
- calls.push(factoryMulticallContract.get_gauge(addr));
43
- calls.push(factoryMulticallContract.get_coins(addr));
44
- }
45
- const res = await this.multicallProvider.all(calls);
46
- const tokenAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
47
- const gaugeAddresses = res.filter((a, i) => i % 3 == 1).map((a) => a.toLowerCase());
48
- const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 2));
49
- return [tokenAddresses, gaugeAddresses, coinAddresses];
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
- factorySwapAddresses.forEach((addr) => {
53
- this.setContract(addr, cryptoFactorySwapABI);
155
+ var _this = this;
156
+ factorySwapAddresses.forEach(function (addr) {
157
+ _this.setContract(addr, cryptoFactorySwapABI);
54
158
  });
55
159
  }
56
160
  function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
57
- factoryTokenAddresses.forEach((addr) => {
58
- this.setContract(addr, ERC20ABI);
161
+ var _this = this;
162
+ factoryTokenAddresses.forEach(function (addr) {
163
+ _this.setContract(addr, ERC20ABI);
59
164
  });
60
165
  }
61
166
  function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
62
- factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
63
- this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
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
- const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
68
- for (const addr of flattenedCoinAddresses) {
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
- return coinAddresses.map((coins) => coins.map((c) => c === this.constants.NATIVE_TOKEN.wrappedAddress ? this.constants.NATIVE_TOKEN.address : c));
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
- const dict = {};
79
- for (const poolData of Object.values(this.constants.POOLS_DATA)) {
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
- async function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
95
- const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
96
- const newCoinAddresses = [];
97
- const coinAddrNamesDict = {};
98
- const coinAddrDecimalsDict = {};
99
- for (const addr of flattenedCoinAddresses) {
100
- if (addr in existingCoinAddrNameDict) {
101
- coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
102
- coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
103
- }
104
- else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
105
- coinAddrNamesDict[addr] = "MKR";
106
- }
107
- else {
108
- newCoinAddresses.push(addr);
109
- }
110
- }
111
- const calls = [];
112
- for (const addr of tokenAddresses) {
113
- calls.push(this.contracts[addr].multicallContract.symbol());
114
- calls.push(this.contracts[addr].multicallContract.name());
115
- }
116
- for (const addr of newCoinAddresses) {
117
- calls.push(this.contracts[addr].multicallContract.symbol());
118
- calls.push(this.contracts[addr].multicallContract.decimals());
119
- }
120
- const res = await this.multicallProvider.all(calls);
121
- const res1 = res.slice(0, tokenAddresses.length * 2);
122
- const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
123
- const tokenNames = res1.filter((a, i) => i % 2 == 1);
124
- const res2 = res.slice(tokenAddresses.length * 2);
125
- const symbols = res2.filter((a, i) => i % 2 == 0);
126
- const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
127
- newCoinAddresses.forEach((addr, i) => {
128
- coinAddrNamesDict[addr] = symbols[i];
129
- coinAddrDecimalsDict[addr] = decimals[i];
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 async function getCryptoFactoryPoolData(fromIdx = 0, swapAddress) {
135
- const [poolIds, swapAddresses] = swapAddress ?
136
- [[await getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
137
- : await getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
138
- if (poolIds.length === 0)
139
- return {};
140
- const [tokenAddresses, gaugeAddresses, coinAddresses] = await getPoolsData.call(this, swapAddresses);
141
- setCryptoFactorySwapContracts.call(this, swapAddresses);
142
- setCryptoFactoryTokenContracts.call(this, tokenAddresses);
143
- setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
144
- setCryptoFactoryCoinsContracts.call(this, coinAddresses);
145
- setFactoryZapContracts.call(this, true);
146
- const underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
147
- const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
148
- const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = await getCoinsData.call(this, tokenAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
149
- const CRYPTO_FACTORY_POOLS_DATA = {};
150
- for (let i = 0; i < poolIds.length; i++) {
151
- const lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
152
- const basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
153
- const basePoolId = lpTokenBasePoolIdDict[coinAddresses[i][1].toLowerCase()];
154
- if (basePoolId) { // isMeta
155
- const allPoolsData = { ...this.constants.POOLS_DATA, ...CRYPTO_FACTORY_POOLS_DATA };
156
- const basePoolCoinNames = [...allPoolsData[basePoolId].underlying_coins];
157
- const basePoolCoinAddresses = [...allPoolsData[basePoolId].underlying_coin_addresses];
158
- const basePoolDecimals = [...allPoolsData[basePoolId].underlying_decimals];
159
- const basePoolZap = basePoolIdZapDict[basePoolId];
160
- CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
161
- name: poolNames[i].split(": ")[1].trim(),
162
- full_name: poolNames[i],
163
- symbol: poolSymbols[i],
164
- reference_asset: "CRYPTO",
165
- swap_address: swapAddresses[i],
166
- token_address: tokenAddresses[i],
167
- gauge_address: gaugeAddresses[i],
168
- deposit_address: basePoolZap.address,
169
- is_meta: true,
170
- is_crypto: true,
171
- is_factory: true,
172
- base_pool: basePoolId,
173
- underlying_coins: [coinAddressNameDict[underlyingCoinAddresses[i][0]], ...basePoolCoinNames],
174
- wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
175
- underlying_coin_addresses: [underlyingCoinAddresses[i][0], ...basePoolCoinAddresses],
176
- wrapped_coin_addresses: coinAddresses[i],
177
- underlying_decimals: [coinAddressDecimalsDict[underlyingCoinAddresses[i][0]], ...basePoolDecimals],
178
- wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
179
- swap_abi: cryptoFactorySwapABI,
180
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
181
- deposit_abi: basePoolZap.ABI,
182
- };
183
- }
184
- else {
185
- CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
186
- name: poolNames[i].split(": ")[1].trim(),
187
- full_name: poolNames[i],
188
- symbol: poolSymbols[i],
189
- reference_asset: "CRYPTO",
190
- swap_address: swapAddresses[i],
191
- token_address: tokenAddresses[i],
192
- gauge_address: gaugeAddresses[i],
193
- is_crypto: true,
194
- is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
195
- is_factory: true,
196
- underlying_coins: underlyingCoinAddresses[i].map((addr) => coinAddressNameDict[addr]),
197
- wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
198
- underlying_coin_addresses: underlyingCoinAddresses[i],
199
- wrapped_coin_addresses: coinAddresses[i],
200
- underlying_decimals: underlyingCoinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
201
- wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
202
- swap_abi: cryptoFactorySwapABI,
203
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
204
- };
205
- }
206
- }
207
- return CRYPTO_FACTORY_POOLS_DATA;
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
  }
@@ -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>>;