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