hermes-swap 0.0.20 → 0.0.22

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,5 +1,7 @@
1
- import { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath } from './types.js';
2
- export { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath };
1
+ import type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath } from './types.js';
2
+ import { ChainNameEnum, AddressConst, DexType } from './types.js';
3
+ export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath };
4
+ export { ChainNameEnum, AddressConst, DexType };
3
5
  declare class Hermes {
4
6
  private config;
5
7
  private providerMap;
package/dist/cjs/index.js CHANGED
@@ -33,14 +33,6 @@ __export(src_exports, {
33
33
  ChainNameEnum: () => import_types.ChainNameEnum,
34
34
  DexType: () => import_types.DexType,
35
35
  Hermes: () => Hermes,
36
- IBridgeParams: () => import_types.IBridgeParams,
37
- IConfig: () => import_types.IConfig,
38
- IExpectParams: () => import_types.IExpectParams,
39
- IExpectPayload: () => import_types.IExpectPayload,
40
- IReceipt: () => import_types.IReceipt,
41
- IRouterPath: () => import_types.IRouterPath,
42
- ISwapAndBridgeParams: () => import_types.ISwapAndBridgeParams,
43
- ISwapParams: () => import_types.ISwapParams,
44
36
  default: () => src_default
45
37
  });
46
38
  module.exports = __toCommonJS(src_exports);
@@ -63,7 +55,6 @@ var Hermes = class {
63
55
  this.walletMap.set(chainName, new import_ethers.ethers.Wallet(rpc.privateKey, provider));
64
56
  }
65
57
  }
66
- console.log(Object.entries(this.config.rpc), this.walletMap);
67
58
  for (const [chainName, quoterAddress] of Object.entries(this.config.quoterAddress)) {
68
59
  this.quoterAddressMap.set(chainName, quoterAddress);
69
60
  }
@@ -154,17 +145,37 @@ var Hermes = class {
154
145
  return {
155
146
  fromToken: fromTokenAddress,
156
147
  toToken: toTokenAddress,
157
- amountOut
148
+ amountOut,
149
+ hash: receipt.hash,
150
+ from: receipt.from,
151
+ to: receipt.from,
152
+ logs: receipt.logs
158
153
  };
159
154
  }
160
155
  async bridge(params) {
161
156
  this.validateParams(params);
162
- const receipt = {};
157
+ const receipt = {
158
+ fromToken: params.tokenAddress,
159
+ toToken: params.tokenAddress,
160
+ amountOut: params.amountInWei,
161
+ hash: "",
162
+ from: "",
163
+ to: "",
164
+ logs: []
165
+ };
163
166
  return Promise.resolve(receipt);
164
167
  }
165
168
  async swapAndBridge(params) {
166
169
  this.validateParams(params);
167
- const receipt = {};
170
+ const receipt = {
171
+ fromToken: params.path[0].fromCoinAddress,
172
+ toToken: params.path[params.path.length - 1].toCoinAddress,
173
+ amountOut: params.minAmountOutList[params.minAmountOutList.length - 1],
174
+ hash: "",
175
+ from: "",
176
+ to: "",
177
+ logs: []
178
+ };
168
179
  return Promise.resolve(receipt);
169
180
  }
170
181
  validateParams(params) {
@@ -195,13 +206,5 @@ var src_default = Hermes;
195
206
  AddressConst,
196
207
  ChainNameEnum,
197
208
  DexType,
198
- Hermes,
199
- IBridgeParams,
200
- IConfig,
201
- IExpectParams,
202
- IExpectPayload,
203
- IReceipt,
204
- IRouterPath,
205
- ISwapAndBridgeParams,
206
- ISwapParams
209
+ Hermes
207
210
  });
@@ -1,4 +1,4 @@
1
- import type { BytesLike } from 'ethers';
1
+ import type { BytesLike, JsonRpcProvider } from 'ethers';
2
2
  export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
4
  quoterAddress: Record<string, string>;
@@ -39,9 +39,46 @@ export interface ISwapAndBridgeParams {
39
39
  extra?: BytesLike;
40
40
  }
41
41
  export interface IReceipt {
42
- fromToken?: string;
43
- toToken?: string;
44
- amountOut?: bigint;
42
+ fromToken: string;
43
+ toToken: string;
44
+ amountOut: bigint;
45
+ hash: string;
46
+ from: string;
47
+ to: string;
48
+ logs: ILog[];
49
+ }
50
+ export interface IEthersReceipt {
51
+ provider: JsonRpcProvider;
52
+ to: string;
53
+ from: string;
54
+ contractAddress: string | null;
55
+ hash: string;
56
+ index: number;
57
+ blockHash: string;
58
+ blockNumber: number;
59
+ logsBloom: string;
60
+ gasUsed: bigint;
61
+ blobGasUsed: null;
62
+ cumulativeGasUsed: bigint;
63
+ gasPrice: bigint;
64
+ blobGasPrice: null;
65
+ type: number;
66
+ status: number;
67
+ root: undefined;
68
+ logs: ILog[];
69
+ }
70
+ export interface ILog {
71
+ provider: JsonRpcProvider;
72
+ transactionHash: string;
73
+ blockHash: string;
74
+ blockNumber: number;
75
+ removed: undefined;
76
+ address: string;
77
+ data: string;
78
+ topics: string[];
79
+ index: number;
80
+ transactionIndex: number;
81
+ args: any[];
45
82
  }
