@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.
Files changed (100) hide show
  1. package/lib/boosting.js +137 -402
  2. package/lib/constants/abis/avaxcrypto/swap.json +1195 -0
  3. package/lib/constants/abis/avaxcrypto/zap.json +250 -0
  4. package/lib/constants/aliases.d.ts +11 -11
  5. package/lib/constants/aliases.js +12 -15
  6. package/lib/constants/coins/arbitrum.js +6 -9
  7. package/lib/constants/coins/aurora.js +6 -9
  8. package/lib/constants/coins/avalanche.js +12 -10
  9. package/lib/constants/coins/celo.js +6 -9
  10. package/lib/constants/coins/ethereum.js +10 -13
  11. package/lib/constants/coins/fantom.js +8 -11
  12. package/lib/constants/coins/kava.js +6 -9
  13. package/lib/constants/coins/moonbeam.js +6 -9
  14. package/lib/constants/coins/optimism.js +6 -9
  15. package/lib/constants/coins/polygon.js +7 -10
  16. package/lib/constants/coins/xdai.js +6 -9
  17. package/lib/constants/pools/arbitrum.d.ts +2 -4
  18. package/lib/constants/pools/arbitrum.js +22 -28
  19. package/lib/constants/pools/aurora.d.ts +2 -4
  20. package/lib/constants/pools/aurora.js +6 -12
  21. package/lib/constants/pools/avalanche.d.ts +2 -4
  22. package/lib/constants/pools/avalanche.js +51 -22
  23. package/lib/constants/pools/celo.d.ts +2 -4
  24. package/lib/constants/pools/celo.js +2 -5
  25. package/lib/constants/pools/ethereum.js +247 -253
  26. package/lib/constants/pools/fantom.d.ts +2 -4
  27. package/lib/constants/pools/fantom.js +28 -34
  28. package/lib/constants/pools/index.d.ts +11 -11
  29. package/lib/constants/pools/index.js +12 -25
  30. package/lib/constants/pools/kava.d.ts +2 -4
  31. package/lib/constants/pools/kava.js +2 -5
  32. package/lib/constants/pools/moonbeam.d.ts +2 -4
  33. package/lib/constants/pools/moonbeam.js +6 -12
  34. package/lib/constants/pools/optimism.d.ts +2 -4
  35. package/lib/constants/pools/optimism.js +9 -15
  36. package/lib/constants/pools/polygon.d.ts +2 -4
  37. package/lib/constants/pools/polygon.js +23 -28
  38. package/lib/constants/pools/xdai.d.ts +2 -4
  39. package/lib/constants/pools/xdai.js +25 -30
  40. package/lib/constants/utils.js +20 -29
  41. package/lib/curve.d.ts +9 -7
  42. package/lib/curve.js +397 -615
  43. package/lib/external-api.d.ts +1 -1
  44. package/lib/external-api.js +47 -140
  45. package/lib/factory/common.js +6 -10
  46. package/lib/factory/constants-crypto.js +48 -54
  47. package/lib/factory/constants.js +274 -280
  48. package/lib/factory/deploy.d.ts +8 -8
  49. package/lib/factory/deploy.js +177 -347
  50. package/lib/factory/factory-api.js +195 -278
  51. package/lib/factory/factory-crypto.js +170 -323
  52. package/lib/factory/factory.js +195 -350
  53. package/lib/index.d.ts +24 -25
  54. package/lib/index.js +87 -143
  55. package/lib/interfaces.d.ts +6 -5
  56. package/lib/interfaces.js +1 -2
  57. package/lib/pools/PoolTemplate.d.ts +1 -0
  58. package/lib/pools/PoolTemplate.js +1516 -2928
  59. package/lib/pools/index.d.ts +2 -2
  60. package/lib/pools/index.js +3 -7
  61. package/lib/pools/mixins/common.d.ts +3 -4
  62. package/lib/pools/mixins/common.js +23 -102
  63. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
  64. package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
  65. package/lib/pools/mixins/depositMixins.d.ts +1 -1
  66. package/lib/pools/mixins/depositMixins.js +145 -405
  67. package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
  68. package/lib/pools/mixins/depositWrappedMixins.js +72 -227
  69. package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -2
  70. package/lib/pools/mixins/poolBalancesMixin.js +25 -131
  71. package/lib/pools/mixins/swapMixins.d.ts +1 -1
  72. package/lib/pools/mixins/swapMixins.js +127 -353
  73. package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
  74. package/lib/pools/mixins/swapWrappedMixins.js +90 -276
  75. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -2
  76. package/lib/pools/mixins/withdrawExpectedMixins.js +26 -154
  77. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
  78. package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
  79. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
  80. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
  81. package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
  82. package/lib/pools/mixins/withdrawMixins.js +124 -378
  83. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
  84. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
  85. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
  86. package/lib/pools/mixins/withdrawOneCoinMixins.js +125 -378
  87. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
  88. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
  89. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
  90. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
  91. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
  92. package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
  93. package/lib/pools/poolConstructor.d.ts +1 -1
  94. package/lib/pools/poolConstructor.js +79 -109
  95. package/lib/pools/utils.js +298 -500
  96. package/lib/router.d.ts +2 -2
  97. package/lib/router.js +406 -650
  98. package/lib/utils.d.ts +9 -9
  99. package/lib/utils.js +377 -731
  100. package/package.json +8 -8
