@curvefi/api 2.63.0 → 2.63.1

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 +3 -1
  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 +1 -6
  56. package/lib/pools/PoolTemplate.js +1773 -3025
  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 +5 -25
  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 +5 -4
  82. package/lib/utils.js +539 -918
  83. package/package.json +1 -1
@@ -7,325 +7,207 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- 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;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
- if (ar || !(i in from)) {
40
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
- ar[i] = from[i];
42
- }
43
- }
44
- return to.concat(ar || Array.prototype.slice.call(from));
45
- };
46
10
  import { curve } from "../curve.js";
47
11
  import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
48
12
  import twocryptoFactorySwapABI from "../constants/abis/factory-twocrypto/factory-twocrypto-pool.json" assert { type: 'json' };
49
13
  import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
50
14
  import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
51
- var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
15
+ const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
52
16
  function getRecentlyCreatedCryptoPoolId(swapAddress) {
53
- return __awaiter(this, void 0, void 0, function () {
54
- var factoryContract, poolCount, _a, _b, _c, i, address;
55
- return __generator(this, function (_e) {
56
- switch (_e.label) {
57
- case 0:
58
- factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
59
- _a = Number;
60
- _c = (_b = curve).formatUnits;
61
- return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
62
- case 1:
63
- poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
64
- i = 1;
65
- _e.label = 2;
66
- case 2:
67
- if (!(i <= poolCount)) return [3 /*break*/, 5];
68
- return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
69
- case 3:
70
- address = _e.sent();
71
- if (address.toLowerCase() === swapAddress.toLowerCase())
72
- return [2 /*return*/, "factory-twocrypto-".concat(poolCount - i)];
73
- _e.label = 4;
74
- case 4:
75
- i++;
76
- return [3 /*break*/, 2];
77
- case 5: throw Error("Unknown pool");
78
- }
79
- });
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
19
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
20
+ for (let i = 1; i <= poolCount; i++) {
21
+ const address = yield factoryContract.pool_list(poolCount - i);
22
+ if (address.toLowerCase() === swapAddress.toLowerCase())
23
+ return `factory-twocrypto-${poolCount - i}`;
24
+ }
25
+ throw Error("Unknown pool");
80
26
  });
81
27
  }
