stackswap-front-api-test-02 1.0.83 → 1.0.86
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 +112 -112
- package/dist/esm/stackswap/config.js +185 -185
- 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/farm2.manager.js.map +1 -1
- 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/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/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/swap.manager.d.ts +39 -35
- package/dist/esm/stackswap/manager/swap.manager.js +331 -290
- package/dist/esm/stackswap/manager/swap.manager.js.map +1 -1
- 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 +112 -112
- package/dist/stackswap/config.js +190 -190
- 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/farm2.manager.js.map +1 -1
- 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/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/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/swap.manager.d.ts +39 -35
- package/dist/stackswap/manager/swap.manager.js +338 -297
- package/dist/stackswap/manager/swap.manager.js.map +1 -1
- 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 +292 -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/multisig.manager.ts +87 -87
- package/src/stackswap/manager/nft.manager.ts +311 -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 +391 -351
- package/src/stackswap/manager/token.manager.ts +167 -167
- package/src/stackswap/util.ts +237 -237
|
@@ -1,298 +1,339 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SwapManager = exports.SwapType = void 0;
|
|
7
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
const transactions_1 = require("@stacks/transactions");
|
|
9
|
-
const connect_1 = require("@stacks/connect");
|
|
10
|
-
const util_1 = require("../util");
|
|
11
|
-
const pool_manager_1 = require("./pool.manager");
|
|
12
|
-
const token_manager_1 = require("./token.manager");
|
|
13
|
-
const axios_1 = __importDefault(require("axios"));
|
|
14
|
-
var SwapType;
|
|
15
|
-
(function (SwapType) {
|
|
16
|
-
SwapType[SwapType["NO_ROUTE"] = 0] = "NO_ROUTE";
|
|
17
|
-
SwapType[SwapType["ON_LOADING"] = 1] = "ON_LOADING";
|
|
18
|
-
SwapType[SwapType["SINGLE"] = 2] = "SINGLE";
|
|
19
|
-
SwapType[SwapType["ROUTER_STX"] = 10] = "ROUTER_STX";
|
|
20
|
-
SwapType[SwapType["ROUTER_STSW"] = 11] = "ROUTER_STSW";
|
|
21
|
-
})(SwapType = exports.SwapType || (exports.SwapType = {}));
|
|
22
|
-
class SwapManager {
|
|
23
|
-
constructor(stackswap) {
|
|
24
|
-
this.stackswap = stackswap;
|
|
25
|
-
}
|
|
26
|
-
async
|
|
27
|
-
const url = this.stackswap.config.STACKS_BACKEND_URL() + '/api/
|
|
28
|
-
const result = await axios_1.default.get(url, { timeout: 50000, });
|
|
29
|
-
const res = result.data;
|
|
30
|
-
if (Object.keys(res).length === 0) {
|
|
31
|
-
return { valid: SwapType.NO_ROUTE };
|
|
32
|
-
}
|
|
33
|
-
else if (res.type === 'SWAP') {
|
|
34
|
-
return {
|
|
35
|
-
valid: SwapType.SINGLE,
|
|
36
|
-
x_to_y: res.direction,
|
|
37
|
-
pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.pair, token_x, token_y, res.direction)
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
else if (res.type === 'RouterSWAP') {
|
|
41
|
-
if (res.bridge_token === 'STX') {
|
|
42
|
-
return {
|
|
43
|
-
valid: SwapType.ROUTER_STX,
|
|
44
|
-
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), res.from_direction),
|
|
45
|
-
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), token_y, res.to_direction),
|
|
46
|
-
router_from_mode: res.from_direction,
|
|
47
|
-
router_to_mode: res.to_direction
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
else if (res.bridge_token === 'STSW') {
|
|
51
|
-
return {
|
|
52
|
-
valid: SwapType.ROUTER_STSW,
|
|
53
|
-
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), res.from_direction),
|
|
54
|
-
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), token_y, res.to_direction),
|
|
55
|
-
router_from_mode: res.from_direction,
|
|
56
|
-
router_to_mode: res.to_direction
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return { valid: SwapType.NO_ROUTE };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return { valid: SwapType.NO_ROUTE };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
(0,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
(0,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SwapManager = exports.SwapType = void 0;
|
|
7
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const transactions_1 = require("@stacks/transactions");
|
|
9
|
+
const connect_1 = require("@stacks/connect");
|
|
10
|
+
const util_1 = require("../util");
|
|
11
|
+
const pool_manager_1 = require("./pool.manager");
|
|
12
|
+
const token_manager_1 = require("./token.manager");
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
14
|
+
var SwapType;
|
|
15
|
+
(function (SwapType) {
|
|
16
|
+
SwapType[SwapType["NO_ROUTE"] = 0] = "NO_ROUTE";
|
|
17
|
+
SwapType[SwapType["ON_LOADING"] = 1] = "ON_LOADING";
|
|
18
|
+
SwapType[SwapType["SINGLE"] = 2] = "SINGLE";
|
|
19
|
+
SwapType[SwapType["ROUTER_STX"] = 10] = "ROUTER_STX";
|
|
20
|
+
SwapType[SwapType["ROUTER_STSW"] = 11] = "ROUTER_STSW";
|
|
21
|
+
})(SwapType = exports.SwapType || (exports.SwapType = {}));
|
|
22
|
+
class SwapManager {
|
|
23
|
+
constructor(stackswap) {
|
|
24
|
+
this.stackswap = stackswap;
|
|
25
|
+
}
|
|
26
|
+
async findRouter2(token_x, token_y, current_block) {
|
|
27
|
+
const url = this.stackswap.config.STACKS_BACKEND_URL() + '/api/v2/swap/' + token_x.addr + '/' + token_y.addr + '/' + current_block;
|
|
28
|
+
const result = await axios_1.default.get(url, { timeout: 50000, });
|
|
29
|
+
const res = result.data;
|
|
30
|
+
if (Object.keys(res).length === 0) {
|
|
31
|
+
return { valid: SwapType.NO_ROUTE };
|
|
32
|
+
}
|
|
33
|
+
else if (res.type === 'SWAP') {
|
|
34
|
+
return {
|
|
35
|
+
valid: SwapType.SINGLE,
|
|
36
|
+
x_to_y: res.direction,
|
|
37
|
+
pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.pair, token_x, token_y, res.direction)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else if (res.type === 'RouterSWAP') {
|
|
41
|
+
if (res.bridge_token === 'STX') {
|
|
42
|
+
return {
|
|
43
|
+
valid: SwapType.ROUTER_STX,
|
|
44
|
+
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), res.from_direction),
|
|
45
|
+
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), token_y, res.to_direction),
|
|
46
|
+
router_from_mode: res.from_direction,
|
|
47
|
+
router_to_mode: res.to_direction
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else if (res.bridge_token === 'STSW') {
|
|
51
|
+
return {
|
|
52
|
+
valid: SwapType.ROUTER_STSW,
|
|
53
|
+
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), res.from_direction),
|
|
54
|
+
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), token_y, res.to_direction),
|
|
55
|
+
router_from_mode: res.from_direction,
|
|
56
|
+
router_to_mode: res.to_direction
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return { valid: SwapType.NO_ROUTE };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return { valid: SwapType.NO_ROUTE };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async findRouter(token_x, token_y, current_block) {
|
|
68
|
+
const url = this.stackswap.config.STACKS_BACKEND_URL() + '/api/v1/swap/' + token_x.addr + '/' + token_y.addr + '/' + current_block;
|
|
69
|
+
const result = await axios_1.default.get(url, { timeout: 50000, });
|
|
70
|
+
const res = result.data;
|
|
71
|
+
if (Object.keys(res).length === 0) {
|
|
72
|
+
return { valid: SwapType.NO_ROUTE };
|
|
73
|
+
}
|
|
74
|
+
else if (res.type === 'SWAP') {
|
|
75
|
+
return {
|
|
76
|
+
valid: SwapType.SINGLE,
|
|
77
|
+
x_to_y: res.direction,
|
|
78
|
+
pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.pair, token_x, token_y, res.direction)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
else if (res.type === 'RouterSWAP') {
|
|
82
|
+
if (res.bridge_token === 'STX') {
|
|
83
|
+
return {
|
|
84
|
+
valid: SwapType.ROUTER_STX,
|
|
85
|
+
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), res.from_direction),
|
|
86
|
+
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX), token_y, res.to_direction),
|
|
87
|
+
router_from_mode: res.from_direction,
|
|
88
|
+
router_to_mode: res.to_direction
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else if (res.bridge_token === 'STSW') {
|
|
92
|
+
return {
|
|
93
|
+
valid: SwapType.ROUTER_STSW,
|
|
94
|
+
router_from_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.from_pair, token_x, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), res.from_direction),
|
|
95
|
+
router_to_pair: pool_manager_1.LiquidityPool.parsePoolsFromServerData2(res.to_pair, token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STSW), token_y, res.to_direction),
|
|
96
|
+
router_from_mode: res.from_direction,
|
|
97
|
+
router_to_mode: res.to_direction
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return { valid: SwapType.NO_ROUTE };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return { valid: SwapType.NO_ROUTE };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async routerSwapContractCall(token_from_amount, token_to_amount, token_bridge_amount, pair_from, pair_to, router_from_mode, router_to_mode, tolerance, callback = null) {
|
|
109
|
+
const token_from = router_from_mode ? pair_from.token_x : pair_from.token_y;
|
|
110
|
+
const token_bridge = router_from_mode ? pair_from.token_y : pair_from.token_x;
|
|
111
|
+
const token_to = router_to_mode ? pair_to.token_y : pair_to.token_x;
|
|
112
|
+
const from_amt = new bignumber_js_1.default(10 ** token_from.decimal).multipliedBy(token_from_amount).integerValue();
|
|
113
|
+
const bridge_amt = new bignumber_js_1.default(10 ** token_bridge.decimal).multipliedBy(token_bridge_amount).integerValue();
|
|
114
|
+
const to_amt = new bignumber_js_1.default(10 ** token_to.decimal).multipliedBy(token_to_amount).integerValue();
|
|
115
|
+
const bridge_min = bridge_amt.multipliedBy((100 - tolerance)).dividedBy(100).integerValue();
|
|
116
|
+
const to_min = to_amt.multipliedBy((100 - tolerance)).dividedBy(100).multipliedBy((100 - tolerance)).dividedBy(100).integerValue();
|
|
117
|
+
const token_from_addr = (token_from.addr);
|
|
118
|
+
const token_bridge_addr = (token_bridge.addr);
|
|
119
|
+
const token_to_addr = (token_to.addr);
|
|
120
|
+
const pair_from_addr = pair_from.token_lp.addr;
|
|
121
|
+
const pair_to_addr = pair_to.token_lp.addr;
|
|
122
|
+
const from_mode = router_from_mode ? (0, transactions_1.trueCV)() : (0, transactions_1.falseCV)();
|
|
123
|
+
const to_mode = router_to_mode ? (0, transactions_1.trueCV)() : (0, transactions_1.falseCV)();
|
|
124
|
+
const post_condition = [];
|
|
125
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_from.addr, from_amt.toString(), transactions_1.FungibleConditionCode.Equal));
|
|
126
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, pair_from_addr, token_bridge.addr, bridge_min.toString(), transactions_1.FungibleConditionCode.GreaterEqual));
|
|
127
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_bridge.addr, bridge_min.toString(), transactions_1.FungibleConditionCode.GreaterEqual));
|
|
128
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, pair_to_addr, token_to.addr, to_min.toString(), transactions_1.FungibleConditionCode.GreaterEqual));
|
|
129
|
+
const options = (0, util_1.getWriteOptions)(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_ROUTER_SWAP(), 'router-swap', [
|
|
130
|
+
(0, util_1.parseAddressToCV)(token_from_addr),
|
|
131
|
+
(0, util_1.parseAddressToCV)(token_bridge_addr),
|
|
132
|
+
(0, util_1.parseAddressToCV)(token_to_addr),
|
|
133
|
+
(0, util_1.parseAddressToCV)(pair_from_addr),
|
|
134
|
+
(0, util_1.parseAddressToCV)(pair_to_addr),
|
|
135
|
+
from_mode,
|
|
136
|
+
to_mode,
|
|
137
|
+
(0, transactions_1.uintCV)(from_amt.toString()),
|
|
138
|
+
(0, transactions_1.uintCV)(bridge_min.toString()),
|
|
139
|
+
(0, transactions_1.uintCV)(to_min.toString())
|
|
140
|
+
], post_condition, callback);
|
|
141
|
+
(0, connect_1.openContractCall)(options);
|
|
142
|
+
}
|
|
143
|
+
async swapContractCall(token_x_amount, token_y_amount, pair, x_to_y, tolerance, callback = null) {
|
|
144
|
+
const token_x = x_to_y ? pair.token_x : pair.token_y;
|
|
145
|
+
const token_y = x_to_y ? pair.token_y : pair.token_x;
|
|
146
|
+
const dx_bn = new bignumber_js_1.default(10 ** token_x.decimal).multipliedBy(token_x_amount);
|
|
147
|
+
const dy_min_bn = new bignumber_js_1.default(10 ** token_y.decimal).multipliedBy(token_y_amount).multipliedBy(100 - tolerance).dividedBy(100);
|
|
148
|
+
const dx = dx_bn.toFixed(0).toString();
|
|
149
|
+
const dy_min = dy_min_bn.toFixed(0).toString();
|
|
150
|
+
const functionName = x_to_y ? 'swap-x-for-y' : 'swap-y-for-x';
|
|
151
|
+
const token_x_addr = x_to_y ? (token_x.addr) : (token_y.addr);
|
|
152
|
+
const token_y_addr = x_to_y ? (token_y.addr) : (token_x.addr);
|
|
153
|
+
const post_condition = [];
|
|
154
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_x.addr, dx, transactions_1.FungibleConditionCode.Equal));
|
|
155
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, pair.token_lp.addr, token_y.addr, dy_min, transactions_1.FungibleConditionCode.GreaterEqual));
|
|
156
|
+
const options = (0, util_1.getWriteOptions)(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), functionName, [
|
|
157
|
+
(0, util_1.parseAddressToCV)(token_x_addr), (0, util_1.parseAddressToCV)(token_y_addr),
|
|
158
|
+
(0, util_1.parseAddressToCV)(pair.token_lp.addr), (0, transactions_1.uintCV)(dx), (0, transactions_1.uintCV)(dy_min)
|
|
159
|
+
], post_condition, callback);
|
|
160
|
+
(0, connect_1.openContractCall)(options);
|
|
161
|
+
}
|
|
162
|
+
async importContractCall(pair, x_to_y, amount_x, amount_y, callback = null) {
|
|
163
|
+
const token_x = x_to_y ? pair.token_x : pair.token_y;
|
|
164
|
+
const token_y = x_to_y ? pair.token_y : pair.token_x;
|
|
165
|
+
const dx_temp = new bignumber_js_1.default(10 ** token_x.decimal).multipliedBy(amount_x);
|
|
166
|
+
const dy_temp = new bignumber_js_1.default(10 ** token_y.decimal).multipliedBy(amount_y);
|
|
167
|
+
const dx = x_to_y ? dx_temp : dy_temp;
|
|
168
|
+
const dy = x_to_y ? dy_temp : dx_temp;
|
|
169
|
+
const dx_out = dx_temp.multipliedBy(1.2).toFixed(0).toString();
|
|
170
|
+
const dy_out = dy_temp.multipliedBy(1.2).toFixed(0).toString();
|
|
171
|
+
const token_x_addr = x_to_y ? (token_x.addr) : (token_y.addr);
|
|
172
|
+
const token_y_addr = x_to_y ? (token_y.addr) : (token_x.addr);
|
|
173
|
+
const post_condition = [];
|
|
174
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_x.addr, dx_out, transactions_1.FungibleConditionCode.LessEqual));
|
|
175
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_y.addr, dy_out, transactions_1.FungibleConditionCode.LessEqual));
|
|
176
|
+
const options = (0, util_1.getWriteOptions)(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), 'add-to-position', [
|
|
177
|
+
(0, util_1.parseAddressToCV)(token_x_addr), (0, util_1.parseAddressToCV)(token_y_addr),
|
|
178
|
+
(0, util_1.parseAddressToCV)(pair.token_lp.addr), (0, transactions_1.uintCV)(dx.toFixed(0).toString()), (0, transactions_1.uintCV)(dy.toFixed(0).toString())
|
|
179
|
+
], post_condition, callback);
|
|
180
|
+
(0, connect_1.openContractCall)(options);
|
|
181
|
+
}
|
|
182
|
+
async removeContractCall(pair, percent, user_lp_total, dx, dy, swap_contract = this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP(), callback = null) {
|
|
183
|
+
const token_x_addr = pair.token_x.addr;
|
|
184
|
+
const token_y_addr = pair.token_y.addr;
|
|
185
|
+
const pair_addr = pair.token_lp.addr;
|
|
186
|
+
const post_condition = [];
|
|
187
|
+
const burn_amount = new bignumber_js_1.default(user_lp_total).multipliedBy(percent * 1.01).div(100).toFixed(0).toString();
|
|
188
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, pair.token_lp.addr, pair.token_x.addr, dx, transactions_1.FungibleConditionCode.GreaterEqual));
|
|
189
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, pair.token_lp.addr, pair.token_y.addr, dy, transactions_1.FungibleConditionCode.GreaterEqual));
|
|
190
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), pair.token_lp.addr, burn_amount, transactions_1.FungibleConditionCode.LessEqual));
|
|
191
|
+
const options = (0, util_1.getWriteOptions)(this.stackswap, swap_contract, 'reduce-position', [
|
|
192
|
+
(0, util_1.parseAddressToCV)(token_x_addr), (0, util_1.parseAddressToCV)(token_y_addr),
|
|
193
|
+
(0, util_1.parseAddressToCV)(pair_addr), (0, transactions_1.uintCV)(percent),
|
|
194
|
+
], post_condition, callback);
|
|
195
|
+
(0, connect_1.openContractCall)(options);
|
|
196
|
+
}
|
|
197
|
+
async createContractCall(token_x, token_y, token_x_amount, token_y_amount, liquidity_token_addr, callback = null) {
|
|
198
|
+
const token_x_addr = token_x.addr;
|
|
199
|
+
const token_y_addr = token_y.addr;
|
|
200
|
+
const pair_addr = liquidity_token_addr;
|
|
201
|
+
const post_condition = [];
|
|
202
|
+
const amount_X = (0, util_1.decimal2integer)(token_x_amount, token_x.decimal);
|
|
203
|
+
const amount_Y = (0, util_1.decimal2integer)(token_y_amount, token_y.decimal);
|
|
204
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_x.addr, amount_X, transactions_1.FungibleConditionCode.Equal));
|
|
205
|
+
post_condition.push(await (0, util_1.getPostConditionFromAsset)(this.stackswap, this.stackswap.getSenderAddress(), token_y.addr, amount_Y, transactions_1.FungibleConditionCode.Equal));
|
|
206
|
+
const options = (0, util_1.getWriteOptions)(this.stackswap, this.stackswap.config.CONTRACT_NAME_STACKSWAP_ONE_STEP_MINT(), 'create-pair-new-liquidity-token', [
|
|
207
|
+
(0, util_1.parseAddressToCV)(token_x_addr), (0, util_1.parseAddressToCV)(token_y_addr),
|
|
208
|
+
(0, util_1.parseAddressToCV)(pair_addr), (0, transactions_1.stringAsciiCV)(token_x.symbol + '-' + token_y.symbol),
|
|
209
|
+
(0, transactions_1.uintCV)(amount_X), (0, transactions_1.uintCV)(amount_Y), (0, util_1.parseAddressToCV)(pair_addr),
|
|
210
|
+
(0, util_1.parseAddressToCV)(this.stackswap.getQualifiedAddress(this.stackswap.config.CONTRACT_NAME_STACKSWAP_SWAP())),
|
|
211
|
+
], post_condition, callback);
|
|
212
|
+
(0, connect_1.openContractCall)(options);
|
|
213
|
+
}
|
|
214
|
+
price_impact(x_to_y, pair, token_x_amount) {
|
|
215
|
+
try {
|
|
216
|
+
const balance_x = x_to_y ? pair.balance_x : pair.balance_y;
|
|
217
|
+
const token_x_decimal = x_to_y ? pair.token_x.decimal : pair.token_y.decimal;
|
|
218
|
+
const balance_y = x_to_y ? pair.balance_y : pair.balance_y;
|
|
219
|
+
const dx = new bignumber_js_1.default(token_x_amount).multipliedBy(10 ** token_x_decimal);
|
|
220
|
+
if (dx.toNumber() > new bignumber_js_1.default(balance_x).toNumber()) {
|
|
221
|
+
return 100;
|
|
222
|
+
}
|
|
223
|
+
const dy_1 = new bignumber_js_1.default(balance_y).multipliedBy(dx);
|
|
224
|
+
const dy_2 = new bignumber_js_1.default(balance_x).plus(dx);
|
|
225
|
+
const dy = (dy_1.toNumber()) / (dy_2.toNumber());
|
|
226
|
+
const input_price = new bignumber_js_1.default(10 ** 10).multipliedBy(new bignumber_js_1.default(balance_x)).dividedBy(new bignumber_js_1.default(balance_y));
|
|
227
|
+
const output_price = new bignumber_js_1.default(10 ** 10).multipliedBy(new bignumber_js_1.default(balance_x)).plus(dx).dividedBy(new bignumber_js_1.default(balance_y).minus(dy));
|
|
228
|
+
const price_impact2 = output_price.minus(input_price).multipliedBy(10000).dividedBy(input_price);
|
|
229
|
+
let price_impact = price_impact2.toNumber();
|
|
230
|
+
if (price_impact >= 10000) {
|
|
231
|
+
price_impact = 9999;
|
|
232
|
+
}
|
|
233
|
+
return (price_impact / 100).toFixed(5);
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
price_impact_router(router_from_mode, router_to_mode, pair_from, pair_to, token_from_amount) {
|
|
240
|
+
try {
|
|
241
|
+
const balance_x = router_from_mode ? pair_from.balance_x : pair_from.balance_y;
|
|
242
|
+
const token_from_decimal = router_from_mode ? pair_from.token_x.decimal : pair_from.token_y.decimal;
|
|
243
|
+
const balance_y = router_to_mode ? pair_to.balance_y : pair_to.balance_x;
|
|
244
|
+
const dx = new bignumber_js_1.default(token_from_amount).multipliedBy(10 ** token_from_decimal);
|
|
245
|
+
if (dx.toNumber() > new bignumber_js_1.default(balance_x).toNumber()) {
|
|
246
|
+
return 100;
|
|
247
|
+
}
|
|
248
|
+
const dy_1 = new bignumber_js_1.default(balance_y).multipliedBy(dx);
|
|
249
|
+
const dy_2 = new bignumber_js_1.default(balance_x).plus(dx);
|
|
250
|
+
const dy = (dy_1.toNumber()) / (dy_2.toNumber());
|
|
251
|
+
const input_price = new bignumber_js_1.default(10 ** 10).multipliedBy(new bignumber_js_1.default(balance_x)).dividedBy(new bignumber_js_1.default(balance_y));
|
|
252
|
+
const output_price = new bignumber_js_1.default(10 ** 10).multipliedBy(new bignumber_js_1.default(balance_x)).plus(dx).dividedBy(new bignumber_js_1.default(balance_y).minus(dy));
|
|
253
|
+
const price_impact2 = output_price.minus(input_price).multipliedBy(10000).dividedBy(input_price);
|
|
254
|
+
let price_impact = price_impact2.toNumber();
|
|
255
|
+
if (price_impact >= 10000) {
|
|
256
|
+
price_impact = 9999;
|
|
257
|
+
}
|
|
258
|
+
return (price_impact / 100).toFixed(5);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
getPriceString(pair, token_x, token_y, price, price_invert) {
|
|
265
|
+
try {
|
|
266
|
+
if (pair != null && price < 0) {
|
|
267
|
+
return 'dx exceed pool balance';
|
|
268
|
+
}
|
|
269
|
+
else if (token_x != null && token_y != null) {
|
|
270
|
+
if (price_invert) {
|
|
271
|
+
return ` 1 ${token_y.symbol} = ${new bignumber_js_1.default((1 / price)).toFixed(token_x.decimal)} ${token_x.symbol}`;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
return ` 1 ${token_x.symbol} = ${new bignumber_js_1.default(price).toFixed(token_x.decimal)} ${token_y.symbol}`;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return '';
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
return '';
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
getPricesWithSwapData(swap_data, token_x_amount, price_invert) {
|
|
284
|
+
let price = -1;
|
|
285
|
+
switch (swap_data.valid) {
|
|
286
|
+
case SwapType.SINGLE:
|
|
287
|
+
try {
|
|
288
|
+
const temp = swap_data.pair.getPoolPrice(!swap_data.x_to_y, Number(token_x_amount) <= 0 || token_x_amount == '' ? '-1' : token_x_amount);
|
|
289
|
+
if (temp.output_price !== '0') {
|
|
290
|
+
price = (1 / parseFloat(temp.output_price));
|
|
291
|
+
}
|
|
292
|
+
const price_strings = this.getPriceString(swap_data.pair, swap_data.pair.getTokenX(swap_data.x_to_y), swap_data.pair.getTokenY(swap_data.x_to_y), price, price_invert);
|
|
293
|
+
const token_y_amount = new bignumber_js_1.default(temp.dy).toFixed(Number(swap_data.pair.getTokenY(swap_data.x_to_y).decimal)).toString();
|
|
294
|
+
return { price: price, dy: token_y_amount, price_strings: price_strings };
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
return { price: price, dy: '0', price_strings: '' };
|
|
298
|
+
}
|
|
299
|
+
case SwapType.ROUTER_STX:
|
|
300
|
+
const bridge_token = token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX);
|
|
301
|
+
const from_res = swap_data.router_from_pair.getPoolPrice(!swap_data.router_from_mode, Number(token_x_amount) <= 0 || token_x_amount == '' ? '1' : token_x_amount);
|
|
302
|
+
let router_from_price = -1;
|
|
303
|
+
if (from_res.output_price !== '0') {
|
|
304
|
+
router_from_price = (1 / parseFloat(from_res.output_price));
|
|
305
|
+
}
|
|
306
|
+
const router_bridge_amt = new bignumber_js_1.default(new bignumber_js_1.default(from_res.dy).toFixed(Number(bridge_token.decimal))).toString();
|
|
307
|
+
const to_res = swap_data.router_to_pair.getPoolPrice(!swap_data.router_to_mode, Number(router_bridge_amt) <= 0 ? '-1' : router_bridge_amt);
|
|
308
|
+
let router_to_price = -1;
|
|
309
|
+
if (to_res.output_price !== '0') {
|
|
310
|
+
router_to_price = (1 / parseFloat(to_res.output_price));
|
|
311
|
+
}
|
|
312
|
+
const token_y_amount2 = new bignumber_js_1.default(to_res.dy).toFixed(Number(Number(token_x_amount) <= 0 || token_x_amount == '' ? 0 : swap_data.router_to_pair.getTokenY(swap_data.router_to_mode).decimal)).toString();
|
|
313
|
+
price = router_from_price * router_to_price;
|
|
314
|
+
const price_strings2 = this.getPriceString(swap_data.pair, swap_data.router_from_pair.getTokenX(swap_data.router_from_mode), swap_data.router_to_pair.getTokenY(swap_data.router_to_mode), price, price_invert);
|
|
315
|
+
return { price: price, dy: token_y_amount2, price_strings: price_strings2, bridge_amount: router_bridge_amt };
|
|
316
|
+
case SwapType.ROUTER_STSW:
|
|
317
|
+
const bridge_token2 = token_manager_1.Token.getBaseTokens(this.stackswap, token_manager_1.BaseToken.STX);
|
|
318
|
+
const from_res2 = swap_data.router_from_pair.getPoolPrice(!swap_data.router_from_mode, Number(token_x_amount) <= 0 || token_x_amount == '' ? '1' : token_x_amount);
|
|
319
|
+
let router_from_price2 = -1;
|
|
320
|
+
if (from_res2.output_price !== '0') {
|
|
321
|
+
router_from_price2 = (1 / parseFloat(from_res2.output_price));
|
|
322
|
+
}
|
|
323
|
+
const router_bridge_amt2 = new bignumber_js_1.default(new bignumber_js_1.default(from_res2.dy).toFixed(Number(bridge_token2.decimal))).toString();
|
|
324
|
+
const to_res2 = swap_data.router_to_pair.getPoolPrice(!swap_data.router_to_mode, Number(router_bridge_amt2) <= 0 ? '-1' : router_bridge_amt2);
|
|
325
|
+
let router_to_price2 = -1;
|
|
326
|
+
if (to_res2.output_price !== '0') {
|
|
327
|
+
router_to_price2 = (1 / parseFloat(to_res2.output_price));
|
|
328
|
+
}
|
|
329
|
+
const token_y_amount3 = new bignumber_js_1.default(to_res2.dy).toFixed(Number(Number(token_x_amount) <= 0 || token_x_amount == '' ? 0 : swap_data.router_to_pair.getTokenY(swap_data.router_to_mode).decimal)).toString();
|
|
330
|
+
price = router_from_price2 * router_to_price2;
|
|
331
|
+
const price_strings3 = this.getPriceString(swap_data.pair, swap_data.router_from_pair.getTokenX(swap_data.router_from_mode), swap_data.router_to_pair.getTokenY(swap_data.router_to_mode), price, price_invert);
|
|
332
|
+
return { price: price, dy: token_y_amount3, price_strings: price_strings3, bridge_amount: router_bridge_amt2 };
|
|
333
|
+
default:
|
|
334
|
+
return { price: price, dy: '0', price_strings: '' };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.SwapManager = SwapManager;
|
|
298
339
|
//# sourceMappingURL=swap.manager.js.map
|