@@ -1,13 +1,13 @@
1
1
  import { ethers } from "ethers";
2
2
  export declare const deployStablePlainPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<number>;
3
- export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<ethers.ContractTransaction>;
4
- export declare const getDeployedStablePlainPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
3
+ export declare const deployStablePlainPool: (name: string, symbol: string, coins: string[], A: number | string, fee: number | string, assetType: 0 | 1 | 2 | 3, implementationIdx: 0 | 1 | 2 | 3) => Promise<ethers.ContractTransactionResponse>;
4
+ export declare const getDeployedStablePlainPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
5
5
  export declare const deployStableMetaPoolEstimateGas: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<number>;
6
- export declare const deployStableMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<ethers.ContractTransaction>;
7
- export declare const getDeployedStableMetaPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
6
+ export declare const deployStableMetaPool: (basePool: string, name: string, symbol: string, coin: string, A: number | string, fee: number | string, implementationIdx: 0 | 1) => Promise<ethers.ContractTransactionResponse>;
7
+ export declare const getDeployedStableMetaPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
8
8
  export declare const deployCryptoPoolEstimateGas: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number | string, initialPrice: number | string) => Promise<number>;
9
- export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number | string, initialPrice: number | string) => Promise<ethers.ContractTransaction>;
10
- export declare const getDeployedCryptoPoolAddress: (tx: ethers.ContractTransaction) => Promise<string>;
9
+ export declare const deployCryptoPool: (name: string, symbol: string, coins: string[], A: number | string, gamma: number | string, midFee: number | string, outFee: number | string, allowedExtraProfit: number | string, feeGamma: number | string, adjustmentStep: number | string, maHalfTime: number | string, initialPrice: number | string) => Promise<ethers.ContractTransactionResponse>;
10
+ export declare const getDeployedCryptoPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
11
11
  export declare const deployGaugeEstimateGas: (pool: string, isCrypto: boolean) => Promise<number>;
