h-agent-swap 3.0.8 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h-agent-swap",
3
- "version": "3.0.8",
3
+ "version": "3.1.1",
4
4
  "description": "agent-swap",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -0,0 +1,520 @@
1
+ {
2
+ "_format": "hh-sol-artifact-1",
3
+ "contractName": "Treasury",
4
+ "sourceName": "contracts/Treasury.sol",
5
+ "abi": [
6
+ {
7
+ "inputs": [
8
+ {
9
+ "internalType": "address",
10
+ "name": "_route",
11
+ "type": "address"
12
+ }
13
+ ],
14
+ "stateMutability": "nonpayable",
15
+ "type": "constructor"
16
+ },
17
+ {
18
+ "anonymous": false,
19
+ "inputs": [
20
+ {
21
+ "indexed": true,
22
+ "internalType": "address",
23
+ "name": "previousOwner",
24
+ "type": "address"
25
+ },
26
+ {
27
+ "indexed": true,
28
+ "internalType": "address",
29
+ "name": "newOwner",
30
+ "type": "address"
31
+ }
32
+ ],
33
+ "name": "OwnershipTransferred",
34
+ "type": "event"
35
+ },
36
+ {
37
+ "anonymous": false,
38
+ "inputs": [
39
+ {
40
+ "indexed": false,
41
+ "internalType": "uint256",
42
+ "name": "price",
43
+ "type": "uint256"
44
+ },
45
+ {
46
+ "indexed": false,
47
+ "internalType": "bool",
48
+ "name": "strict",
49
+ "type": "bool"
50
+ }
51
+ ],
52
+ "name": "TwapAveragePrice",
53
+ "type": "event"
54
+ },
55
+ {
56
+ "stateMutability": "payable",
57
+ "type": "fallback"
58
+ },
59
+ {
60
+ "inputs": [
61
+ {
62
+ "internalType": "uint256",
63
+ "name": "amount",
64
+ "type": "uint256"
65
+ },
66
+ {
67
+ "internalType": "address[]",
68
+ "name": "path",
69
+ "type": "address[]"
70
+ },
71
+ {
72
+ "internalType": "uint256",
73
+ "name": "side",
74
+ "type": "uint256"
75
+ },
76
+ {
77
+ "internalType": "uint256",
78
+ "name": "point",
79
+ "type": "uint256"
80
+ }
81
+ ],
82
+ "name": "computeAmount",
83
+ "outputs": [
84
+ {
85
+ "internalType": "uint256",
86
+ "name": "result",
87
+ "type": "uint256"
88
+ }
89
+ ],
90
+ "stateMutability": "view",
91
+ "type": "function"
92
+ },
93
+ {
94
+ "inputs": [
95
+ {
96
+ "internalType": "address",
97
+ "name": "tokenIn",
98
+ "type": "address"
99
+ },
100
+ {
101
+ "internalType": "address",
102
+ "name": "tokenOut",
103
+ "type": "address"
104
+ }
105
+ ],
106
+ "name": "getTwapSnapshots",
107
+ "outputs": [
108
+ {
109
+ "components": [
110
+ {
111
+ "internalType": "uint32",
112
+ "name": "timestamp",
113
+ "type": "uint32"
114
+ },
115
+ {
116
+ "internalType": "uint256",
117
+ "name": "price0Cumulative",
118
+ "type": "uint256"
119
+ },
120
+ {
121
+ "internalType": "uint256",
122
+ "name": "price1Cumulative",
123
+ "type": "uint256"
124
+ }
125
+ ],
126
+ "internalType": "struct Treasury.TwapSnapshot",
127
+ "name": "result",
128
+ "type": "tuple"
129
+ },
130
+ {
131
+ "internalType": "uint256",
132
+ "name": "price0",
133
+ "type": "uint256"
134
+ },
135
+ {
136
+ "internalType": "uint256",
137
+ "name": "price1",
138
+ "type": "uint256"
139
+ }
140
+ ],
141
+ "stateMutability": "view",
142
+ "type": "function"
143
+ },
144
+ {
145
+ "inputs": [],
146
+ "name": "logView",
147
+ "outputs": [
148
+ {
149
+ "internalType": "bool",
150
+ "name": "",
151
+ "type": "bool"
152
+ }
153
+ ],
154
+ "stateMutability": "view",
155
+ "type": "function"
156
+ },
157
+ {
158
+ "inputs": [],
159
+ "name": "maxAllowedOffset",
160
+ "outputs": [
161
+ {
162
+ "internalType": "uint256",
163
+ "name": "",
164
+ "type": "uint256"
165
+ }
166
+ ],
167
+ "stateMutability": "view",
168
+ "type": "function"
169
+ },
170
+ {
171
+ "inputs": [],
172
+ "name": "maxSwapRatioBps",
173
+ "outputs": [
174
+ {
175
+ "internalType": "uint256",
176
+ "name": "",
177
+ "type": "uint256"
178
+ }
179
+ ],
180
+ "stateMutability": "view",
181
+ "type": "function"
182
+ },
183
+ {
184
+ "inputs": [],
185
+ "name": "owner",
186
+ "outputs": [
187
+ {
188
+ "internalType": "address",
189
+ "name": "",
190
+ "type": "address"
191
+ }
192
+ ],
193
+ "stateMutability": "view",
194
+ "type": "function"
195
+ },
196
+ {
197
+ "inputs": [
198
+ {
199
+ "internalType": "address",
200
+ "name": "tokenA",
201
+ "type": "address"
202
+ },
203
+ {
204
+ "internalType": "address",
205
+ "name": "tokenB",
206
+ "type": "address"
207
+ }
208
+ ],
209
+ "name": "pairKey",
210
+ "outputs": [
211
+ {
212
+ "internalType": "bytes32",
213
+ "name": "key",
214
+ "type": "bytes32"
215
+ }
216
+ ],
217
+ "stateMutability": "view",
218
+ "type": "function"
219
+ },
220
+ {
221
+ "inputs": [
222
+ {
223
+ "internalType": "uint256",
224
+ "name": "amount",
225
+ "type": "uint256"
226
+ },
227
+ {
228
+ "internalType": "uint256",
229
+ "name": "rate",
230
+ "type": "uint256"
231
+ }
232
+ ],
233
+ "name": "percentage",
234
+ "outputs": [
235
+ {
236
+ "internalType": "uint256",
237
+ "name": "result",
238
+ "type": "uint256"
239
+ }
240
+ ],
241
+ "stateMutability": "view",
242
+ "type": "function"
243
+ },
244
+ {
245
+ "inputs": [],
246
+ "name": "pointMax",
247
+ "outputs": [
248
+ {
249
+ "internalType": "uint256",
250
+ "name": "",
251
+ "type": "uint256"
252
+ }
253
+ ],
254
+ "stateMutability": "view",
255
+ "type": "function"
256
+ },
257
+ {
258
+ "inputs": [],
259
+ "name": "renounceOwnership",
260
+ "outputs": [],
261
+ "stateMutability": "nonpayable",
262
+ "type": "function"
263
+ },
264
+ {
265
+ "inputs": [],
266
+ "name": "route",
267
+ "outputs": [
268
+ {
269
+ "internalType": "address",
270
+ "name": "",
271
+ "type": "address"
272
+ }
273
+ ],
274
+ "stateMutability": "view",
275
+ "type": "function"
276
+ },
277
+ {
278
+ "inputs": [
279
+ {
280
+ "internalType": "bool",
281
+ "name": "_use",
282
+ "type": "bool"
283
+ }
284
+ ],
285
+ "name": "setLogView",
286
+ "outputs": [],
287
+ "stateMutability": "nonpayable",
288
+ "type": "function"
289
+ },
290
+ {
291
+ "inputs": [
292
+ {
293
+ "internalType": "uint256",
294
+ "name": "point",
295
+ "type": "uint256"
296
+ }
297
+ ],
298
+ "name": "setMaxAllowedOffset",
299
+ "outputs": [],
300
+ "stateMutability": "nonpayable",
301
+ "type": "function"
302
+ },
303
+ {
304
+ "inputs": [
305
+ {
306
+ "internalType": "uint256",
307
+ "name": "ratio",
308
+ "type": "uint256"
309
+ }
310
+ ],
311
+ "name": "setMaxSwapRatioBps",
312
+ "outputs": [],
313
+ "stateMutability": "nonpayable",
314
+ "type": "function"
315
+ },
316
+ {
317
+ "inputs": [
318
+ {
319
+ "internalType": "uint32",
320
+ "name": "_period",
321
+ "type": "uint32"
322
+ }
323
+ ],
324
+ "name": "setTwapPeriod",
325
+ "outputs": [],
326
+ "stateMutability": "nonpayable",
327
+ "type": "function"
328
+ },
329
+ {
330
+ "inputs": [
331
+ {
332
+ "internalType": "address",
333
+ "name": "_route",
334
+ "type": "address"
335
+ }
336
+ ],
337
+ "name": "setting",
338
+ "outputs": [],
339
+ "stateMutability": "nonpayable",
340
+ "type": "function"
341
+ },
342
+ {
343
+ "inputs": [
344
+ {
345
+ "internalType": "address[]",
346
+ "name": "path",
347
+ "type": "address[]"
348
+ },
349
+ {
350
+ "internalType": "uint256",
351
+ "name": "inAmount",
352
+ "type": "uint256"
353
+ },
354
+ {
355
+ "internalType": "uint256",
356
+ "name": "outAmountMin",
357
+ "type": "uint256"
358
+ },
359
+ {
360
+ "internalType": "uint256",
361
+ "name": "deadline",
362
+ "type": "uint256"
363
+ },
364
+ {
365
+ "internalType": "uint256",
366
+ "name": "point",
367
+ "type": "uint256"
368
+ }
369
+ ],
370
+ "name": "swap",
371
+ "outputs": [],
372
+ "stateMutability": "nonpayable",
373
+ "type": "function"
374
+ },
375
+ {
376
+ "inputs": [
377
+ {
378
+ "internalType": "address",
379
+ "name": "tokenIn",
380
+ "type": "address"
381
+ },
382
+ {
383
+ "internalType": "address",
384
+ "name": "tokenOut",
385
+ "type": "address"
386
+ }
387
+ ],
388
+ "name": "sync",
389
+ "outputs": [],
390
+ "stateMutability": "nonpayable",
391
+ "type": "function"
392
+ },
393
+ {
394
+ "inputs": [
395
+ {
396
+ "internalType": "address",
397
+ "name": "_token",
398
+ "type": "address"
399
+ },
400
+ {
401
+ "internalType": "address",
402
+ "name": "_recipient",
403
+ "type": "address"
404
+ },
405
+ {
406
+ "internalType": "uint256",
407
+ "name": "_amount",
408
+ "type": "uint256"
409
+ }
410
+ ],
411
+ "name": "tokenSend",
412
+ "outputs": [],
413
+ "stateMutability": "nonpayable",
414
+ "type": "function"
415
+ },
416
+ {
417
+ "inputs": [
418
+ {
419
+ "internalType": "address",
420
+ "name": "newOwner",
421
+ "type": "address"
422
+ }
423
+ ],
424
+ "name": "transferOwnership",
425
+ "outputs": [],
426
+ "stateMutability": "nonpayable",
427
+ "type": "function"
428
+ },
429
+ {
430
+ "inputs": [
431
+ {
432
+ "internalType": "bytes32",
433
+ "name": "",
434
+ "type": "bytes32"
435
+ }
436
+ ],
437
+ "name": "twapLastUpdatedAt",
438
+ "outputs": [
439
+ {
440
+ "internalType": "uint32",
441
+ "name": "",
442
+ "type": "uint32"
443
+ }
444
+ ],
445
+ "stateMutability": "view",
446
+ "type": "function"
447
+ },
448
+ {
449
+ "inputs": [],
450
+ "name": "twapPeriod",
451
+ "outputs": [
452
+ {
453
+ "internalType": "uint32",
454
+ "name": "",
455
+ "type": "uint32"
456
+ }
457
+ ],
458
+ "stateMutability": "view",
459
+ "type": "function"
460
+ },
461
+ {
462
+ "inputs": [
463
+ {
464
+ "internalType": "address",
465
+ "name": "_whiter",
466
+ "type": "address"
467
+ },
468
+ {
469
+ "internalType": "bool",
470
+ "name": "_open",
471
+ "type": "bool"
472
+ }
473
+ ],
474
+ "name": "updateWhite",
475
+ "outputs": [],
476
+ "stateMutability": "nonpayable",
477
+ "type": "function"
478
+ },
479
+ {
480
+ "inputs": [],
481
+ "name": "weth",
482
+ "outputs": [
483
+ {
484
+ "internalType": "address",
485
+ "name": "",
486
+ "type": "address"
487
+ }
488
+ ],
489
+ "stateMutability": "view",
490
+ "type": "function"
491
+ },
492
+ {
493
+ "inputs": [
494
+ {
495
+ "internalType": "address",
496
+ "name": "",
497
+ "type": "address"
498
+ }
499
+ ],
500
+ "name": "whitelist",
501
+ "outputs": [
502
+ {
503
+ "internalType": "bool",
504
+ "name": "",
505
+ "type": "bool"
506
+ }
507
+ ],
508
+ "stateMutability": "view",
509
+ "type": "function"
510
+ },
511
+ {
512
+ "stateMutability": "payable",
513
+ "type": "receive"
514
+ }
515
+ ],
516
+ "bytecode": "0x60806040526009805464ffffffffff191661012c1790556305f5e100600a819055600b819055600c553480156200003557600080fd5b5060405162002c1238038062002c128339810160408190526200005891620001e1565b620000633362000093565b600180556200007281620000e3565b50336000908152600460205260409020805460ff1916600117905562000213565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6001600160a01b0381166200013e5760405162461bcd60e51b815260206004820152601f60248201527f54726561737572793a3a696e76616c696420726f757465206164647265737300604482015260640160405180910390fd5b600380546001600160a01b0319166001600160a01b038316908117909155604080516315ab88c960e31b8152905163ad5c4648916004808201926020929091908290030181865afa15801562000198573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001be9190620001e1565b600280546001600160a01b0319166001600160a01b039290921691909117905550565b600060208284031215620001f457600080fd5b81516001600160a01b03811681146200020c57600080fd5b9392505050565b6129ef80620002236000396000f3fe60806040526004361061015a5760003560e01c8063868c9abc116100c8578063cd27ca8211610084578063f108f87611610061578063f108f8761461045a578063f2fde38b146104a2578063f6207326146104c2578063f9c95d46146104df57005b8063cd27ca82146103fa578063d96661ef1461041a578063ee924d861461043a57005b8063868c9abc1461032c5780638da5cb5b1461034c57806390d436971461036a5780639b19251a1461038a578063aa5d448f146103ba578063c04606f0146103da57005b80632d52aa4e116101175780632d52aa4e146102225780633041949b146102545780633fc8cef31461027457806348c8cd6c146102ac5780635e5ce281146102c2578063715018a61461031757005b806206741114610163578063016eb8a81461018c57806304c8c100146101ac5780630d83b1e4146101cc5780631b153401146101e25780632bd2c18d1461020257005b3661016157005b005b34801561016f57600080fd5b50610179600c5481565b6040519081526020015b60405180910390f35b34801561019857600080fd5b506101796101a7366004612371565b6104ff565b3480156101b857600080fd5b506101616101c73660046123b6565b610520565b3480156101d857600080fd5b50610179600a5481565b3480156101ee57600080fd5b506101616101fd3660046123ef565b61057e565b34801561020e57600080fd5b5061017961021d36600461250f565b6105fa565b34801561022e57600080fd5b5060095461024490640100000000900460ff1681565b6040519015158152602001610183565b34801561026057600080fd5b5061016161026f366004612566565b61064f565b34801561028057600080fd5b50600254610294906001600160a01b031681565b6040516001600160a01b039091168152602001610183565b3480156102b857600080fd5b50610179600b5481565b3480156102ce57600080fd5b506102e26102dd366004612566565b610711565b60408051845163ffffffff1681526020808601519082015293810151908401526060830191909152608082015260a001610183565b34801561032357600080fd5b5061016161082c565b34801561033857600080fd5b50610161610347366004612594565b610862565b34801561035857600080fd5b506000546001600160a01b0316610294565b34801561037657600080fd5b506101616103853660046125ad565b610891565b34801561039657600080fd5b506102446103a536600461260a565b60046020526000908152604090205460ff1681565b3480156103c657600080fd5b506101616103d536600461260a565b610aa8565b3480156103e657600080fd5b506101616103f5366004612594565b610ade565b34801561040657600080fd5b50610179610415366004612566565b610b0d565b34801561042657600080fd5b50600354610294906001600160a01b031681565b34801561044657600080fd5b50610161610455366004612627565b610b3a565b34801561046657600080fd5b5061048d610475366004612594565b60076020526000908152604090205463ffffffff1681565b60405163ffffffff9091168152602001610183565b3480156104ae57600080fd5b506101616104bd36600461260a565b610b84565b3480156104ce57600080fd5b5060095461048d9063ffffffff1681565b3480156104eb57600080fd5b506101616104fa366004612656565b610c1c565b600a54600090610519906105138585610c62565b90610c6e565b9392505050565b6000546001600160a01b031633146105535760405162461bcd60e51b815260040161054a90612673565b60405180910390fd5b6001600160a01b03919091166000908152600460205260409020805460ff1916911515919091179055565b6000546001600160a01b031633146105a85760405162461bcd60e51b815260040161054a90612673565b6105b3838383610c7a565b6105f55760405162461bcd60e51b8152602060048201526013602482015272151c99585cdd5c9e4e8e9cd95b990819985a5b606a1b604482015260640161054a565b505050565b600080808481036106275761060f8787610cb1565b915061061d84836000610dcb565b9150819250610645565b6106318787610e65565b905061063f84826001610dcb565b90508092505b5050949350505050565b3360009081526004602052604090205460ff166106a75760405162461bcd60e51b815260206004820152601660248201527514ddd85c149bdd5d195c8e881b1a5b5a5d0818d85b1b60521b604482015260640161054a565b60006001600160a01b038316156106be57826106cb565b6002546001600160a01b03165b905060006001600160a01b038316156106e457826106f1565b6002546001600160a01b03165b60095490915061070a908390839063ffffffff16610f64565b5050505050565b61073b6040518060600160405280600063ffffffff16815260200160008152602001600081525090565b6009546000908190640100000000900460ff1661077857505060408051606081018252600080825260208201819052918101829052915080610825565b60006001600160a01b0386161561078f578561079c565b6002546001600160a01b03165b905060006001600160a01b038616156107b557856107c2565b6002546001600160a01b03165b905060006107d083836111d0565b60008181526008602090815260408083208151606081018352815463ffffffff168152600182015481850152600290910154818301529383526005825280832054600690925290912054919750955093505050505b9250925092565b6000546001600160a01b031633146108565760405162461bcd60e51b815260040161054a90612673565b6108606000611261565b565b6000546001600160a01b0316331461088c5760405162461bcd60e51b815260040161054a90612673565b600c55565b6108996112b1565b3360009081526004602052604090205460ff166108f15760405162461bcd60e51b815260206004820152601660248201527514ddd85c149bdd5d195c8e881b1a5b5a5d0818d85b1b60521b604482015260640161054a565b6000604051806040016040528061092188600081518110610914576109146126a8565b602002602001015161130a565b815260200187600081518110610939576109396126a8565b60200260200101516001600160a01b031681525090506000604051806040016040528061097e8960018b5161096e91906126d4565b81518110610914576109146126a8565b81526020018860018a5161099291906126d4565b815181106109a2576109a26126a8565b60200260200101516001600160a01b0316815250905060006109c48789610cb1565b90506109d284826000610dcb565b905060006109e584848a858d8b30611348565b905081811015610a375760405162461bcd60e51b815260206004820152601c60248201527f54726561737572793a3a42656c6f77206578706563746174696f6e7300000000604482015260640161054a565b610a4b846020015184602001518a84611599565b86811015610a9b5760405162461bcd60e51b815260206004820152601d60248201527f54726561737572793a3a496e73756666696369656e74206f7574707574000000604482015260640161054a565b5050505061070a60018055565b6000546001600160a01b03163314610ad25760405162461bcd60e51b815260040161054a90612673565b610adb816116e8565b50565b6000546001600160a01b03163314610b085760405162461bcd60e51b815260040161054a90612673565b600b55565b600954600090640100000000900460ff16610b2a57506000610b34565b61051983836111d0565b92915050565b6000546001600160a01b03163314610b645760405162461bcd60e51b815260040161054a90612673565b600980549115156401000000000264ff0000000019909216919091179055565b6000546001600160a01b03163314610bae5760405162461bcd60e51b815260040161054a90612673565b6001600160a01b038116610c135760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161054a565b610adb81611261565b6000546001600160a01b03163314610c465760405162461bcd60e51b815260040161054a90612673565b6009805463ffffffff191663ffffffff92909216919091179055565b600061051982846126eb565b6000610519828461270a565b60006001600160a01b038416610c9c57610c9483836117de565b506001610519565b610ca78484846118f7565b5060019392505050565b60035460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f90610ce89087908790600401612770565b600060405180830381865afa158015610d05573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d2d9190810190612789565b905080610d4560018351611a2190919063ffffffff16565b81518110610d5557610d556126a8565b6020026020010151915060008211610dc45760405162461bcd60e51b815260206004820152602c60248201527f54726561737572793a3a6f7574416d6f756e742073686f756c6420626520677260448201526b06561746572207468616e20360a41b606482015260840161054a565b5092915050565b60006002600a54610ddc919061270a565b841115610e1f5760405162461bcd60e51b815260206004820152601160248201527054726561737572793a3a4d61782035302560781b604482015260640161054a565b60018215610e3b57600a54610e349086611a2d565b9050610e4b565b600a54610e489086611a21565b90505b600a54610e5c906105138684610c62565b95945050505050565b6003546040516307c0329d60e21b815260009182916001600160a01b0390911690631f00ca7490610e9c9087908790600401612770565b600060405180830381865afa158015610eb9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ee19190810190612789565b905080600081518110610ef657610ef66126a8565b6020026020010151915060008211610dc45760405162461bcd60e51b815260206004820152602b60248201527f54726561737572793a3a696e416d6f756e742073686f756c642062652067726560448201526a061746572207468616e20360ac1b606482015260840161054a565b600080610f7185856111d0565b6000818152600860205260408120919250610f8c8787611a39565b5090506000806000610f9d84611c09565b8754929550909350915063ffffffff16600003610fe657845463ffffffff191663ffffffff91909116178455600184019190915560029092019190915550600091506105199050565b8454600090610ffb9063ffffffff168361281a565b90508863ffffffff168163ffffffff161015611021576000975050505050505050610519565b60008163ffffffff1687600101548661103a91906126d4565b611044919061270a565b905060008263ffffffff1688600201548661105f91906126d4565b611069919061270a565b905061108282670de0b6b3a7640000600160701b611df3565b60008a8152600560205260409020556110a881670de0b6b3a7640000600160701b611df3565b60008a81526006602090815260408083209390935560059052205461111b5760405162461bcd60e51b815260206004820152602360248201527f54726561737572793a3a496e76616c696420545741502028707269636530547760448201526261702960e81b606482015260840161054a565b6000898152600660205260409020546111825760405162461bcd60e51b815260206004820152602360248201527f54726561737572793a3a496e76616c696420545741502028707269636531547760448201526261702960e81b606482015260840161054a565b505050600095865260076020526040909520805463ffffffff1990811663ffffffff909716968717909155845416909417835560018381019190915560029092019290925595945050505050565b6000816001600160a01b0316836001600160a01b03161015611233576040516bffffffffffffffffffffffff19606085811b8216602084015284901b1660348201526048015b604051602081830303815290604052805190602001209050610b34565b6040516bffffffffffffffffffffffff19606084811b8216602084015285901b166034820152604801611216565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6002600154036113035760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161054a565b6002600155565b60006001600160a01b03821661132257506001919050565b6002546001600160a01b039081169083160361134057506002919050565b506003919050565b865160009060030361137057602088015160035461137091906001600160a01b031688611e62565b60606000896000015160011480611388575089516002145b905060008960000151600114806113a0575089516002145b9050811580156113ae575080155b15611439576003546040516338ed173960e01b81526001600160a01b03909116906338ed1739906113eb908c908c908c908b908d9060040161283f565b6000604051808303816000875af115801561140a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114329190810190612789565b9250611562565b818015611444575080155b156114c857600354604051637ff36ab560e01b81526001600160a01b0390911690637ff36ab5908b90611481908c908c908b908d9060040161287b565b60006040518083038185885af115801561149f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526114329190810190612789565b811580156114d35750805b15611510576003546040516318cbafe560e01b81526001600160a01b03909116906318cbafe5906113eb908c908c908c908b908d9060040161283f565b60405162461bcd60e51b815260206004820152602160248201527f54726561737572793a3a4554483c2d3e455448206e6f7420737570706f7274656044820152601960fa1b606482015260840161054a565b826001845161157191906126d4565b81518110611581576115816126a8565b60200260200101519350505050979650505050505050565b6000821180156115a95750600081115b6115ed5760405162461bcd60e51b8152602060048201526015602482015274151c99585cdd5c9e4e8e96995c9bc8185b5bdd5b9d605a1b604482015260640161054a565b6000806115fa8686611f8a565b915091508061160a5750506116e2565b60008461161f85670de0b6b3a76400006126eb565b611629919061270a565b90506000600a54600b548561163e91906126eb565b611648919061270a565b9050600081851161165a576000611664565b61166482866126d4565b9050600061167283876128b0565b90508184101580156116845750808411155b6116db5760405162461bcd60e51b815260206004820152602260248201527f54726561737572793a3a507269636520646576696174696f6e20746f6f2068696044820152610ced60f31b606482015260840161054a565b5050505050505b50505050565b6001600160a01b03811661173e5760405162461bcd60e51b815260206004820152601f60248201527f54726561737572793a3a696e76616c696420726f757465206164647265737300604482015260640161054a565b600380546001600160a01b0319166001600160a01b038316908117909155604080516315ab88c960e31b8152905163ad5c4648916004808201926020929091908290030181865afa158015611797573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117bb91906128c8565b600280546001600160a01b0319166001600160a01b039290921691909117905550565b8047101561182e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161054a565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461187b576040519150601f19603f3d011682016040523d82523d6000602084013e611880565b606091505b50509050806105f55760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161054a565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b179052915160009283929087169161195391906128e5565b6000604051808303816000865af19150503d8060008114611990576040519150601f19603f3d011682016040523d82523d6000602084013e611995565b606091505b50915091508180156119bf5750805115806119bf5750808060200190518101906119bf9190612920565b61070a5760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b606482015260840161054a565b600061051982846126d4565b600061051982846128b0565b6000806000600360009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab591906128c8565b60405163e6a4390560e01b81526001600160a01b038781166004830152868116602483015291925060009183169063e6a4390590604401602060405180830381865afa158015611b09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2d91906128c8565b90506001600160a01b038116611b855760405162461bcd60e51b815260206004820152601860248201527f54726561737572793a3a50616972206e6f742065786973740000000000000000604482015260640161054a565b809350836001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611bc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bea91906128c8565b6001600160a01b0316866001600160a01b031614925050509250929050565b6000806000836001600160a01b0316635909c0d56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c70919061293d565b9250836001600160a01b0316635a3d54936040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd4919061293d565b91506000806000866001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611d19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3d9190612972565b9250925092504293508363ffffffff168163ffffffff1614611de9576000611d65828661281a565b905063ffffffff8116611d916001600160701b038616600160701b600160e01b03607087901b1661270a565b611d9b91906126eb565b611da590886128b0565b965063ffffffff8116611dd16001600160701b038516600160701b600160e01b03607088901b1661270a565b611ddb91906126eb565b611de590876128b0565b9550505b5050509193909250565b600081600003611e455760405162461bcd60e51b815260206004820152601860248201527f6d756c4469763a206469766973696f6e206279207a65726f0000000000000000604482015260640161054a565b81611e5084866126eb565b611e5a919061270a565b949350505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1790529151600092839290871691611ebe91906128e5565b6000604051808303816000865af19150503d8060008114611efb576040519150601f19603f3d011682016040523d82523d6000602084013e611f00565b606091505b5091509150818015611f2a575080511580611f2a575080806020019051810190611f2a9190612920565b61070a5760405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b606482015260840161054a565b600080806001600160a01b03851615611fa35784611fb0565b6002546001600160a01b03165b905060006001600160a01b03851615611fc95784611fd6565b6002546001600160a01b03165b90506000611fe483836111d0565b600954909150611ffd908490849063ffffffff16610f64565b5060008181526007602052604090205463ffffffff1680158061202c5750600082815260056020526040902054155b806120435750600082815260066020526040902054155b156120af576120528484612148565b60095490965060009550640100000000900460ff16156120a65760408051878152600060208201527ffb3582a7ead56856e76f4dd65cb289a4eab99d7838c6ab0c08ea8dc71c51ae85910160405180910390a15b50505050612141565b60006120bb8585611a39565b915050806120d7576000838152600660205260409020546120e7565b6000838152600560205260409020545b600954909750640100000000900460ff16156121375760408051888152600160208201527ffb3582a7ead56856e76f4dd65cb289a4eab99d7838c6ab0c08ea8dc71c51ae85910160405180910390a15b6001955050505050505b9250929050565b600080600061215785856121cd565b9150915060008211801561216b5750600081115b6121b05760405162461bcd60e51b815260206004820152601660248201527554726561737572793a3a4e6f206c697175696469747960501b604482015260640161054a565b816121c382670de0b6b3a76400006126eb565b610e5c919061270a565b6000806000600360009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015612225573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061224991906128c8565b60405163e6a4390560e01b81526001600160a01b0387811660048301528681166024830152919091169063e6a4390590604401602060405180830381865afa158015612299573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122bd91906128c8565b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015612300573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123249190612972565b506001600160701b031691506001600160701b03169150856001600160a01b0316876001600160a01b0316101561236057819450809350612367565b8094508193505b5050509250929050565b6000806040838503121561238457600080fd5b50508035926020909101359150565b6001600160a01b0381168114610adb57600080fd5b8015158114610adb57600080fd5b600080604083850312156123c957600080fd5b82356123d481612393565b915060208301356123e4816123a8565b809150509250929050565b60008060006060848603121561240457600080fd5b833561240f81612393565b9250602084013561241f81612393565b929592945050506040919091013590565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561246f5761246f612430565b604052919050565b600067ffffffffffffffff82111561249157612491612430565b5060051b60200190565b600082601f8301126124ac57600080fd5b813560206124c16124bc83612477565b612446565b82815260059290921b840181019181810190868411156124e057600080fd5b8286015b848110156125045780356124f781612393565b83529183019183016124e4565b509695505050505050565b6000806000806080858703121561252557600080fd5b84359350602085013567ffffffffffffffff81111561254357600080fd5b61254f8782880161249b565b949794965050505060408301359260600135919050565b6000806040838503121561257957600080fd5b823561258481612393565b915060208301356123e481612393565b6000602082840312156125a657600080fd5b5035919050565b600080600080600060a086880312156125c557600080fd5b853567ffffffffffffffff8111156125dc57600080fd5b6125e88882890161249b565b9860208801359850604088013597606081013597506080013595509350505050565b60006020828403121561261c57600080fd5b813561051981612393565b60006020828403121561263957600080fd5b8135610519816123a8565b63ffffffff81168114610adb57600080fd5b60006020828403121561266857600080fd5b813561051981612644565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156126e6576126e66126be565b500390565b6000816000190483118215151615612705576127056126be565b500290565b60008261272757634e487b7160e01b600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b838110156127655781516001600160a01b031687529582019590820190600101612740565b509495945050505050565b828152604060208201526000611e5a604083018461272c565b6000602080838503121561279c57600080fd5b825167ffffffffffffffff8111156127b357600080fd5b8301601f810185136127c457600080fd5b80516127d26124bc82612477565b81815260059190911b820183019083810190878311156127f157600080fd5b928401925b8284101561280f578351825292840192908401906127f6565b979650505050505050565b600063ffffffff83811690831681811015612837576128376126be565b039392505050565b85815284602082015260a06040820152600061285e60a083018661272c565b6001600160a01b0394909416606083015250608001529392505050565b848152608060208201526000612894608083018661272c565b6001600160a01b03949094166040830152506060015292915050565b600082198211156128c3576128c36126be565b500190565b6000602082840312156128da57600080fd5b815161051981612393565b6000825160005b8181101561290657602081860181015185830152016128ec565b81811115612915576000828501525b509190910192915050565b60006020828403121561293257600080fd5b8151610519816123a8565b60006020828403121561294f57600080fd5b5051919050565b80516001600160701b038116811461296d57600080fd5b919050565b60008060006060848603121561298757600080fd5b61299084612956565b925061299e60208501612956565b915060408401516129ae81612644565b80915050925092509256fea2646970667358221220979e2ea547e40f2cddad9c7095455d59f5bd75811491879c30ecb3ffc048adde64736f6c634300080e0033",
517
+ "deployedBytecode": "0x60806040526004361061015a5760003560e01c8063868c9abc116100c8578063cd27ca8211610084578063f108f87611610061578063f108f8761461045a578063f2fde38b146104a2578063f6207326146104c2578063f9c95d46146104df57005b8063cd27ca82146103fa578063d96661ef1461041a578063ee924d861461043a57005b8063868c9abc1461032c5780638da5cb5b1461034c57806390d436971461036a5780639b19251a1461038a578063aa5d448f146103ba578063c04606f0146103da57005b80632d52aa4e116101175780632d52aa4e146102225780633041949b146102545780633fc8cef31461027457806348c8cd6c146102ac5780635e5ce281146102c2578063715018a61461031757005b806206741114610163578063016eb8a81461018c57806304c8c100146101ac5780630d83b1e4146101cc5780631b153401146101e25780632bd2c18d1461020257005b3661016157005b005b34801561016f57600080fd5b50610179600c5481565b6040519081526020015b60405180910390f35b34801561019857600080fd5b506101796101a7366004612371565b6104ff565b3480156101b857600080fd5b506101616101c73660046123b6565b610520565b3480156101d857600080fd5b50610179600a5481565b3480156101ee57600080fd5b506101616101fd3660046123ef565b61057e565b34801561020e57600080fd5b5061017961021d36600461250f565b6105fa565b34801561022e57600080fd5b5060095461024490640100000000900460ff1681565b6040519015158152602001610183565b34801561026057600080fd5b5061016161026f366004612566565b61064f565b34801561028057600080fd5b50600254610294906001600160a01b031681565b6040516001600160a01b039091168152602001610183565b3480156102b857600080fd5b50610179600b5481565b3480156102ce57600080fd5b506102e26102dd366004612566565b610711565b60408051845163ffffffff1681526020808601519082015293810151908401526060830191909152608082015260a001610183565b34801561032357600080fd5b5061016161082c565b34801561033857600080fd5b50610161610347366004612594565b610862565b34801561035857600080fd5b506000546001600160a01b0316610294565b34801561037657600080fd5b506101616103853660046125ad565b610891565b34801561039657600080fd5b506102446103a536600461260a565b60046020526000908152604090205460ff1681565b3480156103c657600080fd5b506101616103d536600461260a565b610aa8565b3480156103e657600080fd5b506101616103f5366004612594565b610ade565b34801561040657600080fd5b50610179610415366004612566565b610b0d565b34801561042657600080fd5b50600354610294906001600160a01b031681565b34801561044657600080fd5b50610161610455366004612627565b610b3a565b34801561046657600080fd5b5061048d610475366004612594565b60076020526000908152604090205463ffffffff1681565b60405163ffffffff9091168152602001610183565b3480156104ae57600080fd5b506101616104bd36600461260a565b610b84565b3480156104ce57600080fd5b5060095461048d9063ffffffff1681565b3480156104eb57600080fd5b506101616104fa366004612656565b610c1c565b600a54600090610519906105138585610c62565b90610c6e565b9392505050565b6000546001600160a01b031633146105535760405162461bcd60e51b815260040161054a90612673565b60405180910390fd5b6001600160a01b03919091166000908152600460205260409020805460ff1916911515919091179055565b6000546001600160a01b031633146105a85760405162461bcd60e51b815260040161054a90612673565b6105b3838383610c7a565b6105f55760405162461bcd60e51b8152602060048201526013602482015272151c99585cdd5c9e4e8e9cd95b990819985a5b606a1b604482015260640161054a565b505050565b600080808481036106275761060f8787610cb1565b915061061d84836000610dcb565b9150819250610645565b6106318787610e65565b905061063f84826001610dcb565b90508092505b5050949350505050565b3360009081526004602052604090205460ff166106a75760405162461bcd60e51b815260206004820152601660248201527514ddd85c149bdd5d195c8e881b1a5b5a5d0818d85b1b60521b604482015260640161054a565b60006001600160a01b038316156106be57826106cb565b6002546001600160a01b03165b905060006001600160a01b038316156106e457826106f1565b6002546001600160a01b03165b60095490915061070a908390839063ffffffff16610f64565b5050505050565b61073b6040518060600160405280600063ffffffff16815260200160008152602001600081525090565b6009546000908190640100000000900460ff1661077857505060408051606081018252600080825260208201819052918101829052915080610825565b60006001600160a01b0386161561078f578561079c565b6002546001600160a01b03165b905060006001600160a01b038616156107b557856107c2565b6002546001600160a01b03165b905060006107d083836111d0565b60008181526008602090815260408083208151606081018352815463ffffffff168152600182015481850152600290910154818301529383526005825280832054600690925290912054919750955093505050505b9250925092565b6000546001600160a01b031633146108565760405162461bcd60e51b815260040161054a90612673565b6108606000611261565b565b6000546001600160a01b0316331461088c5760405162461bcd60e51b815260040161054a90612673565b600c55565b6108996112b1565b3360009081526004602052604090205460ff166108f15760405162461bcd60e51b815260206004820152601660248201527514ddd85c149bdd5d195c8e881b1a5b5a5d0818d85b1b60521b604482015260640161054a565b6000604051806040016040528061092188600081518110610914576109146126a8565b602002602001015161130a565b815260200187600081518110610939576109396126a8565b60200260200101516001600160a01b031681525090506000604051806040016040528061097e8960018b5161096e91906126d4565b81518110610914576109146126a8565b81526020018860018a5161099291906126d4565b815181106109a2576109a26126a8565b60200260200101516001600160a01b0316815250905060006109c48789610cb1565b90506109d284826000610dcb565b905060006109e584848a858d8b30611348565b905081811015610a375760405162461bcd60e51b815260206004820152601c60248201527f54726561737572793a3a42656c6f77206578706563746174696f6e7300000000604482015260640161054a565b610a4b846020015184602001518a84611599565b86811015610a9b5760405162461bcd60e51b815260206004820152601d60248201527f54726561737572793a3a496e73756666696369656e74206f7574707574000000604482015260640161054a565b5050505061070a60018055565b6000546001600160a01b03163314610ad25760405162461bcd60e51b815260040161054a90612673565b610adb816116e8565b50565b6000546001600160a01b03163314610b085760405162461bcd60e51b815260040161054a90612673565b600b55565b600954600090640100000000900460ff16610b2a57506000610b34565b61051983836111d0565b92915050565b6000546001600160a01b03163314610b645760405162461bcd60e51b815260040161054a90612673565b600980549115156401000000000264ff0000000019909216919091179055565b6000546001600160a01b03163314610bae5760405162461bcd60e51b815260040161054a90612673565b6001600160a01b038116610c135760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161054a565b610adb81611261565b6000546001600160a01b03163314610c465760405162461bcd60e51b815260040161054a90612673565b6009805463ffffffff191663ffffffff92909216919091179055565b600061051982846126eb565b6000610519828461270a565b60006001600160a01b038416610c9c57610c9483836117de565b506001610519565b610ca78484846118f7565b5060019392505050565b60035460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f90610ce89087908790600401612770565b600060405180830381865afa158015610d05573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610d2d9190810190612789565b905080610d4560018351611a2190919063ffffffff16565b81518110610d5557610d556126a8565b6020026020010151915060008211610dc45760405162461bcd60e51b815260206004820152602c60248201527f54726561737572793a3a6f7574416d6f756e742073686f756c6420626520677260448201526b06561746572207468616e20360a41b606482015260840161054a565b5092915050565b60006002600a54610ddc919061270a565b841115610e1f5760405162461bcd60e51b815260206004820152601160248201527054726561737572793a3a4d61782035302560781b604482015260640161054a565b60018215610e3b57600a54610e349086611a2d565b9050610e4b565b600a54610e489086611a21565b90505b600a54610e5c906105138684610c62565b95945050505050565b6003546040516307c0329d60e21b815260009182916001600160a01b0390911690631f00ca7490610e9c9087908790600401612770565b600060405180830381865afa158015610eb9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ee19190810190612789565b905080600081518110610ef657610ef66126a8565b6020026020010151915060008211610dc45760405162461bcd60e51b815260206004820152602b60248201527f54726561737572793a3a696e416d6f756e742073686f756c642062652067726560448201526a061746572207468616e20360ac1b606482015260840161054a565b600080610f7185856111d0565b6000818152600860205260408120919250610f8c8787611a39565b5090506000806000610f9d84611c09565b8754929550909350915063ffffffff16600003610fe657845463ffffffff191663ffffffff91909116178455600184019190915560029092019190915550600091506105199050565b8454600090610ffb9063ffffffff168361281a565b90508863ffffffff168163ffffffff161015611021576000975050505050505050610519565b60008163ffffffff1687600101548661103a91906126d4565b611044919061270a565b905060008263ffffffff1688600201548661105f91906126d4565b611069919061270a565b905061108282670de0b6b3a7640000600160701b611df3565b60008a8152600560205260409020556110a881670de0b6b3a7640000600160701b611df3565b60008a81526006602090815260408083209390935560059052205461111b5760405162461bcd60e51b815260206004820152602360248201527f54726561737572793a3a496e76616c696420545741502028707269636530547760448201526261702960e81b606482015260840161054a565b6000898152600660205260409020546111825760405162461bcd60e51b815260206004820152602360248201527f54726561737572793a3a496e76616c696420545741502028707269636531547760448201526261702960e81b606482015260840161054a565b505050600095865260076020526040909520805463ffffffff1990811663ffffffff909716968717909155845416909417835560018381019190915560029092019290925595945050505050565b6000816001600160a01b0316836001600160a01b03161015611233576040516bffffffffffffffffffffffff19606085811b8216602084015284901b1660348201526048015b604051602081830303815290604052805190602001209050610b34565b6040516bffffffffffffffffffffffff19606084811b8216602084015285901b166034820152604801611216565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6002600154036113035760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161054a565b6002600155565b60006001600160a01b03821661132257506001919050565b6002546001600160a01b039081169083160361134057506002919050565b506003919050565b865160009060030361137057602088015160035461137091906001600160a01b031688611e62565b60606000896000015160011480611388575089516002145b905060008960000151600114806113a0575089516002145b9050811580156113ae575080155b15611439576003546040516338ed173960e01b81526001600160a01b03909116906338ed1739906113eb908c908c908c908b908d9060040161283f565b6000604051808303816000875af115801561140a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114329190810190612789565b9250611562565b818015611444575080155b156114c857600354604051637ff36ab560e01b81526001600160a01b0390911690637ff36ab5908b90611481908c908c908b908d9060040161287b565b60006040518083038185885af115801561149f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526114329190810190612789565b811580156114d35750805b15611510576003546040516318cbafe560e01b81526001600160a01b03909116906318cbafe5906113eb908c908c908c908b908d9060040161283f565b60405162461bcd60e51b815260206004820152602160248201527f54726561737572793a3a4554483c2d3e455448206e6f7420737570706f7274656044820152601960fa1b606482015260840161054a565b826001845161157191906126d4565b81518110611581576115816126a8565b60200260200101519350505050979650505050505050565b6000821180156115a95750600081115b6115ed5760405162461bcd60e51b8152602060048201526015602482015274151c99585cdd5c9e4e8e96995c9bc8185b5bdd5b9d605a1b604482015260640161054a565b6000806115fa8686611f8a565b915091508061160a5750506116e2565b60008461161f85670de0b6b3a76400006126eb565b611629919061270a565b90506000600a54600b548561163e91906126eb565b611648919061270a565b9050600081851161165a576000611664565b61166482866126d4565b9050600061167283876128b0565b90508184101580156116845750808411155b6116db5760405162461bcd60e51b815260206004820152602260248201527f54726561737572793a3a507269636520646576696174696f6e20746f6f2068696044820152610ced60f31b606482015260840161054a565b5050505050505b50505050565b6001600160a01b03811661173e5760405162461bcd60e51b815260206004820152601f60248201527f54726561737572793a3a696e76616c696420726f757465206164647265737300604482015260640161054a565b600380546001600160a01b0319166001600160a01b038316908117909155604080516315ab88c960e31b8152905163ad5c4648916004808201926020929091908290030181865afa158015611797573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117bb91906128c8565b600280546001600160a01b0319166001600160a01b039290921691909117905550565b8047101561182e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161054a565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461187b576040519150601f19603f3d011682016040523d82523d6000602084013e611880565b606091505b50509050806105f55760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161054a565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b179052915160009283929087169161195391906128e5565b6000604051808303816000865af19150503d8060008114611990576040519150601f19603f3d011682016040523d82523d6000602084013e611995565b606091505b50915091508180156119bf5750805115806119bf5750808060200190518101906119bf9190612920565b61070a5760405162461bcd60e51b815260206004820152602d60248201527f5472616e7366657248656c7065723a3a736166655472616e736665723a20747260448201526c185b9cd9995c8819985a5b1959609a1b606482015260840161054a565b600061051982846126d4565b600061051982846128b0565b6000806000600360009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab591906128c8565b60405163e6a4390560e01b81526001600160a01b038781166004830152868116602483015291925060009183169063e6a4390590604401602060405180830381865afa158015611b09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2d91906128c8565b90506001600160a01b038116611b855760405162461bcd60e51b815260206004820152601860248201527f54726561737572793a3a50616972206e6f742065786973740000000000000000604482015260640161054a565b809350836001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611bc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bea91906128c8565b6001600160a01b0316866001600160a01b031614925050509250929050565b6000806000836001600160a01b0316635909c0d56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c70919061293d565b9250836001600160a01b0316635a3d54936040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd4919061293d565b91506000806000866001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015611d19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3d9190612972565b9250925092504293508363ffffffff168163ffffffff1614611de9576000611d65828661281a565b905063ffffffff8116611d916001600160701b038616600160701b600160e01b03607087901b1661270a565b611d9b91906126eb565b611da590886128b0565b965063ffffffff8116611dd16001600160701b038516600160701b600160e01b03607088901b1661270a565b611ddb91906126eb565b611de590876128b0565b9550505b5050509193909250565b600081600003611e455760405162461bcd60e51b815260206004820152601860248201527f6d756c4469763a206469766973696f6e206279207a65726f0000000000000000604482015260640161054a565b81611e5084866126eb565b611e5a919061270a565b949350505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1790529151600092839290871691611ebe91906128e5565b6000604051808303816000865af19150503d8060008114611efb576040519150601f19603f3d011682016040523d82523d6000602084013e611f00565b606091505b5091509150818015611f2a575080511580611f2a575080806020019051810190611f2a9190612920565b61070a5760405162461bcd60e51b815260206004820152602b60248201527f5472616e7366657248656c7065723a3a73616665417070726f76653a2061707060448201526a1c9bdd994819985a5b195960aa1b606482015260840161054a565b600080806001600160a01b03851615611fa35784611fb0565b6002546001600160a01b03165b905060006001600160a01b03851615611fc95784611fd6565b6002546001600160a01b03165b90506000611fe483836111d0565b600954909150611ffd908490849063ffffffff16610f64565b5060008181526007602052604090205463ffffffff1680158061202c5750600082815260056020526040902054155b806120435750600082815260066020526040902054155b156120af576120528484612148565b60095490965060009550640100000000900460ff16156120a65760408051878152600060208201527ffb3582a7ead56856e76f4dd65cb289a4eab99d7838c6ab0c08ea8dc71c51ae85910160405180910390a15b50505050612141565b60006120bb8585611a39565b915050806120d7576000838152600660205260409020546120e7565b6000838152600560205260409020545b600954909750640100000000900460ff16156121375760408051888152600160208201527ffb3582a7ead56856e76f4dd65cb289a4eab99d7838c6ab0c08ea8dc71c51ae85910160405180910390a15b6001955050505050505b9250929050565b600080600061215785856121cd565b9150915060008211801561216b5750600081115b6121b05760405162461bcd60e51b815260206004820152601660248201527554726561737572793a3a4e6f206c697175696469747960501b604482015260640161054a565b816121c382670de0b6b3a76400006126eb565b610e5c919061270a565b6000806000600360009054906101000a90046001600160a01b03166001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015612225573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061224991906128c8565b60405163e6a4390560e01b81526001600160a01b0387811660048301528681166024830152919091169063e6a4390590604401602060405180830381865afa158015612299573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122bd91906128c8565b9050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015612300573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123249190612972565b506001600160701b031691506001600160701b03169150856001600160a01b0316876001600160a01b0316101561236057819450809350612367565b8094508193505b5050509250929050565b6000806040838503121561238457600080fd5b50508035926020909101359150565b6001600160a01b0381168114610adb57600080fd5b8015158114610adb57600080fd5b600080604083850312156123c957600080fd5b82356123d481612393565b915060208301356123e4816123a8565b809150509250929050565b60008060006060848603121561240457600080fd5b833561240f81612393565b9250602084013561241f81612393565b929592945050506040919091013590565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561246f5761246f612430565b604052919050565b600067ffffffffffffffff82111561249157612491612430565b5060051b60200190565b600082601f8301126124ac57600080fd5b813560206124c16124bc83612477565b612446565b82815260059290921b840181019181810190868411156124e057600080fd5b8286015b848110156125045780356124f781612393565b83529183019183016124e4565b509695505050505050565b6000806000806080858703121561252557600080fd5b84359350602085013567ffffffffffffffff81111561254357600080fd5b61254f8782880161249b565b949794965050505060408301359260600135919050565b6000806040838503121561257957600080fd5b823561258481612393565b915060208301356123e481612393565b6000602082840312156125a657600080fd5b5035919050565b600080600080600060a086880312156125c557600080fd5b853567ffffffffffffffff8111156125dc57600080fd5b6125e88882890161249b565b9860208801359850604088013597606081013597506080013595509350505050565b60006020828403121561261c57600080fd5b813561051981612393565b60006020828403121561263957600080fd5b8135610519816123a8565b63ffffffff81168114610adb57600080fd5b60006020828403121561266857600080fd5b813561051981612644565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000828210156126e6576126e66126be565b500390565b6000816000190483118215151615612705576127056126be565b500290565b60008261272757634e487b7160e01b600052601260045260246000fd5b500490565b600081518084526020808501945080840160005b838110156127655781516001600160a01b031687529582019590820190600101612740565b509495945050505050565b828152604060208201526000611e5a604083018461272c565b6000602080838503121561279c57600080fd5b825167ffffffffffffffff8111156127b357600080fd5b8301601f810185136127c457600080fd5b80516127d26124bc82612477565b81815260059190911b820183019083810190878311156127f157600080fd5b928401925b8284101561280f578351825292840192908401906127f6565b979650505050505050565b600063ffffffff83811690831681811015612837576128376126be565b039392505050565b85815284602082015260a06040820152600061285e60a083018661272c565b6001600160a01b0394909416606083015250608001529392505050565b848152608060208201526000612894608083018661272c565b6001600160a01b03949094166040830152506060015292915050565b600082198211156128c3576128c36126be565b500190565b6000602082840312156128da57600080fd5b815161051981612393565b6000825160005b8181101561290657602081860181015185830152016128ec565b81811115612915576000828501525b509190910192915050565b60006020828403121561293257600080fd5b8151610519816123a8565b60006020828403121561294f57600080fd5b5051919050565b80516001600160701b038116811461296d57600080fd5b919050565b60008060006060848603121561298757600080fd5b61299084612956565b925061299e60208501612956565b915060408401516129ae81612644565b80915050925092509256fea2646970667358221220979e2ea547e40f2cddad9c7095455d59f5bd75811491879c30ecb3ffc048adde64736f6c634300080e0033",
518
+ "linkReferences": {},
519
+ "deployedLinkReferences": {}
520
+ }
package/src/agent-swap.js CHANGED
@@ -393,6 +393,14 @@ ${JSON.stringify(data,null,2)}`)
393
393
 
394
394
 
395
395
 
396
+ async whitelist(address) {
397
+ let result = await this.SC.methods.whitelist(address).call()
398
+ return result
399
+ }
400
+
401
+
402
+
403
+
396
404
  async setTwapPeriod(period) {
397
405
 
398
406
  let params = [
@@ -673,10 +681,7 @@ ${JSON.stringify(data,null,2)}`)
673
681
  if (path.length < 2) {
674
682
  throw "path长度错误"
675
683
  }
