hermes-swap 0.0.33 → 0.1.0

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.
@@ -10,6 +10,7 @@ declare class Hermes {
10
10
  private quoterAddressMap;
11
11
  private aggregatorAddressMap;
12
12
  constructor(config: IConfig);
13
+ expectPriorityLocal(params: IExpectParams): Promise<bigint>;
13
14
  expect(params: IExpectParams): Promise<bigint>;
14
15
  swap(params: ISwapParams, txReq?: TransactionRequest): Promise<IReceipt>;
15
16
  /**
package/dist/cjs/index.js CHANGED
@@ -53,6 +53,11 @@ var Hermes = class {
53
53
  this.quoterAddressMap = /* @__PURE__ */ new Map();
54
54
  this.aggregatorAddressMap = /* @__PURE__ */ new Map();
55
55
  this.config = config;
56
+ if (!config.hermesSignalDomain || config.hermesSignalDomain === "") {
57
+ this.config.hermesSignalDomain = "http://127.0.0.1:3002";
58
+ } else {
59
+ this.config.hermesSignalDomain = config.hermesSignalDomain;
60
+ }
56
61
  for (const [chainName, rpc] of Object.entries(this.config.rpc)) {
57
62
  const provider = new import_ethers.ethers.JsonRpcProvider(rpc.url);
58
63
  this.providerMap.set(chainName, provider);
@@ -67,6 +72,28 @@ var Hermes = class {
67
72
  this.aggregatorAddressMap.set(chainName, aggregatorAddress);
68
73
  }
69
74
  }
75
+ async expectPriorityLocal(params) {
76
+ const wallet = this.walletMap.get(params.chain);
77
+ if (!wallet) {
78
+ throw new Error(`Wallet not configured for chain: ${params.chain}`);
79
+ }
80
+ console.log(`params: ${JSON.stringify(params, (sanitizePricing, value) => typeof value === "bigint" ? value.toString() : value)}`);
81
+ const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote`, {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ },
86
+ body: JSON.stringify(params, (sanitizePricing, value) => typeof value === "bigint" ? value.toString() : value)
87
+ });
88
+ const data = await response.json();
89
+ if (data.message && !data.amountOutWei) {
90
+ throw new Error(`Hermes Signal API 错误: ${data.message}`);
91
+ }
92
+ if (!data.amountOutWei) {
93
+ throw new Error(`Invalid response: amountOutWei is undefined. Response: ${JSON.stringify(data)}`);
94
+ }
95
+ return BigInt(data.amountOutWei);
96
+ }
70
97
  async expect(params) {
71
98
  const wallet = this.walletMap.get(params.chain);
72
99
  if (!wallet) {
@@ -3,6 +3,7 @@ export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
4
  quoterAddress: Record<string, string>;
5
5
  aggregatorAddress: Record<string, string>;
6
+ hermesSignalDomain?: string;
6
7
  }
7
8
  export interface IExpectParams {
8
9
  chain: ChainNameEnum;
@@ -10,6 +10,7 @@ declare class Hermes {
10
10
  private quoterAddressMap;
11
11
  private aggregatorAddressMap;
12
12
  constructor(config: IConfig);
13
+ expectPriorityLocal(params: IExpectParams): Promise<bigint>;
13
14
  expect(params: IExpectParams): Promise<bigint>;
14
15
  swap(params: ISwapParams, txReq?: TransactionRequest): Promise<IReceipt>;
15
16
  /**
package/dist/esm/index.js CHANGED
@@ -40,6 +40,12 @@ var Hermes = /*#__PURE__*/function () {
40
40
  _defineProperty(this, "quoterAddressMap", new Map());
41
41
  _defineProperty(this, "aggregatorAddressMap", new Map());
42
42
  this.config = config;
43
+ if (!config.hermesSignalDomain || config.hermesSignalDomain === '') {
44
+ // 默认 domain
45
+ this.config.hermesSignalDomain = 'http://127.0.0.1:3002';
46
+ } else {
47
+ this.config.hermesSignalDomain = config.hermesSignalDomain;
48
+ }
43
49
  for (var _i = 0, _Object$entries = Object.entries(this.config.rpc); _i < _Object$entries.length; _i++) {
44
50
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
45
51
  chainName = _Object$entries$_i[0],
@@ -64,24 +70,83 @@ var Hermes = /*#__PURE__*/function () {
64
70
  }
65
71
  }
66
72
  _createClass(Hermes, [{
67
- key: "expect",
73
+ key: "expectPriorityLocal",
68
74
  value: function () {
69
- var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
70
- var wallet, address, quoter, quoteParams, amountOutList;
75
+ var _expectPriorityLocal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
76
+ var wallet, response, data;
71
77
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72
78
  while (1) switch (_context.prev = _context.next) {
73
79
  case 0:
74
- // 调用合约
75
80
  wallet = this.walletMap.get(params.chain);
76
81
  if (wallet) {
77
82
  _context.next = 3;
78
83
  break;
79
84
  }
80
85
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
86
+ case 3:
87
+ // 请求 hermesSignalDomain 下的 /api/v1/quote 接口,参数为 params
88
+ console.log("params: ".concat(JSON.stringify(params, function (sanitizePricing, value) {
89
+ return typeof value === 'bigint' ? value.toString() : value;
90
+ })));
91
+ _context.next = 6;
92
+ return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote"), {
93
+ method: 'POST',
94
+ headers: {
95
+ 'Content-Type': 'application/json'
96
+ },
97
+ body: JSON.stringify(params, function (sanitizePricing, value) {
98
+ return typeof value === 'bigint' ? value.toString() : value;
99
+ })
100
+ });
101
+ case 6:
102
+ response = _context.sent;
103
+ _context.next = 9;
104
+ return response.json();
105
+ case 9:
106
+ data = _context.sent;
107
+ if (!(data.message && !data.amountOutWei)) {
108
+ _context.next = 12;
109
+ break;
110
+ }
111
+ throw new Error("Hermes Signal API \u9519\u8BEF: ".concat(data.message));
112
+ case 12:
113
+ if (data.amountOutWei) {
114
+ _context.next = 14;
115
+ break;
116
+ }
117
+ throw new Error("Invalid response: amountOutWei is undefined. Response: ".concat(JSON.stringify(data)));
118
+ case 14:
119
+ return _context.abrupt("return", BigInt(data.amountOutWei));
120
+ case 15:
121
+ case "end":
122
+ return _context.stop();
123
+ }
124
+ }, _callee, this);
125
+ }));
126
+ function expectPriorityLocal(_x) {
127
+ return _expectPriorityLocal.apply(this, arguments);
128
+ }
129
+ return expectPriorityLocal;
130
+ }()
131
+ }, {
132
+ key: "expect",
133
+ value: function () {
134
+ var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
135
+ var wallet, address, quoter, quoteParams, amountOutList;
136
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
137
+ while (1) switch (_context2.prev = _context2.next) {
138
+ case 0:
139
+ // 调用合约
140
+ wallet = this.walletMap.get(params.chain);
141
+ if (wallet) {
142
+ _context2.next = 3;
143
+ break;
144
+ }
145
+ throw new Error("Wallet not configured for chain: ".concat(params.chain));
81
146
  case 3:
82
147
  address = this.getQuoterAddress(params.chain);
83
148
  if (address) {
84
- _context.next = 6;
149
+ _context2.next = 6;
85
150
  break;
86
151
  }
87
152
  throw new Error("Quoter address not found for chain: ".concat(params.chain));
@@ -96,26 +161,26 @@ var Hermes = /*#__PURE__*/function () {
96
161
  extra: p.extra || '0x'
97
162
  };
98
163
  });
99
- _context.next = 10;
164
+ _context2.next = 10;
100
165
  return quoter.multiQuote.staticCall(params.amountInWei, quoteParams, {
101
166
  from: wallet.address
102
167
  });
103
168
  case 10:
104
- amountOutList = _context.sent;
169
+ amountOutList = _context2.sent;
105
170
  if (amountOutList.length) {
106
- _context.next = 13;
171
+ _context2.next = 13;
107
172
  break;
108
173
  }
109
174
  throw new Error('No expect result return from smart contract');
110
175
  case 13:
111
- return _context.abrupt("return", amountOutList[amountOutList.length - 1]);
176
+ return _context2.abrupt("return", amountOutList[amountOutList.length - 1]);
112
177
  case 14:
113
178
  case "end":
114
- return _context.stop();
179
+ return _context2.stop();
115
180
  }
116
- }, _callee, this);
181
+ }, _callee2, this);
117
182
  }));
118
- function expect(_x) {
183
+ function expect(_x2) {
119
184
  return _expect.apply(this, arguments);
120
185
  }
121
186
  return expect;
@@ -123,7 +188,7 @@ var Hermes = /*#__PURE__*/function () {
123
188
  }, {
124
189
  key: "swap",
125
190
  value: function () {
126
- var _swap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
191
+ var _swap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
127
192
  var txReq,
128
193
  fromTokenAddress,
129
194
  toTokenAddress,
@@ -146,14 +211,14 @@ var Hermes = /*#__PURE__*/function () {
146
211
  _step,
147
212
  log,
148
213
  parsed,
149
- _args2 = arguments;
150
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
151
- while (1) switch (_context2.prev = _context2.next) {
214
+ _args3 = arguments;
215
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
216
+ while (1) switch (_context3.prev = _context3.next) {
152
217
  case 0:
153
- txReq = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
218
+ txReq = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
154
219
  this.validateParams(params);
155
220
  if (params.path.length) {
156
- _context2.next = 4;
221
+ _context3.next = 4;
157
222
  break;
158
223
  }
159
224
  throw new Error('Swap path not provided');
@@ -163,7 +228,7 @@ var Hermes = /*#__PURE__*/function () {
163
228
  aggregatorAddress = this.getAggregatorAddress(params.chain);
164
229
  wallet = this.walletMap.get(params.chain);
165
230
  if (wallet) {
166
- _context2.next = 10;
231
+ _context3.next = 10;
167
232
  break;
168
233
  }
169
234
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
@@ -180,108 +245,108 @@ var Hermes = /*#__PURE__*/function () {
180
245
  };
181
246
  });
182
247
  erc20 = new Contract(fromTokenAddress, ['function balanceOf(address) view returns (uint256)', 'function allowance(address, address) view returns (uint256)'], wallet);
183
- _context2.next = 15;
248
+ _context3.next = 15;
184
249
  return erc20.balanceOf(params.user);
185
250
  case 15:
186
- userBalance = _context2.sent;
251
+ userBalance = _context3.sent;
187
252
  if (!(userBalance < params.amountInWei)) {
188
- _context2.next = 18;
253
+ _context3.next = 18;
189
254
  break;
190
255
  }
191
256
  throw new Error('Insufficient balance for swap');
192
257
  case 18:
193
- _context2.next = 20;
258
+ _context3.next = 20;
194
259
  return erc20.allowance(params.user, aggregatorAddress);
195
260
  case 20:
196
- currentAllowance = _context2.sent;
261
+ currentAllowance = _context3.sent;
197
262
  if (!(currentAllowance < params.amountInWei)) {
198
- _context2.next = 23;
263
+ _context3.next = 23;
199
264
  break;
200
265
  }
201
266
  throw new Error('Insufficient allowance token amount for swap');
202
267
  case 23:
203
268
  _txReq = txReq, _ignore = _txReq.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq, _excluded);
204
- _context2.prev = 24;
205
- _context2.next = 27;
269
+ _context3.prev = 24;
270
+ _context3.next = 27;
206
271
  return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, estimationOverrides);
207
272
  case 27:
208
- estimateGas = _context2.sent;
209
- _context2.next = 34;
273
+ estimateGas = _context3.sent;
274
+ _context3.next = 34;
210
275
  break;
211
276
  case 30:
212
- _context2.prev = 30;
213
- _context2.t0 = _context2["catch"](24);
214
- console.warn('Aggregator estimateGas.swap failed', _context2.t0);
215
- throw _context2.t0;
277
+ _context3.prev = 30;
278
+ _context3.t0 = _context3["catch"](24);
279
+ console.warn('Aggregator estimateGas.swap failed', _context3.t0);
280
+ throw _context3.t0;
216
281
  case 34:
217
282
  txReq = this.resolveGasLimit(txReq, estimateGas);
218
- _context2.next = 37;
283
+ _context3.next = 37;
219
284
  return this.resolveNonce(wallet.provider, wallet.address, txReq);
220
285
  case 37:
221
- txReq = _context2.sent;
222
- _context2.next = 40;
286
+ txReq = _context3.sent;
287
+ _context3.next = 40;
223
288
  return this.resolvePricing(wallet.provider, txReq);
224
289
  case 40:
225
- txReq = _context2.sent;
226
- _context2.next = 43;
290
+ txReq = _context3.sent;
291
+ _context3.next = 43;
227
292
  return aggregator.swap(params.user, params.amountInWei, swapParams, params.minAmountOutList, txReq);
228
293
  case 43:
229
- txResponse = _context2.sent;
230
- _context2.next = 46;
294
+ txResponse = _context3.sent;
295
+ _context3.next = 46;
231
296
  return txResponse.wait();
232
297
  case 46:
233
- receipt = _context2.sent;
298
+ receipt = _context3.sent;
234
299
  iface = new ethers.Interface(AggregatorAbi);
235
300
  amountOut = null;
236
301
  _iterator = _createForOfIteratorHelper(receipt.logs);
237
- _context2.prev = 50;
302
+ _context3.prev = 50;
238
303
  _iterator.s();
239
304
  case 52:
240
305
  if ((_step = _iterator.n()).done) {
241
- _context2.next = 66;
306
+ _context3.next = 66;
242
307
  break;
243
308
  }
244
309
  log = _step.value;
245
310
  if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
246
- _context2.next = 64;
311
+ _context3.next = 64;
247
312
  break;
248
313
  }
249
- _context2.prev = 55;
314
+ _context3.prev = 55;
250
315
  parsed = iface.parseLog(log);
251
316
  if (!(parsed && parsed.name === 'Swapped' && parsed.args && parsed.args.amountOut !== undefined)) {
252
- _context2.next = 60;
317
+ _context3.next = 60;
253
318
  break;
254
319
  }
255
320
  amountOut = parsed.args.amountOut;
256
- return _context2.abrupt("break", 66);
321
+ return _context3.abrupt("break", 66);
257
322
  case 60:
258
- _context2.next = 64;
323
+ _context3.next = 64;
259
324
  break;
260
325
  case 62:
261
- _context2.prev = 62;
262
- _context2.t1 = _context2["catch"](55);
326
+ _context3.prev = 62;
327
+ _context3.t1 = _context3["catch"](55);
263
328
  case 64:
264
- _context2.next = 52;
329
+ _context3.next = 52;
265
330
  break;
266
331
  case 66:
267
- _context2.next = 71;
332
+ _context3.next = 71;
268
333
  break;
269
334
  case 68:
270
- _context2.prev = 68;
271
- _context2.t2 = _context2["catch"](50);
272
- _iterator.e(_context2.t2);
335
+ _context3.prev = 68;
336
+ _context3.t2 = _context3["catch"](50);
337
+ _iterator.e(_context3.t2);
273
338
  case 71:
274
- _context2.prev = 71;
339
+ _context3.prev = 71;
275
340
  _iterator.f();
276
- return _context2.finish(71);
341
+ return _context3.finish(71);
277
342
  case 74:
278
343
  if (amountOut) {
279
- _context2.next = 76;
344
+ _context3.next = 76;
280
345
  break;
281
346
  }
282
347
  throw new Error("Swapped event not found: ".concat(receipt.hash));
283
348
  case 76:
284
- return _context2.abrupt("return", {
349
+ return _context3.abrupt("return", {
285
350
  fromToken: fromTokenAddress,
286
351
  toToken: toTokenAddress,
287
352
  amountOut: amountOut,
@@ -292,11 +357,11 @@ var Hermes = /*#__PURE__*/function () {
292
357
  });
293
358
  case 77:
294
359
  case "end":
295
- return _context2.stop();
360
+ return _context3.stop();
296
361
  }
297
- }, _callee2, this, [[24, 30], [50, 68, 71, 74], [55, 62]]);
362
+ }, _callee3, this, [[24, 30], [50, 68, 71, 74], [55, 62]]);
298
363
  }));
299
- function swap(_x2) {
364
+ function swap(_x3) {
300
365
  return _swap.apply(this, arguments);
301
366
  }
302
367
  return swap;
@@ -338,7 +403,7 @@ var Hermes = /*#__PURE__*/function () {
338
403
  }, {
339
404
  key: "bridge",
340
405
  value: function () {
341
- var _bridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
406
+ var _bridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
342
407
  var _params$extra;
343
408
  var txReq,
344
409
  aggregatorAddress,
@@ -353,46 +418,46 @@ var Hermes = /*#__PURE__*/function () {
353
418
  estimationOverrides,
354
419
  response,
355
420
  txReceipt,
356
- _args3 = arguments;
357
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
358
- while (1) switch (_context3.prev = _context3.next) {
421
+ _args4 = arguments;
422
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
423
+ while (1) switch (_context4.prev = _context4.next) {
359
424
  case 0:
360
- txReq = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
425
+ txReq = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
361
426
  this.validateParams(params);
362
427
 
363
428
  // set up
364
429
  aggregatorAddress = this.getAggregatorAddress(params.chain);
365
430
  wallet = this.walletMap.get(params.chain);
366
431
  if (wallet) {
367
- _context3.next = 6;
432
+ _context4.next = 6;
368
433
  break;
369
434
  }
370
435
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
371
436
  case 6:
372
437
  if (!(params.tokenAddress && params.tokenAddress !== ethers.ZeroAddress)) {
373
- _context3.next = 9;
438
+ _context4.next = 9;
374
439
  break;
375
440
  }
376
- _context3.next = 9;
441
+ _context4.next = 9;
377
442
  return this.checkIsEnoughToken(params.tokenAddress, params.user, params.amountInWei, aggregatorAddress, wallet);
378
443
  case 9:
379
444
  if (!(params.bridgeFee > 0n)) {
380
- _context3.next = 18;
445
+ _context4.next = 18;
381
446
  break;
382
447
  }
383
448
  provider = this.providerMap.get(params.chain);
384
449
  if (provider) {
385
- _context3.next = 13;
450
+ _context4.next = 13;
386
451
  break;
387
452
  }
388
453
  throw new Error("Provider not configured for chain: ".concat(params.chain));
389
454
  case 13:
390
- _context3.next = 15;
455
+ _context4.next = 15;
391
456
  return provider.getBalance(params.user);
392
457
  case 15:
393
- nativeBalance = _context3.sent;
458
+ nativeBalance = _context4.sent;
394
459
  if (!(nativeBalance < params.bridgeFee)) {
395
- _context3.next = 18;
460
+ _context4.next = 18;
396
461
  break;
397
462
  }
398
463
  throw new Error('Insufficient native balance for bridge fee');
@@ -415,38 +480,38 @@ var Hermes = /*#__PURE__*/function () {
415
480
 
416
481
  // simulate
417
482
  _txReq2 = txReq, _ignore = _txReq2.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq2, _excluded2);
418
- _context3.prev = 22;
419
- _context3.next = 25;
483
+ _context4.prev = 22;
484
+ _context4.next = 25;
420
485
  return aggregator.bridge.estimateGas(params.user, bridgeArgs, estimationOverrides);
421
486
  case 25:
422
- estimateGas = _context3.sent;
423
- _context3.next = 32;
487
+ estimateGas = _context4.sent;
488
+ _context4.next = 32;
424
489
  break;
425
490
  case 28:
426
- _context3.prev = 28;
427
- _context3.t0 = _context3["catch"](22);
428
- console.error('Bridge gas estimation reverted', _context3.t0);
429
- throw _context3.t0;
491
+ _context4.prev = 28;
492
+ _context4.t0 = _context4["catch"](22);
493
+ console.error('Bridge gas estimation reverted', _context4.t0);
494
+ throw _context4.t0;
430
495
  case 32:
431
496
  // 构造tx req
432
497
  txReq = this.resolveGasLimit(txReq, estimateGas);
433
- _context3.next = 35;
498
+ _context4.next = 35;
434
499
  return this.resolveNonce(wallet.provider, wallet.address, txReq);
435
500
  case 35:
436
- txReq = _context3.sent;
437
- _context3.next = 38;
501
+ txReq = _context4.sent;
502
+ _context4.next = 38;
438
503
  return this.resolvePricing(wallet.provider, txReq);
439
504
  case 38:
440
- txReq = _context3.sent;
441
- _context3.next = 41;
505
+ txReq = _context4.sent;
506
+ _context4.next = 41;
442
507
  return aggregator.bridge(params.user, bridgeArgs, txReq);
443
508
  case 41:
444
- response = _context3.sent;
445
- _context3.next = 44;
509
+ response = _context4.sent;
510
+ _context4.next = 44;
446
511
  return response.wait();
447
512
  case 44:
448
- txReceipt = _context3.sent;
449
- return _context3.abrupt("return", {
513
+ txReceipt = _context4.sent;
514
+ return _context4.abrupt("return", {
450
515
  fromToken: params.tokenAddress,
451
516
  toToken: params.tokenAddress,
452
517
  amountOut: params.amountInWei,
@@ -457,11 +522,11 @@ var Hermes = /*#__PURE__*/function () {
457
522
  });
458
523
  case 46:
459
524
  case "end":
460
- return _context3.stop();
525
+ return _context4.stop();
461
526
  }
462
- }, _callee3, this, [[22, 28]]);
527
+ }, _callee4, this, [[22, 28]]);
463
528
  }));
464
- function bridge(_x3) {
529
+ function bridge(_x4) {
465
530
  return _bridge.apply(this, arguments);
466
531
  }
467
532
  return bridge;
@@ -469,23 +534,23 @@ var Hermes = /*#__PURE__*/function () {
469
534
  }, {
470
535
  key: "estimateBridgeFee",
471
536
  value: function () {
472
- var _estimateBridgeFee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
537
+ var _estimateBridgeFee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
473
538
  var _params$extra2;
474
539
  var wallet, address, quoter, bridgeArgs, bridgeFee;
475
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
476
- while (1) switch (_context4.prev = _context4.next) {
540
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
541
+ while (1) switch (_context5.prev = _context5.next) {
477
542
  case 0:
478
543
  this.validateParams(params);
479
544
  wallet = this.walletMap.get(params.chain);
480
545
  if (wallet) {
481
- _context4.next = 4;
546
+ _context5.next = 4;
482
547
  break;
483
548
  }
484
549
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
485
550
  case 4:
486
551
  address = this.getQuoterAddress(params.chain);
487
552
  if (address) {
488
- _context4.next = 7;
553
+ _context5.next = 7;
489
554
  break;
490
555
  }
491
556
  throw new Error("Quoter address not found for chain: ".concat(params.chain));
@@ -500,20 +565,20 @@ var Hermes = /*#__PURE__*/function () {
500
565
  destUser: params.destUser,
501
566
  extra: (_params$extra2 = params.extra) !== null && _params$extra2 !== void 0 ? _params$extra2 : '0x'
502
567
  };
503
- _context4.next = 11;
568
+ _context5.next = 11;
504
569
  return quoter.quoteBridge.staticCall(bridgeArgs, {
505
570
  from: wallet.address
506
571
  });
507
572
  case 11:
508
- bridgeFee = _context4.sent;
509
- return _context4.abrupt("return", bridgeFee);
573
+ bridgeFee = _context5.sent;
574
+ return _context5.abrupt("return", bridgeFee);
510
575
  case 13:
511
576
  case "end":
512
- return _context4.stop();
577
+ return _context5.stop();
513
578
  }
514
- }, _callee4, this);
579
+ }, _callee5, this);
515
580
  }));
516
- function estimateBridgeFee(_x4) {
581
+ function estimateBridgeFee(_x5) {
517
582
  return _estimateBridgeFee.apply(this, arguments);
518
583
  }
519
584
  return estimateBridgeFee;
@@ -521,7 +586,7 @@ var Hermes = /*#__PURE__*/function () {
521
586
  }, {
522
587
  key: "swapAndBridge",
523
588
  value: function () {
524
- var _swapAndBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
589
+ var _swapAndBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
525
590
  var _params$extra3;
526
591
  var txReq,
527
592
  aggregatorAddress,
@@ -542,28 +607,28 @@ var Hermes = /*#__PURE__*/function () {
542
607
  _step2,
543
608
  log,
544
609
  parsed,
545
- _args5 = arguments;
546
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
547
- while (1) switch (_context5.prev = _context5.next) {
610
+ _args6 = arguments;
611
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
612
+ while (1) switch (_context6.prev = _context6.next) {
548
613
  case 0:
549
- txReq = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
614
+ txReq = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
550
615
  this.validateParams(params);
551
616
 
552
617
  // call the aggregator swap and bridge
553
618
  aggregatorAddress = this.getAggregatorAddress(params.chain);
554
619
  wallet = this.walletMap.get(params.chain);
555
620
  if (wallet) {
556
- _context5.next = 6;
621
+ _context6.next = 6;
557
622
  break;
558
623
  }
559
624
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
560
625
  case 6:
561
626
  fromCoinAddress = params.path[0].fromCoinAddress;
562
627
  if (!(fromCoinAddress && fromCoinAddress !== ethers.ZeroAddress)) {
563
- _context5.next = 10;
628
+ _context6.next = 10;
564
629
  break;
565
630
  }
566
- _context5.next = 10;
631
+ _context6.next = 10;
567
632
  return this.checkIsEnoughToken(fromCoinAddress, params.user, params.amountInWei, aggregatorAddress, wallet);
568
633
  case 10:
569
634
  // 准备合约参数
@@ -593,79 +658,79 @@ var Hermes = /*#__PURE__*/function () {
593
658
  }
594
659
  _txReq3 = txReq, _ignore = _txReq3.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq3, _excluded3);
595
660
  aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
596
- _context5.next = 17;
661
+ _context6.next = 17;
597
662
  return aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, estimationOverrides);
598
663
  case 17:
599
- estimateGas = _context5.sent;
664
+ estimateGas = _context6.sent;
600
665
  txReq = this.resolveGasLimit(txReq, estimateGas);
601
- _context5.next = 21;
666
+ _context6.next = 21;
602
667
  return this.resolveNonce(wallet.provider, wallet.address, txReq);
603
668
  case 21:
604
- txReq = _context5.sent;
605
- _context5.next = 24;
669
+ txReq = _context6.sent;
670
+ _context6.next = 24;
606
671
  return this.resolvePricing(wallet.provider, txReq);
607
672
  case 24:
608
- txReq = _context5.sent;
609
- _context5.next = 27;
673
+ txReq = _context6.sent;
674
+ _context6.next = 27;
610
675
  return aggregator.swapAndBridge(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txReq);
611
676
  case 27:
612
- response = _context5.sent;
613
- _context5.next = 30;
677
+ response = _context6.sent;
678
+ _context6.next = 30;
614
679
  return response.wait();
615
680
  case 30:
616
- txReceipt = _context5.sent;
681
+ txReceipt = _context6.sent;
617
682
  // 解析 SwapAndBridge 事件
618
683
  iface = new ethers.Interface(AggregatorAbi);
619
684
  outputAmountWei = null;
620
685
  _iterator2 = _createForOfIteratorHelper(txReceipt.logs);
621
- _context5.prev = 34;
686
+ _context6.prev = 34;
622
687
  _iterator2.s();
623
688
  case 36:
624
689
  if ((_step2 = _iterator2.n()).done) {
625
- _context5.next = 50;
690
+ _context6.next = 50;
626
691
  break;
627
692
  }
628
693
  log = _step2.value;
629
694
  if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
630
- _context5.next = 48;
695
+ _context6.next = 48;
631
696
  break;
632
697
  }
633
- _context5.prev = 39;
698
+ _context6.prev = 39;
634
699
  parsed = iface.parseLog(log);
635
700
  if (!(parsed && parsed.name === 'SwapAndBridge' && parsed.args && parsed.args.amountOut !== undefined)) {
636
- _context5.next = 44;
701
+ _context6.next = 44;
637
702
  break;
638
703
  }
639
704
  outputAmountWei = parsed.args.amountOut;
640
- return _context5.abrupt("break", 50);
705
+ return _context6.abrupt("break", 50);
641
706
  case 44:
642
- _context5.next = 48;
707
+ _context6.next = 48;
643
708
  break;
644
709
  case 46:
645
- _context5.prev = 46;
646
- _context5.t0 = _context5["catch"](39);
710
+ _context6.prev = 46;
711
+ _context6.t0 = _context6["catch"](39);
647
712
  case 48:
648
- _context5.next = 36;
713
+ _context6.next = 36;
649
714
  break;
650
715
  case 50:
651
- _context5.next = 55;
716
+ _context6.next = 55;
652
717
  break;
653
718
  case 52:
654
- _context5.prev = 52;
655
- _context5.t1 = _context5["catch"](34);
656
- _iterator2.e(_context5.t1);
719
+ _context6.prev = 52;
720
+ _context6.t1 = _context6["catch"](34);
721
+ _iterator2.e(_context6.t1);
657
722
  case 55:
658
- _context5.prev = 55;
723
+ _context6.prev = 55;
659
724
  _iterator2.f();
660
- return _context5.finish(55);
725
+ return _context6.finish(55);
661
726
  case 58:
662
727
  if (outputAmountWei) {
663
- _context5.next = 60;
728
+ _context6.next = 60;
664
729
  break;
665
730
  }
666
731
  throw new Error("SwapAndBridge event not found: ".concat(txReceipt.hash));
667
732
  case 60:
668
- return _context5.abrupt("return", {
733
+ return _context6.abrupt("return", {
669
734
  fromToken: params.path[0].fromCoinAddress,
670
735
  toToken: params.path[params.path.length - 1].toCoinAddress,
671
736
  amountOut: outputAmountWei,
@@ -676,11 +741,11 @@ var Hermes = /*#__PURE__*/function () {
676
741
  });
677
742
  case 61:
678
743
  case "end":
679
- return _context5.stop();
744
+ return _context6.stop();
680
745
  }
681
- }, _callee5, this, [[34, 52, 55, 58], [39, 46]]);
746
+ }, _callee6, this, [[34, 52, 55, 58], [39, 46]]);
682
747
  }));
683
- function swapAndBridge(_x5) {
748
+ function swapAndBridge(_x6) {
684
749
  return _swapAndBridge.apply(this, arguments);
685
750
  }
686
751
  return swapAndBridge;
@@ -688,11 +753,11 @@ var Hermes = /*#__PURE__*/function () {
688
753
  }, {
689
754
  key: "estimateGas",
690
755
  value: function () {
691
- var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(estimateType, params) {
756
+ var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(estimateType, params) {
692
757
  var _params$extra4, _swapAndBridgeParams$;
693
758
  var aggregatorAddress, wallet, aggregator, bridgeArgs1, txOverrides1, gasInBridge, swapParams1, swapGas, swapAndBridgeParams, swapParams, bridgeArgs, txOverrides, gas;
694
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
695
- while (1) switch (_context6.prev = _context6.next) {
759
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
760
+ while (1) switch (_context7.prev = _context7.next) {
696
761
  case 0:
697
762
  this.validateParams(params);
698
763
 
@@ -701,17 +766,17 @@ var Hermes = /*#__PURE__*/function () {
701
766
  wallet = this.walletMap.get(params.chain);
702
767
  aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
703
768
  if (wallet) {
704
- _context6.next = 6;
769
+ _context7.next = 6;
705
770
  break;
706
771
  }
707
772
  throw new Error("Wallet not configured for chain: ".concat(params.chain));
708
773
  case 6:
709
- _context6.t0 = estimateType;
710
- _context6.next = _context6.t0 === IEstimateType.BRIDGE ? 9 : _context6.t0 === IEstimateType.SWAP ? 17 : _context6.t0 === IEstimateType.SWAPANDBRIDGE ? 26 : 36;
774
+ _context7.t0 = estimateType;
775
+ _context7.next = _context7.t0 === IEstimateType.BRIDGE ? 9 : _context7.t0 === IEstimateType.SWAP ? 17 : _context7.t0 === IEstimateType.SWAPANDBRIDGE ? 26 : 36;
711
776
  break;
712
777
  case 9:
713
778
  if (!(!('bridgeType' in params) || !('destChain' in params))) {
714
- _context6.next = 11;
779
+ _context7.next = 11;
715
780
  break;
716
781
  }
717
782
  throw new Error('bridge params required');
@@ -729,20 +794,20 @@ var Hermes = /*#__PURE__*/function () {
729
794
  from: wallet.address,
730
795
  value: params.bridgeFee
731
796
  };
732
- _context6.next = 15;
797
+ _context7.next = 15;
733
798
  return aggregator.bridge.estimateGas(params.user, bridgeArgs1, txOverrides1);
734
799
  case 15:
735
- gasInBridge = _context6.sent;
736
- return _context6.abrupt("return", gasInBridge);
800
+ gasInBridge = _context7.sent;
801
+ return _context7.abrupt("return", gasInBridge);
737
802
  case 17:
738
803
  if (!(!('path' in params) || !Array.isArray(params.path) || params.path.length === 0)) {
739
- _context6.next = 19;
804
+ _context7.next = 19;
740
805
  break;
741
806
  }
742
807
  throw new Error('Swap path required for gas estimation');
743
808
  case 19:
744
809
  if (!(!('minAmountOutList' in params) || params.minAmountOutList.length === 0)) {
745
- _context6.next = 21;
810
+ _context7.next = 21;
746
811
  break;
747
812
  }
748
813
  throw new Error('minAmountOutList required for gas estimation');
@@ -757,16 +822,16 @@ var Hermes = /*#__PURE__*/function () {
757
822
  extra: (_pathItem$extra4 = pathItem.extra) !== null && _pathItem$extra4 !== void 0 ? _pathItem$extra4 : '0x'
758
823
  };
759
824
  });
760
- _context6.next = 24;
825
+ _context7.next = 24;
761
826
  return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, {
762
827
  from: wallet.address
763
828
  });
764
829
  case 24:
765
- swapGas = _context6.sent;
766
- return _context6.abrupt("return", swapGas);
830
+ swapGas = _context7.sent;
831
+ return _context7.abrupt("return", swapGas);
767
832
  case 26:
768
833
  if (!(!('path' in params) || !('bridgeType' in params))) {
769
- _context6.next = 28;
834
+ _context7.next = 28;
770
835
  break;
771
836
  }
772
837
  throw new Error('swapAndBridge params required');
@@ -795,20 +860,20 @@ var Hermes = /*#__PURE__*/function () {
795
860
  from: wallet.address,
796
861
  value: swapAndBridgeParams.bridgeFee
797
862
  };
798
- _context6.next = 34;
863
+ _context7.next = 34;
799
864
  return aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txOverrides);
800
865
  case 34:
801
- gas = _context6.sent;
802
- return _context6.abrupt("return", gas);
866
+ gas = _context7.sent;
867
+ return _context7.abrupt("return", gas);
803
868
  case 36:
804
869
  throw 'Not support method in sdk';
805
870
  case 37:
806
871
  case "end":
807
- return _context6.stop();
872
+ return _context7.stop();
808
873
  }
809
- }, _callee6, this);
874
+ }, _callee7, this);
810
875
  }));
811
- function estimateGas(_x6, _x7) {
876
+ function estimateGas(_x7, _x8) {
812
877
  return _estimateGas.apply(this, arguments);
813
878
  }
814
879
  return estimateGas;
@@ -816,68 +881,68 @@ var Hermes = /*#__PURE__*/function () {
816
881
  }, {
817
882
  key: "getAggregatorSupportContracts",
818
883
  value: function () {
819
- var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(chain) {
884
+ var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(chain) {
820
885
  var aggregatorAddress, provider, aggregator, addressList, supportContracts;
821
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
822
- while (1) switch (_context8.prev = _context8.next) {
886
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
887
+ while (1) switch (_context9.prev = _context9.next) {
823
888
  case 0:
824
889
  // 返回传入链支持的dex和桥
825
890
  // 返回dex type数组
826
891
  aggregatorAddress = this.getAggregatorAddress(chain);
827
892
  provider = this.providerMap.get(chain);
828
893
  if (provider) {
829
- _context8.next = 4;
894
+ _context9.next = 4;
830
895
  break;
831
896
  }
832
897
  throw new Error("Provider not configured for chain: ".concat(chain));
833
898
  case 4:
834
899
  aggregator = new Contract(aggregatorAddress, AggregatorAbi, provider);
835
- _context8.next = 7;
900
+ _context9.next = 7;
836
901
  return aggregator.getAddressList();
837
902
  case 7:
838
- addressList = _context8.sent;
903
+ addressList = _context9.sent;
839
904
  if (addressList.length) {
840
- _context8.next = 10;
905
+ _context9.next = 10;
841
906
  break;
842
907
  }
843
- return _context8.abrupt("return", []);
908
+ return _context9.abrupt("return", []);
844
909
  case 10:
845
- _context8.next = 12;
910
+ _context9.next = 12;
846
911
  return Promise.all(addressList.map( /*#__PURE__*/function () {
847
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(contractAddress, index) {
912
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(contractAddress, index) {
848
913
  var _yield$aggregator$con, contractType;
849
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
850
- while (1) switch (_context7.prev = _context7.next) {
914
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
915
+ while (1) switch (_context8.prev = _context8.next) {
851
916
  case 0:
852
- _context7.next = 2;
917
+ _context8.next = 2;
853
918
  return aggregator.contractList(index);
854
919
  case 2:
855
- _yield$aggregator$con = _context7.sent;
920
+ _yield$aggregator$con = _context8.sent;
856
921
  contractType = _yield$aggregator$con.contractType;
857
- return _context7.abrupt("return", {
922
+ return _context8.abrupt("return", {
858
923
  contractType: contractType,
859
924
  contractAddress: contractAddress
860
925
  });
861
926
  case 5:
862
927
  case "end":
863
- return _context7.stop();
928
+ return _context8.stop();
864
929
  }
865
- }, _callee7);
930
+ }, _callee8);
866
931
  }));
867
- return function (_x9, _x10) {
932
+ return function (_x10, _x11) {
868
933
  return _ref.apply(this, arguments);
869
934
  };
870
935
  }()));
871
936
  case 12:
872
- supportContracts = _context8.sent;
873
- return _context8.abrupt("return", supportContracts);
937
+ supportContracts = _context9.sent;
938
+ return _context9.abrupt("return", supportContracts);
874
939
  case 14:
875
940
  case "end":
876
- return _context8.stop();
941
+ return _context9.stop();
877
942
  }
878
- }, _callee8, this);
943
+ }, _callee9, this);
879
944
  }));
880
- function getAggregatorSupportContracts(_x8) {
945
+ function getAggregatorSupportContracts(_x9) {
881
946
  return _getAggregatorSupportContracts.apply(this, arguments);
882
947
  }
883
948
  return getAggregatorSupportContracts;
@@ -885,68 +950,68 @@ var Hermes = /*#__PURE__*/function () {
885
950
  }, {
886
951
  key: "getQuoterSupportContracts",
887
952
  value: function () {
888
- var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(chain) {
953
+ var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(chain) {
889
954
  var quoterAddress, provider, quoter, addressList, supportContracts;
890
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
891
- while (1) switch (_context10.prev = _context10.next) {
955
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
956
+ while (1) switch (_context11.prev = _context11.next) {
892
957
  case 0:
893
958
  // 返回传入链支持的dex和桥
894
959
  // 返回dex type数组
895
960
  quoterAddress = this.getQuoterAddress(chain);
896
961
  provider = this.providerMap.get(chain);
897
962
  if (provider) {
898
- _context10.next = 4;
963
+ _context11.next = 4;
899
964
  break;
900
965
  }
901
966
  throw new Error("Provider not configured for chain: ".concat(chain));
902
967
  case 4:
903
968
  quoter = new Contract(quoterAddress, QuoterAbi, provider);
904
- _context10.next = 7;
969
+ _context11.next = 7;
905
970
  return quoter.getAddressList();
906
971
  case 7:
907
- addressList = _context10.sent;
972
+ addressList = _context11.sent;
908
973
  if (addressList.length) {
909
- _context10.next = 10;
974
+ _context11.next = 10;
910
975
  break;
911
976
  }
912
- return _context10.abrupt("return", []);
977
+ return _context11.abrupt("return", []);
913
978
  case 10:
914
- _context10.next = 12;
979
+ _context11.next = 12;
915
980
  return Promise.all(addressList.map( /*#__PURE__*/function () {
916
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(contractAddress, index) {
981
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(contractAddress, index) {
917
982
  var _yield$quoter$contrac, contractType;
918
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
919
- while (1) switch (_context9.prev = _context9.next) {
983
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
984
+ while (1) switch (_context10.prev = _context10.next) {
920
985
  case 0:
921
- _context9.next = 2;
986
+ _context10.next = 2;
922
987
  return quoter.contractList(index);
923
988
  case 2:
924
- _yield$quoter$contrac = _context9.sent;
989
+ _yield$quoter$contrac = _context10.sent;
925
990
  contractType = _yield$quoter$contrac.contractType;
926
- return _context9.abrupt("return", {
991
+ return _context10.abrupt("return", {
927
992
  contractType: contractType,
928
993
  contractAddress: contractAddress
929
994
  });
930
995
  case 5:
931
996
  case "end":
932
- return _context9.stop();
997
+ return _context10.stop();
933
998
  }
934
- }, _callee9);
999
+ }, _callee10);
935
1000
  }));
936
- return function (_x12, _x13) {
1001
+ return function (_x13, _x14) {
937
1002
  return _ref2.apply(this, arguments);
938
1003
  };
939
1004
  }()));
940
1005
  case 12:
941
- supportContracts = _context10.sent;
942
- return _context10.abrupt("return", supportContracts);
1006
+ supportContracts = _context11.sent;
1007
+ return _context11.abrupt("return", supportContracts);
943
1008
  case 14:
944
1009
  case "end":
945
- return _context10.stop();
1010
+ return _context11.stop();
946
1011
  }
947
- }, _callee10, this);
1012
+ }, _callee11, this);
948
1013
  }));
949
- function getQuoterSupportContracts(_x11) {
1014
+ function getQuoterSupportContracts(_x12) {
950
1015
  return _getQuoterSupportContracts.apply(this, arguments);
951
1016
  }
952
1017
  return getQuoterSupportContracts;
@@ -1011,31 +1076,31 @@ var Hermes = /*#__PURE__*/function () {
1011
1076
  }, {
1012
1077
  key: "resolveNonce",
1013
1078
  value: function () {
1014
- var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(provider, from, tx) {
1079
+ var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(provider, from, tx) {
1015
1080
  var nonce;
1016
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1017
- while (1) switch (_context11.prev = _context11.next) {
1081
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1082
+ while (1) switch (_context12.prev = _context12.next) {
1018
1083
  case 0:
1019
1084
  if (!(tx.nonce != null)) {
1020
- _context11.next = 2;
1085
+ _context12.next = 2;
1021
1086
  break;
1022
1087
  }
1023
- return _context11.abrupt("return", tx);
1088
+ return _context12.abrupt("return", tx);
1024
1089
  case 2:
1025
- _context11.next = 4;
1090
+ _context12.next = 4;
1026
1091
  return provider.getTransactionCount(from, 'latest');
1027
1092
  case 4:
1028
- nonce = _context11.sent;
1029
- return _context11.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1093
+ nonce = _context12.sent;
1094
+ return _context12.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1030
1095
  nonce: nonce
1031
1096
  }));
1032
1097
  case 6:
1033
1098
  case "end":
1034
- return _context11.stop();
1099
+ return _context12.stop();
1035
1100
  }
1036
- }, _callee11);
1101
+ }, _callee12);
1037
1102
  }));
1038
- function resolveNonce(_x14, _x15, _x16) {
1103
+ function resolveNonce(_x15, _x16, _x17) {
1039
1104
  return _resolveNonce.apply(this, arguments);
1040
1105
  }
1041
1106
  return resolveNonce;
@@ -1043,47 +1108,47 @@ var Hermes = /*#__PURE__*/function () {
1043
1108
  }, {
1044
1109
  key: "resolvePricing",
1045
1110
  value: function () {
1046
- var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(provider, tx) {
1111
+ var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(provider, tx) {
1047
1112
  var fd;
1048
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1049
- while (1) switch (_context12.prev = _context12.next) {
1113
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1114
+ while (1) switch (_context13.prev = _context13.next) {
1050
1115
  case 0:
1051
1116
  if (!(tx.gasPrice != null || tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null)) {
1052
- _context12.next = 2;
1117
+ _context13.next = 2;
1053
1118
  break;
1054
1119
  }
1055
- return _context12.abrupt("return", this.sanitizePricing(tx));
1120
+ return _context13.abrupt("return", this.sanitizePricing(tx));
1056
1121
  case 2:
1057
- _context12.next = 4;
1122
+ _context13.next = 4;
1058
1123
  return provider.getFeeData();
1059
1124
  case 4:
1060
- fd = _context12.sent;
1125
+ fd = _context13.sent;
1061
1126
  if (!(fd.maxFeePerGas != null && fd.maxPriorityFeePerGas != null)) {
1062
- _context12.next = 7;
1127
+ _context13.next = 7;
1063
1128
  break;
1064
1129
  }
1065
- return _context12.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1130
+ return _context13.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1066
1131
  maxFeePerGas: fd.maxFeePerGas * 150n / 100n,
1067
1132
  // 上浮50%
1068
1133
  maxPriorityFeePerGas: fd.maxPriorityFeePerGas
1069
1134
  }));
1070
1135
  case 7:
1071
1136
  if (!(fd.gasPrice != null)) {
1072
- _context12.next = 9;
1137
+ _context13.next = 9;
1073
1138
  break;
1074
1139
  }
1075
- return _context12.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1140
+ return _context13.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
1076
1141
  gasPrice: fd.gasPrice
1077
1142
  }));
1078
1143
  case 9:
1079
- return _context12.abrupt("return", tx);
1144
+ return _context13.abrupt("return", tx);
1080
1145
  case 10:
1081
1146
  case "end":
1082
- return _context12.stop();
1147
+ return _context13.stop();
1083
1148
  }
1084
- }, _callee12, this);
1149
+ }, _callee13, this);
1085
1150
  }));
1086
- function resolvePricing(_x17, _x18) {
1151
+ function resolvePricing(_x18, _x19) {
1087
1152
  return _resolvePricing.apply(this, arguments);
1088
1153
  }
1089
1154
  return resolvePricing;
@@ -1102,38 +1167,38 @@ var Hermes = /*#__PURE__*/function () {
1102
1167
  }, {
1103
1168
  key: "checkIsEnoughToken",
1104
1169
  value: function () {
1105
- var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(fromTokenAddress, userAddress, amountInWei, aggregatorAddress, wallet) {
1170
+ var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(fromTokenAddress, userAddress, amountInWei, aggregatorAddress, wallet) {
1106
1171
  var erc20, userBalance, currentAllowance;
1107
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1108
- while (1) switch (_context13.prev = _context13.next) {
1172
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1173
+ while (1) switch (_context14.prev = _context14.next) {
1109
1174
  case 0:
1110
1175
  erc20 = new Contract(fromTokenAddress, ['function balanceOf(address) view returns (uint256)', 'function allowance(address, address) view returns (uint256)'], wallet);
1111
- _context13.next = 3;
1176
+ _context14.next = 3;
1112
1177
  return erc20.balanceOf(userAddress);
1113
1178
  case 3:
1114
- userBalance = _context13.sent;
1179
+ userBalance = _context14.sent;
1115
1180
  if (!(userBalance < amountInWei)) {
1116
- _context13.next = 6;
1181
+ _context14.next = 6;
1117
1182
  break;
1118
1183
  }
1119
1184
  throw new Error('Insufficient balance token amount');
1120
1185
  case 6:
1121
- _context13.next = 8;
1186
+ _context14.next = 8;
1122
1187
  return erc20.allowance(userAddress, aggregatorAddress);
1123
1188
  case 8:
1124
- currentAllowance = _context13.sent;
1189
+ currentAllowance = _context14.sent;
1125
1190
  if (!(currentAllowance < amountInWei)) {
1126
- _context13.next = 11;
1191
+ _context14.next = 11;
1127
1192
  break;
1128
1193
  }
1129
1194
  throw new Error('Insufficient allowance token amount');
1130
1195
  case 11:
1131
1196
  case "end":
1132
- return _context13.stop();
1197
+ return _context14.stop();
1133
1198
  }
1134
- }, _callee13);
1199
+ }, _callee14);
1135
1200
  }));
1136
- function checkIsEnoughToken(_x19, _x20, _x21, _x22, _x23) {
1201
+ function checkIsEnoughToken(_x20, _x21, _x22, _x23, _x24) {
1137
1202
  return _checkIsEnoughToken.apply(this, arguments);
1138
1203
  }
1139
1204
  return checkIsEnoughToken;
@@ -3,6 +3,7 @@ export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
4
  quoterAddress: Record<string, string>;
5
5
  aggregatorAddress: Record<string, string>;
6
+ hermesSignalDomain?: string;
6
7
  }
7
8
  export interface IExpectParams {
8
9
  chain: ChainNameEnum;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-swap",
3
- "version": "0.0.33",
3
+ "version": "0.1.0",
4
4
  "description": "A TypeScript utility library for swap and bridge",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",