@curvefi/api 2.63.0 → 2.63.2
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 +247 -645
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +19 -19
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/base.js +5 -5
- package/lib/constants/coins/bsc.js +5 -5
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +9 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/fraxtal.js +5 -5
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/mantle.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/coins/xlayer.js +5 -5
- package/lib/constants/coins/zksync.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/base.js +1 -1
- package/lib/constants/pools/bsc.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +2 -2
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/fraxtal.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/mantle.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/pools/xlayer.js +1 -1
- package/lib/constants/pools/zksync.js +1 -1
- package/lib/constants/tricryptoDeployImplementations.js +1 -1
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +10 -6
- package/lib/curve.js +534 -909
- package/lib/dao.js +351 -705
- package/lib/external-api.js +127 -256
- package/lib/factory/common.js +4 -4
- package/lib/factory/constants-crypto.js +33 -33
- package/lib/factory/constants.js +34 -34
- package/lib/factory/deploy.js +542 -907
- package/lib/factory/factory-api.js +205 -269
- package/lib/factory/factory-crypto.js +202 -342
- package/lib/factory/factory-tricrypto.js +164 -286
- package/lib/factory/factory-twocrypto.js +151 -269
- package/lib/factory/factory.js +245 -385
- package/lib/index.js +109 -198
- package/lib/interfaces.d.ts +46 -6
- package/lib/pools/PoolTemplate.js +1774 -3027
- package/lib/pools/gaugePool.js +112 -251
- package/lib/pools/mixins/common.js +22 -93
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
- package/lib/pools/mixins/depositMixins.js +160 -386
- package/lib/pools/mixins/depositWrappedMixins.js +79 -205
- package/lib/pools/mixins/poolBalancesMixin.js +24 -87
- package/lib/pools/mixins/swapMixins.js +139 -324
- package/lib/pools/mixins/swapWrappedMixins.js +111 -265
- package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
- package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
- package/lib/pools/mixins/withdrawMixins.js +139 -359
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
- package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
- package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
- package/lib/pools/poolConstructor.js +11 -31
- package/lib/pools/utils.js +301 -469
- package/lib/route-finder.worker.d.ts +9 -0
- package/lib/route-finder.worker.js +112 -0
- package/lib/route-graph.worker.d.ts +11 -0
- package/lib/route-graph.worker.js +334 -0
- package/lib/router.js +323 -912
- package/lib/utils.d.ts +8 -7
- package/lib/utils.js +540 -927
- package/package.json +3 -2
package/lib/factory/deploy.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,42 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
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;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
-
if (ar || !(i in from)) {
|
|
51
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
-
};
|
|
57
10
|
import { ethers, Contract, Typed } from "ethers";
|
|
58
11
|
import { curve } from "../curve.js";
|
|
59
12
|
import { getPool } from "../pools/index.js";
|
|
@@ -62,904 +15,586 @@ import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert
|
|
|
62
15
|
import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" assert { type: 'json' };
|
|
63
16
|
import { tricryptoDeployImplementations } from "../constants/tricryptoDeployImplementations.js";
|
|
64
17
|
// ------- STABLE PLAIN POOLS -------
|
|
65
|
-
|
|
18
|
+
const _deployStablePlainPool = (name, symbol, coins, A, fee, // %
|
|
66
19
|
assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
|
|
67
20
|
implementationIdx, emaTime, // seconds
|
|
68
|
-
oracleAddress, methodName, estimateGas)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (estimateGas)
|
|
117
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
118
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
119
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
120
|
-
case 2:
|
|
121
|
-
_b.sent();
|
|
122
|
-
return [4 /*yield*/, contract[methodToCall].apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
|
|
123
|
-
case 3: return [2 /*return*/, _b.sent()];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}); };
|
|
127
|
-
export var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
|
|
21
|
+
oracleAddress, methodName, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
if (name.length > 32)
|
|
23
|
+
throw Error("Max name length = 32");
|
|
24
|
+
if (symbol.length > 10)
|
|
25
|
+
throw Error("Max symbol length = 10");
|
|
26
|
+
if (![2, 3, 4].includes(coins.length))
|
|
27
|
+
throw Error("Invalid number of coins. Must be 2, 3 or 4");
|
|
28
|
+
if (BN(fee).lt(0.04))
|
|
29
|
+
throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
|
|
30
|
+
if (BN(fee).gt(1))
|
|
31
|
+
throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
|
|
32
|
+
if (![0, 1, 2, 3].includes(assetType))
|
|
33
|
+
throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
|
|
34
|
+
if (curve.chainId !== 1 || coins.length > 2) {
|
|
35
|
+
if (![0, 1, 2, 3].includes(implementationIdx))
|
|
36
|
+
throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (![0, 1, 2, 3, 4, 5].includes(implementationIdx))
|
|
40
|
+
throw Error("Invalid implementationIdx. Must be one 0, 1, 2, 3, 4 or 5");
|
|
41
|
+
}
|
|
42
|
+
if (emaTime <= 0)
|
|
43
|
+
throw Error(`emaTime must be > 0. Passed emaTime = ${emaTime}`);
|
|
44
|
+
const _A = parseUnits(A, 0);
|
|
45
|
+
const _fee = parseUnits(fee, 8);
|
|
46
|
+
const _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
|
|
47
|
+
const useProxy = (curve.chainId === 1 && coins.length === 2 && implementationIdx === 4 && emaTime !== 600) ||
|
|
48
|
+
(curve.chainId === 1 && coins.length === 2 && implementationIdx === 5 && emaTime !== 600) ||
|
|
49
|
+
((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 0 && emaTime !== 600);
|
|
50
|
+
const setOracle = ((curve.chainId === 42161 || curve.chainId == 10) && coins.length === 2 && implementationIdx === 2);
|
|
51
|
+
const contractAddress = (useProxy || setOracle) ? curve.constants.ALIASES.factory_admin : curve.constants.ALIASES.factory;
|
|
52
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
53
|
+
const args = [name, symbol, _coins, _A, _fee, assetType, implementationIdx];
|
|
54
|
+
if (useProxy || setOracle)
|
|
55
|
+
args.push(parseUnits(Math.floor(emaTime / Math.log(2)), 0));
|
|
56
|
+
if (setOracle) {
|
|
57
|
+
const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
|
|
58
|
+
args.push(methodId, oracleAddress);
|
|
59
|
+
}
|
|
60
|
+
const methodToCall = setOracle ? "deploy_plain_pool_and_set_oracle" : "deploy_plain_pool";
|
|
61
|
+
const gas = yield contract[methodToCall].estimateGas(...args, curve.constantOptions);
|
|
62
|
+
if (estimateGas)
|
|
63
|
+
return smartNumber(gas);
|
|
64
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
65
|
+
yield curve.updateFeeData();
|
|
66
|
+
return yield contract[methodToCall](...args, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
67
|
+
});
|
|
68
|
+
export const deployStablePlainPoolEstimateGas = (name, symbol, coins, A, fee, // %
|
|
128
69
|
assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
|
|
129
|
-
implementationIdx, emaTime, // seconds
|
|
130
|
-
oracleAddress, methodName) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
switch (_a.label) {
|
|
137
|
-
case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true)];
|
|
138
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
export var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
|
|
70
|
+
implementationIdx, emaTime = 600, // seconds
|
|
71
|
+
oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true);
|
|
73
|
+
});
|
|
74
|
+
export const deployStablePlainPool = (name, symbol, coins, A, fee, // %
|
|
144
75
|
assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
|
|
145
|
-
implementationIdx, emaTime, // seconds
|
|
146
|
-
oracleAddress, methodName) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
-
return __generator(this, function (_a) {
|
|
152
|
-
switch (_a.label) {
|
|
153
|
-
case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false)];
|
|
154
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
var _deployStableNgPlainPool = function (name, symbol, coins, A, fee, // %
|
|
76
|
+
implementationIdx, emaTime = 600, // seconds
|
|
77
|
+
oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false);
|
|
79
|
+
});
|
|
80
|
+
const _deployStableNgPlainPool = (name, symbol, coins, A, fee, // %
|
|
160
81
|
offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
161
|
-
implementationIdx, emaTime, // seconds
|
|
162
|
-
oracleAddresses, methodNames, estimateGas) {
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
methodIds.push('0x00000000');
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
methodIds.push(ethers.id(item).substring(0, 10));
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
args = [name, symbol, _coins, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetTypes, methodIds, _oracleAddresses];
|
|
222
|
-
return [4 /*yield*/, (_a = contract.deploy_plain_pool).estimateGas.apply(_a, __spreadArray(__spreadArray([], args, false), [curve.constantOptions], false))];
|
|
223
|
-
case 1:
|
|
224
|
-
gas = _b.sent();
|
|
225
|
-
if (estimateGas)
|
|
226
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
227
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
228
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
229
|
-
case 2:
|
|
230
|
-
_b.sent();
|
|
231
|
-
return [4 /*yield*/, contract.deploy_plain_pool.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
|
|
232
|
-
case 3: return [2 /*return*/, _b.sent()];
|
|
233
|
-
}
|
|
234
|
-
});
|
|
82
|
+
implementationIdx, emaTime = 600, // seconds
|
|
83
|
+
oracleAddresses, methodNames, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
if (name.length > 32)
|
|
85
|
+
throw Error("Max name length = 32");
|
|
86
|
+
if (symbol.length > 10)
|
|
87
|
+
throw Error("Max symbol length = 10");
|
|
88
|
+
if (coins.length < 1)
|
|
89
|
+
throw Error("Invalid number of coins. Must be more than 1");
|
|
90
|
+
if (coins.length > 9)
|
|
91
|
+
throw Error("Invalid number of coins. Must be less than 9");
|
|
92
|
+
if (BN(fee).gt(1))
|
|
93
|
+
throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
|
|
94
|
+
let _oracleAddresses;
|
|
95
|
+
if (oracleAddresses.length === 0) {
|
|
96
|
+
_oracleAddresses = new Array(coins.length).fill(curve.constants.ZERO_ADDRESS);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
_oracleAddresses = oracleAddresses;
|
|
100
|
+
}
|
|
101
|
+
let _methodNames;
|
|
102
|
+
if (methodNames.length === 0) {
|
|
103
|
+
_methodNames = new Array(coins.length).fill("0x00000000");
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
_methodNames = methodNames;
|
|
107
|
+
}
|
|
108
|
+
if (coins.length !== assetTypes.length)
|
|
109
|
+
throw Error("Invalid length of assetTypes. Must be same coins length");
|
|
110
|
+
if (coins.length !== _oracleAddresses.length)
|
|
111
|
+
throw Error("Invalid length of oracleAddresses. Must be same coins length");
|
|
112
|
+
if (coins.length !== _methodNames.length)
|
|
113
|
+
throw Error("Invalid length of methodNames. Must be same coins length");
|
|
114
|
+
assetTypes.forEach((item, index) => {
|
|
115
|
+
if (![0, 1, 2, 3].includes(item))
|
|
116
|
+
throw Error(`Invalid assetType. Must be one of: 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626 for assetTypes[${index}]`);
|
|
117
|
+
});
|
|
118
|
+
if (![0].includes(implementationIdx))
|
|
119
|
+
throw Error("Invalid implementationIdx. Must be 0");
|
|
120
|
+
if (emaTime <= 0)
|
|
121
|
+
throw Error(`emaTime must be > 0. Passed emaTime = ${emaTime}`);
|
|
122
|
+
const _A = parseUnits(A, 0);
|
|
123
|
+
const _fee = parseUnits(fee, 8);
|
|
124
|
+
const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
|
|
125
|
+
const _coins = coins;
|
|
126
|
+
const contractAddress = curve.constants.ALIASES.stable_ng_factory;
|
|
127
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
128
|
+
const methodIds = [];
|
|
129
|
+
_methodNames.forEach((item) => {
|
|
130
|
+
if (item === '0x00000000' || item === '') {
|
|
131
|
+
methodIds.push('0x00000000');
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
methodIds.push(ethers.id(item).substring(0, 10));
|
|
135
|
+
}
|
|
235
136
|
});
|
|
236
|
-
|
|
237
|
-
|
|
137
|
+
const args = [name, symbol, _coins, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetTypes, methodIds, _oracleAddresses];
|
|
138
|
+
const gas = yield contract.deploy_plain_pool.estimateGas(...args, curve.constantOptions);
|
|
139
|
+
if (estimateGas)
|
|
140
|
+
return smartNumber(gas);
|
|
141
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
142
|
+
yield curve.updateFeeData();
|
|
143
|
+
return yield contract.deploy_plain_pool(...args, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
144
|
+
});
|
|
145
|
+
export const deployStableNgPlainPoolEstimateGas = (name, symbol, coins, A, fee, // %
|
|
238
146
|
offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
239
147
|
implementationIdx, emaTime, // seconds
|
|
240
|
-
oracleAddresses, methodNames)
|
|
241
|
-
return
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}); };
|
|
248
|
-
export var deployStableNgPlainPool = function (name, symbol, coins, A, fee, // %
|
|
148
|
+
oracleAddresses, methodNames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
149
|
+
return yield _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, true);
|
|
150
|
+
});
|
|
151
|
+
export const deployStableNgPlainPool = (name, symbol, coins, A, fee, // %
|
|
249
152
|
offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
250
153
|
implementationIdx, emaTime, // seconds
|
|
251
|
-
oracleAddresses, methodNames)
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
curve.setContract(poolAddress, Plain2ETHOracleABIABI);
|
|
278
|
-
poolContract = curve.contracts[poolAddress].contract;
|
|
279
|
-
methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
|
|
280
|
-
return [4 /*yield*/, poolContract.set_oracle.estimateGas(methodId, oracleAddress, curve.constantOptions)];
|
|
281
|
-
case 1:
|
|
282
|
-
_gas = _a.sent();
|
|
283
|
-
if (estimateGas)
|
|
284
|
-
return [2 /*return*/, Number(_gas)];
|
|
285
|
-
gasLimit = mulBy1_3(_gas);
|
|
286
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
287
|
-
case 2:
|
|
288
|
-
_a.sent();
|
|
289
|
-
return [4 /*yield*/, poolContract.set_oracle(methodId, oracleAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
290
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}); };
|
|
294
|
-
export var setOracleEstimateGas = function (poolAddress, oracleAddress, methodName) {
|
|
295
|
-
if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
|
|
296
|
-
if (methodName === void 0) { methodName = "0x00000000"; }
|
|
297
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
298
|
-
return __generator(this, function (_a) {
|
|
299
|
-
switch (_a.label) {
|
|
300
|
-
case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, true)];
|
|
301
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
export var setOracle = function (poolAddress, oracleAddress, methodName) {
|
|
307
|
-
if (oracleAddress === void 0) { oracleAddress = curve.constants.ZERO_ADDRESS; }
|
|
308
|
-
if (methodName === void 0) { methodName = "0x00000000"; }
|
|
309
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
310
|
-
return __generator(this, function (_a) {
|
|
311
|
-
switch (_a.label) {
|
|
312
|
-
case 0: return [4 /*yield*/, _setOracle(poolAddress, oracleAddress, methodName, false)];
|
|
313
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
};
|
|
154
|
+
oracleAddresses, methodNames) => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
return yield _deployStableNgPlainPool(name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, false);
|
|
156
|
+
});
|
|
157
|
+
export const getDeployedStablePlainPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
const txInfo = yield tx.wait();
|
|
159
|
+
if (!txInfo)
|
|
160
|
+
throw Error("Can't get tx info");
|
|
161
|
+
return txInfo.logs[0].address.toLowerCase();
|
|
162
|
+
});
|
|
163
|
+
export const _setOracle = (poolAddress, oracleAddress, methodName, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
curve.setContract(poolAddress, Plain2ETHOracleABIABI);
|
|
165
|
+
const poolContract = curve.contracts[poolAddress].contract;
|
|
166
|
+
const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
|
|
167
|
+
const _gas = yield poolContract.set_oracle.estimateGas(methodId, oracleAddress, curve.constantOptions);
|
|
168
|
+
if (estimateGas)
|
|
169
|
+
return Number(_gas);
|
|
170
|
+
const gasLimit = mulBy1_3(_gas);
|
|
171
|
+
yield curve.updateFeeData();
|
|
172
|
+
return yield poolContract.set_oracle(methodId, oracleAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
173
|
+
});
|
|
174
|
+
export const setOracleEstimateGas = (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
return yield _setOracle(poolAddress, oracleAddress, methodName, true);
|
|
176
|
+
});
|
|
177
|
+
export const setOracle = (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
return yield _setOracle(poolAddress, oracleAddress, methodName, false);
|
|
179
|
+
});
|
|
318
180
|
// ------- STABLE META POOLS -------
|
|
319
|
-
|
|
320
|
-
implementationIdx, estimateGas)
|
|
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
|
-
export var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
|
|
353
|
-
implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
354
|
-
return __generator(this, function (_a) {
|
|
355
|
-
switch (_a.label) {
|
|
356
|
-
case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
|
|
357
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
}); };
|
|
361
|
-
export var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
|
|
362
|
-
implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
363
|
-
return __generator(this, function (_a) {
|
|
364
|
-
switch (_a.label) {
|
|
365
|
-
case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
|
|
366
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}); };
|
|
370
|
-
var _deployStableNgMetaPool = function (basePool, name, symbol, coin, A, fee, // %
|
|
181
|
+
const _deployStableMetaPool = (basePool, name, symbol, coin, A, fee, // %
|
|
182
|
+
implementationIdx, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
+
if (name.length > 32)
|
|
184
|
+
throw Error("Max name length = 32");
|
|
185
|
+
if (symbol.length > 10)
|
|
186
|
+
throw Error("Max symbol length = 10");
|
|
187
|
+
if (BN(fee).lt(0.04))
|
|
188
|
+
throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
|
|
189
|
+
if (BN(fee).gt(1))
|
|
190
|
+
throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
|
|
191
|
+
if (![0, 1].includes(implementationIdx))
|
|
192
|
+
throw Error("Invalid implementationIdx. Must be one 0 or 1");
|
|
193
|
+
const _A = parseUnits(A, 0);
|
|
194
|
+
const _fee = parseUnits(fee, 8);
|
|
195
|
+
const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
|
|
196
|
+
const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions);
|
|
197
|
+
if (estimateGas)
|
|
198
|
+
return smartNumber(gas);
|
|
199
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
200
|
+
yield curve.updateFeeData();
|
|
201
|
+
return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
202
|
+
});
|
|
203
|
+
export const deployStableMetaPoolEstimateGas = (basePool, name, symbol, coin, A, fee, // %
|
|
204
|
+
implementationIdx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
|
+
return yield _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true);
|
|
206
|
+
});
|
|
207
|
+
export const deployStableMetaPool = (basePool, name, symbol, coin, A, fee, // %
|
|
208
|
+
implementationIdx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
return yield _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false);
|
|
210
|
+
});
|
|
211
|
+
const _deployStableNgMetaPool = (basePool, name, symbol, coin, A, fee, // %
|
|
371
212
|
offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
372
|
-
emaTime, // seconds
|
|
373
|
-
implementationIdx, methodName, oracleAddress, estimateGas) {
|
|
374
|
-
if (
|
|
375
|
-
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
contract = curve.contracts[curve.constants.ALIASES.stable_ng_factory].contract;
|
|
396
|
-
return [4 /*yield*/, contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, curve.constantOptions)];
|
|
397
|
-
case 1:
|
|
398
|
-
gas = _a.sent();
|
|
399
|
-
if (estimateGas)
|
|
400
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
401
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
402
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
403
|
-
case 2:
|
|
404
|
-
_a.sent();
|
|
405
|
-
return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
406
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
};
|
|
411
|
-
export var deployStableNgMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
|
|
213
|
+
emaTime = 600, // seconds
|
|
214
|
+
implementationIdx = 0, methodName = "0x00000000", oracleAddress = curve.constants.ZERO_ADDRESS, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
215
|
+
if (name.length > 32)
|
|
216
|
+
throw Error("Max name length = 32");
|
|
217
|
+
if (symbol.length > 10)
|
|
218
|
+
throw Error("Max symbol length = 10");
|
|
219
|
+
if (BN(fee).gt(1))
|
|
220
|
+
throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
|
|
221
|
+
if (![0, 1].includes(implementationIdx))
|
|
222
|
+
throw Error("Invalid implementationIdx. Must be one 0 or 1");
|
|
223
|
+
const _A = parseUnits(A, 0);
|
|
224
|
+
const _fee = parseUnits(fee, 8);
|
|
225
|
+
const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
|
|
226
|
+
const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
|
|
227
|
+
const contract = curve.contracts[curve.constants.ALIASES.stable_ng_factory].contract;
|
|
228
|
+
const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, curve.constantOptions);
|
|
229
|
+
if (estimateGas)
|
|
230
|
+
return smartNumber(gas);
|
|
231
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
232
|
+
yield curve.updateFeeData();
|
|
233
|
+
return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
234
|
+
});
|
|
235
|
+
export const deployStableNgMetaPoolEstimateGas = (basePool, name, symbol, coin, A, fee, // %
|
|
412
236
|
offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
413
237
|
emaTime, // seconds
|
|
414
|
-
implementationIdx, methodName, oracleAddress)
|
|
415
|
-
return
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}); };
|
|
422
|
-
export var deployStableNgMetaPool = function (basePool, name, symbol, coin, A, fee, // %
|
|
238
|
+
implementationIdx, methodName, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
239
|
+
return yield _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, true);
|
|
240
|
+
});
|
|
241
|
+
export const deployStableNgMetaPool = (basePool, name, symbol, coin, A, fee, // %
|
|
423
242
|
offpegFeeMultiplier, emaTime, // seconds
|
|
424
243
|
implementationIdx, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
|
|
425
|
-
methodName, oracleAddress)
|
|
426
|
-
return
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
case 0: return [4 /*yield*/, tx.wait()];
|
|
438
|
-
case 1:
|
|
439
|
-
txInfo = _a.sent();
|
|
440
|
-
if (!txInfo)
|
|
441
|
-
throw Error("Can't get tx info");
|
|
442
|
-
for (i = txInfo.logs.length - 1; i > -1; i--) {
|
|
443
|
-
if ("args" in txInfo.logs[i]) {
|
|
444
|
-
basePoolId = getPoolIdBySwapAddress(txInfo.logs[i].args[1]);
|
|
445
|
-
basePool = getPool(basePoolId);
|
|
446
|
-
return [2 /*return*/, txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase()];
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
throw Error("Can't get deployed metapool address");
|
|
244
|
+
methodName, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
return yield _deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, false);
|
|
246
|
+
});
|
|
247
|
+
export const getDeployedStableMetaPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
248
|
+
const txInfo = yield tx.wait();
|
|
249
|
+
if (!txInfo)
|
|
250
|
+
throw Error("Can't get tx info");
|
|
251
|
+
for (let i = txInfo.logs.length - 1; i > -1; i--) {
|
|
252
|
+
if ("args" in txInfo.logs[i]) {
|
|
253
|
+
const basePoolId = getPoolIdBySwapAddress(txInfo.logs[i].args[1]);
|
|
254
|
+
const basePool = getPool(basePoolId);
|
|
255
|
+
return txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase();
|
|
450
256
|
}
|
|
451
|
-
}
|
|
452
|
-
|
|
257
|
+
}
|
|
258
|
+
throw Error("Can't get deployed metapool address");
|
|
259
|
+
});
|
|
453
260
|
// ------- CRYPTO POOLS -------
|
|
454
|
-
|
|
261
|
+
const _deployCryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
455
262
|
outFee, // %
|
|
456
263
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
457
|
-
initialPrice, estimateGas)
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
522
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
523
|
-
case 2:
|
|
524
|
-
_a.sent();
|
|
525
|
-
return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
|
|
526
|
-
_maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
527
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
}); };
|
|
531
|
-
export var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
|
|
264
|
+
initialPrice, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
if (name.length > 32)
|
|
266
|
+
throw Error("Max name length = 32");
|
|
267
|
+
if (symbol.length > 10)
|
|
268
|
+
throw Error("Max symbol length = 10");
|
|
269
|
+
if (coins.length !== 2)
|
|
270
|
+
throw Error("Invalid number of coins. Must be 2");
|
|
271
|
+
if (coins[0] === coins[1])
|
|
272
|
+
throw Error("Coins must be different");
|
|
273
|
+
if (BN(A).lt(4000))
|
|
274
|
+
throw Error(`A must be >= 4000. Passed A = ${A}`);
|
|
275
|
+
if (BN(A).gt(4 * (Math.pow(10, 9))))
|
|
276
|
+
throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
|
|
277
|
+
if (BN(gamma).lt(1e-8))
|
|
278
|
+
throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
|
|
279
|
+
if (BN(gamma).gt(0.02))
|
|
280
|
+
throw Error(`gamma must be <= 0.02. Passed gamma = ${gamma}`);
|
|
281
|
+
if (BN(midFee).lt(0.005))
|
|
282
|
+
throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
|
|
283
|
+
if (BN(midFee).gt(100))
|
|
284
|
+
throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
|
|
285
|
+
if (BN(outFee).lt(BN(midFee)))
|
|
286
|
+
throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
|
|
287
|
+
if (BN(outFee).gt(100))
|
|
288
|
+
throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
|
|
289
|
+
if (BN(allowedExtraProfit).lt(0))
|
|
290
|
+
throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
291
|
+
if (BN(allowedExtraProfit).gt(0.01))
|
|
292
|
+
throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
293
|
+
if (BN(feeGamma).lt(0))
|
|
294
|
+
throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
|
|
295
|
+
if (BN(feeGamma).gt(1))
|
|
296
|
+
throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
|
|
297
|
+
if (BN(adjustmentStep).lt(0))
|
|
298
|
+
throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
|
|
299
|
+
if (BN(adjustmentStep).gt(1))
|
|
300
|
+
throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
|
|
301
|
+
if (BN(maHalfTime).lt(0))
|
|
302
|
+
throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
|
|
303
|
+
if (BN(maHalfTime).gt(604800))
|
|
304
|
+
throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
|
|
305
|
+
if (BN(initialPrice).lt(1e-12))
|
|
306
|
+
throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
|
|
307
|
+
if (BN(initialPrice).gt(1e12))
|
|
308
|
+
throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
|
|
309
|
+
const _A = parseUnits(A, 0);
|
|
310
|
+
const _gamma = parseUnits(gamma);
|
|
311
|
+
const _midFee = parseUnits(midFee, 8);
|
|
312
|
+
const _outFee = parseUnits(outFee, 8);
|
|
313
|
+
const _allowedExtraProfit = parseUnits(allowedExtraProfit);
|
|
314
|
+
const _feeGamma = parseUnits(feeGamma);
|
|
315
|
+
const _adjustmentStep = parseUnits(adjustmentStep);
|
|
316
|
+
const _maHalfTime = parseUnits(maHalfTime, 0);
|
|
317
|
+
const _initialPrice = parseUnits(initialPrice);
|
|
318
|
+
const contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
|
|
319
|
+
const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions);
|
|
320
|
+
if (estimateGas)
|
|
321
|
+
return smartNumber(gas);
|
|
322
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
323
|
+
yield curve.updateFeeData();
|
|
324
|
+
return yield contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
|
|
325
|
+
_maHalfTime, _initialPrice, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
326
|
+
});
|
|
327
|
+
export const deployCryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
|
|
532
328
|
outFee, // %
|
|
533
329
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
534
|
-
initialPrice)
|
|
535
|
-
return
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
}); };
|
|
542
|
-
export var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
|
|
330
|
+
initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
|
+
return yield _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
|
|
332
|
+
});
|
|
333
|
+
export const deployCryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
543
334
|
outFee, // %
|
|
544
335
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
545
|
-
initialPrice)
|
|
546
|
-
return
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
switch (_a.label) {
|
|
557
|
-
case 0: return [4 /*yield*/, tx.wait()];
|
|
558
|
-
case 1:
|
|
559
|
-
txInfo = _a.sent();
|
|
560
|
-
if (!txInfo)
|
|
561
|
-
throw Error("Can't get tx info");
|
|
562
|
-
lpTokenAddress = txInfo.logs[0].address;
|
|
563
|
-
contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
|
|
564
|
-
return [4 /*yield*/, contract.minter(curve.constantOptions)];
|
|
565
|
-
case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
|
|
566
|
-
}
|
|
567
|
-
});
|
|
568
|
-
}); };
|
|
336
|
+
initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
|
+
return yield _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
|
|
338
|
+
});
|
|
339
|
+
export const getDeployedCryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
+
const txInfo = yield tx.wait();
|
|
341
|
+
if (!txInfo)
|
|
342
|
+
throw Error("Can't get tx info");
|
|
343
|
+
const lpTokenAddress = txInfo.logs[0].address;
|
|
344
|
+
const contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
|
|
345
|
+
return (yield contract.minter(curve.constantOptions)).toLowerCase();
|
|
346
|
+
});
|
|
569
347
|
// ------- TWOCRYPTO POOLS -------
|
|
570
|
-
|
|
348
|
+
const _deployTwocryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
571
349
|
outFee, // %
|
|
572
350
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
573
|
-
initialPrice, estimateGas)
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
639
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
640
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
641
|
-
case 2:
|
|
642
|
-
_a.sent();
|
|
643
|
-
return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
644
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
}); };
|
|
648
|
-
export var deployTwocryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
|
|
351
|
+
initialPrice, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
352
|
+
if (name.length > 32)
|
|
353
|
+
throw Error("Max name length = 32");
|
|
354
|
+
if (symbol.length > 10)
|
|
355
|
+
throw Error("Max symbol length = 10");
|
|
356
|
+
if (coins.length !== 2)
|
|
357
|
+
throw Error("Invalid number of coins. Must be 2");
|
|
358
|
+
if (coins[0] === coins[1])
|
|
359
|
+
throw Error("Coins must be different");
|
|
360
|
+
if (BN(A).lt(4000))
|
|
361
|
+
throw Error(`A must be >= 4000. Passed A = ${A}`);
|
|
362
|
+
if (BN(A).gt(4 * (Math.pow(10, 9))))
|
|
363
|
+
throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
|
|
364
|
+
const MIN_GAMMA = BN((Math.pow(10, 10)) / (Math.pow(10, 18)));
|
|
365
|
+
const MAX_GAMMA = BN(199 * (Math.pow(10, 15)) / (Math.pow(10, 18)));
|
|
366
|
+
if (BN(gamma).lt(MIN_GAMMA))
|
|
367
|
+
throw Error(`gamma must be >= ${MIN_GAMMA}. Passed gamma = ${gamma}`);
|
|
368
|
+
if (BN(gamma).gt(MAX_GAMMA))
|
|
369
|
+
throw Error(`gamma must be <= ${MAX_GAMMA}. Passed gamma = ${gamma}`);
|
|
370
|
+
if (BN(midFee).lt(0.005))
|
|
371
|
+
throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
|
|
372
|
+
if (BN(midFee).gt(100))
|
|
373
|
+
throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
|
|
374
|
+
if (BN(outFee).lt(BN(midFee)))
|
|
375
|
+
throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
|
|
376
|
+
if (BN(outFee).gt(100))
|
|
377
|
+
throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
|
|
378
|
+
if (BN(allowedExtraProfit).lt(0))
|
|
379
|
+
throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
380
|
+
if (BN(allowedExtraProfit).gt(0.01))
|
|
381
|
+
throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
382
|
+
if (BN(feeGamma).lt(0))
|
|
383
|
+
throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
|
|
384
|
+
if (BN(feeGamma).gt(1))
|
|
385
|
+
throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
|
|
386
|
+
if (BN(adjustmentStep).lt(0))
|
|
387
|
+
throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
|
|
388
|
+
if (BN(adjustmentStep).gt(1))
|
|
389
|
+
throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
|
|
390
|
+
if (BN(maHalfTime).lt(0))
|
|
391
|
+
throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
|
|
392
|
+
if (BN(maHalfTime).gt(604800))
|
|
393
|
+
throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
|
|
394
|
+
if (BN(initialPrice).lt(1e-12))
|
|
395
|
+
throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
|
|
396
|
+
if (BN(initialPrice).gt(1e12))
|
|
397
|
+
throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
|
|
398
|
+
const _A = parseUnits(A, 0);
|
|
399
|
+
const _gamma = parseUnits(gamma);
|
|
400
|
+
const _midFee = parseUnits(midFee, 8);
|
|
401
|
+
const _outFee = parseUnits(outFee, 8);
|
|
402
|
+
const _allowedExtraProfit = parseUnits(allowedExtraProfit);
|
|
403
|
+
const _feeGamma = parseUnits(feeGamma);
|
|
404
|
+
const _adjustmentStep = parseUnits(adjustmentStep);
|
|
405
|
+
const _maHalfTime = parseUnits(maHalfTime, 0);
|
|
406
|
+
const _initialPrice = parseUnits(initialPrice);
|
|
407
|
+
const contract = curve.contracts[curve.constants.ALIASES.twocrypto_factory].contract;
|
|
408
|
+
const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, curve.constantOptions);
|
|
409
|
+
if (estimateGas)
|
|
410
|
+
return smartNumber(gas);
|
|
411
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
412
|
+
yield curve.updateFeeData();
|
|
413
|
+
return yield contract.deploy_pool(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
414
|
+
});
|
|
415
|
+
export const deployTwocryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
|
|
649
416
|
outFee, // %
|
|
650
417
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
651
|
-
initialPrice)
|
|
652
|
-
return
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
}); };
|
|
659
|
-
export var deployTwocryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
|
|
418
|
+
initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
419
|
+
return yield _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
|
|
420
|
+
});
|
|
421
|
+
export const deployTwocryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
660
422
|
outFee, // %
|
|
661
423
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
662
|
-
initialPrice)
|
|
663
|
-
return
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
switch (_a.label) {
|
|
674
|
-
case 0: return [4 /*yield*/, tx.wait()];
|
|
675
|
-
case 1:
|
|
676
|
-
txInfo = _a.sent();
|
|
677
|
-
if (!txInfo)
|
|
678
|
-
throw Error("Can't get tx info");
|
|
679
|
-
for (i = txInfo.logs.length - 1; i > -1; i--) {
|
|
680
|
-
if ("args" in txInfo.logs[i]) {
|
|
681
|
-
// @ts-ignore
|
|
682
|
-
return [2 /*return*/, txInfo.logs[i].args[0]];
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
throw Error("Can't get deployed tricrypto pool address");
|
|
424
|
+
initialPrice) => __awaiter(void 0, void 0, void 0, function* () {
|
|
425
|
+
return yield _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
|
|
426
|
+
});
|
|
427
|
+
export const getDeployedTwocryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
428
|
+
const txInfo = yield tx.wait();
|
|
429
|
+
if (!txInfo)
|
|
430
|
+
throw Error("Can't get tx info");
|
|
431
|
+
for (let i = txInfo.logs.length - 1; i > -1; i--) {
|
|
432
|
+
if ("args" in txInfo.logs[i]) {
|
|
433
|
+
// @ts-ignore
|
|
434
|
+
return txInfo.logs[i].args[0];
|
|
686
435
|
}
|
|
687
|
-
}
|
|
688
|
-
|
|
436
|
+
}
|
|
437
|
+
throw Error("Can't get deployed tricrypto pool address");
|
|
438
|
+
});
|
|
689
439
|
// ------- TRICRYPTO POOLS -------
|
|
690
|
-
|
|
440
|
+
const _deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
691
441
|
outFee, // %
|
|
692
442
|
allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
|
|
693
|
-
initialPrices, estimateGas)
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
763
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
764
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
765
|
-
case 2:
|
|
766
|
-
_a.sent();
|
|
767
|
-
return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
768
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
}); };
|
|
772
|
-
export var deployTricryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
|
|
443
|
+
initialPrices, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
444
|
+
if (name.length > 64)
|
|
445
|
+
throw Error("Max name length = 64");
|
|
446
|
+
if (symbol.length > 32)
|
|
447
|
+
throw Error("Max symbol length = 32");
|
|
448
|
+
if (coins.length !== 3)
|
|
449
|
+
throw Error("Invalid number of coins. Must be 3");
|
|
450
|
+
if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
|
|
451
|
+
throw Error("Coins must be different");
|
|
452
|
+
if (BN(A).lt(2700))
|
|
453
|
+
throw Error(`A must be >= 2700. Passed A = ${A}`);
|
|
454
|
+
if (BN(A).gt(27 * (Math.pow(10, 7))))
|
|
455
|
+
throw Error(`A must be <= 27 * 10 ** 7. Passed A = ${A}`);
|
|
456
|
+
if (BN(gamma).lt(1e-8))
|
|
457
|
+
throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
|
|
458
|
+
if (BN(gamma).gt(0.05))
|
|
459
|
+
throw Error(`gamma must be <= 0.05. Passed gamma = ${gamma}`);
|
|
460
|
+
if (BN(midFee).lt(0))
|
|
461
|
+
throw Error(`midFee must be >= 0. Passed midFee = ${midFee}`);
|
|
462
|
+
if (BN(midFee).gt(100))
|
|
463
|
+
throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
|
|
464
|
+
if (BN(outFee).lt(BN(midFee)))
|
|
465
|
+
throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
|
|
466
|
+
if (BN(outFee).gt(100))
|
|
467
|
+
throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
|
|
468
|
+
if (BN(allowedExtraProfit).lt(0))
|
|
469
|
+
throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
470
|
+
if (BN(allowedExtraProfit).gt(1))
|
|
471
|
+
throw Error(`allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ${allowedExtraProfit}`);
|
|
472
|
+
if (BN(feeGamma).lt(0))
|
|
473
|
+
throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
|
|
474
|
+
if (BN(feeGamma).gt(1))
|
|
475
|
+
throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
|
|
476
|
+
if (BN(adjustmentStep).lt(0))
|
|
477
|
+
throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
|
|
478
|
+
if (BN(adjustmentStep).gt(1))
|
|
479
|
+
throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
|
|
480
|
+
if (BN(emaTime).lt(60))
|
|
481
|
+
throw Error(`maHalfTime must be >= 60. Passed maHalfTime=${emaTime}`);
|
|
482
|
+
if (BN(emaTime).gt(604800))
|
|
483
|
+
throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${emaTime}`);
|
|
484
|
+
if (initialPrices.length !== 2)
|
|
485
|
+
throw Error("Invalid number of initial prices. Must be 2");
|
|
486
|
+
if (BN(initialPrices[0]).lt(1e-12))
|
|
487
|
+
throw Error(`initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=${initialPrices[0]}`);
|
|
488
|
+
if (BN(initialPrices[0]).gt(1e12))
|
|
489
|
+
throw Error(`initialPrices[0] must be <= 1e12. Passed initialPrices[0]=${initialPrices[0]}`);
|
|
490
|
+
if (BN(initialPrices[1]).lt(1e-12))
|
|
491
|
+
throw Error(`initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=${initialPrices[1]}`);
|
|
492
|
+
if (BN(initialPrices[1]).gt(1e12))
|
|
493
|
+
throw Error(`initialPrices[1] must be <= 1e12. Passed initialPrices[1]=${initialPrices[1]}`);
|
|
494
|
+
const _A = parseUnits(A, 0);
|
|
495
|
+
const _gamma = parseUnits(gamma);
|
|
496
|
+
const _midFee = parseUnits(midFee, 8);
|
|
497
|
+
const _outFee = parseUnits(outFee, 8);
|
|
498
|
+
const _allowedExtraProfit = parseUnits(allowedExtraProfit);
|
|
499
|
+
const _feeGamma = parseUnits(feeGamma);
|
|
500
|
+
const _adjustmentStep = parseUnits(adjustmentStep);
|
|
501
|
+
const _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
|
|
502
|
+
const _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
|
|
503
|
+
const contract = curve.contracts[curve.constants.ALIASES.tricrypto_factory].contract;
|
|
504
|
+
const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, curve.constants.ZERO_ADDRESS, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, curve.constantOptions);
|
|
505
|
+
if (estimateGas)
|
|
506
|
+
return smartNumber(gas);
|
|
507
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
508
|
+
yield curve.updateFeeData();
|
|
509
|
+
return yield contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, tricryptoDeployImplementations[curve.chainId].implementationIdx, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
510
|
+
});
|
|
511
|
+
export const deployTricryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
|
|
773
512
|
outFee, // %
|
|
774
513
|
allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
|
|
775
|
-
initialPrices)
|
|
776
|
-
return
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
}); };
|
|
783
|
-
export var deployTricryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
|
|
514
|
+
initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
515
|
+
return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true);
|
|
516
|
+
});
|
|
517
|
+
export const deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
|
|
784
518
|
outFee, // %
|
|
785
519
|
allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
|
|
786
|
-
initialPrices)
|
|
787
|
-
return
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
switch (_a.label) {
|
|
798
|
-
case 0: return [4 /*yield*/, tx.wait()];
|
|
799
|
-
case 1:
|
|
800
|
-
txInfo = _a.sent();
|
|
801
|
-
if (!txInfo)
|
|
802
|
-
throw Error("Can't get tx info");
|
|
803
|
-
for (i = txInfo.logs.length - 1; i > -1; i--) {
|
|
804
|
-
if ("args" in txInfo.logs[i]) {
|
|
805
|
-
// @ts-ignore
|
|
806
|
-
return [2 /*return*/, txInfo.logs[i].args[0]];
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
throw Error("Can't get deployed tricrypto pool address");
|
|
810
|
-
}
|
|
811
|
-
});
|
|
812
|
-
}); };
|
|
813
|
-
// ------- GAUGE -------
|
|
814
|
-
var _deployGauge = function (pool, factory, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
815
|
-
var contract, gas, gasLimit;
|
|
816
|
-
return __generator(this, function (_a) {
|
|
817
|
-
switch (_a.label) {
|
|
818
|
-
case 0:
|
|
819
|
-
if (curve.chainId !== 1)
|
|
820
|
-
throw Error("There is no deployGauge method on sidechain network");
|
|
821
|
-
contract = curve.contracts[factory].contract;
|
|
822
|
-
return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, curve.constantOptions)];
|
|
823
|
-
case 1:
|
|
824
|
-
gas = _a.sent();
|
|
825
|
-
if (estimateGas)
|
|
826
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
827
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
828
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
829
|
-
case 2:
|
|
830
|
-
_a.sent();
|
|
831
|
-
return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
832
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
520
|
+
initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
|
|
521
|
+
return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false);
|
|
522
|
+
});
|
|
523
|
+
export const getDeployedTricryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
524
|
+
const txInfo = yield tx.wait();
|
|
525
|
+
if (!txInfo)
|
|
526
|
+
throw Error("Can't get tx info");
|
|
527
|
+
for (let i = txInfo.logs.length - 1; i > -1; i--) {
|
|
528
|
+
if ("args" in txInfo.logs[i]) {
|
|
529
|
+
// @ts-ignore
|
|
530
|
+
return txInfo.logs[i].args[0];
|
|
833
531
|
}
|
|
834
|
-
});
|
|
835
|
-
}); };
|
|
836
|
-
var _deployGaugeSidechain = function (pool, salt, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
837
|
-
var contract, _salt, gas, gasLimit;
|
|
838
|
-
return __generator(this, function (_a) {
|
|
839
|
-
switch (_a.label) {
|
|
840
|
-
case 0:
|
|
841
|
-
if (curve.chainId === 1)
|
|
842
|
-
throw Error("There is no deployGaugeSidechain method on ethereum network");
|
|
843
|
-
contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
|
|
844
|
-
_salt = ethers.encodeBytes32String(salt);
|
|
845
|
-
return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), curve.signerAddress, curve.constantOptions)];
|
|
846
|
-
case 1:
|
|
847
|
-
gas = _a.sent();
|
|
848
|
-
if (estimateGas)
|
|
849
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
850
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
851
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
852
|
-
case 2:
|
|
853
|
-
_a.sent();
|
|
854
|
-
return [4 /*yield*/, contract.deploy_gauge(pool, Typed.bytes32(_salt), curve.signerAddress, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
855
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
}); };
|
|
859
|
-
var _deployGaugeMirror = function (chainId, salt, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
860
|
-
var contract, _salt, gas, gasLimit;
|
|
861
|
-
return __generator(this, function (_a) {
|
|
862
|
-
switch (_a.label) {
|
|
863
|
-
case 0:
|
|
864
|
-
if (curve.chainId !== 1)
|
|
865
|
-
throw Error("There is no deployGaugeMirror method on sidechain network");
|
|
866
|
-
contract = chainId === 252 ? curve.contracts[curve.constants.ALIASES.gauge_factory_fraxtal].contract : curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
|
|
867
|
-
_salt = ethers.encodeBytes32String(salt);
|
|
868
|
-
return [4 /*yield*/, contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), curve.constantOptions)];
|
|
869
|
-
case 1:
|
|
870
|
-
gas = _a.sent();
|
|
871
|
-
if (estimateGas)
|
|
872
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
873
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
874
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
875
|
-
case 2:
|
|
876
|
-
_a.sent();
|
|
877
|
-
return [4 /*yield*/, contract.deploy_gauge(chainId, Typed.bytes32(_salt), __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
878
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
}); };
|
|
882
|
-
export var deployGaugeEstimateGas = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
883
|
-
switch (_a.label) {
|
|
884
|
-
case 0: return [4 /*yield*/, _deployGauge(pool, factory, true)];
|
|
885
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
886
|
-
}
|
|
887
|
-
}); }); };
|
|
888
|
-
export var deployGauge = function (pool, factory) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
889
|
-
switch (_a.label) {
|
|
890
|
-
case 0: return [4 /*yield*/, _deployGauge(pool, factory, false)];
|
|
891
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
892
532
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
})
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
export
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
return
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
return [4 /*yield*/, contract.get_gauge(chainId, currentIndex)];
|
|
962
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
}); };
|
|
533
|
+
throw Error("Can't get deployed tricrypto pool address");
|
|
534
|
+
});
|
|
535
|
+
// ------- GAUGE -------
|
|
536
|
+
const _deployGauge = (pool, factory, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
537
|
+
if (curve.chainId !== 1)
|
|
538
|
+
throw Error("There is no deployGauge method on sidechain network");
|
|
539
|
+
const contract = curve.contracts[factory].contract;
|
|
540
|
+
const gas = yield contract.deploy_gauge.estimateGas(pool, curve.constantOptions);
|
|
541
|
+
if (estimateGas)
|
|
542
|
+
return smartNumber(gas);
|
|
543
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
544
|
+
yield curve.updateFeeData();
|
|
545
|
+
return yield contract.deploy_gauge(pool, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
546
|
+
});
|
|
547
|
+
const _deployGaugeSidechain = (pool, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
548
|
+
if (curve.chainId === 1)
|
|
549
|
+
throw Error("There is no deployGaugeSidechain method on ethereum network");
|
|
550
|
+
const contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
|
|
551
|
+
const _salt = ethers.encodeBytes32String(salt);
|
|
552
|
+
const gas = yield contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), curve.signerAddress, curve.constantOptions);
|
|
553
|
+
if (estimateGas)
|
|
554
|
+
return smartNumber(gas);
|
|
555
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
556
|
+
yield curve.updateFeeData();
|
|
557
|
+
return yield contract.deploy_gauge(pool, Typed.bytes32(_salt), curve.signerAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
558
|
+
});
|
|
559
|
+
const _deployGaugeMirror = (chainId, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
|
|
560
|
+
if (curve.chainId !== 1)
|
|
561
|
+
throw Error("There is no deployGaugeMirror method on sidechain network");
|
|
562
|
+
const contract = chainId === 252 ? curve.contracts[curve.constants.ALIASES.gauge_factory_fraxtal].contract : curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
|
|
563
|
+
const _salt = ethers.encodeBytes32String(salt);
|
|
564
|
+
const gas = yield contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), curve.constantOptions);
|
|
565
|
+
if (estimateGas)
|
|
566
|
+
return smartNumber(gas);
|
|
567
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
568
|
+
yield curve.updateFeeData();
|
|
569
|
+
return yield contract.deploy_gauge(chainId, Typed.bytes32(_salt), Object.assign(Object.assign({}, curve.options), { gasLimit }));
|
|
570
|
+
});
|
|
571
|
+
export const deployGaugeEstimateGas = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, true); });
|
|
572
|
+
export const deployGauge = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, false); });
|
|
573
|
+
export const deployGaugeSidechainEstimateGas = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, true); });
|
|
574
|
+
export const deployGaugeSidechain = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, false); });
|
|
575
|
+
export const deployGaugeMirrorEstimateGas = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, true); });
|
|
576
|
+
export const deployGaugeMirror = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, false); });
|
|
577
|
+
export const getDeployedGaugeAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
578
|
+
const txInfo = yield tx.wait();
|
|
579
|
+
if (!txInfo)
|
|
580
|
+
throw Error("Can't get tx info");
|
|
581
|
+
// @ts-ignore
|
|
582
|
+
return txInfo.logs[0].args[txInfo.logs[0].args.length - 1].toLowerCase();
|
|
583
|
+
});
|
|
584
|
+
export const getDeployedGaugeMirrorAddressByTx = (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
585
|
+
if (curve.chainId !== 1)
|
|
586
|
+
throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
|
|
587
|
+
const txInfo = yield tx.wait();
|
|
588
|
+
if (!txInfo)
|
|
589
|
+
throw Error("Can't get tx info");
|
|
590
|
+
// @ts-ignore
|
|
591
|
+
return txInfo.logs[1].args[txInfo.logs[1].args.length - 1].toLowerCase();
|
|
592
|
+
});
|
|
593
|
+
export const getDeployedGaugeMirrorAddress = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
594
|
+
if (curve.chainId !== 1)
|
|
595
|
+
throw Error("There is no getDeployedGaugeMirrorAddress method on sidechain network");
|
|
596
|
+
const contract = curve.contracts[curve.constants.ALIASES.gauge_factory].contract;
|
|
597
|
+
const gaugeCount = yield contract.get_gauge_count(chainId);
|
|
598
|
+
const currentIndex = Number(gaugeCount) - 1;
|
|
599
|
+
return yield contract.get_gauge(chainId, currentIndex);
|
|
600
|
+
});
|