hermes-swap 0.0.10 → 0.0.12
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/README.md +2 -0
- package/dist/cjs/abis/quoter.d.ts +80 -0
- package/dist/cjs/abis/quoter.js +524 -0
- package/dist/cjs/bridge/index.d.ts +0 -0
- package/dist/cjs/bridge/index.js +0 -0
- package/dist/cjs/dex/index.d.ts +0 -0
- package/dist/cjs/dex/index.js +0 -0
- package/dist/cjs/index.d.ts +20 -0
- package/dist/cjs/index.js +177 -0
- package/dist/cjs/types.d.ts +218 -0
- package/dist/cjs/types.js +207 -0
- package/dist/esm/abis/quoter.d.ts +80 -0
- package/dist/esm/abis/quoter.js +381 -0
- package/dist/esm/bridge/index.d.ts +0 -0
- package/dist/esm/bridge/index.js +0 -0
- package/dist/esm/dex/index.d.ts +0 -0
- package/dist/esm/dex/index.js +5 -0
- package/dist/esm/index.d.ts +13 -2
- package/dist/esm/index.js +285 -1
- package/dist/esm/types.d.ts +194 -0
- package/dist/esm/types.js +175 -1
- package/package.json +5 -1
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,285 @@
|
|
|
1
|
-
function _typeof(
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
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); }
|
|
17
|
+
import { ChainNameEnum, AddressConst } from "./types";
|
|
18
|
+
import { ethers } from 'ethers';
|
|
19
|
+
import { Contract } from 'ethers';
|
|
20
|
+
import QuoterAbi from "./abis/quoter";
|
|
21
|
+
var Hermes = /*#__PURE__*/function () {
|
|
22
|
+
function Hermes(config) {
|
|
23
|
+
_classCallCheck(this, Hermes);
|
|
24
|
+
_defineProperty(this, "config", void 0);
|
|
25
|
+
_defineProperty(this, "providerMap", new Map());
|
|
26
|
+
_defineProperty(this, "walletMap", new Map());
|
|
27
|
+
_defineProperty(this, "quoterAddressMap", new Map());
|
|
28
|
+
_defineProperty(this, "aggregatorAddressMap", new Map());
|
|
29
|
+
_defineProperty(this, "executorMap", new Map());
|
|
30
|
+
this.config = config;
|
|
31
|
+
for (var _i = 0, _Object$entries = Object.entries(this.config.rpc); _i < _Object$entries.length; _i++) {
|
|
32
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
33
|
+
chainName = _Object$entries$_i[0],
|
|
34
|
+
rpc = _Object$entries$_i[1];
|
|
35
|
+
var provider = new ethers.JsonRpcProvider(rpc.url);
|
|
36
|
+
this.providerMap.set(chainName, provider);
|
|
37
|
+
if (rpc.privateKey) {
|
|
38
|
+
this.walletMap.set(chainName, new ethers.Wallet(rpc.privateKey));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(this.config.quoterAddress); _i2 < _Object$entries2.length; _i2++) {
|
|
42
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
43
|
+
_chainName = _Object$entries2$_i[0],
|
|
44
|
+
quoterAddress = _Object$entries2$_i[1];
|
|
45
|
+
this.quoterAddressMap.set(_chainName, quoterAddress);
|
|
46
|
+
}
|
|
47
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(this.config.aggregatorAddress); _i3 < _Object$entries3.length; _i3++) {
|
|
48
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
49
|
+
_chainName2 = _Object$entries3$_i[0],
|
|
50
|
+
aggregatorAddress = _Object$entries3$_i[1];
|
|
51
|
+
this.aggregatorAddressMap.set(_chainName2, aggregatorAddress);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// load executor
|
|
55
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(this.config.executorMap); _i4 < _Object$entries4.length; _i4++) {
|
|
56
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
57
|
+
_chainName3 = _Object$entries4$_i[0],
|
|
58
|
+
executorPrivateKey = _Object$entries4$_i[1];
|
|
59
|
+
var _provider = this.providerMap.get(_chainName3);
|
|
60
|
+
var executor = new ethers.Wallet(executorPrivateKey, _provider);
|
|
61
|
+
this.executorMap.set(_chainName3, executor);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
_createClass(Hermes, [{
|
|
65
|
+
key: "expect",
|
|
66
|
+
value: function () {
|
|
67
|
+
var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
68
|
+
var tokenPair, address, provider, quoteParams, executorWallet, quoter, amountOutList;
|
|
69
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
70
|
+
while (1) switch (_context.prev = _context.next) {
|
|
71
|
+
case 0:
|
|
72
|
+
// 直接调用fx合约: fx合约地址: 0xF9C0c2afCF3CB0B29c32dc2B3Bc8feA039206bdf
|
|
73
|
+
// this.validateParams(params);
|
|
74
|
+
|
|
75
|
+
// const tokenPair = this.getTokenPair(params.chain, params.fromToken, params.toToken);
|
|
76
|
+
// const provider = this.providerMap.get(params.chain);
|
|
77
|
+
// if (!provider) {
|
|
78
|
+
// throw new Error(`Provider not found for chain: ${params.chain}`);
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
// if (!tokenPair.path.length) {
|
|
82
|
+
// throw new Error(`Quote path not configured for chain: ${params.chain} from: ${params.fromToken} to: ${params.toToken}`);
|
|
83
|
+
// }
|
|
84
|
+
|
|
85
|
+
// const fxPath = tokenPair.path[0];
|
|
86
|
+
// const fxAbi: ethers.InterfaceAbi = [
|
|
87
|
+
// {
|
|
88
|
+
// inputs: [
|
|
89
|
+
// {
|
|
90
|
+
// components: [
|
|
91
|
+
// { internalType: 'uint256', name: 'amountIn', type: 'uint256' },
|
|
92
|
+
// { internalType: 'address', name: 'pool', type: 'address' },
|
|
93
|
+
// { internalType: 'address', name: 'fromCoin', type: 'address' },
|
|
94
|
+
// { internalType: 'address', name: 'toCoin', type: 'address' },
|
|
95
|
+
// { internalType: 'bytes', name: 'extra', type: 'bytes' },
|
|
96
|
+
// ],
|
|
97
|
+
// internalType: 'struct QuoteParam',
|
|
98
|
+
// name: 'param',
|
|
99
|
+
// type: 'tuple',
|
|
100
|
+
// },
|
|
101
|
+
// ],
|
|
102
|
+
// name: 'quote',
|
|
103
|
+
// outputs: [
|
|
104
|
+
// { internalType: 'uint256', name: 'amountOut', type: 'uint256' },
|
|
105
|
+
// ],
|
|
106
|
+
// stateMutability: 'view',
|
|
107
|
+
// type: 'function',
|
|
108
|
+
// },
|
|
109
|
+
// ];
|
|
110
|
+
|
|
111
|
+
// const fxContract = new Contract('0xF9C0c2afCF3CB0B29c32dc2B3Bc8feA039206bdf', fxAbi, provider);
|
|
112
|
+
// const amountOut = await fxContract.quote({
|
|
113
|
+
// amountIn: params.amount,
|
|
114
|
+
// pool: fxPath.pool,
|
|
115
|
+
// fromCoin: fxPath.fromCoin,
|
|
116
|
+
// toCoin: fxPath.toCoin,
|
|
117
|
+
// extra: params.extra ?? fxPath.extra ?? '0x',
|
|
118
|
+
// });
|
|
119
|
+
// return amountOut as bigint;
|
|
120
|
+
|
|
121
|
+
// 校验
|
|
122
|
+
this.validateParams(params);
|
|
123
|
+
|
|
124
|
+
// 找池子: weth => usdt
|
|
125
|
+
tokenPair = this.getTokenPair(params.chain, params.fromToken, params.toToken);
|
|
126
|
+
if (tokenPair) {
|
|
127
|
+
_context.next = 4;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
throw new Error("Token pair not found for chain: ".concat(params.chain));
|
|
131
|
+
case 4:
|
|
132
|
+
address = this.getQuoterAddress(params.chain);
|
|
133
|
+
console.log("quoter address: ", address);
|
|
134
|
+
provider = this.providerMap.get(params.chain);
|
|
135
|
+
if (provider) {
|
|
136
|
+
_context.next = 9;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
throw new Error("Provider not found for chain: ".concat(params.chain));
|
|
140
|
+
case 9:
|
|
141
|
+
if (tokenPair.path.length) {
|
|
142
|
+
_context.next = 11;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
throw new Error("Quote path not configured for chain: ".concat(params.chain, " from: ").concat(params.fromToken, " to: ").concat(params.toToken));
|
|
146
|
+
case 11:
|
|
147
|
+
console.log("dex type: ", params.dexType);
|
|
148
|
+
quoteParams = tokenPair.path.map(function (pathItem) {
|
|
149
|
+
var _params$dexType, _ref, _pathItem$extra;
|
|
150
|
+
return {
|
|
151
|
+
dexType: (_params$dexType = params.dexType) !== null && _params$dexType !== void 0 ? _params$dexType : pathItem.dexType,
|
|
152
|
+
pool: pathItem.pool,
|
|
153
|
+
fromCoin: pathItem.fromCoin,
|
|
154
|
+
toCoin: pathItem.toCoin,
|
|
155
|
+
extra: (_ref = (_pathItem$extra = pathItem.extra) !== null && _pathItem$extra !== void 0 ? _pathItem$extra : params.extra) !== null && _ref !== void 0 ? _ref : '0x'
|
|
156
|
+
};
|
|
157
|
+
}); // 调用合约
|
|
158
|
+
executorWallet = this.executorMap.get(params.chain);
|
|
159
|
+
if (executorWallet) {
|
|
160
|
+
_context.next = 16;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
throw new Error("Executor wallet not configured for chain: ".concat(params.chain));
|
|
164
|
+
case 16:
|
|
165
|
+
console.log("wallet address: ", executorWallet.address);
|
|
166
|
+
quoter = new Contract(address, QuoterAbi, executorWallet);
|
|
167
|
+
_context.t0 = console;
|
|
168
|
+
_context.next = 21;
|
|
169
|
+
return quoter.executor();
|
|
170
|
+
case 21:
|
|
171
|
+
_context.t1 = _context.sent;
|
|
172
|
+
_context.t0.log.call(_context.t0, "executor address: ", _context.t1);
|
|
173
|
+
_context.next = 25;
|
|
174
|
+
return quoter.multiQuote(params.amount, quoteParams);
|
|
175
|
+
case 25:
|
|
176
|
+
amountOutList = _context.sent;
|
|
177
|
+
return _context.abrupt("return", amountOutList.length ? amountOutList[amountOutList.length - 1] : BigInt(0));
|
|
178
|
+
case 27:
|
|
179
|
+
case "end":
|
|
180
|
+
return _context.stop();
|
|
181
|
+
}
|
|
182
|
+
}, _callee, this);
|
|
183
|
+
}));
|
|
184
|
+
function expect(_x) {
|
|
185
|
+
return _expect.apply(this, arguments);
|
|
186
|
+
}
|
|
187
|
+
return expect;
|
|
188
|
+
}()
|
|
189
|
+
}, {
|
|
190
|
+
key: "swap",
|
|
191
|
+
value: function swap(params) {
|
|
192
|
+
this.validateParams(params);
|
|
193
|
+
var receipt = {
|
|
194
|
+
fromToken: params.fromToken,
|
|
195
|
+
toToken: params.toToken,
|
|
196
|
+
amount: params.amount
|
|
197
|
+
};
|
|
198
|
+
return Promise.resolve(receipt);
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "bridge",
|
|
202
|
+
value: function bridge(params) {
|
|
203
|
+
this.validateParams(params);
|
|
204
|
+
var receipt = {
|
|
205
|
+
fromToken: params.fromToken,
|
|
206
|
+
toToken: params.toToken,
|
|
207
|
+
amount: params.amount
|
|
208
|
+
};
|
|
209
|
+
return Promise.resolve(receipt);
|
|
210
|
+
}
|
|
211
|
+
}, {
|
|
212
|
+
key: "swapAndBridge",
|
|
213
|
+
value: function swapAndBridge(params) {
|
|
214
|
+
this.validateParams(params);
|
|
215
|
+
var receipt = {};
|
|
216
|
+
return Promise.resolve(receipt);
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
key: "validateParams",
|
|
220
|
+
value: function validateParams(params) {
|
|
221
|
+
if (!params.chain) {
|
|
222
|
+
throw new Error('Chain not found');
|
|
223
|
+
}
|
|
224
|
+
var provider = this.providerMap.get(params.chain);
|
|
225
|
+
if (!provider) {
|
|
226
|
+
throw new Error('Provider not found');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "getAllTokenPair",
|
|
231
|
+
value: function getAllTokenPair() {
|
|
232
|
+
return _defineProperty({}, ChainNameEnum.ETH, [{
|
|
233
|
+
from: AddressConst.weth.eth,
|
|
234
|
+
to: AddressConst.usdt.eth,
|
|
235
|
+
path: []
|
|
236
|
+
},
|
|
237
|
+
// fx
|
|
238
|
+
{
|
|
239
|
+
from: AddressConst.weth.eth,
|
|
240
|
+
to: AddressConst.feth.eth,
|
|
241
|
+
path: [{
|
|
242
|
+
dexType: 'f(x)',
|
|
243
|
+
pool: '0xe7b9c7c9cA85340b8c06fb805f7775e3015108dB',
|
|
244
|
+
fromCoin: AddressConst.weth.eth,
|
|
245
|
+
toCoin: AddressConst.feth.eth,
|
|
246
|
+
extra: '0x'
|
|
247
|
+
}]
|
|
248
|
+
}]);
|
|
249
|
+
}
|
|
250
|
+
}, {
|
|
251
|
+
key: "getTokenPair",
|
|
252
|
+
value: function getTokenPair(chain, from, to) {
|
|
253
|
+
var tokenPairMap = this.getAllTokenPair();
|
|
254
|
+
var tokenPairList = tokenPairMap[chain];
|
|
255
|
+
if (!tokenPairList) {
|
|
256
|
+
throw new Error("Token pair not found for chain: ".concat(chain));
|
|
257
|
+
}
|
|
258
|
+
var tokenPair = tokenPairList.find(function (item) {
|
|
259
|
+
return item.from.toLocaleLowerCase() === from.toLocaleLowerCase() && item.to.toLocaleLowerCase() === to.toLocaleLowerCase();
|
|
260
|
+
});
|
|
261
|
+
if (!tokenPair) {
|
|
262
|
+
throw new Error("Token pair not found for chain: ".concat(chain, " from: ").concat(from, " to: ").concat(to));
|
|
263
|
+
}
|
|
264
|
+
return tokenPair;
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
key: "getQuoterAddress",
|
|
268
|
+
value: function getQuoterAddress(chain) {
|
|
269
|
+
if (this.quoterAddressMap.has(chain)) {
|
|
270
|
+
return this.quoterAddressMap.get(chain);
|
|
271
|
+
}
|
|
272
|
+
throw new Error("Quoter address not found for chain: ".concat(chain));
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "getAggregatorAddress",
|
|
276
|
+
value: function getAggregatorAddress(chain) {
|
|
277
|
+
if (this.aggregatorAddressMap.has(chain)) {
|
|
278
|
+
return this.aggregatorAddressMap.get(chain);
|
|
279
|
+
}
|
|
280
|
+
throw new Error("Aggregator address not found for chain: ".concat(chain));
|
|
281
|
+
}
|
|
282
|
+
}]);
|
|
283
|
+
return Hermes;
|
|
284
|
+
}();
|
|
285
|
+
export default Hermes;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
|
+
import type { BytesLike } from 'ethers';
|
|
2
|
+
export interface IConfig {
|
|
3
|
+
rpc: Record<string, IRpcConfig>;
|
|
4
|
+
quoterAddress: Record<string, string>;
|
|
5
|
+
aggregatorAddress: Record<string, string>;
|
|
6
|
+
executorMap: Record<string, string>;
|
|
7
|
+
}
|
|
1
8
|
export interface IExpectParams {
|
|
9
|
+
chain: ChainNameEnum;
|
|
10
|
+
dexType?: string;
|
|
2
11
|
fromToken: string;
|
|
3
12
|
toToken: string;
|
|
4
13
|
amount: bigint;
|
|
14
|
+
extra?: BytesLike;
|
|
5
15
|
}
|
|
6
16
|
export interface ISwapParams {
|
|
17
|
+
chain: ChainNameEnum;
|
|
18
|
+
user: string;
|
|
7
19
|
fromToken: string;
|
|
8
20
|
toToken: string;
|
|
9
21
|
amount: bigint;
|
|
10
22
|
}
|
|
11
23
|
export interface IBridgeParams {
|
|
24
|
+
chain: ChainNameEnum;
|
|
25
|
+
user: string;
|
|
12
26
|
fromToken: string;
|
|
13
27
|
toToken: string;
|
|
14
28
|
amount: bigint;
|
|
15
29
|
}
|
|
16
30
|
export interface ISwapAndBridgeParams {
|
|
31
|
+
chain: ChainNameEnum;
|
|
32
|
+
user: string;
|
|
17
33
|
swapParams: ISwapParams;
|
|
18
34
|
bridgeParams: IBridgeParams;
|
|
19
35
|
}
|
|
@@ -22,3 +38,181 @@ export interface IReceipt {
|
|
|
22
38
|
toToken?: string;
|
|
23
39
|
amount?: bigint;
|
|
24
40
|
}
|
|
41
|
+
export declare enum DexType {
|
|
42
|
+
FX = "f(x)"
|
|
43
|
+
}
|
|
44
|
+
export declare enum ChainNameEnum {
|
|
45
|
+
ETH = "ETH",// Ethereum Mainnet
|
|
46
|
+
ARB = "ARB",// Arbitrum One
|
|
47
|
+
BSC = "BSC",// BNB Smart Chain Mainnet
|
|
48
|
+
POL = "POL",// Polygon Mainnet
|
|
49
|
+
OP = "OP",// Optimism
|
|
50
|
+
BASE = "BASE",// Base
|
|
51
|
+
XPLA = "XPLA",// XPLA Mainnet
|
|
52
|
+
TELOS = "TELOS",// Telos EVM Mainnet
|
|
53
|
+
OKT = "OKT",// OKXChain Mainnet
|
|
54
|
+
VIC = "VIC",// Viction
|
|
55
|
+
GNOSIS = "GNOSIS",// Gnosis
|
|
56
|
+
FUSE = "FUSE",// Fuse Mainnet
|
|
57
|
+
MANTA = "MANTA",// Manta Pacific Mainnet
|
|
58
|
+
OPBNB = "OPBNB",// opBNB Mainnet
|
|
59
|
+
FTM = "FTM",// Fantom Opera
|
|
60
|
+
ORDERLY = "ORDERLY",// Orderly Mainnet
|
|
61
|
+
ASTAR = "ASTAR",// Astar
|
|
62
|
+
CFX = "CFX",// Conflux eSpace
|
|
63
|
+
METIS = "METIS",// Metis Andromeda Mainnet
|
|
64
|
+
POLZK = "POLZK",// Polygon zkEVM
|
|
65
|
+
CORE = "CORE",// Core Blockchain Mainnet
|
|
66
|
+
MOON = "MOON",// Moonbeam
|
|
67
|
+
MOVR = "MOVR",// Moonriver
|
|
68
|
+
TENET = "TENET",// Tenet
|
|
69
|
+
KAVA = "KAVA",// Kava
|
|
70
|
+
BEAM = "BEAM",// Beam
|
|
71
|
+
MNT = "MNT",// Mantle
|
|
72
|
+
EON = "EON",// Horizen EON Mainnet
|
|
73
|
+
KLAY = "KLAY",// Kaia Mainnet
|
|
74
|
+
NOVA = "NOVA",// Arbitrum Nova
|
|
75
|
+
CELO = "CELO",// Celo Mainnet
|
|
76
|
+
AVAX = "AVAX",// Avalanche C-Chain
|
|
77
|
+
LINEA = "LINEA",// Linea
|
|
78
|
+
SCROLL = "SCROLL",// Scroll
|
|
79
|
+
LOOT = "LOOT",// Loot Mainnet
|
|
80
|
+
ZORA = "ZORA",// Zora
|
|
81
|
+
AURORA = "AURORA",// Aurora Mainnet
|
|
82
|
+
NOTALLOW = "NOTALLOW",// Not Allowed Chain
|
|
83
|
+
SOL = "SOL",// Solana Mainnet
|
|
84
|
+
SWIMMER = "SWIMMER",// Swimmer
|
|
85
|
+
DFK = "DFK",// DFK
|
|
86
|
+
HARMONY = "HARMONY",// Harmony
|
|
87
|
+
DEXALOT = "DEXALOT",// Dexalot
|
|
88
|
+
INTAIN = "INTAIN",// Intain
|
|
89
|
+
GOERLI = "GOERLI",// Goerli
|
|
90
|
+
CANTO = "CANTO",// Canto
|
|
91
|
+
ZKSYNC = "ZKSYNC",// zkSync
|
|
92
|
+
SHRAPNEL = "SHRAPNEL",// Shrapnel
|
|
93
|
+
DOS = "DOS",// DOS
|
|
94
|
+
ZKPOLYGON = "ZKPOLYGON",// Polygon zkEVM
|
|
95
|
+
SEPOLIA = "SEPOLIA",// Sepolia
|
|
96
|
+
METER = "METER",// Meter
|
|
97
|
+
HUBBLE = "HUBBLE",// Hubble
|
|
98
|
+
ZKCONSENSYS = "ZKCONSENSYS",// Linea
|
|
99
|
+
TOMO = "TOMO",// Tomo
|
|
100
|
+
MERITCIRCLE = "MERITCIRCLE",// Merit Circle
|
|
101
|
+
LIF3 = "LIF3",// LIF3
|
|
102
|
+
SHIMMER = "SHIMMER",// Shimmer
|
|
103
|
+
BB1 = "BB1",// BB1
|
|
104
|
+
RARIBLE = "RARIBLE",// Rarible
|
|
105
|
+
XAI = "XAI",// XAI
|
|
106
|
+
REAL = "REAL",// Real
|
|
107
|
+
TILTYARD = "TILTYARD",// Tiltyard
|
|
108
|
+
FRAXTAL = "FRAXTAL",// Fraxtal
|
|
109
|
+
TRON = "TRON",// Tron
|
|
110
|
+
ZKATANA = "ZKATANA",// zkAtana
|
|
111
|
+
BLAST = "BLAST",// Blast
|
|
112
|
+
MODE = "MODE",// Mode
|
|
113
|
+
MASA = "MASA",// Masa
|
|
114
|
+
HOMEVERSE = "HOMEVERSE",// Homeverse
|
|
115
|
+
MERLIN = "MERLIN",// Merlin
|
|
116
|
+
DEGEN = "DEGEN",// Degen
|
|
117
|
+
SKALE = "SKALE",// Skale
|
|
118
|
+
XLAYER = "XLAYER",// XLayer
|
|
119
|
+
SANKO = "SANKO",// Sanko
|
|
120
|
+
BOB = "BOB",// Bob
|
|
121
|
+
SEI = "SEI",// Sei
|
|
122
|
+
EBI = "EBI",// EBI
|
|
123
|
+
CYBER = "CYBER",// Cyber
|
|
124
|
+
IOTA = "IOTA",// IOTA
|
|
125
|
+
KINTO = "KINTO",// Kinto
|
|
126
|
+
JOC = "JOC",// JOC
|
|
127
|
+
TAIKO = "TAIKO",// Taiko
|
|
128
|
+
XCHAIN = "XCHAIN",// XChain
|
|
129
|
+
ETHERLINK = "ETHERLINK",// Etherlink
|
|
130
|
+
BOUNCEBIT = "BOUNCEBIT",// BounceBit
|
|
131
|
+
GRAVITY = "GRAVITY",// Gravity
|
|
132
|
+
FLARE = "FLARE",// Flare
|
|
133
|
+
ZKLINK = "ZKLINK",// zkLink
|
|
134
|
+
PEAQ = "PEAQ",// PEAQ
|
|
135
|
+
ZIRCUIT = "ZIRCUIT",// Zircuit
|
|
136
|
+
LIGHTLINK = "LIGHTLINK",// Lightlink
|
|
137
|
+
APTOS = "APTOS",// Aptos
|
|
138
|
+
CODEX = "CODEX",// Codex
|
|
139
|
+
LYRA = "LYRA",// Lyra
|
|
140
|
+
APE = "APE",// Ape
|
|
141
|
+
REYA = "REYA",// Reya
|
|
142
|
+
BITLAYER = "BITLAYER",// Bitlayer
|
|
143
|
+
DM2VERSE = "DM2VERSE",// DM2Verse
|
|
144
|
+
INITIA = "INITIA",// Initia
|
|
145
|
+
MOVEMENT = "MOVEMENT",// Movement
|
|
146
|
+
HEDERA = "HEDERA",// Hedera
|
|
147
|
+
PLUME = "PLUME",// Plume
|
|
148
|
+
WORLDCHAIN = "WORLDCHAIN",// Worldcoin
|
|
149
|
+
UNICHAIN = "UNICHAIN",// Unichain
|
|
150
|
+
LISK = "LISK",// Lisk
|
|
151
|
+
MORPH = "MORPH",// Morph
|
|
152
|
+
ABSTRACT = "ABSTRACT",// Abstract
|
|
153
|
+
SUPERPOSITION = "SUPERPOSITION",// Superposition
|
|
154
|
+
EDU = "EDU",// Edu
|
|
155
|
+
HEMI = "HEMI",// Hemi
|
|
156
|
+
ISLANDER = "ISLANDER",// Islander
|
|
157
|
+
MP1 = "MP1",// MP1
|
|
158
|
+
SONIC = "SONIC",// Sonic
|
|
159
|
+
ROOTSTOCK = "ROOTSTOCK",// Rootstock
|
|
160
|
+
SOPHON = "SOPHON",// Sophon
|
|
161
|
+
SWELL = "SWELL",// Swell
|
|
162
|
+
FLOW = "FLOW",// Flow
|
|
163
|
+
BL4 = "BL4",// BL4
|
|
164
|
+
BL5 = "BL5",// BL5
|
|
165
|
+
INK = "INK",// Ink
|
|
166
|
+
SONEIUM = "SONEIUM",// Soneium
|
|
167
|
+
SPACE = "SPACE",// Space
|
|
168
|
+
GLUE = "GLUE",// Glue
|
|
169
|
+
CRONOSEVM = "CRONOSEVM",// Cronos EVM
|
|
170
|
+
CRONOSZKEVM = "CRONOSZKEVM",// Cronos zkEVM
|
|
171
|
+
GOAT = "GOAT",// Goat
|
|
172
|
+
BERA = "BERA",// Bera
|
|
173
|
+
BAHAMUT = "BAHAMUT",// Bahamut
|
|
174
|
+
STORY = "STORY",// Story
|
|
175
|
+
XDC = "XDC",// XDC
|
|
176
|
+
CONCRETE = "CONCRETE",// Concrete
|
|
177
|
+
HYPERLIQUID = "HYPERLIQUID",// Hyperliquid
|
|
178
|
+
NIBIRUBURNED = "NIBIRUBURNED",// Nibiru Burned
|
|
179
|
+
NIBIRU = "NIBIRU",// Nibiru
|
|
180
|
+
PLUMEPHOENIX = "PLUMEPHOENIX",// Plume Phoenix
|
|
181
|
+
GUNZ = "GUNZ",// Gunz
|
|
182
|
+
ANIMECHAIN = "ANIMECHAIN",// Animechain
|
|
183
|
+
LENS = "LENS",// Lens
|
|
184
|
+
SUBTENSOREVM = "SUBTENSOREVM",// Subtensor EVM
|
|
185
|
+
KATANA = "KATANA",// Katana
|
|
186
|
+
BOTANIX = "BOTANIX",// Botanix
|
|
187
|
+
TAC = "TAC",// TAC
|
|
188
|
+
SILICON = "SILICON",// Silicon
|
|
189
|
+
SOMNIA = "SOMNIA",// Somnia
|
|
190
|
+
PLACEHOLDER0 = "PLACEHOLDER0",// Placeholder0
|
|
191
|
+
CAMP = "CAMP",// Camp
|
|
192
|
+
CONVERGE = "CONVERGE",// Converge
|
|
193
|
+
HUMANITY = "HUMANITY",// Humanity
|
|
194
|
+
PLASMA = "PLASMA",// Plasma
|
|
195
|
+
APEXFUSIONNEXUS = "APEXFUSIONNEXUS",// Apex Fusion Nexus
|
|
196
|
+
PGN = "PGN",// PGN
|
|
197
|
+
BEVM = "BEVM"
|
|
198
|
+
}
|
|
199
|
+
export interface IRpcConfig {
|
|
200
|
+
url: string;
|
|
201
|
+
privateKey?: string;
|
|
202
|
+
}
|
|
203
|
+
export declare const AddressConst: {
|
|
204
|
+
weth: {
|
|
205
|
+
eth: string;
|
|
206
|
+
};
|
|
207
|
+
usdt: {
|
|
208
|
+
eth: string;
|
|
209
|
+
};
|
|
210
|
+
feth: {
|
|
211
|
+
eth: string;
|
|
212
|
+
};
|
|
213
|
+
xeth: {
|
|
214
|
+
eth: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
export interface IExpectPayload {
|
|
218
|
+
}
|