hermes-swap 0.1.3 → 0.1.5

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.js CHANGED
@@ -73,10 +73,6 @@ var Hermes = class {
73
73
  }
74
74
  }
75
75
  async expectPriorityLocal(params) {
76
- const wallet = this.walletMap.get(params.chain);
77
- if (!wallet) {
78
- throw new Error(`Wallet not configured for chain: ${params.chain}`);
79
- }
80
76
  const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote`, {
81
77
  method: "POST",
82
78
  headers: {
@@ -85,8 +81,8 @@ var Hermes = class {
85
81
  body: JSON.stringify(params, (sanitizePricing, value) => typeof value === "bigint" ? value.toString() : value)
86
82
  });
87
83
  const data = await response.json();
88
- if (data.message && !data.amountOutWei) {
89
- throw new Error(`Hermes Signal API 错误: ${data.message}`);
84
+ if (data.code && data.msg) {
85
+ throw new Error(`Hermes Signal API 错误 [${data.code}]: ${data.msg}`);
90
86
  }
91
87
  if (!data.amountOutWei) {
92
88
  throw new Error(`Invalid response: amountOutWei is undefined. Response: ${JSON.stringify(data)}`);
@@ -94,15 +90,15 @@ var Hermes = class {
94
90
  return BigInt(data.amountOutWei);
95
91
  }
96
92
  async expect(params) {
97
- const wallet = this.walletMap.get(params.chain);
98
- if (!wallet) {
99
- throw new Error(`Wallet not configured for chain: ${params.chain}`);
93
+ const provider = this.providerMap.get(params.chain);
94
+ if (!provider) {
95
+ throw new Error(`Chain: ${params.chain} provider is undefined`);
100
96
  }
101
97
  const address = this.getQuoterAddress(params.chain);
102
98
  if (!address) {
103
99
  throw new Error(`Quoter address not found for chain: ${params.chain}`);
104
100
  }
105
- const quoter = new import_ethers.Contract(address, import_quoter.default, wallet);
101
+ const quoter = new import_ethers.Contract(address, import_quoter.default, provider);
106
102
  const quoteParams = params.path.map((p) => ({
107
103
  dexType: p.dexType,
108
104
  pool: p.poolAddress,
@@ -110,7 +106,7 @@ var Hermes = class {
110
106
  toCoin: p.toCoinAddress,
111
107
  extra: p.extra || "0x"
112
108
  }));
113
- const amountOutList = await quoter.multiQuote.staticCall(params.amountInWei, quoteParams, { from: wallet.address });
109
+ const amountOutList = await quoter.multiQuote.staticCall(params.amountInWei, quoteParams, { from: this.config.executor });
114
110
  if (!amountOutList.length) {
115
111
  throw new Error("No expect result return from smart contract");
116
112
  }
@@ -1,6 +1,7 @@
1
1
  import type { BytesLike, JsonRpcProvider } from 'ethers';
2
2
  export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
+ executor: string;
4
5
  quoterAddress: Record<string, string>;
5
6
  aggregatorAddress: Record<string, string>;
6
7
  hermesSignalDomain?: string;
package/dist/esm/index.js CHANGED
@@ -73,18 +73,11 @@ var Hermes = /*#__PURE__*/function () {
73
73
  key: "expectPriorityLocal",
74
74
  value: function () {
75
75
  var _expectPriorityLocal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
76
- var wallet, response, data;
76
+ var response, data;
77
77
  return _regeneratorRuntime().wrap(function _callee$(_context) {
78
78
  while (1) switch (_context.prev = _context.next) {
79
79
  case 0:
80
- wallet = this.walletMap.get(params.chain);
81
- if (wallet) {
82
- _context.next = 3;
83
- break;
84
- }
85
- throw new Error("Wallet not configured for chain: ".concat(params.chain));
86
- case 3:
87
- _context.next = 5;
80
+ _context.next = 2;
88
81
  return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote"), {
89
82
  method: 'POST',
90
83
  headers: {
@@ -94,26 +87,26 @@ var Hermes = /*#__PURE__*/function () {
94
87
  return typeof value === 'bigint' ? value.toString() : value;
95
88
  })
96
89
  });
97
- case 5:
90
+ case 2:
98
91
  response = _context.sent;
99
- _context.next = 8;
92
+ _context.next = 5;
100
93
  return response.json();
101
- case 8:
94
+ case 5:
102
95
  data = _context.sent;
103
- if (!(data.message && !data.amountOutWei)) {
104
- _context.next = 11;
96
+ if (!(data.code && data.msg)) {
97
+ _context.next = 8;
105
98
  break;
106
99
  }
107
- throw new Error("Hermes Signal API \u9519\u8BEF: ".concat(data.message));
108
- case 11:
100
+ throw new Error("Hermes Signal API \u9519\u8BEF [".concat(data.code, "]: ").concat(data.msg));
101
+ case 8:
109
102
  if (data.amountOutWei) {
110
- _context.next = 13;
103
+ _context.next = 10;
111
104
  break;
112
105
  }
113
106
  throw new Error("Invalid response: amountOutWei is undefined. Response: ".concat(JSON.stringify(data)));
114
- case 13:
107
+ case 10:
115
108
  return _context.abrupt("return", BigInt(data.amountOutWei));
116
- case 14:
109
+ case 11:
117
110
  case "end":
118
111
  return _context.stop();
119
112
  }
@@ -128,17 +121,17 @@ var Hermes = /*#__PURE__*/function () {
128
121
  key: "expect",
129
122
  value: function () {
130
123
  var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
131
- var wallet, address, quoter, quoteParams, amountOutList;
124
+ var provider, address, quoter, quoteParams, amountOutList;
132
125
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
133
126
  while (1) switch (_context2.prev = _context2.next) {
134
127
  case 0:
135
128
  // 调用合约
136
- wallet = this.walletMap.get(params.chain);
137
- if (wallet) {
129
+ provider = this.providerMap.get(params.chain);
130
+ if (provider) {
138
131
  _context2.next = 3;
139
132
  break;
140
133
  }
141
- throw new Error("Wallet not configured for chain: ".concat(params.chain));
134
+ throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
142
135
  case 3:
143
136
  address = this.getQuoterAddress(params.chain);
144
137
  if (address) {
@@ -147,7 +140,7 @@ var Hermes = /*#__PURE__*/function () {
147
140
  }
148
141
  throw new Error("Quoter address not found for chain: ".concat(params.chain));
149
142
  case 6:
150
- quoter = new Contract(address, QuoterAbi, wallet); // 转换字段名以匹配合约 ABI
143
+ quoter = new Contract(address, QuoterAbi, provider); // 转换字段名以匹配合约 ABI
151
144
  quoteParams = params.path.map(function (p) {
152
145
  return {
153
146
  dexType: p.dexType,
@@ -159,7 +152,7 @@ var Hermes = /*#__PURE__*/function () {
159
152
  });
160
153
  _context2.next = 10;
161
154
  return quoter.multiQuote.staticCall(params.amountInWei, quoteParams, {
162
- from: wallet.address
155
+ from: this.config.executor
163
156
  });
164
157
  case 10:
165
158
  amountOutList = _context2.sent;
@@ -1,6 +1,7 @@
1
1
  import type { BytesLike, JsonRpcProvider } from 'ethers';
2
2
  export interface IConfig {
3
3
  rpc: Record<string, IRpcConfig>;
4
+ executor: string;
4
5
  quoterAddress: Record<string, string>;
5
6
  aggregatorAddress: Record<string, string>;
6
7
  hermesSignalDomain?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-swap",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "A TypeScript utility library for swap and bridge",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",