hermes-swap 0.0.12 → 0.0.13

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.
@@ -12,8 +12,6 @@ declare class Hermes {
12
12
  bridge(params: IBridgeParams): Promise<IReceipt>;
13
13
  swapAndBridge(params: ISwapAndBridgeParams): Promise<IReceipt>;
14
14
  private validateParams;
15
- private getAllTokenPair;
16
- private getTokenPair;
17
15
  private getQuoterAddress;
18
16
  private getAggregatorAddress;
19
17
  }
package/dist/cjs/index.js CHANGED
@@ -32,7 +32,6 @@ __export(src_exports, {
32
32
  default: () => src_default
33
33
  });
34
34
  module.exports = __toCommonJS(src_exports);
35
- var import_types = require("./types");
36
35
  var import_ethers = require("ethers");
37
36
  var import_ethers2 = require("ethers");
38
37
  var import_quoter = __toESM(require("./abis/quoter"));
@@ -64,57 +63,36 @@ var Hermes = class {
64
63
  }
65
64
  }
66
65
  async expect(params) {
67
- this.validateParams(params);
68
- const tokenPair = this.getTokenPair(params.chain, params.fromToken, params.toToken);
69
- if (!tokenPair) {
70
- throw new Error(`Token pair not found for chain: ${params.chain}`);
71
- }
72
- const address = this.getQuoterAddress(params.chain);
73
- console.log("quoter address: ", address);
74
- const provider = this.providerMap.get(params.chain);
75
- if (!provider) {
76
- throw new Error(`Provider not found for chain: ${params.chain}`);
77
- }
78
- if (!tokenPair.path.length) {
79
- throw new Error(`Quote path not configured for chain: ${params.chain} from: ${params.fromToken} to: ${params.toToken}`);
80
- }
81
- console.log("dex type: ", params.dexType);
82
- const quoteParams = tokenPair.path.map((pathItem) => ({
83
- dexType: params.dexType ?? pathItem.dexType,
84
- pool: pathItem.pool,
85
- fromCoin: pathItem.fromCoin,
86
- toCoin: pathItem.toCoin,
87
- extra: pathItem.extra ?? params.extra ?? "0x"
88
- }));
89
66
  const executorWallet = this.executorMap.get(params.chain);
90
67
  if (!executorWallet) {
91
68
  throw new Error(`Executor wallet not configured for chain: ${params.chain}`);
92
69
  }
93
- console.log("wallet address: ", executorWallet.address);
70
+ const address = this.getQuoterAddress(params.chain);
71
+ if (!address) {
72
+ throw new Error(`Quoter address not found for chain: ${params.chain}`);
73
+ }
94
74
  const quoter = new import_ethers2.Contract(address, import_quoter.default, executorWallet);
95
- console.log("executor address: ", await quoter.executor());
96
- const amountOutList = await quoter.multiQuote(params.amount, quoteParams);
75
+ const quoteParams = params.path.map((p) => ({
76
+ dexType: p.dexType,
77
+ pool: p.poolAddress,
78
+ fromCoin: p.fromCoinAddress,
79
+ toCoin: p.toCoinAddress,
80
+ extra: p.extra || "0x"
81
+ }));
82
+ const amountOutList = await quoter.multiQuote(params.amountInWei, quoteParams);
97
83
  return amountOutList.length ? amountOutList[amountOutList.length - 1] : BigInt(0);
98
84
  }
