hermes-swap 0.2.1 → 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,7 +1,7 @@
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;
@@ -12,6 +12,7 @@ declare class Hermes {
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
@@ -77,6 +77,40 @@ var Hermes = class {
77
77
  this.aggregatorAddressMap.set(chainName, aggregatorAddress);
78
78
  }
79
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
+ }
80
114
  async expectPriorityLocal(params) {
81
115
  const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote`, {
82
116
  method: "POST",
@@ -12,6 +12,17 @@ export interface IExpectParams {
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,7 +1,7 @@
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;
@@ -12,6 +12,7 @@ declare class Hermes {
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[]>;