stackswap-front-api-test-02 1.0.89 → 1.0.90
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 +10 -10
- package/dist/esm/index.d.ts +84 -84
- package/dist/esm/index.js +143 -143
- package/dist/esm/stackswap/config.d.ts +114 -112
- package/dist/esm/stackswap/config.js +188 -185
- package/dist/esm/stackswap/config.js.map +1 -1
- package/dist/esm/stackswap/manager/farm.manager.d.ts +41 -41
- package/dist/esm/stackswap/manager/farm.manager.js +293 -293
- package/dist/esm/stackswap/manager/farm2.manager.d.ts +60 -60
- package/dist/esm/stackswap/manager/farm2.manager.js +403 -403
- package/dist/esm/stackswap/manager/governance.manager.d.ts +9 -9
- package/dist/esm/stackswap/manager/governance.manager.js +53 -53
- package/dist/esm/stackswap/manager/launchpad.manager.d.ts +13 -13
- package/dist/esm/stackswap/manager/launchpad.manager.js +147 -147
- package/dist/esm/stackswap/manager/lbtc.manager.d.ts +31 -31
- package/dist/esm/stackswap/manager/lbtc.manager.js +326 -326
- package/dist/esm/stackswap/manager/lbtcstaking.manager.d.ts +26 -0
- package/dist/esm/stackswap/manager/lbtcstaking.manager.js +153 -0
- package/dist/esm/stackswap/manager/lbtcstaking.manager.js.map +1 -0
- package/dist/esm/stackswap/manager/multisig.manager.d.ts +11 -11
- package/dist/esm/stackswap/manager/multisig.manager.js +51 -51
- package/dist/esm/stackswap/manager/nft.manager.d.ts +52 -52
- package/dist/esm/stackswap/manager/nft.manager.js +243 -243
- package/dist/esm/stackswap/manager/nft.manager.js.map +1 -1
- package/dist/esm/stackswap/manager/operator.manager.d.ts +17 -17
- package/dist/esm/stackswap/manager/operator.manager.js +85 -85
- package/dist/esm/stackswap/manager/other.manager.d.ts +9 -9
- package/dist/esm/stackswap/manager/other.manager.js +47 -47
- package/dist/esm/stackswap/manager/pool.manager.d.ts +34 -34
- package/dist/esm/stackswap/manager/pool.manager.js +171 -171
- package/dist/esm/stackswap/manager/poxl.manager.d.ts +16 -16
- package/dist/esm/stackswap/manager/poxl.manager.js +71 -71
- package/dist/esm/stackswap/manager/staking.manager.d.ts +25 -25
- package/dist/esm/stackswap/manager/staking.manager.js +233 -233
- package/dist/esm/stackswap/manager/staking.manager.js.map +1 -1
- package/dist/esm/stackswap/manager/swap.manager.d.ts +39 -39
- package/dist/esm/stackswap/manager/swap.manager.js +332 -332
- package/dist/esm/stackswap/manager/token.manager.d.ts +31 -31
- package/dist/esm/stackswap/manager/token.manager.js +133 -133
- package/dist/esm/stackswap/util.d.ts +35 -35
- package/dist/esm/stackswap/util.js +201 -201
- package/dist/index.d.ts +84 -84
- package/dist/index.js +152 -152
- package/dist/index.umd.js +1 -1
- package/dist/stackswap/config.d.ts +114 -112
- package/dist/stackswap/config.js +193 -190
- package/dist/stackswap/config.js.map +1 -1
- package/dist/stackswap/manager/farm.manager.d.ts +41 -41
- package/dist/stackswap/manager/farm.manager.js +301 -301
- package/dist/stackswap/manager/farm2.manager.d.ts +60 -60
- package/dist/stackswap/manager/farm2.manager.js +410 -410
- package/dist/stackswap/manager/governance.manager.d.ts +9 -9
- package/dist/stackswap/manager/governance.manager.js +60 -60
- package/dist/stackswap/manager/launchpad.manager.d.ts +13 -13
- package/dist/stackswap/manager/launchpad.manager.js +151 -151
- package/dist/stackswap/manager/lbtc.manager.d.ts +31 -31
- package/dist/stackswap/manager/lbtc.manager.js +333 -333
- package/dist/stackswap/manager/lbtcstaking.manager.d.ts +26 -0
- package/dist/stackswap/manager/lbtcstaking.manager.js +160 -0
- package/dist/stackswap/manager/lbtcstaking.manager.js.map +1 -0
- package/dist/stackswap/manager/multisig.manager.d.ts +11 -11
- package/dist/stackswap/manager/multisig.manager.js +55 -55
- package/dist/stackswap/manager/nft.manager.d.ts +52 -52
- package/dist/stackswap/manager/nft.manager.js +250 -250
- package/dist/stackswap/manager/nft.manager.js.map +1 -1
- package/dist/stackswap/manager/operator.manager.d.ts +17 -17
- package/dist/stackswap/manager/operator.manager.js +92 -92
- package/dist/stackswap/manager/other.manager.d.ts +9 -9
- package/dist/stackswap/manager/other.manager.js +54 -54
- package/dist/stackswap/manager/pool.manager.d.ts +34 -34
- package/dist/stackswap/manager/pool.manager.js +179 -179
- package/dist/stackswap/manager/poxl.manager.d.ts +16 -16
- package/dist/stackswap/manager/poxl.manager.js +78 -78
- package/dist/stackswap/manager/staking.manager.d.ts +25 -25
- package/dist/stackswap/manager/staking.manager.js +240 -240
- package/dist/stackswap/manager/staking.manager.js.map +1 -1
- package/dist/stackswap/manager/swap.manager.d.ts +39 -39
- package/dist/stackswap/manager/swap.manager.js +339 -339
- package/dist/stackswap/manager/token.manager.d.ts +31 -31
- package/dist/stackswap/manager/token.manager.js +141 -141
- package/dist/stackswap/util.d.ts +35 -35
- package/dist/stackswap/util.js +218 -218
- package/package.json +43 -43
- package/src/index.ts +204 -204
- package/src/stackswap/config.ts +297 -292
- package/src/stackswap/manager/farm.manager.ts +399 -399
- package/src/stackswap/manager/farm2.manager.ts +463 -463
- package/src/stackswap/manager/governance.manager.ts +95 -95
- package/src/stackswap/manager/launchpad.manager.ts +190 -190
- package/src/stackswap/manager/lbtcstaking.manager.ts +219 -0
- package/src/stackswap/manager/multisig.manager.ts +87 -87
- package/src/stackswap/manager/nft.manager.ts +307 -311
- package/src/stackswap/manager/operator.manager.ts +123 -123
- package/src/stackswap/manager/other.manager.ts +71 -71
- package/src/stackswap/manager/pool.manager.ts +202 -202
- package/src/stackswap/manager/poxl.manager.ts +99 -99
- package/src/stackswap/manager/staking.manager.ts +321 -321
- package/src/stackswap/manager/swap.manager.ts +392 -392
- package/src/stackswap/manager/token.manager.ts +167 -167
- package/src/stackswap/util.ts +237 -237
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
import {callReadOnlyFunction, cvToValue} from "@stacks/transactions";
|
|
2
|
-
import BigNumber from "bignumber.js";
|
|
3
|
-
import axios from "axios";
|
|
4
|
-
import {StackswapAPI} from "../../index";
|
|
5
|
-
import {decimal2integer, getPriceAndDY, getReadOptions, parseAddressToCV} from "../util";
|
|
6
|
-
import {Token} from "./token.manager";
|
|
7
|
-
|
|
8
|
-
export class LiquidityPool {
|
|
9
|
-
name: string;
|
|
10
|
-
token_x: Token;
|
|
11
|
-
token_y: Token;
|
|
12
|
-
token_lp: Token;
|
|
13
|
-
loaded: boolean = false;
|
|
14
|
-
balance_x: string = '0';
|
|
15
|
-
balance_y: string = '0';
|
|
16
|
-
share_total: string = '0';
|
|
17
|
-
|
|
18
|
-
constructor(name: string, token_x: Token, token_y: Token, token_lp: Token, balance_x: string = '0', balance_y: string= '0', share_total:string ='0') {
|
|
19
|
-
this.name = name;
|
|
20
|
-
this.token_x = token_x;
|
|
21
|
-
this.token_y = token_y;
|
|
22
|
-
this.token_lp = token_lp;
|
|
23
|
-
this.balance_x = balance_x;
|
|
24
|
-
this.balance_y = balance_y;
|
|
25
|
-
this.share_total = share_total
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getTokenX(direction: boolean = true){
|
|
29
|
-
return direction ? this.token_x : this.token_y;
|
|
30
|
-
}
|
|
31
|
-
getTokenY(direction: boolean = true){
|
|
32
|
-
return direction ? this.token_y : this.token_x;
|
|
33
|
-
}
|
|
34
|
-
toString() : string {
|
|
35
|
-
return '' + {name : this.name, token_x : this.token_x.toString(), token_y : this.token_y.toString(), token_lp: this.token_lp.toString(), balance_x : this.balance_x, balance_y : this.balance_y, share_total: this.share_total, loaded: this.loaded}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static parsePoolFromJson(data: any) : LiquidityPool{
|
|
39
|
-
if ( data.share_total != null ){
|
|
40
|
-
return new LiquidityPool(data.name, Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), Token.parseTokenFromJson(data.token_lp), data.balance_x, data.balance_y, data.share_total);
|
|
41
|
-
} else {
|
|
42
|
-
return new LiquidityPool(data.name, Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), new Token(data.name, 6, '', data.token_swapr, data.name));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static parsePoolsFromJsonList(datas: any) : LiquidityPool[]{
|
|
47
|
-
const temp_list = [];
|
|
48
|
-
for (const data of datas) {
|
|
49
|
-
temp_list.push(LiquidityPool.parsePoolFromJson(data));
|
|
50
|
-
}
|
|
51
|
-
return temp_list;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static parsePoolsFromServerData(pair: any, token_x : Token, token_y: Token, direction : boolean = true) : LiquidityPool{
|
|
55
|
-
if( direction){
|
|
56
|
-
const temp = new LiquidityPool(pair.name.value, token_x, token_y, new Token(pair.name.value, 6, '', pair['liquidity-token'].value, pair.name.value),pair['balance-x'].value, pair['balance-y'].value, pair['shares-total'].value);
|
|
57
|
-
temp.loaded = true;
|
|
58
|
-
return temp;
|
|
59
|
-
} else {
|
|
60
|
-
const temp = new LiquidityPool(pair.name.value, token_y, token_x, new Token(pair.name.value, 6, '', pair['liquidity-token'].value, pair.name.value),pair['balance-x'].value, pair['balance-y'].value, pair['shares-total'].value)
|
|
61
|
-
temp.loaded = true;
|
|
62
|
-
return temp;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static parsePoolsFromServerData2(pair: any, token_x : Token, token_y: Token, direction : boolean = true) : LiquidityPool{
|
|
67
|
-
if( direction){
|
|
68
|
-
const temp = new LiquidityPool(pair.name, token_x, token_y, new Token(pair.name, 6, '', pair['liquidity-token'], pair.name),pair['balance-x'], pair['balance-y'], pair['shares-total']);
|
|
69
|
-
temp.loaded = true;
|
|
70
|
-
return temp;
|
|
71
|
-
} else {
|
|
72
|
-
const temp = new LiquidityPool(pair.name, token_y, token_x, new Token(pair.name, 6, '', pair['liquidity-token'], pair.name),pair['balance-x'], pair['balance-y'], pair['shares-total'])
|
|
73
|
-
temp.loaded = true;
|
|
74
|
-
return temp;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static parsePoolsFromDBData(data: any) : LiquidityPool{
|
|
79
|
-
const temp = new LiquidityPool(data.pair_name,
|
|
80
|
-
Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), new Token(data.pair_name, 6, '', data.pair_addr, data.pair_name), decimal2integer(data.balance_token_x, data.token_x.decimal), decimal2integer(data.balance_token_y, data.token_y.decimal), data.total_lp_amt);
|
|
81
|
-
temp.loaded = true;
|
|
82
|
-
return temp;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
getPoolPrice(inverted: boolean = false, amount: string = '-1') : {dy: string, output_price: string}{
|
|
87
|
-
if(this.share_total === '0'){
|
|
88
|
-
return {dy: '0', output_price: '0'};
|
|
89
|
-
}
|
|
90
|
-
if (inverted) {
|
|
91
|
-
return getPriceAndDY(this, amount, false);
|
|
92
|
-
} else {
|
|
93
|
-
return getPriceAndDY(this, amount, true);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getPoolTVL(stackswap: StackswapAPI, pool: LiquidityPool, stx_usd:number, stsw_usd:number, btc_usd:number) : number{
|
|
98
|
-
|
|
99
|
-
const x_token_addr = pool.token_x.addr;
|
|
100
|
-
const y_token_addr = pool.token_y.addr;
|
|
101
|
-
|
|
102
|
-
let total_balance = new BigNumber(-1);
|
|
103
|
-
let total_price = -1;
|
|
104
|
-
if(x_token_addr === stackswap.config.BASE_WSTX_DATA().addr){
|
|
105
|
-
total_balance = (new BigNumber(pool.balance_x).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
106
|
-
total_price = total_balance.multipliedBy(stx_usd).toNumber();
|
|
107
|
-
}else if(y_token_addr === stackswap.config.BASE_WSTX_DATA().addr){
|
|
108
|
-
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
109
|
-
total_price = total_balance.multipliedBy(stx_usd).toNumber();
|
|
110
|
-
}else if(x_token_addr === stackswap.config.BASE_STSW_DATA().addr){
|
|
111
|
-
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
112
|
-
total_price = total_balance.multipliedBy(stsw_usd).toNumber();
|
|
113
|
-
}else if(y_token_addr === stackswap.config.BASE_STSW_DATA().addr){
|
|
114
|
-
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
115
|
-
total_price = total_balance.multipliedBy(stsw_usd).toNumber();
|
|
116
|
-
}else if(x_token_addr === stackswap.config.BASE_LBTC_DATA().addr){
|
|
117
|
-
total_balance = (new BigNumber(pool.balance_x).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
118
|
-
total_price = total_balance.multipliedBy(btc_usd).toNumber();
|
|
119
|
-
}else if(y_token_addr === stackswap.config.BASE_LBTC_DATA().addr){
|
|
120
|
-
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
121
|
-
total_price = total_balance.multipliedBy(btc_usd).toNumber();
|
|
122
|
-
}
|
|
123
|
-
return total_price;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
getNewPoolShareRatio(token_amount: any, inversed: boolean) : number {
|
|
127
|
-
if (this.loaded) {
|
|
128
|
-
try {
|
|
129
|
-
const token_input = new BigNumber(token_amount);
|
|
130
|
-
const token_in_pool = new BigNumber(inversed ? this.balance_x : this.balance_y);
|
|
131
|
-
const token_in_pool_new = token_input.plus(token_in_pool);
|
|
132
|
-
const temp = (token_input.dividedBy(token_in_pool_new).multipliedBy(100)).toNumber();
|
|
133
|
-
// console.log(temp, isNaN(temp));
|
|
134
|
-
|
|
135
|
-
if ( ! isNaN(temp) ) {
|
|
136
|
-
return temp;
|
|
137
|
-
} else {
|
|
138
|
-
return 0;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
} catch (e) {
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
return 0;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
export class PoolManager {
|
|
152
|
-
stackswap: StackswapAPI;
|
|
153
|
-
|
|
154
|
-
constructor(stackswap: StackswapAPI) {
|
|
155
|
-
this.stackswap = stackswap;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async getPoolLists() : Promise<LiquidityPool[]>{
|
|
159
|
-
const url1 = this.stackswap.config.STACKS_BACKEND_URL() + '/stacks/pair/' + this.stackswap.config.STACKS_BACKEND_PARAM();
|
|
160
|
-
const res1 = await axios.get ( url1, {
|
|
161
|
-
timeout: 30000, // 해당시간안에 응답이 오지않는다면 에러처리된다.
|
|
162
|
-
});
|
|
163
|
-
return LiquidityPool.parsePoolsFromJsonList(res1.data);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async getPairDataFromContract( token_x: Token, token_y: Token ) : Promise<LiquidityPool | null> {
|
|
167
|
-
const pair_details_options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), 'get-pair-details',
|
|
168
|
-
[ parseAddressToCV(token_x.addr), parseAddressToCV(token_y.addr) ]);
|
|
169
|
-
try {
|
|
170
|
-
const result = await callReadOnlyFunction(pair_details_options);
|
|
171
|
-
// @ts-ignore
|
|
172
|
-
// console.log(result);
|
|
173
|
-
// console.log(cvToValue(result));
|
|
174
|
-
const result2 = await callReadOnlyFunction(getReadOptions(this.stackswap, cvToValue(result)['liquidity-token'].value, 'get-lp-data', []));
|
|
175
|
-
// console.log('cv-to-value',cvToValue(result2)['value']);
|
|
176
|
-
// console.log(cvToValue(result2).value);
|
|
177
|
-
return LiquidityPool.parsePoolsFromServerData(cvToValue(result2).value, token_x, token_y, true);
|
|
178
|
-
} catch (e) {
|
|
179
|
-
// console.log(e);
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
// console.log(pair_details_result)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async getPoolDatasLegacy( token_x: Token, token_y: Token, swap_contract: string) : Promise<LiquidityPool | null> {
|
|
186
|
-
const pair_details_options : any = getReadOptions(this.stackswap, swap_contract, 'get-pair-details',
|
|
187
|
-
[ parseAddressToCV(token_x.addr), parseAddressToCV(token_y.addr) ]);
|
|
188
|
-
try {
|
|
189
|
-
const result = await callReadOnlyFunction(pair_details_options);
|
|
190
|
-
// @ts-ignore
|
|
191
|
-
const result2 = await callReadOnlyFunction(getReadOptions(this.stackswap, cvToValue(result)['liquidity-token'].value, 'get-lp-data', []));
|
|
192
|
-
// console.log('cv-to-value',cvToValue(result2)['value']);
|
|
193
|
-
// console.log(cvToValue(result2).value);
|
|
194
|
-
return LiquidityPool.parsePoolsFromServerData(cvToValue(result2).value, token_x, token_y, true);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
// console.log(e);
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
// console.log(pair_details_result)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}
|
|
1
|
+
import {callReadOnlyFunction, cvToValue} from "@stacks/transactions";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import {StackswapAPI} from "../../index";
|
|
5
|
+
import {decimal2integer, getPriceAndDY, getReadOptions, parseAddressToCV} from "../util";
|
|
6
|
+
import {Token} from "./token.manager";
|
|
7
|
+
|
|
8
|
+
export class LiquidityPool {
|
|
9
|
+
name: string;
|
|
10
|
+
token_x: Token;
|
|
11
|
+
token_y: Token;
|
|
12
|
+
token_lp: Token;
|
|
13
|
+
loaded: boolean = false;
|
|
14
|
+
balance_x: string = '0';
|
|
15
|
+
balance_y: string = '0';
|
|
16
|
+
share_total: string = '0';
|
|
17
|
+
|
|
18
|
+
constructor(name: string, token_x: Token, token_y: Token, token_lp: Token, balance_x: string = '0', balance_y: string= '0', share_total:string ='0') {
|
|
19
|
+
this.name = name;
|
|
20
|
+
this.token_x = token_x;
|
|
21
|
+
this.token_y = token_y;
|
|
22
|
+
this.token_lp = token_lp;
|
|
23
|
+
this.balance_x = balance_x;
|
|
24
|
+
this.balance_y = balance_y;
|
|
25
|
+
this.share_total = share_total
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getTokenX(direction: boolean = true){
|
|
29
|
+
return direction ? this.token_x : this.token_y;
|
|
30
|
+
}
|
|
31
|
+
getTokenY(direction: boolean = true){
|
|
32
|
+
return direction ? this.token_y : this.token_x;
|
|
33
|
+
}
|
|
34
|
+
toString() : string {
|
|
35
|
+
return '' + {name : this.name, token_x : this.token_x.toString(), token_y : this.token_y.toString(), token_lp: this.token_lp.toString(), balance_x : this.balance_x, balance_y : this.balance_y, share_total: this.share_total, loaded: this.loaded}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static parsePoolFromJson(data: any) : LiquidityPool{
|
|
39
|
+
if ( data.share_total != null ){
|
|
40
|
+
return new LiquidityPool(data.name, Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), Token.parseTokenFromJson(data.token_lp), data.balance_x, data.balance_y, data.share_total);
|
|
41
|
+
} else {
|
|
42
|
+
return new LiquidityPool(data.name, Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), new Token(data.name, 6, '', data.token_swapr, data.name));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static parsePoolsFromJsonList(datas: any) : LiquidityPool[]{
|
|
47
|
+
const temp_list = [];
|
|
48
|
+
for (const data of datas) {
|
|
49
|
+
temp_list.push(LiquidityPool.parsePoolFromJson(data));
|
|
50
|
+
}
|
|
51
|
+
return temp_list;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static parsePoolsFromServerData(pair: any, token_x : Token, token_y: Token, direction : boolean = true) : LiquidityPool{
|
|
55
|
+
if( direction){
|
|
56
|
+
const temp = new LiquidityPool(pair.name.value, token_x, token_y, new Token(pair.name.value, 6, '', pair['liquidity-token'].value, pair.name.value),pair['balance-x'].value, pair['balance-y'].value, pair['shares-total'].value);
|
|
57
|
+
temp.loaded = true;
|
|
58
|
+
return temp;
|
|
59
|
+
} else {
|
|
60
|
+
const temp = new LiquidityPool(pair.name.value, token_y, token_x, new Token(pair.name.value, 6, '', pair['liquidity-token'].value, pair.name.value),pair['balance-x'].value, pair['balance-y'].value, pair['shares-total'].value)
|
|
61
|
+
temp.loaded = true;
|
|
62
|
+
return temp;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static parsePoolsFromServerData2(pair: any, token_x : Token, token_y: Token, direction : boolean = true) : LiquidityPool{
|
|
67
|
+
if( direction){
|
|
68
|
+
const temp = new LiquidityPool(pair.name, token_x, token_y, new Token(pair.name, 6, '', pair['liquidity-token'], pair.name),pair['balance-x'], pair['balance-y'], pair['shares-total']);
|
|
69
|
+
temp.loaded = true;
|
|
70
|
+
return temp;
|
|
71
|
+
} else {
|
|
72
|
+
const temp = new LiquidityPool(pair.name, token_y, token_x, new Token(pair.name, 6, '', pair['liquidity-token'], pair.name),pair['balance-x'], pair['balance-y'], pair['shares-total'])
|
|
73
|
+
temp.loaded = true;
|
|
74
|
+
return temp;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static parsePoolsFromDBData(data: any) : LiquidityPool{
|
|
79
|
+
const temp = new LiquidityPool(data.pair_name,
|
|
80
|
+
Token.parseTokenFromJson(data.token_x), Token.parseTokenFromJson(data.token_y), new Token(data.pair_name, 6, '', data.pair_addr, data.pair_name), decimal2integer(data.balance_token_x, data.token_x.decimal), decimal2integer(data.balance_token_y, data.token_y.decimal), data.total_lp_amt);
|
|
81
|
+
temp.loaded = true;
|
|
82
|
+
return temp;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
getPoolPrice(inverted: boolean = false, amount: string = '-1') : {dy: string, output_price: string}{
|
|
87
|
+
if(this.share_total === '0'){
|
|
88
|
+
return {dy: '0', output_price: '0'};
|
|
89
|
+
}
|
|
90
|
+
if (inverted) {
|
|
91
|
+
return getPriceAndDY(this, amount, false);
|
|
92
|
+
} else {
|
|
93
|
+
return getPriceAndDY(this, amount, true);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getPoolTVL(stackswap: StackswapAPI, pool: LiquidityPool, stx_usd:number, stsw_usd:number, btc_usd:number) : number{
|
|
98
|
+
|
|
99
|
+
const x_token_addr = pool.token_x.addr;
|
|
100
|
+
const y_token_addr = pool.token_y.addr;
|
|
101
|
+
|
|
102
|
+
let total_balance = new BigNumber(-1);
|
|
103
|
+
let total_price = -1;
|
|
104
|
+
if(x_token_addr === stackswap.config.BASE_WSTX_DATA().addr){
|
|
105
|
+
total_balance = (new BigNumber(pool.balance_x).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
106
|
+
total_price = total_balance.multipliedBy(stx_usd).toNumber();
|
|
107
|
+
}else if(y_token_addr === stackswap.config.BASE_WSTX_DATA().addr){
|
|
108
|
+
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
109
|
+
total_price = total_balance.multipliedBy(stx_usd).toNumber();
|
|
110
|
+
}else if(x_token_addr === stackswap.config.BASE_STSW_DATA().addr){
|
|
111
|
+
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
112
|
+
total_price = total_balance.multipliedBy(stsw_usd).toNumber();
|
|
113
|
+
}else if(y_token_addr === stackswap.config.BASE_STSW_DATA().addr){
|
|
114
|
+
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
115
|
+
total_price = total_balance.multipliedBy(stsw_usd).toNumber();
|
|
116
|
+
}else if(x_token_addr === stackswap.config.BASE_LBTC_DATA().addr){
|
|
117
|
+
total_balance = (new BigNumber(pool.balance_x).dividedBy(new BigNumber(10 ** pool.token_x.decimal))).multipliedBy(2);
|
|
118
|
+
total_price = total_balance.multipliedBy(btc_usd).toNumber();
|
|
119
|
+
}else if(y_token_addr === stackswap.config.BASE_LBTC_DATA().addr){
|
|
120
|
+
total_balance = (new BigNumber(pool.balance_y).dividedBy(new BigNumber(10 ** pool.token_y.decimal))).multipliedBy(2);
|
|
121
|
+
total_price = total_balance.multipliedBy(btc_usd).toNumber();
|
|
122
|
+
}
|
|
123
|
+
return total_price;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getNewPoolShareRatio(token_amount: any, inversed: boolean) : number {
|
|
127
|
+
if (this.loaded) {
|
|
128
|
+
try {
|
|
129
|
+
const token_input = new BigNumber(token_amount);
|
|
130
|
+
const token_in_pool = new BigNumber(inversed ? this.balance_x : this.balance_y);
|
|
131
|
+
const token_in_pool_new = token_input.plus(token_in_pool);
|
|
132
|
+
const temp = (token_input.dividedBy(token_in_pool_new).multipliedBy(100)).toNumber();
|
|
133
|
+
// console.log(temp, isNaN(temp));
|
|
134
|
+
|
|
135
|
+
if ( ! isNaN(temp) ) {
|
|
136
|
+
return temp;
|
|
137
|
+
} else {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
export class PoolManager {
|
|
152
|
+
stackswap: StackswapAPI;
|
|
153
|
+
|
|
154
|
+
constructor(stackswap: StackswapAPI) {
|
|
155
|
+
this.stackswap = stackswap;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async getPoolLists() : Promise<LiquidityPool[]>{
|
|
159
|
+
const url1 = this.stackswap.config.STACKS_BACKEND_URL() + '/stacks/pair/' + this.stackswap.config.STACKS_BACKEND_PARAM();
|
|
160
|
+
const res1 = await axios.get ( url1, {
|
|
161
|
+
timeout: 30000, // 해당시간안에 응답이 오지않는다면 에러처리된다.
|
|
162
|
+
});
|
|
163
|
+
return LiquidityPool.parsePoolsFromJsonList(res1.data);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async getPairDataFromContract( token_x: Token, token_y: Token ) : Promise<LiquidityPool | null> {
|
|
167
|
+
const pair_details_options : any = getReadOptions(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), 'get-pair-details',
|
|
168
|
+
[ parseAddressToCV(token_x.addr), parseAddressToCV(token_y.addr) ]);
|
|
169
|
+
try {
|
|
170
|
+
const result = await callReadOnlyFunction(pair_details_options);
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
// console.log(result);
|
|
173
|
+
// console.log(cvToValue(result));
|
|
174
|
+
const result2 = await callReadOnlyFunction(getReadOptions(this.stackswap, cvToValue(result)['liquidity-token'].value, 'get-lp-data', []));
|
|
175
|
+
// console.log('cv-to-value',cvToValue(result2)['value']);
|
|
176
|
+
// console.log(cvToValue(result2).value);
|
|
177
|
+
return LiquidityPool.parsePoolsFromServerData(cvToValue(result2).value, token_x, token_y, true);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
// console.log(e);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
// console.log(pair_details_result)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async getPoolDatasLegacy( token_x: Token, token_y: Token, swap_contract: string) : Promise<LiquidityPool | null> {
|
|
186
|
+
const pair_details_options : any = getReadOptions(this.stackswap, swap_contract, 'get-pair-details',
|
|
187
|
+
[ parseAddressToCV(token_x.addr), parseAddressToCV(token_y.addr) ]);
|
|
188
|
+
try {
|
|
189
|
+
const result = await callReadOnlyFunction(pair_details_options);
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
const result2 = await callReadOnlyFunction(getReadOptions(this.stackswap, cvToValue(result)['liquidity-token'].value, 'get-lp-data', []));
|
|
192
|
+
// console.log('cv-to-value',cvToValue(result2)['value']);
|
|
193
|
+
// console.log(cvToValue(result2).value);
|
|
194
|
+
return LiquidityPool.parsePoolsFromServerData(cvToValue(result2).value, token_x, token_y, true);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
// console.log(e);
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
// console.log(pair_details_result)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import {openContractCall} from "@stacks/connect";
|
|
3
|
-
import {decimal2integer, getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
4
|
-
import {
|
|
5
|
-
callReadOnlyFunction,
|
|
6
|
-
cvToValue,
|
|
7
|
-
FungibleConditionCode,
|
|
8
|
-
noneCV,
|
|
9
|
-
standardPrincipalCV,
|
|
10
|
-
uintCV
|
|
11
|
-
} from "@stacks/transactions";
|
|
12
|
-
import {StackswapAPI} from "../../index";
|
|
13
|
-
import {BaseToken, Token} from "./token.manager";
|
|
14
|
-
|
|
15
|
-
export class PoxlManager {
|
|
16
|
-
stackswap: StackswapAPI;
|
|
17
|
-
|
|
18
|
-
constructor(stackswap: StackswapAPI) {
|
|
19
|
-
this.stackswap = stackswap;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async minePOXLToken(token : Token, mine_amount: string, callback : any = null) {
|
|
23
|
-
const post_condition = [];
|
|
24
|
-
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), Token.getBaseTokens(this.stackswap, BaseToken.STX).addr, decimal2integer(mine_amount,6), FungibleConditionCode.Equal));
|
|
25
|
-
const options = getWriteOptions(this.stackswap, token.addr, 'mine-tokens', [
|
|
26
|
-
uintCV(decimal2integer(mine_amount,6)), noneCV() ], post_condition, callback);
|
|
27
|
-
await openContractCall(options);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async stackPOXLToken(token : Token, stack_amount: string, stack_lock_period : string, callback : any = null) {
|
|
31
|
-
const post_condition = [];
|
|
32
|
-
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), token.addr, decimal2integer(stack_amount, token.decimal), FungibleConditionCode.Equal));
|
|
33
|
-
const options = getWriteOptions(this.stackswap, token.addr, 'stack-tokens', [ uintCV(stack_amount), uintCV(stack_lock_period) ], post_condition, callback);
|
|
34
|
-
await openContractCall(options);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async claimMiningReward(token : Token, mined_blocknum: string, callback : any = null) {
|
|
38
|
-
const options = getWriteOptions(this.stackswap, token.addr, 'claim-token-reward', [
|
|
39
|
-
uintCV(mined_blocknum)],[], callback);
|
|
40
|
-
await openContractCall(options);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async claimStackingReward(token : Token, target_reward_cycle: string, callback : any = null) {
|
|
44
|
-
const options = getWriteOptions(this.stackswap, token.addr, 'claim-stacking-reward', [
|
|
45
|
-
uintCV(target_reward_cycle)], [], callback, true);
|
|
46
|
-
await openContractCall(options);
|
|
47
|
-
}
|
|
48
|
-
async getRandomInt( contract_address: string, input: number) {
|
|
49
|
-
await callReadOnlyFunction( getReadOptions(this.stackswap, contract_address, 'get-random-uint-at-block', [uintCV(input)]));
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
// console.log(result['value'].value.toString());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async getMinedBlock( contract_address: string, offset: number) {
|
|
55
|
-
const get_result = await axios.get( this.stackswap.config.STACKS_API_URL() + '/extended/v1/address/' + this.stackswap.getSenderAddress() + '/transactions', {
|
|
56
|
-
params: {
|
|
57
|
-
limit: 40,
|
|
58
|
-
offset,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
const total = get_result.data.total;
|
|
62
|
-
const results = get_result.data.results;
|
|
63
|
-
const mined_block: number[] = [];
|
|
64
|
-
// console.log(results);
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
for (const item of results) {
|
|
67
|
-
// console.log(item);
|
|
68
|
-
try {
|
|
69
|
-
if (contract_address === item.contract_call.contract_id && item.contract_call.function_name === 'mine-tokens') {
|
|
70
|
-
const temp = await this.canClaimCall(contract_address, item.block_height);
|
|
71
|
-
// console.log(temp);
|
|
72
|
-
if (temp) {
|
|
73
|
-
mined_block.push(item.block_height);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} catch (e) {
|
|
77
|
-
// console.log(e);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// console.log(mined_block);
|
|
81
|
-
return {total, mined_block};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27.miamicoin-core-v1
|
|
85
|
-
async canClaimCall( contract_address: string, block: number) {
|
|
86
|
-
// const poxl_token = contract_address.split('.');
|
|
87
|
-
const options = getReadOptions(this.stackswap, contract_address, 'can-claim-mining-reward', [
|
|
88
|
-
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
89
|
-
uintCV(block),
|
|
90
|
-
]);
|
|
91
|
-
const result = await callReadOnlyFunction(options);
|
|
92
|
-
// console.log(cvToValue(result));
|
|
93
|
-
return cvToValue(result);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {openContractCall} from "@stacks/connect";
|
|
3
|
+
import {decimal2integer, getPostConditionFromAsset, getReadOptions, getWriteOptions} from "../util";
|
|
4
|
+
import {
|
|
5
|
+
callReadOnlyFunction,
|
|
6
|
+
cvToValue,
|
|
7
|
+
FungibleConditionCode,
|
|
8
|
+
noneCV,
|
|
9
|
+
standardPrincipalCV,
|
|
10
|
+
uintCV
|
|
11
|
+
} from "@stacks/transactions";
|
|
12
|
+
import {StackswapAPI} from "../../index";
|
|
13
|
+
import {BaseToken, Token} from "./token.manager";
|
|
14
|
+
|
|
15
|
+
export class PoxlManager {
|
|
16
|
+
stackswap: StackswapAPI;
|
|
17
|
+
|
|
18
|
+
constructor(stackswap: StackswapAPI) {
|
|
19
|
+
this.stackswap = stackswap;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async minePOXLToken(token : Token, mine_amount: string, callback : any = null) {
|
|
23
|
+
const post_condition = [];
|
|
24
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), Token.getBaseTokens(this.stackswap, BaseToken.STX).addr, decimal2integer(mine_amount,6), FungibleConditionCode.Equal));
|
|
25
|
+
const options = getWriteOptions(this.stackswap, token.addr, 'mine-tokens', [
|
|
26
|
+
uintCV(decimal2integer(mine_amount,6)), noneCV() ], post_condition, callback);
|
|
27
|
+
await openContractCall(options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async stackPOXLToken(token : Token, stack_amount: string, stack_lock_period : string, callback : any = null) {
|
|
31
|
+
const post_condition = [];
|
|
32
|
+
post_condition.push(await getPostConditionFromAsset(this.stackswap, this.stackswap.getSenderAddress(), token.addr, decimal2integer(stack_amount, token.decimal), FungibleConditionCode.Equal));
|
|
33
|
+
const options = getWriteOptions(this.stackswap, token.addr, 'stack-tokens', [ uintCV(stack_amount), uintCV(stack_lock_period) ], post_condition, callback);
|
|
34
|
+
await openContractCall(options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async claimMiningReward(token : Token, mined_blocknum: string, callback : any = null) {
|
|
38
|
+
const options = getWriteOptions(this.stackswap, token.addr, 'claim-token-reward', [
|
|
39
|
+
uintCV(mined_blocknum)],[], callback);
|
|
40
|
+
await openContractCall(options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async claimStackingReward(token : Token, target_reward_cycle: string, callback : any = null) {
|
|
44
|
+
const options = getWriteOptions(this.stackswap, token.addr, 'claim-stacking-reward', [
|
|
45
|
+
uintCV(target_reward_cycle)], [], callback, true);
|
|
46
|
+
await openContractCall(options);
|
|
47
|
+
}
|
|
48
|
+
async getRandomInt( contract_address: string, input: number) {
|
|
49
|
+
await callReadOnlyFunction( getReadOptions(this.stackswap, contract_address, 'get-random-uint-at-block', [uintCV(input)]));
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
// console.log(result['value'].value.toString());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async getMinedBlock( contract_address: string, offset: number) {
|
|
55
|
+
const get_result = await axios.get( this.stackswap.config.STACKS_API_URL() + '/extended/v1/address/' + this.stackswap.getSenderAddress() + '/transactions', {
|
|
56
|
+
params: {
|
|
57
|
+
limit: 40,
|
|
58
|
+
offset,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const total = get_result.data.total;
|
|
62
|
+
const results = get_result.data.results;
|
|
63
|
+
const mined_block: number[] = [];
|
|
64
|
+
// console.log(results);
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
for (const item of results) {
|
|
67
|
+
// console.log(item);
|
|
68
|
+
try {
|
|
69
|
+
if (contract_address === item.contract_call.contract_id && item.contract_call.function_name === 'mine-tokens') {
|
|
70
|
+
const temp = await this.canClaimCall(contract_address, item.block_height);
|
|
71
|
+
// console.log(temp);
|
|
72
|
+
if (temp) {
|
|
73
|
+
mined_block.push(item.block_height);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// console.log(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// console.log(mined_block);
|
|
81
|
+
return {total, mined_block};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27.miamicoin-core-v1
|
|
85
|
+
async canClaimCall( contract_address: string, block: number) {
|
|
86
|
+
// const poxl_token = contract_address.split('.');
|
|
87
|
+
const options = getReadOptions(this.stackswap, contract_address, 'can-claim-mining-reward', [
|
|
88
|
+
standardPrincipalCV(this.stackswap.getSenderAddress()),
|
|
89
|
+
uintCV(block),
|
|
90
|
+
]);
|
|
91
|
+
const result = await callReadOnlyFunction(options);
|
|
92
|
+
// console.log(cvToValue(result));
|
|
93
|
+
return cvToValue(result);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
}
|