99
- swap(params) {
85
+ async swap(params) {
100
86
  this.validateParams(params);
101
- const receipt = {
102
- fromToken: params.fromToken,
103
- toToken: params.toToken,
104
- amount: params.amount
105
- };
87
+ const receipt = {};
106
88
  return Promise.resolve(receipt);
107
89
  }
108
- bridge(params) {
90
+ async bridge(params) {
109
91
  this.validateParams(params);
110
- const receipt = {
111
- fromToken: params.fromToken,
112
- toToken: params.toToken,
113
- amount: params.amount
114
- };
92
+ const receipt = {};
115
93
  return Promise.resolve(receipt);
116
94
  }
117
- swapAndBridge(params) {
95
+ async swapAndBridge(params) {
118
96
  this.validateParams(params);
119
97
  const receipt = {};
120
98
  return Promise.resolve(receipt);
@@ -128,39 +106,6 @@ var Hermes = class {
128
106
  throw new Error("Provider not found");
129
107
  }
130
108
  }
131
- getAllTokenPair() {
132
- return {
133
- [import_types.ChainNameEnum.ETH]: [
134
- { from: import_types.AddressConst.weth.eth, to: import_types.AddressConst.usdt.eth, path: [] },
135
- // fx
136
- {
137
- from: import_types.AddressConst.weth.eth,
138
- to: import_types.AddressConst.feth.eth,
139
- path: [
140
- {
141
- dexType: "f(x)",
142
- pool: "0xe7b9c7c9cA85340b8c06fb805f7775e3015108dB",
143
- fromCoin: import_types.AddressConst.weth.eth,
144
- toCoin: import_types.AddressConst.feth.eth,
145
- extra: "0x"
146
- }
147
- ]
148
- }
149
- ]
150
- };
151
- }
152
- getTokenPair(chain, from, to) {
153
- const tokenPairMap = this.getAllTokenPair();
154
- const tokenPairList = tokenPairMap[chain];
155
- if (!tokenPairList) {
156
- throw new Error(`Token pair not found for chain: ${chain}`);
157
- }
158
- const tokenPair = tokenPairList.find((item) => item.from.toLocaleLowerCase() === from.toLocaleLowerCase() && item.to.toLocaleLowerCase() === to.toLocaleLowerCase());
159
- if (!tokenPair) {
160
- throw new Error(`Token pair not found for chain: ${chain} from: ${from} to: ${to}`);
161
- }
162
- return tokenPair;
163
- }
164
109
  getQuoterAddress(chain) {
165
110
  if (this.quoterAddressMap.has(chain)) {
166
111
  return this.quoterAddressMap.get(chain);
@@ -7,31 +7,37 @@ export interface IConfig {
7
7
  }
8
8
  export interface IExpectParams {
9
9
  chain: ChainNameEnum;
10
- dexType?: string;
11
- fromToken: string;
12
- toToken: string;
13
- amount: bigint;
14
- extra?: BytesLike;
10
+ amountInWei: bigint;
11
+ path: IPath[];
15
12
  }
16
13
  export interface ISwapParams {
17
- chain: ChainNameEnum;
18
14
  user: string;
19
- fromToken: string;
20
- toToken: string;
21
- amount: bigint;
15
+ chain: ChainNameEnum;
16
+ amountInWei: bigint;
17
+ path: IPath[];
18
+ minAmountOutList: bigint[];
22
19
  }
23
20
  export interface IBridgeParams {
24
21
  chain: ChainNameEnum;
25
22
  user: string;
26
- fromToken: string;
27
- toToken: string;
28
- amount: bigint;
23
+ amountInWei: bigint;
24
+ bridgeType: string;
25
+ bridgeAddress: string;
26
+ tokenAddress: string;
27
+ destChain: string;
28
+ extra?: BytesLike;
29
29
  }
30
30
  export interface ISwapAndBridgeParams {
31
31
  chain: ChainNameEnum;
32
32
  user: string;
33
- swapParams: ISwapParams;
34
- bridgeParams: IBridgeParams;
33
+ amountInWei: bigint;
34
+ path: IPath[];
35
+ minAmountOutList: bigint[];
36
+ bridgeType: string;
37
+ bridgeAddress: string;
38
+ tokenAddress: string;
39
+ destChain: string;
40
+ extra?: BytesLike;
35
41
  }
36
42
  export interface IReceipt {
37
43
  fromToken?: string;
@@ -216,3 +222,10 @@ export declare const AddressConst: {
216
222
  };
217
223
  export interface IExpectPayload {
218
224
  }
225
+ export interface IPath {
226
+ dexType: string;
227
+ poolAddress: string;
228
+ fromCoinAddress: string;
229
+ toCoinAddress: string;
230
+ extra?: BytesLike;
231
+ }