@curvefi/api 2.66.30 → 2.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/lib/boosting.d.ts +33 -32
  2. package/lib/boosting.js +320 -252
  3. package/lib/cached.d.ts +4 -3
  4. package/lib/cached.js +63 -19
  5. package/lib/constants/coins/hyperliquid.d.ts +2 -0
  6. package/lib/constants/coins/hyperliquid.js +5 -0
  7. package/lib/constants/coins/index.d.ts +2 -1
  8. package/lib/constants/coins/index.js +2 -1
  9. package/lib/constants/factory/crypto.d.ts +5 -0
  10. package/lib/constants/factory/crypto.js +8 -0
  11. package/lib/constants/factory/stable.js +3 -0
  12. package/lib/constants/network_constants.js +37 -11
  13. package/lib/constants/pools/hyperliquid.d.ts +2 -0
  14. package/lib/constants/pools/hyperliquid.js +2 -0
  15. package/lib/constants/pools/index.d.ts +2 -1
  16. package/lib/constants/pools/index.js +2 -1
  17. package/lib/constants/utils.d.ts +14 -1
  18. package/lib/constants/utils.js +21 -6
  19. package/lib/constants/volumeNetworks.js +1 -1
  20. package/lib/curve.d.ts +5 -5
  21. package/lib/curve.js +21 -38
  22. package/lib/dao.d.ts +32 -31
  23. package/lib/dao.js +420 -350
  24. package/lib/external-api.d.ts +1 -1
  25. package/lib/external-api.js +2 -2
  26. package/lib/factory/common.d.ts +2 -1
  27. package/lib/factory/common.js +1 -1
  28. package/lib/factory/deploy.d.ts +46 -45
  29. package/lib/factory/deploy.js +630 -551
  30. package/lib/factory/factory-api.d.ts +3 -2
  31. package/lib/factory/factory-api.js +22 -23
  32. package/lib/factory/factory-crypto.d.ts +1 -1
  33. package/lib/factory/factory-crypto.js +12 -15
  34. package/lib/factory/factory-tricrypto.d.ts +1 -1
  35. package/lib/factory/factory-tricrypto.js +14 -15
  36. package/lib/factory/factory-twocrypto.d.ts +1 -1
  37. package/lib/factory/factory-twocrypto.js +12 -13
  38. package/lib/factory/factory.d.ts +4 -3
  39. package/lib/factory/factory.js +21 -24
  40. package/lib/index.d.ts +413 -104
  41. package/lib/index.js +253 -257
  42. package/lib/interfaces.d.ts +2 -0
  43. package/lib/pools/PoolTemplate.d.ts +13 -12
  44. package/lib/pools/PoolTemplate.js +279 -285
  45. package/lib/pools/mixins/common.js +2 -2
  46. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
  47. package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
  48. package/lib/pools/mixins/depositMixins.d.ts +25 -5
  49. package/lib/pools/mixins/depositMixins.js +38 -76
  50. package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
  51. package/lib/pools/mixins/depositWrappedMixins.js +17 -33
  52. package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
  53. package/lib/pools/mixins/poolBalancesMixin.js +3 -5
  54. package/lib/pools/mixins/swapMixins.d.ts +20 -4
  55. package/lib/pools/mixins/swapMixins.js +36 -70
  56. package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
  57. package/lib/pools/mixins/swapWrappedMixins.js +32 -60
  58. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
  59. package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
  60. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
  61. package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
  62. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
  63. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
  64. package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
  65. package/lib/pools/mixins/withdrawMixins.js +33 -67
  66. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
  67. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
  68. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
  69. package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
  70. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
  73. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
  74. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
  75. package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
  76. package/lib/pools/poolConstructor.d.ts +2 -1
  77. package/lib/pools/poolConstructor.js +27 -28
  78. package/lib/pools/subClasses/corePool.d.ts +4 -1
  79. package/lib/pools/subClasses/corePool.js +5 -7
  80. package/lib/pools/subClasses/gaugePool.d.ts +5 -3
  81. package/lib/pools/subClasses/gaugePool.js +19 -18
  82. package/lib/pools/subClasses/statsPool.d.ts +2 -0
  83. package/lib/pools/subClasses/statsPool.js +22 -10
  84. package/lib/pools/subClasses/walletPool.d.ts +2 -1
  85. package/lib/pools/subClasses/walletPool.js +6 -6
  86. package/lib/pools/utils.d.ts +7 -6
  87. package/lib/pools/utils.js +316 -297
  88. package/lib/route-graph.worker.d.ts +2 -2
  89. package/lib/route-graph.worker.js +4 -6
  90. package/lib/router.d.ts +12 -11
  91. package/lib/router.js +331 -295
  92. package/lib/utils.d.ts +34 -33
  93. package/lib/utils.js +483 -435
  94. package/package.json +2 -2
@@ -7,597 +7,676 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { ethers, Contract, Typed } from "ethers";
11
- import { curve } from "../curve.js";
10
+ import { Contract, ethers, Typed } from "ethers";
12
11
  import { NETWORK_CONSTANTS } from "../constants/network_constants.js";
13
12
  import { getPool } from "../pools/index.js";
14
- import { parseUnits, BN, mulBy1_3, getPoolIdBySwapAddress, DIGas, smartNumber } from '../utils.js';
15
- import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" with { type: 'json' };
16
- import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" with { type: 'json' };
13
+ import { BN, DIGas, getPoolIdBySwapAddress, mulBy1_3, parseUnits, smartNumber } from '../utils.js';
14
+ import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" with { type: "json" };
15
+ import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" with { type: "json" };
17
16
  // ------- STABLE PLAIN POOLS -------
