@curvefi/api 2.63.0 → 2.63.2

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 (83) hide show
  1. package/lib/boosting.js +247 -645
  2. package/lib/constants/L2Networks.js +1 -1
  3. package/lib/constants/aliases.js +19 -19
  4. package/lib/constants/coins/arbitrum.js +5 -5
  5. package/lib/constants/coins/aurora.js +5 -5
  6. package/lib/constants/coins/avalanche.js +6 -6
  7. package/lib/constants/coins/base.js +5 -5
  8. package/lib/constants/coins/bsc.js +5 -5
  9. package/lib/constants/coins/celo.js +5 -5
  10. package/lib/constants/coins/ethereum.js +9 -9
  11. package/lib/constants/coins/fantom.js +7 -7
  12. package/lib/constants/coins/fraxtal.js +5 -5
  13. package/lib/constants/coins/kava.js +5 -5
  14. package/lib/constants/coins/mantle.js +5 -5
  15. package/lib/constants/coins/moonbeam.js +5 -5
  16. package/lib/constants/coins/optimism.js +5 -5
  17. package/lib/constants/coins/polygon.js +6 -6
  18. package/lib/constants/coins/xdai.js +5 -5
  19. package/lib/constants/coins/xlayer.js +5 -5
  20. package/lib/constants/coins/zksync.js +5 -5
  21. package/lib/constants/pools/arbitrum.js +1 -1
  22. package/lib/constants/pools/aurora.js +1 -1
  23. package/lib/constants/pools/avalanche.js +1 -1
  24. package/lib/constants/pools/base.js +1 -1
  25. package/lib/constants/pools/bsc.js +1 -1
  26. package/lib/constants/pools/celo.js +1 -1
  27. package/lib/constants/pools/ethereum.js +2 -2
  28. package/lib/constants/pools/fantom.js +1 -1
  29. package/lib/constants/pools/fraxtal.js +1 -1
  30. package/lib/constants/pools/kava.js +1 -1
  31. package/lib/constants/pools/mantle.js +1 -1
  32. package/lib/constants/pools/moonbeam.js +1 -1
  33. package/lib/constants/pools/optimism.js +1 -1
  34. package/lib/constants/pools/polygon.js +1 -1
  35. package/lib/constants/pools/xdai.js +1 -1
  36. package/lib/constants/pools/xlayer.js +1 -1
  37. package/lib/constants/pools/zksync.js +1 -1
  38. package/lib/constants/tricryptoDeployImplementations.js +1 -1
  39. package/lib/constants/utils.js +18 -19
  40. package/lib/constants/volumeNetworks.js +1 -1
  41. package/lib/curve.d.ts +10 -6
  42. package/lib/curve.js +534 -909
  43. package/lib/dao.js +351 -705
  44. package/lib/external-api.js +127 -256
  45. package/lib/factory/common.js +4 -4
  46. package/lib/factory/constants-crypto.js +33 -33
  47. package/lib/factory/constants.js +34 -34
  48. package/lib/factory/deploy.js +542 -907
  49. package/lib/factory/factory-api.js +205 -269
  50. package/lib/factory/factory-crypto.js +202 -342
  51. package/lib/factory/factory-tricrypto.js +164 -286
  52. package/lib/factory/factory-twocrypto.js +151 -269
  53. package/lib/factory/factory.js +245 -385
  54. package/lib/index.js +109 -198
  55. package/lib/interfaces.d.ts +46 -6
  56. package/lib/pools/PoolTemplate.js +1774 -3027
  57. package/lib/pools/gaugePool.js +112 -251
  58. package/lib/pools/mixins/common.js +22 -93
  59. package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
  60. package/lib/pools/mixins/depositMixins.js +160 -386
  61. package/lib/pools/mixins/depositWrappedMixins.js +79 -205
  62. package/lib/pools/mixins/poolBalancesMixin.js +24 -87
  63. package/lib/pools/mixins/swapMixins.js +139 -324
  64. package/lib/pools/mixins/swapWrappedMixins.js +111 -265
  65. package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
  66. package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
  67. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
  68. package/lib/pools/mixins/withdrawMixins.js +139 -359
  69. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
  70. package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
  73. package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
  74. package/lib/pools/poolConstructor.js +11 -31
  75. package/lib/pools/utils.js +301 -469
  76. package/lib/route-finder.worker.d.ts +9 -0
  77. package/lib/route-finder.worker.js +112 -0
  78. package/lib/route-graph.worker.d.ts +11 -0
  79. package/lib/route-graph.worker.js +334 -0
  80. package/lib/router.js +323 -912
  81. package/lib/utils.d.ts +8 -7
  82. package/lib/utils.js +540 -927
  83. package/package.json +3 -2