12
- export declare const deployGauge: (pool: string, isCrypto: boolean) => Promise<ethers.ContractTransaction>;
13
- export declare const getDeployedGaugeAddress: (tx: ethers.ContractTransaction) => Promise<string>;
12
+ export declare const deployGauge: (pool: string, isCrypto: boolean) => Promise<ethers.ContractTransactionResponse>;
13
+ export declare const getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
@@ -1,360 +1,190 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
1
+ import { Contract } from "ethers";
2
+ import { curve } from "../curve.js";
3
+ import { parseUnits, BN, mulBy1_3 } from "../utils.js";
4
+ import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert { type: 'json' };
5
+ // ------- STABLE PLAIN POOLS -------
6
+ const _deployStablePlainPool = async (name, symbol, coins, A, fee, // %
7
+ assetType, implementationIdx, estimateGas) => {
8
+ if (name.length > 32)
9
+ throw Error("Max name length = 32");
10
+ if (symbol.length > 10)
11
+ throw Error("Max symbol length = 10");
12
+ if (![2, 3, 4].includes(coins.length))
13
+ throw Error("Invalid number of coins. Must be 2, 3 or 4");
14
+ if (BN(fee).lt(0.04))
15
+ throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
16
+ if (BN(fee).gt(1))
17
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
18
+ if (![0, 1, 2, 3].includes(assetType))
19
+ throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
20
+ if (![0, 1, 2, 3].includes(implementationIdx))
21
+ throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
22
+ const _A = parseUnits(A, 0);
23
+ const _fee = parseUnits(fee, 8);
24
+ const _coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
25
+ const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
26
+ const gas = await contract.deploy_plain_pool.estimateGas(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve.constantOptions);
27
+ if (estimateGas)
28
+ return Number(gas);
29
+ const gasLimit = mulBy1_3(gas);
30
+ await curve.updateFeeData();
31
+ return await contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, { ...curve.options, gasLimit });
12
32
  };
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
- });
33
+ export const deployStablePlainPoolEstimateGas = async (name, symbol, coins, A, fee, // %
34
+ assetType, implementationIdx) => {
35
+ return await _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true);
21
36
  };
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
- }
37
+ export const deployStablePlainPool = async (name, symbol, coins, A, fee, // %
38
+ assetType, implementationIdx) => {
39
+ return await _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false);
48
40
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
41
+ export const getDeployedStablePlainPoolAddress = async (tx) => {
42
+ const txInfo = await tx.wait();
43
+ if (!txInfo)
44
+ throw Error("Can't get tx info");
45
+ return txInfo.logs[0].address.toLowerCase();
51
46
  };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.getDeployedGaugeAddress = exports.deployGauge = exports.deployGaugeEstimateGas = exports.getDeployedCryptoPoolAddress = exports.deployCryptoPool = exports.deployCryptoPoolEstimateGas = exports.getDeployedStableMetaPoolAddress = exports.deployStableMetaPool = exports.deployStableMetaPoolEstimateGas = exports.getDeployedStablePlainPoolAddress = exports.deployStablePlainPool = exports.deployStablePlainPoolEstimateGas = void 0;
54
- var ethers_1 = require("ethers");
55
- var curve_1 = require("../curve");
56
- var utils_1 = require("../utils");
57
- var curve_lp_token_v5_json_1 = __importDefault(require("../constants/abis/curve_lp_token_v5.json"));
58
- // ------- STABLE PLAIN POOLS -------
59
- var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
60
- assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
61
- var _A, _fee, _coins, contract, gas, gasLimit;
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- if (name.length > 32)
66
- throw Error("Max name length = 32");
67
- if (symbol.length > 10)
68
- throw Error("Max symbol length = 10");
69
- if (![2, 3, 4].includes(coins.length))
70
- throw Error("Invalid number of coins. Must be 2, 3 or 4");
71
- if ((0, utils_1.BN)(fee).lt(0.04))
72
- throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
73
- if ((0, utils_1.BN)(fee).gt(1))
74
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
75
- if (![0, 1, 2, 3].includes(assetType))
76
- throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
77
- if (![0, 1, 2, 3].includes(implementationIdx))
78
- throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
79
- _A = (0, utils_1.parseUnits)(A, 0);
80
- _fee = (0, utils_1.parseUnits)(fee, 8);
81
- _coins = coins.concat(Array(4 - coins.length).fill(ethers_1.ethers.constants.AddressZero));
82
- contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.factory].contract;
83
- return [4 /*yield*/, contract.estimateGas.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve_1.curve.constantOptions)];
84
- case 1:
85
- gas = _a.sent();
86
- if (estimateGas)
87
- return [2 /*return*/, gas.toNumber()];
88
- gasLimit = gas.mul(130).div(100);
89
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
90
- case 2:
91
- _a.sent();
92
- return [4 /*yield*/, contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
93
- case 3: return [2 /*return*/, _a.sent()];
94
- }
95
- });
96
- }); };
97
- var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
98
- assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- switch (_a.label) {
101
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true)];
102
- case 1: return [2 /*return*/, _a.sent()];
103
- }
104
- });
105
- }); };
106
- exports.deployStablePlainPoolEstimateGas = deployStablePlainPoolEstimateGas;
107
- var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
108
- assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false)];
112
- case 1: return [2 /*return*/, _a.sent()];
113
- }
114
- });
115
- }); };
116
- exports.deployStablePlainPool = deployStablePlainPool;
117
- var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
118
- var txInfo;
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0: return [4 /*yield*/, tx.wait()];
122
- case 1:
123
- txInfo = _a.sent();
124
- return [2 /*return*/, txInfo.logs[0].address.toLowerCase()];
125
- }
126
- });
127
- }); };
128
- exports.getDeployedStablePlainPoolAddress = getDeployedStablePlainPoolAddress;
129
47
  // ------- STABLE META POOLS -------