46
83
  export declare enum DexType {
47
84
  FX = "f(x)"
@@ -1,5 +1,7 @@
1
- import { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath } from './types.js';
2
- export { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath };
1
+ import type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath } from './types.js';
2
+ import { ChainNameEnum, AddressConst, DexType } from './types.js';
3
+ export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath };
4
+ export { ChainNameEnum, AddressConst, DexType };
3
5
  declare class Hermes {
4
6
  private config;
5
7
  private providerMap;
package/dist/esm/index.js CHANGED
@@ -15,14 +15,15 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
15
15
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
17
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
- import { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath } from "./types.js";
18
+ import { ChainNameEnum, AddressConst, DexType } from "./types.js";
19
19
  import { ethers } from 'ethers';
20
20
  import { Contract } from 'ethers';
21
21
  import QuoterAbi from "./abis/quoter.js";
22
22
  import AggregatorAbi from "./abis/aggregator.js";
23
23
 
24
24
  // 导出所有类型定义,方便用户使用
25
- export { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, ChainNameEnum, AddressConst, IExpectPayload, DexType, IRouterPath };
25
+
26
+ export { ChainNameEnum, AddressConst, DexType };
26
27
  var Hermes = /*#__PURE__*/function () {
27
28
  function Hermes(config) {
28
29
  _classCallCheck(this, Hermes);
@@ -42,7 +43,6 @@ var Hermes = /*#__PURE__*/function () {
42
43
  this.walletMap.set(chainName, new ethers.Wallet(rpc.privateKey, provider));
43
44
  }
44
45
  }
45
- console.log(Object.entries(this.config.rpc), this.walletMap);
46
46
  for (var _i2 = 0, _Object$entries2 = Object.entries(this.config.quoterAddress); _i2 < _Object$entries2.length; _i2++) {
47
47
  var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
48
48
  _chainName = _Object$entries2$_i[0],
@@ -246,7 +246,11 @@ var Hermes = /*#__PURE__*/function () {
246
246
  return _context2.abrupt("return", {
247
247
  fromToken: fromTokenAddress,
248
248
  toToken: toTokenAddress,
249
- amountOut: amountOut
249
+ amountOut: amountOut,
250
+ hash: receipt.hash,
251
+ from: receipt.from,
252
+ to: receipt.from,
253
+ logs: receipt.logs
250
254
  });
251
255
  case 76:
252
256
  case "end":
@@ -268,7 +272,15 @@ var Hermes = /*#__PURE__*/function () {
268
272
  while (1) switch (_context3.prev = _context3.next) {
269
273
  case 0:
270
274
  this.validateParams(params);
271
- receipt = {};
275
+ receipt = {
276
+ fromToken: params.tokenAddress,
277
+ toToken: params.tokenAddress,
278
+ amountOut: params.amountInWei,
279
+ hash: '',
280
+ from: '',
281
+ to: '',
282
+ logs: []
283
+ };
272
284
  return _context3.abrupt("return", Promise.resolve(receipt));
273
285
  case 3:
274
286
  case "end":
@@ -290,7 +302,15 @@ var Hermes = /*#__PURE__*/function () {
290
302
  while (1) switch (_context4.prev = _context4.next) {
291
303
  case 0:
292
304
  this.validateParams(params);
293
- receipt = {};
305
+ receipt = {
306
+ fromToken: params.path[0].fromCoinAddress,
307
+ toToken: params.path[params.path.length - 1].toCoinAddress,
308
+ amountOut: params.minAmountOutList[params.minAmountOutList.length - 1],
309
+ hash: '',
310
+ from: '',
311
+ to: '',
312
+ logs: []
313
+ };
294
314
  return _context4.abrupt("return", Promise.resolve(receipt));
295
315
  case 3:
296
316
  case "end":
@@ -1,4 +1,4 @@
1
- import type { BytesLike } from 'ethers';
1
+ import type { BytesLike, JsonRpcProvider } from 'ethers';
2
2
  export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
4
  quoterAddress: Record<string, string>;
@@ -39,9 +39,46 @@ export interface ISwapAndBridgeParams {
39
39
  extra?: BytesLike;
40
40
  }
41
41
  export interface IReceipt {
42
- fromToken?: string;
43
- toToken?: string;
44
- amountOut?: bigint;
42
+ fromToken: string;
43
+ toToken: string;
44
+ amountOut: bigint;
45
+ hash: string;
46
+ from: string;
47
+ to: string;
48
+ logs: ILog[];
49
+ }
50
+ export interface IEthersReceipt {
51
+ provider: JsonRpcProvider;
52
+ to: string;
53
+ from: string;
54
+ contractAddress: string | null;
55
+ hash: string;
56
+ index: number;
57
+ blockHash: string;
58
+ blockNumber: number;
59
+ logsBloom: string;
60
+ gasUsed: bigint;
61
+ blobGasUsed: null;
62
+ cumulativeGasUsed: bigint;
63
+ gasPrice: bigint;
64
+ blobGasPrice: null;
65
+ type: number;
66
+ status: number;
67
+ root: undefined;
68
+ logs: ILog[];
69
+ }
70
+ export interface ILog {
71
+ provider: JsonRpcProvider;
72
+ transactionHash: string;
73
+ blockHash: string;
74
+ blockNumber: number;
75
+ removed: undefined;
76
+ address: string;
77
+ data: string;
78
+ topics: string[];
79
+ index: number;
80
+ transactionIndex: number;
81
+ args: any[];
45
82
  }
46
83
  export declare enum DexType {
47
84
  FX = "f(x)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-swap",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "A TypeScript utility library for swap and bridge",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",