@curvefi/api 2.66.29 → 2.66.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/boosting.d.ts +33 -32
- package/lib/boosting.js +320 -252
- package/lib/cached.d.ts +4 -3
- package/lib/cached.js +63 -19
- package/lib/constants/utils.d.ts +14 -1
- package/lib/constants/utils.js +21 -6
- package/lib/curve.d.ts +5 -5
- package/lib/curve.js +21 -38
- package/lib/dao.d.ts +32 -31
- package/lib/dao.js +420 -350
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +2 -2
- package/lib/factory/common.d.ts +2 -1
- package/lib/factory/common.js +1 -1
- package/lib/factory/deploy.d.ts +46 -45
- package/lib/factory/deploy.js +630 -551
- package/lib/factory/factory-api.d.ts +3 -2
- package/lib/factory/factory-api.js +22 -23
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +12 -15
- package/lib/factory/factory-tricrypto.d.ts +1 -1
- package/lib/factory/factory-tricrypto.js +14 -15
- package/lib/factory/factory-twocrypto.d.ts +1 -1
- package/lib/factory/factory-twocrypto.js +12 -13
- package/lib/factory/factory.d.ts +4 -3
- package/lib/factory/factory.js +21 -24
- package/lib/index.d.ts +413 -104
- package/lib/index.js +253 -257
- package/lib/interfaces.d.ts +2 -0
- package/lib/pools/PoolTemplate.d.ts +13 -12
- package/lib/pools/PoolTemplate.js +279 -285
- package/lib/pools/mixins/common.js +2 -2
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
- package/lib/pools/mixins/depositMixins.d.ts +25 -5
- package/lib/pools/mixins/depositMixins.js +38 -76
- package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/depositWrappedMixins.js +17 -33
- package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
- package/lib/pools/mixins/poolBalancesMixin.js +3 -5
- package/lib/pools/mixins/swapMixins.d.ts +20 -4
- package/lib/pools/mixins/swapMixins.js +36 -70
- package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
- package/lib/pools/mixins/swapWrappedMixins.js +32 -60
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
- package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
- package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawMixins.js +33 -67
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
- package/lib/pools/poolConstructor.d.ts +2 -1
- package/lib/pools/poolConstructor.js +27 -28
- package/lib/pools/subClasses/corePool.d.ts +4 -1
- package/lib/pools/subClasses/corePool.js +5 -7
- package/lib/pools/subClasses/gaugePool.d.ts +5 -3
- package/lib/pools/subClasses/gaugePool.js +19 -18
- package/lib/pools/subClasses/statsPool.d.ts +2 -0
- package/lib/pools/subClasses/statsPool.js +22 -10
- package/lib/pools/subClasses/walletPool.d.ts +2 -1
- package/lib/pools/subClasses/walletPool.js +6 -6
- package/lib/pools/utils.d.ts +7 -6
- package/lib/pools/utils.js +316 -297
- package/lib/route-graph.worker.d.ts +2 -2
- package/lib/route-graph.worker.js +4 -6
- package/lib/router.d.ts +12 -11
- package/lib/router.js +331 -295
- package/lib/utils.d.ts +34 -33
- package/lib/utils.js +481 -435
- package/package.json +1 -1
package/lib/dao.js
CHANGED
|
@@ -7,372 +7,442 @@ 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 { curve } from "./curve.js";
|
|
11
10
|
import { Contract } from "ethers";
|
|
12
|
-
import { _getAllGauges,
|
|
13
|
-
import { _getAddress, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN,
|
|
14
|
-
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type:
|
|
11
|
+
import { _getAllGauges, _getDaoProposal, _getDaoProposalList } from './external-api.js';
|
|
12
|
+
import { _getAddress, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from './utils.js';
|
|
13
|
+
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: "json" };
|
|
15
14
|
// ----------------- Refactored boosting stuff -----------------
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
address =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
15
|
+
export function crvSupplyStats() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (this.chainId !== 1)
|
|
18
|
+
throw Error("Ethereum-only method");
|
|
19
|
+
const crvContract = this.contracts[this.constants.ALIASES.crv].multicallContract;
|
|
20
|
+
const veContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
|
|
21
|
+
const csContract = this.contracts[this.constants.ALIASES.circulating_supply].multicallContract;
|
|
22
|
+
const [_circulating, _locked, _veCrv] = yield this.multicallProvider.all([
|
|
23
|
+
csContract.circulating_supply(),
|
|
24
|
+
crvContract.balanceOf(this.constants.ALIASES.voting_escrow),
|
|
25
|
+
veContract.totalSupply(),
|
|
26
|
+
]);
|
|
27
|
+
return {
|
|
28
|
+
circulating: this.formatUnits(_circulating),
|
|
29
|
+
locked: this.formatUnits(_locked),
|
|
30
|
+
total: this.formatUnits(_circulating + _locked),
|
|
31
|
+
veCrv: this.formatUnits(_veCrv),
|
|
32
|
+
averageLockTime: toBN(_veCrv).div(toBN(_locked)).times(4).toFixed(4), // years
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function userCrv() {
|
|
37
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
38
|
+
if (this.chainId !== 1)
|
|
39
|
+
throw Error("Ethereum-only method");
|
|
40
|
+
address = _getAddress.call(this, address);
|
|
41
|
+
const _balance = yield this.contracts[this.constants.ALIASES.crv].contract.balanceOf(address);
|
|
42
|
+
return this.formatUnits(_balance);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export function userVeCrv() {
|
|
46
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
47
|
+
if (this.chainId !== 1)
|
|
48
|
+
throw Error("Ethereum-only method");
|
|
49
|
+
address = _getAddress.call(this, address);
|
|
50
|
+
const contract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
|
|
51
|
+
const [_veCrv, _veCrvTotal, _locked] = yield this.multicallProvider.all([
|
|
52
|
+
contract.balanceOf(address),
|
|
53
|
+
contract.totalSupply(),
|
|
54
|
+
contract.locked(address),
|
|
55
|
+
]);
|
|
56
|
+
const _lockedCrv = _locked[0];
|
|
57
|
+
const _unlockTime = _locked[1];
|
|
58
|
+
return {
|
|
59
|
+
veCrv: this.formatUnits(_veCrv),
|
|
60
|
+
veCrvPct: toBN(_veCrv).div(toBN(_veCrvTotal)).times(100).toString(),
|
|
61
|
+
lockedCrv: this.formatUnits(_lockedCrv),
|
|
62
|
+
unlockTime: Number(this.formatUnits(_unlockTime, 0)) * 1000,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function crvLockIsApproved(amount) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (this.chainId !== 1)
|
|
69
|
+
throw Error("Ethereum-only method");
|
|
70
|
+
return yield hasAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.signerAddress, this.constants.ALIASES.voting_escrow);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function crvLockApproveEstimateGas(amount) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
if (this.chainId !== 1)
|
|
76
|
+
throw Error("Ethereum-only method");
|
|
77
|
+
return yield ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crv], [amount], this.constants.ALIASES.voting_escrow, false);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function crvLockApprove(amount) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (this.chainId !== 1)
|
|
83
|
+
throw Error("Ethereum-only method");
|
|
84
|
+
return yield ensureAllowance.call(this, [this.constants.ALIASES.crv], [amount], this.constants.ALIASES.voting_escrow, false);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
76
87
|
export const calcCrvUnlockTime = (days, start = Date.now()) => {
|
|
77
88
|
const week = 86400 * 7;
|
|
78
89
|
const now = Number(start) / 1000;
|
|
79
90
|
const unlockTime = now + (86400 * Number(days));
|
|
80
91
|
return Math.floor(unlockTime / week) * week * 1000;
|
|
81
92
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
93
|
+
function _createCrvLock(amount, days, estimateGas) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
if (this.chainId !== 1)
|
|
96
|
+
throw Error("Ethereum-only method");
|
|
97
|
+
const crvBalance = yield userCrv.call(this);
|
|
98
|
+
if (BN(crvBalance).lt(amount))
|
|
99
|
+
throw Error(`Not enough CRV. Wallet balance: ${crvBalance}, required: ${amount}`);
|
|
100
|
+
if (!(yield crvLockIsApproved.call(this, amount)))
|
|
101
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
102
|
+
const _amount = parseUnits(amount);
|
|
103
|
+
const unlockTime = Math.floor(Date.now() / 1000) + (days * 86400);
|
|
104
|
+
const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
|
|
105
|
+
const gas = yield contract.create_lock.estimateGas(_amount, unlockTime, this.constantOptions);
|
|
106
|
+
if (estimateGas)
|
|
107
|
+
return smartNumber(gas);
|
|
108
|
+
yield this.updateFeeData();
|
|
109
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
110
|
+
return (yield contract.create_lock(_amount, unlockTime, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export function createCrvLockEstimateGas(amount, days) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
return yield _createCrvLock.call(this, amount, Number(days), true);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export function createCrvLock(amount, days) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return yield _createCrvLock.call(this, amount, Number(days), false);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function _increaseCrvLockedAmount(amount, estimateGas) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
if (this.chainId !== 1)
|
|
126
|
+
throw Error("Ethereum-only method");
|
|
127
|
+
const crvBalance = yield userCrv.call(this);
|
|
128
|
+
if (BN(crvBalance).lt(amount))
|
|
129
|
+
throw Error(`Not enough CRV. Wallet balance: ${crvBalance}, required: ${amount}`);
|
|
130
|
+
if (!(yield crvLockIsApproved.call(this, amount)))
|
|
131
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
132
|
+
const _amount = parseUnits(amount);
|
|
133
|
+
const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
|
|
134
|
+
const gas = yield contract.increase_amount.estimateGas(_amount, this.constantOptions);
|
|
135
|
+
if (estimateGas)
|
|
136
|
+
return smartNumber(gas);
|
|
137
|
+
yield this.updateFeeData();
|
|
138
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
139
|
+
return (yield contract.increase_amount(_amount, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export function increaseCrvLockedAmountEstimateGas(amount) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
return yield _increaseCrvLockedAmount.call(this, amount, true);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function increaseCrvLockedAmount(amount) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
return yield _increaseCrvLockedAmount.call(this, amount, false);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function _increaseCrvUnlockTime(days, estimateGas) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
if (this.chainId !== 1)
|
|
155
|
+
throw Error("Ethereum-only method");
|
|
156
|
+
const { unlockTime } = yield userVeCrv.call(this);
|
|
157
|
+
const newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
|
|
158
|
+
const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
|
|
159
|
+
const gas = yield contract.increase_unlock_time.estimateGas(newUnlockTime, this.constantOptions);
|
|
160
|
+
if (estimateGas)
|
|
161
|
+
return smartNumber(gas);
|
|
162
|
+
yield this.updateFeeData();
|
|
163
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
164
|
+
return (yield contract.increase_unlock_time(newUnlockTime, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
export function increaseCrvUnlockTimeEstimateGas(days) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return yield _increaseCrvUnlockTime.call(this, Number(days), true);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export function increaseCrvUnlockTime(days) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
return yield _increaseCrvUnlockTime.call(this, Number(days), false);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function _withdrawLockedCrv(estimateGas) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
if (this.chainId !== 1)
|
|
180
|
+
throw Error("Ethereum-only method");
|
|
181
|
+
const { unlockTime } = yield userVeCrv.call(this);
|
|
182
|
+
if (unlockTime > Date.now())
|
|
183
|
+
throw Error("The lock haven't expired yet");
|
|
184
|
+
const contract = this.contracts[this.constants.ALIASES.voting_escrow].contract;
|
|
185
|
+
const gas = yield contract.withdraw.estimateGas(this.constantOptions);
|
|
186
|
+
if (estimateGas)
|
|
187
|
+
return smartNumber(gas);
|
|
188
|
+
yield this.updateFeeData();
|
|
189
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
190
|
+
return (yield contract.withdraw(Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
export function withdrawLockedCrvEstimateGas() {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
return yield _withdrawLockedCrv.call(this, true);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
export function withdrawLockedCrv() {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
return yield _withdrawLockedCrv.call(this, false);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
export function claimableFees() {
|
|
204
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
205
|
+
address = _getAddress.call(this, address);
|
|
206
|
+
const contract = new Contract(this.constants.ALIASES.fee_distributor, feeDistributorViewABI, this.provider);
|
|
207
|
+
return this.formatUnits(yield contract.claim(address, this.constantOptions));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function _claimFees(address, estimateGas) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
address = _getAddress.call(this, address);
|
|
213
|
+
const contract = this.contracts[this.constants.ALIASES.fee_distributor].contract;
|
|
214
|
+
const gas = yield contract.claim.estimateGas(address, this.constantOptions);
|
|
215
|
+
if (estimateGas)
|
|
216
|
+
return smartNumber(gas);
|
|
217
|
+
yield this.updateFeeData();
|
|
218
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
219
|
+
return (yield contract.claim(address, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
export function claimFeesEstimateGas() {
|
|
223
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
224
|
+
return yield _claimFees.call(this, address, true);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
export function claimFees() {
|
|
228
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
229
|
+
return yield _claimFees.call(this, address, false);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
189
232
|
// ----------------- Gauge weights -----------------
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
for (let i = 0; i < gaugeData.length; i++) {
|
|
202
|
-
if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
|
|
203
|
-
continue;
|
|
204
|
-
res.push({
|
|
205
|
-
poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
|
|
206
|
-
network: gaugeData[i].blockchainId,
|
|
207
|
-
gaugeAddress: gaugeData[i].gauge,
|
|
208
|
-
poolAddress: gaugeData[i].swap || '',
|
|
209
|
-
lpTokenAddress: gaugeData[i].swap_token || '',
|
|
210
|
-
poolName: gaugeData[i].shortName,
|
|
211
|
-
totalVeCrv: curve.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
|
|
212
|
-
relativeWeight: curve.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
|
|
213
|
-
isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return res;
|
|
217
|
-
});
|
|
218
|
-
export const userGaugeVotes = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (address = "") {
|
|
219
|
-
var _a, _b;
|
|
220
|
-
if (curve.chainId !== 1)
|
|
221
|
-
throw Error("Ethereum-only method");
|
|
222
|
-
address = _getAddress(address);
|
|
223
|
-
const gcMulticallContract = curve.contracts[curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
224
|
-
const veMulticallContract = curve.contracts[curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
225
|
-
const gaugeData = Object.values(yield _getAllGauges());
|
|
226
|
-
const calls = [veMulticallContract.balanceOf(address)];
|
|
227
|
-
for (const d of gaugeData) {
|
|
228
|
-
const gaugeAddress = d.rootGauge ? d.rootGauge : d.gauge;
|
|
229
|
-
calls.push(gcMulticallContract.vote_user_slopes(address, gaugeAddress));
|
|
230
|
-
}
|
|
231
|
-
const [veCrvBalance, ...votes] = yield curve.multicallProvider.all(calls);
|
|
232
|
-
const res = { gauges: [], powerUsed: "0.0", veCrvUsed: "0.0" };
|
|
233
|
-
let powerUsed = BigInt(0);
|
|
234
|
-
let veCrvUsed = BigInt(0);
|
|
235
|
-
for (let i = 0; i < votes.length; i++) {
|
|
236
|
-
if (votes[i][1] === BigInt(0))
|
|
237
|
-
continue;
|
|
238
|
-
let dt = votes[i][2] - BigInt(Math.floor(Date.now() / 1000));
|
|
239
|
-
if (dt < BigInt(0))
|
|
240
|
-
dt = BigInt(0);
|
|
241
|
-
res.gauges.push({
|
|
242
|
-
userPower: curve.formatUnits(votes[i][1], 2),
|
|
243
|
-
userVeCrv: curve.formatUnits(votes[i][0] * dt, 18),
|
|
244
|
-
userFutureVeCrv: curve.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
|
|
245
|
-
expired: dt === BigInt(0),
|
|
246
|
-
gaugeData: {
|
|
233
|
+
export function getVotingGaugeList() {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
if (this.chainId !== 1)
|
|
237
|
+
throw Error("Ethereum-only method");
|
|
238
|
+
const gaugeData = Object.values(yield _getAllGauges());
|
|
239
|
+
const res = [];
|
|
240
|
+
for (let i = 0; i < gaugeData.length; i++) {
|
|
241
|
+
if ((gaugeData[i].is_killed || gaugeData[i].hasNoCrv) && Number(gaugeData[i].gauge_controller.gauge_relative_weight) === 0)
|
|
242
|
+
continue;
|
|
243
|
+
res.push({
|
|
247
244
|
poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
|
|
248
245
|
network: gaugeData[i].blockchainId,
|
|
249
246
|
gaugeAddress: gaugeData[i].gauge,
|
|
250
247
|
poolAddress: gaugeData[i].swap || '',
|
|
251
248
|
lpTokenAddress: gaugeData[i].swap_token || '',
|
|
252
249
|
poolName: gaugeData[i].shortName,
|
|
253
|
-
totalVeCrv:
|
|
254
|
-
relativeWeight:
|
|
250
|
+
totalVeCrv: this.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
|
|
251
|
+
relativeWeight: this.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
|
|
255
252
|
isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return res;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
export function userGaugeVotes() {
|
|
259
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
260
|
+
var _a, _b;
|
|
261
|
+
if (this.chainId !== 1)
|
|
262
|
+
throw Error("Ethereum-only method");
|
|
263
|
+
address = _getAddress.call(this, address);
|
|
264
|
+
const gcMulticallContract = this.contracts[this.constants.ALIASES.gauge_controller].multicallContract;
|
|
265
|
+
const veMulticallContract = this.contracts[this.constants.ALIASES.voting_escrow].multicallContract;
|
|
266
|
+
const gaugeData = Object.values(yield _getAllGauges());
|
|
267
|
+
const calls = [veMulticallContract.balanceOf(address)];
|
|
268
|
+
for (const d of gaugeData) {
|
|
269
|
+
const gaugeAddress = d.rootGauge ? d.rootGauge : d.gauge;
|
|
270
|
+
calls.push(gcMulticallContract.vote_user_slopes(address, gaugeAddress));
|
|
271
|
+
}
|
|
272
|
+
const [veCrvBalance, ...votes] = yield this.multicallProvider.all(calls);
|
|
273
|
+
const res = { gauges: [], powerUsed: "0.0", veCrvUsed: "0.0" };
|
|
274
|
+
let powerUsed = BigInt(0);
|
|
275
|
+
let veCrvUsed = BigInt(0);
|
|
276
|
+
for (let i = 0; i < votes.length; i++) {
|
|
277
|
+
if (votes[i][1] === BigInt(0))
|
|
278
|
+
continue;
|
|
279
|
+
let dt = votes[i][2] - BigInt(Math.floor(Date.now() / 1000));
|
|
280
|
+
if (dt < BigInt(0))
|
|
281
|
+
dt = BigInt(0);
|
|
282
|
+
res.gauges.push({
|
|
283
|
+
userPower: this.formatUnits(votes[i][1], 2),
|
|
284
|
+
userVeCrv: this.formatUnits(votes[i][0] * dt, 18),
|
|
285
|
+
userFutureVeCrv: this.formatUnits(veCrvBalance * votes[i][1] / BigInt(10000), 18),
|
|
286
|
+
expired: dt === BigInt(0),
|
|
287
|
+
gaugeData: {
|
|
288
|
+
poolUrl: ((_a = gaugeData[i].poolUrls) === null || _a === void 0 ? void 0 : _a.swap[0]) || '',
|
|
289
|
+
network: gaugeData[i].blockchainId,
|
|
290
|
+
gaugeAddress: gaugeData[i].gauge,
|
|
291
|
+
poolAddress: gaugeData[i].swap || '',
|
|
292
|
+
lpTokenAddress: gaugeData[i].swap_token || '',
|
|
293
|
+
poolName: gaugeData[i].shortName,
|
|
294
|
+
totalVeCrv: this.formatUnits(gaugeData[i].gauge_controller.get_gauge_weight, 18),
|
|
295
|
+
relativeWeight: this.formatUnits(gaugeData[i].gauge_controller.gauge_relative_weight, 16),
|
|
296
|
+
isKilled: (_b = gaugeData[i].is_killed) !== null && _b !== void 0 ? _b : false,
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
powerUsed += votes[i][1];
|
|
300
|
+
veCrvUsed += votes[i][0] * dt;
|
|
301
|
+
}
|
|
302
|
+
res.powerUsed = this.formatUnits(powerUsed, 2);
|
|
303
|
+
res.veCrvUsed = this.formatUnits(veCrvUsed.toString(), 18);
|
|
304
|
+
return res;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
export function voteForGaugeNextTime(gauge) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
if (this.chainId !== 1)
|
|
310
|
+
throw Error("Ethereum-only method");
|
|
311
|
+
const _lastVote = yield this.contracts[this.constants.ALIASES.gauge_controller].contract.last_user_vote(this.signerAddress, gauge, this.constantOptions);
|
|
312
|
+
return (Number(_lastVote) + (10 * 86400)) * 1000;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function _voteForGauge(gauge, power, estimateGas) {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
if (this.chainId !== 1)
|
|
318
|
+
throw Error("Ethereum-only method");
|
|
319
|
+
const gcContract = this.contracts[this.constants.ALIASES.gauge_controller].contract;
|
|
320
|
+
const gcMulticallContract = this.contracts[this.constants.ALIASES.gauge_controller].multicallContract;
|
|
321
|
+
const _power = parseUnits(power, 2);
|
|
322
|
+
const [_powerUsed, _vote_slopes] = yield this.multicallProvider.all([
|
|
323
|
+
gcMulticallContract.vote_user_power(this.signerAddress),
|
|
324
|
+
gcMulticallContract.vote_user_slopes(this.signerAddress, gauge),
|
|
325
|
+
]);
|
|
326
|
+
const _freePower = BigInt(10000) - _powerUsed;
|
|
327
|
+
if (_power > _freePower + _vote_slopes[1])
|
|
328
|
+
throw Error(`User have only ${this.formatUnits(_freePower, 2)} % free power. Trying to use ${this.formatUnits(_power, 2)}`);
|
|
329
|
+
const nextVoteTime = yield voteForGaugeNextTime.call(this, gauge);
|
|
330
|
+
if (Date.now() < nextVoteTime)
|
|
331
|
+
throw Error(`User can't change vote for this gauge earlier than ${new Date(nextVoteTime)}`);
|
|
332
|
+
const gas = yield gcContract.vote_for_gauge_weights.estimateGas(gauge, _power, this.constantOptions);
|
|
333
|
+
if (estimateGas)
|
|
334
|
+
return smartNumber(gas);
|
|
335
|
+
yield this.updateFeeData();
|
|
336
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
337
|
+
return (yield gcContract.vote_for_gauge_weights(gauge, _power, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export function voteForGaugeEstimateGas(gauge, power) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
return yield _voteForGauge.call(this, gauge, power, true);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
export function voteForGauge(gauge, power) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
return yield _voteForGauge.call(this, gauge, power, false);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
300
350
|
// ----------------- Proposals -----------------
|
|
301
|
-
export
|
|
302
|
-
return
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
351
|
+
export function getProposalList() {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
+
return yield _getDaoProposalList();
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
export function getProposal(type, id) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
+
return yield _getDaoProposal(type, id);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
export function userProposalVotes() {
|
|
362
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
363
|
+
if (this.chainId !== 1)
|
|
364
|
+
throw Error("Ethereum-only method");
|
|
365
|
+
address = _getAddress.call(this, address);
|
|
366
|
+
const proposalList = yield _getDaoProposalList();
|
|
367
|
+
const calls = [];
|
|
368
|
+
for (const proposal of proposalList) {
|
|
369
|
+
if (proposal.voteType.toUpperCase() == "PARAMETER") {
|
|
370
|
+
calls.push(this.contracts[this.constants.ALIASES.voting_parameter].multicallContract.getVoterState(proposal.voteId, address));
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
calls.push(this.contracts[this.constants.ALIASES.voting_ownership].multicallContract.getVoterState(proposal.voteId, address));
|
|
374
|
+
}
|
|
316
375
|
}
|
|
317
|
-
|
|
318
|
-
|
|
376
|
+
const userState = (yield this.multicallProvider.all(calls)).map(Number);
|
|
377
|
+
const userProposalList = [];
|
|
378
|
+
const voteEnum = {
|
|
379
|
+
1: "yes",
|
|
380
|
+
2: "no",
|
|
381
|
+
3: "even",
|
|
382
|
+
};
|
|
383
|
+
for (let i = 0; i < proposalList.length; i++) {
|
|
384
|
+
if (userState[i] > 0)
|
|
385
|
+
userProposalList.push(Object.assign(Object.assign({}, proposalList[i]), { userVote: voteEnum[userState[i]] }));
|
|
319
386
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
387
|
+
return userProposalList;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function _voteForProposal(type, id, support, estimateGas) {
|
|
391
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
392
|
+
if (this.chainId !== 1)
|
|
393
|
+
throw Error("Ethereum-only method");
|
|
394
|
+
const contractAddress = type.toUpperCase() === "PARAMETER" ? this.constants.ALIASES.voting_parameter : this.constants.ALIASES.voting_ownership;
|
|
395
|
+
const contract = this.contracts[contractAddress].contract;
|
|
396
|
+
const yesPct = support ? BigInt(Math.pow(10, 18)) : BigInt(0);
|
|
397
|
+
const noPct = BigInt(Math.pow(10, 18)) - yesPct;
|
|
398
|
+
const gas = yield contract.votePct.estimateGas(id, yesPct, noPct, true, this.constantOptions);
|
|
399
|
+
if (estimateGas)
|
|
400
|
+
return smartNumber(gas);
|
|
401
|
+
yield this.updateFeeData();
|
|
402
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
403
|
+
return (yield contract.votePct(id, yesPct, noPct, false, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
export function voteForProposalEstimateGas(type, id, support) {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
+
return yield _voteForProposal.call(this, type, id, support, true);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
export function voteForProposal(type, id, support) {
|
|
412
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
413
|
+
return yield _voteForProposal.call(this, type, id, support, false);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function _executeVote(type_1, id_1) {
|
|
417
|
+
return __awaiter(this, arguments, void 0, function* (type, id, estimateGas = false) {
|
|
418
|
+
if (this.chainId !== 1)
|
|
419
|
+
throw Error("Ethereum-only method");
|
|
420
|
+
const contractAddress = type.toUpperCase() === "PARAMETER" ? this.constants.ALIASES.voting_parameter : this.constants.ALIASES.voting_ownership;
|
|
421
|
+
const contract = this.contracts[contractAddress].contract;
|
|
422
|
+
const gas = yield contract.executeVote.estimateGas(id, this.constantOptions);
|
|
423
|
+
if (estimateGas)
|
|
424
|
+
return smartNumber(gas);
|
|
425
|
+
yield this.updateFeeData();
|
|
426
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
427
|
+
return (yield contract.executeVote(id, Object.assign(Object.assign({}, this.options), { gasLimit }))).hash;
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
export function executeVoteEstimateGas(type, id) {
|
|
431
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
+
return yield _executeVote.call(this, type, id, true);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
export function executeVote(type, id) {
|
|
436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
+
return yield _executeVote.call(this, type, id, false);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
export function isCanVoteExecute(type, id) {
|
|
441
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
+
if (this.chainId !== 1)
|
|
443
|
+
throw Error("Ethereum-only method");
|
|
444
|
+
const contractAddress = type.toUpperCase() === "PARAMETER" ? this.constants.ALIASES.voting_parameter : this.constants.ALIASES.voting_ownership;
|
|
445
|
+
const contract = this.contracts[contractAddress].contract;
|
|
446
|
+
return yield contract.canExecute(id, Object.assign({}, this.options));
|
|
447
|
+
});
|
|
448
|
+
}
|