stackswap-front-api-test-02 1.1.39 → 1.1.41
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/stackswap/config.d.ts +2 -0
- package/dist/esm/stackswap/config.js +3 -0
- package/dist/esm/stackswap/config.js.map +1 -1
- package/dist/esm/stackswap/manager/bridge.manager.d.ts +26 -0
- package/dist/esm/stackswap/manager/bridge.manager.js +214 -0
- package/dist/esm/stackswap/manager/bridge.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/staking.manager.d.ts +1 -0
- package/dist/esm/stackswap/manager/staking.manager.js +2 -2
- package/dist/esm/stackswap/manager/staking.manager.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/stackswap/config.d.ts +2 -0
- package/dist/stackswap/config.js +3 -0
- package/dist/stackswap/config.js.map +1 -1
- package/dist/stackswap/manager/bridge.manager.d.ts +26 -0
- package/dist/stackswap/manager/bridge.manager.js +221 -0
- package/dist/stackswap/manager/bridge.manager.js.map +1 -0
- package/dist/stackswap/manager/staking.manager.d.ts +1 -0
- package/dist/stackswap/manager/staking.manager.js +2 -2
- package/dist/stackswap/manager/staking.manager.js.map +1 -1
- package/package.json +1 -1
- package/src/stackswap/config.ts +4 -1
- package/src/stackswap/manager/bridge.manager.ts +294 -0
- package/src/stackswap/manager/staking.manager.ts +2 -2
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
callReadOnlyFunction,
|
|
4
|
+
cvToValue, falseCV,
|
|
5
|
+
FungibleConditionCode, listCV,
|
|
6
|
+
stringAsciiCV, trueCV,
|
|
7
|
+
uintCV
|
|
8
|
+
} from "@stacks/transactions";
|
|
9
|
+
import {openContractCall} from "@stacks/connect";
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import {getPostConditionFromAsset, getReadOptions, getWriteOptions, parseAddressToCV} from "../util";
|
|
12
|
+
import {StackswapAPI} from "../../index";
|
|
13
|
+
|
|
14
|
+
export class StakingManager {
|
|
15
|
+
stackswap: StackswapAPI;
|
|
16
|
+
|
|
17
|
+
constructor(stackswap: StackswapAPI) {
|
|
18
|
+
this.stackswap = stackswap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async get_voters() {
|
|
23
|
+
// console.log('getStakingSTSWBalance');
|
|
24
|
+
|
|
25
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'get-voters',
|
|
26
|
+
[]);
|
|
27
|
+
try {
|
|
28
|
+
const result = await callReadOnlyFunction(options);
|
|
29
|
+
const temp2 = [];
|
|
30
|
+
for (const cvToValueElement of cvToValue(result)) {
|
|
31
|
+
temp2.push(cvToValueElement.value);
|
|
32
|
+
}
|
|
33
|
+
console.log('get_voters', temp2);
|
|
34
|
+
return temp2;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// console.log(e);
|
|
37
|
+
return '0';
|
|
38
|
+
}
|
|
39
|
+
// console.log(pair_details_result)
|
|
40
|
+
}
|
|
41
|
+
async getVoteRes() {
|
|
42
|
+
// console.log('getStakingSTSWBalance');
|
|
43
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getVoteRes',
|
|
44
|
+
[]);
|
|
45
|
+
try {
|
|
46
|
+
const result = await callReadOnlyFunction(options);
|
|
47
|
+
console.log('getVoteRes', cvToValue(result));
|
|
48
|
+
return cvToValue(result);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// console.log(e);
|
|
51
|
+
return '0';
|
|
52
|
+
}
|
|
53
|
+
// console.log(pair_details_result)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async GetFee() {
|
|
57
|
+
// console.log('getStakingSTSWBalance');
|
|
58
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'GetFee',
|
|
59
|
+
[]);
|
|
60
|
+
try {
|
|
61
|
+
const result = await callReadOnlyFunction(options);
|
|
62
|
+
console.log('GetFee', cvToValue(result));
|
|
63
|
+
return cvToValue(result);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// console.log(e);
|
|
66
|
+
return '0';
|
|
67
|
+
}
|
|
68
|
+
// console.log(pair_details_result)
|
|
69
|
+
}
|
|
70
|
+
async getETHToken(token: string) {
|
|
71
|
+
// console.log('getStakingSTSWBalance');
|
|
72
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getETHToken',
|
|
73
|
+
[parseAddressToCV(token)]);
|
|
74
|
+
try {
|
|
75
|
+
const result = await callReadOnlyFunction(options);
|
|
76
|
+
console.log('getETHToken', cvToValue(result));
|
|
77
|
+
return cvToValue(result);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// console.log(e);
|
|
80
|
+
return '0';
|
|
81
|
+
}
|
|
82
|
+
// console.log(pair_details_result)
|
|
83
|
+
}
|
|
84
|
+
async getOrderIDInfo_From(id: string) {
|
|
85
|
+
// console.log('getStakingSTSWBalance');
|
|
86
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getOrderIDInfo_From',
|
|
87
|
+
[uintCV(id)]);
|
|
88
|
+
try {
|
|
89
|
+
const result = await callReadOnlyFunction(options);
|
|
90
|
+
console.log('getOrderIDInfo_From', cvToValue(result));
|
|
91
|
+
return cvToValue(result);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
// console.log(e);
|
|
94
|
+
return '0';
|
|
95
|
+
}
|
|
96
|
+
// console.log(pair_details_result)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getOrderIDInfo_To(id: string) {
|
|
100
|
+
// console.log('getStakingSTSWBalance');
|
|
101
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getOrderIDInfo_To',
|
|
102
|
+
[uintCV(id)]);
|
|
103
|
+
try {
|
|
104
|
+
const result = await callReadOnlyFunction(options);
|
|
105
|
+
console.log('getOrderIDInfo_To', cvToValue(result));
|
|
106
|
+
return cvToValue(result);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
// console.log(e);
|
|
109
|
+
return '0';
|
|
110
|
+
}
|
|
111
|
+
// console.log(pair_details_result)
|
|
112
|
+
}
|
|
113
|
+
async getOrderInfo_To(token: string, round: string|number) {
|
|
114
|
+
// console.log('getStakingSTSWBalance');
|
|
115
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getOrderInfo_To',
|
|
116
|
+
[parseAddressToCV(token), uintCV(round)]);
|
|
117
|
+
try {
|
|
118
|
+
const result = await callReadOnlyFunction(options);
|
|
119
|
+
console.log('getOrderInfoWallet_From', cvToValue(result));
|
|
120
|
+
return cvToValue(result);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
// console.log(e);
|
|
123
|
+
return '0';
|
|
124
|
+
}
|
|
125
|
+
// console.log(pair_details_result)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async getOrderInfo_From(token: string, round: string|number) {
|
|
129
|
+
// console.log('getStakingSTSWBalance');
|
|
130
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getOrderInfo_From',
|
|
131
|
+
[parseAddressToCV(token), uintCV(round)]);
|
|
132
|
+
try {
|
|
133
|
+
const result = await callReadOnlyFunction(options);
|
|
134
|
+
console.log('getOrderInfoWallet_To', cvToValue(result));
|
|
135
|
+
return cvToValue(result);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
// console.log(e);
|
|
138
|
+
return '0';
|
|
139
|
+
}
|
|
140
|
+
// console.log(pair_details_result)
|
|
141
|
+
}
|
|
142
|
+
async getOrderInfoWallet_From(token: string, round: string|number) {
|
|
143
|
+
// console.log('getStakingSTSWBalance');
|
|
144
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getWithdrawInfo_Wallet',
|
|
145
|
+
[parseAddressToCV(this.stackswap.getSenderAddress()),parseAddressToCV(token), uintCV(round)]);
|
|
146
|
+
try {
|
|
147
|
+
const result = await callReadOnlyFunction(options);
|
|
148
|
+
console.log('getOrderInfoWallet_From', cvToValue(result));
|
|
149
|
+
return cvToValue(result);
|
|
150
|
+
} catch (e) {
|
|
151
|
+
// console.log(e);
|
|
152
|
+
return '0';
|
|
153
|
+
}
|
|
154
|
+
// console.log(pair_details_result)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async getOrderInfoWallet_To(token: string, round: string|number) {
|
|
158
|
+
// console.log('getStakingSTSWBalance');
|
|
159
|
+
const options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'getDepositInfo_Wallet',
|
|
160
|
+
[parseAddressToCV(this.stackswap.getSenderAddress()), parseAddressToCV(token), uintCV(round)]);
|
|
161
|
+
try {
|
|
162
|
+
const result = await callReadOnlyFunction(options);
|
|
163
|
+
console.log('getOrderInfoWallet_To', cvToValue(result));
|
|
164
|
+
return cvToValue(result);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
// console.log(e);
|
|
167
|
+
return '0';
|
|
168
|
+
}
|
|
169
|
+
// console.log(pair_details_result)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async withdrawFixFee(amount: string, callback : any = null){
|
|
173
|
+
|
|
174
|
+
// console.log({amount});
|
|
175
|
+
const post_condition = [
|
|
176
|
+
// await getPostConditionFromAsset(getSenderAddress(source), BASE_STSW_DATA().addr, new BigNumber(amount).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal),
|
|
177
|
+
await getPostConditionFromAsset(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), this.stackswap.config.BASE_WSTX_DATA().addr, new BigNumber(amount).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal)
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'WithdrawFee_FIX', [
|
|
181
|
+
], post_condition, callback);
|
|
182
|
+
await openContractCall(function_option);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async WithdrawFee_RATIO(type: string, token: string, amount: string, callback : any = null){
|
|
186
|
+
let functionName = 'WithdrawFee_RATIO_1';
|
|
187
|
+
switch (type) {
|
|
188
|
+
case 'ratio1' :
|
|
189
|
+
functionName = 'WithdrawFee_RATIO_1';
|
|
190
|
+
break;
|
|
191
|
+
case 'ratio2' :
|
|
192
|
+
functionName = 'WithdrawFee_RATIO_2';
|
|
193
|
+
break;
|
|
194
|
+
case 'ratio3' :
|
|
195
|
+
functionName = 'WithdrawFee_RATIO_3';
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
// console.log({amount});
|
|
199
|
+
const post_condition = [
|
|
200
|
+
await getPostConditionFromAsset(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), this.stackswap.config.BASE_STSW_DATA().addr, new BigNumber(amount).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal),
|
|
201
|
+
// await getPostConditionFromAsset(getSenderAddress(source), BASE_WSTX_DATA().addr, new BigNumber(10).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal)
|
|
202
|
+
];
|
|
203
|
+
|
|
204
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), functionName, [
|
|
205
|
+
parseAddressToCV(token),
|
|
206
|
+
], post_condition, callback);
|
|
207
|
+
await openContractCall(function_option);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async getLockedAmount(token: any = this.stackswap.config.BASE_STSW_DATA()) {
|
|
211
|
+
const amountInWallet = await this.stackswap.tokenManager.getBalanceOf(token, this.stackswap.config.CONTRACT_NAME_BRIDGE());
|
|
212
|
+
const tokenData = await this.getETHToken(token.addr);
|
|
213
|
+
const bnAmount = new BigNumber(amountInWallet)
|
|
214
|
+
.minus(tokenData.FEE_RATIO_1_AMT.value)
|
|
215
|
+
.minus(tokenData.FEE_RATIO_2_AMT.value)
|
|
216
|
+
.minus(tokenData.FEE_RATIO_3_AMT.value)
|
|
217
|
+
return {
|
|
218
|
+
amountDecimal : bnAmount.dividedBy(10**token.decimal).toFixed(token.decimal),
|
|
219
|
+
amount : bnAmount.toFixed(0),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async vote(vote: boolean, callback : any = null){
|
|
224
|
+
|
|
225
|
+
// console.log({amount});
|
|
226
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'vote', [
|
|
227
|
+
vote? trueCV() : falseCV()
|
|
228
|
+
], [], callback);
|
|
229
|
+
await openContractCall(function_option);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async depositSTSW_SIP10_to_ERC20(addr: string, amount: string, fee: string, callback : any = null){
|
|
233
|
+
|
|
234
|
+
// console.log({amount});
|
|
235
|
+
const post_condition = [
|
|
236
|
+
await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_STSW_DATA().addr, new BigNumber(amount).plus(fee).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal),
|
|
237
|
+
await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), this.stackswap.config.BASE_WSTX_DATA().addr, new BigNumber(10).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal)
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'DepositForETH', [
|
|
241
|
+
stringAsciiCV(addr),
|
|
242
|
+
parseAddressToCV(this.stackswap.config.BASE_STSW_DATA().addr),
|
|
243
|
+
uintCV(new BigNumber(amount).multipliedBy(10**6).toFixed(0)),
|
|
244
|
+
uintCV(new BigNumber(fee).multipliedBy(10**6).toFixed(0)),
|
|
245
|
+
], post_condition, callback);
|
|
246
|
+
await openContractCall(function_option);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async cancel_depositSTSW_SIP10_to_ERC20(orderID: string, amount: string, callback : any = null){
|
|
250
|
+
|
|
251
|
+
// console.log({amount});
|
|
252
|
+
const post_condition = [
|
|
253
|
+
await getPostConditionFromAsset(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), this.stackswap.config.BASE_STSW_DATA().addr, new BigNumber(amount).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal),
|
|
254
|
+
// await getPostConditionFromAsset(getSenderAddress(source), BASE_WSTX_DATA().addr, new BigNumber(10).multipliedBy(10**6).toFixed(0), FungibleConditionCode.Equal)
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'Cancel_DepositForETH', [
|
|
258
|
+
uintCV(orderID)
|
|
259
|
+
], post_condition, callback);
|
|
260
|
+
await openContractCall(function_option);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async registerTokenPair(sip10Addr:string, ercAddr: string, min: string, max: string, callback : any = null){
|
|
264
|
+
|
|
265
|
+
// console.log({amount});
|
|
266
|
+
const post_condition: any = [
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'RegisterTokenPair', [
|
|
270
|
+
parseAddressToCV(sip10Addr),
|
|
271
|
+
stringAsciiCV(ercAddr),
|
|
272
|
+
uintCV(new BigNumber(min).multipliedBy(10**6).toFixed(0)),
|
|
273
|
+
uintCV(new BigNumber(max).multipliedBy(10**6).toFixed(0)),
|
|
274
|
+
], post_condition, callback);
|
|
275
|
+
await openContractCall(function_option);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async update_depositSTSW_SIP10_to_ERC20(round: string, orders: string[], callback : any = null){
|
|
279
|
+
|
|
280
|
+
// console.log({amount});
|
|
281
|
+
const tempList = [];
|
|
282
|
+
for (const order of orders) {
|
|
283
|
+
tempList.push(uintCV(order));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const function_option : any = getWriteOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_BRIDGE(), 'DepositForETH', [
|
|
287
|
+
parseAddressToCV(this.stackswap.config.BASE_STSW_DATA().addr),
|
|
288
|
+
uintCV(round),
|
|
289
|
+
listCV(tempList),
|
|
290
|
+
], [], callback);
|
|
291
|
+
await openContractCall(function_option);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
}
|
|
@@ -96,9 +96,9 @@ export class StakingManager {
|
|
|
96
96
|
// console.log('reward', round, cvToValue(result));
|
|
97
97
|
const res = cvToValue(result).value;
|
|
98
98
|
// console.log('getRoundData', res);
|
|
99
|
-
return {amount: res.amountSTSW.value, value: res.amountvSTSW.value};
|
|
99
|
+
return {amount: res.amountSTSW.value, value: res.amountvSTSW.value, rewardBase: res.amountRewardBase.value};
|
|
100
100
|
} catch (e) {
|
|
101
|
-
return {amount: '0', value: '0'};
|
|
101
|
+
return {amount: '0', value: '0', rewardBase: '0'};
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
async getRoundDataDefault(round: number) {
|