@curvefi/api 2.30.1 → 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/abis/avaxcrypto/swap.json +1195 -0
- package/lib/constants/abis/avaxcrypto/zap.json +250 -0
- 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 +12 -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 +51 -22
- 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 +23 -28
- package/lib/constants/pools/xdai.d.ts +2 -4
- package/lib/constants/pools/xdai.js +25 -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 +6 -5
- package/lib/interfaces.js +1 -2
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +1516 -2928
- 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 -102
- 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 +145 -405
- 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 -2
- package/lib/pools/mixins/poolBalancesMixin.js +25 -131
- 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 -2
- package/lib/pools/mixins/withdrawExpectedMixins.js +26 -154
- 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 +124 -378
- 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 +125 -378
- 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 +79 -109
- package/lib/pools/utils.js +298 -500
- package/lib/router.d.ts +2 -2
- package/lib/router.js +406 -650
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +377 -731
- package/package.json +8 -8
package/lib/factory/factory.js
CHANGED
|
@@ -1,73 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 (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
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
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.getFactoryPoolData = void 0;
|
|
63
|
-
var ethers_1 = require("ethers");
|
|
64
|
-
var ethcall_1 = require("ethcall");
|
|
65
|
-
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.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_1 = require("./constants");
|
|
70
|
-
var BLACK_LIST = {
|
|
1
|
+
import { Contract as MulticallContract } from "ethcall";
|
|
2
|
+
import { curve } from "../curve.js";
|
|
3
|
+
import ERC20ABI from "../constants/abis/ERC20.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 { FACTORY_CONSTANTS } from "./constants.js";
|
|
8
|
+
const BLACK_LIST = {
|
|
71
9
|
1: [
|
|
72
10
|
"0x066b6e1e93fa7dcd3f0eb7f8bac7d5a747ce0bf9",
|
|
73
11
|
],
|
|
@@ -77,322 +15,229 @@ var BLACK_LIST = {
|
|
|
77
15
|
"0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
|
|
78
16
|
],
|
|
79
17
|
};
|
|
80
|
-
|
|
81
|
-
function getRecentlyCreatedPoolId(swapAddress) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
91
|
-
case 1:
|
|
92
|
-
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
93
|
-
i = 1;
|
|
94
|
-
_e.label = 2;
|
|
95
|
-
case 2:
|
|
96
|
-
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
97
|
-
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
98
|
-
case 3:
|
|
99
|
-
address = _e.sent();
|
|
100
|
-
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
101
|
-
return [2 /*return*/, "factory-v2-".concat(poolCount - i)];
|
|
102
|
-
_e.label = 4;
|
|
103
|
-
case 4:
|
|
104
|
-
i++;
|
|
105
|
-
return [3 /*break*/, 2];
|
|
106
|
-
case 5: throw Error("Unknown pool");
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
18
|
+
const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
|
|
19
|
+
async function getRecentlyCreatedPoolId(swapAddress) {
|
|
20
|
+
const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
|
|
21
|
+
const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
|
|
22
|
+
for (let i = 1; i <= poolCount; i++) {
|
|
23
|
+
const address = await factoryContract.pool_list(poolCount - i);
|
|
24
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
25
|
+
return `factory-v2-${poolCount - i}`;
|
|
26
|
+
}
|
|
27
|
+
throw Error("Unknown pool");
|
|
110
28
|
}
|
|
111
|
-
function getFactoryIdsAndSwapAddresses(fromIdx) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
calls = [];
|
|
127
|
-
for (i = fromIdx; i < poolCount; i++) {
|
|
128
|
-
calls.push(factoryMulticallContract.pool_list(i));
|
|
129
|
-
}
|
|
130
|
-
if (calls.length === 0)
|
|
131
|
-
return [2 /*return*/, [[], []]];
|
|
132
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
133
|
-
case 2:
|
|
134
|
-
factories = (_f.sent()).map(function (addr, i) { return ({ id: "factory-v2-".concat(fromIdx + i), address: addr.toLowerCase() }); });
|
|
135
|
-
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
136
|
-
blacklist = (_a = BLACK_LIST[this.chainId]) !== null && _a !== void 0 ? _a : [];
|
|
137
|
-
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address) && !blacklist.includes(f.address); });
|
|
138
|
-
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
29
|
+
async function getFactoryIdsAndSwapAddresses(fromIdx = 0) {
|
|
30
|
+
const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
|
|
31
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.factory].multicallContract;
|
|
32
|
+
const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
|
|
33
|
+
const calls = [];
|
|
34
|
+
for (let i = fromIdx; i < poolCount; i++) {
|
|
35
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
36
|
+
}
|
|
37
|
+
if (calls.length === 0)
|
|
38
|
+
return [[], []];
|
|
39
|
+
let factories = (await this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-v2-${fromIdx + i}`, address: addr.toLowerCase() }));
|
|
40
|
+
const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
|
|
41
|
+
const blacklist = BLACK_LIST[this.chainId] ?? [];
|
|
42
|
+
factories = factories.filter((f) => !swapAddresses.includes(f.address) && !blacklist.includes(f.address));
|
|
43
|
+
return [factories.map((f) => f.id), factories.map((f) => f.address)];
|
|
142
44
|
}
|
|
143
45
|
function _handleReferenceAssets(referenceAssets) {
|
|
144
|
-
return referenceAssets.map(
|
|
46
|
+
return referenceAssets.map((t) => {
|
|
145
47
|
return {
|
|
146
48
|
0: "USD",
|
|
147
49
|
1: "ETH",
|
|
148
50
|
2: "BTC",
|
|
149
|
-
}[
|
|
51
|
+
}[curve.formatUnits(t, 0)] || "OTHER";
|
|
150
52
|
});
|
|
151
53
|
}
|
|
152
54
|
function _handleCoinAddresses(coinAddresses) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.address : addr.toLowerCase(); }); });
|
|
55
|
+
return coinAddresses.map((addresses) => addresses
|
|
56
|
+
.filter((addr) => addr !== curve.constants.ZERO_ADDRESS)
|
|
57
|
+
.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.address : addr.toLowerCase()));
|
|
157
58
|
}
|
|
158
|
-
function getPoolsData(factorySwapAddresses) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
implememntationAddresses = res.filter(function (a, i) { return i % 7 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
181
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 7 == 1; }).map(function (a) { return a.toLowerCase(); });
|
|
182
|
-
referenceAssets = _handleReferenceAssets(res.filter(function (a, i) { return i % 7 == 2; }));
|
|
183
|
-
symbols = res.filter(function (a, i) { return i % 7 == 3; });
|
|
184
|
-
names = res.filter(function (a, i) { return i % 7 == 4; });
|
|
185
|
-
isMeta = res.filter(function (a, i) { return i % 7 == 5; });
|
|
186
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 7 == 6; }));
|
|
187
|
-
return [2 /*return*/, [implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses]];
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
59
|
+
async function getPoolsData(factorySwapAddresses) {
|
|
60
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.factory].multicallContract;
|
|
61
|
+
const calls = [];
|
|
62
|
+
for (const addr of factorySwapAddresses) {
|
|
63
|
+
const tempSwapContract = new MulticallContract(addr, ERC20ABI);
|
|
64
|
+
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
65
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
66
|
+
calls.push(factoryMulticallContract.get_pool_asset_type(addr));
|
|
67
|
+
calls.push(tempSwapContract.symbol());
|
|
68
|
+
calls.push(tempSwapContract.name());
|
|
69
|
+
calls.push(factoryMulticallContract.is_meta(addr));
|
|
70
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
71
|
+
}
|
|
72
|
+
const res = await this.multicallProvider.all(calls);
|
|
73
|
+
const implememntationAddresses = res.filter((a, i) => i % 7 == 0).map((a) => a.toLowerCase());
|
|
74
|
+
const gaugeAddresses = res.filter((a, i) => i % 7 == 1).map((a) => a.toLowerCase());
|
|
75
|
+
const referenceAssets = _handleReferenceAssets(res.filter((a, i) => i % 7 == 2));
|
|
76
|
+
const symbols = res.filter((a, i) => i % 7 == 3);
|
|
77
|
+
const names = res.filter((a, i) => i % 7 == 4);
|
|
78
|
+
const isMeta = res.filter((a, i) => i % 7 == 5);
|
|
79
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 7 == 6));
|
|
80
|
+
return [implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses];
|
|
191
81
|
}
|
|
192
82
|
function setFactorySwapContracts(factorySwapAddresses, factorySwapABIs) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
_this.setContract(addr, factorySwapABIs[i]);
|
|
83
|
+
factorySwapAddresses.forEach((addr, i) => {
|
|
84
|
+
this.setContract(addr, factorySwapABIs[i]);
|
|
196
85
|
});
|
|
197
86
|
}
|
|
198
87
|
function setFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
_this.setContract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default);
|
|
88
|
+
factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
|
|
89
|
+
this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
202
90
|
});
|
|
203
91
|
}
|
|
204
92
|
function setFactoryCoinsContracts(coinAddresses) {
|
|
205
|
-
|
|
206
|
-
for (
|
|
207
|
-
var addr = flattenedCoinAddresses_1[_i];
|
|
93
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
94
|
+
for (const addr of flattenedCoinAddresses) {
|
|
208
95
|
if (addr in this.contracts)
|
|
209
96
|
continue;
|
|
210
|
-
this.setContract(addr,
|
|
97
|
+
this.setContract(addr, ERC20ABI);
|
|
211
98
|
}
|
|
212
99
|
}
|
|
213
100
|
function getExistingCoinAddressNameDict() {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
poolData.wrapped_coin_addresses.forEach(
|
|
101
|
+
const dict = {};
|
|
102
|
+
for (const poolData of Object.values(this.constants.POOLS_DATA)) {
|
|
103
|
+
poolData.wrapped_coin_addresses.forEach((addr, i) => {
|
|
217
104
|
if (!(addr.toLowerCase() in dict)) {
|
|
218
105
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
219
106
|
}
|
|
220
107
|
});
|
|
221
|
-
poolData.underlying_coin_addresses.forEach(
|
|
108
|
+
poolData.underlying_coin_addresses.forEach((addr, i) => {
|
|
222
109
|
if (!(addr.toLowerCase() in dict)) {
|
|
223
110
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
224
111
|
}
|
|
225
112
|
});
|
|
226
|
-
};
|
|
227
|
-
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
228
|
-
var poolData = _a[_i];
|
|
229
|
-
_loop_1(poolData);
|
|
230
113
|
}
|
|
231
114
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
232
115
|
return dict;
|
|
233
116
|
}
|
|
234
|
-
function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
261
|
-
case 1:
|
|
262
|
-
res = _b.sent();
|
|
263
|
-
symbols = res.filter(function (a, i) { return i % 2 == 0; });
|
|
264
|
-
decimals = res.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(ethers_1.ethers.utils.formatUnits(_d, 0)); });
|
|
265
|
-
newCoinAddresses.forEach(function (addr, i) {
|
|
266
|
-
coinAddrNamesDict[addr] = symbols[i];
|
|
267
|
-
coinAddrDecimalsDict[addr] = decimals[i];
|
|
268
|
-
});
|
|
269
|
-
return [2 /*return*/, [coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
117
|
+
async function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
118
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
119
|
+
const newCoinAddresses = [];
|
|
120
|
+
const coinAddrNamesDict = {};
|
|
121
|
+
const coinAddrDecimalsDict = {};
|
|
122
|
+
for (const addr of flattenedCoinAddresses) {
|
|
123
|
+
if (addr in existingCoinAddrNameDict) {
|
|
124
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
125
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
newCoinAddresses.push(addr);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const calls = [];
|
|
132
|
+
for (const addr of newCoinAddresses) {
|
|
133
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
134
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
135
|
+
}
|
|
136
|
+
const res = await this.multicallProvider.all(calls);
|
|
137
|
+
const symbols = res.filter((a, i) => i % 2 == 0);
|
|
138
|
+
const decimals = res.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
|
|
139
|
+
newCoinAddresses.forEach((addr, i) => {
|
|
140
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
141
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
272
142
|
});
|
|
143
|
+
return [coinAddrNamesDict, coinAddrDecimalsDict];
|
|
273
144
|
}
|
|
274
|
-
function getFactoryPoolData(fromIdx, swapAddress) {
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
|
|
373
|
-
implementation_address: implementations[i],
|
|
374
|
-
is_meta: true,
|
|
375
|
-
is_factory: true,
|
|
376
|
-
base_pool: basePoolIds[i],
|
|
377
|
-
underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolIdCoinsDict[basePoolIds[i]], true),
|
|
378
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
379
|
-
underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolIdCoinAddressesDict[basePoolIds[i]], true),
|
|
380
|
-
wrapped_coin_addresses: coinAddresses[i],
|
|
381
|
-
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
|
|
382
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
383
|
-
swap_abi: swapABIs[i],
|
|
384
|
-
gauge_abi: this_1.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
|
|
385
|
-
deposit_abi: basePoolZap.ABI,
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
this_1 = this;
|
|
390
|
-
for (i = 0; i < poolIds.length; i++) {
|
|
391
|
-
_loop_2(i);
|
|
392
|
-
}
|
|
393
|
-
return [2 /*return*/, FACTORY_POOLS_DATA];
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
});
|
|
145
|
+
export async function getFactoryPoolData(fromIdx = 0, swapAddress) {
|
|
146
|
+
const [rawPoolIds, rawSwapAddresses] = swapAddress ?
|
|
147
|
+
[[await getRecentlyCreatedPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
|
|
148
|
+
: await getFactoryIdsAndSwapAddresses.call(this, fromIdx);
|
|
149
|
+
if (rawPoolIds.length === 0)
|
|
150
|
+
return {};
|
|
151
|
+
const [rawImplementations, rawGauges, rawReferenceAssets, rawPoolSymbols, rawPoolNames, rawIsMeta, rawCoinAddresses] = await getPoolsData.call(this, rawSwapAddresses);
|
|
152
|
+
const poolIds = [];
|
|
153
|
+
const swapAddresses = [];
|
|
154
|
+
const implementations = [];
|
|
155
|
+
const gaugeAddresses = [];
|
|
156
|
+
const referenceAssets = [];
|
|
157
|
+
const poolSymbols = [];
|
|
158
|
+
const poolNames = [];
|
|
159
|
+
const isMeta = [];
|
|
160
|
+
const coinAddresses = [];
|
|
161
|
+
const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
|
|
162
|
+
for (let i = 0; i < rawPoolIds.length; i++) {
|
|
163
|
+
if (rawImplementations[i] in implementationABIDict) {
|
|
164
|
+
poolIds.push(rawPoolIds[i]);
|
|
165
|
+
swapAddresses.push(rawSwapAddresses[i]);
|
|
166
|
+
implementations.push(rawImplementations[i]);
|
|
167
|
+
gaugeAddresses.push(rawGauges[i]);
|
|
168
|
+
referenceAssets.push(rawReferenceAssets[i]);
|
|
169
|
+
poolSymbols.push(rawPoolSymbols[i]);
|
|
170
|
+
poolNames.push(rawPoolNames[i]);
|
|
171
|
+
isMeta.push(rawIsMeta[i]);
|
|
172
|
+
coinAddresses.push(rawCoinAddresses[i]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const swapABIs = implementations.map((addr) => implementationABIDict[addr]);
|
|
176
|
+
setFactorySwapContracts.call(this, swapAddresses, swapABIs);
|
|
177
|
+
setFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
178
|
+
setFactoryCoinsContracts.call(this, coinAddresses);
|
|
179
|
+
setFactoryZapContracts.call(this, false);
|
|
180
|
+
const [coinAddressNameDict, coinAddressDecimalsDict] = await getCoinsData.call(this, coinAddresses, getExistingCoinAddressNameDict.call(this), this.constants.DECIMALS);
|
|
181
|
+
const implementationBasePoolIdDict = FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
|
|
182
|
+
const basePoolIds = implementations.map((addr) => implementationBasePoolIdDict[addr]);
|
|
183
|
+
const FACTORY_POOLS_DATA = {};
|
|
184
|
+
for (let i = 0; i < poolIds.length; i++) {
|
|
185
|
+
if (!isMeta[i]) {
|
|
186
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
187
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
188
|
+
full_name: poolNames[i],
|
|
189
|
+
symbol: poolSymbols[i],
|
|
190
|
+
reference_asset: referenceAssets[i],
|
|
191
|
+
swap_address: swapAddresses[i],
|
|
192
|
+
token_address: swapAddresses[i],
|
|
193
|
+
gauge_address: gaugeAddresses[i],
|
|
194
|
+
implementation_address: implementations[i],
|
|
195
|
+
is_plain: true,
|
|
196
|
+
is_factory: true,
|
|
197
|
+
underlying_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
198
|
+
wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
199
|
+
underlying_coin_addresses: coinAddresses[i],
|
|
200
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
201
|
+
underlying_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
202
|
+
wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
203
|
+
swap_abi: swapABIs[i],
|
|
204
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
const allPoolsData = { ...this.constants.POOLS_DATA, ...FACTORY_POOLS_DATA };
|
|
209
|
+
// @ts-ignore
|
|
210
|
+
const basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coins]));
|
|
211
|
+
// @ts-ignore
|
|
212
|
+
const basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coin_addresses]));
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
const basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_decimals]));
|
|
215
|
+
const basePoolIdZapDict = FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
|
|
216
|
+
const basePoolZap = basePoolIdZapDict[basePoolIds[i]];
|
|
217
|
+
FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
218
|
+
name: poolNames[i].split(": ")[1].trim(),
|
|
219
|
+
full_name: poolNames[i],
|
|
220
|
+
symbol: poolSymbols[i],
|
|
221
|
+
reference_asset: referenceAssets[i],
|
|
222
|
+
swap_address: swapAddresses[i],
|
|
223
|
+
token_address: swapAddresses[i],
|
|
224
|
+
gauge_address: gaugeAddresses[i],
|
|
225
|
+
deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
|
|
226
|
+
implementation_address: implementations[i],
|
|
227
|
+
is_meta: true,
|
|
228
|
+
is_factory: true,
|
|
229
|
+
base_pool: basePoolIds[i],
|
|
230
|
+
underlying_coins: [coinAddressNameDict[coinAddresses[i][0]], ...basePoolIdCoinsDict[basePoolIds[i]]],
|
|
231
|
+
wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
|
|
232
|
+
underlying_coin_addresses: [coinAddresses[i][0], ...basePoolIdCoinAddressesDict[basePoolIds[i]]],
|
|
233
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
234
|
+
underlying_decimals: [coinAddressDecimalsDict[coinAddresses[i][0]], ...basePoolIdDecimalsDict[basePoolIds[i]]],
|
|
235
|
+
wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
|
|
236
|
+
swap_abi: swapABIs[i],
|
|
237
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
238
|
+
deposit_abi: basePoolZap.ABI,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return FACTORY_POOLS_DATA;
|
|
397
243
|
}
|
|
398
|
-
exports.getFactoryPoolData = getFactoryPoolData;
|