hermes-swap 0.1.10 → 0.2.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/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/types.d.ts +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +35 -27
- package/dist/esm/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IBridgeParams, IBatchReceipt, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts } from './types.js';
|
|
2
2
|
import { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap } from './types.js';
|
|
3
3
|
import { TransactionRequest } from 'ethers';
|
|
4
|
-
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts };
|
|
4
|
+
export type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts, };
|
|
5
5
|
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap };
|
|
6
6
|
declare class Hermes {
|
|
7
7
|
private config;
|
|
8
8
|
private providerMap;
|
|
9
9
|
private walletMap;
|
|
10
10
|
private quoterAddressMap;
|
|
11
|
-
private flashbotSigner
|
|
11
|
+
private flashbotSigner?;
|
|
12
12
|
private aggregatorAddressMap;
|
|
13
13
|
private executor;
|
|
14
14
|
constructor(config: IConfig);
|
package/dist/cjs/index.js
CHANGED
|
@@ -55,7 +55,9 @@ var Hermes = class {
|
|
|
55
55
|
this.aggregatorAddressMap = /* @__PURE__ */ new Map();
|
|
56
56
|
this.config = config;
|
|
57
57
|
this.executor = config.executor;
|
|
58
|
-
|
|
58
|
+
if (config.flashbotSigner) {
|
|
59
|
+
this.flashbotSigner = new import_ethers.ethers.Wallet(config.flashbotSigner);
|
|
60
|
+
}
|
|
59
61
|
if (!config.hermesSignalDomain || config.hermesSignalDomain === "") {
|
|
60
62
|
this.config.hermesSignalDomain = "http://127.0.0.1:3002";
|
|
61
63
|
} else {
|
|
@@ -286,6 +288,9 @@ var Hermes = class {
|
|
|
286
288
|
};
|
|
287
289
|
}
|
|
288
290
|
async swapByFlashbots(params, txReq = {}, _targetBlockNumber) {
|
|
291
|
+
if (!this.flashbotSigner) {
|
|
292
|
+
throw new Error("flashbot signer未初始化");
|
|
293
|
+
}
|
|
289
294
|
const provider = this.providerMap.get(params.chain);
|
|
290
295
|
const wallet = this.walletMap.get(params.chain);
|
|
291
296
|
if (!wallet || !provider) {
|
package/dist/cjs/types.d.ts
CHANGED
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IBridgeParams, IBatchReceipt, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts } from './types.js';
|
|
2
2
|
import { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap } from './types.js';
|
|
3
3
|
import { TransactionRequest } from 'ethers';
|
|
4
|
-
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts };
|
|
4
|
+
export type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts, };
|
|
5
5
|
export { ChainNameEnum, AddressConst, DexType, BridgeType, IEstimateType, LayerZeroV1ChainIdMap, LayerZeroV1ChainNameMap, LayerZeroV2ChainIdMap, LayerZeroV2ChainNameMap };
|
|
6
6
|
declare class Hermes {
|
|
7
7
|
private config;
|
|
8
8
|
private providerMap;
|
|
9
9
|
private walletMap;
|
|
10
10
|
private quoterAddressMap;
|
|
11
|
-
private flashbotSigner
|
|
11
|
+
private flashbotSigner?;
|
|
12
12
|
private aggregatorAddressMap;
|
|
13
13
|
private executor;
|
|
14
14
|
constructor(config: IConfig);
|
package/dist/esm/index.js
CHANGED
|
@@ -46,7 +46,9 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
46
46
|
_defineProperty(this, "executor", void 0);
|
|
47
47
|
this.config = config;
|
|
48
48
|
this.executor = config.executor;
|
|
49
|
-
|
|
49
|
+
if (config.flashbotSigner) {
|
|
50
|
+
this.flashbotSigner = new ethers.Wallet(config.flashbotSigner);
|
|
51
|
+
}
|
|
50
52
|
if (!config.hermesSignalDomain || config.hermesSignalDomain === '') {
|
|
51
53
|
// 默认 domain
|
|
52
54
|
this.config.hermesSignalDomain = 'http://127.0.0.1:3002';
|
|
@@ -615,14 +617,20 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
615
617
|
case 0:
|
|
616
618
|
txReq = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
|
|
617
619
|
_targetBlockNumber = _args7.length > 2 ? _args7[2] : undefined;
|
|
620
|
+
if (this.flashbotSigner) {
|
|
621
|
+
_context7.next = 4;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
throw new Error('flashbot signer未初始化');
|
|
625
|
+
case 4:
|
|
618
626
|
provider = this.providerMap.get(params.chain);
|
|
619
627
|
wallet = this.walletMap.get(params.chain);
|
|
620
628
|
if (!(!wallet || !provider)) {
|
|
621
|
-
_context7.next =
|
|
629
|
+
_context7.next = 8;
|
|
622
630
|
break;
|
|
623
631
|
}
|
|
624
632
|
throw new Error("sdk\u4E0D\u652F\u6301\u7684\u94FE\uFF1A ".concat(params.chain));
|
|
625
|
-
case
|
|
633
|
+
case 8:
|
|
626
634
|
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
627
635
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
628
636
|
swapParams = params.path.map(function (pathItem) {
|
|
@@ -636,27 +644,27 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
636
644
|
};
|
|
637
645
|
});
|
|
638
646
|
_txReq3 = txReq, _ignore = _txReq3.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq3, _excluded3);
|
|
639
|
-
_context7.prev =
|
|
640
|
-
_context7.next =
|
|
647
|
+
_context7.prev = 12;
|
|
648
|
+
_context7.next = 15;
|
|
641
649
|
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, estimationOverrides);
|
|
642
|
-
case
|
|
650
|
+
case 15:
|
|
643
651
|
estimateGas = _context7.sent;
|
|
644
|
-
_context7.next =
|
|
652
|
+
_context7.next = 22;
|
|
645
653
|
break;
|
|
646
|
-
case
|
|
647
|
-
_context7.prev =
|
|
648
|
-
_context7.t0 = _context7["catch"](
|
|
654
|
+
case 18:
|
|
655
|
+
_context7.prev = 18;
|
|
656
|
+
_context7.t0 = _context7["catch"](12);
|
|
649
657
|
console.warn('Aggregator estimateGas.swap failed', _context7.t0);
|
|
650
658
|
throw _context7.t0;
|
|
651
|
-
case
|
|
659
|
+
case 22:
|
|
652
660
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
653
|
-
_context7.next =
|
|
661
|
+
_context7.next = 25;
|
|
654
662
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
655
|
-
case
|
|
663
|
+
case 25:
|
|
656
664
|
txReq = _context7.sent;
|
|
657
|
-
_context7.next =
|
|
665
|
+
_context7.next = 28;
|
|
658
666
|
return this.resolvePricing(wallet.provider, txReq);
|
|
659
|
-
case
|
|
667
|
+
case 28:
|
|
660
668
|
txReq = _context7.sent;
|
|
661
669
|
this.validateParams(params);
|
|
662
670
|
swapCallData = this.genSwapCalldata(params);
|
|
@@ -671,9 +679,9 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
671
679
|
data: swapCallData.data,
|
|
672
680
|
gasLimit: txReq.gasLimit
|
|
673
681
|
};
|
|
674
|
-
_context7.next =
|
|
682
|
+
_context7.next = 34;
|
|
675
683
|
return wallet.signTransaction(baseTx);
|
|
676
|
-
case
|
|
684
|
+
case 34:
|
|
677
685
|
signTx = _context7.sent;
|
|
678
686
|
rawTxs = [signTx];
|
|
679
687
|
txHashes = rawTxs.map(function (tx) {
|
|
@@ -683,19 +691,19 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
683
691
|
console.log("Transaction ".concat(i + 1, ": ").concat(hash));
|
|
684
692
|
});
|
|
685
693
|
if (!_targetBlockNumber) {
|
|
686
|
-
_context7.next =
|
|
694
|
+
_context7.next = 42;
|
|
687
695
|
break;
|
|
688
696
|
}
|
|
689
697
|
targetBlock = _targetBlockNumber;
|
|
690
|
-
_context7.next =
|
|
698
|
+
_context7.next = 46;
|
|
691
699
|
break;
|
|
692
|
-
case 40:
|
|
693
|
-
_context7.next = 42;
|
|
694
|
-
return provider.getBlockNumber();
|
|
695
700
|
case 42:
|
|
701
|
+
_context7.next = 44;
|
|
702
|
+
return provider.getBlockNumber();
|
|
703
|
+
case 44:
|
|
696
704
|
_context7.t1 = _context7.sent;
|
|
697
705
|
targetBlock = _context7.t1 + 1;
|
|
698
|
-
case
|
|
706
|
+
case 46:
|
|
699
707
|
// 注册检查是否上链
|
|
700
708
|
resultPromise = new Promise(function (resolve) {
|
|
701
709
|
var onBlock = /*#__PURE__*/function () {
|
|
@@ -794,15 +802,15 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
794
802
|
}();
|
|
795
803
|
provider.on('block', onBlock);
|
|
796
804
|
});
|
|
797
|
-
_context7.next =
|
|
805
|
+
_context7.next = 49;
|
|
798
806
|
return this.sendBundle(rawTxs, targetBlock, this.flashbotSigner);
|
|
799
|
-
case
|
|
807
|
+
case 49:
|
|
800
808
|
return _context7.abrupt("return", resultPromise);
|
|
801
|
-
case
|
|
809
|
+
case 50:
|
|
802
810
|
case "end":
|
|
803
811
|
return _context7.stop();
|
|
804
812
|
}
|
|
805
|
-
}, _callee7, this, [[
|
|
813
|
+
}, _callee7, this, [[12, 18]]);
|
|
806
814
|
}));
|
|
807
815
|
function swapByFlashbots(_x6) {
|
|
808
816
|
return _swapByFlashbots.apply(this, arguments);
|
package/dist/esm/types.d.ts
CHANGED