18
- const _deployStablePlainPool = (name, symbol, coins, A, fee, // %
17
+ function _deployStablePlainPool(name, symbol, coins, A, fee, // %
19
18
  assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
20
19
  implementationIdx, emaTime, // seconds
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_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1, ...args_1) => __awaiter(void 0, [name_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1, ...args_1], void 0, function* (name, symbol, coins, A, fee, // %
69
- assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
70
- implementationIdx, emaTime = 600, // seconds
71
- oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") {
72
- return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true);
73
- });
74
- export const deployStablePlainPool = (name_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1, ...args_1) => __awaiter(void 0, [name_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1, ...args_1], void 0, function* (name, symbol, coins, A, fee, // %
75
- assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
76
- implementationIdx, emaTime = 600, // seconds
77
- oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") {
78
- return yield _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false);
79
- });
80
- const _deployStableNgPlainPool = (name_1, symbol_1, coins_1, A_1, fee_1, offpegFeeMultiplier_1, assetTypes_1, implementationIdx_1, ...args_1) => __awaiter(void 0, [name_1, symbol_1, coins_1, A_1, fee_1, offpegFeeMultiplier_1, assetTypes_1, implementationIdx_1, ...args_1], void 0, function* (name, symbol, coins, A, fee, // %
81
- offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
82
- implementationIdx, emaTime = 600, // seconds
83
- oracleAddresses, methodNames, estimateGas) {
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');
20
+ oracleAddress, methodName, estimateGas) {
21
+ return __awaiter(this, 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 (this.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(this.constants.ZERO_ADDRESS));
47
+ const useProxy = (this.chainId === 1 && coins.length === 2 && implementationIdx === 4 && emaTime !== 600) ||
48
+ (this.chainId === 1 && coins.length === 2 && implementationIdx === 5 && emaTime !== 600) ||
49
+ ((this.chainId === 42161 || this.chainId == 10) && coins.length === 2 && implementationIdx === 0 && emaTime !== 600);
50
+ const setOracle = ((this.chainId === 42161 || this.chainId == 10) && coins.length === 2 && implementationIdx === 2);
51
+ const contractAddress = (useProxy || setOracle) ? this.constants.ALIASES.factory_admin : this.constants.ALIASES.factory;
52
+ const contract = this.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, this.constantOptions);
62
+ if (estimateGas)
63
+ return smartNumber(gas);
64
+ const gasLimit = mulBy1_3(DIGas(gas));
65
+ yield this.updateFeeData();
66
+ return yield contract[methodToCall](...args, Object.assign(Object.assign({}, this.options), { gasLimit }));
67
+ });
68
+ }
69
+ export function deployStablePlainPoolEstimateGas(name_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1) {
70
+ return __awaiter(this, arguments, void 0, function* (name, symbol, coins, A, fee, // %
71
+ assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
72
+ implementationIdx, emaTime = 600, // seconds
73
+ oracleAddress = this.constants.ZERO_ADDRESS, methodName = "0x00000000") {
74
+ return yield _deployStablePlainPool.call(this, name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, true);
75
+ });
76
+ }
77
+ export function deployStablePlainPool(name_1, symbol_1, coins_1, A_1, fee_1, assetType_1, implementationIdx_1) {
78
+ return __awaiter(this, arguments, void 0, function* (name, symbol, coins, A, fee, // %
79
+ assetType, // 0 = USD, 1 = ETH, 2 = BTC, 3 = Other
80
+ implementationIdx, emaTime = 600, // seconds
81
+ oracleAddress = this.constants.ZERO_ADDRESS, methodName = "0x00000000") {
82
+ return yield _deployStablePlainPool.call(this, name, symbol, coins, A, fee, assetType, implementationIdx, emaTime, oracleAddress, methodName, false);
83
+ });
84
+ }
85
+ function _deployStableNgPlainPool(name_1, symbol_1, coins_1, A_1, fee_1, offpegFeeMultiplier_1, assetTypes_1, implementationIdx_1) {
86
+ return __awaiter(this, arguments, void 0, function* (name, symbol, coins, A, fee, // %
87
+ offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
88
+ implementationIdx, emaTime = 600, // seconds
89
+ oracleAddresses, methodNames, estimateGas) {
90
+ if (name.length > 32)
91
+ throw Error("Max name length = 32");
92
+ if (symbol.length > 10)
93
+ throw Error("Max symbol length = 10");
94
+ if (coins.length < 1)
95
+ throw Error("Invalid number of coins. Must be more than 1");
96
+ if (coins.length > 9)
97
+ throw Error("Invalid number of coins. Must be less than 9");
98
+ if (BN(fee).gt(1))
99
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
100
+ let _oracleAddresses;
101
+ if (oracleAddresses.length === 0) {
102
+ _oracleAddresses = new Array(coins.length).fill(this.constants.ZERO_ADDRESS);
103
+ }
104
+ else {
105
+ _oracleAddresses = oracleAddresses;
106
+ }
107
+ let _methodNames;
108
+ if (methodNames.length === 0) {
109
+ _methodNames = new Array(coins.length).fill("0x00000000");
132
110
  }
133
111
  else {
134
- methodIds.push(ethers.id(item).substring(0, 10));
112
+ _methodNames = methodNames;
135
113
  }
114
+ if (coins.length !== assetTypes.length)
115
+ throw Error("Invalid length of assetTypes. Must be same coins length");
116
+ if (coins.length !== _oracleAddresses.length)
117
+ throw Error("Invalid length of oracleAddresses. Must be same coins length");
118
+ if (coins.length !== _methodNames.length)
119
+ throw Error("Invalid length of methodNames. Must be same coins length");
120
+ assetTypes.forEach((item, index) => {
121
+ if (![0, 1, 2, 3].includes(item))
122
+ throw Error(`Invalid assetType. Must be one of: 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626 for assetTypes[${index}]`);
123
+ });
124
+ if (![0].includes(implementationIdx))
125
+ throw Error("Invalid implementationIdx. Must be 0");
126
+ if (emaTime <= 0)
127
+ throw Error(`emaTime must be > 0. Passed emaTime = ${emaTime}`);
128
+ const _A = parseUnits(A, 0);
129
+ const _fee = parseUnits(fee, 8);
130
+ const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
131
+ const _coins = coins;
132
+ const contractAddress = this.constants.ALIASES.stable_ng_factory;
133
+ const contract = this.contracts[contractAddress].contract;
134
+ const methodIds = [];
135
+ _methodNames.forEach((item) => {
136
+ if (item === '0x00000000' || item === '') {
137
+ methodIds.push('0x00000000');
138
+ }
139
+ else {
140
+ methodIds.push(ethers.id(item).substring(0, 10));
141
+ }
142
+ });
143
+ const args = [name, symbol, _coins, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetTypes, methodIds, _oracleAddresses];
144
+ const gas = yield contract.deploy_plain_pool.estimateGas(...args, this.constantOptions);
145
+ if (estimateGas)
146
+ return smartNumber(gas);
147
+ const gasLimit = mulBy1_3(DIGas(gas));
148
+ yield this.updateFeeData();
149
+ return yield contract.deploy_plain_pool(...args, Object.assign(Object.assign({}, this.options), { gasLimit }));
136
150
  });
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, // %
151
+ }
152
+ export function deployStableNgPlainPoolEstimateGas(name, symbol, coins, A, fee, // %
146
153
  offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
147
154
  implementationIdx, emaTime, // seconds
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, // %
155
+ oracleAddresses, methodNames) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return yield _deployStableNgPlainPool.call(this, name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, true);
158
+ });
159
+ }
160
+ export function deployStableNgPlainPool(name, symbol, coins, A, fee, // %
152
161
  offpegFeeMultiplier, assetTypes, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
153
162
  implementationIdx, emaTime, // seconds
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_1, ...args_1) => __awaiter(void 0, [poolAddress_1, ...args_1], void 0, function* (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") {
175
- return yield _setOracle(poolAddress, oracleAddress, methodName, true);
176
- });
177
- export const setOracle = (poolAddress_1, ...args_1) => __awaiter(void 0, [poolAddress_1, ...args_1], void 0, function* (poolAddress, oracleAddress = curve.constants.ZERO_ADDRESS, methodName = "0x00000000") {
178
- return yield _setOracle(poolAddress, oracleAddress, methodName, false);
179
- });
163
+ oracleAddresses, methodNames) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ return yield _deployStableNgPlainPool.call(this, name, symbol, coins, A, fee, offpegFeeMultiplier, assetTypes, implementationIdx, emaTime, oracleAddresses, methodNames, false);
166
+ });
167
+ }
168
+ export function getDeployedStablePlainPoolAddress(tx) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ const txInfo = yield tx.wait();
171
+ if (!txInfo)
172
+ throw Error("Can't get tx info");
173
+ return txInfo.logs[0].address.toLowerCase();
174
+ });
175
+ }
176
+ export function _setOracle(poolAddress, oracleAddress, methodName, estimateGas) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ this.setContract(poolAddress, Plain2ETHOracleABIABI);
179
+ const poolContract = this.contracts[poolAddress].contract;
180
+ const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
181
+ const _gas = yield poolContract.set_oracle.estimateGas(methodId, oracleAddress, this.constantOptions);
182
+ if (estimateGas)
183
+ return Number(_gas);
184
+ const gasLimit = mulBy1_3(_gas);
185
+ yield this.updateFeeData();
186
+ return yield poolContract.set_oracle(methodId, oracleAddress, Object.assign(Object.assign({}, this.options), { gasLimit }));
187
+ });
188
+ }
189
+ export function setOracleEstimateGas(poolAddress_1) {
190
+ return __awaiter(this, arguments, void 0, function* (poolAddress, oracleAddress = this.constants.ZERO_ADDRESS, methodName = "0x00000000") {
191
+ return yield _setOracle.call(this, poolAddress, oracleAddress, methodName, true);
192
+ });
193
+ }
194
+ export function setOracle(poolAddress_1) {
195
+ return __awaiter(this, arguments, void 0, function* (poolAddress, oracleAddress = this.constants.ZERO_ADDRESS, methodName = "0x00000000") {
196
+ return yield _setOracle.call(this, poolAddress, oracleAddress, methodName, false);
197
+ });
198
+ }
180
199
  // ------- STABLE META POOLS -------
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_1, name_1, symbol_1, coin_1, A_1, fee_1, offpegFeeMultiplier_1, assetType_1, ...args_1) => __awaiter(void 0, [basePool_1, name_1, symbol_1, coin_1, A_1, fee_1, offpegFeeMultiplier_1, assetType_1, ...args_1], void 0, function* (basePool, name, symbol, coin, A, fee, // %
212
- offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
213
- emaTime = 600, // seconds
214
- implementationIdx = 0, methodName = "0x00000000", oracleAddress = curve.constants.ZERO_ADDRESS, estimateGas) {
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, // %
200
+ function _deployStableMetaPool(basePool, name, symbol, coin, A, fee, // %
201
+ implementationIdx, estimateGas) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ if (name.length > 32)
204
+ throw Error("Max name length = 32");
205
+ if (symbol.length > 10)
206
+ throw Error("Max symbol length = 10");
207
+ if (BN(fee).lt(0.04))
208
+ throw Error(`fee must be >= 0.04%. Passed fee = ${fee}`);
209
+ if (BN(fee).gt(1))
210
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
211
+ if (![0, 1].includes(implementationIdx))
212
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
213
+ const _A = parseUnits(A, 0);
214
+ const _fee = parseUnits(fee, 8);
215
+ const contract = this.contracts[this.constants.ALIASES.factory].contract;
216
+ const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, this.constantOptions);
217
+ if (estimateGas)
218
+ return smartNumber(gas);
219
+ const gasLimit = mulBy1_3(DIGas(gas));
220
+ yield this.updateFeeData();
221
+ return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, Object.assign(Object.assign({}, this.options), { gasLimit }));
222
+ });
223
+ }
224
+ export function deployStableMetaPoolEstimateGas(basePool, name, symbol, coin, A, fee, // %
225
+ implementationIdx) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ return yield _deployStableMetaPool.call(this, basePool, name, symbol, coin, A, fee, implementationIdx, true);
228
+ });
229
+ }
230
+ export function deployStableMetaPool(basePool, name, symbol, coin, A, fee, // %
231
+ implementationIdx) {
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ return yield _deployStableMetaPool.call(this, basePool, name, symbol, coin, A, fee, implementationIdx, false);
234
+ });
235
+ }
236
+ function _deployStableNgMetaPool(basePool_1, name_1, symbol_1, coin_1, A_1, fee_1, offpegFeeMultiplier_1, assetType_1) {
237
+ return __awaiter(this, arguments, void 0, function* (basePool, name, symbol, coin, A, fee, // %
238
+ offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
239
+ emaTime = 600, // seconds
240
+ implementationIdx = 0, methodName = "0x00000000", oracleAddress = this.constants.ZERO_ADDRESS, estimateGas) {
241
+ if (name.length > 32)
242
+ throw Error("Max name length = 32");
243
+ if (symbol.length > 10)
244
+ throw Error("Max symbol length = 10");
245
+ if (BN(fee).gt(1))
246
+ throw Error(`fee must be <= 1%. Passed fee = ${fee}`);
247
+ if (![0, 1].includes(implementationIdx))
248
+ throw Error("Invalid implementationIdx. Must be one 0 or 1");
249
+ const _A = parseUnits(A, 0);
250
+ const _fee = parseUnits(fee, 8);
251
+ const _offpegFeeMultiplier = parseUnits(offpegFeeMultiplier, 10);
252
+ const methodId = methodName === "0x00000000" ? "0x00000000" : ethers.id(methodName).substring(0, 10);
253
+ const contract = this.contracts[this.constants.ALIASES.stable_ng_factory].contract;
254
+ const gas = yield contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, this.constantOptions);
255
+ if (estimateGas)
256
+ return smartNumber(gas);
257
+ const gasLimit = mulBy1_3(DIGas(gas));
258
+ yield this.updateFeeData();
259
+ return yield contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, _offpegFeeMultiplier, emaTime, implementationIdx, assetType, methodId, oracleAddress, Object.assign(Object.assign({}, this.options), { gasLimit }));
260
+ });
261
+ }
262
+ export function deployStableNgMetaPoolEstimateGas(basePool, name, symbol, coin, A, fee, // %
236
263
  offpegFeeMultiplier, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
237
264
  emaTime, // seconds
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, // %
265
+ implementationIdx, methodName, oracleAddress) {
266
+ return __awaiter(this, void 0, void 0, function* () {
267
+ return yield _deployStableNgMetaPool.call(this, basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, true);
268
+ });
269
+ }
270
+ export function deployStableNgMetaPool(basePool, name, symbol, coin, A, fee, // %
242
271
  offpegFeeMultiplier, emaTime, // seconds
243
272
  implementationIdx, assetType, // 0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
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();
273
+ methodName, oracleAddress) {
274
+ return __awaiter(this, void 0, void 0, function* () {
275
+ return yield _deployStableNgMetaPool.call(this, basePool, name, symbol, coin, A, fee, offpegFeeMultiplier, assetType, emaTime, implementationIdx, methodName, oracleAddress, false);
276
+ });
277
+ }
278
+ export function getDeployedStableMetaPoolAddress(tx) {
279
+ return __awaiter(this, void 0, void 0, function* () {
280
+ const txInfo = yield tx.wait();
281
+ if (!txInfo)
282
+ throw Error("Can't get tx info");
283
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
284
+ if ("args" in txInfo.logs[i]) {
285
+ const basePoolId = getPoolIdBySwapAddress.call(this, txInfo.logs[i].args[1]);
286
+ const basePool = getPool.call(this, basePoolId);
287
+ return txInfo.logs[basePool.underlyingCoins.length].address.toLowerCase();
288
+ }
256
289
  }
257
- }
258
- throw Error("Can't get deployed metapool address");
259
- });
290
+ throw Error("Can't get deployed metapool address");
291
+ });
292
+ }
260
293
  // ------- CRYPTO POOLS -------
