stackswap-front-api-test-02 1.1.52 → 1.1.54
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/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stackswap/config.d.ts +6 -1
- package/dist/esm/stackswap/config.js +9 -2
- package/dist/esm/stackswap/config.js.map +1 -1
- package/dist/esm/stackswap/manager/farm3.manager.d.ts +99 -0
- package/dist/esm/stackswap/manager/farm3.manager.js +519 -0
- package/dist/esm/stackswap/manager/farm3.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/swap.manager.js +4 -4
- package/dist/esm/stackswap/manager/swap.manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/stackswap/config.d.ts +6 -1
- package/dist/stackswap/config.js +9 -2
- package/dist/stackswap/config.js.map +1 -1
- package/dist/stackswap/manager/farm3.manager.d.ts +99 -0
- package/dist/stackswap/manager/farm3.manager.js +526 -0
- package/dist/stackswap/manager/farm3.manager.js.map +1 -0
- package/dist/stackswap/manager/swap.manager.js +4 -4
- package/dist/stackswap/manager/swap.manager.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/stackswap/config.ts +14 -2
- package/src/stackswap/manager/farm3.manager.ts +664 -0
- package/src/stackswap/manager/swap.manager.ts +5 -6
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
import {
|
|
2
|
+
callReadOnlyFunction,
|
|
3
|
+
contractPrincipalCV,
|
|
4
|
+
cvToValue, FungibleConditionCode,
|
|
5
|
+
listCV,
|
|
6
|
+
standardPrincipalCV,
|
|
7
|
+
uintCV
|
|
8
|
+
} from '@stacks/transactions';
|
|
9
|
+
import BigNumber from 'bignumber.js';
|
|
10
|
+
import {openContractCall} from '@stacks/connect';
|
|
11
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions, num2decimal} from "../util";
|
|
12
|
+
import {StackswapAPI} from "../../index";
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
|
|
15
|
+
export enum Mode {
|
|
16
|
+
WITH_SERVER,
|
|
17
|
+
ONLY_BLOCKCHAIN
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class Farm2Manager {
|
|
21
|
+
stackswap: StackswapAPI;
|
|
22
|
+
|
|
23
|
+
constructor(stackswap: StackswapAPI) {``
|
|
24
|
+
this.stackswap = stackswap;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getFarmingRound3(bh: number) {
|
|
28
|
+
try {
|
|
29
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'getRewardRound', [
|
|
30
|
+
uintCV(bh)
|
|
31
|
+
]);
|
|
32
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
33
|
+
const result = cvToValue(result_raw);
|
|
34
|
+
// console.log('farming round', result);
|
|
35
|
+
return result.value;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getFarmingRoundFirstBlock3(cycle: number) {
|
|
42
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'getFirstBlockOfRound', [
|
|
43
|
+
uintCV(cycle)
|
|
44
|
+
]);
|
|
45
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
46
|
+
const result = cvToValue(result_raw);
|
|
47
|
+
// console.log(result);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// async isUserMigratable2(pool_address: string, farming_contract: string) {
|
|
52
|
+
// const address = pool_address.split('.');
|
|
53
|
+
// const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'isUserMigratable', [
|
|
54
|
+
// contractPrincipalCV(address[0], address[1]),
|
|
55
|
+
// standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
56
|
+
// ]);
|
|
57
|
+
// try {
|
|
58
|
+
// const result_raw = await callReadOnlyFunction(function_option);
|
|
59
|
+
// const result = cvToValue(result_raw);
|
|
60
|
+
// // console.log('migrate' , result);
|
|
61
|
+
// return result;
|
|
62
|
+
// } catch (e) {
|
|
63
|
+
// return true;
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
getPoolUSDPriceFarm(farm: any, farm_total: any, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }) {
|
|
68
|
+
// BigNumber.config({ DECIMAL_PLACES: 6});
|
|
69
|
+
let tvl = 0;
|
|
70
|
+
switch (farm.BASE) {
|
|
71
|
+
case 'STX':
|
|
72
|
+
if (farm.token_x.symbol === farm.BASE) {
|
|
73
|
+
tvl = (new BigNumber(farm.pair.balance_x).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stx)).toNumber();
|
|
74
|
+
} else {
|
|
75
|
+
tvl = (new BigNumber(farm.pair.balance_y).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stx)).toNumber();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case 'STSW':
|
|
79
|
+
if (farm.token_x.symbol === farm.BASE) {
|
|
80
|
+
tvl = (new BigNumber(farm.pair.balance_x).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stsw)).toNumber();
|
|
81
|
+
} else {
|
|
82
|
+
tvl = (new BigNumber(farm.pair.balance_y).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stsw)).toNumber();
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case 'lBTC':
|
|
86
|
+
if (farm.token_x.symbol === farm.BASE) {
|
|
87
|
+
tvl = (new BigNumber(farm.pair.balance_x).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_lbtc)).toNumber();
|
|
88
|
+
} else {
|
|
89
|
+
tvl = (new BigNumber(farm.pair.balance_y).multipliedBy(farm_total).dividedBy(farm.pair.share_total).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_lbtc)).toNumber();
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
tvl = 0;
|
|
94
|
+
}
|
|
95
|
+
return tvl;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async getFarmingStakerStatus3(pool_address: string, cur_round: number) {
|
|
99
|
+
const address = pool_address.split('.');
|
|
100
|
+
// console.log('getFarmingStakerStatus', farming_contract);
|
|
101
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPUserDataOrDefault', [
|
|
102
|
+
contractPrincipalCV(address[0], address[1]),
|
|
103
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
104
|
+
]);
|
|
105
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
106
|
+
const result = cvToValue(result_raw);
|
|
107
|
+
try {
|
|
108
|
+
// console.log('getFarmingStakerStatus', result);
|
|
109
|
+
const pooledToken = result.value.amountLP.value;
|
|
110
|
+
const unclaimedList = [];
|
|
111
|
+
const stakedList = []
|
|
112
|
+
for (const unclaimedElement of result.value.unclaimedList.value) {
|
|
113
|
+
if (unclaimedElement.value < cur_round) {
|
|
114
|
+
unclaimedList.push(unclaimedElement.value);
|
|
115
|
+
// console.log('TTT', unclaimedElement.value)
|
|
116
|
+
}
|
|
117
|
+
stakedList.push(unclaimedElement.value);
|
|
118
|
+
}
|
|
119
|
+
// console.log({pooledToken, unclaimedList, stakedList});
|
|
120
|
+
return {pooledToken, unclaimedList, stakedList};
|
|
121
|
+
} catch (e) {
|
|
122
|
+
// console.log(e);
|
|
123
|
+
return {pooledToken: 0, unclaimedList: [], stakedList: []}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async getFarmingTotalStatusCycle3(cycle: number, group: string| number) {
|
|
128
|
+
// console.log(cycle);
|
|
129
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getGroupRoundDataOrDefault', [
|
|
130
|
+
uintCV(cycle),
|
|
131
|
+
uintCV(group),
|
|
132
|
+
]);
|
|
133
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
134
|
+
const result = cvToValue(result_raw);
|
|
135
|
+
// console.log('FARMING TOTAL', result);
|
|
136
|
+
try {
|
|
137
|
+
return {
|
|
138
|
+
reward: result.reward.value,
|
|
139
|
+
value: result.value.value
|
|
140
|
+
}
|
|
141
|
+
// return new BigNumber(result.value.amountUstx.value).multipliedBy(2).toFixed(0).toString();
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return {
|
|
144
|
+
reward: 0,
|
|
145
|
+
value: 0
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async getFarmingTotalPoolStatus3(pool_address: string) {
|
|
151
|
+
const address = pool_address.split('.');
|
|
152
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPTotalDataOrDefault', [
|
|
153
|
+
contractPrincipalCV(address[0], address[1]),
|
|
154
|
+
]);
|
|
155
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
156
|
+
const result = cvToValue(result_raw);
|
|
157
|
+
// console.log('lp total data', result);
|
|
158
|
+
try {
|
|
159
|
+
return {amountLP: result.value.amountLP.value, weight: result.value.weight.value};
|
|
160
|
+
// return {amountLP: result.value.amountLP.value, weight: '3'};
|
|
161
|
+
} catch (e) {
|
|
162
|
+
return {amountLP: '0', weight: '1'};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async getFarmingTotalPoolStatusCycle3(pool_address: string, cycle: number) {
|
|
167
|
+
const address = pool_address.split('.');
|
|
168
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPRoundDataOrDefault', [
|
|
169
|
+
contractPrincipalCV(address[0], address[1]),
|
|
170
|
+
uintCV(cycle),
|
|
171
|
+
]);
|
|
172
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
173
|
+
const result = cvToValue(result_raw);
|
|
174
|
+
// console.log('lp round data', result);
|
|
175
|
+
try {
|
|
176
|
+
return result.value;
|
|
177
|
+
} catch (e) {
|
|
178
|
+
return {
|
|
179
|
+
value: 0,
|
|
180
|
+
weight: 0,
|
|
181
|
+
amountLP: 0,
|
|
182
|
+
price: 0
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async getFarmingTotalValue3(pool_address: string, group: string) {
|
|
188
|
+
try {
|
|
189
|
+
const address = pool_address.split('.');
|
|
190
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPGroupDataOrDefault', [
|
|
191
|
+
contractPrincipalCV(address[0], address[1]),
|
|
192
|
+
uintCV(group)
|
|
193
|
+
]);
|
|
194
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
195
|
+
const result = cvToValue(result_raw);
|
|
196
|
+
// console.log('get_farming_total',result.value);
|
|
197
|
+
return result.value;
|
|
198
|
+
} catch (e) {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async getFarmingUserRewardPerCycle3(pool_address: string, cycle: number) {
|
|
204
|
+
const address = pool_address.split('.');
|
|
205
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'getFarmingReward', [
|
|
206
|
+
contractPrincipalCV(address[0], address[1]),
|
|
207
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
208
|
+
uintCV(cycle),
|
|
209
|
+
]);
|
|
210
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
211
|
+
const result = cvToValue(result_raw);
|
|
212
|
+
// console.log('reward', result);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async getFarmingUserRewardList3(pool_address: string, unclaimed_list: any) {
|
|
217
|
+
const address = pool_address.split('.');
|
|
218
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'getFarmingRewardFromList', [
|
|
219
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
220
|
+
contractPrincipalCV(address[0], address[1]),
|
|
221
|
+
listCV(unclaimed_list),
|
|
222
|
+
]);
|
|
223
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
224
|
+
const result = cvToValue(result_raw);
|
|
225
|
+
// console.log('getFarmingUserRewardTotal', result);
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async getFarmingRewardInfo3(pool_address: string, round: number) {
|
|
230
|
+
const address = pool_address.split('.');
|
|
231
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPUserRoundDataOrDefault', [
|
|
232
|
+
contractPrincipalCV(address[0], address[1]),
|
|
233
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
234
|
+
uintCV(round),
|
|
235
|
+
]);
|
|
236
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
237
|
+
const result = cvToValue(result_raw);
|
|
238
|
+
// console.log(result);
|
|
239
|
+
return result.value.returnLP.value;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async getLPUserRoundData(pool_address: string, round: number) {
|
|
243
|
+
try{
|
|
244
|
+
|
|
245
|
+
const address = pool_address.split('.');
|
|
246
|
+
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), 'getLPUserRoundDataOrDefault', [
|
|
247
|
+
contractPrincipalCV(address[0], address[1]),
|
|
248
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
249
|
+
uintCV(round),
|
|
250
|
+
]);
|
|
251
|
+
const result_raw = await callReadOnlyFunction(function_option);
|
|
252
|
+
const result = cvToValue(result_raw);
|
|
253
|
+
// console.log(result);
|
|
254
|
+
return result.value;
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
console.log(e);
|
|
258
|
+
return {
|
|
259
|
+
amountLP: {
|
|
260
|
+
value: '0'
|
|
261
|
+
},
|
|
262
|
+
returnLP: {
|
|
263
|
+
value: '0'
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// async migrateToVersion2(pool_address: string, farming_contract: string, callback: any) {
|
|
270
|
+
// const address = pool_address.split('.');
|
|
271
|
+
// // console.log(amountTokens);
|
|
272
|
+
// const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING3(), 'migrateFromVersion1', [
|
|
273
|
+
// contractPrincipalCV(address[0], address[1]),
|
|
274
|
+
// ], [], callback);
|
|
275
|
+
// await openContractCall(function_option);
|
|
276
|
+
// }
|
|
277
|
+
|
|
278
|
+
async stakeFarmingContract3(pool_address: string, amountTokens: string, lockPeriod: number, callback: any) {
|
|
279
|
+
const address = pool_address.split('.');
|
|
280
|
+
// console.log(amountTokens);
|
|
281
|
+
const amount = new BigNumber(amountTokens).multipliedBy(10 ** 6).toFixed(0).toString();
|
|
282
|
+
const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'stakeTokens', [
|
|
283
|
+
uintCV(amount),
|
|
284
|
+
contractPrincipalCV(address[0], address[1]),
|
|
285
|
+
uintCV(lockPeriod),
|
|
286
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
287
|
+
], [await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), pool_address, amount, FungibleConditionCode.Equal)], callback);
|
|
288
|
+
await openContractCall(function_option);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async getFarmBalance3(token: any) {
|
|
292
|
+
// console.log("getBalance", token)
|
|
293
|
+
const pair_details_options: any = getReadOptions(this.stackswap, token.addr, 'get-balance',
|
|
294
|
+
[contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3())]);
|
|
295
|
+
try {
|
|
296
|
+
const result = await callReadOnlyFunction(pair_details_options);
|
|
297
|
+
return cvToValue(result).value;
|
|
298
|
+
} catch (e) {
|
|
299
|
+
return 0;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async claimFarmingContract3(pool_address: string, amount_STSW: string, amount_LP: string, callback: any) {
|
|
304
|
+
const address = pool_address.split('.');
|
|
305
|
+
const post_condition = [];
|
|
306
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), this.stackswap.config.BASE_STSW_DATA().addr, amount_STSW, FungibleConditionCode.Equal));
|
|
307
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), pool_address, amount_LP, FungibleConditionCode.Equal));
|
|
308
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
309
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
310
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP() , this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
311
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP() , this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
312
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, amount_STSW, FungibleConditionCode.Equal));
|
|
313
|
+
const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), 'CLAIM_FROM_FARM', [
|
|
314
|
+
contractPrincipalCV(address[0], address[1]),
|
|
315
|
+
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
316
|
+
], post_condition, callback);
|
|
317
|
+
await openContractCall(function_option);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// async claimFarmingRewardRound(pool_address: string, amount_STSW: string, amount_LP: string, round: number|string, callback: any) {
|
|
321
|
+
// const address = pool_address.split('.');
|
|
322
|
+
// const post_condition = [];
|
|
323
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), this.stackswap.config.BASE_STSW_DATA().addr, amount_STSW, FungibleConditionCode.Equal));
|
|
324
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), pool_address, amount_LP, FungibleConditionCode.Equal));
|
|
325
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
326
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
327
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP() , this.stackswap.config.BASE_STSW_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
328
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STSW_LBTC_LP() , this.stackswap.config.BASE_LBTC_DATA().addr, 0, FungibleConditionCode.GreaterEqual));
|
|
329
|
+
// post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, amount_STSW, FungibleConditionCode.Equal));
|
|
330
|
+
// const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_REWARD_BALANCER(), 'CLAIM_FROM_FARM', [
|
|
331
|
+
// contractPrincipalCV(address[0], address[1]),
|
|
332
|
+
// contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
333
|
+
// ], post_condition, callback);
|
|
334
|
+
// await openContractCall(function_option);
|
|
335
|
+
// }
|
|
336
|
+
|
|
337
|
+
async unstakeFarmingContract3(pool_address: string, cycle: number, amount_LP: string, callback: any) {
|
|
338
|
+
const address = pool_address.split('.');
|
|
339
|
+
const post_condition = [];
|
|
340
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_DATA_3(), pool_address, amount_LP, FungibleConditionCode.Equal));
|
|
341
|
+
const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3(), 'unstakeLP', [
|
|
342
|
+
uintCV(cycle),
|
|
343
|
+
contractPrincipalCV(address[0], address[1]),
|
|
344
|
+
], post_condition, callback);
|
|
345
|
+
await openContractCall(function_option);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async getCurrentFarmingRound3() {
|
|
349
|
+
const bh = await this.stackswap.getCurrentBlock();
|
|
350
|
+
return await this.getFarmingRound3(Number(bh));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async getRewardBalanceFromFarming3(pool_addr: string, unclaimed_list: any) {
|
|
354
|
+
// let reward_balance = new BigNumber(0);
|
|
355
|
+
const num_list = [];
|
|
356
|
+
for (const unclaimed of unclaimed_list) {
|
|
357
|
+
num_list.push(uintCV(unclaimed));
|
|
358
|
+
}
|
|
359
|
+
let reward_num = new BigNumber(0);
|
|
360
|
+
// console.log(pool_addr, num_list, farming_contract)
|
|
361
|
+
try {
|
|
362
|
+
for (let i = 0; i < num_list.length; i += 4) {
|
|
363
|
+
// console.log(pool_addr, num_list.slice(i, i + 4 < num_list.length ? i + 4 : num_list.length), farming_contract);
|
|
364
|
+
const result = await this.getFarmingUserRewardList3(pool_addr, num_list.slice(i, i + 4 < num_list.length ? i + 4 : num_list.length));
|
|
365
|
+
// rewardSum.value;
|
|
366
|
+
// console.log('temp result', result.rewardSum.value);
|
|
367
|
+
reward_num = reward_num.plus(new BigNumber(result.rewardSum.value));
|
|
368
|
+
}
|
|
369
|
+
return num2decimal(reward_num.toString(), 6);
|
|
370
|
+
} catch (e) {
|
|
371
|
+
// console.log(e);
|
|
372
|
+
return num2decimal(reward_num.toString(), 6);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
getFarmingAPR(tvl: string, stsw_price: string, reward: string, weight: string) {
|
|
378
|
+
// console.log('farmingAPR');
|
|
379
|
+
// console.log({tvl, stsw_price, reward, weight})
|
|
380
|
+
if (!tvl || new BigNumber(tvl) <= new BigNumber(0)) {
|
|
381
|
+
const temp = new BigNumber(reward).dividedBy(10 ** 12).multipliedBy(5200).multipliedBy(stsw_price);
|
|
382
|
+
// console.log('reward_to_stx', temp.toFixed(3).toString());
|
|
383
|
+
// console.log(typeof temp);
|
|
384
|
+
return temp.toFixed(3).toString();
|
|
385
|
+
} else {
|
|
386
|
+
// BigNumber.config({DECIMAL_PLACES: 10});
|
|
387
|
+
const tvl_bn = new BigNumber(tvl).multipliedBy(10 ** 12);
|
|
388
|
+
// console.log({tvl_bn: tvl_bn.toString()});
|
|
389
|
+
const reward_usd = new BigNumber(reward).multipliedBy(stsw_price);
|
|
390
|
+
// console.log({reward_stx: reward_usd.toString()});
|
|
391
|
+
const new_reward = reward_usd.div(tvl_bn);
|
|
392
|
+
// console.log({new_reward: new_reward.toString()});
|
|
393
|
+
const new_reward_apr = new_reward.multipliedBy(5200).multipliedBy(weight);
|
|
394
|
+
// console.log({new_reward_apr: new_reward_apr.toString()});
|
|
395
|
+
return new_reward_apr.toFixed(3).toString();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async getFarmDataFromData(data: any, type: Mode, callback: any) {
|
|
400
|
+
const oracle_stsw = (await this.stackswap.lbtcManager.getPrice('STSW'))['last-price'].value;
|
|
401
|
+
const oracle_stx = (await this.stackswap.lbtcManager.getPrice('STX'))['last-price'].value;
|
|
402
|
+
const oracle_lbtc = (await this.stackswap.lbtcManager.getPrice('lBTC'))['last-price'].value;
|
|
403
|
+
const bh = await this.stackswap.getCurrentBlock();
|
|
404
|
+
return await this.getEachFarmData(data, bh, {oracle_stsw, oracle_lbtc, oracle_stx}, type, callback)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
checkAndSetFarmAPR(farms : any, farm_length: number, oracle_data: any){
|
|
408
|
+
if (farms.length === farm_length) {
|
|
409
|
+
const tvls = {'group1': '0', 'group2': '0', 'group5': '0'}
|
|
410
|
+
for (const farm_temp of farms) {
|
|
411
|
+
switch (farm_temp.farm_group) {
|
|
412
|
+
case 1:
|
|
413
|
+
tvls.group1 = new BigNumber(tvls.group1).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.farm_total_v3, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
414
|
+
break;
|
|
415
|
+
case 2:
|
|
416
|
+
tvls.group2 = new BigNumber(tvls.group2).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.farm_total_v3, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
417
|
+
break;
|
|
418
|
+
case 5:
|
|
419
|
+
tvls.group5 = new BigNumber(tvls.group5).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.farm_total_v3, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
// console.log({tvls})
|
|
424
|
+
for (const farm_temp of farms) {
|
|
425
|
+
switch (farm_temp.farm_group) {
|
|
426
|
+
case 1:
|
|
427
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group1, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
428
|
+
break;
|
|
429
|
+
case 2:
|
|
430
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group2, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
431
|
+
break;
|
|
432
|
+
case 5:
|
|
433
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group5, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
// console.log(farm_temp.APR)
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return farms;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
checkAndSetFarmAPR_Dash(farms : any, farm_length: number, oracle_data: any){
|
|
444
|
+
if (farms.length === farm_length) {
|
|
445
|
+
const tvls = {'group1': '0', 'group2': '0', 'group5': '0'}
|
|
446
|
+
for (const farm_temp of farms) {
|
|
447
|
+
switch (farm_temp.farm_group) {
|
|
448
|
+
case 1:
|
|
449
|
+
tvls.group1 = new BigNumber(tvls.group1).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.total_locked_lp, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
450
|
+
break;
|
|
451
|
+
case 2:
|
|
452
|
+
tvls.group2 = new BigNumber(tvls.group2).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.total_locked_lp, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
453
|
+
break;
|
|
454
|
+
case 5:
|
|
455
|
+
tvls.group5 = new BigNumber(tvls.group5).plus(new BigNumber(this.getPoolUSDPriceFarm(farm_temp, farm_temp.total_locked_lp, oracle_data)).multipliedBy(farm_temp.weight)).toString();
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
farm_temp.value_per_1LP = new BigNumber(this.getPoolUSDPriceFarm(farm_temp, 1000000, oracle_data)).multipliedBy(farm_temp.weight).toString();
|
|
459
|
+
}
|
|
460
|
+
// console.log({tvls})
|
|
461
|
+
for (const farm_temp of farms) {
|
|
462
|
+
switch (farm_temp.farm_group) {
|
|
463
|
+
case 1:
|
|
464
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group1, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
465
|
+
farm_temp.group_value = tvls.group1;
|
|
466
|
+
break;
|
|
467
|
+
case 2:
|
|
468
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group2, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
469
|
+
farm_temp.group_value = tvls.group2;
|
|
470
|
+
break;
|
|
471
|
+
case 5:
|
|
472
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group5, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
473
|
+
farm_temp.group_value = tvls.group5;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
// console.log(farm_temp.APR)
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return farms;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
async getEachFarmData(data: any, bh: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, type: Mode, callback: any) {
|
|
483
|
+
|
|
484
|
+
const tvl_apr = new BigNumber(0);
|
|
485
|
+
const farms : any[] = [];
|
|
486
|
+
const farm_length: number = data.length;
|
|
487
|
+
|
|
488
|
+
for (let i = 0; i < data.length; i++) {
|
|
489
|
+
|
|
490
|
+
const farm_round = await this.getCurrentFarmingRound3();
|
|
491
|
+
this.getFarmData(data[i], farm_round, bh, tvl_apr, oracle_data, type).then((value) => {
|
|
492
|
+
value.farm_group = data[i].farm_group;
|
|
493
|
+
value.farm_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3();
|
|
494
|
+
farms.push(value);
|
|
495
|
+
this.checkAndSetFarmAPR(farms, farm_length, oracle_data);
|
|
496
|
+
|
|
497
|
+
// console.log("let's callback");
|
|
498
|
+
callback({farms, farm_round, oracle_data});
|
|
499
|
+
})
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async getEachFarmDataSerial(data: any, bh: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, type: Mode) {
|
|
503
|
+
|
|
504
|
+
const tvl_apr = new BigNumber(0);
|
|
505
|
+
const farms : any[] = [];
|
|
506
|
+
const farm_length: number = data.length;
|
|
507
|
+
const farm_round = await this.getCurrentFarmingRound3();
|
|
508
|
+
|
|
509
|
+
for (let i = 0; i < data.length; i++) {
|
|
510
|
+
|
|
511
|
+
const value = await this.getFarmData(data[i], farm_round, bh, tvl_apr, oracle_data, type);
|
|
512
|
+
value.farm_group = data[i].farm_group;
|
|
513
|
+
value.farm_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3();
|
|
514
|
+
farms.push(value);
|
|
515
|
+
}
|
|
516
|
+
this.checkAndSetFarmAPR(farms,farm_length, oracle_data);
|
|
517
|
+
return {farms, farm_round, oracle_data};
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
delay(ms: number) {
|
|
521
|
+
return new Promise( resolve => setTimeout(resolve, ms) );
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
async getEachFarmDataSerialDash(data: any, bh: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, type: Mode, amount: number, delayTime:number = 0) {
|
|
526
|
+
|
|
527
|
+
const farms : any[][] = [];
|
|
528
|
+
const farm_length: number = data.length;
|
|
529
|
+
for (let i = 0; i < amount; i++) {
|
|
530
|
+
farms.push([]);
|
|
531
|
+
}
|
|
532
|
+
const farm_round = await this.getCurrentFarmingRound3();
|
|
533
|
+
for (let farm_round_iter = Number(farm_round); farm_round_iter < Number(farm_round) + amount ; farm_round_iter++) {
|
|
534
|
+
for (let i = 0; i < data.length; i++) {
|
|
535
|
+
const farm_data = _.cloneDeep(data[i]);
|
|
536
|
+
const value = await this.getFarmDataMinimal(farm_data, farm_round_iter, bh, oracle_data, type);
|
|
537
|
+
value.farm_group = farm_data.farm_group;
|
|
538
|
+
value.farm_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING_LOGIC_3();
|
|
539
|
+
|
|
540
|
+
farms[farm_round_iter-Number(farm_round)].push(value);
|
|
541
|
+
await this.delay(delayTime);
|
|
542
|
+
|
|
543
|
+
}
|
|
544
|
+
this.checkAndSetFarmAPR_Dash(farms[farm_round_iter-Number(farm_round)],farm_length, oracle_data);
|
|
545
|
+
}
|
|
546
|
+
// this.checkAndSetFarmAPR(farms,farm_length, oracle_data);
|
|
547
|
+
return {farms, farm_round, oracle_data};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
async getFarmData(farm: any, farm_round: any, block_height: string, tvl_apr: BigNumber, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, type : Mode ) {
|
|
551
|
+
farm.valid = false;
|
|
552
|
+
farm.cur_round = farm_round;
|
|
553
|
+
switch (type) {
|
|
554
|
+
case Mode.ONLY_BLOCKCHAIN:
|
|
555
|
+
farm.pair = (await this.stackswap.poolManager.getPairDataFromContract(farm.token_x, farm.token_y));
|
|
556
|
+
break;
|
|
557
|
+
case Mode.WITH_SERVER:
|
|
558
|
+
farm.pair = (await this.stackswap.swapManager.findRouter(farm.token_x, farm.token_y, Number(block_height))).pair;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
// farm.pair.sharetoken = {balance: 0, addr: farm.pair.token_lp.addr};
|
|
562
|
+
farm.pair.price = (farm.pair.balance_y / (10 ** farm.token_y.decimal)) / (farm.pair.balance_x / (10 ** farm.token_x.decimal));
|
|
563
|
+
const farm_total_v3 = await this.getFarmBalance3(farm.pair.token_lp);
|
|
564
|
+
|
|
565
|
+
farm.TVL = this.getPoolUSDPriceFarm(farm, new BigNumber(farm_total_v3).toString(), oracle_data);
|
|
566
|
+
farm.total_locked_lp = new BigNumber(farm_total_v3).toString();
|
|
567
|
+
farm.farm_total_v3 = (await this.getFarmingTotalPoolStatusCycle3(farm.pair.token_lp.addr, farm_round)).amountLP.value;
|
|
568
|
+
const farm_temp_total_data = await this.getFarmingTotalStatusCycle3(farm_round, farm.farm_group);
|
|
569
|
+
farm.reward = farm_temp_total_data.reward;
|
|
570
|
+
const lpTotalData = await this.getFarmingTotalPoolStatus3(farm.pair.token_lp.addr);
|
|
571
|
+
farm.weight = lpTotalData.weight;
|
|
572
|
+
tvl_apr = tvl_apr.plus(new BigNumber(this.getPoolUSDPriceFarm(farm, farm.total_locked_lp, oracle_data)).multipliedBy(farm.weight));
|
|
573
|
+
// console.log(farming_contract, farm.TVL, tvl_apr);
|
|
574
|
+
farm.valid = true;
|
|
575
|
+
|
|
576
|
+
return farm;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
localCache:{[name: string]: {block_height: string, data: any} } = {};
|
|
581
|
+
|
|
582
|
+
async getFarmDataMinimal(farm: any, farm_round: any, block_height: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, type : Mode ) {
|
|
583
|
+
farm.valid = false;
|
|
584
|
+
farm.cur_round = farm_round;
|
|
585
|
+
|
|
586
|
+
if(this.localCache[`${farm.token_swapr}|FarmPairData`] == null ||
|
|
587
|
+
Number(this.localCache[`${farm.token_swapr}|FarmPairData`].block_height) < Number(block_height)){
|
|
588
|
+
switch (type) {
|
|
589
|
+
case Mode.ONLY_BLOCKCHAIN:
|
|
590
|
+
farm.pair = (await this.stackswap.poolManager.getPairDataFromContract(farm.token_x, farm.token_y));
|
|
591
|
+
break;
|
|
592
|
+
case Mode.WITH_SERVER:
|
|
593
|
+
farm.pair = (await this.stackswap.swapManager.findRouter(farm.token_x, farm.token_y, Number(block_height))).pair;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
this.localCache[`${farm.token_swapr}|FarmPairData`] = {
|
|
597
|
+
block_height : block_height,
|
|
598
|
+
data : farm.pair,
|
|
599
|
+
}
|
|
600
|
+
}else {
|
|
601
|
+
farm.pair = this.localCache[`${farm.token_swapr}|FarmPairData`].data;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// farm.pair.sharetoken = {balance: 0, addr: farm.pair.token_lp.addr};
|
|
605
|
+
farm.pair.price = (farm.pair.balance_y / (10 ** farm.token_y.decimal)) / (farm.pair.balance_x / (10 ** farm.token_x.decimal));
|
|
606
|
+
// const farm_total_v2 = await this.getFarmBalance3(farm.pair.token_lp, farming_contract);
|
|
607
|
+
// const farm_total_v1 = await this.stackswap.farmManager.getFarmBalance(farm.pair.token_lp);
|
|
608
|
+
const temp_farm_round_data= await this.getFarmingTotalPoolStatusCycle3(farm.pair.token_lp.addr, farm_round);
|
|
609
|
+
// console.log(temp_farm_round_data);
|
|
610
|
+
farm.total_locked_lp = temp_farm_round_data.amountLP.value;
|
|
611
|
+
farm.TVL = this.getPoolUSDPriceFarm(farm, farm.total_locked_lp, oracle_data);
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
if(this.localCache[`${farm.farm_group}|FarmReward`] == null ||
|
|
616
|
+
Number(this.localCache[`${farm.farm_group}|FarmReward`].block_height) < Number(block_height)){
|
|
617
|
+
const farm_temp_total_data = await this.getFarmingTotalStatusCycle3(farm_round, farm.farm_group);
|
|
618
|
+
farm.reward = farm_temp_total_data.reward;
|
|
619
|
+
this.localCache[`${farm.farm_group}|FarmReward`] = {
|
|
620
|
+
block_height : block_height,
|
|
621
|
+
data : farm_temp_total_data.reward,
|
|
622
|
+
}
|
|
623
|
+
}else {
|
|
624
|
+
farm.reward = this.localCache[`${farm.farm_group}|FarmReward`].data;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
let lpTotalData : any = null;
|
|
628
|
+
if(this.localCache[`${farm.token_swapr}|'FarmTotalPool`] == null ||
|
|
629
|
+
Number(this.localCache[`${farm.token_swapr}|'FarmTotalPool`].block_height) < Number(block_height) ){
|
|
630
|
+
|
|
631
|
+
lpTotalData = await this.getFarmingTotalPoolStatus3(farm.pair.token_lp.addr);
|
|
632
|
+
this.localCache[`${farm.token_swapr}|'FarmTotalPool`] = {
|
|
633
|
+
block_height : block_height,
|
|
634
|
+
data : lpTotalData,
|
|
635
|
+
}
|
|
636
|
+
}else {
|
|
637
|
+
lpTotalData = this.localCache[`${farm.token_swapr}|'FarmTotalPool`].data;
|
|
638
|
+
|
|
639
|
+
}
|
|
640
|
+
farm.weight = lpTotalData.weight; //TODO if weight chanages, use temp_farm_round_Data.weight
|
|
641
|
+
// tvl_apr = tvl_apr.plus(new BigNumber(this.getPoolUSDPriceFarm(farm, farm.total_locked_lp, oracle_data)).multipliedBy(farm.weight));
|
|
642
|
+
// console.log(farming_contract, farm.TVL, tvl_apr);
|
|
643
|
+
farm.valid = true;
|
|
644
|
+
|
|
645
|
+
return farm;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async getFarmUserData3(farm: any, farm_round: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }, callback: any) {
|
|
649
|
+
this.getFarmingStakerStatus3(farm.pair.token_lp.addr, Number(farm_round)).then((status_v3) => {
|
|
650
|
+
farm.claimable_list = status_v3.unclaimedList;
|
|
651
|
+
farm.pooled_lp_v3 = status_v3.pooledToken;
|
|
652
|
+
farm.pooled_stsw = new BigNumber(status_v3.pooledToken).toString();
|
|
653
|
+
farm.stakedList = status_v3.stakedList;
|
|
654
|
+
farm.user_TVL = this.getPoolUSDPriceFarm(farm, farm.pooled_stsw, oracle_data);
|
|
655
|
+
// console.log('migrated', status_v2, status_v1);
|
|
656
|
+
this.getRewardBalanceFromFarming3(farm.pair.token_lp.addr, status_v3.unclaimedList).then(reward_v2 => {
|
|
657
|
+
// console.log({reward_v2})
|
|
658
|
+
farm.total_reward = new BigNumber(reward_v2).toString();
|
|
659
|
+
callback(farm);
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|