@curvefi/api 2.3.4 → 2.4.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.
- package/README.md +129 -7
- package/lib/constants/pools/ethereum.js +25 -26
- package/lib/interfaces.d.ts +9 -0
- package/lib/pools/PoolTemplate.d.ts +24 -3
- package/lib/pools/PoolTemplate.js +441 -54
- package/lib/utils.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -424,6 +424,7 @@ import curve from "@curvefi/api";
|
|
|
424
424
|
|
|
425
425
|
await compound.stats.parameters();
|
|
426
426
|
// {
|
|
427
|
+
// lpTokenSupply: '66658430.461661546713781772',
|
|
427
428
|
// virtualPrice: '1.107067773320466717',
|
|
428
429
|
// fee: '0.04',
|
|
429
430
|
// adminFee: '0.02',
|
|
@@ -1070,21 +1071,94 @@ import curve from "@curvefi/api";
|
|
|
1070
1071
|
})()
|
|
1071
1072
|
```
|
|
1072
1073
|
|
|
1073
|
-
##
|
|
1074
|
+
## CRV. Profit, claim, boosting
|
|
1074
1075
|
```ts
|
|
1075
1076
|
import curve from "@curvefi/api";
|
|
1076
1077
|
|
|
1077
1078
|
(async () => {
|
|
1078
|
-
await curve.init('JsonRpc', {}, { gasPrice: 0
|
|
1079
|
-
|
|
1080
|
-
const pool = curve.getPool('susd');
|
|
1079
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0 });
|
|
1081
1080
|
|
|
1082
|
-
|
|
1081
|
+
const pool = curve.getPool('compound');
|
|
1082
|
+
|
|
1083
|
+
await pool.depositAndStake([1000, 1000]);
|
|
1084
|
+
await pool.crvProfit();
|
|
1085
|
+
// {
|
|
1086
|
+
// day: '0.01861607837347995222',
|
|
1087
|
+
// week: '0.13031254861435966551',
|
|
1088
|
+
// month: '0.55848235120439856649',
|
|
1089
|
+
// year: '6.79486860632018255891',
|
|
1090
|
+
// token: '0xd533a949740bb3306d119cc777fa900ba034cd52',
|
|
1091
|
+
// symbol: 'CRV',
|
|
1092
|
+
// price: 0.978134
|
|
1093
|
+
// }
|
|
1094
|
+
await pool.stats.tokenApy();
|
|
1095
|
+
// [ '0.3324', '0.8309' ]
|
|
1096
|
+
await pool.currentCrvApy();
|
|
1097
|
+
// 0.3324
|
|
1098
|
+
await pool.boost();
|
|
1099
|
+
// 1.0
|
|
1100
|
+
|
|
1101
|
+
await curve.boosting.createLock(10000, 365 * 4);
|
|
1102
|
+
await pool.depositAndStake([1000, 1000]);
|
|
1103
|
+
// crvProfit = {
|
|
1104
|
+
// day: '0.05703837081508656944',
|
|
1105
|
+
// week: '0.39926859570560598606',
|
|
1106
|
+
// month: '1.7111511244525970831',
|
|
1107
|
+
// year: '20.81900534750659784443',
|
|
1108
|
+
// token: '0xd533a949740bb3306d119cc777fa900ba034cd52',
|
|
1109
|
+
// symbol: 'CRV',
|
|
1110
|
+
// price: 0.978134
|
|
1111
|
+
// }
|
|
1112
|
+
//
|
|
1113
|
+
// currentApy = 0.5092
|
|
1114
|
+
// boost = 1.532
|
|
1115
|
+
|
|
1116
|
+
await pool.wallet.lpTokenBalances();
|
|
1117
|
+
// { lpToken: '0.0', gauge: '3610.795806899650569624' }
|
|
1118
|
+
await pool.maxBoostedStake();
|
|
1119
|
+
// 1281.660714834072909477
|
|
1120
|
+
|
|
1121
|
+
// ------ Wait some time... ------
|
|
1083
1122
|
await pool.claimableCrv();
|
|
1084
|
-
// 0.
|
|
1123
|
+
// 0.4085482040149887
|
|
1085
1124
|
await pool.claimCrv();
|
|
1125
|
+
// claimableCrv = 0.0
|
|
1126
|
+
})()
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
## Rewards. Profit and claim
|
|
1130
|
+
```ts
|
|
1131
|
+
import curve from "@curvefi/api";
|
|
1086
1132
|
|
|
1087
|
-
|
|
1133
|
+
(async () => {
|
|
1134
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
1135
|
+
|
|
1136
|
+
const pool = curve.getPool('susd');
|
|
1137
|
+
|
|
1138
|
+
await pool.rewardTokens();
|
|
1139
|
+
// [
|
|
1140
|
+
// {
|
|
1141
|
+
// token: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
|
1142
|
+
// symbol: 'SNX',
|
|
1143
|
+
// decimals: 18
|
|
1144
|
+
// }
|
|
1145
|
+
// ]
|
|
1146
|
+
await pool.depositAndStake([1000, 1000, 1000, 1000]);
|
|
1147
|
+
await pool.rewardsProfit();
|
|
1148
|
+
// [
|
|
1149
|
+
// {
|
|
1150
|
+
// day: '0.02387645750842563304',
|
|
1151
|
+
// week: '0.16713520255897943129',
|
|
1152
|
+
// month: '0.71629372525276899123',
|
|
1153
|
+
// year: '8.71490699057535605995',
|
|
1154
|
+
// token: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
|
1155
|
+
// symbol: 'SNX',
|
|
1156
|
+
// price: 2.61
|
|
1157
|
+
// }
|
|
1158
|
+
// ]
|
|
1159
|
+
|
|
1160
|
+
// ------ Wait some time... ------
|
|
1161
|
+
|
|
1088
1162
|
await pool.claimableRewards();
|
|
1089
1163
|
// [
|
|
1090
1164
|
// {
|
|
@@ -1094,8 +1168,56 @@ import curve from "@curvefi/api";
|
|
|
1094
1168
|
// }
|
|
1095
1169
|
// ]
|
|
1096
1170
|
await pool.claimRewards();
|
|
1171
|
+
// claimableRewards = [
|
|
1172
|
+
// {
|
|
1173
|
+
// token: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
|
1174
|
+
// symbol: 'SNX',
|
|
1175
|
+
// amount: '0.0'
|
|
1176
|
+
// }
|
|
1177
|
+
// ]
|
|
1097
1178
|
})()
|
|
1098
1179
|
```
|
|
1180
|
+
## User balances, base profit and share
|
|
1181
|
+
```ts
|
|
1182
|
+
(async () => {
|
|
1183
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0 });
|
|
1184
|
+
|
|
1185
|
+
const pool = curve.getPool('frax');
|
|
1186
|
+
|
|
1187
|
+
await pool.deposit([1000, 1000, 1000, 1000]);
|
|
1188
|
+
// { lpToken: '3967.761942945398518479', gauge: '0.0' }
|
|
1189
|
+
await pool.stake(2000);
|
|
1190
|
+
// { lpToken: '1967.761942945398518479', gauge: '2000.0' }
|
|
1191
|
+
|
|
1192
|
+
await pool.userBalances();
|
|
1193
|
+
// [
|
|
1194
|
+
// '2489.266644542275414077',
|
|
1195
|
+
// '276.21290758040371998',
|
|
1196
|
+
// '280.160024',
|
|
1197
|
+
// '955.058471'
|
|
1198
|
+
// ]
|
|
1199
|
+
await pool.userWrappedBalances();
|
|
1200
|
+
// [ '2489.266644542275414077', '1479.135765218522838249' ]
|
|
1201
|
+
await pool.userLiquidityUSD();
|
|
1202
|
+
// 4003.16466431
|
|
1203
|
+
await pool.baseProfit();
|
|
1204
|
+
// {
|
|
1205
|
+
// day: '0.01476134356908610233',
|
|
1206
|
+
// week: '0.1036132769753159106',
|
|
1207
|
+
// month: '0.44899086689303561258',
|
|
1208
|
+
// year: '5.38789040271642735101374407'
|
|
1209
|
+
// }
|
|
1210
|
+
await pool.userShare();
|
|
1211
|
+
// {
|
|
1212
|
+
// lpUser: '3967.761942945398518479',
|
|
1213
|
+
// lpTotal: '1124490985.047288488832152598',
|
|
1214
|
+
// lpShare: '0.000352849600015116',
|
|
1215
|
+
// gaugeUser: '2000.0',
|
|
1216
|
+
// gaugeTotal: '1123703753.306098922471106555',
|
|
1217
|
+
// gaugeShare: '0.000177982853053192'
|
|
1218
|
+
// }
|
|
1219
|
+
})()
|
|
1220
|
+
````
|
|
1099
1221
|
|
|
1100
1222
|
## Gas estimation
|
|
1101
1223
|
Every non-constant method has corresponding gas estimation method. Rule: ```obj.method -> obj.estimateGas.method```
|
|
@@ -17,17 +17,16 @@ var deposit_json_2 = __importDefault(require("../abis/usdt/deposit.json"));
|
|
|
17
17
|
var swap_json_2 = __importDefault(require("../abis/usdt/swap.json"));
|
|
18
18
|
var deposit_json_3 = __importDefault(require("../abis/iearn/deposit.json"));
|
|
19
19
|
var swap_json_3 = __importDefault(require("../abis/iearn/swap.json"));
|
|
20
|
-
var sCurveRewards_json_1 = __importDefault(require("../abis/iearn/sCurveRewards.json"));
|
|
21
20
|
var deposit_json_4 = __importDefault(require("../abis/busd/deposit.json"));
|
|
22
21
|
var swap_json_4 = __importDefault(require("../abis/busd/swap.json"));
|
|
23
22
|
var deposit_json_5 = __importDefault(require("../abis/susdv2/deposit.json"));
|
|
24
23
|
var swap_json_5 = __importDefault(require("../abis/susdv2/swap.json"));
|
|
25
|
-
var
|
|
24
|
+
var sCurveRewards_json_1 = __importDefault(require("../abis/susdv2/sCurveRewards.json"));
|
|
26
25
|
var deposit_json_6 = __importDefault(require("../abis/pax/deposit.json"));
|
|
27
26
|
var swap_json_6 = __importDefault(require("../abis/pax/swap.json"));
|
|
28
27
|
var swap_json_7 = __importDefault(require("../abis/ren/swap.json"));
|
|
29
28
|
var swap_json_8 = __importDefault(require("../abis/sbtc/swap.json"));
|
|
30
|
-
var
|
|
29
|
+
var sCurveRewards_json_2 = __importDefault(require("../abis/sbtc/sCurveRewards.json"));
|
|
31
30
|
var swap_json_9 = __importDefault(require("../abis/hbtc/swap.json"));
|
|
32
31
|
var swap_json_10 = __importDefault(require("../abis/3pool/swap.json"));
|
|
33
32
|
var swap_json_11 = __importDefault(require("../abis/gusd/swap.json"));
|
|
@@ -40,36 +39,36 @@ var swap_json_14 = __importDefault(require("../abis/usdn/swap.json"));
|
|
|
40
39
|
var deposit_json_10 = __importDefault(require("../abis/usdn/deposit.json"));
|
|
41
40
|
var swap_json_15 = __importDefault(require("../abis/musd/swap.json"));
|
|
42
41
|
var deposit_json_11 = __importDefault(require("../abis/musd/deposit.json"));
|
|
43
|
-
var
|
|
42
|
+
var sCurveRewards_json_3 = __importDefault(require("../abis/musd/sCurveRewards.json"));
|
|
44
43
|
var swap_json_16 = __importDefault(require("../abis/rsv/swap.json"));
|
|
45
44
|
var deposit_json_12 = __importDefault(require("../abis/rsv/deposit.json"));
|
|
46
|
-
var
|
|
45
|
+
var sCurveRewards_json_4 = __importDefault(require("../abis/rsv/sCurveRewards.json"));
|
|
47
46
|
var swap_json_17 = __importDefault(require("../abis/tbtc/swap.json"));
|
|
48
47
|
var deposit_json_13 = __importDefault(require("../abis/tbtc/deposit.json"));
|
|
49
|
-
var
|
|
48
|
+
var sCurveRewards_json_5 = __importDefault(require("../abis/tbtc/sCurveRewards.json"));
|
|
50
49
|
var swap_json_18 = __importDefault(require("../abis/dusd/swap.json"));
|
|
51
50
|
var deposit_json_14 = __importDefault(require("../abis/dusd/deposit.json"));
|
|
52
|
-
var
|
|
51
|
+
var sCurveRewards_json_6 = __importDefault(require("../abis/dusd/sCurveRewards.json"));
|
|
53
52
|
var swap_json_19 = __importDefault(require("../abis/pbtc/swap.json"));
|
|
54
53
|
var deposit_json_15 = __importDefault(require("../abis/pbtc/deposit.json"));
|
|
55
|
-
var
|
|
54
|
+
var sCurveRewards_json_7 = __importDefault(require("../abis/pbtc/sCurveRewards.json"));
|
|
56
55
|
var swap_json_20 = __importDefault(require("../abis/bbtc/swap.json"));
|
|
57
56
|
var deposit_json_16 = __importDefault(require("../abis/bbtc/deposit.json"));
|
|
58
57
|
var swap_json_21 = __importDefault(require("../abis/obtc/swap.json"));
|
|
59
58
|
var deposit_json_17 = __importDefault(require("../abis/obtc/deposit.json"));
|
|
60
|
-
var
|
|
59
|
+
var sCurveRewards_json_8 = __importDefault(require("../abis/obtc/sCurveRewards.json"));
|
|
61
60
|
var swap_json_22 = __importDefault(require("../abis/seth/swap.json"));
|
|
62
61
|
var swap_json_23 = __importDefault(require("../abis/eurs/swap.json"));
|
|
63
|
-
var
|
|
62
|
+
var sCurveRewards_json_9 = __importDefault(require("../abis/eurs/sCurveRewards.json"));
|
|
64
63
|
var swap_json_24 = __importDefault(require("../abis/ust/swap.json"));
|
|
65
64
|
var deposit_json_18 = __importDefault(require("../abis/ust/deposit.json"));
|
|
66
65
|
var swap_json_25 = __importDefault(require("../abis/aave/swap.json"));
|
|
67
66
|
var rewards_json_1 = __importDefault(require("../abis/aave/rewards.json"));
|
|
68
67
|
var swap_json_26 = __importDefault(require("../abis/steth/swap.json"));
|
|
69
|
-
var
|
|
68
|
+
var sCurveRewards_json_10 = __importDefault(require("../abis/steth/sCurveRewards.json"));
|
|
70
69
|
var swap_json_27 = __importDefault(require("../abis/saave/swap.json"));
|
|
71
70
|
var swap_json_28 = __importDefault(require("../abis/ankreth/swap.json"));
|
|
72
|
-
var
|
|
71
|
+
var sCurveRewards_json_11 = __importDefault(require("../abis/ankreth/sCurveRewards.json"));
|
|
73
72
|
var swap_json_29 = __importDefault(require("../abis/usdp/swap.json"));
|
|
74
73
|
var deposit_json_19 = __importDefault(require("../abis/usdp/deposit.json"));
|
|
75
74
|
var swap_json_30 = __importDefault(require("../abis/ib/swap.json"));
|
|
@@ -157,7 +156,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
157
156
|
token_address: '0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8',
|
|
158
157
|
gauge_address: '0xFA712EE4788C042e2B7BB55E6cb8ec569C4530c1',
|
|
159
158
|
deposit_address: '0xbBC81d23Ea2c3ec7e56D39296F0cbB648873a5d3',
|
|
160
|
-
sCurveRewards_address: '0x0001FB050Fe7312791bF6475b96569D83F695C9f',
|
|
159
|
+
// sCurveRewards_address: '0x0001FB050Fe7312791bF6475b96569D83F695C9f',
|
|
161
160
|
is_lending: true,
|
|
162
161
|
underlying_coins: ['DAI', 'USDC', 'USDT', 'TUSD'],
|
|
163
162
|
wrapped_coins: ['yDAI', 'yUSDC', 'yUSDT', 'yTUSD'],
|
|
@@ -179,7 +178,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
179
178
|
swap_abi: swap_json_3.default,
|
|
180
179
|
gauge_abi: gauge_json_1.default,
|
|
181
180
|
deposit_abi: deposit_json_3.default,
|
|
182
|
-
sCurveRewards_abi:
|
|
181
|
+
// sCurveRewards_abi: iearnSCurveRewardsABI,
|
|
183
182
|
},
|
|
184
183
|
busd: {
|
|
185
184
|
name: "busd",
|
|
@@ -242,7 +241,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
242
241
|
swap_abi: swap_json_5.default,
|
|
243
242
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
244
243
|
deposit_abi: deposit_json_5.default,
|
|
245
|
-
sCurveRewards_abi:
|
|
244
|
+
sCurveRewards_abi: sCurveRewards_json_1.default,
|
|
246
245
|
},
|
|
247
246
|
pax: {
|
|
248
247
|
name: "pax",
|
|
@@ -325,7 +324,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
325
324
|
wrapped_decimals: [8, 8, 18],
|
|
326
325
|
swap_abi: swap_json_8.default,
|
|
327
326
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
328
|
-
sCurveRewards_abi:
|
|
327
|
+
sCurveRewards_abi: sCurveRewards_json_2.default,
|
|
329
328
|
},
|
|
330
329
|
hbtc: {
|
|
331
330
|
name: "hbtc",
|
|
@@ -522,7 +521,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
522
521
|
swap_abi: swap_json_15.default,
|
|
523
522
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
524
523
|
deposit_abi: deposit_json_11.default,
|
|
525
|
-
sCurveRewards_abi:
|
|
524
|
+
sCurveRewards_abi: sCurveRewards_json_3.default,
|
|
526
525
|
},
|
|
527
526
|
rsv: {
|
|
528
527
|
name: "rsv",
|
|
@@ -553,7 +552,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
553
552
|
swap_abi: swap_json_16.default,
|
|
554
553
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
555
554
|
deposit_abi: deposit_json_12.default,
|
|
556
|
-
sCurveRewards_abi:
|
|
555
|
+
sCurveRewards_abi: sCurveRewards_json_4.default,
|
|
557
556
|
},
|
|
558
557
|
tbtc: {
|
|
559
558
|
name: "tbtc",
|
|
@@ -584,7 +583,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
584
583
|
swap_abi: swap_json_17.default,
|
|
585
584
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
586
585
|
deposit_abi: deposit_json_13.default,
|
|
587
|
-
sCurveRewards_abi:
|
|
586
|
+
sCurveRewards_abi: sCurveRewards_json_5.default,
|
|
588
587
|
},
|
|
589
588
|
dusd: {
|
|
590
589
|
name: "dusd",
|
|
@@ -615,7 +614,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
615
614
|
swap_abi: swap_json_18.default,
|
|
616
615
|
gauge_abi: gauge_synthetix_json_1.default,
|
|
617
616
|
deposit_abi: deposit_json_14.default,
|
|
618
|
-
sCurveRewards_abi:
|
|
617
|
+
sCurveRewards_abi: sCurveRewards_json_6.default,
|
|
619
618
|
},
|
|
620
619
|
pbtc: {
|
|
621
620
|
name: "pbtc",
|
|
@@ -646,7 +645,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
646
645
|
swap_abi: swap_json_19.default,
|
|
647
646
|
gauge_abi: gauge_v2_json_1.default,
|
|
648
647
|
deposit_abi: deposit_json_15.default,
|
|
649
|
-
sCurveRewards_abi:
|
|
648
|
+
sCurveRewards_abi: sCurveRewards_json_7.default,
|
|
650
649
|
},
|
|
651
650
|
bbtc: {
|
|
652
651
|
name: "bbtc",
|
|
@@ -706,7 +705,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
706
705
|
swap_abi: swap_json_21.default,
|
|
707
706
|
gauge_abi: gauge_v2_json_1.default,
|
|
708
707
|
deposit_abi: deposit_json_17.default,
|
|
709
|
-
sCurveRewards_abi:
|
|
708
|
+
sCurveRewards_abi: sCurveRewards_json_8.default,
|
|
710
709
|
},
|
|
711
710
|
seth: {
|
|
712
711
|
name: "seth",
|
|
@@ -756,7 +755,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
756
755
|
wrapped_decimals: [2, 18],
|
|
757
756
|
swap_abi: swap_json_23.default,
|
|
758
757
|
gauge_abi: gauge_v2_json_1.default,
|
|
759
|
-
sCurveRewards_abi:
|
|
758
|
+
sCurveRewards_abi: sCurveRewards_json_9.default,
|
|
760
759
|
},
|
|
761
760
|
ust: {
|
|
762
761
|
name: "ust",
|
|
@@ -795,7 +794,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
795
794
|
swap_address: '0xDeBF20617708857ebe4F679508E7b7863a8A8EeE',
|
|
796
795
|
token_address: '0xFd2a8fA60Abd58Efe3EeE34dd494cD491dC14900',
|
|
797
796
|
gauge_address: '0xd662908ADA2Ea1916B3318327A97eB18aD588b5d',
|
|
798
|
-
sCurveRewards_address: "
|
|
797
|
+
sCurveRewards_address: "0x96d7bc17912e4f320c4894194564cf8425cfe8d9",
|
|
799
798
|
is_lending: true,
|
|
800
799
|
underlying_coins: ['DAI', 'USDC', 'USDT'],
|
|
801
800
|
wrapped_coins: ['aDAI', 'aUSDC', 'aUSDT'],
|
|
@@ -840,7 +839,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
840
839
|
wrapped_decimals: [18, 18],
|
|
841
840
|
swap_abi: swap_json_26.default,
|
|
842
841
|
gauge_abi: gauge_v2_json_1.default,
|
|
843
|
-
sCurveRewards_abi:
|
|
842
|
+
sCurveRewards_abi: sCurveRewards_json_10.default,
|
|
844
843
|
},
|
|
845
844
|
saave: {
|
|
846
845
|
name: "saave",
|
|
@@ -893,7 +892,7 @@ exports.POOLS_DATA_ETHEREUM = (0, utils_1.lowerCasePoolDataAddresses)({
|
|
|
893
892
|
wrapped_decimals: [18, 18],
|
|
894
893
|
swap_abi: swap_json_28.default,
|
|
895
894
|
gauge_abi: gauge_v2_json_1.default,
|
|
896
|
-
sCurveRewards_abi:
|
|
895
|
+
sCurveRewards_abi: sCurveRewards_json_11.default,
|
|
897
896
|
},
|
|
898
897
|
usdp: {
|
|
899
898
|
name: "usdp",
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import memoize from "memoizee";
|
|
2
|
-
import { IDict, IReward } from '../interfaces';
|
|
2
|
+
import { IDict, IReward, IProfit } from '../interfaces';
|
|
3
3
|
export declare class PoolTemplate {
|
|
4
4
|
id: string;
|
|
5
5
|
name: string;
|
|
@@ -120,9 +120,13 @@ export declare class PoolTemplate {
|
|
|
120
120
|
stake(lpTokenAmount: number | string): Promise<string>;
|
|
121
121
|
private unstakeEstimateGas;
|
|
122
122
|
unstake(lpTokenAmount: number | string): Promise<string>;
|
|
123
|
+
crvProfit: (address?: string) => Promise<IProfit>;
|
|
123
124
|
claimableCrv(address?: string): Promise<string>;
|
|
124
125
|
claimCrvEstimateGas(): Promise<number>;
|
|
125
126
|
claimCrv(): Promise<string>;
|
|
127
|
+
boost: (address?: string) => Promise<string>;
|
|
128
|
+
currentCrvApy: (address?: string) => Promise<string>;
|
|
129
|
+
maxBoostedStake: (...addresses: string[]) => Promise<IDict<string> | string>;
|
|
126
130
|
rewardTokens: (() => Promise<{
|
|
127
131
|
token: string;
|
|
128
132
|
symbol: string;
|
|
@@ -132,6 +136,7 @@ export declare class PoolTemplate {
|
|
|
132
136
|
symbol: string;
|
|
133
137
|
decimals: number;
|
|
134
138
|
}[]>>;
|
|
139
|
+
rewardsProfit: (address?: string) => Promise<IProfit[]>;
|
|
135
140
|
claimableRewards(address?: string): Promise<{
|
|
136
141
|
token: string;
|
|
137
142
|
symbol: string;
|
|
@@ -192,6 +197,24 @@ export declare class PoolTemplate {
|
|
|
192
197
|
private walletUnderlyingCoinBalances;
|
|
193
198
|
private walletWrappedCoinBalances;
|
|
194
199
|
private walletAllCoinBalances;
|
|
200
|
+
private _userLpTotalBalance;
|
|
201
|
+
userBalances(address?: string): Promise<string[]>;
|
|
202
|
+
userWrappedBalances(address?: string): Promise<string[]>;
|
|
203
|
+
userLiquidityUSD(address?: string): Promise<string>;
|
|
204
|
+
baseProfit(address?: string): Promise<{
|
|
205
|
+
day: string;
|
|
206
|
+
week: string;
|
|
207
|
+
month: string;
|
|
208
|
+
year: string;
|
|
209
|
+
}>;
|
|
210
|
+
userShare(address?: string): Promise<{
|
|
211
|
+
lpUser: string;
|
|
212
|
+
lpTotal: string;
|
|
213
|
+
lpShare: string;
|
|
214
|
+
gaugeUser?: string;
|
|
215
|
+
gaugeTotal?: string;
|
|
216
|
+
gaugeShare?: string;
|
|
217
|
+
}>;
|
|
195
218
|
private _swapExpected;
|
|
196
219
|
swapExpected(inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<string>;
|
|
197
220
|
swapPriceImpact(inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<string>;
|
|
@@ -209,9 +232,7 @@ export declare class PoolTemplate {
|
|
|
209
232
|
swapWrappedApprove(inputCoin: string | number, amount: number | string): Promise<string[]>;
|
|
210
233
|
private swapWrappedEstimateGas;
|
|
211
234
|
swapWrapped(inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage?: number): Promise<string>;
|
|
212
|
-
gaugeMaxBoostedDeposit: (...addresses: string[]) => Promise<IDict<string>>;
|
|
213
235
|
gaugeOptimalDeposits: (...accounts: string[]) => Promise<IDict<string>>;
|
|
214
|
-
boost: (address: string) => Promise<string>;
|
|
215
236
|
private _getCoinIdx;
|
|
216
237
|
private _getRates;
|
|
217
238
|
private _balances;
|
|
@@ -67,16 +67,22 @@ var external_api_1 = require("../external-api");
|
|
|
67
67
|
var utils_1 = require("../utils");
|
|
68
68
|
var curve_1 = require("../curve");
|
|
69
69
|
var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
|
|
70
|
+
var DAY = 86400;
|
|
71
|
+
var WEEK = 7 * DAY;
|
|
72
|
+
var MONTH = 30 * DAY;
|
|
73
|
+
var YEAR = 365 * DAY;
|
|
70
74
|
var PoolTemplate = /** @class */ (function () {
|
|
71
75
|
function PoolTemplate(id) {
|
|
72
76
|
var _this = this;
|
|
73
77
|
this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
74
|
-
var multicallContract, calls, additionalCalls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
|
|
78
|
+
var multicallContract, lpMulticallContract, calls, additionalCalls, _a, _lpTokenSupply, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, lpTokenSupply, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
|
|
75
79
|
return __generator(this, function (_f) {
|
|
76
80
|
switch (_f.label) {
|
|
77
81
|
case 0:
|
|
78
82
|
multicallContract = curve_1.curve.contracts[this.address].multicallContract;
|
|
83
|
+
lpMulticallContract = curve_1.curve.contracts[this.lpToken].multicallContract;
|
|
79
84
|
calls = [
|
|
85
|
+
lpMulticallContract.totalSupply(),
|
|
80
86
|
multicallContract.get_virtual_price(),
|
|
81
87
|
multicallContract.fee(),
|
|
82
88
|
multicallContract.admin_fee(),
|
|
@@ -90,14 +96,15 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
90
96
|
}
|
|
91
97
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
92
98
|
case 1:
|
|
93
|
-
_a = _f.sent(),
|
|
99
|
+
_a = _f.sent(), _lpTokenSupply = _a[0], _virtualPrice = _a[1], _fee = _a[2], _adminFee = _a[3], _A = _a[4], _gamma = _a[5];
|
|
94
100
|
_c = [
|
|
101
|
+
ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
|
|
95
102
|
ethers_1.ethers.utils.formatUnits(_virtualPrice),
|
|
96
103
|
ethers_1.ethers.utils.formatUnits(_fee, 8),
|
|
97
104
|
ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
|
|
98
105
|
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
99
106
|
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
100
|
-
],
|
|
107
|
+
], lpTokenSupply = _c[0], virtualPrice = _c[1], fee = _c[2], adminFee = _c[3], A = _c[4], gamma = _c[5];
|
|
101
108
|
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
|
|
102
109
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
|
|
103
110
|
case 2:
|
|
@@ -108,7 +115,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
108
115
|
_future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
|
|
109
116
|
_initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
|
|
110
117
|
], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
|
|
111
|
-
return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
|
|
118
|
+
return [2 /*return*/, { lpTokenSupply: lpTokenSupply, virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
|
|
112
119
|
}
|
|
113
120
|
});
|
|
114
121
|
}); };
|
|
@@ -313,6 +320,182 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
313
320
|
}
|
|
314
321
|
});
|
|
315
322
|
}); };
|
|
323
|
+
// ---------------- CRV PROFIT, CLAIM, BOOSTING ----------------
|
|
324
|
+
this.crvProfit = function (address) {
|
|
325
|
+
if (address === void 0) { address = ""; }
|
|
326
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
327
|
+
var inflationRateBN, workingSupplyBN, workingBalanceBN, gaugeContract, crvContract, currentWeek, _a, gaugeContract, gaugeControllerContract, weightBN, crvPrice, dailyIncome, weeklyIncome, monthlyIncome, annualIncome;
|
|
328
|
+
var _c, _d;
|
|
329
|
+
return __generator(this, function (_e) {
|
|
330
|
+
switch (_e.label) {
|
|
331
|
+
case 0:
|
|
332
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
333
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
334
|
+
address = address || curve_1.curve.signerAddress;
|
|
335
|
+
if (!address)
|
|
336
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
337
|
+
if (!(curve_1.curve.chainId !== 1)) return [3 /*break*/, 4];
|
|
338
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
339
|
+
crvContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.crv].contract;
|
|
340
|
+
currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
341
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
342
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
343
|
+
gaugeContract.working_balances(address),
|
|
344
|
+
gaugeContract.working_supply(),
|
|
345
|
+
])];
|
|
346
|
+
case 1:
|
|
347
|
+
_c = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _c[0], workingBalanceBN = _c[1], workingSupplyBN = _c[2];
|
|
348
|
+
if (!inflationRateBN.eq(0)) return [3 /*break*/, 3];
|
|
349
|
+
_a = utils_1.toBN;
|
|
350
|
+
return [4 /*yield*/, crvContract.balanceOf(this.gauge, curve_1.curve.constantOptions)];
|
|
351
|
+
case 2:
|
|
352
|
+
inflationRateBN = _a.apply(void 0, [_e.sent()]).div(WEEK);
|
|
353
|
+
_e.label = 3;
|
|
354
|
+
case 3: return [3 /*break*/, 6];
|
|
355
|
+
case 4:
|
|
356
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
357
|
+
gaugeControllerContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.gauge_controller].multicallContract;
|
|
358
|
+
weightBN = void 0;
|
|
359
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
360
|
+
gaugeContract.inflation_rate(),
|
|
361
|
+
gaugeControllerContract.gauge_relative_weight(this.gauge),
|
|
362
|
+
gaugeContract.working_balances(address),
|
|
363
|
+
gaugeContract.working_supply(),
|
|
364
|
+
])];
|
|
365
|
+
case 5:
|
|
366
|
+
_d = (_e.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflationRateBN = _d[0], weightBN = _d[1], workingBalanceBN = _d[2], workingSupplyBN = _d[3];
|
|
367
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
368
|
+
_e.label = 6;
|
|
369
|
+
case 6: return [4 /*yield*/, (0, utils_1._getUsdRate)('CRV')];
|
|
370
|
+
case 7:
|
|
371
|
+
crvPrice = _e.sent();
|
|
372
|
+
if (workingSupplyBN.eq(0))
|
|
373
|
+
return [2 /*return*/, {
|
|
374
|
+
day: "0.0",
|
|
375
|
+
week: "0.0",
|
|
376
|
+
month: "0.0",
|
|
377
|
+
year: "0.0",
|
|
378
|
+
token: curve_1.curve.constants.ALIASES.crv,
|
|
379
|
+
symbol: 'CRV',
|
|
380
|
+
price: crvPrice,
|
|
381
|
+
}];
|
|
382
|
+
dailyIncome = inflationRateBN.times(DAY).times(workingBalanceBN).div(workingSupplyBN);
|
|
383
|
+
weeklyIncome = inflationRateBN.times(WEEK).times(workingBalanceBN).div(workingSupplyBN);
|
|
384
|
+
monthlyIncome = inflationRateBN.times(MONTH).times(workingBalanceBN).div(workingSupplyBN);
|
|
385
|
+
annualIncome = inflationRateBN.times(YEAR).times(workingBalanceBN).div(workingSupplyBN);
|
|
386
|
+
return [2 /*return*/, {
|
|
387
|
+
day: dailyIncome.toString(),
|
|
388
|
+
week: weeklyIncome.toString(),
|
|
389
|
+
month: monthlyIncome.toString(),
|
|
390
|
+
year: annualIncome.toString(),
|
|
391
|
+
token: curve_1.curve.constants.ALIASES.crv,
|
|
392
|
+
symbol: 'CRV',
|
|
393
|
+
price: crvPrice,
|
|
394
|
+
}];
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
this.boost = function (address) {
|
|
400
|
+
if (address === void 0) { address = ""; }
|
|
401
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
402
|
+
var gaugeContract, _a, workingBalanceBN, balanceBN, boostBN;
|
|
403
|
+
return __generator(this, function (_c) {
|
|
404
|
+
switch (_c.label) {
|
|
405
|
+
case 0:
|
|
406
|
+
if (curve_1.curve.chainId !== 1)
|
|
407
|
+
throw Error("Boosting is available only on Ethereum network");
|
|
408
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
409
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
410
|
+
address = address || curve_1.curve.signerAddress;
|
|
411
|
+
if (!address)
|
|
412
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
413
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
414
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
415
|
+
gaugeContract.working_balances(address),
|
|
416
|
+
gaugeContract.balanceOf(address),
|
|
417
|
+
])];
|
|
418
|
+
case 1:
|
|
419
|
+
_a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), workingBalanceBN = _a[0], balanceBN = _a[1];
|
|
420
|
+
boostBN = workingBalanceBN.div(0.4).div(balanceBN);
|
|
421
|
+
return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
this.currentCrvApy = function (address) {
|
|
427
|
+
if (address === void 0) { address = ""; }
|
|
428
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
429
|
+
var _a, baseApy, maxApy, boost;
|
|
430
|
+
return __generator(this, function (_c) {
|
|
431
|
+
switch (_c.label) {
|
|
432
|
+
case 0:
|
|
433
|
+
address = address || curve_1.curve.signerAddress;
|
|
434
|
+
if (!address)
|
|
435
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
436
|
+
return [4 /*yield*/, this.statsTokenApy()];
|
|
437
|
+
case 1:
|
|
438
|
+
_a = _c.sent(), baseApy = _a[0], maxApy = _a[1];
|
|
439
|
+
if (curve_1.curve.chainId !== 1)
|
|
440
|
+
return [2 /*return*/, baseApy];
|
|
441
|
+
return [4 /*yield*/, this.boost(address)];
|
|
442
|
+
case 2:
|
|
443
|
+
boost = _c.sent();
|
|
444
|
+
if (boost == "2.5")
|
|
445
|
+
return [2 /*return*/, maxApy];
|
|
446
|
+
if (boost === "NaN")
|
|
447
|
+
return [2 /*return*/, "NaN"];
|
|
448
|
+
return [2 /*return*/, (0, utils_1.BN)(baseApy).times((0, utils_1.BN)(boost)).toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
this.maxBoostedStake = function () {
|
|
454
|
+
var addresses = [];
|
|
455
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
456
|
+
addresses[_i] = arguments[_i];
|
|
457
|
+
}
|
|
458
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
459
|
+
var votingEscrowContract, gaugeContract, contractCalls, _response, responseBN, _a, veTotalSupplyBN, gaugeTotalSupplyBN, resultBN, result, _c, _d, entry;
|
|
460
|
+
return __generator(this, function (_e) {
|
|
461
|
+
switch (_e.label) {
|
|
462
|
+
case 0:
|
|
463
|
+
if (curve_1.curve.chainId !== 1)
|
|
464
|
+
throw Error("Boosting is available only on Ethereum network");
|
|
465
|
+
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
466
|
+
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
467
|
+
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
468
|
+
addresses = addresses[0];
|
|
469
|
+
if (addresses.length === 0 && curve_1.curve.signerAddress !== '')
|
|
470
|
+
addresses = [curve_1.curve.signerAddress];
|
|
471
|
+
if (addresses.length === 0)
|
|
472
|
+
throw Error("Need to connect wallet or pass addresses into args");
|
|
473
|
+
votingEscrowContract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.voting_escrow].multicallContract;
|
|
474
|
+
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
475
|
+
contractCalls = [votingEscrowContract.totalSupply(), gaugeContract.totalSupply()];
|
|
476
|
+
addresses.forEach(function (account) {
|
|
477
|
+
contractCalls.push(votingEscrowContract.balanceOf(account));
|
|
478
|
+
});
|
|
479
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
|
|
480
|
+
case 1:
|
|
481
|
+
_response = _e.sent();
|
|
482
|
+
responseBN = _response.map(function (value) { return (0, utils_1.toBN)(value); });
|
|
483
|
+
_a = responseBN.splice(0, 2), veTotalSupplyBN = _a[0], gaugeTotalSupplyBN = _a[1];
|
|
484
|
+
resultBN = {};
|
|
485
|
+
addresses.forEach(function (acct, i) {
|
|
486
|
+
resultBN[acct] = responseBN[i].div(veTotalSupplyBN).times(gaugeTotalSupplyBN);
|
|
487
|
+
});
|
|
488
|
+
result = {};
|
|
489
|
+
for (_c = 0, _d = Object.entries(resultBN); _c < _d.length; _c++) {
|
|
490
|
+
entry = _d[_c];
|
|
491
|
+
result[entry[0]] = (0, utils_1.toStringFromBN)(entry[1]);
|
|
492
|
+
}
|
|
493
|
+
return [2 /*return*/, addresses.length === 1 ? result[addresses[0]] : result];
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
// ---------------- REWARDS PROFIT, CLAIM ----------------
|
|
316
499
|
this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
317
500
|
var gaugeContract, gaugeMulticallContract, rewardCount, _a, _c, _d, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, _e, symbol, decimals;
|
|
318
501
|
return __generator(this, function (_f) {
|
|
@@ -379,46 +562,117 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
379
562
|
promise: true,
|
|
380
563
|
maxAge: 30 * 60 * 1000, // 30m
|
|
381
564
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
var addresses = [];
|
|
385
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
386
|
-
addresses[_i] = arguments[_i];
|
|
387
|
-
}
|
|
565
|
+
this.rewardsProfit = function (address) {
|
|
566
|
+
if (address === void 0) { address = ""; }
|
|
388
567
|
return __awaiter(_this, void 0, void 0, function () {
|
|
389
|
-
var
|
|
568
|
+
var rewardTokens, gaugeContract, result, calls, _i, rewardTokens_2, rewardToken, res, balanceBN, totalSupplyBN, _a, rewardTokens_3, rewardToken, _rewardData, periodFinish, inflationRateBN, tokenPrice, rewardToken, sRewardContract, _c, _inflationRate, _periodFinish, _balance, _totalSupply, periodFinish, inflationRateBN, balanceBN, totalSupplyBN, tokenPrice, _d, rewardTokens_4, rewardToken, tokenPrice;
|
|
390
569
|
return __generator(this, function (_e) {
|
|
391
570
|
switch (_e.label) {
|
|
392
571
|
case 0:
|
|
393
572
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
394
573
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
574
|
+
address = address || curve_1.curve.signerAddress;
|
|
575
|
+
if (!address)
|
|
576
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
577
|
+
return [4 /*yield*/, this.rewardTokens()];
|
|
578
|
+
case 1:
|
|
579
|
+
rewardTokens = _e.sent();
|
|
398
580
|
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
581
|
+
result = [];
|
|
582
|
+
if (!('reward_data(address)' in curve_1.curve.contracts[this.gauge].contract)) return [3 /*break*/, 7];
|
|
583
|
+
calls = [gaugeContract.balanceOf(address), gaugeContract.totalSupply()];
|
|
584
|
+
for (_i = 0, rewardTokens_2 = rewardTokens; _i < rewardTokens_2.length; _i++) {
|
|
585
|
+
rewardToken = rewardTokens_2[_i];
|
|
586
|
+
calls.push(gaugeContract.reward_data(rewardToken.token));
|
|
587
|
+
}
|
|
588
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
589
|
+
case 2:
|
|
590
|
+
res = _e.sent();
|
|
591
|
+
balanceBN = (0, utils_1.toBN)(res.shift());
|
|
592
|
+
totalSupplyBN = (0, utils_1.toBN)(res.shift());
|
|
593
|
+
_a = 0, rewardTokens_3 = rewardTokens;
|
|
594
|
+
_e.label = 3;
|
|
595
|
+
case 3:
|
|
596
|
+
if (!(_a < rewardTokens_3.length)) return [3 /*break*/, 6];
|
|
597
|
+
rewardToken = rewardTokens_3[_a];
|
|
598
|
+
_rewardData = res.shift();
|
|
599
|
+
periodFinish = Number(ethers_1.ethers.utils.formatUnits(_rewardData.period_finish, 0)) * 1000;
|
|
600
|
+
inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_rewardData.rate, rewardToken.decimals) : (0, utils_1.BN)(0);
|
|
601
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
602
|
+
case 4:
|
|
603
|
+
tokenPrice = _e.sent();
|
|
604
|
+
result.push({
|
|
605
|
+
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
606
|
+
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
607
|
+
month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
|
|
608
|
+
year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
|
|
609
|
+
token: rewardToken.token,
|
|
610
|
+
symbol: rewardToken.symbol,
|
|
611
|
+
price: tokenPrice,
|
|
402
612
|
});
|
|
403
|
-
|
|
404
|
-
case
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
613
|
+
_e.label = 5;
|
|
614
|
+
case 5:
|
|
615
|
+
_a++;
|
|
616
|
+
return [3 /*break*/, 3];
|
|
617
|
+
case 6: return [3 /*break*/, 14];
|
|
618
|
+
case 7:
|
|
619
|
+
if (!(this.sRewardContract && "rewardRate()" in curve_1.curve.contracts[this.sRewardContract].contract && "periodFinish()" && rewardTokens.length === 1)) return [3 /*break*/, 10];
|
|
620
|
+
rewardToken = rewardTokens[0];
|
|
621
|
+
sRewardContract = curve_1.curve.contracts[this.sRewardContract].multicallContract;
|
|
622
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
623
|
+
sRewardContract.rewardRate(),
|
|
624
|
+
sRewardContract.periodFinish(),
|
|
625
|
+
gaugeContract.balanceOf(address),
|
|
626
|
+
gaugeContract.totalSupply(),
|
|
627
|
+
])];
|
|
628
|
+
case 8:
|
|
629
|
+
_c = _e.sent(), _inflationRate = _c[0], _periodFinish = _c[1], _balance = _c[2], _totalSupply = _c[3];
|
|
630
|
+
periodFinish = Number(ethers_1.ethers.utils.formatUnits(_periodFinish, 0)) * 1000;
|
|
631
|
+
inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_inflationRate, rewardToken.decimals) : (0, utils_1.BN)(0);
|
|
632
|
+
balanceBN = (0, utils_1.toBN)(_balance);
|
|
633
|
+
totalSupplyBN = (0, utils_1.toBN)(_totalSupply);
|
|
634
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
635
|
+
case 9:
|
|
636
|
+
tokenPrice = _e.sent();
|
|
637
|
+
result.push({
|
|
638
|
+
day: inflationRateBN.times(DAY).times(balanceBN).div(totalSupplyBN).toString(),
|
|
639
|
+
week: inflationRateBN.times(WEEK).times(balanceBN).div(totalSupplyBN).toString(),
|
|
640
|
+
month: inflationRateBN.times(MONTH).times(balanceBN).div(totalSupplyBN).toString(),
|
|
641
|
+
year: inflationRateBN.times(YEAR).times(balanceBN).div(totalSupplyBN).toString(),
|
|
642
|
+
token: rewardToken.token,
|
|
643
|
+
symbol: rewardToken.symbol,
|
|
644
|
+
price: tokenPrice,
|
|
411
645
|
});
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
646
|
+
return [3 /*break*/, 14];
|
|
647
|
+
case 10:
|
|
648
|
+
if (!['aave', 'saave', 'ankreth'].includes(this.id)) return [3 /*break*/, 14];
|
|
649
|
+
_d = 0, rewardTokens_4 = rewardTokens;
|
|
650
|
+
_e.label = 11;
|
|
651
|
+
case 11:
|
|
652
|
+
if (!(_d < rewardTokens_4.length)) return [3 /*break*/, 14];
|
|
653
|
+
rewardToken = rewardTokens_4[_d];
|
|
654
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken.token)];
|
|
655
|
+
case 12:
|
|
656
|
+
tokenPrice = _e.sent();
|
|
657
|
+
result.push({
|
|
658
|
+
day: "0",
|
|
659
|
+
week: "0",
|
|
660
|
+
month: "0",
|
|
661
|
+
year: "0",
|
|
662
|
+
token: rewardToken.token,
|
|
663
|
+
symbol: rewardToken.symbol,
|
|
664
|
+
price: tokenPrice,
|
|
665
|
+
});
|
|
666
|
+
_e.label = 13;
|
|
667
|
+
case 13:
|
|
668
|
+
_d++;
|
|
669
|
+
return [3 /*break*/, 11];
|
|
670
|
+
case 14: return [2 /*return*/, result];
|
|
418
671
|
}
|
|
419
672
|
});
|
|
420
673
|
});
|
|
421
674
|
};
|
|
675
|
+
// ---------------- ... ----------------
|
|
422
676
|
this.gaugeOptimalDeposits = function () {
|
|
423
677
|
var accounts = [];
|
|
424
678
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -486,25 +740,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
486
740
|
});
|
|
487
741
|
});
|
|
488
742
|
};
|
|
489
|
-
this.boost = function (address) { return __awaiter(_this, void 0, void 0, function () {
|
|
490
|
-
var gaugeContract, _a, workingBalance, balance, boost;
|
|
491
|
-
return __generator(this, function (_c) {
|
|
492
|
-
switch (_c.label) {
|
|
493
|
-
case 0:
|
|
494
|
-
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
495
|
-
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
496
|
-
gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
|
|
497
|
-
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
498
|
-
gaugeContract.working_balances(address),
|
|
499
|
-
gaugeContract.balanceOf(address),
|
|
500
|
-
])];
|
|
501
|
-
case 1:
|
|
502
|
-
_a = (_c.sent()).map(function (value) { return Number(ethers_1.ethers.utils.formatUnits(value)); }), workingBalance = _a[0], balance = _a[1];
|
|
503
|
-
boost = workingBalance / (0.4 * balance);
|
|
504
|
-
return [2 /*return*/, boost.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
}); };
|
|
508
743
|
this._getCoinIdx = function (coin, useUnderlying) {
|
|
509
744
|
if (useUnderlying === void 0) { useUnderlying = true; }
|
|
510
745
|
if (typeof coin === 'number') {
|
|
@@ -1225,7 +1460,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1225
1460
|
PoolTemplate.prototype.claimableRewards = function (address) {
|
|
1226
1461
|
if (address === void 0) { address = ""; }
|
|
1227
1462
|
return __awaiter(this, void 0, void 0, function () {
|
|
1228
|
-
var gaugeContract, rewardTokens, rewards, _i,
|
|
1463
|
+
var gaugeContract, rewardTokens, rewards, _i, rewardTokens_5, rewardToken, _amount, rewardToken, _totalAmount, _claimedAmount;
|
|
1229
1464
|
return __generator(this, function (_a) {
|
|
1230
1465
|
switch (_a.label) {
|
|
1231
1466
|
case 0:
|
|
@@ -1241,11 +1476,11 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1241
1476
|
rewardTokens = _a.sent();
|
|
1242
1477
|
rewards = [];
|
|
1243
1478
|
if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 6];
|
|
1244
|
-
_i = 0,
|
|
1479
|
+
_i = 0, rewardTokens_5 = rewardTokens;
|
|
1245
1480
|
_a.label = 2;
|
|
1246
1481
|
case 2:
|
|
1247
|
-
if (!(_i <
|
|
1248
|
-
rewardToken =
|
|
1482
|
+
if (!(_i < rewardTokens_5.length)) return [3 /*break*/, 5];
|
|
1483
|
+
rewardToken = rewardTokens_5[_i];
|
|
1249
1484
|
return [4 /*yield*/, gaugeContract.claimable_reward(address, rewardToken.token, curve_1.curve.constantOptions)];
|
|
1250
1485
|
case 3:
|
|
1251
1486
|
_amount = _a.sent();
|
|
@@ -2204,6 +2439,158 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2204
2439
|
});
|
|
2205
2440
|
});
|
|
2206
2441
|
};
|
|
2442
|
+
// ---------------- USER BALANCES, BASE PROFIT AND SHARE ----------------
|
|
2443
|
+
PoolTemplate.prototype._userLpTotalBalance = function (address) {
|
|
2444
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2445
|
+
var lpBalances, lpTotalBalanceBN;
|
|
2446
|
+
return __generator(this, function (_a) {
|
|
2447
|
+
switch (_a.label) {
|
|
2448
|
+
case 0: return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2449
|
+
case 1:
|
|
2450
|
+
lpBalances = _a.sent();
|
|
2451
|
+
lpTotalBalanceBN = (0, utils_1.BN)(lpBalances.lpToken);
|
|
2452
|
+
if ('gauge' in lpBalances)
|
|
2453
|
+
lpTotalBalanceBN = lpTotalBalanceBN.plus((0, utils_1.BN)(lpBalances.gauge));
|
|
2454
|
+
return [2 /*return*/, lpTotalBalanceBN.toString()];
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2457
|
+
});
|
|
2458
|
+
};
|
|
2459
|
+
PoolTemplate.prototype.userBalances = function (address) {
|
|
2460
|
+
if (address === void 0) { address = ""; }
|
|
2461
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2462
|
+
var lpTotalBalanceBN;
|
|
2463
|
+
return __generator(this, function (_a) {
|
|
2464
|
+
switch (_a.label) {
|
|
2465
|
+
case 0:
|
|
2466
|
+
address = address || curve_1.curve.signerAddress;
|
|
2467
|
+
if (!address)
|
|
2468
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2469
|
+
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2470
|
+
case 1:
|
|
2471
|
+
lpTotalBalanceBN = _a.sent();
|
|
2472
|
+
return [4 /*yield*/, this.withdrawExpected(lpTotalBalanceBN.toString())];
|
|
2473
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2474
|
+
}
|
|
2475
|
+
});
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2478
|
+
PoolTemplate.prototype.userWrappedBalances = function (address) {
|
|
2479
|
+
if (address === void 0) { address = ""; }
|
|
2480
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2481
|
+
var lpTotalBalanceBN;
|
|
2482
|
+
return __generator(this, function (_a) {
|
|
2483
|
+
switch (_a.label) {
|
|
2484
|
+
case 0:
|
|
2485
|
+
address = address || curve_1.curve.signerAddress;
|
|
2486
|
+
if (!address)
|
|
2487
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2488
|
+
return [4 /*yield*/, this._userLpTotalBalance(address)];
|
|
2489
|
+
case 1:
|
|
2490
|
+
lpTotalBalanceBN = _a.sent();
|
|
2491
|
+
return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toString())];
|
|
2492
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
2493
|
+
}
|
|
2494
|
+
});
|
|
2495
|
+
});
|
|
2496
|
+
};
|
|
2497
|
+
PoolTemplate.prototype.userLiquidityUSD = function (address) {
|
|
2498
|
+
if (address === void 0) { address = ""; }
|
|
2499
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2500
|
+
var balances, promises, _i, _a, addr, prices, totalLiquidity;
|
|
2501
|
+
return __generator(this, function (_c) {
|
|
2502
|
+
switch (_c.label) {
|
|
2503
|
+
case 0: return [4 /*yield*/, this.userBalances(address)];
|
|
2504
|
+
case 1:
|
|
2505
|
+
balances = _c.sent();
|
|
2506
|
+
promises = [];
|
|
2507
|
+
for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
|
|
2508
|
+
addr = _a[_i];
|
|
2509
|
+
promises.push((0, utils_1._getUsdRate)(addr));
|
|
2510
|
+
}
|
|
2511
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
2512
|
+
case 2:
|
|
2513
|
+
prices = _c.sent();
|
|
2514
|
+
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
2515
|
+
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
2516
|
+
}
|
|
2517
|
+
});
|
|
2518
|
+
});
|
|
2519
|
+
};
|
|
2520
|
+
PoolTemplate.prototype.baseProfit = function (address) {
|
|
2521
|
+
if (address === void 0) { address = ""; }
|
|
2522
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2523
|
+
var apyData, apyBN, totalLiquidityBN, _a, annualProfitBN, monthlyProfitBN, weeklyProfitBN, daylyProfitBN;
|
|
2524
|
+
return __generator(this, function (_c) {
|
|
2525
|
+
switch (_c.label) {
|
|
2526
|
+
case 0: return [4 /*yield*/, this.statsBaseApy()];
|
|
2527
|
+
case 1:
|
|
2528
|
+
apyData = _c.sent();
|
|
2529
|
+
if (!('week' in apyData))
|
|
2530
|
+
return [2 /*return*/, { day: "0", week: "0", month: "0", year: "0" }];
|
|
2531
|
+
apyBN = (0, utils_1.BN)(apyData.week).div(100);
|
|
2532
|
+
_a = utils_1.BN;
|
|
2533
|
+
return [4 /*yield*/, this.userLiquidityUSD(address)];
|
|
2534
|
+
case 2:
|
|
2535
|
+
totalLiquidityBN = _a.apply(void 0, [_c.sent()]);
|
|
2536
|
+
annualProfitBN = apyBN.times(totalLiquidityBN);
|
|
2537
|
+
monthlyProfitBN = annualProfitBN.div(12);
|
|
2538
|
+
weeklyProfitBN = annualProfitBN.div(52);
|
|
2539
|
+
daylyProfitBN = annualProfitBN.div(365);
|
|
2540
|
+
return [2 /*return*/, {
|
|
2541
|
+
day: daylyProfitBN.toString(),
|
|
2542
|
+
week: weeklyProfitBN.toString(),
|
|
2543
|
+
month: monthlyProfitBN.toString(),
|
|
2544
|
+
year: annualProfitBN.toString(),
|
|
2545
|
+
}];
|
|
2546
|
+
}
|
|
2547
|
+
});
|
|
2548
|
+
});
|
|
2549
|
+
};
|
|
2550
|
+
PoolTemplate.prototype.userShare = function (address) {
|
|
2551
|
+
if (address === void 0) { address = ""; }
|
|
2552
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2553
|
+
var withGauge, userLpBalance, userLpTotalBalanceBN, totalLp, gaugeLp, _a, _c;
|
|
2554
|
+
var _d;
|
|
2555
|
+
return __generator(this, function (_e) {
|
|
2556
|
+
switch (_e.label) {
|
|
2557
|
+
case 0:
|
|
2558
|
+
withGauge = this.gauge !== ethers_1.ethers.constants.AddressZero;
|
|
2559
|
+
address = address || curve_1.curve.signerAddress;
|
|
2560
|
+
if (!address)
|
|
2561
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2562
|
+
return [4 /*yield*/, this.walletLpTokenBalances(address)];
|
|
2563
|
+
case 1:
|
|
2564
|
+
userLpBalance = _e.sent();
|
|
2565
|
+
userLpTotalBalanceBN = (0, utils_1.BN)(userLpBalance.lpToken);
|
|
2566
|
+
if (withGauge)
|
|
2567
|
+
userLpTotalBalanceBN = userLpTotalBalanceBN.plus((0, utils_1.BN)(userLpBalance.gauge));
|
|
2568
|
+
if (!withGauge) return [3 /*break*/, 3];
|
|
2569
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all([
|
|
2570
|
+
curve_1.curve.contracts[this.lpToken].multicallContract.totalSupply(),
|
|
2571
|
+
curve_1.curve.contracts[this.gauge].multicallContract.totalSupply(),
|
|
2572
|
+
])];
|
|
2573
|
+
case 2:
|
|
2574
|
+
_d = (_e.sent()).map(function (_supply) { return ethers_1.ethers.utils.formatUnits(_supply); }), totalLp = _d[0], gaugeLp = _d[1];
|
|
2575
|
+
return [3 /*break*/, 5];
|
|
2576
|
+
case 3:
|
|
2577
|
+
_c = (_a = ethers_1.ethers.utils).formatUnits;
|
|
2578
|
+
return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply()];
|
|
2579
|
+
case 4:
|
|
2580
|
+
totalLp = _c.apply(_a, [_e.sent()]);
|
|
2581
|
+
_e.label = 5;
|
|
2582
|
+
case 5: return [2 /*return*/, {
|
|
2583
|
+
lpUser: userLpTotalBalanceBN.toString(),
|
|
2584
|
+
lpTotal: totalLp,
|
|
2585
|
+
lpShare: userLpTotalBalanceBN.div(totalLp).times(100).toString(),
|
|
2586
|
+
gaugeUser: userLpBalance.gauge,
|
|
2587
|
+
gaugeTotal: gaugeLp,
|
|
2588
|
+
gaugeShare: withGauge ? (0, utils_1.BN)(userLpBalance.gauge).div((0, utils_1.BN)(gaugeLp)).times(100).toString() : undefined,
|
|
2589
|
+
}];
|
|
2590
|
+
}
|
|
2591
|
+
});
|
|
2592
|
+
});
|
|
2593
|
+
};
|
|
2207
2594
|
// ---------------- SWAP ----------------
|
|
2208
2595
|
PoolTemplate.prototype._swapExpected = function (i, j, _amount) {
|
|
2209
2596
|
return __awaiter(this, void 0, void 0, function () {
|
package/lib/utils.js
CHANGED
|
@@ -464,6 +464,7 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
464
464
|
throw Error('curve object is not initialized');
|
|
465
465
|
}
|
|
466
466
|
assetId = {
|
|
467
|
+
'CRV': 'curve-dao-token',
|
|
467
468
|
'EUR': curve_1.curve.constants.COINS.eurt,
|
|
468
469
|
'BTC': 'bitcoin',
|
|
469
470
|
'ETH': 'ethereum',
|