261
- const _deployCryptoPool = (name, symbol, coins, A, gamma, midFee, // %
294
+ function _deployCryptoPool(name, symbol, coins, A, gamma, midFee, // %
262
295
  outFee, // %
263
296
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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, // %
297
+ initialPrice, estimateGas) {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ if (name.length > 32)
300
+ throw Error("Max name length = 32");
301
+ if (symbol.length > 10)
302
+ throw Error("Max symbol length = 10");
303
+ if (coins.length !== 2)
304
+ throw Error("Invalid number of coins. Must be 2");
305
+ if (coins[0] === coins[1])
306
+ throw Error("Coins must be different");
307
+ if (BN(A).lt(4000))
308
+ throw Error(`A must be >= 4000. Passed A = ${A}`);
309
+ if (BN(A).gt(4 * (Math.pow(10, 9))))
310
+ throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
311
+ if (BN(gamma).lt(1e-8))
312
+ throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
313
+ if (BN(gamma).gt(0.02))
314
+ throw Error(`gamma must be <= 0.02. Passed gamma = ${gamma}`);
315
+ if (BN(midFee).lt(0.005))
316
+ throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
317
+ if (BN(midFee).gt(100))
318
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
319
+ if (BN(outFee).lt(BN(midFee)))
320
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
321
+ if (BN(outFee).gt(100))
322
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
323
+ if (BN(allowedExtraProfit).lt(0))
324
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
325
+ if (BN(allowedExtraProfit).gt(0.01))
326
+ throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
327
+ if (BN(feeGamma).lt(0))
328
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
329
+ if (BN(feeGamma).gt(1))
330
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
331
+ if (BN(adjustmentStep).lt(0))
332
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
333
+ if (BN(adjustmentStep).gt(1))
334
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
335
+ if (BN(maHalfTime).lt(0))
336
+ throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
337
+ if (BN(maHalfTime).gt(604800))
338
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
339
+ if (BN(initialPrice).lt(1e-12))
340
+ throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
341
+ if (BN(initialPrice).gt(1e12))
342
+ throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
343
+ const _A = parseUnits(A, 0);
344
+ const _gamma = parseUnits(gamma);
345
+ const _midFee = parseUnits(midFee, 8);
346
+ const _outFee = parseUnits(outFee, 8);
347
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
348
+ const _feeGamma = parseUnits(feeGamma);
349
+ const _adjustmentStep = parseUnits(adjustmentStep);
350
+ const _maHalfTime = parseUnits(maHalfTime, 0);
351
+ const _initialPrice = parseUnits(initialPrice);
352
+ const contract = this.contracts[this.constants.ALIASES.crypto_factory].contract;
353
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, this.constantOptions);
354
+ if (estimateGas)
355
+ return smartNumber(gas);
356
+ const gasLimit = mulBy1_3(DIGas(gas));
357
+ yield this.updateFeeData();
358
+ return yield contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
359
+ _maHalfTime, _initialPrice, Object.assign(Object.assign({}, this.options), { gasLimit }));
360
+ });
361
+ }
362
+ export function deployCryptoPoolEstimateGas(name, symbol, coins, A, gamma, midFee, // %
328
363
  outFee, // %
329
364
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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, // %
365
+ initialPrice) {
366
+ return __awaiter(this, void 0, void 0, function* () {
367
+ return yield _deployCryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
368
+ });
369
+ }
370
+ export function deployCryptoPool(name, symbol, coins, A, gamma, midFee, // %
334
371
  outFee, // %
335
372
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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
- });
373
+ initialPrice) {
374
+ return __awaiter(this, void 0, void 0, function* () {
375
+ return yield _deployCryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
376
+ });
377
+ }
378
+ export function getDeployedCryptoPoolAddress(tx) {
379
+ return __awaiter(this, void 0, void 0, function* () {
380
+ const txInfo = yield tx.wait();
381
+ if (!txInfo)
382
+ throw Error("Can't get tx info");
383
+ const lpTokenAddress = txInfo.logs[0].address;
384
+ const contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, this.provider);
385
+ return (yield contract.minter(this.constantOptions)).toLowerCase();
386
+ });
387
+ }
347
388
  // ------- TWOCRYPTO POOLS -------
