hermes-swap 0.2.0 → 0.3.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.
@@ -1,17 +1,18 @@
1
- import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IBridgeParams, IBatchReceipt, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts } from './types.js';
1
+ import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IExpectSplitOrderParams, IExpectSplitOrderResp, 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, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts, };
4
+ export type { IExpectSplitOrderParams, IExpectSplitOrderResp, 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);
15
+ expectWithSplitOrder(params: IExpectSplitOrderParams): Promise<IExpectSplitOrderResp[]>;
15
16
  expectPriorityLocal(params: IExpectParams): Promise<bigint>;
16
17
  expect(params: IExpectParams): Promise<bigint>;
17
18
  batchMultiExpect(params: IBatchExpectParams): Promise<bigint[]>;
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
- this.flashbotSigner = new import_ethers.ethers.Wallet(config.flashbotSigner);
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 {
@@ -75,6 +77,40 @@ var Hermes = class {
75
77
  this.aggregatorAddressMap.set(chainName, aggregatorAddress);
76
78
  }
77
79
  }
80
+ async expectWithSplitOrder(params) {
81
+ const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote-best`, {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ },
86
+ body: JSON.stringify(
87
+ {
88
+ chain: params.chain,
89
+ amountInWei: params.amountInWei,
90
+ fromToken: params.fromTokenAddress,
91
+ toToken: params.toTokenAddress
92
+ },
93
+ (sanitizePricing, value) => typeof value === "bigint" ? value.toString() : value
94
+ )
95
+ });
96
+ const data = await response.json();
97
+ if (data.code && data.msg) {
98
+ throw new Error(`Hermes Signal API 错误 [${data.code}]: ${data.msg}`);
99
+ }
100
+ if (!Array.isArray(data)) {
101
+ throw new Error(`Invalid response: expected array. Response: ${JSON.stringify(data)}`);
102
+ }
103
+ return data.map((item) => {
104
+ if (!item.poolStepConfig || item.amountInWei == null || item.amountOutWei == null) {
105
+ throw new Error(`Invalid response item: ${JSON.stringify(item)}`);
106
+ }
107
+ return {
108
+ routePath: item.poolStepConfig,
109
+ amountIn: BigInt(item.amountInWei),
110
+ amountOut: BigInt(item.amountOutWei)
111
+ };
112
+ });
113
+ }
78
114
  async expectPriorityLocal(params) {
79
115
  const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote`, {
80
116
  method: "POST",
@@ -286,6 +322,9 @@ var Hermes = class {
286
322
  };
287
323
  }
288
324
  async swapByFlashbots(params, txReq = {}, _targetBlockNumber) {
325
+ if (!this.flashbotSigner) {
326
+ throw new Error("flashbot signer未初始化");
327
+ }
289
328
  const provider = this.providerMap.get(params.chain);
290
329
  const wallet = this.walletMap.get(params.chain);
291
330
  if (!wallet || !provider) {
@@ -5,13 +5,24 @@ export interface IConfig {
5
5
  quoterAddress: Record<string, string>;
6
6
  aggregatorAddress: Record<string, string>;
7
7
  hermesSignalDomain?: string;
8
- flashbotSigner: string;
8
+ flashbotSigner?: string;
9
9
  }
10
10
  export interface IExpectParams {
11
11
  chain: ChainNameEnum;
12
12
  amountInWei: bigint;
13
13
  path: IRouterPath[];
14
14
  }
15
+ export interface IExpectSplitOrderParams {
16
+ chain: ChainNameEnum;
17
+ amountInWei: bigint;
18
+ fromTokenAddress: string;
19
+ toTokenAddress: string;
20
+ }
21
+ export interface IExpectSplitOrderResp {
22
+ routePath: IRouterPath[];
23
+ amountIn: bigint;
24
+ amountOut: bigint;
25
+ }
15
26
  export interface IBatchExpectParams {
16
27
  chain: ChainNameEnum;
17
28
  amountInWei: bigint[];
@@ -1,17 +1,18 @@
1
- import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IBridgeParams, IBatchReceipt, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts } from './types.js';
1
+ import type { IExpectParams, IBatchMultiSwapParams, IBatchExpectParams, ISwapParams, IExpectSplitOrderParams, IExpectSplitOrderResp, 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, IBatchMultiSwapParams, IBatchExpectParams, IBatchReceipt, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, SupportContracts, };
4
+ export type { IExpectSplitOrderParams, IExpectSplitOrderResp, 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);
15
+ expectWithSplitOrder(params: IExpectSplitOrderParams): Promise<IExpectSplitOrderResp[]>;
15
16
  expectPriorityLocal(params: IExpectParams): Promise<bigint>;
16
17
  expect(params: IExpectParams): Promise<bigint>;
17
18
  batchMultiExpect(params: IBatchExpectParams): Promise<bigint[]>;