@curvefi/api 1.18.0 → 1.19.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.
- 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/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 +3 -3
- package/lib/index.d.ts +3 -0
- package/lib/index.js +14 -0
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools.d.ts +1 -0
- package/lib/pools.js +56 -19
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +3 -1
- package/package.json +1 -1
package/lib/curve.js
CHANGED
|
@@ -63,6 +63,7 @@ exports.curve = exports.ALIASES = exports.DECIMALS_LOWER_CASE = exports.DECIMALS
|
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var ethcall_1 = require("ethcall");
|
|
65
65
|
var factory_1 = require("./factory");
|
|
66
|
+
var factory_crypto_1 = require("./factory-crypto");
|
|
66
67
|
var ERC20_json_1 = __importDefault(require("./constants/abis/json/ERC20.json"));
|
|
67
68
|
var cERC20_json_1 = __importDefault(require("./constants/abis/json/cERC20.json"));
|
|
68
69
|
var yERC20_json_1 = __importDefault(require("./constants/abis/json/yERC20.json"));
|
|
@@ -75,6 +76,7 @@ var deposit_and_stake_json_1 = __importDefault(require("./constants/abis/json/de
|
|
|
75
76
|
var registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
|
|
76
77
|
var streamer_json_1 = __importDefault(require("./constants/abis/json/streamer.json"));
|
|
77
78
|
var factory_json_1 = __importDefault(require("./constants/abis/json/factory.json"));
|
|
79
|
+
var factory_crypto_json_1 = __importDefault(require("./constants/abis/json/factory-crypto.json"));
|
|
78
80
|
var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
|
|
79
81
|
var abis_polygon_1 = require("./constants/abis/abis-polygon");
|
|
80
82
|
var coins_ethereum_1 = require("./constants/coins-ethereum");
|
|
@@ -89,6 +91,7 @@ exports.ALIASES = {
|
|
|
89
91
|
"router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
|
|
90
92
|
"deposit_and_stake": "0x271fbE8aB7f1fB262f81C77Ea5303F03DA9d3d6A",
|
|
91
93
|
"factory": '0xb9fc157394af804a3578134a6585c0dc9cc990d4',
|
|
94
|
+
"crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99',
|
|
92
95
|
"registry_exchange": "",
|
|
93
96
|
};
|
|
94
97
|
var Curve = /** @class */ (function () {
|
|
@@ -421,6 +424,21 @@ var Curve = /** @class */ (function () {
|
|
|
421
424
|
contract: new ethers_1.Contract(exports.ALIASES.factory, factory_json_1.default, this.signer || this.provider),
|
|
422
425
|
multicallContract: new ethcall_1.Contract(exports.ALIASES.factory, factory_json_1.default),
|
|
423
426
|
};
|
|
427
|
+
this.contracts[exports.ALIASES.crypto_factory] = {
|
|
428
|
+
contract: new ethers_1.Contract(exports.ALIASES.crypto_factory, factory_crypto_json_1.default, this.signer || this.provider),
|
|
429
|
+
multicallContract: new ethcall_1.Contract(exports.ALIASES.crypto_factory, factory_crypto_json_1.default),
|
|
430
|
+
};
|
|
431
|
+
this.contracts[exports.ALIASES.crypto_factory.toLowerCase()] = {
|
|
432
|
+
contract: new ethers_1.Contract(exports.ALIASES.crypto_factory, factory_crypto_json_1.default, this.signer || this.provider),
|
|
433
|
+
multicallContract: new ethcall_1.Contract(exports.ALIASES.crypto_factory, factory_crypto_json_1.default),
|
|
434
|
+
};
|
|
435
|
+
this.constants = {
|
|
436
|
+
ALIASES: exports.ALIASES,
|
|
437
|
+
POOLS_DATA: exports.POOLS_DATA,
|
|
438
|
+
DECIMALS_LOWER_CASE: exports.DECIMALS_LOWER_CASE,
|
|
439
|
+
LP_TOKENS: exports.LP_TOKENS,
|
|
440
|
+
GAUGES: exports.GAUGES,
|
|
441
|
+
};
|
|
424
442
|
return [2 /*return*/];
|
|
425
443
|
}
|
|
426
444
|
});
|
|
@@ -432,13 +450,6 @@ var Curve = /** @class */ (function () {
|
|
|
432
450
|
return __generator(this, function (_b) {
|
|
433
451
|
switch (_b.label) {
|
|
434
452
|
case 0:
|
|
435
|
-
this.constants = {
|
|
436
|
-
ALIASES: exports.ALIASES,
|
|
437
|
-
POOLS_DATA: exports.POOLS_DATA,
|
|
438
|
-
DECIMALS_LOWER_CASE: exports.DECIMALS_LOWER_CASE,
|
|
439
|
-
LP_TOKENS: exports.LP_TOKENS,
|
|
440
|
-
GAUGES: exports.GAUGES,
|
|
441
|
-
};
|
|
442
453
|
_a = this.constants;
|
|
443
454
|
return [4 /*yield*/, factory_1.getFactoryPoolData.call(this)];
|
|
444
455
|
case 1:
|
|
@@ -448,6 +459,23 @@ var Curve = /** @class */ (function () {
|
|
|
448
459
|
});
|
|
449
460
|
});
|
|
450
461
|
};
|
|
462
|
+
Curve.prototype.fetchCryptoFactoryPools = function () {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
464
|
+
var _a;
|
|
465
|
+
return __generator(this, function (_b) {
|
|
466
|
+
switch (_b.label) {
|
|
467
|
+
case 0:
|
|
468
|
+
if (!(this.chainId === 1 || this.chainId === 1337)) return [3 /*break*/, 2];
|
|
469
|
+
_a = this.constants;
|
|
470
|
+
return [4 /*yield*/, factory_crypto_1.getCryptoFactoryPoolData.call(this)];
|
|
471
|
+
case 1:
|
|
472
|
+
_a.CRYPTO_FACTORY_POOLS_DATA = _b.sent();
|
|
473
|
+
_b.label = 2;
|
|
474
|
+
case 2: return [2 /*return*/];
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
};
|
|
451
479
|
Curve.prototype.setCustomFeeData = function (customFeeData) {
|
|
452
480
|
this.feeData = __assign(__assign({}, this.feeData), customFeeData);
|
|
453
481
|
};
|
|
@@ -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
|
@@ -277,7 +277,7 @@ function getFactoryPoolNames(factorySwapAddresses) {
|
|
|
277
277
|
}
|
|
278
278
|
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
279
279
|
case 1:
|
|
280
|
-
names =
|
|
280
|
+
names = _a.sent();
|
|
281
281
|
existingNames = Object.keys(this.constants.POOLS_DATA);
|
|
282
282
|
// rename duplications
|
|
283
283
|
for (i = 0; i < names.length; i++) {
|
|
@@ -285,8 +285,8 @@ function getFactoryPoolNames(factorySwapAddresses) {
|
|
|
285
285
|
n = 1;
|
|
286
286
|
do {
|
|
287
287
|
n++;
|
|
288
|
-
} while (names.indexOf(names[i] + "-".concat(n)) !== -1 || existingNames.includes(names[i] + "-".concat(n)));
|
|
289
|
-
names[i]
|
|
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
290
|
}
|
|
291
291
|
}
|
|
292
292
|
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;
|
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
package/lib/pools.d.ts
CHANGED