@curvefi/api 1.17.2 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +57 -0
  2. package/lib/constants/abis/abis-ethereum.js +6 -6
  3. package/lib/constants/abis/json/factory-crypto/factory-crypto-pool-2.json +1112 -0
  4. package/lib/constants/abis/json/factory-crypto.json +635 -0
  5. package/lib/constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json +197 -0
  6. package/lib/constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json +197 -0
  7. package/lib/constants/abis/json/factory-v2/MetaBTC.json +919 -0
  8. package/lib/constants/abis/json/factory-v2/MetaBTCBalances.json +932 -0
  9. package/lib/constants/abis/json/factory-v2/MetaBTCBalancesRen.json +932 -0
  10. package/lib/constants/abis/json/factory-v2/MetaBTCRen.json +919 -0
  11. package/lib/constants/abis/json/factory-v2/MetaUSD.json +919 -0
  12. package/lib/constants/abis/json/factory-v2/MetaUSDBalances.json +932 -0
  13. package/lib/constants/abis/json/factory-v2/Plain2Balances.json +845 -0
  14. package/lib/constants/abis/json/factory-v2/Plain2Basic.json +845 -0
  15. package/lib/constants/abis/json/factory-v2/Plain2ETH.json +845 -0
  16. package/lib/constants/abis/json/factory-v2/Plain2Optimized.json +844 -0
  17. package/lib/constants/abis/json/factory-v2/Plain3Balances.json +845 -0
  18. package/lib/constants/abis/json/factory-v2/Plain3Basic.json +845 -0
  19. package/lib/constants/abis/json/factory-v2/Plain3ETH.json +845 -0
  20. package/lib/constants/abis/json/factory-v2/Plain3Optimized.json +845 -0
  21. package/lib/constants/abis/json/factory-v2/Plain4Balances.json +845 -0
  22. package/lib/constants/abis/json/factory-v2/Plain4Basic.json +845 -0
  23. package/lib/constants/abis/json/factory-v2/Plain4ETH.json +845 -0
  24. package/lib/constants/abis/json/factory-v2/Plain4Optimized.json +845 -0
  25. package/lib/constants/abis/json/factory.json +1063 -0
  26. package/lib/constants/abis/json/registry_exchange.json +207 -84
  27. package/lib/constants/aliases.d.ts +4 -0
  28. package/lib/constants/aliases.js +4 -0
  29. package/lib/constants/coins-polygon.js +3 -2
  30. package/lib/curve.d.ts +5 -0
  31. package/lib/curve.js +62 -0
  32. package/lib/factory-crypto.d.ts +32 -0
  33. package/lib/factory-crypto.js +377 -0
  34. package/lib/factory.d.ts +32 -0
  35. package/lib/factory.js +607 -0
  36. package/lib/index.d.ts +7 -0
  37. package/lib/index.js +28 -0
  38. package/lib/interfaces.d.ts +28 -1
  39. package/lib/pools.d.ts +5 -0
  40. package/lib/pools.js +359 -159
  41. package/lib/utils.d.ts +8 -1
  42. package/lib/utils.js +111 -8
  43. package/package.json +4 -2