@@ -1,14 +1,3 @@
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
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,42 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
18
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
19
8
  });
20
9
  };
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
- };
57
10
  import { curve } from "../curve.js";
58
11
  import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
59
12
  import cryptoFactorySwapABI from "../constants/abis/factory-crypto/factory-crypto-pool-2.json" assert { type: 'json' };
@@ -61,352 +14,259 @@ import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type
61
14
  import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
62
15
  import { setFactoryZapContracts } from "./common.js";
63
16
  import { CRYPTO_FACTORY_CONSTANTS } from "./constants-crypto.js";
64
- var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
17
+ const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
65
18
  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
- });
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
21
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
22
+ for (let i = 1; i <= poolCount; i++) {
23
+ const address = yield factoryContract.pool_list(poolCount - i);
24
+ if (address.toLowerCase() === swapAddress.toLowerCase())
25
+ return `factory-crypto-${poolCount - i}`;
26
+ }
27
+ throw Error("Unknown pool");
93
28
  });
94
29
  }
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
- });
30
+ function getCryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
33
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
34
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
35
+ const calls = [];
36
+ for (let i = fromIdx; i < poolCount; i++) {
37
+ calls.push(factoryMulticallContract.pool_list(i));
38
+ }
39
+ if (calls.length === 0)
40
+ return [[], []];
41
+ let factories = (yield this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-crypto-${fromIdx + i}`, address: addr.toLowerCase() }));
42
+ const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
43
+ factories = factories.filter((f) => !swapAddresses.includes(f.address));
44
+ return [factories.map((f) => f.id), factories.map((f) => f.address)];
123
45
  });
124
46
  }
125
47
  function _handleCoinAddresses(coinAddresses) {
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(); }); });
48
+ return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
128
49
  }
129
50
  function _getLpTokenMap(factorySwapAddresses) {
130
- return __awaiter(this, void 0, void 0, function () {
131
- var factoryMulticallContract, LpTokenMap, getLpTokenCalls, _i, factorySwapAddresses_1, addr, lpTokens;
132
- return __generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0:
135
- factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
136
- LpTokenMap = {};
137
- getLpTokenCalls = [];
138
- for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
139
- addr = factorySwapAddresses_1[_i];
140
- getLpTokenCalls.push(factoryMulticallContract.get_token(addr));
141
- }
142
- return [4 /*yield*/, this.multicallProvider.all(getLpTokenCalls)];
143
- case 1:
144
- lpTokens = _a.sent();
145
- lpTokens.forEach(function (item, index) {
146
- if (typeof item === "string") {
147
- LpTokenMap[factorySwapAddresses[index]] = item;
148
- }
149
- else {
150
- throw Error("Lp token is not string");
151
- }
152
- });
153
- return [2 /*return*/, LpTokenMap];
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
53
+ const LpTokenMap = {};
54
+ const getLpTokenCalls = [];
55
+ for (const addr of factorySwapAddresses) {
56
+ getLpTokenCalls.push(factoryMulticallContract.get_token(addr));
57
+ }
58
+ const lpTokens = yield this.multicallProvider.all(getLpTokenCalls);
59
+ lpTokens.forEach((item, index) => {
60
+ if (typeof item === "string") {
61
+ LpTokenMap[factorySwapAddresses[index]] = item;
62
+ }
63
+ else {
64
+ throw Error("Lp token is not string");
154
65
  }
155
66
  });
67
+ return LpTokenMap;
156
68
  });
157
69
  }
158
70
  function getPoolsData(factorySwapAddresses) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- var factoryMulticallContract, isfactoryGaugeNull, calls, _i, factorySwapAddresses_2, addr, factoryMulticallGaugeContract, LpTokenMap, _a, factorySwapAddresses_3, addr, res, tokenAddresses, coinAddresses, gaugeAddresses, tokenAddresses, gaugeAddresses, coinAddresses;
161
- return __generator(this, function (_b) {
162
- switch (_b.label) {
163
- case 0:
164
- factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
165
- isfactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
166
- calls = [];
167
- if (!(this.chainId === 1)) return [3 /*break*/, 1];
168
- for (_i = 0, factorySwapAddresses_2 = factorySwapAddresses; _i < factorySwapAddresses_2.length; _i++) {
169
- addr = factorySwapAddresses_2[_i];
170
- calls.push(factoryMulticallContract.get_token(addr));
171
- calls.push(factoryMulticallContract.get_gauge(addr));
172
- calls.push(factoryMulticallContract.get_coins(addr));
173
- }
174
- return [3 /*break*/, 3];
175
- case 1:
176
- factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
177
- return [4 /*yield*/, _getLpTokenMap.call(this, factorySwapAddresses)];
178
- case 2:
179
- LpTokenMap = _b.sent();
180
- for (_a = 0, factorySwapAddresses_3 = factorySwapAddresses; _a < factorySwapAddresses_3.length; _a++) {
181
- addr = factorySwapAddresses_3[_a];
182
- calls.push(factoryMulticallContract.get_token(addr));
183
- if (!isfactoryGaugeNull) {
184
- calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(LpTokenMap[addr]));
185
- }
186
- calls.push(factoryMulticallContract.get_coins(addr));
187
- }
188
- _b.label = 3;
189
- case 3: return [4 /*yield*/, this.multicallProvider.all(calls)];
190
- case 4:
191
- res = _b.sent();
192
- if (isfactoryGaugeNull) {
193
- tokenAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
194
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 1; }));
195
- gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(function () { return '0x0000000000000000000000000000000000000000'; });
196
- return [2 /*return*/, [tokenAddresses, gaugeAddresses, coinAddresses]];
197
- }
198
- else {
199
- tokenAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
200
- gaugeAddresses = res.filter(function (a, i) { return i % 3 == 1; }).map(function (a) { return a.toLowerCase(); });
201
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 2; }));
202
- return [2 /*return*/, [tokenAddresses, gaugeAddresses, coinAddresses]];
203
- }
204
- return [2 /*return*/];
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
73
+ const isfactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
74
+ const calls = [];
75
+ if (this.chainId === 1) {
76
+ for (const addr of factorySwapAddresses) {
77
+ calls.push(factoryMulticallContract.get_token(addr));
78
+ calls.push(factoryMulticallContract.get_gauge(addr));
79
+ calls.push(factoryMulticallContract.get_coins(addr));
205
80
  }
206
- });
81
+ }
82
+ else {
83
+ const factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
84
+ const LpTokenMap = yield _getLpTokenMap.call(this, factorySwapAddresses);
85
+ for (const addr of factorySwapAddresses) {
86
+ calls.push(factoryMulticallContract.get_token(addr));
87
+ if (!isfactoryGaugeNull) {
88
+ calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(LpTokenMap[addr]));
89
+ }
90
+ calls.push(factoryMulticallContract.get_coins(addr));
91
+ }
92
+ }
93
+ const res = yield this.multicallProvider.all(calls);
94
+ if (isfactoryGaugeNull) {
95
+ const tokenAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
96
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 1));
97
+ const gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(() => '0x0000000000000000000000000000000000000000');
98
+ return [tokenAddresses, gaugeAddresses, coinAddresses];
99
+ }
100
+ else {
101
+ const tokenAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
102
+ const gaugeAddresses = res.filter((a, i) => i % 3 == 1).map((a) => a.toLowerCase());
103
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 2));
104
+ return [tokenAddresses, gaugeAddresses, coinAddresses];
105
+ }
207
106
  });
208
107
  }
209
108
  function setCryptoFactorySwapContracts(factorySwapAddresses) {
210
- var _this = this;
211
- factorySwapAddresses.forEach(function (addr) {
212
- _this.setContract(addr, cryptoFactorySwapABI);
109
+ factorySwapAddresses.forEach((addr) => {
110
+ this.setContract(addr, cryptoFactorySwapABI);
213
111
  });
214
112
  }
215
113
  function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
216
- var _this = this;
217
- factoryTokenAddresses.forEach(function (addr) {
218
- _this.setContract(addr, ERC20ABI);
114
+ factoryTokenAddresses.forEach((addr) => {
115
+ this.setContract(addr, ERC20ABI);
219
116
  });
220
117
  }
221
118
  function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
222
- var _this = this;
223
- factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
224
- _this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
119
+ factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
120
+ this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
225
121
  });
226
122
  }
227
123
  function setCryptoFactoryCoinsContracts(coinAddresses) {
228
- var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
229
- for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
230
- var addr = flattenedCoinAddresses_1[_i];
124
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
125
+ for (const addr of flattenedCoinAddresses) {
231
126
  if (addr in this.contracts)
232
127
  continue;
233
128
  this.setContract(addr, ERC20ABI);
234
129
  }
235
130
  }
236
131
  function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
237
- var _this = this;
238
- return __spreadArray([], coinAddresses.map(function (coins) { return coins.map(function (c) { return c === _this.constants.NATIVE_TOKEN.wrappedAddress ? _this.constants.NATIVE_TOKEN.address : c; }); }), true);
132
+ return [...coinAddresses.map((coins) => coins.map((c) => c === this.constants.NATIVE_TOKEN.wrappedAddress ? this.constants.NATIVE_TOKEN.address : c))];
239
133
  }
240
134
  function getExistingCoinAddressNameDict() {
241
- var dict = {};
242
- var _loop_1 = function (poolData) {
243
- poolData.wrapped_coin_addresses.forEach(function (addr, i) {
135
+ const dict = {};
136
+ for (const poolData of Object.values(this.constants.POOLS_DATA)) {
137
+ poolData.wrapped_coin_addresses.forEach((addr, i) => {
244
138
  if (!(addr.toLowerCase() in dict)) {
245
139
  dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
246
140
  }
247
141
  });
248
- poolData.underlying_coin_addresses.forEach(function (addr, i) {
142
+ poolData.underlying_coin_addresses.forEach((addr, i) => {
249
143
  if (!(addr.toLowerCase() in dict)) {
250
144
  dict[addr.toLowerCase()] = poolData.underlying_coins[i];
251
145
  }
252
146
  });
253
- };
254
- for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
255
- var poolData = _a[_i];
256
- _loop_1(poolData);
257
147
  }
258
148
  dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
259
149
  return dict;
260
150
  }
261
151
  function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
262
- return __awaiter(this, void 0, void 0, function () {
263
- 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;
264
- return __generator(this, function (_c) {
265
- switch (_c.label) {
266
- case 0:
267
- flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
268
- newCoinAddresses = [];
269
- coinAddrNamesDict = {};
270
- coinAddrDecimalsDict = {};
271
- for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
272
- addr = flattenedCoinAddresses_2[_i];
273
- if (addr in existingCoinAddrNameDict) {
274
- coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
275
- coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
276
- }
277
- else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
278
- coinAddrNamesDict[addr] = "MKR";
279
- coinAddrDecimalsDict[addr] = 18;
280
- }
281
- else {
282
- newCoinAddresses.push(addr);
283
- }
284
- }
285
- calls = [];
286
- for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
287
- addr = tokenAddresses_1[_a];
288
- calls.push(this.contracts[addr].multicallContract.symbol());
289
- calls.push(this.contracts[addr].multicallContract.name());
290
- }
291
- for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
292
- addr = newCoinAddresses_1[_b];
293
- calls.push(this.contracts[addr].multicallContract.symbol());
294
- calls.push(this.contracts[addr].multicallContract.decimals());
295
- }
296
- return [4 /*yield*/, this.multicallProvider.all(calls)];
297
- case 1:
298
- res = _c.sent();
299
- res1 = res.slice(0, tokenAddresses.length * 2);
300
- tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
301
- tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
302
- res2 = res.slice(tokenAddresses.length * 2);
303
- symbols = res2.filter(function (a, i) { return i % 2 == 0; });
304
- decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
305
- newCoinAddresses.forEach(function (addr, i) {
306
- coinAddrNamesDict[addr] = symbols[i];
307
- coinAddrDecimalsDict[addr] = decimals[i];
308
- });
309
- coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
310
- coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
311
- return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
154
+ const newCoinAddresses = [];
155
+ const coinAddrNamesDict = {};
156
+ const coinAddrDecimalsDict = {};
157
+ for (const addr of flattenedCoinAddresses) {
158
+ if (addr in existingCoinAddrNameDict) {
159
+ coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
160
+ coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
161
+ }
162
+ else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
163
+ coinAddrNamesDict[addr] = "MKR";
164
+ coinAddrDecimalsDict[addr] = 18;
312
165
  }
166
+ else {
167
+ newCoinAddresses.push(addr);
168
+ }
169
+ }
170
+ const calls = [];
171
+ for (const addr of tokenAddresses) {
172
+ calls.push(this.contracts[addr].multicallContract.symbol());
173
+ calls.push(this.contracts[addr].multicallContract.name());
174
+ }
175
+ for (const addr of newCoinAddresses) {
176
+ calls.push(this.contracts[addr].multicallContract.symbol());
177
+ calls.push(this.contracts[addr].multicallContract.decimals());
178
+ }
179
+ const res = yield this.multicallProvider.all(calls);
180
+ const res1 = res.slice(0, tokenAddresses.length * 2);
181
+ const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
182
+ const tokenNames = res1.filter((a, i) => i % 2 == 1);
183
+ const res2 = res.slice(tokenAddresses.length * 2);
184
+ const symbols = res2.filter((a, i) => i % 2 == 0);
185
+ const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
186
+ newCoinAddresses.forEach((addr, i) => {
187
+ coinAddrNamesDict[addr] = symbols[i];
188
+ coinAddrDecimalsDict[addr] = decimals[i];
313
189
  });
190
+ coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
191
+ coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
192
+ return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
314
193
  });
315
194
  }
316
- export function getCryptoFactoryPoolData(fromIdx, swapAddress) {
317
- if (fromIdx === void 0) { fromIdx = 0; }
318
- return __awaiter(this, void 0, void 0, function () {
319
- 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;
320
- return __generator(this, function (_f) {
321
- switch (_f.label) {
322
- case 0:
323
- if (!swapAddress) return [3 /*break*/, 2];
324
- return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
325
- case 1:
326
- _b = [[_f.sent()], [swapAddress.toLowerCase()]];
327
- return [3 /*break*/, 4];
328
- case 2: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx)];
329
- case 3:
330
- _b = _f.sent();
331
- _f.label = 4;
332
- case 4:
333
- _a = _b, poolIds = _a[0], swapAddresses = _a[1];
334
- if (poolIds.length === 0)
335
- return [2 /*return*/, {}];
336
- return [4 /*yield*/, getPoolsData.call(this, swapAddresses)];
337
- case 5:
338
- _c = _f.sent(), tokenAddresses = _c[0], gaugeAddresses = _c[1], coinAddresses = _c[2];
339
- setCryptoFactorySwapContracts.call(this, swapAddresses);
340
- setCryptoFactoryTokenContracts.call(this, tokenAddresses);
341
- setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
342
- setCryptoFactoryCoinsContracts.call(this, coinAddresses);
343
- setFactoryZapContracts.call(this, true);
344
- underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
345
- existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
346
- return [4 /*yield*/, getCoinsData.call(this, tokenAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS)];
347
- case 6:
348
- _e = _f.sent(), poolSymbols = _e[0], poolNames = _e[1], coinAddressNameDict = _e[2], coinAddressDecimalsDict = _e[3];
349
- CRYPTO_FACTORY_POOLS_DATA = {};
350
- for (i = 0; i < poolIds.length; i++) {
351
- lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
352
- basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
353
- basePoolId = lpTokenBasePoolIdDict[coinAddresses[i][1].toLowerCase()];
354
- if (basePoolId) { // isMeta
355
- allPoolsData = __assign(__assign({}, this.constants.POOLS_DATA), CRYPTO_FACTORY_POOLS_DATA);
356
- basePoolCoinNames = __spreadArray([], allPoolsData[basePoolId].underlying_coins, true);
357
- basePoolCoinAddresses = __spreadArray([], allPoolsData[basePoolId].underlying_coin_addresses, true);
358
- basePoolDecimals = __spreadArray([], allPoolsData[basePoolId].underlying_decimals, true);
359
- basePoolZap = basePoolIdZapDict[basePoolId];
360
- this.constants.BASE_POOLS[basePoolId] = this.constants.BASE_POOLS[basePoolId] ? this.constants.BASE_POOLS[basePoolId] + 1 : 1;
361
- CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
362
- name: poolNames[i].split(": ")[1].trim(),
363
- full_name: poolNames[i],
364
- symbol: poolSymbols[i],
365
- reference_asset: "CRYPTO",
366
- swap_address: swapAddresses[i],
367
- token_address: tokenAddresses[i],
368
- gauge_address: gaugeAddresses[i],
369
- deposit_address: basePoolZap.address,
370
- is_meta: true,
371
- is_crypto: true,
372
- is_factory: true,
373
- base_pool: basePoolId,
374
- underlying_coins: __spreadArray([coinAddressNameDict[underlyingCoinAddresses[i][0]]], basePoolCoinNames, true),
375
- wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
376
- underlying_coin_addresses: __spreadArray([underlyingCoinAddresses[i][0]], basePoolCoinAddresses, true),
377
- wrapped_coin_addresses: coinAddresses[i],
378
- underlying_decimals: __spreadArray([coinAddressDecimalsDict[underlyingCoinAddresses[i][0]]], basePoolDecimals, true),
379
- wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
380
- swap_abi: cryptoFactorySwapABI,
381
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
382
- deposit_abi: basePoolZap.ABI,
383
- };
384
- }
385
- else {
386
- CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
387
- name: poolNames[i].split(": ")[1].trim(),
388
- full_name: poolNames[i],
389
- symbol: poolSymbols[i],
390
- reference_asset: "CRYPTO",
391
- swap_address: swapAddresses[i],
392
- token_address: tokenAddresses[i],
393
- gauge_address: gaugeAddresses[i],
394
- is_crypto: true,
395
- is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
396
- is_factory: true,
397
- underlying_coins: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
398
- wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
399
- underlying_coin_addresses: underlyingCoinAddresses[i],
400
- wrapped_coin_addresses: coinAddresses[i],
401
- underlying_decimals: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
402
- wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
403
- swap_abi: cryptoFactorySwapABI,
404
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
405
- };
406
- }
407
- }
408
- return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
195
+ export function getCryptoFactoryPoolData(fromIdx = 0, swapAddress) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const [poolIds, swapAddresses] = swapAddress ?
198
+ [[yield getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
199
+ : yield getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
200
+ if (poolIds.length === 0)
201
+ return {};
202
+ const [tokenAddresses, gaugeAddresses, coinAddresses] = yield getPoolsData.call(this, swapAddresses);
203
+ setCryptoFactorySwapContracts.call(this, swapAddresses);
204
+ setCryptoFactoryTokenContracts.call(this, tokenAddresses);
205
+ setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
206
+ setCryptoFactoryCoinsContracts.call(this, coinAddresses);
207
+ setFactoryZapContracts.call(this, true);
208
+ const underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
209
+ const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
210
+ const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = yield getCoinsData.call(this, tokenAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
211
+ const CRYPTO_FACTORY_POOLS_DATA = {};
212
+ for (let i = 0; i < poolIds.length; i++) {
213
+ const lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
214
+ const basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
215
+ const basePoolId = lpTokenBasePoolIdDict[coinAddresses[i][1].toLowerCase()];
216
+ if (basePoolId) { // isMeta
217
+ const allPoolsData = Object.assign(Object.assign({}, this.constants.POOLS_DATA), CRYPTO_FACTORY_POOLS_DATA);
218
+ const basePoolCoinNames = [...allPoolsData[basePoolId].underlying_coins];
219
+ const basePoolCoinAddresses = [...allPoolsData[basePoolId].underlying_coin_addresses];
220
+ const basePoolDecimals = [...allPoolsData[basePoolId].underlying_decimals];
221
+ const basePoolZap = basePoolIdZapDict[basePoolId];
222
+ this.constants.BASE_POOLS[basePoolId] = this.constants.BASE_POOLS[basePoolId] ? this.constants.BASE_POOLS[basePoolId] + 1 : 1;
223
+ CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
224
+ name: poolNames[i].split(": ")[1].trim(),
225
+ full_name: poolNames[i],
226
+ symbol: poolSymbols[i],
227
+ reference_asset: "CRYPTO",
228
+ swap_address: swapAddresses[i],
229
+ token_address: tokenAddresses[i],
230
+ gauge_address: gaugeAddresses[i],
231
+ deposit_address: basePoolZap.address,
232
+ is_meta: true,
233
+ is_crypto: true,
234
+ is_factory: true,
235
+ base_pool: basePoolId,
236
+ underlying_coins: [coinAddressNameDict[underlyingCoinAddresses[i][0]], ...basePoolCoinNames],
237
+ wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
238
+ underlying_coin_addresses: [underlyingCoinAddresses[i][0], ...basePoolCoinAddresses],
239
+ wrapped_coin_addresses: coinAddresses[i],
240
+ underlying_decimals: [coinAddressDecimalsDict[underlyingCoinAddresses[i][0]], ...basePoolDecimals],
241
+ wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
242
+ swap_abi: cryptoFactorySwapABI,
243
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
244
+ deposit_abi: basePoolZap.ABI,
245
+ };
409
246
  }
410
- });
247
+ else {
248
+ CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
249
+ name: poolNames[i].split(": ")[1].trim(),
250
+ full_name: poolNames[i],
251
+ symbol: poolSymbols[i],
252
+ reference_asset: "CRYPTO",
253
+ swap_address: swapAddresses[i],
254
+ token_address: tokenAddresses[i],
255
+ gauge_address: gaugeAddresses[i],
256
+ is_crypto: true,
257
+ is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
258
+ is_factory: true,
259
+ underlying_coins: [...underlyingCoinAddresses[i].map((addr) => coinAddressNameDict[addr])],
260
+ wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
261
+ underlying_coin_addresses: underlyingCoinAddresses[i],
262
+ wrapped_coin_addresses: coinAddresses[i],
263
+ underlying_decimals: [...underlyingCoinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
264
+ wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
265
+ swap_abi: cryptoFactorySwapABI,
266
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
267
+ };
268
+ }
269
+ }
270
+ return CRYPTO_FACTORY_POOLS_DATA;
411
271
  });
412
272
  }