stackswap-front-api-test-02 1.0.38 → 1.0.46
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 +10 -4
- package/dist/esm/index.js +38 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stackswap/config.d.ts +29 -3
- package/dist/esm/stackswap/config.js +62 -3
- package/dist/esm/stackswap/config.js.map +1 -1
- package/dist/esm/stackswap/manager/farm2.manager.d.ts +39 -20
- package/dist/esm/stackswap/manager/farm2.manager.js +158 -62
- package/dist/esm/stackswap/manager/farm2.manager.js.map +1 -1
- package/dist/esm/stackswap/manager/staking.manager.js +2 -2
- package/dist/esm/stackswap/manager/staking.manager.js.map +1 -1
- package/dist/esm/stackswap/util.d.ts +0 -2
- package/dist/esm/stackswap/util.js +3 -41
- package/dist/esm/stackswap/util.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.js +40 -18
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/stackswap/config.d.ts +29 -3
- package/dist/stackswap/config.js +64 -4
- package/dist/stackswap/config.js.map +1 -1
- package/dist/stackswap/manager/farm2.manager.d.ts +39 -20
- package/dist/stackswap/manager/farm2.manager.js +157 -61
- package/dist/stackswap/manager/farm2.manager.js.map +1 -1
- package/dist/stackswap/manager/staking.manager.js +2 -2
- package/dist/stackswap/manager/staking.manager.js.map +1 -1
- package/dist/stackswap/util.d.ts +0 -2
- package/dist/stackswap/util.js +4 -44
- package/dist/stackswap/util.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +43 -18
- package/src/stackswap/config.ts +79 -5
- package/src/stackswap/manager/farm2.manager.ts +189 -126
- package/src/stackswap/manager/staking.manager.ts +2 -2
- package/src/stackswap/util.ts +6 -38
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@stacks/transactions';
|
|
9
9
|
import BigNumber from 'bignumber.js';
|
|
10
10
|
import {openContractCall} from '@stacks/connect';
|
|
11
|
-
import {getPostConditionFromAsset, getReadOptions, getWriteOptions, num2decimal
|
|
11
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions, num2decimal} from "../util";
|
|
12
12
|
import {StackswapAPI} from "../../index";
|
|
13
13
|
|
|
14
14
|
|
|
@@ -18,10 +18,10 @@ export class Farm2Manager {
|
|
|
18
18
|
constructor(stackswap: StackswapAPI) {
|
|
19
19
|
this.stackswap = stackswap;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
async
|
|
21
|
+
|
|
22
|
+
async getFarmingRound2(bh: number, farming_contract: string) {
|
|
23
23
|
try {
|
|
24
|
-
const function_option = getReadOptions(this.stackswap,
|
|
24
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getRewardRound', [
|
|
25
25
|
uintCV(bh)
|
|
26
26
|
]);
|
|
27
27
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
@@ -33,9 +33,8 @@ export class Farm2Manager {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const function_option = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING(), 'getFirstBlockOfRound', [
|
|
36
|
+
async getFarmingRoundFirstBlock2(cycle: number, farming_contract: string) {
|
|
37
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getFirstBlockOfRound', [
|
|
39
38
|
uintCV(cycle)
|
|
40
39
|
]);
|
|
41
40
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
@@ -44,10 +43,9 @@ export class Farm2Manager {
|
|
|
44
43
|
return result;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
async isUserMigratable( pool_address: string) {
|
|
46
|
+
async isUserMigratable2(pool_address: string, farming_contract: string) {
|
|
49
47
|
const address = pool_address.split('.');
|
|
50
|
-
const function_option = getReadOptions(this.stackswap,
|
|
48
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'isUserMigratable', [
|
|
51
49
|
contractPrincipalCV(address[0], address[1]),
|
|
52
50
|
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
53
51
|
]);
|
|
@@ -61,29 +59,29 @@ export class Farm2Manager {
|
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
getPoolUSDPriceFarm(farm: any, farm_total: any, oracle_stx: any, oracle_stsw: any, oracle_lbtc: any) {
|
|
62
|
+
getPoolUSDPriceFarm(farm: any, farm_total: any, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }) {
|
|
65
63
|
// BigNumber.config({ DECIMAL_PLACES: 6});
|
|
66
64
|
let tvl = 0;
|
|
67
65
|
switch (farm.BASE) {
|
|
68
66
|
case 'STX':
|
|
69
67
|
if (farm.token_x.symbol === farm.BASE) {
|
|
70
|
-
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_stx)).toNumber();
|
|
68
|
+
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stx)).toNumber();
|
|
71
69
|
} else {
|
|
72
|
-
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_stx)).toNumber();
|
|
70
|
+
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stx)).toNumber();
|
|
73
71
|
}
|
|
74
72
|
break;
|
|
75
73
|
case 'STSW':
|
|
76
74
|
if (farm.token_x.symbol === farm.BASE) {
|
|
77
|
-
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_stsw)).toNumber();
|
|
75
|
+
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stsw)).toNumber();
|
|
78
76
|
} else {
|
|
79
|
-
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_stsw)).toNumber();
|
|
77
|
+
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 12))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_stsw)).toNumber();
|
|
80
78
|
}
|
|
81
79
|
break;
|
|
82
80
|
case 'lBTC':
|
|
83
81
|
if (farm.token_x.symbol === farm.BASE) {
|
|
84
|
-
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_lbtc)).toNumber();
|
|
82
|
+
tvl = (new BigNumber(farm.pair['balance-x'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_lbtc)).toNumber();
|
|
85
83
|
} else {
|
|
86
|
-
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_lbtc)).toNumber();
|
|
84
|
+
tvl = (new BigNumber(farm.pair['balance-y'].value).multipliedBy(farm_total).dividedBy(farm.pair['shares-total'].value).dividedBy(new BigNumber(10 ** 14))).multipliedBy(2).multipliedBy(new BigNumber(oracle_data.oracle_lbtc)).toNumber();
|
|
87
85
|
}
|
|
88
86
|
break;
|
|
89
87
|
default:
|
|
@@ -92,35 +90,35 @@ export class Farm2Manager {
|
|
|
92
90
|
return tvl;
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
async getFarming(pair: any,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
async getFarmingStakerStatus( pool_address: string, cur_round: number) {
|
|
93
|
+
//
|
|
94
|
+
// async getFarming(pair: any ,token_x: any, token_y: any, farm_total: any){
|
|
95
|
+
// // BigNumber.config({ DECIMAL_PLACES: 6});
|
|
96
|
+
// const x_token_addr = token_x.addr;
|
|
97
|
+
// // console.log(token_x.addr);
|
|
98
|
+
// const y_token_addr = token_y.addr;
|
|
99
|
+
// // console.log(token_y.addr);
|
|
100
|
+
// let total_balacne = new BigNumber(-1);
|
|
101
|
+
// if(x_token_addr === this.stackswap.config.BASE_WSTX_DATA().addr){
|
|
102
|
+
// total_balacne = (new BigNumber(pair['balance-x'].value).multipliedBy(farm_total).dividedBy(pair['shares-total'].value).dividedBy(new BigNumber(10 ** token_x.decimal))).multipliedBy(2);
|
|
103
|
+
// }else if(y_token_addr === this.stackswap.config.BASE_WSTX_DATA().addr){
|
|
104
|
+
// total_balacne = (new BigNumber(pair['balance-y'].value).multipliedBy(farm_total).dividedBy(pair['shares-total'].value).dividedBy(new BigNumber(10 ** token_y.decimal))).multipliedBy(2);
|
|
105
|
+
// }
|
|
106
|
+
// // console.log('pool_stx_price', token_x.addr, token_y.addr,token_x.balance, token_y.balance,total_balacne.toNumber());
|
|
107
|
+
// // console.log(pair["balance-x"].value, pair["balance-y"].value, total_balacne.toNumber());
|
|
108
|
+
// return total_balacne;
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
async getFarmingStakerStatus2(pool_address: string, cur_round: number, farming_contract: string) {
|
|
115
112
|
const address = pool_address.split('.');
|
|
116
|
-
|
|
113
|
+
console.log('getFarmingStakerStatus', farming_contract);
|
|
114
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getLPUserData', [
|
|
117
115
|
contractPrincipalCV(address[0], address[1]),
|
|
118
116
|
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
119
117
|
]);
|
|
120
118
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
121
119
|
const result = cvToValue(result_raw);
|
|
122
120
|
try {
|
|
123
|
-
|
|
121
|
+
console.log('getFarmingStakerStatus', result);
|
|
124
122
|
const pooledToken = result.value.amountLP.value;
|
|
125
123
|
const unclaimedList = [];
|
|
126
124
|
const stakedList = []
|
|
@@ -134,15 +132,14 @@ export class Farm2Manager {
|
|
|
134
132
|
// console.log({pooledToken, unclaimedList, stakedList});
|
|
135
133
|
return {pooledToken, unclaimedList, stakedList};
|
|
136
134
|
} catch (e) {
|
|
137
|
-
|
|
135
|
+
console.log(e);
|
|
138
136
|
return {pooledToken: 0, unclaimedList: [], stakedList: []}
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
139
|
|
|
142
|
-
|
|
143
|
-
async getFarmingTotalStatusCycle( cycle: number) {
|
|
140
|
+
async getFarmingTotalStatusCycle2(cycle: number, farming_contract: string) {
|
|
144
141
|
// console.log(cycle);
|
|
145
|
-
const function_option = getReadOptions(this.stackswap,
|
|
142
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getTotalRoundDataOrDefault', [
|
|
146
143
|
uintCV(cycle),
|
|
147
144
|
]);
|
|
148
145
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
@@ -162,31 +159,9 @@ export class Farm2Manager {
|
|
|
162
159
|
}
|
|
163
160
|
}
|
|
164
161
|
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
168
|
-
* @param this.stackswap
|
|
169
|
-
* @param pool_address
|
|
170
|
-
* @param cycle
|
|
171
|
-
*
|
|
172
|
-
* {
|
|
173
|
-
* "type": "(tuple (amountLP uint) (weight uint))",
|
|
174
|
-
* "value": {
|
|
175
|
-
* "amountLP": {
|
|
176
|
-
* "type": "uint",
|
|
177
|
-
* "value": "122000000"
|
|
178
|
-
* },
|
|
179
|
-
* "weight": {
|
|
180
|
-
* "type": "uint",
|
|
181
|
-
* "value": "1"
|
|
182
|
-
* }
|
|
183
|
-
* }
|
|
184
|
-
* }
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
async getFarmingTotalPoolStatus( pool_address: string) {
|
|
162
|
+
async getFarmingTotalPoolStatus2(pool_address: string, farming_contract: string) {
|
|
188
163
|
const address = pool_address.split('.');
|
|
189
|
-
const function_option = getReadOptions(this.stackswap,
|
|
164
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getLPTotalData', [
|
|
190
165
|
contractPrincipalCV(address[0], address[1]),
|
|
191
166
|
]);
|
|
192
167
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
@@ -200,23 +175,9 @@ export class Farm2Manager {
|
|
|
200
175
|
}
|
|
201
176
|
}
|
|
202
177
|
|
|
203
|
-
|
|
204
|
-
*
|
|
205
|
-
* @param this.stackswap
|
|
206
|
-
* @param pool_address
|
|
207
|
-
* @param cycle
|
|
208
|
-
*
|
|
209
|
-
* {
|
|
210
|
-
* value: u0,
|
|
211
|
-
* weight: u0,
|
|
212
|
-
* amountLP: u0,
|
|
213
|
-
* price: u0
|
|
214
|
-
* }
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
async getFarmingTotalPoolStatusCycle( pool_address: string, cycle: number) {
|
|
178
|
+
async getFarmingTotalPoolStatusCycle2(pool_address: string, cycle: number, farming_contract: string) {
|
|
218
179
|
const address = pool_address.split('.');
|
|
219
|
-
const function_option = getReadOptions(this.stackswap,
|
|
180
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getLPRoundData', [
|
|
220
181
|
contractPrincipalCV(address[0], address[1]),
|
|
221
182
|
uintCV(cycle),
|
|
222
183
|
]);
|
|
@@ -230,11 +191,10 @@ export class Farm2Manager {
|
|
|
230
191
|
}
|
|
231
192
|
}
|
|
232
193
|
|
|
233
|
-
|
|
234
|
-
async getFarmingTotalValue( pool_address: string) {
|
|
194
|
+
async getFarmingTotalValue2(pool_address: string, farming_contract: string) {
|
|
235
195
|
try {
|
|
236
196
|
const address = pool_address.split('.');
|
|
237
|
-
const function_option = getReadOptions(this.stackswap,
|
|
197
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getLPTotalData', [
|
|
238
198
|
contractPrincipalCV(address[0], address[1]),
|
|
239
199
|
]);
|
|
240
200
|
const result_raw = await callReadOnlyFunction(function_option);
|
|
@@ -246,11 +206,9 @@ export class Farm2Manager {
|
|
|
246
206
|
}
|
|
247
207
|
}
|
|
248
208
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
async getFarmingUserRewardPerCycle( pool_address: string, cycle: number) {
|
|
209
|
+
async getFarmingUserRewardPerCycle2(pool_address: string, cycle: number, farming_contract: string) {
|
|
252
210
|
const address = pool_address.split('.');
|
|
253
|
-
const function_option = getReadOptions(this.stackswap,
|
|
211
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getFarmingReward', [
|
|
254
212
|
contractPrincipalCV(address[0], address[1]),
|
|
255
213
|
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
256
214
|
uintCV(cycle),
|
|
@@ -261,11 +219,9 @@ export class Farm2Manager {
|
|
|
261
219
|
return result;
|
|
262
220
|
}
|
|
263
221
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
async getFarmingUserRewardList( pool_address: string, unclaimed_list: any) {
|
|
222
|
+
async getFarmingUserRewardList2(pool_address: string, unclaimed_list: any, farming_contract: string) {
|
|
267
223
|
const address = pool_address.split('.');
|
|
268
|
-
const function_option = getReadOptions(this.stackswap,
|
|
224
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getFarmingRewardFromList', [
|
|
269
225
|
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
270
226
|
contractPrincipalCV(address[0], address[1]),
|
|
271
227
|
listCV(unclaimed_list),
|
|
@@ -277,9 +233,9 @@ export class Farm2Manager {
|
|
|
277
233
|
}
|
|
278
234
|
|
|
279
235
|
|
|
280
|
-
async
|
|
236
|
+
async getFarmingRewardInfo2(pool_address: string, cycle: number, farming_contract: string) {
|
|
281
237
|
const address = pool_address.split('.');
|
|
282
|
-
const function_option = getReadOptions(this.stackswap,
|
|
238
|
+
const function_option = getReadOptions(this.stackswap, farming_contract, 'getLPUserRoundData', [
|
|
283
239
|
contractPrincipalCV(address[0], address[1]),
|
|
284
240
|
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
285
241
|
uintCV(cycle),
|
|
@@ -290,22 +246,20 @@ export class Farm2Manager {
|
|
|
290
246
|
return result.value.returnLP.value;
|
|
291
247
|
}
|
|
292
248
|
|
|
293
|
-
|
|
294
|
-
async migrateToVersion2( pool_address: string, callback: any = null) {
|
|
249
|
+
async migrateToVersion2(pool_address: string, farming_contract: string, callback: any) {
|
|
295
250
|
const address = pool_address.split('.');
|
|
296
251
|
// console.log(amountTokens);
|
|
297
|
-
const function_option = getWriteOptions(this.stackswap,
|
|
252
|
+
const function_option = getWriteOptions(this.stackswap, farming_contract, 'migrateFromVersion1', [
|
|
298
253
|
contractPrincipalCV(address[0], address[1]),
|
|
299
254
|
], [], callback);
|
|
300
255
|
await openContractCall(function_option);
|
|
301
256
|
}
|
|
302
257
|
|
|
303
|
-
|
|
304
|
-
async stakeFarmingContract( pool_address: string, amountTokens: string, lockPeriod: number, callback: any = null) {
|
|
258
|
+
async stakeFarmingContract2(pool_address: string, amountTokens: string, lockPeriod: number, callback: any, farming_contract: string) {
|
|
305
259
|
const address = pool_address.split('.');
|
|
306
260
|
// console.log(amountTokens);
|
|
307
261
|
const amount = new BigNumber(amountTokens).multipliedBy(10 ** 6).toFixed(0).toString();
|
|
308
|
-
const function_option = getWriteOptions(this.stackswap,
|
|
262
|
+
const function_option = getWriteOptions(this.stackswap, farming_contract, 'stakeTokens', [
|
|
309
263
|
uintCV(amount),
|
|
310
264
|
contractPrincipalCV(address[0], address[1]),
|
|
311
265
|
uintCV(lockPeriod),
|
|
@@ -314,10 +268,10 @@ export class Farm2Manager {
|
|
|
314
268
|
await openContractCall(function_option);
|
|
315
269
|
}
|
|
316
270
|
|
|
317
|
-
async
|
|
271
|
+
async getFarmBalance2(token: any, farming_contract: string) {
|
|
318
272
|
// console.log("getBalance", token)
|
|
319
273
|
const pair_details_options: any = getReadOptions(this.stackswap, token.addr, 'get-balance',
|
|
320
|
-
[contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(),
|
|
274
|
+
[contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), farming_contract)]);
|
|
321
275
|
try {
|
|
322
276
|
const result = await callReadOnlyFunction(pair_details_options);
|
|
323
277
|
return cvToValue(result).value;
|
|
@@ -326,13 +280,12 @@ export class Farm2Manager {
|
|
|
326
280
|
}
|
|
327
281
|
}
|
|
328
282
|
|
|
329
|
-
|
|
330
|
-
async claimFarmingContract( pool_address: string, cycle: number, amount_STSW: string, amount_LP: string, callback: any = null) {
|
|
283
|
+
async claimFarmingContract2(pool_address: string, cycle: number, amount_STSW: string, amount_LP: string, callback: any, farming_contract: string) {
|
|
331
284
|
const address = pool_address.split('.');
|
|
332
285
|
const post_condition = [];
|
|
333
|
-
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' +
|
|
334
|
-
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' +
|
|
335
|
-
const function_option = getWriteOptions(this.stackswap,
|
|
286
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + farming_contract, this.stackswap.config.BASE_STSW_DATA().addr, amount_STSW, FungibleConditionCode.Equal));
|
|
287
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + farming_contract, pool_address, amount_LP, FungibleConditionCode.Equal));
|
|
288
|
+
const function_option = getWriteOptions(this.stackswap, farming_contract, 'claimStakingReward', [
|
|
336
289
|
uintCV(cycle),
|
|
337
290
|
contractPrincipalCV(address[0], address[1]),
|
|
338
291
|
contractPrincipalCV(this.stackswap.config.STACKSWAP_ADDRESS(), this.stackswap.config.CONTRACT_NAME_ORACLE())
|
|
@@ -341,48 +294,46 @@ export class Farm2Manager {
|
|
|
341
294
|
}
|
|
342
295
|
|
|
343
296
|
|
|
344
|
-
async
|
|
297
|
+
async unstakeFarmingContract2(pool_address: string, cycle: number, amount_LP: string, callback: any, farming_contract: string) {
|
|
345
298
|
const address = pool_address.split('.');
|
|
346
299
|
const post_condition = [];
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const function_option = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING(), 'unstake-from-farming', [
|
|
300
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.config.STACKSWAP_ADDRESS() + '.' + farming_contract, pool_address, amount_LP, FungibleConditionCode.Equal));
|
|
301
|
+
const function_option = getWriteOptions(this.stackswap, farming_contract, 'unstake-from-farming', [
|
|
350
302
|
uintCV(cycle),
|
|
351
303
|
contractPrincipalCV(address[0], address[1]),
|
|
352
304
|
], post_condition, callback);
|
|
353
305
|
await openContractCall(function_option);
|
|
354
306
|
}
|
|
355
307
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return await this. getFarmingRound(bh);
|
|
308
|
+
async getCurrentFarmingRound2(farming_contract: string) {
|
|
309
|
+
const bh = await this.stackswap.getCurrentBlock();
|
|
310
|
+
return await this.getFarmingRound2(Number(bh), farming_contract);
|
|
360
311
|
}
|
|
361
312
|
|
|
362
|
-
|
|
363
|
-
async getRewardBalanceFromFarming( pool_addr: string, unclaimed_list: any) {
|
|
313
|
+
async getRewardBalanceFromFarming2(pool_addr: string, unclaimed_list: any, farming_contract: string) {
|
|
364
314
|
// let reward_balance = new BigNumber(0);
|
|
365
315
|
const num_list = [];
|
|
366
316
|
for (const unclaimed of unclaimed_list) {
|
|
367
317
|
num_list.push(uintCV(unclaimed));
|
|
368
318
|
}
|
|
369
319
|
let reward_num = new BigNumber(0);
|
|
370
|
-
|
|
320
|
+
console.log(pool_addr, num_list, farming_contract)
|
|
371
321
|
try {
|
|
372
322
|
for (let i = 0; i < num_list.length; i += 4) {
|
|
373
|
-
|
|
374
|
-
const result = await this.
|
|
323
|
+
console.log(pool_addr, num_list.slice(i, i + 4 < num_list.length ? i + 4 : num_list.length), farming_contract);
|
|
324
|
+
const result = await this.getFarmingUserRewardList2(pool_addr, num_list.slice(i, i + 4 < num_list.length ? i + 4 : num_list.length), farming_contract);
|
|
375
325
|
// rewardSum.value;
|
|
376
|
-
|
|
326
|
+
console.log('temp result', result.rewardSum.value);
|
|
377
327
|
reward_num = reward_num.plus(new BigNumber(result.rewardSum.value));
|
|
378
328
|
}
|
|
379
|
-
return
|
|
329
|
+
return num2decimal(reward_num.toString(), 6);
|
|
380
330
|
} catch (e) {
|
|
381
331
|
// console.log(e);
|
|
382
|
-
return
|
|
332
|
+
return num2decimal(reward_num.toString(), 6);
|
|
383
333
|
}
|
|
384
334
|
}
|
|
385
|
-
|
|
335
|
+
|
|
336
|
+
|
|
386
337
|
getFarmingAPR(tvl: string, stsw_price: string, reward: string, weight: string) {
|
|
387
338
|
// console.log('farmingAPR');
|
|
388
339
|
// console.log({tvl, stsw_price, reward, weight})
|
|
@@ -404,4 +355,116 @@ export class Farm2Manager {
|
|
|
404
355
|
return new_reward_apr.toFixed(3).toString();
|
|
405
356
|
}
|
|
406
357
|
}
|
|
358
|
+
|
|
359
|
+
async getFarmDataFromData(data: any) {
|
|
360
|
+
const oracle_stsw = (await this.stackswap.lbtcManager.getPrice('STSW'))['last-price'].value;
|
|
361
|
+
const oracle_stx = (await this.stackswap.lbtcManager.getPrice('STX'))['last-price'].value;
|
|
362
|
+
const oracle_lbtc = (await this.stackswap.lbtcManager.getPrice('lBTC'))['last-price'].value;
|
|
363
|
+
const bh = await this.stackswap.getCurrentBlock();
|
|
364
|
+
return await this.getEachFarmData(data, bh, {oracle_stsw, oracle_lbtc, oracle_stx})
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async getEachFarmData(data: any, bh: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }) {
|
|
369
|
+
|
|
370
|
+
const tvl_apr = new BigNumber(0);
|
|
371
|
+
const farms : any[] = [];
|
|
372
|
+
const farm_length: number = data.length;
|
|
373
|
+
|
|
374
|
+
for (let i = 0; i < data.length; i++) {
|
|
375
|
+
let farming_contract = '';
|
|
376
|
+
if (data[i].farm_group === 1) {
|
|
377
|
+
farming_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING2_1();
|
|
378
|
+
} else if (data[i].farm_group === 5) {
|
|
379
|
+
farming_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_FARMING2_5();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const farm_round = await this.getCurrentFarmingRound2(farming_contract);
|
|
383
|
+
this.getFarmData(data[i], farm_round, bh, tvl_apr, farming_contract, oracle_data).then((value) => {
|
|
384
|
+
value.farm_group = data[i].farm_group;
|
|
385
|
+
value.farm_contract = farming_contract;
|
|
386
|
+
farms.push(value);
|
|
387
|
+
|
|
388
|
+
if (farms.length === farm_length) {
|
|
389
|
+
const tvls = {'group1': '0', 'group5': '0'}
|
|
390
|
+
for (const farm_temp of farms) {
|
|
391
|
+
switch (farm_temp.farm_group) {
|
|
392
|
+
case 1:
|
|
393
|
+
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();
|
|
394
|
+
break;
|
|
395
|
+
case 5:
|
|
396
|
+
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();
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
console.log({tvls})
|
|
401
|
+
for (const farm_temp of farms) {
|
|
402
|
+
switch (farm_temp.farm_group) {
|
|
403
|
+
case 1:
|
|
404
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group1, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
405
|
+
break;
|
|
406
|
+
case 5:
|
|
407
|
+
farm_temp.APR = this.getFarmingAPR(tvls.group5, oracle_data.oracle_stsw, farm_temp.reward, farm_temp.weight);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
console.log(farm_temp.APR)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
})
|
|
414
|
+
}
|
|
415
|
+
return farms;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async getFarmData(farm: any, farm_round: any, block_height: string, tvl_apr: BigNumber, farming_contract: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }) {
|
|
419
|
+
farm.valid = false;
|
|
420
|
+
farm.cur_round = farm_round;
|
|
421
|
+
farm.pair = (await this.stackswap.swapManager.findRouter(farm.token_x, farm.token_y, Number(block_height))).pair;
|
|
422
|
+
farm.pair.sharetoken = {balance: 0, addr: farm.pair['liquidity-token'].value};
|
|
423
|
+
farm.pair.price = (farm.pair['balance-y'].value / (10 ** farm.token_y.decimal)) / (farm.pair['balance-x'].value / (10 ** farm.token_x.decimal));
|
|
424
|
+
const farm_total_v2 = await this.getFarmBalance2(farm.pair.sharetoken, farming_contract);
|
|
425
|
+
const farm_total_v1 = await this.stackswap.farmManager.getFarmBalance(farm.pair.sharetoken);
|
|
426
|
+
farm.TVL = this.getPoolUSDPriceFarm(farm, new BigNumber(farm_total_v1).plus(farm_total_v2).toString(), oracle_data);
|
|
427
|
+
farm.total_locked_lp = new BigNumber(farm_total_v1).plus(farm_total_v2).toString();
|
|
428
|
+
const farm_temp_total_data = await this.getFarmingTotalStatusCycle2(farm_round, farming_contract);
|
|
429
|
+
farm.reward = farm_temp_total_data.reward;
|
|
430
|
+
const lpTotalData = await this.getFarmingTotalPoolStatus2(farm.token_swapr, farming_contract);
|
|
431
|
+
farm.weight = lpTotalData.weight;
|
|
432
|
+
tvl_apr = tvl_apr.plus(new BigNumber(this.getPoolUSDPriceFarm(farm, farm.total_locked_lp, oracle_data)).multipliedBy(farm.weight));
|
|
433
|
+
console.log(farming_contract, farm.TVL, tvl_apr);
|
|
434
|
+
farm.valid = true;
|
|
435
|
+
|
|
436
|
+
return farm;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async getFarmUserData(farm: any, farm_round: string, farming_contract: string, oracle_data: { oracle_stx: any, oracle_stsw: any, oracle_lbtc: any }){
|
|
440
|
+
farm.isMigratable = await this.isUserMigratable2(farm.pair['liquidity-token'].value, farming_contract); // 신규는 무조건 true
|
|
441
|
+
this.getFarmingStakerStatus2(farm.token_swapr, Number(farm_round), farming_contract).then((status_v2) => {
|
|
442
|
+
if (!farm.isMigratable) {
|
|
443
|
+
this.stackswap.farmManager.getFarmingStakerStatus(farm.token_swapr, Number(farm_round)).then((status_v1) => {
|
|
444
|
+
farm.claimable_list = status_v2.unclaimedList.concat(status_v1.unclaimedList);
|
|
445
|
+
farm.pooled_stsw = new BigNumber(status_v2.pooledToken).plus(status_v1.pooledToken).toString();
|
|
446
|
+
farm.stakedList = status_v2.stakedList;
|
|
447
|
+
farm.user_TVL = this.getPoolUSDPriceFarm(farm, farm.pooled_stsw, oracle_data);
|
|
448
|
+
// console.log('migrated', status_v2, status_v1);
|
|
449
|
+
this.getRewardBalanceFromFarming2(farm.token_swapr, status_v2.unclaimedList, farming_contract).then(reward_v2 => {
|
|
450
|
+
this.stackswap.farmManager.getRewardBalanceFromFarming(farm.token_swapr, status_v1.unclaimedList).then(reward_v1 => {
|
|
451
|
+
console.log({reward_v2})
|
|
452
|
+
farm.total_reward = new BigNumber(reward_v2).plus(reward_v1).toString();
|
|
453
|
+
}
|
|
454
|
+
)
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
} else {
|
|
458
|
+
console.log('not yet migrated', status_v2);
|
|
459
|
+
farm.claimable_list = status_v2.unclaimedList;
|
|
460
|
+
farm.pooled_stsw = status_v2.pooledToken;
|
|
461
|
+
farm.stakedList = status_v2.stakedList;
|
|
462
|
+
farm.user_TVL = this.getPoolUSDPriceFarm(farm, farm.pooled_stsw, oracle_data);
|
|
463
|
+
this.getRewardBalanceFromFarming2(farm.token_swapr, status_v2.unclaimedList, farming_contract).then(reward => {
|
|
464
|
+
console.log({reward})
|
|
465
|
+
farm.total_reward = reward;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
}
|
|
407
470
|
}
|
|
@@ -235,7 +235,7 @@ export class StakingManager {
|
|
|
235
235
|
);
|
|
236
236
|
|
|
237
237
|
const function_option : any = getWriteOptions(this.stackswap,
|
|
238
|
-
this.stackswap.config.
|
|
238
|
+
this.stackswap.config.BASE_vSTSW_DATA().addr,
|
|
239
239
|
'stake-tokens',[
|
|
240
240
|
uintCV(invest_amt_bn),uintCV(period_month)],
|
|
241
241
|
postConditions, callback
|
|
@@ -245,7 +245,7 @@ export class StakingManager {
|
|
|
245
245
|
|
|
246
246
|
async txCooldownFromVSTSW(index:number, callback : any = null){
|
|
247
247
|
const function_option : any = getWriteOptions(this.stackswap,
|
|
248
|
-
this.stackswap.config.
|
|
248
|
+
this.stackswap.config.BASE_vSTSW_DATA().addr,
|
|
249
249
|
'unstake-tokens', [uintCV(index)], [], callback);
|
|
250
250
|
await openContractCall(function_option);
|
|
251
251
|
}
|
package/src/stackswap/util.ts
CHANGED
|
@@ -159,11 +159,14 @@ export function decimal2integer(input:any, decimal:number = 6){
|
|
|
159
159
|
|
|
160
160
|
export function numWithComma(input:any) {
|
|
161
161
|
if(typeof (input) === 'string'){
|
|
162
|
-
return input.
|
|
162
|
+
return new BigNumber(input).toNumber().toLocaleString();
|
|
163
|
+
// return input.replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ',');
|
|
163
164
|
}else if(typeof (input) === 'number'){
|
|
164
|
-
return input.
|
|
165
|
+
return new BigNumber(input).toNumber().toLocaleString();
|
|
166
|
+
// return input.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ',');
|
|
165
167
|
}else if(BigNumber.isBigNumber(input)){
|
|
166
|
-
return input.
|
|
168
|
+
return input.toNumber().toLocaleString();
|
|
169
|
+
// return input.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ',');
|
|
167
170
|
}else{
|
|
168
171
|
return 'ERROR';
|
|
169
172
|
}
|
|
@@ -232,38 +235,3 @@ export function getAmountStringWithDecimal(amount: string, decimal: number) {
|
|
|
232
235
|
return new BigNumber(10 ** decimal).multipliedBy(new BigNumber(amount)).toString();
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
|
-
export function getDecimalStringfromString2(amount: string, decimal: number) {
|
|
236
|
-
const amount_bn = new BigNumber(amount);
|
|
237
|
-
const decimal_bn = new BigNumber(10**decimal);
|
|
238
|
-
BigNumber.config({ DECIMAL_PLACES: 3});
|
|
239
|
-
return (amount_bn.dividedBy(decimal_bn)).toFixed(0).toString();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function getDecimalStringfromString(amount: string, decimal: number) {
|
|
243
|
-
const len_str = amount.length;
|
|
244
|
-
if ( len_str > decimal) {
|
|
245
|
-
const temp =amount.substr(0, len_str-decimal) + '.'+amount.substr(len_str-decimal, len_str).replace(/.0+$/, '')
|
|
246
|
-
if (temp === '0.') {
|
|
247
|
-
return '0';
|
|
248
|
-
} else{
|
|
249
|
-
if(temp.charAt(temp.length-1) === '.'){
|
|
250
|
-
return temp.substr(0, temp.length-1);
|
|
251
|
-
} else {
|
|
252
|
-
return temp;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
const temp = '0'.repeat(decimal-len_str+1) + amount;
|
|
257
|
-
const temp2 = temp.substr(0, temp.length-decimal) + '.'+temp.substr(temp.length - decimal, temp.length).replace(/0+$/, '');
|
|
258
|
-
|
|
259
|
-
if (temp2 === '0.') {
|
|
260
|
-
return '0';
|
|
261
|
-
} else{
|
|
262
|
-
if(temp2.charAt(temp2.length-1) === '.'){
|
|
263
|
-
return temp2.substr(0, temp2.length-1);
|
|
264
|
-
} else {
|
|
265
|
-
return temp2;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|