package/lib/factory.js ADDED
@@ -0,0 +1,607 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.getFactoryPoolData = void 0;
52
+ var ethers_1 = require("ethers");
53
+ var ethcall_1 = require("ethcall");
54
+ var ERC20_json_1 = __importDefault(require("./constants/abis/json/ERC20.json"));
55
+ var swap_json_1 = __importDefault(require("./constants/abis/json/factoryPools/swap.json"));
56
+ var deposit_json_1 = __importDefault(require("./constants/abis/json/factoryPools/deposit.json"));
57
+ var gauge_factory_json_1 = __importDefault(require("./constants/abis/json/gauge_factory.json"));
58
+ var DepositZapMetaUsdPolygon_json_1 = __importDefault(require("./constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json"));
59
+ var DepositZapMetaBtcPolygon_json_1 = __importDefault(require("./constants/abis/json/factory-v2/DepositZapMetaBtcPolygon.json"));
60
+ var MetaUSD_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaUSD.json"));
61
+ var MetaUSDBalances_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaUSDBalances.json"));
62
+ var MetaBTC_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaBTC.json"));
63
+ var MetaBTCBalances_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaBTCBalances.json"));
64
+ var MetaBTCRen_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaBTCRen.json"));
65
+ var MetaBTCBalancesRen_json_1 = __importDefault(require("./constants/abis/json/factory-v2/MetaBTCBalancesRen.json"));
66
+ var Plain2Basic_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain2Basic.json"));
67
+ var Plain2Balances_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain2Balances.json"));
68
+ var Plain2ETH_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain2ETH.json"));
69
+ var Plain2Optimized_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain2Optimized.json"));
70
+ var Plain3Basic_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain3Basic.json"));
71
+ var Plain3Balances_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain3Balances.json"));
72
+ var Plain3ETH_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain3ETH.json"));
73
+ var Plain3Optimized_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain3Optimized.json"));
74
+ var Plain4Basic_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain4Basic.json"));
75
+ var Plain4Balances_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain4Balances.json"));
76
+ var Plain4ETH_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain4ETH.json"));
77
+ var Plain4Optimized_json_1 = __importDefault(require("./constants/abis/json/factory-v2/Plain4Optimized.json"));
78
+ var implementationABIDictEthereum = {
79
+ "0x5F890841f657d90E081bAbdB532A05996Af79Fe6": swap_json_1.default,
80
+ "0x213be373FDff327658139C7df330817DAD2d5bBE": MetaUSD_json_1.default,
81
+ "0x55Aa9BF126bCABF0bDC17Fa9E39Ec9239e1ce7A9": MetaUSDBalances_json_1.default,
82
+ "0xC6A8466d128Fbfd34AdA64a9FFFce325D57C9a52": MetaBTC_json_1.default,
83
+ "0xc4C78b08fA0c3d0a312605634461A88184Ecd630": MetaBTCBalances_json_1.default,
84
+ "0xECAaecd9d2193900b424774133B1f51ae0F29d9E": MetaBTCRen_json_1.default,
85
+ "0x40fD58D44cFE63E8517c9Bb3ac98676838Ea56A8": MetaBTCBalancesRen_json_1.default,
86
+ "0x6523Ac15EC152Cb70a334230F6c5d62C5Bd963f1": Plain2Basic_json_1.default,
87
+ "0x24D937143d3F5cF04c72bA112735151A8CAE2262": Plain2Balances_json_1.default,
88
+ "0x6326DEbBAa15bCFE603d831e7D75f4fc10d9B43E": Plain2ETH_json_1.default,
89
+ "0x4A4d7868390EF5CaC51cDA262888f34bD3025C3F": Plain2Optimized_json_1.default,
90
+ "0x9B52F13DF69D79Ec5aAB6D1aCe3157d29B409cC3": Plain3Basic_json_1.default,
91
+ "0x50b085f2e5958C4A87baf93A8AB79F6bec068494": Plain3Balances_json_1.default,
92
+ "0x8c1aB78601c259E1B43F19816923609dC7d7de9B": Plain3ETH_json_1.default,
93
+ "0xE5F4b89E0A16578B3e0e7581327BDb4C712E44De": Plain3Optimized_json_1.default,
94
+ "0x5Bd47eA4494e0F8DE6e3Ca10F1c05F55b72466B8": Plain4Basic_json_1.default,
95
+ "0xd35B58386705CE75CE6d09842E38E9BE9CDe5bF6": Plain4Balances_json_1.default,
96
+ "0x88855cdF2b0A8413D470B86952E726684de915be": Plain4ETH_json_1.default,
97
+ "0xaD4753D045D3Aed5C1a6606dFb6a7D7AD67C1Ad7": Plain4Optimized_json_1.default,
98
+ };
99
+ var implementationABIDictPolygon = {
100
+ "0x4fb93D7d320E8A263F22f62C2059dFC2A8bCbC4c": MetaUSD_json_1.default,
101
+ "0x39fE1824f98CD828050D7c51dA443E84121c7cf1": MetaUSDBalances_json_1.default,
102
+ "0xC05EB760A135d3D0c839f1141423002681157a17": MetaBTCRen_json_1.default,
103
+ "0xD8336532f6ED7b94282fAF724fe41d6145E07Cfc": MetaBTCBalancesRen_json_1.default,
104
+ "0x571FF5b7b346F706aa48d696a9a4a288e9Bb4091": Plain2Basic_json_1.default,
105
+ "0x8925D9d9B4569D737a48499DeF3f67BaA5a144b9": Plain2Balances_json_1.default,
106
+ "0xAe00f57663F4C85FC948B13963cd4627dAF01061": Plain2ETH_json_1.default,
107
+ "0x8101E6760130be2C8Ace79643AB73500571b7162": Plain2Optimized_json_1.default,
108
+ "0x493084cA44C779Af27a416ac1F71e3823BF21b53": Plain3Basic_json_1.default,
109
+ "0x9B4Ed6F8904E976146b3dC0233CD48Cf81835240": Plain3Balances_json_1.default,
110
+ "0xA9134FaE98F92217f457918505375Ae91fdc5e3c": Plain3ETH_json_1.default,
111
+ "0xCC9fd96C26c450Dd4580893afF75efd5cb6C12Fc": Plain3Optimized_json_1.default,
112
+ "0x991b05d5316fa3A2C053F84658b84987cd5c9970": Plain4Basic_json_1.default,
113
+ "0xC7c46488566b9ef9B981b87E328939CaA5ca152f": Plain4Balances_json_1.default,
114
+ "0xf31bcdf0B9a5eCD7AB463eB905551fBc32e51856": Plain4ETH_json_1.default,
115
+ "0xAc273d5b4FC06625d8b1abA3BE8De15bDFb8E39f": Plain4Optimized_json_1.default,
116
+ };
117
+ var basePoolAddressNameDictEthereum = {
118
+ "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7": "3pool",
119
+ "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714": "sbtc",
120
+ "0x93054188d876f558f4a66B2EF1d97d16eDf0895B": "ren",
121
+ };
122
+ var basePoolAddressNameDictPolygon = {
123
+ "0x445FE580eF8d70FF569aB36e80c647af338db351": "aave",
124
+ "0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": "ren",
125
+ };
126
+ var basePoolAddressCoinsDictEthereum = {
127
+ "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7": ['DAI', 'USDC', 'USDT'],
128
+ "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714": ['renBTC', 'WBTC', 'sBTC'],
129
+ "0x93054188d876f558f4a66B2EF1d97d16eDf0895B": ['renBTC', 'WBTC'], // ren
130
+ };
131
+ var basePoolAddressCoinsDictPolygon = {
132
+ "0x445FE580eF8d70FF569aB36e80c647af338db351": ['DAI', 'USDC', 'USDT'],
133
+ "0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": ['WBTC', 'renBTC'], // ren
134
+ };
135
+ var basePoolAddressCoinAddressesDictEthereum = {
136
+ "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7": [
137
+ '0x6B175474E89094C44Da98b954EedeAC495271d0F',
138
+ '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
139
+ '0xdAC17F958D2ee523a2206206994597C13D831ec7',
140
+ ].map(function (addr) { return addr.toLowerCase(); }),
141
+ "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714": [
142
+ '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D',
143
+ '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
144
+ '0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6',
145
+ ].map(function (addr) { return addr.toLowerCase(); }),
146
+ "0x93054188d876f558f4a66B2EF1d97d16eDf0895B": [
147
+ '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D',
148
+ '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
149
+ ].map(function (addr) { return addr.toLowerCase(); }),
150
+ };
151
+ var basePoolAddressCoinAddressesDictPolygon = {
152
+ "0x445FE580eF8d70FF569aB36e80c647af338db351": [
153
+ '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063',
154
+ '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
155
+ '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
156
+ ].map(function (addr) { return addr.toLowerCase(); }),
157
+ "0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": [
158
+ '0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6',
159
+ '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
160
+ ].map(function (addr) { return addr.toLowerCase(); }),
161
+ };
162
+ var basePoolAddressDecimalsDictEthereum = {
163
+ "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7": [18, 6, 6],
164
+ "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714": [8, 8, 18],
165
+ "0x93054188d876f558f4a66B2EF1d97d16eDf0895B": [8, 8], // ren
166
+ };
167
+ var basePoolAddressDecimalsDictPolygon = {
168
+ "0x445FE580eF8d70FF569aB36e80c647af338db351": [18, 6, 6],
169
+ "0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": [8, 8], // ren
170
+ };
171
+ var basePoolAddressZapDictEthereum = {
172
+ "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7": "0xA79828DF1850E8a3A3064576f380D90aECDD3359".toLowerCase(),
173
+ "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714": "0x7abdbaf29929e7f8621b757d2a7c04d78d633834".toLowerCase(),
174
+ "0x93054188d876f558f4a66B2EF1d97d16eDf0895B": "0x7abdbaf29929e7f8621b757d2a7c04d78d633834".toLowerCase(), // ren TODO CHECK!!!
175
+ };
176
+ var basePoolAddressZapDictPolygon = {
177
+ "0x445FE580eF8d70FF569aB36e80c647af338db351": "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase(),
178
+ "0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": "0xE2e6DC1708337A6e59f227921db08F21e3394723".toLowerCase(), // ren
179
+ };
180
+ var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
181
+ function getFactorySwapAddresses() {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factorySwapAddresses, swapAddresses;
184
+ return __generator(this, function (_e) {
185
+ switch (_e.label) {
186
+ case 0:
187
+ factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
188
+ factoryMulticallContract = this.contracts[this.constants.ALIASES.factory].multicallContract;
189
+ _a = Number;
190
+ _c = (_b = ethers_1.ethers.utils).formatUnits;
191
+ return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
192
+ case 1:
193
+ poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
194
+ calls = [];
195
+ for (i = 0; i < poolCount; i++) {
196
+ calls.push(factoryMulticallContract.pool_list(i));
197
+ }
198
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
199
+ case 2:
200
+ factorySwapAddresses = (_e.sent()).map(function (addr) { return addr.toLowerCase(); });
201
+ swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
202
+ return [2 /*return*/, factorySwapAddresses.filter(function (addr) { return !swapAddresses.includes(addr); })];
203
+ }
204
+ });
205
+ });
206
+ }
207
+ function getFactorySwapABIs(factorySwapAddresses) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ var implementationABIDict, factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, implementationAddresses;
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0:
213
+ implementationABIDict = this.chainId === 137 ? implementationABIDictPolygon : implementationABIDictEthereum;
214
+ return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
215
+ case 1:
216
+ factoryMulticallContract = _a.sent();
217
+ calls = [];
218
+ for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
219
+ addr = factorySwapAddresses_1[_i];
220
+ calls.push(factoryMulticallContract.get_implementation_address(addr));
221
+ }
222
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
223
+ case 2:
224
+ implementationAddresses = _a.sent();
225
+ return [2 /*return*/, implementationAddresses.map(function (addr) { return implementationABIDict[addr]; })];
226
+ }
227
+ });
228
+ });
229
+ }
230
+ function setFactorySwapContracts(factorySwapAddresses, factorySwapABIs) {
231
+ var _this = this;
232
+ factorySwapAddresses.forEach(function (addr, i) {
233
+ _this.contracts[addr] = {
234
+ contract: new ethers_1.Contract(addr, factorySwapABIs[i], _this.signer || _this.provider),
235
+ multicallContract: new ethcall_1.Contract(addr, factorySwapABIs[i]),
236
+ };
237
+ });
238
+ }
239
+ function getFactoryGaugeAddresses(factorySwapAddresses) {
240
+ return __awaiter(this, void 0, void 0, function () {
241
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_2, addr;
242
+ return __generator(this, function (_a) {
243
+ switch (_a.label) {
244
+ case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
245
+ case 1:
246
+ factoryMulticallContract = _a.sent();
247
+ calls = [];
248
+ for (_i = 0, factorySwapAddresses_2 = factorySwapAddresses; _i < factorySwapAddresses_2.length; _i++) {
249
+ addr = factorySwapAddresses_2[_i];
250
+ calls.push(factoryMulticallContract.get_gauge(addr));
251
+ }
252
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
253
+ case 2: return [2 /*return*/, (_a.sent()).map(function (addr) { return addr.toLowerCase(); })];
254
+ }
255
+ });
256
+ });
257
+ }
258
+ function setFactoryGaugeContracts(factoryGaugeAddresses) {
259
+ var _this = this;
260
+ factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
261
+ _this.contracts[addr] = {
262
+ contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
263
+ multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
264
+ };
265
+ });
266
+ }
267
+ function getFactoryPoolNames(factorySwapAddresses) {
268
+ return __awaiter(this, void 0, void 0, function () {
269
+ var calls, _i, factorySwapAddresses_3, addr, names, existingNames, i, n;
270
+ return __generator(this, function (_a) {
271
+ switch (_a.label) {
272
+ case 0:
273
+ calls = [];
274
+ for (_i = 0, factorySwapAddresses_3 = factorySwapAddresses; _i < factorySwapAddresses_3.length; _i++) {
275
+ addr = factorySwapAddresses_3[_i];
276
+ calls.push(this.contracts[addr].multicallContract.symbol());
277
+ }
278
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
279
+ case 1:
280
+ names = _a.sent();
281
+ existingNames = Object.keys(this.constants.POOLS_DATA);
282
+ // rename duplications
283
+ for (i = 0; i < names.length; i++) {
284
+ if (names.indexOf(names[i]) !== i || existingNames.includes(names[i])) {
285
+ n = 1;
286
+ do {
287
+ n++;
288
+ } while (names.indexOf(names[i].slice(0, -2) + "-".concat(n) + "-f") !== -1 || existingNames.includes(names[i].slice(0, -2) + "-".concat(n) + "-f"));
289
+ names[i] = names[i].slice(0, -2) + "-".concat(n) + "-f";
290
+ }
291
+ }
292
+ return [2 /*return*/, names];
293
+ }
294
+ });
295
+ });
296
+ }
297
+ function getFactoryReferenceAssets(factorySwapAddresses) {
298
+ return __awaiter(this, void 0, void 0, function () {
299
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_4, addr;
300
+ return __generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
303
+ case 1:
304
+ factoryMulticallContract = _a.sent();
305
+ calls = [];
306
+ for (_i = 0, factorySwapAddresses_4 = factorySwapAddresses; _i < factorySwapAddresses_4.length; _i++) {
307
+ addr = factorySwapAddresses_4[_i];
308
+ calls.push(factoryMulticallContract.get_pool_asset_type(addr));
309
+ }
310
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
311
+ case 2: return [2 /*return*/, (_a.sent()).map(function (t) {
312
+ return {
313
+ 0: "USD",
314
+ 1: "ETH",
315
+ 2: "BTC",
316
+ }[ethers_1.ethers.utils.formatUnits(t, 0)] || "OTHER";
317
+ })];
318
+ }
319
+ });
320
+ });
321
+ }
322
+ function getFactoryCoinAddresses(factorySwapAddresses) {
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_5, addr;
325
+ return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
328
+ case 1:
329
+ factoryMulticallContract = _a.sent();
330
+ calls = [];
331
+ for (_i = 0, factorySwapAddresses_5 = factorySwapAddresses; _i < factorySwapAddresses_5.length; _i++) {
332
+ addr = factorySwapAddresses_5[_i];
333
+ calls.push(factoryMulticallContract.get_coins(addr));
334
+ }
335
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
336
+ case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses
337
+ .filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
338
+ .map(function (addr) { return addr.toLowerCase(); }); })];
339
+ }
340
+ });
341
+ });
342
+ }
343
+ function setFactoryCoinsContracts(coinAddresses) {
344
+ var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
345
+ for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
346
+ var addr = flattenedCoinAddresses_1[_i];
347
+ if (addr in this.contracts)
348
+ continue;
349
+ this.contracts[addr] = {
350
+ contract: new ethers_1.Contract(addr, ERC20_json_1.default, this.signer || this.provider),
351
+ multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
352
+ };
353
+ }
354
+ }
355
+ function getExistingCoinAddressNameDict() {
356
+ var dict = {};
357
+ var _loop_1 = function (poolData) {
358
+ poolData.coin_addresses.forEach(function (addr, i) {
359
+ if (!(addr.toLowerCase() in dict)) {
360
+ dict[addr.toLowerCase()] = poolData.coins[i];
361
+ }
362
+ });
363
+ poolData.underlying_coin_addresses.forEach(function (addr, i) {
364
+ if (!(addr.toLowerCase() in dict)) {
365
+ dict[addr.toLowerCase()] = poolData.underlying_coins[i];
366
+ }
367
+ });
368
+ };
369
+ for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
370
+ var poolData = _a[_i];
371
+ _loop_1(poolData);
372
+ }
373
+ if (this.chainId === 137)
374
+ dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "MATIC";
375
+ return dict;
376
+ }
377
+ function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
378
+ return __awaiter(this, void 0, void 0, function () {
379
+ var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, _i, flattenedCoinAddresses_2, addr, calls, names;
380
+ var _this = this;
381
+ return __generator(this, function (_a) {
382
+ switch (_a.label) {
383
+ case 0:
384
+ flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
385
+ newCoinAddresses = [];
386
+ coinAddrNamesDict = {};
387
+ for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
388
+ addr = flattenedCoinAddresses_2[_i];
389
+ if (addr in existingCoinAddrNameDict) {
390
+ coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
391
+ }
392
+ else {
393
+ newCoinAddresses.push(addr);
394
+ }
395
+ }
396
+ calls = newCoinAddresses.map(function (addr) {
397
+ return _this.contracts[addr].multicallContract.symbol();
398
+ });
399
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
400
+ case 1:
401
+ names = _a.sent();
402
+ newCoinAddresses.forEach(function (addr, i) {
403
+ coinAddrNamesDict[addr] = names[i];
404
+ });
405
+ return [2 /*return*/, coinAddrNamesDict];
406
+ }
407
+ });
408
+ });
409
+ }
410
+ function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDict) {
411
+ return __awaiter(this, void 0, void 0, function () {
412
+ var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, _i, flattenedCoinAddresses_3, addr, calls, decimals;
413
+ var _this = this;
414
+ return __generator(this, function (_a) {
415
+ switch (_a.label) {
416
+ case 0:
417
+ flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
418
+ newCoinAddresses = [];
419
+ coinAddrNamesDict = {};
420
+ for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
421
+ addr = flattenedCoinAddresses_3[_i];
422
+ if (addr in existingCoinAddressDecimalsDict) {
423
+ coinAddrNamesDict[addr] = existingCoinAddressDecimalsDict[addr];
424
+ }
425
+ else {
426
+ newCoinAddresses.push(addr);
427
+ }
428
+ }
429
+ calls = newCoinAddresses.map(function (addr) {
430
+ return _this.contracts[addr].multicallContract.decimals();
431
+ });
432
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
433
+ case 1:
434
+ decimals = (_a.sent()).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
435
+ newCoinAddresses.forEach(function (addr, i) {
436
+ coinAddrNamesDict[addr] = decimals[i];
437
+ existingCoinAddressDecimalsDict[addr] = decimals[i]; // Add to DECIMALS_LOWER_CASE TODO move to another place
438
+ });
439
+ return [2 /*return*/, coinAddrNamesDict];
440
+ }
441
+ });
442
+ });
443
+ }
444
+ function getFactoryIsMeta(factorySwapAddresses) {
445
+ return __awaiter(this, void 0, void 0, function () {
446
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_6, addr;
447
+ return __generator(this, function (_a) {
448
+ switch (_a.label) {
449
+ case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
450
+ case 1:
451
+ factoryMulticallContract = _a.sent();
452
+ calls = [];
453
+ for (_i = 0, factorySwapAddresses_6 = factorySwapAddresses; _i < factorySwapAddresses_6.length; _i++) {
454
+ addr = factorySwapAddresses_6[_i];
455
+ calls.push(factoryMulticallContract.is_meta(addr));
456
+ }
457
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
458
+ case 2: return [2 /*return*/, _a.sent()];
459
+ }
460
+ });
461
+ });
462
+ }
463
+ function getFactoryBasePoolAddresses(factorySwapAddresses) {
464
+ return __awaiter(this, void 0, void 0, function () {
465
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_7, addr;
466
+ return __generator(this, function (_a) {
467
+ switch (_a.label) {
468
+ case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.factory].multicallContract];
469
+ case 1:
470
+ factoryMulticallContract = _a.sent();
471
+ calls = [];
472
+ for (_i = 0, factorySwapAddresses_7 = factorySwapAddresses; _i < factorySwapAddresses_7.length; _i++) {
473
+ addr = factorySwapAddresses_7[_i];
474
+ calls.push(factoryMulticallContract.get_base_pool(addr));
475
+ }
476
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
477
+ case 2: return [2 /*return*/, _a.sent()];
478
+ }
479
+ });
480
+ });
481
+ }
482
+ function setFactoryZapContracts() {
483
+ if (this.chainId === 137) {
484
+ var metaUsdZapAddress = "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase();
485
+ this.contracts[metaUsdZapAddress] = {
486
+ contract: new ethers_1.Contract(metaUsdZapAddress, DepositZapMetaUsdPolygon_json_1.default, this.signer || this.provider),
487
+ multicallContract: new ethcall_1.Contract(metaUsdZapAddress, DepositZapMetaUsdPolygon_json_1.default),
488
+ };
489
+ var metaBtcZapAddress = "0xE2e6DC1708337A6e59f227921db08F21e3394723".toLowerCase();
490
+ this.contracts[metaBtcZapAddress] = {
491
+ contract: new ethers_1.Contract(metaBtcZapAddress, DepositZapMetaBtcPolygon_json_1.default, this.signer || this.provider),
492
+ multicallContract: new ethcall_1.Contract(metaBtcZapAddress, DepositZapMetaBtcPolygon_json_1.default),
493
+ };
494
+ }
495
+ else {
496
+ var metaSBtcZapAddress = "0x7abdbaf29929e7f8621b757d2a7c04d78d633834".toLowerCase();
497
+ this.contracts[metaSBtcZapAddress] = {
498
+ contract: new ethers_1.Contract(metaSBtcZapAddress, deposit_json_1.default, this.signer || this.provider),
499
+ multicallContract: new ethcall_1.Contract(metaSBtcZapAddress, deposit_json_1.default),
500
+ };
501
+ }
502
+ }
503
+ function getFactoryPoolData() {
504
+ return __awaiter(this, void 0, void 0, function () {
505
+ var swapAddresses, swapABIs, gaugeAddresses, poolNames, referenceAssets, coinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, isMeta, basePoolAddresses, basePoolAddressCoinsDict, basePoolAddressNameDict, basePoolAddressCoinAddressesDict, basePoolAddressDecimalsDict, basePoolAddressZapDict, FACTORY_POOLS_DATA, i;
506
+ var _a, _b;
507
+ return __generator(this, function (_c) {
508
+ switch (_c.label) {
509
+ case 0: return [4 /*yield*/, getFactorySwapAddresses.call(this)];
510
+ case 1:
511
+ swapAddresses = _c.sent();
512
+ return [4 /*yield*/, getFactorySwapABIs.call(this, swapAddresses)];
513
+ case 2:
514
+ swapABIs = _c.sent();
515
+ setFactorySwapContracts.call(this, swapAddresses, swapABIs);
516
+ (_a = this.constants.LP_TOKENS).push.apply(_a, swapAddresses); // TODO move to another place
517
+ return [4 /*yield*/, getFactoryGaugeAddresses.call(this, swapAddresses)];
518
+ case 3:
519
+ gaugeAddresses = _c.sent();
520
+ setFactoryGaugeContracts.call(this, gaugeAddresses);
521
+ (_b = this.constants.GAUGES).push.apply(_b, gaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })); // TODO move to another place
522
+ return [4 /*yield*/, getFactoryPoolNames.call(this, swapAddresses)];
523
+ case 4:
524
+ poolNames = _c.sent();
525
+ return [4 /*yield*/, getFactoryReferenceAssets.call(this, swapAddresses)];
526
+ case 5:
527
+ referenceAssets = _c.sent();
528
+ return [4 /*yield*/, getFactoryCoinAddresses.call(this, swapAddresses)];
529
+ case 6:
530
+ coinAddresses = _c.sent();
531
+ setFactoryCoinsContracts.call(this, coinAddresses);
532
+ existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
533
+ return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
534
+ case 7:
535
+ coinAddressNameDict = _c.sent();
536
+ return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
537
+ case 8:
538
+ coinAddressDecimalsDict = _c.sent();
539
+ return [4 /*yield*/, getFactoryIsMeta.call(this, swapAddresses)];
540
+ case 9:
541
+ isMeta = _c.sent();
542
+ return [4 /*yield*/, getFactoryBasePoolAddresses.call(this, swapAddresses)];
543
+ case 10:
544
+ basePoolAddresses = _c.sent();
545
+ setFactoryZapContracts.call(this);
546
+ basePoolAddressCoinsDict = this.chainId === 137 ? basePoolAddressCoinsDictPolygon : basePoolAddressCoinsDictEthereum;
547
+ basePoolAddressNameDict = this.chainId === 137 ? basePoolAddressNameDictPolygon : basePoolAddressNameDictEthereum;
548
+ basePoolAddressCoinAddressesDict = this.chainId === 137 ? basePoolAddressCoinAddressesDictPolygon : basePoolAddressCoinAddressesDictEthereum;
549
+ basePoolAddressDecimalsDict = this.chainId === 137 ? basePoolAddressDecimalsDictPolygon : basePoolAddressDecimalsDictEthereum;
550
+ basePoolAddressZapDict = this.chainId === 137 ? basePoolAddressZapDictPolygon : basePoolAddressZapDictEthereum;
551
+ FACTORY_POOLS_DATA = {};
552
+ for (i = 0; i < poolNames.length; i++) {
553
+ if (!isMeta[i]) {
554
+ FACTORY_POOLS_DATA[poolNames[i]] = {
555
+ reference_asset: referenceAssets[i],
556
+ N_COINS: coinAddresses[i].length,
557
+ underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
558
+ decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
559
+ use_lending: coinAddresses[i].map(function () { return false; }),
560
+ is_plain: coinAddresses[i].map(function () { return true; }),
561
+ swap_address: swapAddresses[i],
562
+ token_address: swapAddresses[i],
563
+ gauge_address: gaugeAddresses[i],
564
+ underlying_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
565
+ coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
566
+ underlying_coin_addresses: coinAddresses[i],
567
+ coin_addresses: coinAddresses[i],
568
+ swap_abi: swapABIs[i],
569
+ gauge_abi: gauge_factory_json_1.default,
570
+ is_factory: true,
571
+ is_plain_factory: true,
572
+ };
573
+ }
574
+ else {
575
+ FACTORY_POOLS_DATA[poolNames[i]] = {
576
+ reference_asset: referenceAssets[i],
577
+ N_COINS: coinAddresses[i].length,
578
+ underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
579
+ decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
580
+ use_lending: coinAddresses[i].map(function () { return false; }),
581
+ is_plain: coinAddresses[i].map(function () { return true; }),
582
+ swap_address: swapAddresses[i],
583
+ token_address: swapAddresses[i],
584
+ gauge_address: gaugeAddresses[i],
585
+ underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolAddressCoinsDict[basePoolAddresses[i]], true),
586
+ coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
587
+ underlying_coin_addresses: coinAddresses[i],
588
+ coin_addresses: coinAddresses[i],
589
+ swap_abi: swapABIs[i],
590
+ gauge_abi: gauge_factory_json_1.default,
591
+ is_factory: true,
592
+ is_meta_factory: true,
593
+ is_meta: true,
594
+ base_pool: basePoolAddressNameDict[basePoolAddresses[i]],
595
+ meta_coin_addresses: basePoolAddressCoinAddressesDict[basePoolAddresses[i]],
596
+ meta_coin_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolAddressDecimalsDict[basePoolAddresses[i]], true),
597
+ deposit_address: basePoolAddressZapDict[basePoolAddresses[i]],
598
+ deposit_abi: deposit_json_1.default,
599
+ };
600
+ }
601
+ }
602
+ return [2 /*return*/, FACTORY_POOLS_DATA];
603
+ }
604
+ });
605
+ });
606
+ }
607
+ exports.getFactoryPoolData = getFactoryPoolData;
package/lib/index.d.ts CHANGED
@@ -15,6 +15,8 @@ declare function init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', p
15
15
  maxPriorityFeePerGas?: number;
