@curvefi/api 2.31.0 → 2.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/boosting.js +137 -402
- package/lib/constants/aliases.d.ts +11 -11
- package/lib/constants/aliases.js +12 -15
- package/lib/constants/coins/arbitrum.js +6 -9
- package/lib/constants/coins/aurora.js +6 -9
- package/lib/constants/coins/avalanche.js +7 -10
- package/lib/constants/coins/celo.js +6 -9
- package/lib/constants/coins/ethereum.js +10 -13
- package/lib/constants/coins/fantom.js +8 -11
- package/lib/constants/coins/kava.js +6 -9
- package/lib/constants/coins/moonbeam.js +6 -9
- package/lib/constants/coins/optimism.js +6 -9
- package/lib/constants/coins/polygon.js +7 -10
- package/lib/constants/coins/xdai.js +6 -9
- package/lib/constants/pools/arbitrum.d.ts +2 -4
- package/lib/constants/pools/arbitrum.js +22 -28
- package/lib/constants/pools/aurora.d.ts +2 -4
- package/lib/constants/pools/aurora.js +6 -12
- package/lib/constants/pools/avalanche.d.ts +2 -4
- package/lib/constants/pools/avalanche.js +21 -27
- package/lib/constants/pools/celo.d.ts +2 -4
- package/lib/constants/pools/celo.js +2 -5
- package/lib/constants/pools/ethereum.js +247 -253
- package/lib/constants/pools/fantom.d.ts +2 -4
- package/lib/constants/pools/fantom.js +28 -34
- package/lib/constants/pools/index.d.ts +11 -11
- package/lib/constants/pools/index.js +12 -25
- package/lib/constants/pools/kava.d.ts +2 -4
- package/lib/constants/pools/kava.js +2 -5
- package/lib/constants/pools/moonbeam.d.ts +2 -4
- package/lib/constants/pools/moonbeam.js +6 -12
- package/lib/constants/pools/optimism.d.ts +2 -4
- package/lib/constants/pools/optimism.js +9 -15
- package/lib/constants/pools/polygon.d.ts +2 -4
- package/lib/constants/pools/polygon.js +22 -28
- package/lib/constants/pools/xdai.d.ts +2 -4
- package/lib/constants/pools/xdai.js +24 -30
- package/lib/constants/utils.js +20 -29
- package/lib/curve.d.ts +9 -7
- package/lib/curve.js +397 -615
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +47 -140
- package/lib/factory/common.js +6 -10
- package/lib/factory/constants-crypto.js +48 -54
- package/lib/factory/constants.js +274 -280
- package/lib/factory/deploy.d.ts +8 -8
- package/lib/factory/deploy.js +177 -347
- package/lib/factory/factory-api.js +195 -278
- package/lib/factory/factory-crypto.js +170 -323
- package/lib/factory/factory.js +195 -350
- package/lib/index.d.ts +24 -25
- package/lib/index.js +87 -143
- package/lib/interfaces.d.ts +5 -5
- package/lib/interfaces.js +1 -2
- package/lib/pools/PoolTemplate.js +1516 -2929
- package/lib/pools/index.d.ts +2 -2
- package/lib/pools/index.js +3 -7
- package/lib/pools/mixins/common.d.ts +3 -4
- package/lib/pools/mixins/common.js +23 -112
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
- package/lib/pools/mixins/depositMixins.d.ts +1 -1
- package/lib/pools/mixins/depositMixins.js +144 -417
- package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/depositWrappedMixins.js +72 -227
- package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -1
- package/lib/pools/mixins/poolBalancesMixin.js +25 -105
- package/lib/pools/mixins/swapMixins.d.ts +1 -1
- package/lib/pools/mixins/swapMixins.js +127 -353
- package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/swapWrappedMixins.js +90 -276
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawExpectedMixins.js +26 -110
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
- package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawMixins.js +123 -390
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinMixins.js +124 -390
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
- package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
- package/lib/pools/poolConstructor.d.ts +1 -1
- package/lib/pools/poolConstructor.js +77 -101
- package/lib/pools/utils.js +298 -500
- package/lib/router.d.ts +2 -2
- package/lib/router.js +390 -653
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +377 -731
- package/package.json +8 -8
|
@@ -1,361 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
1
|
+
import { curve } from "../curve.js";
|
|
2
|
+
import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
3
|
+
import cryptoFactorySwapABI from "../constants/abis/factory-crypto/factory-crypto-pool-2.json" assert { type: 'json' };
|
|
4
|
+
import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
|
|
5
|
+
import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
|
|
6
|
+
import { setFactoryZapContracts } from "./common.js";
|
|
7
|
+
import { CRYPTO_FACTORY_CONSTANTS } from "./constants-crypto.js";
|
|
8
|
+
const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
|
|
9
|
+
async function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
10
|
+
const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
11
|
+
const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
|
|
12
|
+
for (let i = 1; i <= poolCount; i++) {
|
|
13
|
+
const address = await factoryContract.pool_list(poolCount - i);
|
|
14
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
15
|
+
return `factory-crypto-${poolCount - i}`;
|
|
55
16
|
}
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getCryptoFactoryPoolData = void 0;
|
|
63
|
-
var ethers_1 = require("ethers");
|
|
64
|
-
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
65
|
-
var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
|
|
66
|
-
var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
|
|
67
|
-
var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
|
|
68
|
-
var common_1 = require("./common");
|
|
69
|
-
var constants_crypto_1 = require("./constants-crypto");
|
|
70
|
-
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
71
|
-
function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
var factoryContract, poolCount, _a, _b, _c, i, address;
|
|
74
|
-
return __generator(this, function (_e) {
|
|
75
|
-
switch (_e.label) {
|
|
76
|
-
case 0:
|
|
77
|
-
factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
78
|
-
_a = Number;
|
|
79
|
-
_c = (_b = ethers_1.ethers.utils).formatUnits;
|
|
80
|
-
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
81
|
-
case 1:
|
|
82
|
-
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
83
|
-
i = 1;
|
|
84
|
-
_e.label = 2;
|
|
85
|
-
case 2:
|
|
86
|
-
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
87
|
-
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
88
|
-
case 3:
|
|
89
|
-
address = _e.sent();
|
|
90
|
-
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
91
|
-
return [2 /*return*/, "factory-crypto-".concat(poolCount - i)];
|
|
92
|
-
_e.label = 4;
|
|
93
|
-
case 4:
|
|
94
|
-
i++;
|
|
95
|
-
return [3 /*break*/, 2];
|
|
96
|
-
case 5: throw Error("Unknown pool");
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
17
|
+
throw Error("Unknown pool");
|
|
100
18
|
}
|
|
101
|
-
function getCryptoFactoryIdsAndSwapAddresses(fromIdx) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
calls = [];
|
|
116
|
-
for (i = fromIdx; i < poolCount; i++) {
|
|
117
|
-
calls.push(factoryMulticallContract.pool_list(i));
|
|
118
|
-
}
|
|
119
|
-
if (calls.length === 0)
|
|
120
|
-
return [2 /*return*/, [[], []]];
|
|
121
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
122
|
-
case 2:
|
|
123
|
-
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-crypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
|
|
124
|
-
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
125
|
-
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
|
|
126
|
-
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
19
|
+
async function getCryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
|
|
20
|
+
const factoryContract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
|
|
21
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
|
|
22
|
+
const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
|
|
23
|
+
const calls = [];
|
|
24
|
+
for (let i = fromIdx; i < poolCount; i++) {
|
|
25
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
26
|
+
}
|
|
27
|
+
if (calls.length === 0)
|
|
28
|
+
return [[], []];
|
|
29
|
+
let factories = (await this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-crypto-${fromIdx + i}`, address: addr.toLowerCase() }));
|
|
30
|
+
const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
|
|
31
|
+
factories = factories.filter((f) => !swapAddresses.includes(f.address));
|
|
32
|
+
return [factories.map((f) => f.id), factories.map((f) => f.address)];
|
|
130
33
|
}
|
|
131
34
|
function _handleCoinAddresses(coinAddresses) {
|
|
132
|
-
|
|
133
|
-
return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
|
|
35
|
+
return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
|
|
134
36
|
}
|
|
135
|
-
function getPoolsData(factorySwapAddresses) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
150
|
-
case 1:
|
|
151
|
-
res = _a.sent();
|
|
152
|
-
tokenAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
153
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 3 == 1; }).map(function (a) { return a.toLowerCase(); });
|
|
154
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 2; }));
|
|
155
|
-
return [2 /*return*/, [tokenAddresses, gaugeAddresses, coinAddresses]];
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
37
|
+
async function getPoolsData(factorySwapAddresses) {
|
|
38
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.crypto_factory].multicallContract;
|
|
39
|
+
const calls = [];
|
|
40
|
+
for (const addr of factorySwapAddresses) {
|
|
41
|
+
calls.push(factoryMulticallContract.get_token(addr));
|
|
42
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
43
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
44
|
+
}
|
|
45
|
+
const res = await this.multicallProvider.all(calls);
|
|
46
|
+
const tokenAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
|
|
47
|
+
const gaugeAddresses = res.filter((a, i) => i % 3 == 1).map((a) => a.toLowerCase());
|
|
48
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 2));
|
|
49
|
+
return [tokenAddresses, gaugeAddresses, coinAddresses];
|
|
159
50
|
}
|
|
160
51
|
function setCryptoFactorySwapContracts(factorySwapAddresses) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
_this.setContract(addr, factory_crypto_pool_2_json_1.default);
|
|
52
|
+
factorySwapAddresses.forEach((addr) => {
|
|
53
|
+
this.setContract(addr, cryptoFactorySwapABI);
|
|
164
54
|
});
|
|
165
55
|
}
|
|
166
56
|
function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_this.setContract(addr, ERC20_json_1.default);
|
|
57
|
+
factoryTokenAddresses.forEach((addr) => {
|
|
58
|
+
this.setContract(addr, ERC20ABI);
|
|
170
59
|
});
|
|
171
60
|
}
|
|
172
61
|
function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
_this.setContract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default);
|
|
62
|
+
factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
|
|
63
|
+
this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
176
64
|
});
|
|
177
65
|
}
|
|
178
66
|
function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
179
|
-
|
|
180
|
-
for (
|
|
181
|
-
var addr = flattenedCoinAddresses_1[_i];
|
|
67
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
68
|
+
for (const addr of flattenedCoinAddresses) {
|
|
182
69
|
if (addr in this.contracts)
|
|
183
70
|
continue;
|
|
184
|
-
this.setContract(addr,
|
|
71
|
+
this.setContract(addr, ERC20ABI);
|
|
185
72
|
}
|
|
186
73
|
}
|
|
187
74
|
function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
188
|
-
|
|
189
|
-
return coinAddresses.map(function (coins) { return coins.map(function (c) { return c === _this.constants.NATIVE_TOKEN.wrappedAddress ? _this.constants.NATIVE_TOKEN.address : c; }); });
|
|
75
|
+
return coinAddresses.map((coins) => coins.map((c) => c === this.constants.NATIVE_TOKEN.wrappedAddress ? this.constants.NATIVE_TOKEN.address : c));
|
|
190
76
|
}
|
|
191
77
|
function getExistingCoinAddressNameDict() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
poolData.wrapped_coin_addresses.forEach(
|
|
78
|
+
const dict = {};
|
|
79
|
+
for (const poolData of Object.values(this.constants.POOLS_DATA)) {
|
|
80
|
+
poolData.wrapped_coin_addresses.forEach((addr, i) => {
|
|
195
81
|
if (!(addr.toLowerCase() in dict)) {
|
|
196
82
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
197
83
|
}
|
|
198
84
|
});
|
|
199
|
-
poolData.underlying_coin_addresses.forEach(
|
|
85
|
+
poolData.underlying_coin_addresses.forEach((addr, i) => {
|
|
200
86
|
if (!(addr.toLowerCase() in dict)) {
|
|
201
87
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
202
88
|
}
|
|
203
89
|
});
|
|
204
|
-
};
|
|
205
|
-
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
206
|
-
var poolData = _a[_i];
|
|
207
|
-
_loop_1(poolData);
|
|
208
90
|
}
|
|
209
91
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
210
92
|
return dict;
|
|
211
93
|
}
|
|
212
|
-
function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
res = _c.sent();
|
|
249
|
-
res1 = res.slice(0, tokenAddresses.length * 2);
|
|
250
|
-
tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
|
|
251
|
-
tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
|
|
252
|
-
res2 = res.slice(tokenAddresses.length * 2);
|
|
253
|
-
symbols = res2.filter(function (a, i) { return i % 2 == 0; });
|
|
254
|
-
decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
|
|
255
|
-
newCoinAddresses.forEach(function (addr, i) {
|
|
256
|
-
coinAddrNamesDict[addr] = symbols[i];
|
|
257
|
-
coinAddrDecimalsDict[addr] = decimals[i];
|
|
258
|
-
});
|
|
259
|
-
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
260
|
-
return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
261
|
-
}
|
|
262
|
-
});
|
|
94
|
+
async function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
95
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
96
|
+
const newCoinAddresses = [];
|
|
97
|
+
const coinAddrNamesDict = {};
|
|
98
|
+
const coinAddrDecimalsDict = {};
|
|
99
|
+
for (const addr of flattenedCoinAddresses) {
|
|
100
|
+
if (addr in existingCoinAddrNameDict) {
|
|
101
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
102
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
103
|
+
}
|
|
104
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
105
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
newCoinAddresses.push(addr);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const calls = [];
|
|
112
|
+
for (const addr of tokenAddresses) {
|
|
113
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
114
|
+
calls.push(this.contracts[addr].multicallContract.name());
|
|
115
|
+
}
|
|
116
|
+
for (const addr of newCoinAddresses) {
|
|
117
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
118
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
119
|
+
}
|
|
120
|
+
const res = await this.multicallProvider.all(calls);
|
|
121
|
+
const res1 = res.slice(0, tokenAddresses.length * 2);
|
|
122
|
+
const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
|
|
123
|
+
const tokenNames = res1.filter((a, i) => i % 2 == 1);
|
|
124
|
+
const res2 = res.slice(tokenAddresses.length * 2);
|
|
125
|
+
const symbols = res2.filter((a, i) => i % 2 == 0);
|
|
126
|
+
const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
|
|
127
|
+
newCoinAddresses.forEach((addr, i) => {
|
|
128
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
129
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
263
130
|
});
|
|
131
|
+
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
132
|
+
return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
|
|
264
133
|
}
|
|
265
|
-
function getCryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
swap_address: swapAddresses[i],
|
|
340
|
-
token_address: tokenAddresses[i],
|
|
341
|
-
gauge_address: gaugeAddresses[i],
|
|
342
|
-
is_crypto: true,
|
|
343
|
-
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
344
|
-
is_factory: true,
|
|
345
|
-
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
346
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
347
|
-
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
348
|
-
wrapped_coin_addresses: coinAddresses[i],
|
|
349
|
-
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
350
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
351
|
-
swap_abi: factory_crypto_pool_2_json_1.default,
|
|
352
|
-
gauge_abi: this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return [2 /*return*/, CRYPTO_FACTORY_POOLS_DATA];
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
});
|
|
134
|
+
export async function getCryptoFactoryPoolData(fromIdx = 0, swapAddress) {
|
|
135
|
+
const [poolIds, swapAddresses] = swapAddress ?
|
|
136
|
+
[[await getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
|
|
137
|
+
: await getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
|
|
138
|
+
if (poolIds.length === 0)
|
|
139
|
+
return {};
|
|
140
|
+
const [tokenAddresses, gaugeAddresses, coinAddresses] = await getPoolsData.call(this, swapAddresses);
|
|
141
|
+
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
142
|
+
setCryptoFactoryTokenContracts.call(this, tokenAddresses);
|
|
143
|
+
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
144
|
+
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
145
|
+
setFactoryZapContracts.call(this, true);
|
|
146
|
+
const underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
|
|
147
|
+
const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
148
|
+
const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = await getCoinsData.call(this, tokenAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
|
|
149
|
+
const CRYPTO_FACTORY_POOLS_DATA = {};
|
|
150
|
+
for (let i = 0; i < poolIds.length; i++) {
|
|
151
|
+
const lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
|
|
152
|
+
const basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
|
|
153
|
+
const basePoolId = lpTokenBasePoolIdDict[coinAddresses[i][1].toLowerCase()];
|
|
154
|
+
if (basePoolId) { // isMeta
|
|
155
|
+
const allPoolsData = { ...this.constants.POOLS_DATA, ...CRYPTO_FACTORY_POOLS_DATA };
|
|
156
|
+
const basePoolCoinNames = [...allPoolsData[basePoolId].underlying_coins];
|
|
157
|
+
const basePoolCoinAddresses = [...allPoolsData[basePoolId].underlying_coin_addresses];
|
|
158
|
+
const basePoolDecimals = [...allPoolsData[basePoolId].underlying_decimals];
|
|
159
|
+
const basePoolZap = basePoolIdZapDict[basePoolId];
|
|
160
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
161
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
162
|
+
full_name: poolNames[i],
|
|
163
|
+
symbol: poolSymbols[i],
|
|
164
|
+
reference_asset: "CRYPTO",
|
|
165
|
+
swap_address: swapAddresses[i],
|
|
166
|
+
token_address: tokenAddresses[i],
|
|
167
|
+
gauge_address: gaugeAddresses[i],
|
|
168
|
+
deposit_address: basePoolZap.address,
|
|
169
|
+
is_meta: true,
|
|
170
|
+
is_crypto: true,
|
|
171
|
+
is_factory: true,
|
|
172
|
+
base_pool: basePoolId,
|
|
173
|
+
underlying_coins: [coinAddressNameDict[underlyingCoinAddresses[i][0]], ...basePoolCoinNames],
|
|
174
|
+
wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
175
|
+
underlying_coin_addresses: [underlyingCoinAddresses[i][0], ...basePoolCoinAddresses],
|
|
176
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
177
|
+
underlying_decimals: [coinAddressDecimalsDict[underlyingCoinAddresses[i][0]], ...basePoolDecimals],
|
|
178
|
+
wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
179
|
+
swap_abi: cryptoFactorySwapABI,
|
|
180
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
181
|
+
deposit_abi: basePoolZap.ABI,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
CRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
186
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
187
|
+
full_name: poolNames[i],
|
|
188
|
+
symbol: poolSymbols[i],
|
|
189
|
+
reference_asset: "CRYPTO",
|
|
190
|
+
swap_address: swapAddresses[i],
|
|
191
|
+
token_address: tokenAddresses[i],
|
|
192
|
+
gauge_address: gaugeAddresses[i],
|
|
193
|
+
is_crypto: true,
|
|
194
|
+
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
195
|
+
is_factory: true,
|
|
196
|
+
underlying_coins: underlyingCoinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
197
|
+
wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
198
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
199
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
200
|
+
underlying_decimals: underlyingCoinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
201
|
+
wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
202
|
+
swap_abi: cryptoFactorySwapABI,
|
|
203
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return CRYPTO_FACTORY_POOLS_DATA;
|
|
360
208
|
}
|
|
361
|
-
exports.getCryptoFactoryPoolData = getCryptoFactoryPoolData;
|