@aspan/sdk 0.3.1 → 0.4.1
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 +310 -512
- package/dist/index.d.mts +303 -323
- package/dist/index.d.ts +303 -323
- package/dist/index.js +298 -381
- package/dist/index.mjs +297 -381
- package/package.json +1 -1
- package/src/__tests__/fork.test.ts +2 -2
- package/src/__tests__/router.test.ts +145 -89
- package/src/abi/diamond.ts +74 -0
- package/src/abi/router.ts +60 -191
- package/src/abi/sApUSD.ts +100 -0
- package/src/bot/config.ts +51 -1
- package/src/bot/index.ts +69 -1
- package/src/bot/services/fee-manager.ts +303 -0
- package/src/bot/services/risk-keeper.ts +519 -0
- package/src/client.ts +109 -0
- package/src/index.ts +22 -5
- package/src/router.ts +58 -216
- package/src/types.ts +60 -43
package/src/abi/router.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AspanRouter ABI
|
|
3
3
|
* Periphery contract for one-click swap+mint operations
|
|
4
|
-
* Updated:
|
|
4
|
+
* Updated: 2026-02-04 (v2.0.0 - consolidated API)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export const RouterABI = [
|
|
8
|
-
// ============ Core
|
|
8
|
+
// ============ Core Functions ============
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// swapAndMint - unified swap + mint
|
|
11
11
|
{
|
|
12
12
|
type: "function",
|
|
13
|
-
name: "
|
|
13
|
+
name: "swapAndMint",
|
|
14
14
|
inputs: [
|
|
15
15
|
{
|
|
16
16
|
name: "swapParams",
|
|
@@ -36,48 +36,29 @@ export const RouterABI = [
|
|
|
36
36
|
],
|
|
37
37
|
outputs: [
|
|
38
38
|
{ name: "lstAmount", type: "uint256" },
|
|
39
|
-
{ name: "
|
|
39
|
+
{ name: "mintedAmount", type: "uint256" },
|
|
40
40
|
],
|
|
41
41
|
stateMutability: "payable",
|
|
42
42
|
},
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// swapAndMintDefault - simplified version using default LST
|
|
45
45
|
{
|
|
46
46
|
type: "function",
|
|
47
|
-
name: "
|
|
47
|
+
name: "swapAndMintDefault",
|
|
48
48
|
inputs: [
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{ name: "inputAmount", type: "uint256" },
|
|
55
|
-
{ name: "targetLST", type: "address" },
|
|
56
|
-
{ name: "minLSTOut", type: "uint256" },
|
|
57
|
-
{ name: "poolFee", type: "uint24" },
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "mintParams",
|
|
62
|
-
type: "tuple",
|
|
63
|
-
components: [
|
|
64
|
-
{ name: "mintXBNB", type: "bool" },
|
|
65
|
-
{ name: "minMintOut", type: "uint256" },
|
|
66
|
-
{ name: "recipient", type: "address" },
|
|
67
|
-
{ name: "deadline", type: "uint256" },
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
outputs: [
|
|
72
|
-
{ name: "lstAmount", type: "uint256" },
|
|
73
|
-
{ name: "xBNBAmount", type: "uint256" },
|
|
49
|
+
{ name: "inputToken", type: "address" },
|
|
50
|
+
{ name: "inputAmount", type: "uint256" },
|
|
51
|
+
{ name: "mintXBNB", type: "bool" },
|
|
52
|
+
{ name: "minMintOut", type: "uint256" },
|
|
53
|
+
{ name: "deadline", type: "uint256" },
|
|
74
54
|
],
|
|
55
|
+
outputs: [{ name: "mintedAmount", type: "uint256" }],
|
|
75
56
|
stateMutability: "payable",
|
|
76
57
|
},
|
|
77
58
|
|
|
78
59
|
// ============ Stake+Mint Functions ============
|
|
79
60
|
|
|
80
|
-
// stakeAndMint
|
|
61
|
+
// stakeAndMint - stake BNB directly to LST and mint
|
|
81
62
|
{
|
|
82
63
|
type: "function",
|
|
83
64
|
name: "stakeAndMint",
|
|
@@ -94,135 +75,50 @@ export const RouterABI = [
|
|
|
94
75
|
stateMutability: "payable",
|
|
95
76
|
},
|
|
96
77
|
|
|
97
|
-
// stakeAndMintApUSD (simplified)
|
|
98
|
-
{
|
|
99
|
-
type: "function",
|
|
100
|
-
name: "stakeAndMintApUSD",
|
|
101
|
-
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
102
|
-
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
103
|
-
stateMutability: "payable",
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
// stakeAndMintXBNB (simplified)
|
|
107
|
-
{
|
|
108
|
-
type: "function",
|
|
109
|
-
name: "stakeAndMintXBNB",
|
|
110
|
-
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
111
|
-
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
112
|
-
stateMutability: "payable",
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
// ============ Simplified Swap+Mint Functions ============
|
|
116
|
-
|
|
117
|
-
// swapAndMintApUSDDefault
|
|
118
|
-
{
|
|
119
|
-
type: "function",
|
|
120
|
-
name: "swapAndMintApUSDDefault",
|
|
121
|
-
inputs: [
|
|
122
|
-
{ name: "inputToken", type: "address" },
|
|
123
|
-
{ name: "inputAmount", type: "uint256" },
|
|
124
|
-
{ name: "minMintOut", type: "uint256" },
|
|
125
|
-
{ name: "deadline", type: "uint256" },
|
|
126
|
-
],
|
|
127
|
-
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
128
|
-
stateMutability: "payable",
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
// swapAndMintXBNBDefault
|
|
132
|
-
{
|
|
133
|
-
type: "function",
|
|
134
|
-
name: "swapAndMintXBNBDefault",
|
|
135
|
-
inputs: [
|
|
136
|
-
{ name: "inputToken", type: "address" },
|
|
137
|
-
{ name: "inputAmount", type: "uint256" },
|
|
138
|
-
{ name: "minMintOut", type: "uint256" },
|
|
139
|
-
{ name: "deadline", type: "uint256" },
|
|
140
|
-
],
|
|
141
|
-
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
142
|
-
stateMutability: "payable",
|
|
143
|
-
},
|
|
144
|
-
|
|
145
78
|
// ============ Direct Mint/Redeem Functions ============
|
|
146
79
|
|
|
147
|
-
//
|
|
148
|
-
{
|
|
149
|
-
type: "function",
|
|
150
|
-
name: "mintApUSD",
|
|
151
|
-
inputs: [
|
|
152
|
-
{ name: "lst", type: "address" },
|
|
153
|
-
{ name: "lstAmount", type: "uint256" },
|
|
154
|
-
{ name: "minOut", type: "uint256" },
|
|
155
|
-
],
|
|
156
|
-
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
157
|
-
stateMutability: "nonpayable",
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
// mintXBNB
|
|
80
|
+
// mint - unified mint function
|
|
161
81
|
{
|
|
162
82
|
type: "function",
|
|
163
|
-
name: "
|
|
83
|
+
name: "mint",
|
|
164
84
|
inputs: [
|
|
165
85
|
{ name: "lst", type: "address" },
|
|
166
86
|
{ name: "lstAmount", type: "uint256" },
|
|
87
|
+
{ name: "mintXBNB", type: "bool" },
|
|
167
88
|
{ name: "minOut", type: "uint256" },
|
|
168
89
|
],
|
|
169
|
-
outputs: [{ name: "
|
|
170
|
-
stateMutability: "nonpayable",
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
// redeemApUSD
|
|
174
|
-
{
|
|
175
|
-
type: "function",
|
|
176
|
-
name: "redeemApUSD",
|
|
177
|
-
inputs: [
|
|
178
|
-
{ name: "lst", type: "address" },
|
|
179
|
-
{ name: "apUSDAmount", type: "uint256" },
|
|
180
|
-
{ name: "minOut", type: "uint256" },
|
|
181
|
-
],
|
|
182
|
-
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
90
|
+
outputs: [{ name: "mintedAmount", type: "uint256" }],
|
|
183
91
|
stateMutability: "nonpayable",
|
|
184
92
|
},
|
|
185
93
|
|
|
186
|
-
//
|
|
94
|
+
// redeem - unified redeem function
|
|
187
95
|
{
|
|
188
96
|
type: "function",
|
|
189
|
-
name: "
|
|
97
|
+
name: "redeem",
|
|
190
98
|
inputs: [
|
|
191
99
|
{ name: "lst", type: "address" },
|
|
192
|
-
{ name: "
|
|
100
|
+
{ name: "redeemXBNB", type: "bool" },
|
|
101
|
+
{ name: "amount", type: "uint256" },
|
|
193
102
|
{ name: "minOut", type: "uint256" },
|
|
194
103
|
],
|
|
195
104
|
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
196
105
|
stateMutability: "nonpayable",
|
|
197
106
|
},
|
|
198
107
|
|
|
199
|
-
// ============ Redeem + Swap Functions
|
|
200
|
-
|
|
201
|
-
// redeemApUSDAndSwap
|
|
202
|
-
{
|
|
203
|
-
type: "function",
|
|
204
|
-
name: "redeemApUSDAndSwap",
|
|
205
|
-
inputs: [
|
|
206
|
-
{ name: "lst", type: "address" },
|
|
207
|
-
{ name: "apUSDAmount", type: "uint256" },
|
|
208
|
-
{ name: "path", type: "bytes" },
|
|
209
|
-
{ name: "minOut", type: "uint256" },
|
|
210
|
-
{ name: "deadline", type: "uint256" },
|
|
211
|
-
],
|
|
212
|
-
outputs: [{ name: "outputAmount", type: "uint256" }],
|
|
213
|
-
stateMutability: "nonpayable",
|
|
214
|
-
},
|
|
108
|
+
// ============ Redeem + Swap Functions ============
|
|
215
109
|
|
|
216
|
-
//
|
|
110
|
+
// redeemAndSwap - unified redeem and swap via V3 path
|
|
217
111
|
{
|
|
218
112
|
type: "function",
|
|
219
|
-
name: "
|
|
113
|
+
name: "redeemAndSwap",
|
|
220
114
|
inputs: [
|
|
221
115
|
{ name: "lst", type: "address" },
|
|
222
|
-
{ name: "
|
|
116
|
+
{ name: "redeemXBNB", type: "bool" },
|
|
117
|
+
{ name: "amount", type: "uint256" },
|
|
223
118
|
{ name: "path", type: "bytes" },
|
|
224
119
|
{ name: "minOut", type: "uint256" },
|
|
225
120
|
{ name: "deadline", type: "uint256" },
|
|
121
|
+
{ name: "unwrapBNB", type: "bool" },
|
|
226
122
|
],
|
|
227
123
|
outputs: [{ name: "outputAmount", type: "uint256" }],
|
|
228
124
|
stateMutability: "nonpayable",
|
|
@@ -230,23 +126,14 @@ export const RouterABI = [
|
|
|
230
126
|
|
|
231
127
|
// ============ Native Unstake Functions ============
|
|
232
128
|
|
|
233
|
-
//
|
|
129
|
+
// redeemAndRequestUnstake - unified unstake request
|
|
234
130
|
{
|
|
235
131
|
type: "function",
|
|
236
|
-
name: "
|
|
237
|
-
inputs: [
|
|
238
|
-
|
|
239
|
-
{ name: "
|
|
240
|
-
{ name: "slisBNBAmount", type: "uint256" },
|
|
132
|
+
name: "redeemAndRequestUnstake",
|
|
133
|
+
inputs: [
|
|
134
|
+
{ name: "redeemXBNB", type: "bool" },
|
|
135
|
+
{ name: "amount", type: "uint256" },
|
|
241
136
|
],
|
|
242
|
-
stateMutability: "nonpayable",
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
// redeemXBNBAndRequestUnstake
|
|
246
|
-
{
|
|
247
|
-
type: "function",
|
|
248
|
-
name: "redeemXBNBAndRequestUnstake",
|
|
249
|
-
inputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
250
137
|
outputs: [
|
|
251
138
|
{ name: "requestIndex", type: "uint256" },
|
|
252
139
|
{ name: "slisBNBAmount", type: "uint256" },
|
|
@@ -299,43 +186,25 @@ export const RouterABI = [
|
|
|
299
186
|
stateMutability: "view",
|
|
300
187
|
},
|
|
301
188
|
|
|
302
|
-
// Preview functions
|
|
189
|
+
// Preview functions - unified
|
|
303
190
|
{
|
|
304
191
|
type: "function",
|
|
305
|
-
name: "
|
|
192
|
+
name: "previewMint",
|
|
306
193
|
inputs: [
|
|
307
194
|
{ name: "lst", type: "address" },
|
|
308
195
|
{ name: "lstAmount", type: "uint256" },
|
|
196
|
+
{ name: "mintXBNB", type: "bool" },
|
|
309
197
|
],
|
|
310
|
-
outputs: [{ name: "
|
|
198
|
+
outputs: [{ name: "mintedAmount", type: "uint256" }],
|
|
311
199
|
stateMutability: "view",
|
|
312
200
|
},
|
|
313
201
|
{
|
|
314
202
|
type: "function",
|
|
315
|
-
name: "
|
|
203
|
+
name: "previewRedeem",
|
|
316
204
|
inputs: [
|
|
317
205
|
{ name: "lst", type: "address" },
|
|
318
|
-
{ name: "
|
|
319
|
-
|
|
320
|
-
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
321
|
-
stateMutability: "view",
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
type: "function",
|
|
325
|
-
name: "previewRedeemApUSD",
|
|
326
|
-
inputs: [
|
|
327
|
-
{ name: "lst", type: "address" },
|
|
328
|
-
{ name: "apUSDAmount", type: "uint256" },
|
|
329
|
-
],
|
|
330
|
-
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
331
|
-
stateMutability: "view",
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
type: "function",
|
|
335
|
-
name: "previewRedeemXBNB",
|
|
336
|
-
inputs: [
|
|
337
|
-
{ name: "lst", type: "address" },
|
|
338
|
-
{ name: "xBNBAmount", type: "uint256" },
|
|
206
|
+
{ name: "redeemXBNB", type: "bool" },
|
|
207
|
+
{ name: "amount", type: "uint256" },
|
|
339
208
|
],
|
|
340
209
|
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
341
210
|
stateMutability: "view",
|
|
@@ -422,9 +291,9 @@ export const RouterABI = [
|
|
|
422
291
|
name: "SwapAndMint",
|
|
423
292
|
inputs: [
|
|
424
293
|
{ name: "user", type: "address", indexed: true },
|
|
425
|
-
{ name: "inputToken", type: "address", indexed:
|
|
294
|
+
{ name: "inputToken", type: "address", indexed: true },
|
|
426
295
|
{ name: "inputAmount", type: "uint256", indexed: false },
|
|
427
|
-
{ name: "
|
|
296
|
+
{ name: "targetLST", type: "address", indexed: true },
|
|
428
297
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
429
298
|
{ name: "mintedToken", type: "address", indexed: false },
|
|
430
299
|
{ name: "mintedAmount", type: "uint256", indexed: false },
|
|
@@ -436,20 +305,28 @@ export const RouterABI = [
|
|
|
436
305
|
inputs: [
|
|
437
306
|
{ name: "user", type: "address", indexed: true },
|
|
438
307
|
{ name: "bnbAmount", type: "uint256", indexed: false },
|
|
439
|
-
{ name: "
|
|
308
|
+
{ name: "targetLST", type: "address", indexed: true },
|
|
440
309
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
441
|
-
{ name: "mintedToken", type: "address", indexed:
|
|
310
|
+
{ name: "mintedToken", type: "address", indexed: true },
|
|
442
311
|
{ name: "mintedAmount", type: "uint256", indexed: false },
|
|
443
312
|
],
|
|
444
313
|
},
|
|
314
|
+
{
|
|
315
|
+
type: "event",
|
|
316
|
+
name: "DefaultLSTUpdated",
|
|
317
|
+
inputs: [
|
|
318
|
+
{ name: "oldLST", type: "address", indexed: true },
|
|
319
|
+
{ name: "newLST", type: "address", indexed: true },
|
|
320
|
+
],
|
|
321
|
+
},
|
|
445
322
|
{
|
|
446
323
|
type: "event",
|
|
447
324
|
name: "Mint",
|
|
448
325
|
inputs: [
|
|
449
326
|
{ name: "user", type: "address", indexed: true },
|
|
450
|
-
{ name: "lst", type: "address", indexed:
|
|
327
|
+
{ name: "lst", type: "address", indexed: true },
|
|
451
328
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
452
|
-
{ name: "mintedToken", type: "address", indexed:
|
|
329
|
+
{ name: "mintedToken", type: "address", indexed: true },
|
|
453
330
|
{ name: "mintedAmount", type: "uint256", indexed: false },
|
|
454
331
|
],
|
|
455
332
|
},
|
|
@@ -458,9 +335,9 @@ export const RouterABI = [
|
|
|
458
335
|
name: "Redeem",
|
|
459
336
|
inputs: [
|
|
460
337
|
{ name: "user", type: "address", indexed: true },
|
|
461
|
-
{ name: "redeemedToken", type: "address", indexed:
|
|
338
|
+
{ name: "redeemedToken", type: "address", indexed: true },
|
|
462
339
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
463
|
-
{ name: "lst", type: "address", indexed:
|
|
340
|
+
{ name: "lst", type: "address", indexed: true },
|
|
464
341
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
465
342
|
],
|
|
466
343
|
},
|
|
@@ -473,7 +350,7 @@ export const RouterABI = [
|
|
|
473
350
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
474
351
|
{ name: "lst", type: "address", indexed: false },
|
|
475
352
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
476
|
-
{ name: "outputToken", type: "address", indexed:
|
|
353
|
+
{ name: "outputToken", type: "address", indexed: true },
|
|
477
354
|
{ name: "outputAmount", type: "uint256", indexed: false },
|
|
478
355
|
],
|
|
479
356
|
},
|
|
@@ -482,7 +359,7 @@ export const RouterABI = [
|
|
|
482
359
|
name: "UnstakeRequested",
|
|
483
360
|
inputs: [
|
|
484
361
|
{ name: "user", type: "address", indexed: true },
|
|
485
|
-
{ name: "requestIndex", type: "uint256", indexed:
|
|
362
|
+
{ name: "requestIndex", type: "uint256", indexed: true },
|
|
486
363
|
{ name: "redeemedToken", type: "address", indexed: false },
|
|
487
364
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
488
365
|
{ name: "slisBNBAmount", type: "uint256", indexed: false },
|
|
@@ -493,18 +370,10 @@ export const RouterABI = [
|
|
|
493
370
|
name: "UnstakeClaimed",
|
|
494
371
|
inputs: [
|
|
495
372
|
{ name: "user", type: "address", indexed: true },
|
|
496
|
-
{ name: "requestIndex", type: "uint256", indexed:
|
|
373
|
+
{ name: "requestIndex", type: "uint256", indexed: true },
|
|
497
374
|
{ name: "bnbAmount", type: "uint256", indexed: false },
|
|
498
375
|
],
|
|
499
376
|
},
|
|
500
|
-
{
|
|
501
|
-
type: "event",
|
|
502
|
-
name: "DefaultLSTUpdated",
|
|
503
|
-
inputs: [
|
|
504
|
-
{ name: "oldLST", type: "address", indexed: false },
|
|
505
|
-
{ name: "newLST", type: "address", indexed: false },
|
|
506
|
-
],
|
|
507
|
-
},
|
|
508
377
|
{
|
|
509
378
|
type: "event",
|
|
510
379
|
name: "OwnershipTransferred",
|
|
@@ -528,7 +397,7 @@ export const RouterABI = [
|
|
|
528
397
|
{ type: "error", name: "SwapFailed", inputs: [] },
|
|
529
398
|
{ type: "error", name: "UnsupportedInputToken", inputs: [] },
|
|
530
399
|
{ type: "error", name: "UnsupportedLST", inputs: [] },
|
|
531
|
-
{ type: "error", name: "
|
|
400
|
+
{ type: "error", name: "UnsupportedSwapPath", inputs: [] },
|
|
532
401
|
{ type: "error", name: "WithdrawalAlreadyClaimed", inputs: [] },
|
|
533
402
|
{ type: "error", name: "WithdrawalNotClaimable", inputs: [] },
|
|
534
403
|
{ type: "error", name: "ZeroAmount", inputs: [] },
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SApUSD (Staked ApUSD) Vault ABI
|
|
3
|
+
* Multi-asset vault for staking apUSD and absorbing xBNB during stability events
|
|
4
|
+
*/
|
|
5
|
+
export const SApUSDABI = [
|
|
6
|
+
// ============ View Functions ============
|
|
7
|
+
{
|
|
8
|
+
type: "function",
|
|
9
|
+
name: "totalAssets",
|
|
10
|
+
inputs: [],
|
|
11
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
12
|
+
stateMutability: "view"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: "function",
|
|
16
|
+
name: "totalSupply",
|
|
17
|
+
inputs: [],
|
|
18
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
19
|
+
stateMutability: "view"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "function",
|
|
23
|
+
name: "balanceOf",
|
|
24
|
+
inputs: [{ name: "account", type: "address", internalType: "address" }],
|
|
25
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
26
|
+
stateMutability: "view"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "function",
|
|
30
|
+
name: "hasStabilityConversion",
|
|
31
|
+
inputs: [],
|
|
32
|
+
outputs: [
|
|
33
|
+
{ name: "hasXBNB", type: "bool", internalType: "bool" },
|
|
34
|
+
{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }
|
|
35
|
+
],
|
|
36
|
+
stateMutability: "view"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "function",
|
|
40
|
+
name: "exchangeRate",
|
|
41
|
+
inputs: [],
|
|
42
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
43
|
+
stateMutability: "view"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "function",
|
|
47
|
+
name: "previewCleanXBNB",
|
|
48
|
+
inputs: [
|
|
49
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" },
|
|
50
|
+
{ name: "_router", type: "address", internalType: "address" },
|
|
51
|
+
{ name: "_path", type: "address[]", internalType: "address[]" }
|
|
52
|
+
],
|
|
53
|
+
outputs: [{ name: "expectedApUSD", type: "uint256", internalType: "uint256" }],
|
|
54
|
+
stateMutability: "view"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: "function",
|
|
58
|
+
name: "KEEPER_ROLE",
|
|
59
|
+
inputs: [],
|
|
60
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
61
|
+
stateMutability: "view"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "function",
|
|
65
|
+
name: "hasRole",
|
|
66
|
+
inputs: [
|
|
67
|
+
{ name: "role", type: "bytes32", internalType: "bytes32" },
|
|
68
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
69
|
+
],
|
|
70
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
71
|
+
stateMutability: "view"
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// ============ Keeper Functions ============
|
|
75
|
+
{
|
|
76
|
+
type: "function",
|
|
77
|
+
name: "cleanXBNB",
|
|
78
|
+
inputs: [
|
|
79
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" },
|
|
80
|
+
{ name: "_minApUSDOut", type: "uint256", internalType: "uint256" },
|
|
81
|
+
{ name: "_router", type: "address", internalType: "address" },
|
|
82
|
+
{ name: "_path", type: "address[]", internalType: "address[]" },
|
|
83
|
+
{ name: "_deadline", type: "uint256", internalType: "uint256" }
|
|
84
|
+
],
|
|
85
|
+
outputs: [{ name: "apUSDReceived", type: "uint256", internalType: "uint256" }],
|
|
86
|
+
stateMutability: "nonpayable"
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// ============ Events ============
|
|
90
|
+
{
|
|
91
|
+
type: "event",
|
|
92
|
+
name: "VaultCleaned",
|
|
93
|
+
inputs: [
|
|
94
|
+
{ name: "xBNBSold", type: "uint256", indexed: false, internalType: "uint256" },
|
|
95
|
+
{ name: "apUSDReceived", type: "uint256", indexed: false, internalType: "uint256" },
|
|
96
|
+
{ name: "keeper", type: "address", indexed: true, internalType: "address" }
|
|
97
|
+
],
|
|
98
|
+
anonymous: false
|
|
99
|
+
}
|
|
100
|
+
] as const;
|
package/src/bot/config.ts
CHANGED
|
@@ -32,6 +32,29 @@ export interface BotConfig {
|
|
|
32
32
|
maxRetries: number;
|
|
33
33
|
retryDelayMs: number;
|
|
34
34
|
retryBackoffMultiplier: number;
|
|
35
|
+
|
|
36
|
+
// Risk Keeper Configuration (optional)
|
|
37
|
+
riskKeeper?: {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
sApUSDAddress: Address;
|
|
40
|
+
routerAddress: Address;
|
|
41
|
+
wbnbAddress: Address;
|
|
42
|
+
privateKey: `0x${string}`;
|
|
43
|
+
sm2CooldownMs: number;
|
|
44
|
+
sm2MaxPoolPercent: number;
|
|
45
|
+
twapIntervalMs: number;
|
|
46
|
+
twapPercentage: number;
|
|
47
|
+
maxSlippageBps: number;
|
|
48
|
+
twapStartCR: bigint;
|
|
49
|
+
maxVolatilityPercent: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Fee Manager Configuration (optional)
|
|
53
|
+
feeManager?: {
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
privateKey: `0x${string}`;
|
|
56
|
+
checkIntervalMs: number;
|
|
57
|
+
};
|
|
35
58
|
}
|
|
36
59
|
|
|
37
60
|
export function loadConfig(): BotConfig {
|
|
@@ -50,7 +73,7 @@ export function loadConfig(): BotConfig {
|
|
|
50
73
|
|
|
51
74
|
// Contract
|
|
52
75
|
diamondAddress: (process.env.DIAMOND_ADDRESS ??
|
|
53
|
-
"
|
|
76
|
+
"0x6a11B30d3a70727d5477D6d8090e144443fA1c78") as Address,
|
|
54
77
|
|
|
55
78
|
// Intervals
|
|
56
79
|
statsReportInterval: parseInt(
|
|
@@ -80,5 +103,32 @@ export function loadConfig(): BotConfig {
|
|
|
80
103
|
maxRetries: parseInt(process.env.MAX_RETRIES ?? "3", 10),
|
|
81
104
|
retryDelayMs: parseInt(process.env.RETRY_DELAY_MS ?? "1000", 10),
|
|
82
105
|
retryBackoffMultiplier: parseFloat(process.env.RETRY_BACKOFF ?? "2"),
|
|
106
|
+
|
|
107
|
+
// Risk Keeper (optional - only enabled if private key is provided)
|
|
108
|
+
riskKeeper: process.env.KEEPER_PRIVATE_KEY
|
|
109
|
+
? {
|
|
110
|
+
enabled: process.env.RISK_KEEPER_ENABLED === "true",
|
|
111
|
+
sApUSDAddress: (process.env.SAPUSD_ADDRESS ?? "") as Address,
|
|
112
|
+
routerAddress: (process.env.ROUTER_ADDRESS ?? "0x10ED43C718714eb63d5aA57B78B54704E256024E") as Address, // PancakeSwap V2
|
|
113
|
+
wbnbAddress: (process.env.WBNB_ADDRESS ?? "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c") as Address,
|
|
114
|
+
privateKey: process.env.KEEPER_PRIVATE_KEY as `0x${string}`,
|
|
115
|
+
sm2CooldownMs: parseInt(process.env.SM2_COOLDOWN_MS ?? "1800000", 10), // 30 min
|
|
116
|
+
sm2MaxPoolPercent: parseInt(process.env.SM2_MAX_POOL_PERCENT ?? "40", 10), // 40%
|
|
117
|
+
twapIntervalMs: parseInt(process.env.TWAP_INTERVAL_MS ?? "600000", 10), // 10 min
|
|
118
|
+
twapPercentage: parseInt(process.env.TWAP_PERCENTAGE ?? "5", 10), // 5%
|
|
119
|
+
maxSlippageBps: parseInt(process.env.MAX_SLIPPAGE_BPS ?? "50", 10), // 0.5%
|
|
120
|
+
twapStartCR: BigInt(process.env.TWAP_START_CR ?? "13500"), // 135%
|
|
121
|
+
maxVolatilityPercent: parseInt(process.env.MAX_VOLATILITY_PERCENT ?? "5", 10), // 5%
|
|
122
|
+
}
|
|
123
|
+
: undefined,
|
|
124
|
+
|
|
125
|
+
// Fee Manager (optional - uses same or different private key)
|
|
126
|
+
feeManager: process.env.FEE_MANAGER_ENABLED === "true" && process.env.FEE_MANAGER_PRIVATE_KEY
|
|
127
|
+
? {
|
|
128
|
+
enabled: true,
|
|
129
|
+
privateKey: process.env.FEE_MANAGER_PRIVATE_KEY as `0x${string}`,
|
|
130
|
+
checkIntervalMs: parseInt(process.env.FEE_CHECK_INTERVAL_MS ?? "60000", 10), // 1 min
|
|
131
|
+
}
|
|
132
|
+
: undefined,
|
|
83
133
|
};
|
|
84
134
|
}
|