16
16
  chainId?: number;
17
17
  }): Promise<void>;
18
+ declare function fetchFactoryPools(): Promise<void>;
19
+ declare function fetchCryptoFactoryPools(): Promise<void>;
18
20
  declare function setCustomFeeData(customFeeData: {
19
21
  gasPrice?: number;
20
22
  maxFeePerGas?: number;
@@ -22,7 +24,11 @@ declare function setCustomFeeData(customFeeData: {
22
24
  }): void;
23
25
  declare const curve: {
24
26
  init: typeof init;
27
+ fetchFactoryPools: typeof fetchFactoryPools;
28
+ fetchCryptoFactoryPools: typeof fetchCryptoFactoryPools;
25
29
  getPoolList: () => string[];
30
+ getFactoryPoolList: () => string[];
31
+ getCryptoFactoryPoolList: () => string[];
26
32
  getUsdRate: (coin: string) => Promise<number>;
27
33
  setCustomFeeData: typeof setCustomFeeData;
28
34
  signerAddress: string;
@@ -33,6 +39,7 @@ declare const curve: {
33
39
  hasAllowance: (coins: string[], amounts: string[], address: string, spender: string) => Promise<boolean>;
34
40
  ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
35
41
  getBestPoolAndOutput: (inputCoin: string, outputCoin: string, amount: string) => Promise<{
42
+ poolName: string;
36
43
  poolAddress: string;
37
44
  output: string;
38
45
  }>;