130
- var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
131
- implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
132
- var _A, _fee, contract, gas, gasLimit;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0:
136
- if (name.length > 32)
137
- throw Error("Max name length = 32");
138
- if (symbol.length > 10)
139
- throw Error("Max symbol length = 10");
140
- if ((0, utils_1.BN)(fee).lt(0.04))
141
- throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
142
- if ((0, utils_1.BN)(fee).gt(1))
143
- throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
144
- if (![0, 1].includes(implementationIdx))
145
- throw Error("Invalid implementationIdx. Must be one 0 or 1");
146
- _A = (0, utils_1.parseUnits)(A, 0);
147
- _fee = (0, utils_1.parseUnits)(fee, 8);
148
- contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.factory].contract;
149
- return [4 /*yield*/, contract.estimateGas.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve_1.curve.constantOptions)];
150
- case 1:
151
- gas = _a.sent();
152
- if (estimateGas)
153
- return [2 /*return*/, gas.toNumber()];
154
- gasLimit = gas.mul(130).div(100);
155
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
156
- case 2:
157
- _a.sent();
158
- return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
159
- case 3: return [2 /*return*/, _a.sent()];
160
- }
161
- });
162
- }); };
163
- var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
164
- implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
165
- return __generator(this, function (_a) {
166
- switch (_a.label) {
167
- case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
168
- case 1: return [2 /*return*/, _a.sent()];
169
- }
170
- });
171
- }); };
172
- exports.deployStableMetaPoolEstimateGas = deployStableMetaPoolEstimateGas;
173
- var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
174
- implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
178
- case 1: return [2 /*return*/, _a.sent()];
179
- }
180
- });
181
- }); };
182
- exports.deployStableMetaPool = deployStableMetaPool;
183
- var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
184
- var txInfo;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0: return [4 /*yield*/, tx.wait()];
188
- case 1:
189
- txInfo = _a.sent();
190
- return [2 /*return*/, txInfo.logs[3].address.toLowerCase()];
191
- }
192
- });
193
- }); };
194
- exports.getDeployedStableMetaPoolAddress = getDeployedStableMetaPoolAddress;
48
+ const _deployStableMetaPool = async (basePool, name, symbol, coin, A, fee, // %
49
+ implementationIdx, estimateGas) => {
50
+ if (name.length > 32)
51
+ throw Error("Max name length = 32");
52
+ if (symbol.length > 10)
53
+ throw Error("Max symbol length = 10");
54
+ if (BN(fee).lt(0.04))
55
+ throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
56
+ if (BN(fee).gt(1))
57
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
58
+ if (![0, 1].includes(implementationIdx))
59
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
60
+ const _A = parseUnits(A, 0);
61
+ const _fee = parseUnits(fee, 8);
62
+ const contract = curve.contracts[curve.constants.ALIASES.factory].contract;
63
+ const gas = await contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions);
64
+ if (estimateGas)
65
+ return Number(gas);
66
+ const gasLimit = mulBy1_3(gas);
67
+ await curve.updateFeeData();
68
+ return await contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, { ...curve.options, gasLimit });
69
+ };
70
+ export const deployStableMetaPoolEstimateGas = async (basePool, name, symbol, coin, A, fee, // %
71
+ implementationIdx) => {
72
+ return await _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true);
73
+ };
74
+ export const deployStableMetaPool = async (basePool, name, symbol, coin, A, fee, // %
75
+ implementationIdx) => {
76
+ return await _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false);
77
+ };
78
+ export const getDeployedStableMetaPoolAddress = async (tx) => {
79
+ const txInfo = await tx.wait();
80
+ if (!txInfo)
81
+ throw Error("Can't get tx info");
82
+ return txInfo.logs[3].address.toLowerCase();
83
+ };
195
84
  // ------- CRYPTO POOLS -------