676
- if(outAmountMin == 0) {
677
- outAmountMin = await this.tradeConfig({ amount,path,side,point})
678
- console.log("最小接受数量:",outAmountMin)
679
- }
684
+
680
685
 
681
686
 
682
687
 
@@ -697,6 +702,15 @@ ${JSON.stringify(data,null,2)}`)
697
702
  if(charCompare(this.WETH,inToken)) {
698
703
  ethAmount = inAmount
699
704
  }
705
+
706
+ if(outAmountMin == 0) {
707
+ outAmountMin = await this.tradeConfig({ amount,path,side,point})
708
+ console.log("最小接受数量:",outAmountMin)
709
+ outAmountMin = await OToken.toAmount(outAmountMin)
710
+ }else {
711
+ console.log("最小接受数量:",outAmountMin)
712
+ outAmountMin = await OToken.toAmount(outAmountMin)
713
+ }
700
714
 
701
715
 
702
716
  // 检查最大交换比例
package/src/index.js CHANGED
@@ -5,6 +5,8 @@ let SwapRouter = require("./swap-router")
5
5
  let SwapLP = require("./swap-pair")
6
6
  let Poker = require("./poker")
7
7
  let BERC20 = require("./BERC20")
8
+ let Treasury = require("./treasury")
9
+
8
10
  if (window) {
9
11
  window.AgentSwap = AgentSwap
10
12
  window.SwapFactory = SwapFactory
@@ -12,6 +14,7 @@ if (window) {
12
14
  window.SwapLP = SwapLP
13
15
  window.Poker = Poker
14
16
  window.BERC20 = BERC20
17
+ window.Treasury = Treasury
15
18
  }
16
19
 
17
20
  module.exports = {
@@ -20,5 +23,6 @@ module.exports = {
20
23
  SwapRouter,
21
24
  SwapLP,
22
25
  Poker,
23
- BERC20
26
+ BERC20,
27
+ Treasury
24
28
  }
@@ -58,8 +58,8 @@ class SwapRouter extends HI {
58
58
  }
59
59
  return false
60
60
  }
61
- async updateWhite({ market,status }) {
62
- let result = await this.manage("updateWhite", [market, status])
61
+ async updateWhite({ address,onoff }) {
62
+ let result = await this.manage("updateWhite", [address,onoff])
63
63
  return result
64
64
  }
65
65
 
@@ -0,0 +1,362 @@
1
+ let { HI, HERC20 } = require("h-token-staking")
2
+
3
+ let { abi, bytecode } = require("./abi/Treasury.json")
4
+
5
+ let { plus, reduce, multiplication, division, saveNum, charCompare, longHandle, toSmall } = require("h-token-staking/src/utils")
6
+ const ERC20 = require("h-token-staking/src/ERC20")
7
+
8
+
9
+ class Treasury extends HI {
10
+ constructor({ provider, account, rpcUrl, privateKey, contract, factory = "" }) {
11
+ super({ provider, account, rpcUrl, privateKey, contract, abi })
12
+ this.mainToken = "0x0000000000000000000000000000000000000000"
13
+ this.maxVal = "999000000000000000000000000000000000000000000000000"
14
+ this.WETH = ""
15
+ this.ROUTER = ""
16
+ this.FACTORY = factory
17
+ this.pointMax = "100000000"
18
+
19
+ this.point = 0.01
20
+ }
21
+
22
+ async transfer({ to, amount, contract }) {
23
+ let tokenItem = new ERC20({ ...this.network, contract })
24
+ let user = this.web3.eth.defaultAccount
25
+ let balance = await this.balanceOf({
26
+ token: contract,
27
+ address: user
28
+ })
29
+ if (parseFloat(balance) < parseFloat(amount)) {
30
+ return false
31
+ }
32
+ let result = await tokenItem.transfer(to, amount)
33
+ return result
34
+ }
35
+
36
+ pointOffset({ point, amount, isplus = true }) {
37
+ let result
38
+ if (isplus) {
39
+ result = division(multiplication(amount, plus(this.pointMax, point)), this.pointMax)
40
+ } else {
41
+ result = division(multiplication(amount, reduce(this.pointMax, point)), this.pointMax)
42
+ }
43
+
44
+ return result
45
+ }
46
+
47
+ pointHandle(amount, isplus = true) {
48
+ let rate = 1
49
+ if (isplus) {
50
+ rate = plus(1, this.point)
51
+ } else {
52
+ rate = reduce(1, this.point)
53
+ }
54
+ amount = multiplication(amount, rate)
55
+ amount = saveNum(amount, 0)
56
+ return amount
57
+ }
58
+
59
+ async deploy({ route }) {
60
+ try {
61
+ let from = this.web3.eth.defaultAccount
62
+
63
+ let gasPrice = await this.GasPrice()
64
+ let result = await this.SC.deploy({
65
+ data: bytecode,
66
+ arguments: [route]
67
+ }).send({ from, gasPrice });
68
+ this.SC = result
69
+ return result
70
+ } catch (err) {
71
+ console.log(err)
72
+ }
73
+ }
74
+
75
+ async isOwner() {
76
+ let owner = await this.SC.methods.owner().call()
77
+
78
+ let isOwner = charCompare(owner, this.web3.eth.defaultAccount)
79
+ return isOwner
80
+ }
81
+
82
+ async manage(method, param = []) {
83
+ let isOwner = await this.isOwner()
84
+ if (isOwner) {
85
+ let parmas = await this.buildTx(method, param)
86
+ let result = parmas && await this.broadTx(parmas)
87
+ return result
88
+ } else {
89
+ console.log("非合约所有者调用")
90
+ }
91
+ return false
92
+ }
93
+
94
+ async updateFee({ tokenIn, tokenOut, rate, isOutToken }) {
95
+ let result = await this.manage("updateFee", [tokenIn, tokenOut, rate, isOutToken])
96
+ return result
97
+ }
98
+
99
+ async tokenSend({ token, amount, recipient }) {
100
+ let inToken = new HERC20({ ...this.network, contract: token })
101
+ amount = await inToken.toAmount(amount)
102
+
103
+ let result = await this.manage("tokenSend", [inToken.contract, recipient, amount])
104
+ return result
105
+ }
106
+
107
+ async setting(route) {
108
+ let result = await this.manage("setting", [route])
109
+ return result
110
+ }
111
+
112
+ async sync({ tokenIn, tokenOut }) {
113
+
114
+ let params = [
115
+ tokenIn,
116
+ tokenOut,
117
+ ]
118
+ let result = await this.manage("sync", params)
119
+ return result
120
+ }
121
+
122
+ async updateWhite({ address, onoff }) {
123
+
124
+ let params = [
125
+ address,
126
+ onoff
127
+ ]
128
+ let result = await this.manage("updateWhite", params)
129
+ return result
130
+ }
131
+
132
+ async setMaxAllowedOffset(percent) {
133
+ percent = multiplication(division(percent, 100), this.pointMax)
134
+ let params = [
135
+ percent
136
+ ]
137
+ let result = await this.manage("setMaxAllowedOffset", params)
138
+ return result
139
+ }
140
+
141
+ async getMaxAllowedOffset() {
142
+ let result = await this.SC.methods.maxAllowedOffset().call()
143
+
144
+ return division(result, this.pointMax)
145
+ }
146
+
147
+ async setMaxSwapRatioBps(percent) {
148
+ percent = multiplication(division(percent, 100), this.pointMax)
149
+ let params = [
150
+ percent
151
+ ]
152
+ let result = await this.manage("setMaxSwapRatioBps", params)
153
+ return result
154
+ }
155
+
156
+ async getMaxSwapRatioBps() {
157
+ let result = await this.SC.methods.maxSwapRatioBps().call()
158
+
159
+ return division(result, this.pointMax)
160
+ }
161
+
162
+ async setTwapPeriod(period) {
163
+
164
+ let params = [
165
+ period
166
+ ]
167
+ let result = await this.manage("setTwapPeriod", params)
168
+ return result
169
+ }
170
+
171
+ async getTwapPeriod() {
172
+ let result = await this.SC.methods.twapPeriod().call()
173
+
174
+ return result
175
+ }
176
+
177
+ async route() {
178
+ if (!this.ROUTER) {
179
+ let result = await this.SC.methods.route().call()
180
+ this.ROUTER = result
181
+ }
182
+ return this.ROUTER
183
+ }
184
+
185
+ async weth() {
186
+ if (!this.WETH) {
187
+ let result = await this.SC.methods.weth().call()
188
+ this.WETH = result
189
+ }
190
+ return this.WETH
191
+ }
192
+
193
+ async approve({ token, amount }) {
194
+ let symbol = new HERC20({ ...this.network, contract: token })
195
+ let result = await symbol.tradeApprove(this.contract, amount)
196
+ return result
197
+ }
198
+
199
+ async balanceOf({ token, address }) {
200
+ let symbol = new HERC20({ ...this.network, contract: token })
201
+ let result = await symbol.balanceOf(address)
202
+ result = await symbol.fromAmount(result)
203
+ return result
204
+ }
205
+
206
+ async computeAmount({ amount, path, side = 0, point = 1000, format = false }) {
207
+ let inToken = path[0]
208
+ let outToken = path[path.length - 1]
209
+ let IToken = new HERC20({ ...this.network, contract: inToken })
210
+ let OToken = new HERC20({ ...this.network, contract: outToken })
211
+ if (side == 0) {
212
+ amount = await IToken.toAmount(amount)
213
+ } else {
214
+ amount = await OToken.toAmount(amount)
215
+ }
216
+
217
+ let result = await this.SC.methods.computeAmount(amount, path, side, point).call()
218
+ if (format) {
219
+ if (side == 0) {
220
+ result = await OToken.fromAmount(result)
221
+ } else {
222
+ result = await IToken.fromAmount(result)
223
+ }
224
+ }
225
+ return result
226
+ }
227
+
228
+ async swapRate({ path, point = 1000 }) {
229
+ await this.weth()
230
+ let outToken = path[path.length - 1]
231
+ let OToken = new HERC20({ ...this.network, contract: outToken })
232
+ let outAmount = await this.computeAmount({ amount: 1, path, side: 0, point })
233
+ let amountOut = await OToken.fromAmount(outAmount)
234
+ console.log("汇率:", amountOut)
235
+ return amountOut
236
+ }
237
+
238
+ async swap({ amount, outAmountMin = 0, path, side = 0, point = 1000, deadline = 0 }) {
239
+ await this.weth()
240
+ if (path.length < 2) {
241
+ throw "path长度错误"
242
+ }
243
+
244
+ let inToken = path[0]
245
+ let outToken = path[path.length - 1]
246
+ let inAmount = 0
247
+ let outAmount = 0
248
+ let ethAmount = 0
249
+ let IToken = new HERC20({ ...this.network, contract: inToken })
250
+ let OToken = new HERC20({ ...this.network, contract: outToken })
251
+ if (side == 0) {
252
+ inAmount = await IToken.toAmount(amount)
253
+ outAmount = await this.computeAmount({ amount, path, side, point })
254
+ } else {
255
+ outAmount = await OToken.toAmount(amount)
256
+ inAmount = await this.computeAmount({ amount, path, side, point })
257
+ }
258
+ if (charCompare(this.WETH, inToken)) {
259
+ ethAmount = inAmount
260
+ }
261
+
262
+ outAmountMin = await this.computeAmount({ amount: amount, path, side: 0, point })
263
+ console.log("最小接受数量:", await OToken.fromAmount(outAmountMin))
264
+
265
+ // 批准
266
+ let amountIn = await IToken.fromAmount(inAmount)
267
+ let balance = await this.balanceOf({
268
+ token: inToken,
269
+ address: this.contract
270
+ })
271
+ if (parseFloat(balance) < parseFloat(amountIn)) {
272
+ throw "合约内余额不足,请先充值"
273
+ }
274
+
275
+ // 到期时间
276
+ let now = new Date().getTime()
277
+ now = parseInt(division(now, 1000))
278
+ deadline = deadline ? deadline : plus(multiplication(60, 30), now)
279
+
280
+
281
+ let parma_list = [
282
+ path, inAmount, outAmountMin, deadline, point
283
+ ]
284
+ console.log(parma_list)
285
+ let parmas = await this.buildTx("swap", parma_list, ethAmount)
286
+ let result = parmas && await this.broadTx(parmas)
287
+ return result
288
+
289
+ }
290
+
291
+
292
+ async whitelist(address) {
293
+ let result = await this.SC.methods.whitelist(address).call()
294
+ return result
295
+ }
296
+
297
+ /**
298
+ * 计算使池子价格变动所需投入的代币数量
299
+ *
300
+ * @param {number} R0 - 代币A的当前储备量
301
+ * @param {number} R1 - 代币B的当前储备量
302
+ * @param {number} changePct - 价格变动百分比(正数表示上涨,负数表示下跌,如 2.5 表示 +2.5%,-1.2 表示 -1.2%)
303
+ * @returns {Object} { inputAmount, token }
304
+ * - inputAmount: 需要投入的数量(用户实际支付,含手续费)
305
+ * - token: 'R0' 或 'R1',表示应投入哪种代币
306
+ */
307
+ calculateInputForPriceChange(R0, R1, changePct) {
308
+ const feeRate = 0.0025; // 0.25%
309
+ const effectiveRate = 1 - feeRate; // 0.9975
310
+
311
+ const currentPrice = R1 / R0;
312
+ const targetPrice = currentPrice * (1 + changePct / 100);
313
+
314
+ if (targetPrice <= 0) {
315
+ throw new Error("目标价格必须大于 0");
316
+ }
317
+
318
+ const k = R0 * R1; // 恒定乘积
319
+
320
+ if (changePct > 0) {
321
+ // 价格上涨:需用 B 换 A → 投入 R1(代币B)
322
+ // 新状态满足: R1' / R0' = targetPrice, 且 R0' * R1' = k
323
+ const R1_prime = Math.sqrt(k * targetPrice);
324
+ const deltaR1_effective = R1_prime - R1; // 进入池子的 B(已扣手续费)
325
+ if (deltaR1_effective <= 0) {
326
+ throw new Error("价格上涨需增加 R1,但计算结果非正");
327
+ }
328
+ const inputR1 = deltaR1_effective / effectiveRate; // 用户实际需支付的 B
329
+ return {
330
+ inputAmount: inputR1,
331
+ token: 'R1', // 投入代币B
332
+ newPrice: targetPrice
333
+ };
334
+ } else if (changePct < 0) {
335
+ // 价格下跌:需用 A 换 B → 投入 R0(代币A)
336
+ const R0_prime = Math.sqrt(k / targetPrice);
337
+ const deltaR0_effective = R0_prime - R0; // 进入池子的 A(已扣手续费)
338
+ if (deltaR0_effective <= 0) {
339
+ throw new Error("价格下跌需增加 R0,但计算结果非正");
340
+ }
341
+ const inputR0 = deltaR0_effective / effectiveRate; // 用户实际需支付的 A
342
+ return {
343
+ inputAmount: inputR0,
344
+ token: 'R0', // 投入代币A
345
+ newPrice: targetPrice
346
+ };
347
+ } else {
348
+ return {
349
+ inputAmount: 0,
350
+ token: null,
351
+ newPrice: currentPrice
352
+ };
353
+ }
354
+ }
355
+
356
+
357
+
358
+
359
+ }
360
+
361
+
362
+ module.exports = Treasury