348
- const _deployTwocryptoPool = (name, symbol, coins, A, gamma, midFee, // %
389
+ function _deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, // %
349
390
  outFee, // %
350
391
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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, // %
392
+ initialPrice, estimateGas) {
393
+ return __awaiter(this, void 0, void 0, function* () {
394
+ if (name.length > 32)
395
+ throw Error("Max name length = 32");
396
+ if (symbol.length > 10)
397
+ throw Error("Max symbol length = 10");
398
+ if (coins.length !== 2)
399
+ throw Error("Invalid number of coins. Must be 2");
400
+ if (coins[0] === coins[1])
401
+ throw Error("Coins must be different");
402
+ if (BN(A).lt(4000))
403
+ throw Error(`A must be >= 4000. Passed A = ${A}`);
404
+ if (BN(A).gt(4 * (Math.pow(10, 9))))
405
+ throw Error(`A must be <= 4 * 10 ** 9. Passed A = ${A}`);
406
+ const MIN_GAMMA = BN((Math.pow(10, 10)) / (Math.pow(10, 18)));
407
+ const MAX_GAMMA = BN(199 * (Math.pow(10, 15)) / (Math.pow(10, 18)));
408
+ if (BN(gamma).lt(MIN_GAMMA))
409
+ throw Error(`gamma must be >= ${MIN_GAMMA}. Passed gamma = ${gamma}`);
410
+ if (BN(gamma).gt(MAX_GAMMA))
411
+ throw Error(`gamma must be <= ${MAX_GAMMA}. Passed gamma = ${gamma}`);
412
+ if (BN(midFee).lt(0.005))
413
+ throw Error(`midFee must be >= 0.005. Passed midFee = ${midFee}`);
414
+ if (BN(midFee).gt(100))
415
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
416
+ if (BN(outFee).lt(BN(midFee)))
417
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
418
+ if (BN(outFee).gt(100))
419
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
420
+ if (BN(allowedExtraProfit).lt(0))
421
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
422
+ if (BN(allowedExtraProfit).gt(0.01))
423
+ throw Error(`allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ${allowedExtraProfit}`);
424
+ if (BN(feeGamma).lt(0))
425
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
426
+ if (BN(feeGamma).gt(1))
427
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
428
+ if (BN(adjustmentStep).lt(0))
429
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
430
+ if (BN(adjustmentStep).gt(1))
431
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
432
+ if (BN(maHalfTime).lt(0))
433
+ throw Error(`maHalfTime must be >= 0. Passed maHalfTime=${maHalfTime}`);
434
+ if (BN(maHalfTime).gt(604800))
435
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${maHalfTime}`);
436
+ if (BN(initialPrice).lt(1e-12))
437
+ throw Error(`initialPrice must be >= 1e-12. Passed initialPrice=${initialPrice}`);
438
+ if (BN(initialPrice).gt(1e12))
439
+ throw Error(`initialPrice must be <= 1e12. Passed initialPrice=${initialPrice}`);
440
+ const _A = parseUnits(A, 0);
441
+ const _gamma = parseUnits(gamma);
442
+ const _midFee = parseUnits(midFee, 8);
443
+ const _outFee = parseUnits(outFee, 8);
444
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
445
+ const _feeGamma = parseUnits(feeGamma);
446
+ const _adjustmentStep = parseUnits(adjustmentStep);
447
+ const _maHalfTime = parseUnits(maHalfTime, 0);
448
+ const _initialPrice = parseUnits(initialPrice);
449
+ const contract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
450
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, this.constantOptions);
451
+ if (estimateGas)
452
+ return smartNumber(gas);
453
+ const gasLimit = mulBy1_3(DIGas(gas));
454
+ yield this.updateFeeData();
455
+ return yield contract.deploy_pool(name, symbol, coins, 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _maHalfTime, _initialPrice, Object.assign(Object.assign({}, this.options), { gasLimit }));
456
+ });
457
+ }
458
+ export function deployTwocryptoPoolEstimateGas(name, symbol, coins, A, gamma, midFee, // %
416
459
  outFee, // %
417
460
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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, // %
461
+ initialPrice) {
462
+ return __awaiter(this, void 0, void 0, function* () {
463
+ return yield _deployTwocryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true);
464
+ });
465
+ }
466
+ export function deployTwocryptoPool(name, symbol, coins, A, gamma, midFee, // %
422
467
  outFee, // %
423
468
  allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
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];
469
+ initialPrice) {
470
+ return __awaiter(this, void 0, void 0, function* () {
471
+ return yield _deployTwocryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false);
472
+ });
473
+ }
474
+ export function getDeployedTwocryptoPoolAddress(tx) {
475
+ return __awaiter(this, void 0, void 0, function* () {
476
+ const txInfo = yield tx.wait();
477
+ if (!txInfo)
478
+ throw Error("Can't get tx info");
479
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
480
+ if ("args" in txInfo.logs[i]) {
481
+ return txInfo.logs[i].args[0];
482
+ }
435
483
  }
436
- }
437
- throw Error("Can't get deployed tricrypto pool address");
438
- });
484
+ throw Error("Can't get deployed tricrypto pool address");
485
+ });
486
+ }
439
487
  // ------- TRICRYPTO POOLS -------
440
- const _deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
488
+ function _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, // %
441
489
  outFee, // %
442
490
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
443
- initialPrices, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
444
- var _a, _b, _c, _d;
445
- if (name.length > 64)
446
- throw Error("Max name length = 64");
447
- if (symbol.length > 32)
448
- throw Error("Max symbol length = 32");
449
- if (coins.length !== 3)
450
- throw Error("Invalid number of coins. Must be 3");
451
- if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
452
- throw Error("Coins must be different");
453
- if (BN(A).lt(2700))
454
- throw Error(`A must be >= 2700. Passed A = ${A}`);
455
- if (BN(A).gt(27 * (Math.pow(10, 7))))
456
- throw Error(`A must be <= 27 * 10 ** 7. Passed A = ${A}`);
457
- if (BN(gamma).lt(1e-8))
458
- throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
459
- if (BN(gamma).gt(0.05))
460
- throw Error(`gamma must be <= 0.05. Passed gamma = ${gamma}`);
461
- if (BN(midFee).lt(0))
462
- throw Error(`midFee must be >= 0. Passed midFee = ${midFee}`);
463
- if (BN(midFee).gt(100))
464
- throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
465
- if (BN(outFee).lt(BN(midFee)))
466
- throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
467
- if (BN(outFee).gt(100))
468
- throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
469
- if (BN(allowedExtraProfit).lt(0))
470
- throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
471
- if (BN(allowedExtraProfit).gt(1))
472
- throw Error(`allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ${allowedExtraProfit}`);
473
- if (BN(feeGamma).lt(0))
474
- throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
475
- if (BN(feeGamma).gt(1))
476
- throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
477
- if (BN(adjustmentStep).lt(0))
478
- throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
479
- if (BN(adjustmentStep).gt(1))
480
- throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
481
- if (BN(emaTime).lt(60))
482
- throw Error(`maHalfTime must be >= 60. Passed maHalfTime=${emaTime}`);
483
- if (BN(emaTime).gt(604800))
484
- throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${emaTime}`);
485
- if (initialPrices.length !== 2)
486
- throw Error("Invalid number of initial prices. Must be 2");
487
- if (BN(initialPrices[0]).lt(1e-12))
488
- throw Error(`initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=${initialPrices[0]}`);
489
- if (BN(initialPrices[0]).gt(1e12))
490
- throw Error(`initialPrices[0] must be <= 1e12. Passed initialPrices[0]=${initialPrices[0]}`);
491
- if (BN(initialPrices[1]).lt(1e-12))
492
- throw Error(`initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=${initialPrices[1]}`);
493
- if (BN(initialPrices[1]).gt(1e12))
494
- throw Error(`initialPrices[1] must be <= 1e12. Passed initialPrices[1]=${initialPrices[1]}`);
495
- const _A = parseUnits(A, 0);
496
- const _gamma = parseUnits(gamma);
497
- const _midFee = parseUnits(midFee, 8);
498
- const _outFee = parseUnits(outFee, 8);
499
- const _allowedExtraProfit = parseUnits(allowedExtraProfit);
500
- const _feeGamma = parseUnits(feeGamma);
501
- const _adjustmentStep = parseUnits(adjustmentStep);
502
- const _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
503
- const _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
504
- const contract = curve.contracts[curve.constants.ALIASES.tricrypto_factory].contract;
505
- const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, curve.constants.ZERO_ADDRESS, (_b = (_a = curve.constants.CRYPTO_FACTORY_CONSTANTS.tricryptoDeployImplementations) === null || _a === void 0 ? void 0 : _a.implementationIdx) !== null && _b !== void 0 ? _b : 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, curve.constantOptions);
506
- if (estimateGas)
507
- return smartNumber(gas);
508
- const gasLimit = mulBy1_3(DIGas(gas));
509
- yield curve.updateFeeData();
510
- return yield contract.deploy_pool(name, symbol, coins, curve.constants.NATIVE_TOKEN.wrappedAddress, (_d = (_c = curve.constants.CRYPTO_FACTORY_CONSTANTS.tricryptoDeployImplementations) === null || _c === void 0 ? void 0 : _c.implementationIdx) !== null && _d !== void 0 ? _d : 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, Object.assign(Object.assign({}, curve.options), { gasLimit }));
511
- });
512
- export const deployTricryptoPoolEstimateGas = (name, symbol, coins, A, gamma, midFee, // %
491
+ initialPrices, estimateGas) {
492
+ return __awaiter(this, void 0, void 0, function* () {
493
+ var _a, _b, _c, _d;
494
+ if (name.length > 64)
495
+ throw Error("Max name length = 64");
496
+ if (symbol.length > 32)
497
+ throw Error("Max symbol length = 32");
498
+ if (coins.length !== 3)
499
+ throw Error("Invalid number of coins. Must be 3");
500
+ if (coins[0] === coins[1] || coins[1] === coins[2] || coins[0] === coins[2])
501
+ throw Error("Coins must be different");
502
+ if (BN(A).lt(2700))
503
+ throw Error(`A must be >= 2700. Passed A = ${A}`);
504
+ if (BN(A).gt(27 * (Math.pow(10, 7))))
505
+ throw Error(`A must be <= 27 * 10 ** 7. Passed A = ${A}`);
506
+ if (BN(gamma).lt(1e-8))
507
+ throw Error(`gamma must be >= 1e-8. Passed gamma = ${gamma}`);
508
+ if (BN(gamma).gt(0.05))
509
+ throw Error(`gamma must be <= 0.05. Passed gamma = ${gamma}`);
510
+ if (BN(midFee).lt(0))
511
+ throw Error(`midFee must be >= 0. Passed midFee = ${midFee}`);
512
+ if (BN(midFee).gt(100))
513
+ throw Error(`midFee must be <= 100. Passed midFee = ${midFee}`);
514
+ if (BN(outFee).lt(BN(midFee)))
515
+ throw Error(`outFee must be >= midFee. Passed outFee = ${outFee} < midFee = ${midFee}`);
516
+ if (BN(outFee).gt(100))
517
+ throw Error(`outFee must be <= 100. Passed outFee = ${outFee}`);
518
+ if (BN(allowedExtraProfit).lt(0))
519
+ throw Error(`allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ${allowedExtraProfit}`);
520
+ if (BN(allowedExtraProfit).gt(1))
521
+ throw Error(`allowedExtraProfit must be <= 1. Passed allowedExtraProfit = ${allowedExtraProfit}`);
522
+ if (BN(feeGamma).lt(0))
523
+ throw Error(`feeGamma must be >= 0. Passed feeGamma = ${feeGamma}`);
524
+ if (BN(feeGamma).gt(1))
525
+ throw Error(`feeGamma must be <= 1. Passed feeGamma = ${feeGamma}`);
526
+ if (BN(adjustmentStep).lt(0))
527
+ throw Error(`adjustmentStep must be >= 0. Passed adjustmentStep=${adjustmentStep}`);
528
+ if (BN(adjustmentStep).gt(1))
529
+ throw Error(`adjustmentStep must be <= 1. Passed adjustmentStep=${adjustmentStep}`);
530
+ if (BN(emaTime).lt(60))
531
+ throw Error(`maHalfTime must be >= 60. Passed maHalfTime=${emaTime}`);
532
+ if (BN(emaTime).gt(604800))
533
+ throw Error(`maHalfTime must be <= 604800. Passed maHalfTime=${emaTime}`);
534
+ if (initialPrices.length !== 2)
535
+ throw Error("Invalid number of initial prices. Must be 2");
536
+ if (BN(initialPrices[0]).lt(1e-12))
537
+ throw Error(`initialPrices[0] must be >= 1e-12. Passed initialPrices[0]=${initialPrices[0]}`);
538
+ if (BN(initialPrices[0]).gt(1e12))
539
+ throw Error(`initialPrices[0] must be <= 1e12. Passed initialPrices[0]=${initialPrices[0]}`);
540
+ if (BN(initialPrices[1]).lt(1e-12))
541
+ throw Error(`initialPrices[1] must be >= 1e-12. Passed initialPrices[1]=${initialPrices[1]}`);
542
+ if (BN(initialPrices[1]).gt(1e12))
543
+ throw Error(`initialPrices[1] must be <= 1e12. Passed initialPrices[1]=${initialPrices[1]}`);
544
+ const _A = parseUnits(A, 0);
545
+ const _gamma = parseUnits(gamma);
546
+ const _midFee = parseUnits(midFee, 8);
547
+ const _outFee = parseUnits(outFee, 8);
548
+ const _allowedExtraProfit = parseUnits(allowedExtraProfit);
549
+ const _feeGamma = parseUnits(feeGamma);
550
+ const _adjustmentStep = parseUnits(adjustmentStep);
551
+ const _emaTime = parseUnits(Math.floor(emaTime / Math.log(2)), 0);
552
+ const _initialPrices = [parseUnits(initialPrices[0]), parseUnits(initialPrices[1])];
553
+ const contract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
554
+ const gas = yield contract.deploy_pool.estimateGas(name, symbol, coins, this.constants.ZERO_ADDRESS, (_b = (_a = this.constants.CRYPTO_FACTORY_CONSTANTS.tricryptoDeployImplementations) === null || _a === void 0 ? void 0 : _a.implementationIdx) !== null && _b !== void 0 ? _b : 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, this.constantOptions);
555
+ if (estimateGas)
556
+ return smartNumber(gas);
557
+ const gasLimit = mulBy1_3(DIGas(gas));
558
+ yield this.updateFeeData();
559
+ return yield contract.deploy_pool(name, symbol, coins, this.constants.NATIVE_TOKEN.wrappedAddress, (_d = (_c = this.constants.CRYPTO_FACTORY_CONSTANTS.tricryptoDeployImplementations) === null || _c === void 0 ? void 0 : _c.implementationIdx) !== null && _d !== void 0 ? _d : 0, _A, _gamma, _midFee, _outFee, _feeGamma, _allowedExtraProfit, _adjustmentStep, _emaTime, _initialPrices, Object.assign(Object.assign({}, this.options), { gasLimit }));
560
+ });
561
+ }
562
+ export function deployTricryptoPoolEstimateGas(name, symbol, coins, A, gamma, midFee, // %
513
563
  outFee, // %
514
564
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
515
- initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
516
- return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true);
517
- });
518
- export const deployTricryptoPool = (name, symbol, coins, A, gamma, midFee, // %
565
+ initialPrices) {
566
+ return __awaiter(this, void 0, void 0, function* () {
567
+ return yield _deployTricryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, true);
568
+ });
569
+ }
570
+ export function deployTricryptoPool(name, symbol, coins, A, gamma, midFee, // %
519
571
  outFee, // %
520
572
  allowedExtraProfit, feeGamma, adjustmentStep, emaTime, // Seconds
521
- initialPrices) => __awaiter(void 0, void 0, void 0, function* () {
522
- return yield _deployTricryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false);
523
- });
524
- export const getDeployedTricryptoPoolAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
525
- const txInfo = yield tx.wait();
526
- if (!txInfo)
527
- throw Error("Can't get tx info");
528
- for (let i = txInfo.logs.length - 1; i > -1; i--) {
529
- if ("args" in txInfo.logs[i]) {
530
- // @ts-ignore
531
- return txInfo.logs[i].args[0];
573
+ initialPrices) {
574
+ return __awaiter(this, void 0, void 0, function* () {
575
+ return yield _deployTricryptoPool.call(this, name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, emaTime, initialPrices, false);
576
+ });
577
+ }
578
+ export function getDeployedTricryptoPoolAddress(tx) {
579
+ return __awaiter(this, void 0, void 0, function* () {
580
+ const txInfo = yield tx.wait();
581
+ if (!txInfo)
582
+ throw Error("Can't get tx info");
583
+ for (let i = txInfo.logs.length - 1; i > -1; i--) {
584
+ if ("args" in txInfo.logs[i]) {
585
+ return txInfo.logs[i].args[0];
586
+ }
532
587
  }
533
- }
534
- throw Error("Can't get deployed tricrypto pool address");
535
- });
588
+ throw Error("Can't get deployed tricrypto pool address");
589
+ });
590
+ }
536
591
  // ------- GAUGE -------