196
- var _deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
85
+ const _deployCryptoPool = async (name, symbol, coins, A, gamma, midFee, // %
197
86
  outFee, // %
198
87
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
199
- initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
200
- var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _maHalfTime, _initialPrice, contract, gas, gasLimit;
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0:
204
- if (name.length > 32)
205
- throw Error("Max name length = 32");
206
- if (symbol.length > 10)
207
- throw Error("Max symbol length = 10");
208
- if (coins.length !== 2)
209
- throw Error("Invalid number of coins. Must be 2");
210
- if (coins[1] === coins[2])
211
- throw Error("Coins must be different");
212
- if ((0, utils_1.BN)(A).lt(4000))
213
- throw Error("A must be >= 4000. Passed A = ".concat(A));
214
- if ((0, utils_1.BN)(A).gt(4 * (Math.pow(10, 9))))
215
- throw Error("A must be <= 4 * 10 ** 9. Passed A = ".concat(A));
216
- if ((0, utils_1.BN)(gamma).lt(1e-8))
217
- throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
218
- if ((0, utils_1.BN)(gamma).gt(0.02))
219
- throw Error("gamma must be <= 0.02. Passed gamma = ".concat(gamma));
220
- if ((0, utils_1.BN)(midFee).lt(0.005))
221
- throw Error("midFee must be >= 0.005. Passed midFee = ".concat(midFee));
222
- if ((0, utils_1.BN)(midFee).gt(100))
223
- throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
224
- if ((0, utils_1.BN)(outFee).lt((0, utils_1.BN)(midFee)))
225
- throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
226
- if ((0, utils_1.BN)(outFee).gt(100))
227
- throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
228
- if ((0, utils_1.BN)(allowedExtraProfit).lt(0))
229
- throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
230
- if ((0, utils_1.BN)(allowedExtraProfit).gt(0.01))
231
- throw Error("allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
232
- if ((0, utils_1.BN)(feeGamma).lt(0))
233
- throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
234
- if ((0, utils_1.BN)(feeGamma).gt(1))
235
- throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
236
- if ((0, utils_1.BN)(adjustmentStep).lt(0))
237
- throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
238
- if ((0, utils_1.BN)(adjustmentStep).gt(1))
239
- throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
240
- if ((0, utils_1.BN)(maHalfTime).lt(0))
241
- throw Error("maHalfTime must be >= 0. Passed maHalfTime=".concat(maHalfTime));
242
- if ((0, utils_1.BN)(maHalfTime).gt(604800))
243
- throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(maHalfTime));
244
- if ((0, utils_1.BN)(initialPrice).lt(1e-12))
245
- throw Error("initialPrice must be >= 1e-12. Passed initialPrice=".concat(initialPrice));
246
- if ((0, utils_1.BN)(initialPrice).gt(1e12))
247
- throw Error("initialPrice must be <= 1e12. Passed initialPrice=".concat(initialPrice));
248
- _A = (0, utils_1.parseUnits)(A, 0);
249
- _gamma = (0, utils_1.parseUnits)(gamma);
250
- _midFee = (0, utils_1.parseUnits)(midFee, 8);
251
- _outFee = (0, utils_1.parseUnits)(outFee, 8);
252
- _allowedExtraProfit = (0, utils_1.parseUnits)(allowedExtraProfit);
253
- _feeGamma = (0, utils_1.parseUnits)(feeGamma);
254
- _adjustmentStep = (0, utils_1.parseUnits)(adjustmentStep);
255
- _maHalfTime = (0, utils_1.parseUnits)(maHalfTime, 0);
256
- _initialPrice = (0, utils_1.parseUnits)(initialPrice);
257
- contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crypto_factory].contract;
258
- return [4 /*yield*/, contract.estimateGas.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve_1.curve.constantOptions)];
259
- case 1:
260
- gas = _a.sent();
261
- if (estimateGas)
262
- return [2 /*return*/, gas.toNumber()];
263
- gasLimit = gas.mul(130).div(100);
264
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
265
- case 2:
266
- _a.sent();
267
- return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
268
- _maHalfTime, _initialPrice, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
269
- case 3: return [2 /*return*/, _a.sent()];
270
- }
271
- });
272
- }); };
273
- var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
88
+ initialPrice, estimateGas) => {
89
+ if (name.length > 32)
90
+ throw Error("Max name length = 32");
91
+ if (symbol.length > 10)
92
+ throw Error("Max symbol length = 10");
93
+ if (coins.length !== 2)
94
+ throw Error("Invalid number of coins. Must be 2");
95
+ if (coins[1] === coins[2])
96
+ throw Error("Coins must be different");
97
+ if (BN(A).lt(4000))
98
+ throw Error(`A must be >= 4000. Passed A = ${A}`);
99
+ if (BN(A).gt(4 * (10 ** 9)))
100
+ throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
101
+ if (BN(gamma).lt(1e-8))
102
+ throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
103
+ if (BN(gamma).gt(0.02))
104
+ throw Error(`gamma must be <= 0.02. Passed gamma = ${gamma}`);
105
+ if (BN(midFee).lt(0.005))
106
+ throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
107
+ if (BN(midFee).gt(100))
108
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
109
+ if (BN(outFee).lt(BN(midFee)))
110
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
111
+ if (BN(outFee).gt(100))
112
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
113
+ if (BN(allowedExtraProfit).lt(0))
114
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
115
+ if (BN(allowedExtraProfit).gt(0.01))
116
+ throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
117
+ if (BN(feeGamma).lt(0))
118
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
119
+ if (BN(feeGamma).gt(1))
120
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
121
+ if (BN(adjustmentStep).lt(0))
122
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
123
+ if (BN(adjustmentStep).gt(1))
124
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
125
+ if (BN(maHalfTime).lt(0))
126
+ throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
127
+ if (BN(maHalfTime).gt(604800))
128
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
129
+ if (BN(initialPrice).lt(1e-12))
130
+ throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
131
+ if (BN(initialPrice).gt(1e12))
132
+ throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
133
+ const _A = parseUnits(A, 0);
134
+ const _gamma = parseUnits(gamma);
135
+ const _midFee = parseUnits(midFee, 8);
136
+ const _outFee = parseUnits(outFee, 8);
137
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
138
+ const _feeGamma = parseUnits(feeGamma);
139
+ const _adjustmentStep = parseUnits(adjustmentStep);
140
+ const _maHalfTime = parseUnits(maHalfTime, 0);
141
+ const _initialPrice = parseUnits(initialPrice);
142
+ const contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
143
+ const gas = await contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions);
144
+ if (estimateGas)
145
+ return Number(gas);
146
+ const gasLimit = mulBy1_3(gas);
147
+ await curve.updateFeeData();
148
+ return await contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
149
+ _maHalfTime, _initialPrice, { ...curve.options, gasLimit });
150
+ };
151
+ export const deployCryptoPoolEstimateGas = async (name, symbol, coins, A, gamma, midFee, // %
274
152
  outFee, // %
275
153
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
276
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
277
- return __generator(this, function (_a) {
278
- switch (_a.label) {
279
- case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
280
- case 1: return [2 /*return*/, _a.sent()];
281
- }
282
- });
283
- }); };
284
- exports.deployCryptoPoolEstimateGas = deployCryptoPoolEstimateGas;
285
- var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
154
+ initialPrice) => {
155
+ return await _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
156
+ };
157
+ export const deployCryptoPool = async (name, symbol, coins, A, gamma, midFee, // %
286
158
  outFee, // %
287
159
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
288
- initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
289
- return __generator(this, function (_a) {
290
- switch (_a.label) {
291
- case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
292
- case 1: return [2 /*return*/, _a.sent()];
293
- }
294
- });
295
- }); };
296
- exports.deployCryptoPool = deployCryptoPool;
297
- var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
298
- var txInfo, lpTokenAddress, contract;
299
- return __generator(this, function (_a) {
300
- switch (_a.label) {
301
- case 0: return [4 /*yield*/, tx.wait()];
302
- case 1:
303
- txInfo = _a.sent();
304
- lpTokenAddress = txInfo.logs[0].address;
305
- contract = new ethers_1.Contract(lpTokenAddress, curve_lp_token_v5_json_1.default, curve_1.curve.provider);
306
- return [4 /*yield*/, contract.minter(curve_1.curve.constantOptions)];
307
- case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
308
- }
309
- });
310
- }); };
311
- exports.getDeployedCryptoPoolAddress = getDeployedCryptoPoolAddress;
160
+ initialPrice) => {
161
+ return await _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
162
+ };
163
+ export const getDeployedCryptoPoolAddress = async (tx) => {
164
+ const txInfo = await tx.wait();
165
+ if (!txInfo)
166
+ throw Error("Can't get tx info");
167
+ const lpTokenAddress = txInfo.logs[0].address;
168
+ const contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
169
+ return (await contract.minter(curve.constantOptions)).toLowerCase();
170
+ };
312
171
  // ------- GAUGE -------
