@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.
- package/README.md +57 -0
- package/lib/constants/abis/abis-ethereum.js +6 -6
- 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/factory-v2/DepositZapMetaBtcPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/DepositZapMetaUsdPolygon.json +197 -0
- package/lib/constants/abis/json/factory-v2/MetaBTC.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCBalancesRen.json +932 -0
- package/lib/constants/abis/json/factory-v2/MetaBTCRen.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSD.json +919 -0
- package/lib/constants/abis/json/factory-v2/MetaUSDBalances.json +932 -0
- package/lib/constants/abis/json/factory-v2/Plain2Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain2Optimized.json +844 -0
- package/lib/constants/abis/json/factory-v2/Plain3Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain3Optimized.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Balances.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Basic.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4ETH.json +845 -0
- package/lib/constants/abis/json/factory-v2/Plain4Optimized.json +845 -0
- package/lib/constants/abis/json/factory.json +1063 -0
- package/lib/constants/abis/json/registry_exchange.json +207 -84
- package/lib/constants/aliases.d.ts +4 -0
- package/lib/constants/aliases.js +4 -0
- package/lib/constants/coins-polygon.js +3 -2
- package/lib/curve.d.ts +5 -0
- package/lib/curve.js +62 -0
- package/lib/factory-crypto.d.ts +32 -0
- package/lib/factory-crypto.js +377 -0
- package/lib/factory.d.ts +32 -0
- package/lib/factory.js +607 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +28 -0
- package/lib/interfaces.d.ts +28 -1
- package/lib/pools.d.ts +5 -0
- package/lib/pools.js +359 -159
- package/lib/utils.d.ts +8 -1
- package/lib/utils.js +111 -8
- package/package.json +4 -2
package/lib/curve.js
CHANGED
|
@@ -62,6 +62,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
62
62
|
exports.curve = exports.ALIASES = exports.DECIMALS_LOWER_CASE = exports.DECIMALS = exports.COINS = exports.USD_COINS_LOWER_CASE = exports.USD_COINS = exports.EUR_COINS_LOWER_CASE = exports.EUR_COINS = exports.LINK_COINS_LOWER_CASE = exports.LINK_COINS = exports.ETH_COINS_LOWER_CASE = exports.ETH_COINS = exports.BTC_COINS_LOWER_CASE = exports.BTC_COINS = exports.GAUGES = exports.LP_TOKENS = exports.POOLS_DATA = void 0;
|
|
63
63
|
var ethers_1 = require("ethers");
|
|
64
64
|
var ethcall_1 = require("ethcall");
|
|
65
|
+
var factory_1 = require("./factory");
|
|
66
|
+
var factory_crypto_1 = require("./factory-crypto");
|
|
65
67
|
var ERC20_json_1 = __importDefault(require("./constants/abis/json/ERC20.json"));
|
|
66
68
|
var cERC20_json_1 = __importDefault(require("./constants/abis/json/cERC20.json"));
|
|
67
69
|
var yERC20_json_1 = __importDefault(require("./constants/abis/json/yERC20.json"));
|
|
@@ -73,6 +75,8 @@ var router_json_1 = __importDefault(require("./constants/abis/json/router.json")
|
|
|
73
75
|
var deposit_and_stake_json_1 = __importDefault(require("./constants/abis/json/deposit_and_stake.json"));
|
|
74
76
|
var registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
|
|
75
77
|
var streamer_json_1 = __importDefault(require("./constants/abis/json/streamer.json"));
|
|
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"));
|
|
76
80
|
var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
|
|
77
81
|
var abis_polygon_1 = require("./constants/abis/abis-polygon");
|
|
78
82
|
var coins_ethereum_1 = require("./constants/coins-ethereum");
|
|
@@ -86,6 +90,8 @@ exports.ALIASES = {
|
|
|
86
90
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
|
87
91
|
"router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
|
|
88
92
|
"deposit_and_stake": "0x271fbE8aB7f1fB262f81C77Ea5303F03DA9d3d6A",
|
|
93
|
+
"factory": '0xb9fc157394af804a3578134a6585c0dc9cc990d4',
|
|
94
|
+
"crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99',
|
|
89
95
|
"registry_exchange": "",
|
|
90
96
|
};
|
|
91
97
|
var Curve = /** @class */ (function () {
|
|
@@ -102,6 +108,7 @@ var Curve = /** @class */ (function () {
|
|
|
102
108
|
this.feeData = {};
|
|
103
109
|
this.constantOptions = { gasLimit: 12000000 };
|
|
104
110
|
this.options = {};
|
|
111
|
+
this.constants = {};
|
|
105
112
|
}
|
|
106
113
|
Curve.prototype.init = function (providerType, providerSettings, options // gasPrice in Gwei
|
|
107
114
|
) {
|
|
@@ -409,11 +416,66 @@ var Curve = /** @class */ (function () {
|
|
|
409
416
|
contract: new ethers_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default, this.signer || this.provider),
|
|
410
417
|
multicallContract: new ethcall_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default),
|
|
411
418
|
};
|
|
419
|
+
this.contracts[exports.ALIASES.factory] = {
|
|
420
|
+
contract: new ethers_1.Contract(exports.ALIASES.factory, factory_json_1.default, this.signer || this.provider),
|
|
421
|
+
multicallContract: new ethcall_1.Contract(exports.ALIASES.factory, factory_json_1.default),
|
|
422
|
+
};
|
|
423
|
+
this.contracts[exports.ALIASES.factory.toLowerCase()] = {
|
|
424
|
+
contract: new ethers_1.Contract(exports.ALIASES.factory, factory_json_1.default, this.signer || this.provider),
|
|
425
|
+
multicallContract: new ethcall_1.Contract(exports.ALIASES.factory, factory_json_1.default),
|
|
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
|
+
};
|
|
442
|
+
return [2 /*return*/];
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
Curve.prototype.fetchFactoryPools = function () {
|
|
448
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
449
|
+
var _a;
|
|
450
|
+
return __generator(this, function (_b) {
|
|
451
|
+
switch (_b.label) {
|
|
452
|
+
case 0:
|
|
453
|
+
_a = this.constants;
|
|
454
|
+
return [4 /*yield*/, factory_1.getFactoryPoolData.call(this)];
|
|
455
|
+
case 1:
|
|
456
|
+
_a.FACTORY_POOLS_DATA = _b.sent();
|
|
412
457
|
return [2 /*return*/];
|
|
413
458
|
}
|
|
414
459
|
});
|
|
415
460
|
});
|
|
416
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
|
+
};
|
|
417
479
|
Curve.prototype.setCustomFeeData = function (customFeeData) {
|
|
418
480
|
this.feeData = __assign(__assign({}, this.feeData), customFeeData);
|
|
419
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.d.ts
ADDED
|
@@ -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 getFactoryPoolData(this: CurveInterface): Promise<DictInterface<PoolDataInterface>>;
|
|
32
|
+
export {};
|