@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
package/lib/boosting.js CHANGED
@@ -9,83 +9,97 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { Contract } from "ethers";
11
11
  import BigNumber from "bignumber.js";
12
- import { curve } from "./curve.js";
13
- import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: 'json' };
14
- import feeDistributorCrvUSDViewABI from "./constants/abis/fee_distributor_crvusd_view.json" with { type: 'json' };
15
- import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber, } from "./utils.js";
16
- import { _ensureAllowance, toBN, toStringFromBN, parseUnits, BN } from './utils.js';
12
+ import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: "json" };
13
+ import feeDistributorCrvUSDViewABI from "./constants/abis/fee_distributor_crvusd_view.json" with { type: "json" };
14
+ import { _ensureAllowance, _getBalances, _prepareAddresses, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, toStringFromBN, } from "./utils.js";
17
15
  import { _generateBoostingProof } from './external-api.js';
18
- export const getCrv = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
19
- addresses = _prepareAddresses(addresses);
20
- const rawBalances = (yield _getBalances([curve.constants.ALIASES.crv], addresses));
21
- const balances = {};
22
- for (const address of addresses) {
23
- balances[address] = rawBalances[address].shift();
24
- }
25
- return addresses.length === 1 ? balances[addresses[0]] : balances;
26
- });
27
- export const getLockedAmountAndUnlockTime = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
28
- addresses = _prepareAddresses(addresses);
29
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
30
- const contractCalls = addresses.map((address) => veContract.locked(address));
31
- const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => [curve.formatUnits(value[0]), Number(curve.formatUnits(value[1], 0)) * 1000]);
32
- const result = {};
33
- addresses.forEach((addr, i) => {
34
- result[addr] = { lockedAmount: response[i][0], unlockTime: response[i][1] };
35
- });
36
- return addresses.length === 1 ? result[addresses[0]] : result;
37
- });
38
- export const getVeCrv = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
39
- addresses = _prepareAddresses(addresses);
40
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
41
- const contractCalls = addresses.map((address) => veContract.balanceOf(address));
42
- const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => curve.formatUnits(value));
43
- const result = {};
44
- addresses.forEach((addr, i) => {
45
- result[addr] = response[i];
46
- });
47
- return addresses.length === 1 ? result[addresses[0]] : result;
48
- });
49
- export const getVeCrvPct = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
50
- addresses = _prepareAddresses(addresses);
51
- const veContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
52
- const contractCalls = [veContract.totalSupply()];
53
- addresses.forEach((address) => {
54
- contractCalls.push(veContract.balanceOf(address));
55
- });
56
- const response = (yield curve.multicallProvider.all(contractCalls)).map((value) => toBN(value));
57
- const [veTotalSupply] = response.splice(0, 1);
58
- const resultBN = {};
59
- addresses.forEach((acct, i) => {
60
- resultBN[acct] = response[i].div(veTotalSupply).times(100);
61
- });
62
- const result = {};
63
- for (const entry of Object.entries(resultBN)) {
64
- result[entry[0]] = toStringFromBN(entry[1]);
65
- }
66
- return addresses.length === 1 ? result[addresses[0]] : result;
67
- });
68
- export const isApproved = (amount) => __awaiter(void 0, void 0, void 0, function* () {
69
- return yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow);
70
- });
71
- export const approveEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
72
- return yield ensureAllowanceEstimateGas([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
73
- });
74
- export const approve = (amount) => __awaiter(void 0, void 0, void 0, function* () {
75
- return yield ensureAllowance([curve.constants.ALIASES.crv], [amount], curve.constants.ALIASES.voting_escrow, false);
76
- });
77
- export const createLockEstimateGas = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
78
- const crvBalance = yield getCrv();
79
- if (Number(crvBalance) < Number(amount)) {
80
- throw Error(`Not enough . Actual: ${crvBalance}, required: ${amount}`);
81
- }
82
- if (!(yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
83
- throw Error("Token allowance is needed to estimate gas");
84
- }
85
- const _amount = parseUnits(amount);
86
- const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
87
- return Number(yield curve.contracts[curve.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions));
88
- });
16
+ export function getCrv(...addresses) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ addresses = _prepareAddresses.call(this, addresses);
19
+ const rawBalances = (yield _getBalances.call(this, [this.constants.ALIASES.crv], addresses));
20
+ const balances = {};
21
+ for (const address of addresses) {
22
+ balances[address] = rawBalances[address].shift();
23
+ }
24
+ return addresses.length === 1 ? balances[addresses[0]] : balances;
25
+ });
26
+ }
27
+ export function getLockedAmountAndUnlockTime(...addresses) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ addresses = _prepareAddresses.call(this, addresses);
30
+ const veContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
31
+ const contractCalls = addresses.map((address) => veContract.locked(address));
32
+ const response = (yield this.multicallProvider.all(contractCalls)).map((value) => [this.formatUnits(value[0]), Number(this.formatUnits(value[1], 0)) * 1000]);
33
+ const result = {};
34
+ addresses.forEach((addr, i) => {
35
+ result[addr] = { lockedAmount: response[i][0], unlockTime: response[i][1] };
36
+ });
37
+ return addresses.length === 1 ? result[addresses[0]] : result;
38
+ });
39
+ }
40
+ export function getVeCrv(...addresses) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ addresses = _prepareAddresses.call(this, addresses);
43
+ const veContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
44
+ const contractCalls = addresses.map((address) => veContract.balanceOf(address));
45
+ const response = (yield this.multicallProvider.all(contractCalls)).map((value) => this.formatUnits(value));
46
+ const result = {};
47
+ addresses.forEach((addr, i) => {
48
+ result[addr] = response[i];
49
+ });
50
+ return addresses.length === 1 ? result[addresses[0]] : result;
51
+ });
52
+ }
53
+ export function getVeCrvPct(...addresses) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ addresses = _prepareAddresses.call(this, addresses);
56
+ const veContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
57
+ const contractCalls = [veContract.totalSupply()];
58
+ addresses.forEach((address) => {
59
+ contractCalls.push(veContract.balanceOf(address));
60
+ });
61
+ const response = (yield this.multicallProvider.all(contractCalls)).map((value) => toBN(value));
62
+ const [veTotalSupply] = response.splice(0, 1);
63
+ const resultBN = {};
64
+ addresses.forEach((acct, i) => {
65
+ resultBN[acct] = response[i].div(veTotalSupply).times(100);
66
+ });
67
+ const result = {};
68
+ for (const entry of Object.entries(resultBN)) {
69
+ result[entry[0]] = toStringFromBN(entry[1]);
70
+ }
71
+ return addresses.length === 1 ? result[addresses[0]] : result;
72
+ });
73
+ }
74
+ export function isApproved(amount) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return yield hasAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.signerAddress, this.constants.ALIASES.voting_escrow);
77
+ });
78
+ }
79
+ export function approveEstimateGas(amount) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ return yield ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crv], [amount], this.constants.ALIASES.voting_escrow, false);
82
+ });
83
+ }
84
+ export function approve(amount) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ return yield ensureAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.constants.ALIASES.voting_escrow, false);
87
+ });
88
+ }
89
+ export function createLockEstimateGas(amount, days) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const crvBalance = yield getCrv.call(this);
92
+ if (Number(crvBalance) < Number(amount)) {
93
+ throw Error(`Not enough . Actual: ${crvBalance}, required: ${amount}`);
94
+ }
95
+ if (!(yield hasAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.signerAddress, this.constants.ALIASES.voting_escrow))) {
96
+ throw Error("Token allowance is needed to estimate gas");
97
+ }
98
+ const _amount = parseUnits(amount);
99
+ const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
100
+ return Number(yield this.contracts[this.constants.ALIASES.voting_escrow].contract.create_lock.estimateGas(_amount, unlockTime, this.constantOptions));
101
+ });
102
+ }
89
103
  export const calcUnlockTime = (days, start = Date.now()) => {
90
104
  const week = 86400 * 7;
91
105
  const now = start / 1000;
@@ -113,180 +127,234 @@ export const calculateVeCrv = (amount, unlockTimestamp) => {
113
127
  .div(MAX_TIME_SECONDS);
114
128
  return veCrvBN.toNumber();
115
129
  };
116
- export const createLock = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
117
- const _amount = parseUnits(amount);
118
- const unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
119
- yield _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
120
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
121
- yield curve.updateFeeData();
122
- const gasLimit = mulBy1_3(DIGas(yield contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)));
123
- return (yield contract.create_lock(_amount, unlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
124
- });
125
- export const increaseAmountEstimateGas = (amount) => __awaiter(void 0, void 0, void 0, function* () {
126
- const crvBalance = yield getCrv();
127
- if (Number(crvBalance) < Number(amount)) {
128
- throw Error(`Not enough. Actual: ${crvBalance}, required: ${amount}`);
129
- }
130
- if (!(yield hasAllowance([curve.constants.ALIASES.crv], [amount], curve.signerAddress, curve.constants.ALIASES.voting_escrow))) {
131
- throw Error("Token allowance is needed to estimate gas");
132
- }
133
- const _amount = parseUnits(amount);
134
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
135
- return Number(yield contract.increase_amount.estimateGas(_amount, curve.constantOptions));
136
- });
137
- export const increaseAmount = (amount) => __awaiter(void 0, void 0, void 0, function* () {
138
- const _amount = parseUnits(amount);
139
- yield _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false);
140
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
141
- yield curve.updateFeeData();
142
- const gasLimit = mulBy1_3(DIGas(yield contract.increase_amount.estimateGas(_amount, curve.constantOptions)));
143
- return (yield contract.increase_amount(_amount, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
144
- });
145
- export const increaseUnlockTimeEstimateGas = (days) => __awaiter(void 0, void 0, void 0, function* () {
146
- const { unlockTime } = yield getLockedAmountAndUnlockTime();
147
- const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
148
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
149
- return Number(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)));
150
- });
151
- export const increaseUnlockTime = (days) => __awaiter(void 0, void 0, void 0, function* () {
152
- const { unlockTime } = yield getLockedAmountAndUnlockTime();
153
- const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
154
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
155
- yield curve.updateFeeData();
156
- const gasLimit = mulBy1_3(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)));
157
- return (yield contract.increase_unlock_time(newUnlockTime, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
158
- });
159
- export const withdrawLockedCrvEstimateGas = () => __awaiter(void 0, void 0, void 0, function* () {
160
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
161
- return Number(DIGas(yield contract.withdraw.estimateGas(curve.constantOptions)));
162
- });
163
- export const withdrawLockedCrv = () => __awaiter(void 0, void 0, void 0, function* () {
164
- const contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
165
- yield curve.updateFeeData();
166
- const gasLimit = mulBy1_3(DIGas(yield contract.withdraw.estimateGas(curve.constantOptions)));
167
- return (yield contract.withdraw(Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
168
- });
169
- export const claimableFees = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
170
- address = address || curve.signerAddress;
171
- const contract = new Contract(curve.constants.ALIASES.fee_distributor, feeDistributorViewABI, curve.provider);
172
- return curve.formatUnits(yield contract.claim(address, curve.constantOptions));
173
- });
174
- export const claimFeesEstimateGas = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
175
- address = address || curve.signerAddress;
176
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
177
- return Number(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
178
- });
179
- export const claimFees = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
180
- if (curve.chainId !== 1) {
181
- throw Error('This method is only available for the network with chainId 1');
182
- }
183
- address = address || curve.signerAddress;
184
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
185
- yield curve.updateFeeData();
186
- const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
187
- return (yield contract.claim(address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
188
- });
189
- export const claimableFeesCrvUSD = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
190
- if (curve.chainId !== 1) {
191
- throw Error('This method is only available for the network with chainId 1');
192
- }
193
- address = address || curve.signerAddress;
194
- const contract = new Contract(curve.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDViewABI, curve.provider);
195
- return curve.formatUnits(yield contract.claim(address, curve.constantOptions));
196
- });
197
- export const claimFeesCrvUSDEstimateGas = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
198
- if (curve.chainId !== 1) {
199
- throw Error('This method is only available for the network with chainId 1');
200
- }
201
- address = address || curve.signerAddress;
202
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
203
- return Number(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
204
- });
205
- export const claimFeesCrvUSD = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
206
- address = address || curve.signerAddress;
207
- const contract = curve.contracts[curve.constants.ALIASES.fee_distributor_crvusd].contract;
208
- yield curve.updateFeeData();
209
- const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, curve.constantOptions)));
210
- return (yield contract.claim(address, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
211
- });
130
+ export function createLock(amount, days) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const _amount = parseUnits(amount);
133
+ const unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
134
+ yield _ensureAllowance.call(this, [this.constants.ALIASES.crv], [_amount], this.constants.ALIASES.voting_escrow, false);
135
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
136
+ yield this.updateFeeData();
137
+ const gasLimit = mulBy1_3(DIGas(yield contract.create_lock.estimateGas(_amount, unlockTime, this.constantOptions)));
138
+ return (yield contract.create_lock(_amount, unlockTime, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
139
+ });
140
+ }
141
+ export function increaseAmountEstimateGas(amount) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ const crvBalance = yield getCrv.call(this);
144
+ if (Number(crvBalance) < Number(amount)) {
145
+ throw Error(`Not enough. Actual: ${crvBalance}, required: ${amount}`);
146
+ }
147
+ if (!(yield hasAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.signerAddress, this.constants.ALIASES.voting_escrow))) {
148
+ throw Error("Token allowance is needed to estimate gas");
149
+ }
150
+ const _amount = parseUnits(amount);
151
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
152
+ return Number(yield contract.increase_amount.estimateGas(_amount, this.constantOptions));
153
+ });
154
+ }
155
+ export function increaseAmount(amount) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const _amount = parseUnits(amount);
158
+ yield _ensureAllowance.call(this, [this.constants.ALIASES.crv], [_amount], this.constants.ALIASES.voting_escrow, false);
159
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
160
+ yield this.updateFeeData();
161
+ const gasLimit = mulBy1_3(DIGas(yield contract.increase_amount.estimateGas(_amount, this.constantOptions)));
162
+ return (yield contract.increase_amount(_amount, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
163
+ });
164
+ }
165
+ export function increaseUnlockTimeEstimateGas(days) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ const { unlockTime } = yield getLockedAmountAndUnlockTime.call(this);
168
+ const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
169
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
170
+ return Number(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, this.constantOptions)));
171
+ });
172
+ }
173
+ export function increaseUnlockTime(days) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const { unlockTime } = yield getLockedAmountAndUnlockTime.call(this);
176
+ const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
177
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
178
+ yield this.updateFeeData();
179
+ const gasLimit = mulBy1_3(DIGas(yield contract.increase_unlock_time.estimateGas(newUnlockTime, this.constantOptions)));
180
+ return (yield contract.increase_unlock_time(newUnlockTime, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
181
+ });
182
+ }
183
+ export function withdrawLockedCrvEstimateGas() {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
186
+ return Number(DIGas(yield contract.withdraw.estimateGas(this.constantOptions)));
187
+ });
188
+ }
189
+ export function withdrawLockedCrv() {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
192
+ yield this.updateFeeData();
193
+ const gasLimit = mulBy1_3(DIGas(yield contract.withdraw.estimateGas(this.constantOptions)));
194
+ return (yield contract.withdraw(Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
195
+ });
196
+ }
197
+ export function claimableFees() {
198
+ return __awaiter(this, arguments, void 0, function* (address = "") {
199
+ address = address || this.signerAddress;
200
+ const contract = new Contract(this.constants.ALIASES.fee_distributor, feeDistributorViewABI, this.provider);
201
+ return this.formatUnits(yield contract.claim(address, this.constantOptions));
202
+ });
203
+ }
204
+ export function claimFeesEstimateGas() {
205
+ return __awaiter(this, arguments, void 0, function* (address = "") {
206
+ address = address || this.signerAddress;
207
+ const contract = this.contracts[this.constants.ALIASES.fee_distributor].contract;
208
+ return Number(DIGas(yield contract.claim.estimateGas(address, this.constantOptions)));
209
+ });
210
+ }
211
+ export function claimFees() {
212
+ return __awaiter(this, arguments, void 0, function* (address = "") {
213
+ if (this.chainId !== 1) {
214
+ throw Error('This method is only available for the network with chainId 1');
215
+ }
216
+ address = address || this.signerAddress;
217
+ const contract = this.contracts[this.constants.ALIASES.fee_distributor].contract;
218
+ yield this.updateFeeData();
219
+ const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, this.constantOptions)));
220
+ return (yield contract.claim(address, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
221
+ });
222
+ }
223
+ export function claimableFeesCrvUSD() {
224
+ return __awaiter(this, arguments, void 0, function* (address = "") {
225
+ if (this.chainId !== 1) {
226
+ throw Error('This method is only available for the network with chainId 1');
227
+ }
228
+ address = address || this.signerAddress;
229
+ const contract = new Contract(this.constants.ALIASES.fee_distributor_crvusd, feeDistributorCrvUSDViewABI, this.provider);
230
+ return this.formatUnits(yield contract.claim(address, this.constantOptions));
231
+ });
232
+ }
233
+ export function claimFeesCrvUSDEstimateGas() {
234
+ return __awaiter(this, arguments, void 0, function* (address = "") {
235
+ if (this.chainId !== 1) {
236
+ throw Error('This method is only available for the network with chainId 1');
237
+ }
238
+ address = address || this.signerAddress;
239
+ const contract = this.contracts[this.constants.ALIASES.fee_distributor_crvusd].contract;
240
+ return Number(DIGas(yield contract.claim.estimateGas(address, this.constantOptions)));
241
+ });
242
+ }
243
+ export function claimFeesCrvUSD() {
244
+ return __awaiter(this, arguments, void 0, function* (address = "") {
245
+ address = address || this.signerAddress;
246
+ const contract = this.contracts[this.constants.ALIASES.fee_distributor_crvusd].contract;
247
+ yield this.updateFeeData();
248
+ const gasLimit = mulBy1_3(DIGas(yield contract.claim.estimateGas(address, this.constantOptions)));
249
+ return (yield contract.claim(address, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
250
+ });
251
+ }
212
252
  // ------------ SIDECHAIN ------------
213
- export const lastEthBlock = () => __awaiter(void 0, void 0, void 0, function* () {
214
- if (curve.chainId === 1)
215
- throw Error("There is no lastBlock method on ethereum network");
216
- const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
217
- return Number(yield veOracleContract.last_eth_block_number(curve.constantOptions));
218
- });
219
- export const getAnycallBalance = () => __awaiter(void 0, void 0, void 0, function* () {
220
- if (curve.chainId === 1)
221
- throw Error("There is no getAnycallBalance method on ethereum network");
222
- const anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
223
- const _balance = yield anycallContract.executionBudget(curve.constants.ALIASES.voting_escrow_oracle, curve.constantOptions);
224
- return curve.formatUnits(_balance);
225
- });
226
- const DEFAULT_AMOUNT = (curve.chainId === 42161 || curve.chainId === 10) ? 0.00001 : 0.1;
227
- const _topUpAnycall = (amount, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
228
- if (curve.chainId === 1)
229
- throw Error("There is no topUpAnycall method on ethereum network");
230
- const anycallContract = curve.contracts[curve.constants.ALIASES.anycall].contract;
231
- const value = curve.parseUnits(String(amount));
232
- const gas = yield anycallContract.deposit.estimateGas(curve.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, curve.constantOptions), { value }));
233
- if (estimateGas)
234
- return smartNumber(gas);
235
- yield curve.updateFeeData();
236
- const gasLimit = mulBy1_3(DIGas(gas));
237
- return (yield anycallContract.deposit(curve.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
238
- });
239
- export const topUpAnycallEstimateGas = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (amount = DEFAULT_AMOUNT) {
240
- return yield _topUpAnycall(amount, true);
241
- });
242
- export const topUpAnycall = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (amount = DEFAULT_AMOUNT) {
243
- return yield _topUpAnycall(amount, false);
244
- });
245
- export const lastBlockSent = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
246
- if (curve.chainId !== 1)
247
- throw Error("lastBlockNumberSent method is on ethereum network only");
248
- const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
249
- return Number(yield veOracleContract.get_last_block_number_sent(chainId, curve.constantOptions));
250
- });
251
- export const blockToSend = () => __awaiter(void 0, void 0, void 0, function* () {
252
- if (curve.chainId !== 1)
253
- throw Error("blockToSend method is on ethereum network only");
254
- return (yield curve.provider.getBlockNumber()) - 128;
255
- });
256
- const _sendBlockhash = (block, chainId, estimateGas) => __awaiter(void 0, void 0, void 0, function* () {
257
- if (curve.chainId !== 1)
258
- throw Error("sendBlockhash method is on ethereum network only");
259
- const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
260
- const gas = yield veOracleContract.send_blockhash.estimateGas(block, chainId, curve.constantOptions);
261
- if (estimateGas)
262
- return smartNumber(gas);
263
- yield curve.updateFeeData();
264
- const gasLimit = mulBy1_3(DIGas(gas));
265
- return (yield veOracleContract.send_blockhash(block, chainId, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
266
- });
267
- export const sendBlockhashEstimateGas = (block, chainId) => __awaiter(void 0, void 0, void 0, function* () {
268
- return yield _sendBlockhash(block, chainId, true);
269
- });
270
- export const sendBlockhash = (block, chainId) => __awaiter(void 0, void 0, void 0, function* () {
271
- return yield _sendBlockhash(block, chainId, false);
272
- });
273
- const _submitProof = (block_1, ...args_1) => __awaiter(void 0, [block_1, ...args_1], void 0, function* (block, address = curve.signerAddress, estimateGas) {
274
- if (curve.chainId === 1)
275
- throw Error("submitProof method is on ethereum network only");
276
- if (address === "")
277
- throw Error("Pass address you want to submit proof for");
278
- const proof = yield _generateBoostingProof(block, address);
279
- const veOracleContract = curve.contracts[curve.constants.ALIASES.voting_escrow_oracle].contract;
280
- const gas = yield veOracleContract.submit_state.estimateGas(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, curve.constantOptions);
281
- if (estimateGas)
282
- return smartNumber(gas);
283
- yield curve.updateFeeData();
284
- const gasLimit = mulBy1_3(DIGas(gas));
285
- return (yield veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, Object.assign(Object.assign({}, curve.options), { gasLimit }))).hash;
286
- });
287
- export const submitProofEstimateGas = (block_1, ...args_1) => __awaiter(void 0, [block_1, ...args_1], void 0, function* (block, address = curve.signerAddress) {
288
- return yield _submitProof(block, address, true);
289
- });
290
- export const submitProof = (block_1, ...args_1) => __awaiter(void 0, [block_1, ...args_1], void 0, function* (block, address = curve.signerAddress) {
291
- return yield _submitProof(block, address, false);
292
- });
253
+ export function lastEthBlock() {
254
+ return __awaiter(this, void 0, void 0, function* () {
255
+ if (this.chainId === 1)
256
+ throw Error("There is no lastBlock method on ethereum network");
257
+ const veOracleContract = this.contracts[this.constants.ALIASES.voting_escrow_oracle].contract;
258
+ return Number(yield veOracleContract.last_eth_block_number(this.constantOptions));
259
+ });
260
+ }
261
+ export function getAnycallBalance() {
262
+ return __awaiter(this, void 0, void 0, function* () {
263
+ if (this.chainId === 1)
264
+ throw Error("There is no getAnycallBalance method on ethereum network");
265
+ const anycallContract = this.contracts[this.constants.ALIASES.anycall].contract;
266
+ const _balance = yield anycallContract.executionBudget(this.constants.ALIASES.voting_escrow_oracle, this.constantOptions);
267
+ return this.formatUnits(_balance);
268
+ });
269
+ }
270
+ function defaultAmount() {
271
+ return (this.chainId === 42161 || this.chainId === 10) ? 0.00001 : 0.1;
272
+ }
273
+ function _topUpAnycall(amount, estimateGas) {
274
+ return __awaiter(this, void 0, void 0, function* () {
275
+ if (this.chainId === 1)
276
+ throw Error("There is no topUpAnycall method on ethereum network");
277
+ const anycallContract = this.contracts[this.constants.ALIASES.anycall].contract;
278
+ const value = this.parseUnits(String(amount));
279
+ const gas = yield anycallContract.deposit.estimateGas(this.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, this.constantOptions), { value }));
280
+ if (estimateGas)
281
+ return smartNumber(gas);
282
+ yield this.updateFeeData();
283
+ const gasLimit = mulBy1_3(DIGas(gas));
284
+ return (yield anycallContract.deposit(this.constants.ALIASES.voting_escrow_oracle, Object.assign(Object.assign({}, this.options), { gasLimit, value }))).hash;
285
+ });
286
+ }
287
+ export function topUpAnycallEstimateGas() {
288
+ return __awaiter(this, arguments, void 0, function* (amount = defaultAmount.call(this)) {
289
+ return yield _topUpAnycall.call(this, amount, true);
290
+ });
291
+ }
292
+ export function topUpAnycall() {
293
+ return __awaiter(this, arguments, void 0, function* (amount = defaultAmount.call(this)) {
294
+ return yield _topUpAnycall.call(this, amount, false);
295
+ });
296
+ }
297
+ export function lastBlockSent(chainId) {
298
+ return __awaiter(this, void 0, void 0, function* () {
299
+ if (this.chainId !== 1)
300
+ throw Error("lastBlockNumberSent method is on ethereum network only");
301
+ const veOracleContract = this.contracts[this.constants.ALIASES.voting_escrow_oracle].contract;
302
+ return Number(yield veOracleContract.get_last_block_number_sent(chainId, this.constantOptions));
303
+ });
304
+ }
305
+ export function blockToSend() {
306
+ return __awaiter(this, void 0, void 0, function* () {
307
+ if (this.chainId !== 1)
308
+ throw Error("blockToSend method is on ethereum network only");
309
+ return (yield this.provider.getBlockNumber()) - 128;
310
+ });
311
+ }
312
+ function _sendBlockhash(block, chainId, estimateGas) {
313
+ return __awaiter(this, void 0, void 0, function* () {
314
+ if (this.chainId !== 1)
315
+ throw Error("sendBlockhash method is on ethereum network only");
316
+ const veOracleContract = this.contracts[this.constants.ALIASES.voting_escrow_oracle].contract;
317
+ const gas = yield veOracleContract.send_blockhash.estimateGas(block, chainId, this.constantOptions);
318
+ if (estimateGas)
319
+ return smartNumber(gas);
320
+ yield this.updateFeeData();
321
+ const gasLimit = mulBy1_3(DIGas(gas));
322
+ return (yield veOracleContract.send_blockhash(block, chainId, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
323
+ });
324
+ }
325
+ export function sendBlockhashEstimateGas(block, chainId) {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ return yield _sendBlockhash.call(this, block, chainId, true);
328
+ });
329
+ }
330
+ export function sendBlockhash(block, chainId) {
331
+ return __awaiter(this, void 0, void 0, function* () {
332
+ return yield _sendBlockhash.call(this, block, chainId, false);
333
+ });
334
+ }
335
+ function _submitProof(block_1) {
336
+ return __awaiter(this, arguments, void 0, function* (block, address = this.signerAddress, estimateGas) {
337
+ if (this.chainId === 1)
338
+ throw Error("submitProof method is on ethereum network only");
339
+ if (address === "")
340
+ throw Error("Pass address you want to submit proof for");
341
+ const proof = yield _generateBoostingProof(block, address);
342
+ const veOracleContract = this.contracts[this.constants.ALIASES.voting_escrow_oracle].contract;
343
+ const gas = yield veOracleContract.submit_state.estimateGas(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, this.constantOptions);
344
+ if (estimateGas)
345
+ return smartNumber(gas);
346
+ yield this.updateFeeData();
347
+ const gasLimit = mulBy1_3(DIGas(gas));
348
+ return (yield veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
349
+ });
350
+ }
351
+ export function submitProofEstimateGas(block_1) {
352
+ return __awaiter(this, arguments, void 0, function* (block, address = this.signerAddress) {
353
+ return yield _submitProof.call(this, block, address, true);
354
+ });
355
+ }
356
+ export function submitProof(block_1) {
357
+ return __awaiter(this, arguments, void 0, function* (block, address = this.signerAddress) {
358
+ return yield _submitProof.call(this, block, address, false);
359
+ });
360
+ }