313
- var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
314
- var contractAddress, contract, gas, gasLimit;
315
- return __generator(this, function (_a) {
316
- switch (_a.label) {
317
- case 0:
318
- contractAddress = isCrypto ? curve_1.curve.constants.ALIASES.crypto_factory : curve_1.curve.constants.ALIASES.factory;
319
- contract = curve_1.curve.contracts[contractAddress].contract;
320
- return [4 /*yield*/, contract.estimateGas.deploy_gauge(pool, curve_1.curve.constantOptions)];
321
- case 1:
322
- gas = _a.sent();
323
- if (estimateGas)
324
- return [2 /*return*/, gas.toNumber()];
325
- gasLimit = gas.mul(130).div(100);
326
- return [4 /*yield*/, curve_1.curve.updateFeeData()];
327
- case 2:
328
- _a.sent();
329
- return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
330
- case 3: return [2 /*return*/, _a.sent()];
331
- }
332
- });
333
- }); };
334
- var deployGaugeEstimateGas = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
335
- switch (_a.label) {
336
- case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, true)];
337
- case 1: return [2 /*return*/, _a.sent()];
338
- }
339
- }); }); };
340
- exports.deployGaugeEstimateGas = deployGaugeEstimateGas;
341
- var deployGauge = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
342
- switch (_a.label) {
343
- case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, false)];
344
- case 1: return [2 /*return*/, _a.sent()];
345
- }
346
- }); }); };
347
- exports.deployGauge = deployGauge;
348
- var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
349
- var txInfo;
350
- return __generator(this, function (_a) {
351
- switch (_a.label) {
352
- case 0: return [4 /*yield*/, tx.wait()];
353
- case 1:
354
- txInfo = _a.sent();
355
- // @ts-ignore
356
- return [2 /*return*/, txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase()];
357
- }
358
- });
359
- }); };
360
- exports.getDeployedGaugeAddress = getDeployedGaugeAddress;
172
+ const _deployGauge = async (pool, isCrypto, estimateGas) => {
173
+ const contractAddress = isCrypto ? curve.constants.ALIASES.crypto_factory : curve.constants.ALIASES.factory;
174
+ const contract = curve.contracts[contractAddress].contract;
175
+ const gas = await contract.deploy_gauge.estimateGas(pool, curve.constantOptions);
176
+ if (estimateGas)
177
+ return Number(gas);
178
+ const gasLimit = mulBy1_3(gas);
179
+ await curve.updateFeeData();
180
+ return await contract.deploy_gauge(pool, { ...curve.options, gasLimit });
181
+ };
182
+ export const deployGaugeEstimateGas = async (pool, isCrypto) => await _deployGauge(pool, isCrypto, true);
183
+ export const deployGauge = async (pool, isCrypto) => await _deployGauge(pool, isCrypto, false);
184
+ export const getDeployedGaugeAddress = async (tx) => {
185
+ const txInfo = await tx.wait();
186
+ if (!txInfo)
187
+ throw Error("Can't get tx info");
188
+ // @ts-ignore
189
+ return txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase();
190
+ };