82
- function getTwocryptoFactoryIdsAndSwapAddresses(fromIdx) {
83
- if (fromIdx === void 0) { fromIdx = 0; }
84
- return __awaiter(this, void 0, void 0, function () {
85
- var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
86
- return __generator(this, function (_e) {
87
- switch (_e.label) {
88
- case 0:
89
- factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
90
- factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
91
- _a = Number;
92
- _c = (_b = curve).formatUnits;
93
- return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
94
- case 1:
95
- poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
96
- calls = [];
97
- for (i = fromIdx; i < poolCount; i++) {
98
- calls.push(factoryMulticallContract.pool_list(i));
99
- }
100
- if (calls.length === 0)
101
- return [2 /*return*/, [[], []]];
102
- return [4 /*yield*/, this.multicallProvider.all(calls)];
103
- case 2:
104
- factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-twocrypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
105
- swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
106
- factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
107
- return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
108
- }
109
- });
28
+ function getTwocryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
31
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
32
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
33
+ const calls = [];
34
+ for (let i = fromIdx; i < poolCount; i++) {
35
+ calls.push(factoryMulticallContract.pool_list(i));
36
+ }
37
+ if (calls.length === 0)
38
+ return [[], []];
39
+ let factories = (yield this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-twocrypto-${fromIdx + i}`, address: addr.toLowerCase() }));
40
+ const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
41
+ factories = factories.filter((f) => !swapAddresses.includes(f.address));
42
+ return [factories.map((f) => f.id), factories.map((f) => f.address)];
110
43
  });
111
44
  }
112
45
  function _handleCoinAddresses(coinAddresses) {
113
- var _this = this;
114
- return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
46
+ return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
115
47
  }
116
48
  function getPoolsData(factorySwapAddresses) {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, res, gaugeAddresses, coinAddresses, factoryMulticallContract, isFactoryGaugeNull, factoryMulticallGaugeContract, calls, _a, factorySwapAddresses_2, addr, res, gaugeAddresses, coinAddresses, coinAddresses, gaugeAddresses;
119
- return __generator(this, function (_b) {
120
- switch (_b.label) {
121
- case 0:
122
- if (!(this.chainId === 1)) return [3 /*break*/, 2];
123
- factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
124
- calls = [];
125
- for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
126
- addr = factorySwapAddresses_1[_i];
127
- calls.push(factoryMulticallContract.get_gauge(addr));
128
- calls.push(factoryMulticallContract.get_coins(addr));
129
- }
130
- return [4 /*yield*/, this.multicallProvider.all(calls)];
131
- case 1:
132
- res = _b.sent();
133
- gaugeAddresses = res.filter(function (a, i) { return i % 2 == 0; }).map(function (a) { return a.toLowerCase(); });
134
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 1; }));
135
- return [2 /*return*/, [gaugeAddresses, coinAddresses]];
136
- case 2:
137
- factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
138
- isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
139
- factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
140
- calls = [];
141
- for (_a = 0, factorySwapAddresses_2 = factorySwapAddresses; _a < factorySwapAddresses_2.length; _a++) {
142
- addr = factorySwapAddresses_2[_a];
143
- if (!isFactoryGaugeNull) {
144
- calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
145
- }
146
- calls.push(factoryMulticallContract.get_coins(addr));
147
- }
148
- return [4 /*yield*/, this.multicallProvider.all(calls)];
149
- case 3:
150
- res = _b.sent();
151
- if (!isFactoryGaugeNull) {
152
- gaugeAddresses = res.filter(function (a, i) { return i % 2 == 0; }).map(function (a) { return a.toLowerCase(); });
153
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 1; }));
154
- return [2 /*return*/, [gaugeAddresses, coinAddresses]];
155
- }
156
- else {
157
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 0; }));
158
- gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(function () { return '0x0000000000000000000000000000000000000000'; });
159
- return [2 /*return*/, [gaugeAddresses, coinAddresses]];
160
- }
161
- _b.label = 4;
162
- case 4: return [2 /*return*/];
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (this.chainId === 1) {
51
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
52
+ const calls = [];
53
+ for (const addr of factorySwapAddresses) {
54
+ calls.push(factoryMulticallContract.get_gauge(addr));
55
+ calls.push(factoryMulticallContract.get_coins(addr));
163
56
  }
164
- });
57
+ const res = yield this.multicallProvider.all(calls);
58
+ const gaugeAddresses = res.filter((a, i) => i % 2 == 0).map((a) => a.toLowerCase());
59
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 1));
60
+ return [gaugeAddresses, coinAddresses];
61
+ }
62
+ else {
63
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
64
+ const isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
65
+ const factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
66
+ const calls = [];
67
+ for (const addr of factorySwapAddresses) {
68
+ if (!isFactoryGaugeNull) {
69
+ calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
70
+ }
71
+ calls.push(factoryMulticallContract.get_coins(addr));
72
+ }
73
+ const res = yield this.multicallProvider.all(calls);
74
+ if (!isFactoryGaugeNull) {
75
+ const gaugeAddresses = res.filter((a, i) => i % 2 == 0).map((a) => a.toLowerCase());
76
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 1));
77
+ return [gaugeAddresses, coinAddresses];
78
+ }
79
+ else {
80
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 0));
81
+ const gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(() => '0x0000000000000000000000000000000000000000');
82
+ return [gaugeAddresses, coinAddresses];
83
+ }
84
+ }
165
85
  });
166
86
  }
167
87
  function setTwocryptoFactorySwapContracts(factorySwapAddresses) {
168
- var _this = this;
169
- factorySwapAddresses.forEach(function (addr) {
170
- _this.setContract(addr, twocryptoFactorySwapABI);
88
+ factorySwapAddresses.forEach((addr) => {
89
+ this.setContract(addr, twocryptoFactorySwapABI);
171
90
  });
172
91
  }
173
92
  function setTwocryptoFactoryTokenContracts(factoryTokenAddresses) {
174
- var _this = this;
175
- factoryTokenAddresses.forEach(function (addr) {
176
- _this.setContract(addr, ERC20ABI);
93
+ factoryTokenAddresses.forEach((addr) => {
94
+ this.setContract(addr, ERC20ABI);
177
95
  });
178
96
  }
179
97
  function setTwocryptoFactoryGaugeContracts(factoryGaugeAddresses) {
180
- var _this = this;
181
- factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
182
- _this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
98
+ factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
99
+ this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
183
100
  });
184
101
  }
185
102
  function setTwocryptoFactoryCoinsContracts(coinAddresses) {
186
- var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
187
- for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
188
- var addr = flattenedCoinAddresses_1[_i];
103
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
104
+ for (const addr of flattenedCoinAddresses) {
189
105
  if (addr in this.contracts)
190
106
  continue;
191
107
  this.setContract(addr, ERC20ABI);
192
108
  }
193
109
  }
194
110
  function getTwocryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
195
- return __spreadArray([], coinAddresses.map(function (coins) { return coins.map(function (c) { return c; }); }), true);
111
+ return [...coinAddresses.map((coins) => coins.map((c) => c))];
196
112
  }
197
113
  function getExistingCoinAddressNameDict() {
198
- var dict = {};
199
- var _loop_1 = function (poolData) {
200
- poolData.wrapped_coin_addresses.forEach(function (addr, i) {
114
+ const dict = {};
115
+ for (const poolData of Object.values(this.constants.POOLS_DATA)) {
116
+ poolData.wrapped_coin_addresses.forEach((addr, i) => {
201
117
  if (!(addr.toLowerCase() in dict)) {
202
118
  dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
203
119
  }
204
120
  });
205
- poolData.underlying_coin_addresses.forEach(function (addr, i) {
121
+ poolData.underlying_coin_addresses.forEach((addr, i) => {
206
122
  if (!(addr.toLowerCase() in dict)) {
207
123
  dict[addr.toLowerCase()] = poolData.underlying_coins[i];
208
124
  }
209
125
  });
210
- };
211
- for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
212
- var poolData = _a[_i];
213
- _loop_1(poolData);
214
126
  }
215
127
  dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
216
128
  return dict;
217
129
  }
218
130
  function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- 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;
221
- return __generator(this, function (_c) {
222
- switch (_c.label) {
223
- case 0:
224
- flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
225
- newCoinAddresses = [];
226
- coinAddrNamesDict = {};
227
- coinAddrDecimalsDict = {};
228
- for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
229
- addr = flattenedCoinAddresses_2[_i];
230
- if (addr in existingCoinAddrNameDict) {
231
- coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
232
- coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
233
- }
234
- else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
235
- coinAddrNamesDict[addr] = "MKR";
236
- }
237
- else {
238
- newCoinAddresses.push(addr);
239
- }
240
- }
241
- calls = [];
242
- for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
243
- addr = tokenAddresses_1[_a];
244
- calls.push(this.contracts[addr].multicallContract.symbol());
245
- calls.push(this.contracts[addr].multicallContract.name());
246
- }
247
- for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
248
- addr = newCoinAddresses_1[_b];
249
- calls.push(this.contracts[addr].multicallContract.symbol());
250
- calls.push(this.contracts[addr].multicallContract.decimals());
251
- }
252
- return [4 /*yield*/, this.multicallProvider.all(calls)];
253
- case 1:
254
- res = _c.sent();
255
- res1 = res.slice(0, tokenAddresses.length * 2);
256
- tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
257
- tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
258
- res2 = res.slice(tokenAddresses.length * 2);
259
- symbols = res2.filter(function (a, i) { return i % 2 == 0; });
260
- decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
261
- newCoinAddresses.forEach(function (addr, i) {
262
- coinAddrNamesDict[addr] = symbols[i];
263
- coinAddrDecimalsDict[addr] = decimals[i];
264
- });
265
- coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
266
- coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
267
- return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
133
+ const newCoinAddresses = [];
134
+ const coinAddrNamesDict = {};
135
+ const coinAddrDecimalsDict = {};
136
+ for (const addr of flattenedCoinAddresses) {
137
+ if (addr in existingCoinAddrNameDict) {
138
+ coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
139
+ coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
140
+ }
141
+ else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
142
+ coinAddrNamesDict[addr] = "MKR";
143
+ }
144
+ else {
145
+ newCoinAddresses.push(addr);
268
146
  }
147
+ }
148
+ const calls = [];
149
+ for (const addr of tokenAddresses) {
150
+ calls.push(this.contracts[addr].multicallContract.symbol());
151
+ calls.push(this.contracts[addr].multicallContract.name());
152
+ }
153
+ for (const addr of newCoinAddresses) {
154
+ calls.push(this.contracts[addr].multicallContract.symbol());
155
+ calls.push(this.contracts[addr].multicallContract.decimals());
156
+ }
157
+ const res = yield this.multicallProvider.all(calls);
158
+ const res1 = res.slice(0, tokenAddresses.length * 2);
159
+ const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
160
+ const tokenNames = res1.filter((a, i) => i % 2 == 1);
161
+ const res2 = res.slice(tokenAddresses.length * 2);
162
+ const symbols = res2.filter((a, i) => i % 2 == 0);
163
+ const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
164
+ newCoinAddresses.forEach((addr, i) => {
165
+ coinAddrNamesDict[addr] = symbols[i];
166
+ coinAddrDecimalsDict[addr] = decimals[i];
269
167
  });
168
+ coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
169
+ coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
170
+ return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
270
171
  });
271
172
  }
272
- export function getTwocryptoFactoryPoolData(fromIdx, swapAddress) {
273
- if (fromIdx === void 0) { fromIdx = 0; }
274
- return __awaiter(this, void 0, void 0, function () {
275
- var _a, poolIds, swapAddresses, _b, _c, gaugeAddresses, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, _e, poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict, TWOCRYPTO_FACTORY_POOLS_DATA, i;
276
- return __generator(this, function (_f) {
277
- switch (_f.label) {
278
- case 0:
279
- if (!swapAddress) return [3 /*break*/, 2];
280
- return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
281
- case 1:
282
- _b = [[_f.sent()], [swapAddress.toLowerCase()]];
283
- return [3 /*break*/, 4];
284
- case 2: return [4 /*yield*/, getTwocryptoFactoryIdsAndSwapAddresses.call(this, fromIdx)];
285
- case 3:
286
- _b = _f.sent();
287
- _f.label = 4;
288
- case 4:
289
- _a = _b, poolIds = _a[0], swapAddresses = _a[1];
290
- if (poolIds.length === 0)
291
- return [2 /*return*/, {}];
292
- return [4 /*yield*/, getPoolsData.call(this, swapAddresses)];
293
- case 5:
294
- _c = _f.sent(), gaugeAddresses = _c[0], coinAddresses = _c[1];
295
- setTwocryptoFactorySwapContracts.call(this, swapAddresses);
296
- setTwocryptoFactoryGaugeContracts.call(this, gaugeAddresses);
297
- setTwocryptoFactoryCoinsContracts.call(this, coinAddresses);
298
- underlyingCoinAddresses = getTwocryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
299
- existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
300
- return [4 /*yield*/, getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS)];
301
- case 6:
302
- _e = _f.sent(), poolSymbols = _e[0], poolNames = _e[1], coinAddressNameDict = _e[2], coinAddressDecimalsDict = _e[3];
303
- TWOCRYPTO_FACTORY_POOLS_DATA = {};
304
- for (i = 0; i < poolIds.length; i++) {
305
- TWOCRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
306
- name: poolNames[i],
307
- full_name: poolNames[i],
308
- symbol: poolSymbols[i],
309
- reference_asset: "CRYPTO",
310
- swap_address: swapAddresses[i],
311
- token_address: swapAddresses[i],
312
- gauge_address: gaugeAddresses[i],
313
- is_crypto: true,
314
- is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
315
- is_factory: true,
316
- underlying_coins: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
317
- wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
318
- underlying_coin_addresses: underlyingCoinAddresses[i],
319
- wrapped_coin_addresses: coinAddresses[i],
320
- underlying_decimals: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
321
- wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
322
- swap_abi: twocryptoFactorySwapABI,
323
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
324
- is_ng: true,
325
- };
326
- }
327
- return [2 /*return*/, TWOCRYPTO_FACTORY_POOLS_DATA];
328
- }
329
- });
173
+ export function getTwocryptoFactoryPoolData(fromIdx = 0, swapAddress) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const [poolIds, swapAddresses] = swapAddress ?
176
+ [[yield getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
177
+ : yield getTwocryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
178
+ if (poolIds.length === 0)
179
+ return {};
180
+ const [gaugeAddresses, coinAddresses] = yield getPoolsData.call(this, swapAddresses);
181
+ setTwocryptoFactorySwapContracts.call(this, swapAddresses);
182
+ setTwocryptoFactoryGaugeContracts.call(this, gaugeAddresses);
183
+ setTwocryptoFactoryCoinsContracts.call(this, coinAddresses);
184
+ const underlyingCoinAddresses = getTwocryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
185
+ const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
186
+ const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = yield getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
187
+ const TWOCRYPTO_FACTORY_POOLS_DATA = {};
188
+ for (let i = 0; i < poolIds.length; i++) {
189
+ TWOCRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
190
+ name: poolNames[i],
191
+ full_name: poolNames[i],
192
+ symbol: poolSymbols[i],
193
+ reference_asset: "CRYPTO",
194
+ swap_address: swapAddresses[i],
195
+ token_address: swapAddresses[i],
196
+ gauge_address: gaugeAddresses[i],
197
+ is_crypto: true,
198
+ is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
199
+ is_factory: true,
200
+ underlying_coins: [...underlyingCoinAddresses[i].map((addr) => coinAddressNameDict[addr])],
201
+ wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
202
+ underlying_coin_addresses: underlyingCoinAddresses[i],
203
+ wrapped_coin_addresses: coinAddresses[i],
204
+ underlying_decimals: [...underlyingCoinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
205
+ wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
206
+ swap_abi: twocryptoFactorySwapABI,
207
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
208
+ is_ng: true,
209
+ };
210
+ }
211
+ return TWOCRYPTO_FACTORY_POOLS_DATA;
330
212
  });
331
213
  }