@curvefi/api 1.18.0 → 1.20.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.
- package/README.md +44 -24
- package/lib/constants/abis/json/factory-crypto/factory-crypto-pool-2.json +1112 -0
- package/lib/constants/abis/json/factory-crypto.json +635 -0
- package/lib/constants/abis/json/registry_exchange.json +207 -84
- package/lib/constants/aliases.d.ts +2 -0
- package/lib/constants/aliases.js +2 -0
- package/lib/curve.d.ts +2 -0
- package/lib/curve.js +35 -7
- package/lib/factory-crypto.d.ts +32 -0
- package/lib/factory-crypto.js +377 -0
- package/lib/factory.js +12 -5
- package/lib/index.d.ts +4 -0
- package/lib/index.js +14 -0
- package/lib/interfaces.d.ts +13 -0
- package/lib/pools.d.ts +2 -0
- package/lib/pools.js +211 -98
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Contract, ethers } from "ethers";
|
|
2
|
+
import { Contract as MulticallContract, Provider as MulticallProvider } from "ethcall";
|
|
3
|
+
import { DictInterface, PoolDataInterface } from "./interfaces";
|
|
4
|
+
interface CurveInterface {
|
|
5
|
+
provider: ethers.providers.Web3Provider | ethers.providers.JsonRpcProvider;
|
|
6
|
+
multicallProvider: MulticallProvider;
|
|
7
|
+
signer: ethers.Signer;
|
|
8
|
+
signerAddress: string;
|
|
9
|
+
chainId: number;
|
|
10
|
+
contracts: {
|
|
11
|
+
[index: string]: {
|
|
12
|
+
contract: Contract;
|
|
13
|
+
multicallContract: MulticallContract;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
feeData: {
|
|
17
|
+
gasPrice?: number;
|
|
18
|
+
maxFeePerGas?: number;
|
|
19
|
+
maxPriorityFeePerGas?: number;
|
|
20
|
+
};
|
|
21
|
+
constantOptions: {
|
|
22
|
+
gasLimit: number;
|
|
23
|
+
};
|
|
24
|
+
options: {
|
|
25
|
+
gasPrice?: number | ethers.BigNumber;
|
|
26
|
+
maxFeePerGas?: number | ethers.BigNumber;
|
|
27
|
+
maxPriorityFeePerGas?: number | ethers.BigNumber;
|
|
28
|
+
};
|
|
29
|
+
constants: DictInterface<any>;
|
|
30
|
+
}
|
|
31
|
+
export declare function getCryptoFactoryPoolData(this: CurveInterface): Promise<DictInterface<PoolDataInterface>>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,377 @@
|
|
|
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 (_) 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.getCryptoFactoryPoolData = void 0;
|
|
54
|
+
var ethers_1 = require("ethers");
|
|
55
|
+
var ethcall_1 = require("ethcall");
|
|
56
|
+
var ERC20_json_1 = __importDefault(require("./constants/abis/json/ERC20.json"));
|
|
57
|
+
var factory_crypto_pool_2_json_1 = __importDefault(require("./constants/abis/json/factory-crypto/factory-crypto-pool-2.json"));
|
|
58
|
+
var gauge_factory_json_1 = __importDefault(require("./constants/abis/json/gauge_factory.json"));
|
|
59
|
+
var WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
60
|
+
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
61
|
+
function getCryptoFactorySwapAddresses() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factorySwapAddresses, swapAddresses;
|
|
64
|
+
return __generator(this, function (_e) {
|
|
65
|
+
switch (_e.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
68
|
+
factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
|
|
69
|
+
_a = Number;
|
|
70
|
+
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
71
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
72
|
+
case 1:
|
|
73
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
74
|
+
calls = [];
|
|
75
|
+
for (i = 0; i < poolCount; i++) {
|
|
76
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
77
|
+
}
|
|
78
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
79
|
+
case 2:
|
|
80
|
+
factorySwapAddresses = (_e.sent()).map(function (addr) { return addr.toLowerCase(); });
|
|
81
|
+
swapAddresses = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.FACTORY_POOLS_DATA))
|
|
82
|
+
.map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
83
|
+
return [2 /*return*/, factorySwapAddresses.filter(function (addr) { return !swapAddresses.includes(addr); })];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function setCryptoFactorySwapContracts(factorySwapAddresses) {
|
|
89
|
+
var _this = this;
|
|
90
|
+
factorySwapAddresses.forEach(function (addr) {
|
|
91
|
+
_this.contracts[addr] = {
|
|
92
|
+
contract: new ethers_1.Contract(addr, factory_crypto_pool_2_json_1.default, _this.signer || _this.provider),
|
|
93
|
+
multicallContract: new ethcall_1.Contract(addr, factory_crypto_pool_2_json_1.default),
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function getCryptoFactoryTokenAddresses(factorySwapAddresses) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].multicallContract];
|
|
103
|
+
case 1:
|
|
104
|
+
factoryMulticallContract = _a.sent();
|
|
105
|
+
calls = [];
|
|
106
|
+
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
107
|
+
addr = factorySwapAddresses_1[_i];
|
|
108
|
+
calls.push(factoryMulticallContract.get_token(addr));
|
|
109
|
+
}
|
|
110
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
111
|
+
case 2: return [2 /*return*/, (_a.sent()).map(function (addr) { return addr.toLowerCase(); })];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
117
|
+
var _this = this;
|
|
118
|
+
factoryTokenAddresses.forEach(function (addr) {
|
|
119
|
+
_this.contracts[addr] = {
|
|
120
|
+
contract: new ethers_1.Contract(addr, ERC20_json_1.default, _this.signer || _this.provider),
|
|
121
|
+
multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function getCryptoFactoryGaugeAddresses(factorySwapAddresses) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_2, addr;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].multicallContract];
|
|
131
|
+
case 1:
|
|
132
|
+
factoryMulticallContract = _a.sent();
|
|
133
|
+
calls = [];
|
|
134
|
+
for (_i = 0, factorySwapAddresses_2 = factorySwapAddresses; _i < factorySwapAddresses_2.length; _i++) {
|
|
135
|
+
addr = factorySwapAddresses_2[_i];
|
|
136
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
137
|
+
}
|
|
138
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
139
|
+
case 2: return [2 /*return*/, (_a.sent()).map(function (addr) { return addr.toLowerCase(); })];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
145
|
+
var _this = this;
|
|
146
|
+
factoryGaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; }).forEach(function (addr, i) {
|
|
147
|
+
_this.contracts[addr] = {
|
|
148
|
+
contract: new ethers_1.Contract(addr, gauge_factory_json_1.default, _this.signer || _this.provider),
|
|
149
|
+
multicallContract: new ethcall_1.Contract(addr, gauge_factory_json_1.default),
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function getCryptoFactoryPoolNames(factoryTokenAddresses) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var calls, _i, factoryTokenAddresses_1, addr, names, existingNames, i, n;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
calls = [];
|
|
160
|
+
for (_i = 0, factoryTokenAddresses_1 = factoryTokenAddresses; _i < factoryTokenAddresses_1.length; _i++) {
|
|
161
|
+
addr = factoryTokenAddresses_1[_i];
|
|
162
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
163
|
+
}
|
|
164
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
165
|
+
case 1:
|
|
166
|
+
names = (_a.sent()).map(function (name) { return name + "V2"; });
|
|
167
|
+
existingNames = Object.keys(this.constants.POOLS_DATA);
|
|
168
|
+
// rename duplications
|
|
169
|
+
for (i = 0; i < names.length; i++) {
|
|
170
|
+
if (names.indexOf(names[i]) !== i || existingNames.includes(names[i])) {
|
|
171
|
+
n = 1;
|
|
172
|
+
do {
|
|
173
|
+
n++;
|
|
174
|
+
} while (names.indexOf(names[i].slice(0, -4) + "-".concat(n) + "-fV2") !== -1 || existingNames.includes(names[i].slice(0, -4) + "-".concat(n) + "-fV2"));
|
|
175
|
+
names[i] = names[i].slice(0, -4) + "-".concat(n) + "-fV2";
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return [2 /*return*/, names];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function getCryptoFactoryCoinAddresses(factorySwapAddresses) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_3, addr;
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0: return [4 /*yield*/, this.contracts[this.constants.ALIASES.crypto_factory].multicallContract];
|
|
189
|
+
case 1:
|
|
190
|
+
factoryMulticallContract = _a.sent();
|
|
191
|
+
calls = [];
|
|
192
|
+
for (_i = 0, factorySwapAddresses_3 = factorySwapAddresses; _i < factorySwapAddresses_3.length; _i++) {
|
|
193
|
+
addr = factorySwapAddresses_3[_i];
|
|
194
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
195
|
+
}
|
|
196
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
197
|
+
case 2: return [2 /*return*/, (_a.sent()).map(function (addresses) { return addresses.map(function (addr) { return addr.toLowerCase(); }); })];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
203
|
+
var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
204
|
+
for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
|
|
205
|
+
var addr = flattenedCoinAddresses_1[_i];
|
|
206
|
+
if (addr in this.contracts)
|
|
207
|
+
continue;
|
|
208
|
+
this.contracts[addr] = {
|
|
209
|
+
contract: new ethers_1.Contract(addr, ERC20_json_1.default, this.signer || this.provider),
|
|
210
|
+
multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
return [2 /*return*/, coinAddresses.map(function (coins) { return coins.map(function (c) { return c === WETH_ADDRESS ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : c; }); })];
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
function getExistingCoinAddressNameDict() {
|
|
222
|
+
var dict = {};
|
|
223
|
+
var _loop_1 = function (poolData) {
|
|
224
|
+
poolData.coin_addresses.forEach(function (addr, i) {
|
|
225
|
+
if (!(addr.toLowerCase() in dict)) {
|
|
226
|
+
dict[addr.toLowerCase()] = poolData.coins[i];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
poolData.underlying_coin_addresses.forEach(function (addr, i) {
|
|
230
|
+
if (!(addr.toLowerCase() in dict)) {
|
|
231
|
+
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
236
|
+
var poolData = _a[_i];
|
|
237
|
+
_loop_1(poolData);
|
|
238
|
+
}
|
|
239
|
+
if (this.chainId === 137)
|
|
240
|
+
dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "MATIC";
|
|
241
|
+
return dict;
|
|
242
|
+
}
|
|
243
|
+
function getCoinAddressNameDict(coinAddresses, existingCoinAddrNameDict) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, _i, flattenedCoinAddresses_2, addr, calls, names;
|
|
246
|
+
var _this = this;
|
|
247
|
+
return __generator(this, function (_a) {
|
|
248
|
+
switch (_a.label) {
|
|
249
|
+
case 0:
|
|
250
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
251
|
+
newCoinAddresses = [];
|
|
252
|
+
coinAddrNamesDict = {};
|
|
253
|
+
for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
|
|
254
|
+
addr = flattenedCoinAddresses_2[_i];
|
|
255
|
+
if (addr in existingCoinAddrNameDict) {
|
|
256
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
newCoinAddresses.push(addr);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
calls = newCoinAddresses.map(function (addr) {
|
|
263
|
+
return _this.contracts[addr].multicallContract.symbol();
|
|
264
|
+
});
|
|
265
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
266
|
+
case 1:
|
|
267
|
+
names = _a.sent();
|
|
268
|
+
newCoinAddresses.forEach(function (addr, i) {
|
|
269
|
+
coinAddrNamesDict[addr] = names[i];
|
|
270
|
+
});
|
|
271
|
+
return [2 /*return*/, coinAddrNamesDict];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function getCoinAddressDecimalsDict(coinAddresses, existingCoinAddressDecimalsDict) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
278
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, _i, flattenedCoinAddresses_3, addr, calls, decimals;
|
|
279
|
+
var _this = this;
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
switch (_a.label) {
|
|
282
|
+
case 0:
|
|
283
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
284
|
+
newCoinAddresses = [];
|
|
285
|
+
coinAddrNamesDict = {};
|
|
286
|
+
for (_i = 0, flattenedCoinAddresses_3 = flattenedCoinAddresses; _i < flattenedCoinAddresses_3.length; _i++) {
|
|
287
|
+
addr = flattenedCoinAddresses_3[_i];
|
|
288
|
+
if (addr in existingCoinAddressDecimalsDict) {
|
|
289
|
+
coinAddrNamesDict[addr] = existingCoinAddressDecimalsDict[addr];
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
newCoinAddresses.push(addr);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
calls = newCoinAddresses.map(function (addr) {
|
|
296
|
+
return _this.contracts[addr].multicallContract.decimals();
|
|
297
|
+
});
|
|
298
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
299
|
+
case 1:
|
|
300
|
+
decimals = (_a.sent()).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
|
|
301
|
+
newCoinAddresses.forEach(function (addr, i) {
|
|
302
|
+
coinAddrNamesDict[addr] = decimals[i];
|
|
303
|
+
existingCoinAddressDecimalsDict[addr] = decimals[i]; // Add to DECIMALS_LOWER_CASE TODO move to another place
|
|
304
|
+
});
|
|
305
|
+
return [2 /*return*/, coinAddrNamesDict];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function getCryptoFactoryPoolData() {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
312
|
+
var swapAddresses, tokenAddresses, gaugeAddresses, poolNames, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, coinAddressNameDict, coinAddressDecimalsDict, CRYPTO_FACTORY_POOLS_DATA, i;
|
|
313
|
+
var _a, _b;
|
|
314
|
+
return __generator(this, function (_c) {
|
|
315
|
+
switch (_c.label) {
|
|
316
|
+
case 0: return [4 /*yield*/, getCryptoFactorySwapAddresses.call(this)];
|
|
317
|
+
case 1:
|
|
318
|
+
swapAddresses = _c.sent();
|
|
319
|
+
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
320
|
+
return [4 /*yield*/, getCryptoFactoryTokenAddresses.call(this, swapAddresses)];
|
|
321
|
+
case 2:
|
|
322
|
+
tokenAddresses = _c.sent();
|
|
323
|
+
setCryptoFactoryTokenContracts.call(this, tokenAddresses);
|
|
324
|
+
(_a = this.constants.LP_TOKENS).push.apply(_a, tokenAddresses); // TODO move to another place
|
|
325
|
+
return [4 /*yield*/, getCryptoFactoryGaugeAddresses.call(this, swapAddresses)];
|
|
326
|
+
case 3:
|
|
327
|
+
gaugeAddresses = _c.sent();
|
|
328
|
+
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
329
|
+
(_b = this.constants.GAUGES).push.apply(_b, gaugeAddresses.filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })); // TODO move to another place
|
|
330
|
+
return [4 /*yield*/, getCryptoFactoryPoolNames.call(this, tokenAddresses)];
|
|
331
|
+
case 4:
|
|
332
|
+
poolNames = _c.sent();
|
|
333
|
+
return [4 /*yield*/, getCryptoFactoryCoinAddresses.call(this, swapAddresses)];
|
|
334
|
+
case 5:
|
|
335
|
+
coinAddresses = _c.sent();
|
|
336
|
+
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
337
|
+
return [4 /*yield*/, getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses)];
|
|
338
|
+
case 6:
|
|
339
|
+
underlyingCoinAddresses = _c.sent();
|
|
340
|
+
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
341
|
+
return [4 /*yield*/, getCoinAddressNameDict.call(this, coinAddresses, existingCoinAddressNameDict)];
|
|
342
|
+
case 7:
|
|
343
|
+
coinAddressNameDict = _c.sent();
|
|
344
|
+
coinAddressNameDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 'ETH';
|
|
345
|
+
return [4 /*yield*/, getCoinAddressDecimalsDict.call(this, coinAddresses, this.constants.DECIMALS_LOWER_CASE)];
|
|
346
|
+
case 8:
|
|
347
|
+
coinAddressDecimalsDict = _c.sent();
|
|
348
|
+
coinAddressDecimalsDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 18;
|
|
349
|
+
CRYPTO_FACTORY_POOLS_DATA = {};
|
|
350
|
+
for (i = 0; i < poolNames.length; i++) {
|
|
351
|
+
CRYPTO_FACTORY_POOLS_DATA[poolNames[i]] = {
|
|
352
|
+
reference_asset: "CRYPTO",
|
|
353
|
+
N_COINS: coinAddresses[i].length,
|
|
354
|
+
is_crypto: true,
|
|
355
|
+
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
356
|
+
decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
357
|
+
use_lending: coinAddresses[i].map(function () { return false; }),
|
|
358
|
+
is_plain: coinAddresses[i].map(function () { return true; }),
|
|
359
|
+
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
360
|
+
coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
361
|
+
swap_address: swapAddresses[i],
|
|
362
|
+
token_address: tokenAddresses[i],
|
|
363
|
+
gauge_address: gaugeAddresses[i],
|
|
364
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
365
|
+
coin_addresses: coinAddresses[i],
|
|
366
|
+
swap_abi: factory_crypto_pool_2_json_1.default[i],
|
|
367
|
+
gauge_abi: gauge_factory_json_1.default,
|
|
368
|
+
is_factory: true,
|
|
369
|
+
is_crypto_factory: true,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
exports.getCryptoFactoryPoolData = getCryptoFactoryPoolData;
|
package/lib/factory.js
CHANGED
|
@@ -177,10 +177,16 @@ var basePoolAddressZapDictPolygon = {
|
|
|
177
177
|
"0x445FE580eF8d70FF569aB36e80c647af338db351": "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase(),
|
|
178
178
|
"0xC2d95EEF97Ec6C17551d45e77B590dc1F9117C67": "0xE2e6DC1708337A6e59f227921db08F21e3394723".toLowerCase(), // ren
|
|
179
179
|
};
|
|
180
|
+
var blackListPolygon = [
|
|
181
|
+
"0x666dc3b4babfd063faf965bd020024af0dc51b64",
|
|
182
|
+
"0xe4199bc5c5c1f63dba47b56b6db7144c51cf0bf8",
|
|
183
|
+
"0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
|
|
184
|
+
];
|
|
185
|
+
var blackListEthereum = [];
|
|
180
186
|
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
181
187
|
function getFactorySwapAddresses() {
|
|
182
188
|
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factorySwapAddresses, swapAddresses;
|
|
189
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factorySwapAddresses, swapAddresses, blacklist;
|
|
184
190
|
return __generator(this, function (_e) {
|
|
185
191
|
switch (_e.label) {
|
|
186
192
|
case 0:
|
|
@@ -199,7 +205,8 @@ function getFactorySwapAddresses() {
|
|
|
199
205
|
case 2:
|
|
200
206
|
factorySwapAddresses = (_e.sent()).map(function (addr) { return addr.toLowerCase(); });
|
|
201
207
|
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
202
|
-
|
|
208
|
+
blacklist = this.chainId === 137 ? blackListPolygon : blackListEthereum;
|
|
209
|
+
return [2 /*return*/, factorySwapAddresses.filter(function (addr) { return !swapAddresses.includes(addr) && !blacklist.includes(addr); })];
|
|
203
210
|
}
|
|
204
211
|
});
|
|
205
212
|
});
|
|
@@ -277,7 +284,7 @@ function getFactoryPoolNames(factorySwapAddresses) {
|
|
|
277
284
|
}
|
|
278
285
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
279
286
|
case 1:
|
|
280
|
-
names =
|
|
287
|
+
names = _a.sent();
|
|
281
288
|
existingNames = Object.keys(this.constants.POOLS_DATA);
|
|
282
289
|
// rename duplications
|
|
283
290
|
for (i = 0; i < names.length; i++) {
|
|
@@ -285,8 +292,8 @@ function getFactoryPoolNames(factorySwapAddresses) {
|
|
|
285
292
|
n = 1;
|
|
286
293
|
do {
|
|
287
294
|
n++;
|
|
288
|
-
} while (names.indexOf(names[i] + "-".concat(n)) !== -1 || existingNames.includes(names[i] + "-".concat(n)));
|
|
289
|
-
names[i]
|
|
295
|
+
} while (names.indexOf(names[i].slice(0, -2) + "-".concat(n) + "-f") !== -1 || existingNames.includes(names[i].slice(0, -2) + "-".concat(n) + "-f"));
|
|
296
|
+
names[i] = names[i].slice(0, -2) + "-".concat(n) + "-f";
|
|
290
297
|
}
|
|
291
298
|
}
|
|
292
299
|
return [2 /*return*/, names];
|
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare function init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', p
|
|
|
16
16
|
chainId?: number;
|
|
17
17
|
}): Promise<void>;
|
|
18
18
|
declare function fetchFactoryPools(): Promise<void>;
|
|
19
|
+
declare function fetchCryptoFactoryPools(): Promise<void>;
|
|
19
20
|
declare function setCustomFeeData(customFeeData: {
|
|
20
21
|
gasPrice?: number;
|
|
21
22
|
maxFeePerGas?: number;
|
|
@@ -24,8 +25,10 @@ declare function setCustomFeeData(customFeeData: {
|
|
|
24
25
|
declare const curve: {
|
|
25
26
|
init: typeof init;
|
|
26
27
|
fetchFactoryPools: typeof fetchFactoryPools;
|
|
28
|
+
fetchCryptoFactoryPools: typeof fetchCryptoFactoryPools;
|
|
27
29
|
getPoolList: () => string[];
|
|
28
30
|
getFactoryPoolList: () => string[];
|
|
31
|
+
getCryptoFactoryPoolList: () => string[];
|
|
29
32
|
getUsdRate: (coin: string) => Promise<number>;
|
|
30
33
|
setCustomFeeData: typeof setCustomFeeData;
|
|
31
34
|
signerAddress: string;
|
|
@@ -36,6 +39,7 @@ declare const curve: {
|
|
|
36
39
|
hasAllowance: (coins: string[], amounts: string[], address: string, spender: string) => Promise<boolean>;
|
|
37
40
|
ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
|
|
38
41
|
getBestPoolAndOutput: (inputCoin: string, outputCoin: string, amount: string) => Promise<{
|
|
42
|
+
poolName: string;
|
|
39
43
|
poolAddress: string;
|
|
40
44
|
output: string;
|
|
41
45
|
}>;
|
package/lib/index.js
CHANGED
|
@@ -69,14 +69,28 @@ function fetchFactoryPools() {
|
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
function fetchCryptoFactoryPools() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, curve_1.curve.fetchCryptoFactoryPools()];
|
|
77
|
+
case 1:
|
|
78
|
+
_a.sent();
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
72
84
|
function setCustomFeeData(customFeeData) {
|
|
73
85
|
curve_1.curve.setCustomFeeData(customFeeData);
|
|
74
86
|
}
|
|
75
87
|
var curve = {
|
|
76
88
|
init: init,
|
|
77
89
|
fetchFactoryPools: fetchFactoryPools,
|
|
90
|
+
fetchCryptoFactoryPools: fetchCryptoFactoryPools,
|
|
78
91
|
getPoolList: utils_1.getPoolList,
|
|
79
92
|
getFactoryPoolList: utils_1.getFactoryPoolList,
|
|
93
|
+
getCryptoFactoryPoolList: utils_1.getCryptoFactoryPoolList,
|
|
80
94
|
getUsdRate: utils_1.getUsdRate,
|
|
81
95
|
setCustomFeeData: setCustomFeeData,
|
|
82
96
|
signerAddress: '',
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
1
2
|
export interface DictInterface<T> {
|
|
2
3
|
[index: string]: T;
|
|
3
4
|
}
|
|
@@ -40,6 +41,7 @@ export interface PoolDataInterface {
|
|
|
40
41
|
is_factory?: boolean;
|
|
41
42
|
is_plain_factory?: boolean;
|
|
42
43
|
is_meta_factory?: boolean;
|
|
44
|
+
is_crypto_factory?: boolean;
|
|
43
45
|
adapter_abi?: any;
|
|
44
46
|
old_adapter_address?: string;
|
|
45
47
|
adapter_biconomy_address?: string;
|
|
@@ -71,3 +73,14 @@ export interface IPoolStats {
|
|
|
71
73
|
export interface IStats {
|
|
72
74
|
[index: string]: IPoolStats;
|
|
73
75
|
}
|
|
76
|
+
export interface ISinglePoolSwapData {
|
|
77
|
+
poolName: string;
|
|
78
|
+
poolAddress: string;
|
|
79
|
+
i: number;
|
|
80
|
+
j: number;
|
|
81
|
+
swapType: 1 | 2 | 3 | 4;
|
|
82
|
+
swapAddress: string;
|
|
83
|
+
}
|
|
84
|
+
export interface ISinglePoolSwapDataAndOutput extends ISinglePoolSwapData {
|
|
85
|
+
_output: ethers.BigNumber;
|
|
86
|
+
}
|
package/lib/pools.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class Pool {
|
|
|
23
23
|
isFactory: boolean;
|
|
24
24
|
isMetaFactory: boolean;
|
|
25
25
|
isPlainFactory: boolean;
|
|
26
|
+
isCryptoFactory: boolean;
|
|
26
27
|
rewardTokens: string[];
|
|
27
28
|
estimateGas: {
|
|
28
29
|
addLiquidityApprove: (amounts: string[]) => Promise<number>;
|
|
@@ -221,6 +222,7 @@ export declare class Pool {
|
|
|
221
222
|
private _getExchangeOutputWrapped;
|
|
222
223
|
}
|
|
223
224
|
export declare const getBestPoolAndOutput: (inputCoin: string, outputCoin: string, amount: string) => Promise<{
|
|
225
|
+
poolName: string;
|
|
224
226
|
poolAddress: string;
|
|
225
227
|
output: string;
|
|
226
228
|
}>;
|