537
- const _deployGauge = (pool, factory, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
538
- if (curve.chainId !== 1)
539
- throw Error("There is no deployGauge method on sidechain network");
540
- const contract = curve.contracts[factory].contract;
541
- const gas = yield contract.deploy_gauge.estimateGas(pool, curve.constantOptions);
542
- if (estimateGas)
543
- return smartNumber(gas);
544
- const gasLimit = mulBy1_3(DIGas(gas));
545
- yield curve.updateFeeData();
546
- return yield contract.deploy_gauge(pool, Object.assign(Object.assign({}, curve.options), { gasLimit }));
547
- });
548
- const _deployGaugeSidechain = (pool, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
549
- if (curve.chainId === 1)
550
- throw Error("There is no deployGaugeSidechain method on ethereum network");
551
- const contract = curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;
552
- const _salt = ethers.encodeBytes32String(salt);
553
- const gas = yield contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), curve.signerAddress, curve.constantOptions);
554
- if (estimateGas)
555
- return smartNumber(gas);
556
- const gasLimit = mulBy1_3(DIGas(gas));
557
- yield curve.updateFeeData();
558
- return yield contract.deploy_gauge(pool, Typed.bytes32(_salt), curve.signerAddress, Object.assign(Object.assign({}, curve.options), { gasLimit }));
559
- });
560
- const _deployGaugeMirror = (chainId, salt, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
561
- if (curve.chainId !== 1)
562
- throw Error("There is no deployGaugeMirror method on sidechain network");
563
- const rootGaugeFactory = chainId !== 42161 ? NETWORK_CONSTANTS[curve.chainId].ALIASES.root_gauge_factory : NETWORK_CONSTANTS[curve.chainId].ALIASES.root_gauge_factory_arbitrum;
564
- const contract = curve.contracts[rootGaugeFactory].contract;
565
- const _salt = ethers.encodeBytes32String(salt);
566
- const gas = yield contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), curve.constantOptions);
567
- if (estimateGas)
568
- return smartNumber(gas);
569
- const gasLimit = mulBy1_3(DIGas(gas));
570
- yield curve.updateFeeData();
571
- return yield contract.deploy_gauge(chainId, Typed.bytes32(_salt), Object.assign(Object.assign({}, curve.options), { gasLimit }));
572
- });
573
- export const deployGaugeEstimateGas = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, true); });
574
- export const deployGauge = (pool, factory) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGauge(pool, factory, false); });
575
- export const deployGaugeSidechainEstimateGas = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, true); });
576
- export const deployGaugeSidechain = (pool, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeSidechain(pool, salt, false); });
577
- export const deployGaugeMirrorEstimateGas = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, true); });
578
- export const deployGaugeMirror = (chainId, salt) => __awaiter(void 0, void 0, void 0, function* () { return yield _deployGaugeMirror(chainId, salt, false); });
579
- export const getDeployedGaugeAddress = (tx) => __awaiter(void 0, void 0, void 0, function* () {
580
- const txInfo = yield tx.wait();
581
- if (!txInfo)
582
- throw Error("Can't get tx info");
583
- // @ts-ignore
584
- return txInfo.logs[0].args[txInfo.logs[0].args.length - 1].toLowerCase();
585
- });
586
- export const getDeployedGaugeMirrorAddressByTx = (tx) => __awaiter(void 0, void 0, void 0, function* () {
587
- if (curve.chainId !== 1)
588
- throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
589
- const txInfo = yield tx.wait();
590
- if (!txInfo)
591
- throw Error("Can't get tx info");
592
- // @ts-ignore
593
- return txInfo.logs[1].args[txInfo.logs[1].args.length - 1].toLowerCase();
594
- });
595
- export const getDeployedGaugeMirrorAddress = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
596
- if (curve.chainId !== 1)
597
- throw Error("There is no getDeployedGaugeMirrorAddress method on sidechain network");
598
- const rootGaugeFactory = chainId !== 42161 ? NETWORK_CONSTANTS[curve.chainId].ALIASES.root_gauge_factory : NETWORK_CONSTANTS[curve.chainId].ALIASES.root_gauge_factory_arbitrum;
599
- const contract = curve.contracts[rootGaugeFactory].contract;
600
- const gaugeCount = yield contract.get_gauge_count(chainId);
601
- const currentIndex = Number(gaugeCount) - 1;
602
- return yield contract.get_gauge(chainId, currentIndex);
603
- });
592
+ function _deployGauge(pool, factory, estimateGas) {
593
+ return __awaiter(this, void 0, void 0, function* () {
594
+ if (this.chainId !== 1)
595
+ throw Error("There is no deployGauge method on sidechain network");
596
+ const contract = this.contracts[factory].contract;
597
+ const gas = yield contract.deploy_gauge.estimateGas(pool, this.constantOptions);
598
+ if (estimateGas)
599
+ return smartNumber(gas);
600
+ const gasLimit = mulBy1_3(DIGas(gas));
601
+ yield this.updateFeeData();
602
+ return yield contract.deploy_gauge(pool, Object.assign(Object.assign({}, this.options), { gasLimit }));
603
+ });
604
+ }
605
+ function _deployGaugeSidechain(pool, salt, estimateGas) {
606
+ return __awaiter(this, void 0, void 0, function* () {
607
+ if (this.chainId === 1)
608
+ throw Error("There is no deployGaugeSidechain method on ethereum network");
609
+ const contract = this.contracts[this.constants.ALIASES.child_gauge_factory].contract;
610
+ const _salt = ethers.encodeBytes32String(salt);
611
+ const gas = yield contract.deploy_gauge.estimateGas(pool, Typed.bytes32(_salt), this.signerAddress, this.constantOptions);
612
+ if (estimateGas)
613
+ return smartNumber(gas);
614
+ const gasLimit = mulBy1_3(DIGas(gas));
615
+ yield this.updateFeeData();
616
+ return yield contract.deploy_gauge(pool, Typed.bytes32(_salt), this.signerAddress, Object.assign(Object.assign({}, this.options), { gasLimit }));
617
+ });
618
+ }
619
+ function _deployGaugeMirror(chainId, salt, estimateGas) {
620
+ return __awaiter(this, void 0, void 0, function* () {
621
+ if (this.chainId !== 1)
622
+ throw Error("There is no deployGaugeMirror method on sidechain network");
623
+ const rootGaugeFactory = chainId !== 42161 ? NETWORK_CONSTANTS[this.chainId].ALIASES.root_gauge_factory : NETWORK_CONSTANTS[this.chainId].ALIASES.root_gauge_factory_arbitrum;
624
+ const contract = this.contracts[rootGaugeFactory].contract;
625
+ const _salt = ethers.encodeBytes32String(salt);
626
+ const gas = yield contract.deploy_gauge.estimateGas(chainId, Typed.bytes32(_salt), this.constantOptions);
627
+ if (estimateGas)
628
+ return smartNumber(gas);
629
+ const gasLimit = mulBy1_3(DIGas(gas));
630
+ yield this.updateFeeData();
631
+ return yield contract.deploy_gauge(chainId, Typed.bytes32(_salt), Object.assign(Object.assign({}, this.options), { gasLimit }));
632
+ });
633
+ }
634
+ export function deployGaugeEstimateGas(pool, factory) {
635
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGauge.call(this, pool, factory, true); });
636
+ }
637
+ export function deployGauge(pool, factory) {
638
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGauge.call(this, pool, factory, false); });
639
+ }
640
+ export function deployGaugeSidechainEstimateGas(pool, salt) {
641
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGaugeSidechain.call(this, pool, salt, true); });
642
+ }
643
+ export function deployGaugeSidechain(pool, salt) {
644
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGaugeSidechain.call(this, pool, salt, false); });
645
+ }
646
+ export function deployGaugeMirrorEstimateGas(chainId, salt) {
647
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGaugeMirror.call(this, chainId, salt, true); });
648
+ }
649
+ export function deployGaugeMirror(chainId, salt) {
650
+ return __awaiter(this, void 0, void 0, function* () { return yield _deployGaugeMirror.call(this, chainId, salt, false); });
651
+ }
652
+ export function getDeployedGaugeAddress(tx) {
653
+ return __awaiter(this, void 0, void 0, function* () {
654
+ const txInfo = yield tx.wait();
655
+ if (!txInfo)
656
+ throw Error("Can't get tx info");
657
+ const log = txInfo.logs[0];
658
+ return log.args[log.args.length - 1].toLowerCase();
659
+ });
660
+ }
661
+ export function getDeployedGaugeMirrorAddressByTx(tx) {
662
+ return __awaiter(this, void 0, void 0, function* () {
663
+ if (this.chainId !== 1)
664
+ throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
665
+ const txInfo = yield tx.wait();
666
+ if (!txInfo)
667
+ throw Error("Can't get tx info");
668
+ const log = txInfo.logs[1];
669
+ return log.args[log.args.length - 1].toLowerCase();
670
+ });
671
+ }
672
+ export function getDeployedGaugeMirrorAddress(chainId) {
673
+ return __awaiter(this, void 0, void 0, function* () {
674
+ if (this.chainId !== 1)
675
+ throw Error("There is no getDeployedGaugeMirrorAddress method on sidechain network");
676
+ const rootGaugeFactory = chainId !== 42161 ? NETWORK_CONSTANTS[this.chainId].ALIASES.root_gauge_factory : NETWORK_CONSTANTS[this.chainId].ALIASES.root_gauge_factory_arbitrum;
677
+ const contract = this.contracts[rootGaugeFactory].contract;
678
+ const gaugeCount = yield contract.get_gauge_count(chainId);
679
+ const currentIndex = Number(gaugeCount) - 1;
680
+ return yield contract.get_gauge(chainId, currentIndex);
681
+ });
682
+ }