@reactmore/crypto-wallet-sdk 1.2.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.
- package/LICENSE +21 -0
- package/README.md +255 -0
- package/dist/api/dex.d.ts +7 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/crypto-wallet-sdk.cjs.development.js +1962 -0
- package/dist/crypto-wallet-sdk.cjs.development.js.map +1 -0
- package/dist/crypto-wallet-sdk.cjs.production.min.js +2 -0
- package/dist/crypto-wallet-sdk.cjs.production.min.js.map +1 -0
- package/dist/crypto-wallet-sdk.esm.js +1950 -0
- package/dist/crypto-wallet-sdk.esm.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/services/base/index.d.ts +1 -0
- package/dist/services/base/wallet.d.ts +10 -0
- package/dist/services/btc/index.d.ts +1 -0
- package/dist/services/btc/wallet.d.ts +8 -0
- package/dist/services/evm/index.d.ts +2 -0
- package/dist/services/evm/types.d.ts +69 -0
- package/dist/services/evm/wallet.d.ts +24 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/sol/index.d.ts +2 -0
- package/dist/services/sol/types.d.ts +21 -0
- package/dist/services/sol/wallet.d.ts +19 -0
- package/dist/services/wallet-registry.d.ts +7 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/utils/amount.d.ts +10 -0
- package/dist/utils/btcUnits.d.ts +4 -0
- package/dist/utils/evmUnits.d.ts +6 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/response.d.ts +2 -0
- package/dist/utils/solUnits.d.ts +4 -0
- package/package.json +72 -0
|
@@ -0,0 +1,1962 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var cryptoLib = require('@okxweb3/crypto-lib');
|
|
8
|
+
var coinEthereum = require('@okxweb3/coin-ethereum');
|
|
9
|
+
var BigNumber = _interopDefault(require('bignumber.js'));
|
|
10
|
+
var ethers = require('ethers');
|
|
11
|
+
var coinBitcoin = require('@okxweb3/coin-bitcoin');
|
|
12
|
+
var coinSolana = require('@okxweb3/coin-solana');
|
|
13
|
+
var solanaWeb3 = require('@solana/web3.js');
|
|
14
|
+
var splToken = require('@solana/spl-token');
|
|
15
|
+
var splTokenRegistry = require('@solana/spl-token-registry');
|
|
16
|
+
var BufferLayout = require('buffer-layout');
|
|
17
|
+
|
|
18
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
19
|
+
try {
|
|
20
|
+
var i = n[a](c),
|
|
21
|
+
u = i.value;
|
|
22
|
+
} catch (n) {
|
|
23
|
+
return void e(n);
|
|
24
|
+
}
|
|
25
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
26
|
+
}
|
|
27
|
+
function _asyncToGenerator(n) {
|
|
28
|
+
return function () {
|
|
29
|
+
var t = this,
|
|
30
|
+
e = arguments;
|
|
31
|
+
return new Promise(function (r, o) {
|
|
32
|
+
var a = n.apply(t, e);
|
|
33
|
+
function _next(n) {
|
|
34
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
35
|
+
}
|
|
36
|
+
function _throw(n) {
|
|
37
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
38
|
+
}
|
|
39
|
+
_next(void 0);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function _defineProperties(e, r) {
|
|
44
|
+
for (var t = 0; t < r.length; t++) {
|
|
45
|
+
var o = r[t];
|
|
46
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _createClass(e, r, t) {
|
|
50
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
51
|
+
writable: !1
|
|
52
|
+
}), e;
|
|
53
|
+
}
|
|
54
|
+
function _extends() {
|
|
55
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
56
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
57
|
+
var t = arguments[e];
|
|
58
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
59
|
+
}
|
|
60
|
+
return n;
|
|
61
|
+
}, _extends.apply(null, arguments);
|
|
62
|
+
}
|
|
63
|
+
function _inheritsLoose(t, o) {
|
|
64
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
65
|
+
}
|
|
66
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
67
|
+
if (null == r) return {};
|
|
68
|
+
var t = {};
|
|
69
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
70
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
71
|
+
t[n] = r[n];
|
|
72
|
+
}
|
|
73
|
+
return t;
|
|
74
|
+
}
|
|
75
|
+
function _regenerator() {
|
|
76
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
77
|
+
var e,
|
|
78
|
+
t,
|
|
79
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
80
|
+
n = r.iterator || "@@iterator",
|
|
81
|
+
o = r.toStringTag || "@@toStringTag";
|
|
82
|
+
function i(r, n, o, i) {
|
|
83
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
84
|
+
u = Object.create(c.prototype);
|
|
85
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
86
|
+
var i,
|
|
87
|
+
c,
|
|
88
|
+
u,
|
|
89
|
+
f = 0,
|
|
90
|
+
p = o || [],
|
|
91
|
+
y = !1,
|
|
92
|
+
G = {
|
|
93
|
+
p: 0,
|
|
94
|
+
n: 0,
|
|
95
|
+
v: e,
|
|
96
|
+
a: d,
|
|
97
|
+
f: d.bind(e, 4),
|
|
98
|
+
d: function (t, r) {
|
|
99
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
function d(r, n) {
|
|
103
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
104
|
+
var o,
|
|
105
|
+
i = p[t],
|
|
106
|
+
d = G.p,
|
|
107
|
+
l = i[2];
|
|
108
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
109
|
+
}
|
|
110
|
+
if (o || r > 1) return a;
|
|
111
|
+
throw y = !0, n;
|
|
112
|
+
}
|
|
113
|
+
return function (o, p, l) {
|
|
114
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
115
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
116
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
117
|
+
try {
|
|
118
|
+
if (f = 2, i) {
|
|
119
|
+
if (c || (o = "next"), t = i[o]) {
|
|
120
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
121
|
+
if (!t.done) return t;
|
|
122
|
+
u = t.value, c < 2 && (c = 0);
|
|
123
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
124
|
+
i = e;
|
|
125
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
126
|
+
} catch (t) {
|
|
127
|
+
i = e, c = 1, u = t;
|
|
128
|
+
} finally {
|
|
129
|
+
f = 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
value: t,
|
|
134
|
+
done: y
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
}(r, o, i), !0), u;
|
|
138
|
+
}
|
|
139
|
+
var a = {};
|
|
140
|
+
function Generator() {}
|
|
141
|
+
function GeneratorFunction() {}
|
|
142
|
+
function GeneratorFunctionPrototype() {}
|
|
143
|
+
t = Object.getPrototypeOf;
|
|
144
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
145
|
+
return this;
|
|
146
|
+
}), t),
|
|
147
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
148
|
+
function f(e) {
|
|
149
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
150
|
+
}
|
|
151
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
152
|
+
return this;
|
|
153
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
154
|
+
return "[object Generator]";
|
|
155
|
+
}), (_regenerator = function () {
|
|
156
|
+
return {
|
|
157
|
+
w: i,
|
|
158
|
+
m: f
|
|
159
|
+
};
|
|
160
|
+
})();
|
|
161
|
+
}
|
|
162
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
163
|
+
var i = Object.defineProperty;
|
|
164
|
+
try {
|
|
165
|
+
i({}, "", {});
|
|
166
|
+
} catch (e) {
|
|
167
|
+
i = 0;
|
|
168
|
+
}
|
|
169
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
170
|
+
function o(r, n) {
|
|
171
|
+
_regeneratorDefine(e, r, function (e) {
|
|
172
|
+
return this._invoke(r, n, e);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
r ? i ? i(e, r, {
|
|
176
|
+
value: n,
|
|
177
|
+
enumerable: !t,
|
|
178
|
+
configurable: !t,
|
|
179
|
+
writable: !t
|
|
180
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
181
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
182
|
+
}
|
|
183
|
+
function _setPrototypeOf(t, e) {
|
|
184
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
185
|
+
return t.__proto__ = e, t;
|
|
186
|
+
}, _setPrototypeOf(t, e);
|
|
187
|
+
}
|
|
188
|
+
function _toPrimitive(t, r) {
|
|
189
|
+
if ("object" != typeof t || !t) return t;
|
|
190
|
+
var e = t[Symbol.toPrimitive];
|
|
191
|
+
if (void 0 !== e) {
|
|
192
|
+
var i = e.call(t, r || "default");
|
|
193
|
+
if ("object" != typeof i) return i;
|
|
194
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
195
|
+
}
|
|
196
|
+
return ("string" === r ? String : Number)(t);
|
|
197
|
+
}
|
|
198
|
+
function _toPropertyKey(t) {
|
|
199
|
+
var i = _toPrimitive(t, "string");
|
|
200
|
+
return "symbol" == typeof i ? i : i + "";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var DexAPI = /*#__PURE__*/function () {
|
|
204
|
+
function DexAPI(config) {
|
|
205
|
+
this.config = config;
|
|
206
|
+
this.defaultNetworkConfigs = {
|
|
207
|
+
"1": {
|
|
208
|
+
id: "1",
|
|
209
|
+
explorer: "https://etherscan.io/",
|
|
210
|
+
defaultSlippage: "0.005",
|
|
211
|
+
maxSlippage: "1",
|
|
212
|
+
confirmationTimeout: 60000,
|
|
213
|
+
maxRetries: 3
|
|
214
|
+
},
|
|
215
|
+
"11155111": {
|
|
216
|
+
id: "11155111",
|
|
217
|
+
explorer: "https://sepolia.etherscan.io/",
|
|
218
|
+
defaultSlippage: "0.005",
|
|
219
|
+
maxSlippage: "1",
|
|
220
|
+
confirmationTimeout: 60000,
|
|
221
|
+
maxRetries: 3
|
|
222
|
+
},
|
|
223
|
+
"56": {
|
|
224
|
+
id: "56",
|
|
225
|
+
explorer: "https://bscscan.com/",
|
|
226
|
+
defaultSlippage: "0.005",
|
|
227
|
+
maxSlippage: "1",
|
|
228
|
+
confirmationTimeout: 60000,
|
|
229
|
+
maxRetries: 3
|
|
230
|
+
},
|
|
231
|
+
"97": {
|
|
232
|
+
id: "97",
|
|
233
|
+
explorer: "https://testnet.bscscan.com/",
|
|
234
|
+
defaultSlippage: "0.005",
|
|
235
|
+
maxSlippage: "1",
|
|
236
|
+
confirmationTimeout: 60000,
|
|
237
|
+
maxRetries: 3
|
|
238
|
+
},
|
|
239
|
+
"501": {
|
|
240
|
+
id: "501",
|
|
241
|
+
explorer: "https://web3.okx.com/explorer/sol/tx",
|
|
242
|
+
defaultSlippage: "0.005",
|
|
243
|
+
maxSlippage: "1",
|
|
244
|
+
computeUnits: 300000,
|
|
245
|
+
confirmationTimeout: 60000,
|
|
246
|
+
maxRetries: 3
|
|
247
|
+
},
|
|
248
|
+
"784": {
|
|
249
|
+
id: "784",
|
|
250
|
+
explorer: "https://web3.okx.com/explorer/sui/tx",
|
|
251
|
+
defaultSlippage: "0.005",
|
|
252
|
+
maxSlippage: "1",
|
|
253
|
+
confirmationTimeout: 60000,
|
|
254
|
+
maxRetries: 3
|
|
255
|
+
},
|
|
256
|
+
"43114": {
|
|
257
|
+
id: "43114",
|
|
258
|
+
explorer: "https://web3.okx.com/explorer/avax/tx",
|
|
259
|
+
defaultSlippage: "0.005",
|
|
260
|
+
maxSlippage: "1",
|
|
261
|
+
confirmationTimeout: 60000,
|
|
262
|
+
maxRetries: 3
|
|
263
|
+
},
|
|
264
|
+
"137": {
|
|
265
|
+
id: "137",
|
|
266
|
+
explorer: "https://web3.okx.com/explorer/polygon/tx",
|
|
267
|
+
defaultSlippage: "0.005",
|
|
268
|
+
maxSlippage: "1",
|
|
269
|
+
confirmationTimeout: 60000,
|
|
270
|
+
maxRetries: 3
|
|
271
|
+
},
|
|
272
|
+
"80002": {
|
|
273
|
+
id: "80002",
|
|
274
|
+
explorer: "https://amoy.polygonscan.com",
|
|
275
|
+
defaultSlippage: "0.005",
|
|
276
|
+
maxSlippage: "1",
|
|
277
|
+
confirmationTimeout: 60000,
|
|
278
|
+
maxRetries: 3
|
|
279
|
+
},
|
|
280
|
+
"146": {
|
|
281
|
+
id: "146",
|
|
282
|
+
explorer: "https://web3.okx.com/explorer/sonic/tx",
|
|
283
|
+
defaultSlippage: "0.005",
|
|
284
|
+
maxSlippage: "1",
|
|
285
|
+
confirmationTimeout: 60000,
|
|
286
|
+
maxRetries: 3
|
|
287
|
+
},
|
|
288
|
+
"8453": {
|
|
289
|
+
id: "8453",
|
|
290
|
+
explorer: "https://web3.okx.com/explorer/base/tx",
|
|
291
|
+
defaultSlippage: "0.005",
|
|
292
|
+
maxSlippage: "1",
|
|
293
|
+
confirmationTimeout: 60000,
|
|
294
|
+
maxRetries: 3
|
|
295
|
+
},
|
|
296
|
+
"196": {
|
|
297
|
+
id: "196",
|
|
298
|
+
explorer: "https://web3.okx.com/explorer/x-layer/tx",
|
|
299
|
+
defaultSlippage: "0.005",
|
|
300
|
+
maxSlippage: "1",
|
|
301
|
+
confirmationTimeout: 60000,
|
|
302
|
+
maxRetries: 3
|
|
303
|
+
},
|
|
304
|
+
"10": {
|
|
305
|
+
id: "10",
|
|
306
|
+
explorer: "https://web3.okx.com/explorer/optimism/tx",
|
|
307
|
+
defaultSlippage: "0.005",
|
|
308
|
+
maxSlippage: "1",
|
|
309
|
+
confirmationTimeout: 60000,
|
|
310
|
+
maxRetries: 3
|
|
311
|
+
},
|
|
312
|
+
"42161": {
|
|
313
|
+
id: "42161",
|
|
314
|
+
explorer: "https://web3.okx.com/explorer/arbitrum/tx",
|
|
315
|
+
defaultSlippage: "0.005",
|
|
316
|
+
maxSlippage: "1",
|
|
317
|
+
confirmationTimeout: 60000,
|
|
318
|
+
maxRetries: 3
|
|
319
|
+
},
|
|
320
|
+
"100": {
|
|
321
|
+
id: "100",
|
|
322
|
+
explorer: "https://web3.okx.com/explorer/gnosis/tx",
|
|
323
|
+
defaultSlippage: "0.005",
|
|
324
|
+
maxSlippage: "1",
|
|
325
|
+
confirmationTimeout: 60000,
|
|
326
|
+
maxRetries: 3
|
|
327
|
+
},
|
|
328
|
+
"169": {
|
|
329
|
+
id: "169",
|
|
330
|
+
explorer: "https://web3.okx.com/explorer/manta/tx",
|
|
331
|
+
defaultSlippage: "0.005",
|
|
332
|
+
maxSlippage: "1",
|
|
333
|
+
confirmationTimeout: 60000,
|
|
334
|
+
maxRetries: 3
|
|
335
|
+
},
|
|
336
|
+
"250": {
|
|
337
|
+
id: "250",
|
|
338
|
+
explorer: "https://web3.okx.com/explorer/ftm/tx",
|
|
339
|
+
defaultSlippage: "0.005",
|
|
340
|
+
maxSlippage: "1",
|
|
341
|
+
confirmationTimeout: 60000,
|
|
342
|
+
maxRetries: 3
|
|
343
|
+
},
|
|
344
|
+
"324": {
|
|
345
|
+
id: "324",
|
|
346
|
+
explorer: "https://web3.okx.com/explorer/zksync/tx",
|
|
347
|
+
defaultSlippage: "0.005",
|
|
348
|
+
maxSlippage: "1",
|
|
349
|
+
confirmationTimeout: 60000,
|
|
350
|
+
maxRetries: 3
|
|
351
|
+
},
|
|
352
|
+
"1101": {
|
|
353
|
+
id: "1101",
|
|
354
|
+
explorer: "https://web3.okx.com/explorer/polygon-zkevm/tx",
|
|
355
|
+
defaultSlippage: "0.005",
|
|
356
|
+
maxSlippage: "1",
|
|
357
|
+
confirmationTimeout: 60000,
|
|
358
|
+
maxRetries: 3
|
|
359
|
+
},
|
|
360
|
+
"5000": {
|
|
361
|
+
id: "5000",
|
|
362
|
+
explorer: "https://web3.okx.com/explorer/mantle/tx",
|
|
363
|
+
defaultSlippage: "0.005",
|
|
364
|
+
maxSlippage: "1",
|
|
365
|
+
confirmationTimeout: 60000,
|
|
366
|
+
maxRetries: 3
|
|
367
|
+
},
|
|
368
|
+
"25": {
|
|
369
|
+
id: "25",
|
|
370
|
+
explorer: "https://cronoscan.com/tx",
|
|
371
|
+
defaultSlippage: "0.005",
|
|
372
|
+
maxSlippage: "1",
|
|
373
|
+
confirmationTimeout: 60000,
|
|
374
|
+
maxRetries: 3
|
|
375
|
+
},
|
|
376
|
+
"534352": {
|
|
377
|
+
id: "534352",
|
|
378
|
+
explorer: "https://web3.okx.com/explorer/scroll/tx",
|
|
379
|
+
defaultSlippage: "0.005",
|
|
380
|
+
maxSlippage: "1",
|
|
381
|
+
confirmationTimeout: 60000,
|
|
382
|
+
maxRetries: 3
|
|
383
|
+
},
|
|
384
|
+
"59144": {
|
|
385
|
+
id: "59144",
|
|
386
|
+
explorer: "https://web3.okx.com/explorer/linea/tx",
|
|
387
|
+
defaultSlippage: "0.005",
|
|
388
|
+
maxSlippage: "1",
|
|
389
|
+
confirmationTimeout: 60000,
|
|
390
|
+
maxRetries: 3
|
|
391
|
+
},
|
|
392
|
+
"1088": {
|
|
393
|
+
id: "1088",
|
|
394
|
+
explorer: "https://web3.okx.com/explorer/metis/tx",
|
|
395
|
+
defaultSlippage: "0.005",
|
|
396
|
+
maxSlippage: "1",
|
|
397
|
+
confirmationTimeout: 60000,
|
|
398
|
+
maxRetries: 3
|
|
399
|
+
},
|
|
400
|
+
"1030": {
|
|
401
|
+
id: "1030",
|
|
402
|
+
explorer: "https://www.confluxscan.io/tx",
|
|
403
|
+
defaultSlippage: "0.005",
|
|
404
|
+
maxSlippage: "1",
|
|
405
|
+
confirmationTimeout: 60000,
|
|
406
|
+
maxRetries: 3
|
|
407
|
+
},
|
|
408
|
+
"81457": {
|
|
409
|
+
id: "81457",
|
|
410
|
+
explorer: "https://web3.okx.com/explorer/blast/tx",
|
|
411
|
+
defaultSlippage: "0.005",
|
|
412
|
+
maxSlippage: "1",
|
|
413
|
+
confirmationTimeout: 60000,
|
|
414
|
+
maxRetries: 3
|
|
415
|
+
},
|
|
416
|
+
"7000": {
|
|
417
|
+
id: "7000",
|
|
418
|
+
explorer: "https://explorer.zetachain.com/tx",
|
|
419
|
+
defaultSlippage: "0.005",
|
|
420
|
+
maxSlippage: "1",
|
|
421
|
+
confirmationTimeout: 60000,
|
|
422
|
+
maxRetries: 3
|
|
423
|
+
},
|
|
424
|
+
"66": {
|
|
425
|
+
id: "66",
|
|
426
|
+
explorer: "https://www.okx.com/web3/explorer/oktc/tx",
|
|
427
|
+
defaultSlippage: "0.005",
|
|
428
|
+
maxSlippage: "1",
|
|
429
|
+
confirmationTimeout: 60000,
|
|
430
|
+
maxRetries: 3
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
this.config.networks = _extends({}, this.defaultNetworkConfigs, config.networks || {});
|
|
434
|
+
}
|
|
435
|
+
var _proto = DexAPI.prototype;
|
|
436
|
+
_proto.getNetworkConfig = function getNetworkConfig(chainId) {
|
|
437
|
+
var _this$config$networks;
|
|
438
|
+
var networkConfig = (_this$config$networks = this.config.networks) == null ? void 0 : _this$config$networks[chainId];
|
|
439
|
+
if (!networkConfig) {
|
|
440
|
+
throw new Error("Network configuration not found for chain " + chainId);
|
|
441
|
+
}
|
|
442
|
+
return networkConfig;
|
|
443
|
+
};
|
|
444
|
+
return DexAPI;
|
|
445
|
+
}();
|
|
446
|
+
|
|
447
|
+
var BaseWallet = /*#__PURE__*/function () {
|
|
448
|
+
function BaseWallet(config) {
|
|
449
|
+
this.config = _extends({
|
|
450
|
+
timeout: 30000
|
|
451
|
+
}, config);
|
|
452
|
+
this.dex = new DexAPI(this.config);
|
|
453
|
+
}
|
|
454
|
+
var _proto = BaseWallet.prototype;
|
|
455
|
+
_proto.generateMnemonic = /*#__PURE__*/function () {
|
|
456
|
+
var _generateMnemonic = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(numWords) {
|
|
457
|
+
var strength;
|
|
458
|
+
return _regenerator().w(function (_context) {
|
|
459
|
+
while (1) switch (_context.n) {
|
|
460
|
+
case 0:
|
|
461
|
+
if (numWords === void 0) {
|
|
462
|
+
numWords = 12;
|
|
463
|
+
}
|
|
464
|
+
strength = numWords / 3 * 32;
|
|
465
|
+
return _context.a(2, cryptoLib.bip39.generateMnemonic(strength));
|
|
466
|
+
}
|
|
467
|
+
}, _callee);
|
|
468
|
+
}));
|
|
469
|
+
function generateMnemonic(_x) {
|
|
470
|
+
return _generateMnemonic.apply(this, arguments);
|
|
471
|
+
}
|
|
472
|
+
return generateMnemonic;
|
|
473
|
+
}();
|
|
474
|
+
return _createClass(BaseWallet, [{
|
|
475
|
+
key: "currentChain",
|
|
476
|
+
get: function get() {
|
|
477
|
+
if (!this.config.chainId) throw new Error("chainId not set in config");
|
|
478
|
+
return this.dex.getNetworkConfig(this.config.chainId);
|
|
479
|
+
}
|
|
480
|
+
}]);
|
|
481
|
+
}();
|
|
482
|
+
|
|
483
|
+
var successResponse = function successResponse(args) {
|
|
484
|
+
return args;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// src/utils/amount.ts
|
|
488
|
+
/**
|
|
489
|
+
* Convert human-readable amount → raw integer by decimals
|
|
490
|
+
* ex: 0.1 USDC (decimals 6) => 100000
|
|
491
|
+
*/
|
|
492
|
+
var parseAmount = function parseAmount(amount, decimals) {
|
|
493
|
+
var bn = new BigNumber(amount);
|
|
494
|
+
var multiplier = new BigNumber(10).pow(decimals);
|
|
495
|
+
return BigInt(bn.times(multiplier).toFixed(0));
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Convert raw amount → human-readable number by decimals
|
|
499
|
+
* ex: 100000 (decimals 6) => 0.1
|
|
500
|
+
*/
|
|
501
|
+
var formatAmount = function formatAmount(raw, decimals) {
|
|
502
|
+
var bn = new BigNumber(raw.toString());
|
|
503
|
+
var divisor = new BigNumber(10).pow(decimals);
|
|
504
|
+
return bn.dividedBy(divisor).toNumber();
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// src/utils/evmUnits.ts
|
|
508
|
+
// Ether = 18 decimals
|
|
509
|
+
var parseEther = function parseEther(v) {
|
|
510
|
+
return parseAmount(v, 18);
|
|
511
|
+
};
|
|
512
|
+
var formatEther = function formatEther(v) {
|
|
513
|
+
return formatAmount(v, 18);
|
|
514
|
+
};
|
|
515
|
+
// Gwei = 9 decimals
|
|
516
|
+
var parseGwei = function parseGwei(v) {
|
|
517
|
+
return parseAmount(v, 9);
|
|
518
|
+
};
|
|
519
|
+
var formatGwei = function formatGwei(v) {
|
|
520
|
+
return formatAmount(v, 9);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
var erc20Abi = [
|
|
524
|
+
{
|
|
525
|
+
constant: true,
|
|
526
|
+
inputs: [
|
|
527
|
+
],
|
|
528
|
+
name: "name",
|
|
529
|
+
outputs: [
|
|
530
|
+
{
|
|
531
|
+
name: "",
|
|
532
|
+
type: "string"
|
|
533
|
+
}
|
|
534
|
+
],
|
|
535
|
+
payable: false,
|
|
536
|
+
stateMutability: "view",
|
|
537
|
+
type: "function"
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
constant: false,
|
|
541
|
+
inputs: [
|
|
542
|
+
{
|
|
543
|
+
name: "_spender",
|
|
544
|
+
type: "address"
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: "_value",
|
|
548
|
+
type: "uint256"
|
|
549
|
+
}
|
|
550
|
+
],
|
|
551
|
+
name: "approve",
|
|
552
|
+
outputs: [
|
|
553
|
+
{
|
|
554
|
+
name: "",
|
|
555
|
+
type: "bool"
|
|
556
|
+
}
|
|
557
|
+
],
|
|
558
|
+
payable: false,
|
|
559
|
+
stateMutability: "nonpayable",
|
|
560
|
+
type: "function"
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
constant: true,
|
|
564
|
+
inputs: [
|
|
565
|
+
],
|
|
566
|
+
name: "totalSupply",
|
|
567
|
+
outputs: [
|
|
568
|
+
{
|
|
569
|
+
name: "",
|
|
570
|
+
type: "uint256"
|
|
571
|
+
}
|
|
572
|
+
],
|
|
573
|
+
payable: false,
|
|
574
|
+
stateMutability: "view",
|
|
575
|
+
type: "function"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
constant: false,
|
|
579
|
+
inputs: [
|
|
580
|
+
{
|
|
581
|
+
name: "_from",
|
|
582
|
+
type: "address"
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
name: "_to",
|
|
586
|
+
type: "address"
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
name: "_value",
|
|
590
|
+
type: "uint256"
|
|
591
|
+
}
|
|
592
|
+
],
|
|
593
|
+
name: "transferFrom",
|
|
594
|
+
outputs: [
|
|
595
|
+
{
|
|
596
|
+
name: "",
|
|
597
|
+
type: "bool"
|
|
598
|
+
}
|
|
599
|
+
],
|
|
600
|
+
payable: false,
|
|
601
|
+
stateMutability: "nonpayable",
|
|
602
|
+
type: "function"
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
constant: true,
|
|
606
|
+
inputs: [
|
|
607
|
+
],
|
|
608
|
+
name: "decimals",
|
|
609
|
+
outputs: [
|
|
610
|
+
{
|
|
611
|
+
name: "",
|
|
612
|
+
type: "uint8"
|
|
613
|
+
}
|
|
614
|
+
],
|
|
615
|
+
payable: false,
|
|
616
|
+
stateMutability: "view",
|
|
617
|
+
type: "function"
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
constant: true,
|
|
621
|
+
inputs: [
|
|
622
|
+
{
|
|
623
|
+
name: "_owner",
|
|
624
|
+
type: "address"
|
|
625
|
+
}
|
|
626
|
+
],
|
|
627
|
+
name: "balanceOf",
|
|
628
|
+
outputs: [
|
|
629
|
+
{
|
|
630
|
+
name: "balance",
|
|
631
|
+
type: "uint256"
|
|
632
|
+
}
|
|
633
|
+
],
|
|
634
|
+
payable: false,
|
|
635
|
+
stateMutability: "view",
|
|
636
|
+
type: "function"
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
constant: true,
|
|
640
|
+
inputs: [
|
|
641
|
+
],
|
|
642
|
+
name: "symbol",
|
|
643
|
+
outputs: [
|
|
644
|
+
{
|
|
645
|
+
name: "",
|
|
646
|
+
type: "string"
|
|
647
|
+
}
|
|
648
|
+
],
|
|
649
|
+
payable: false,
|
|
650
|
+
stateMutability: "view",
|
|
651
|
+
type: "function"
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
constant: false,
|
|
655
|
+
inputs: [
|
|
656
|
+
{
|
|
657
|
+
name: "_to",
|
|
658
|
+
type: "address"
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: "_value",
|
|
662
|
+
type: "uint256"
|
|
663
|
+
}
|
|
664
|
+
],
|
|
665
|
+
name: "transfer",
|
|
666
|
+
outputs: [
|
|
667
|
+
{
|
|
668
|
+
name: "",
|
|
669
|
+
type: "bool"
|
|
670
|
+
}
|
|
671
|
+
],
|
|
672
|
+
payable: false,
|
|
673
|
+
stateMutability: "nonpayable",
|
|
674
|
+
type: "function"
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
constant: true,
|
|
678
|
+
inputs: [
|
|
679
|
+
{
|
|
680
|
+
name: "_owner",
|
|
681
|
+
type: "address"
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
name: "_spender",
|
|
685
|
+
type: "address"
|
|
686
|
+
}
|
|
687
|
+
],
|
|
688
|
+
name: "allowance",
|
|
689
|
+
outputs: [
|
|
690
|
+
{
|
|
691
|
+
name: "",
|
|
692
|
+
type: "uint256"
|
|
693
|
+
}
|
|
694
|
+
],
|
|
695
|
+
payable: false,
|
|
696
|
+
stateMutability: "view",
|
|
697
|
+
type: "function"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
payable: true,
|
|
701
|
+
stateMutability: "payable",
|
|
702
|
+
type: "fallback"
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
anonymous: false,
|
|
706
|
+
inputs: [
|
|
707
|
+
{
|
|
708
|
+
indexed: true,
|
|
709
|
+
name: "owner",
|
|
710
|
+
type: "address"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
indexed: true,
|
|
714
|
+
name: "spender",
|
|
715
|
+
type: "address"
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
indexed: false,
|
|
719
|
+
name: "value",
|
|
720
|
+
type: "uint256"
|
|
721
|
+
}
|
|
722
|
+
],
|
|
723
|
+
name: "Approval",
|
|
724
|
+
type: "event"
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
anonymous: false,
|
|
728
|
+
inputs: [
|
|
729
|
+
{
|
|
730
|
+
indexed: true,
|
|
731
|
+
name: "from",
|
|
732
|
+
type: "address"
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
indexed: true,
|
|
736
|
+
name: "to",
|
|
737
|
+
type: "address"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
indexed: false,
|
|
741
|
+
name: "value",
|
|
742
|
+
type: "uint256"
|
|
743
|
+
}
|
|
744
|
+
],
|
|
745
|
+
name: "Transfer",
|
|
746
|
+
type: "event"
|
|
747
|
+
}
|
|
748
|
+
];
|
|
749
|
+
|
|
750
|
+
var _excluded = ["privateKey", "contractAddress", "rpcUrl"];
|
|
751
|
+
var provider = function provider(rpcUrl) {
|
|
752
|
+
return new ethers.ethers.JsonRpcProvider(rpcUrl);
|
|
753
|
+
};
|
|
754
|
+
var DEFAULT_PRIORITY = "0.1";
|
|
755
|
+
var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
|
|
756
|
+
function EvmWallet(config) {
|
|
757
|
+
var _this;
|
|
758
|
+
_this = _BaseWallet.call(this, config) || this;
|
|
759
|
+
_this.wallet = new coinEthereum.EthWallet();
|
|
760
|
+
return _this;
|
|
761
|
+
}
|
|
762
|
+
_inheritsLoose(EvmWallet, _BaseWallet);
|
|
763
|
+
var _proto = EvmWallet.prototype;
|
|
764
|
+
_proto.getContract = /*#__PURE__*/function () {
|
|
765
|
+
var _getContract = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
766
|
+
var contractAddress, rpcUrl, privateKey, abi, providerInstance, gasFeeData, nonce, contract, signer, code, _t;
|
|
767
|
+
return _regenerator().w(function (_context) {
|
|
768
|
+
while (1) switch (_context.n) {
|
|
769
|
+
case 0:
|
|
770
|
+
contractAddress = _ref.contractAddress, rpcUrl = _ref.rpcUrl, privateKey = _ref.privateKey, abi = _ref.abi;
|
|
771
|
+
if (rpcUrl) {
|
|
772
|
+
_context.n = 1;
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
throw new Error("RPC URL is required");
|
|
776
|
+
case 1:
|
|
777
|
+
providerInstance = provider(rpcUrl != null ? rpcUrl : this.config.rpcUrl);
|
|
778
|
+
_context.n = 2;
|
|
779
|
+
return providerInstance.getFeeData();
|
|
780
|
+
case 2:
|
|
781
|
+
gasFeeData = _context.v;
|
|
782
|
+
if (!privateKey) {
|
|
783
|
+
_context.n = 5;
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
signer = new ethers.ethers.Wallet(privateKey, providerInstance);
|
|
787
|
+
_t = providerInstance;
|
|
788
|
+
_context.n = 3;
|
|
789
|
+
return signer.getAddress();
|
|
790
|
+
case 3:
|
|
791
|
+
_context.n = 4;
|
|
792
|
+
return _t.getTransactionCount.call(_t, _context.v, "pending");
|
|
793
|
+
case 4:
|
|
794
|
+
nonce = _context.v;
|
|
795
|
+
case 5:
|
|
796
|
+
if (!contractAddress) {
|
|
797
|
+
_context.n = 7;
|
|
798
|
+
break;
|
|
799
|
+
}
|
|
800
|
+
contract = new ethers.ethers.Contract(contractAddress, abi || erc20Abi, signer || providerInstance);
|
|
801
|
+
_context.n = 6;
|
|
802
|
+
return providerInstance.getCode(contractAddress);
|
|
803
|
+
case 6:
|
|
804
|
+
code = _context.v;
|
|
805
|
+
if (!(code === "0x")) {
|
|
806
|
+
_context.n = 7;
|
|
807
|
+
break;
|
|
808
|
+
}
|
|
809
|
+
throw new Error("Address is not a contract");
|
|
810
|
+
case 7:
|
|
811
|
+
return _context.a(2, {
|
|
812
|
+
contract: contract,
|
|
813
|
+
signer: signer,
|
|
814
|
+
gasFeeData: gasFeeData,
|
|
815
|
+
nonce: nonce,
|
|
816
|
+
providerInstance: providerInstance
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
}, _callee, this);
|
|
820
|
+
}));
|
|
821
|
+
function getContract(_x) {
|
|
822
|
+
return _getContract.apply(this, arguments);
|
|
823
|
+
}
|
|
824
|
+
return getContract;
|
|
825
|
+
}();
|
|
826
|
+
_proto.generateWallet = /*#__PURE__*/function () {
|
|
827
|
+
var _generateWallet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
|
|
828
|
+
var mnemonic, derivationPath, hdPath, getMnemonic, derivePrivateKey, _yield$this$wallet$ge, address, publicKey, _t2;
|
|
829
|
+
return _regenerator().w(function (_context2) {
|
|
830
|
+
while (1) switch (_context2.n) {
|
|
831
|
+
case 0:
|
|
832
|
+
mnemonic = _ref2.mnemonic, derivationPath = _ref2.derivationPath;
|
|
833
|
+
hdPath = derivationPath || "m/44'/60'/0'/0/0";
|
|
834
|
+
if (!(mnemonic != null)) {
|
|
835
|
+
_context2.n = 1;
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
_t2 = mnemonic;
|
|
839
|
+
_context2.n = 3;
|
|
840
|
+
break;
|
|
841
|
+
case 1:
|
|
842
|
+
_context2.n = 2;
|
|
843
|
+
return this.generateMnemonic(12);
|
|
844
|
+
case 2:
|
|
845
|
+
_t2 = _context2.v;
|
|
846
|
+
case 3:
|
|
847
|
+
getMnemonic = _t2;
|
|
848
|
+
_context2.n = 4;
|
|
849
|
+
return this.wallet.getDerivedPrivateKey({
|
|
850
|
+
mnemonic: getMnemonic,
|
|
851
|
+
hdPath: hdPath
|
|
852
|
+
});
|
|
853
|
+
case 4:
|
|
854
|
+
derivePrivateKey = _context2.v;
|
|
855
|
+
_context2.n = 5;
|
|
856
|
+
return this.wallet.getNewAddress({
|
|
857
|
+
privateKey: derivePrivateKey
|
|
858
|
+
});
|
|
859
|
+
case 5:
|
|
860
|
+
_yield$this$wallet$ge = _context2.v;
|
|
861
|
+
address = _yield$this$wallet$ge.address;
|
|
862
|
+
publicKey = _yield$this$wallet$ge.publicKey;
|
|
863
|
+
return _context2.a(2, successResponse({
|
|
864
|
+
address: address,
|
|
865
|
+
publicKey: publicKey,
|
|
866
|
+
privateKey: derivePrivateKey
|
|
867
|
+
}));
|
|
868
|
+
}
|
|
869
|
+
}, _callee2, this);
|
|
870
|
+
}));
|
|
871
|
+
function generateWallet(_x2) {
|
|
872
|
+
return _generateWallet.apply(this, arguments);
|
|
873
|
+
}
|
|
874
|
+
return generateWallet;
|
|
875
|
+
}();
|
|
876
|
+
_proto.getBalance = /*#__PURE__*/function () {
|
|
877
|
+
var _getBalance = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref3) {
|
|
878
|
+
var rpcUrl, contractAddress, address, _yield$this$getContra, contract, providerInstance, decimals, _balance, balance;
|
|
879
|
+
return _regenerator().w(function (_context3) {
|
|
880
|
+
while (1) switch (_context3.n) {
|
|
881
|
+
case 0:
|
|
882
|
+
rpcUrl = _ref3.rpcUrl, contractAddress = _ref3.contractAddress, address = _ref3.address;
|
|
883
|
+
_context3.n = 1;
|
|
884
|
+
return this.getContract({
|
|
885
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl,
|
|
886
|
+
contractAddress: contractAddress
|
|
887
|
+
});
|
|
888
|
+
case 1:
|
|
889
|
+
_yield$this$getContra = _context3.v;
|
|
890
|
+
contract = _yield$this$getContra.contract;
|
|
891
|
+
providerInstance = _yield$this$getContra.providerInstance;
|
|
892
|
+
if (!contract) {
|
|
893
|
+
_context3.n = 4;
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
_context3.n = 2;
|
|
897
|
+
return contract.decimals();
|
|
898
|
+
case 2:
|
|
899
|
+
decimals = _context3.v;
|
|
900
|
+
_context3.n = 3;
|
|
901
|
+
return contract.balanceOf(address);
|
|
902
|
+
case 3:
|
|
903
|
+
_balance = _context3.v;
|
|
904
|
+
return _context3.a(2, successResponse({
|
|
905
|
+
balance: formatAmount(_balance.toString(), decimals),
|
|
906
|
+
_rawBalance: _balance.toString(),
|
|
907
|
+
_decimal: decimals
|
|
908
|
+
}));
|
|
909
|
+
case 4:
|
|
910
|
+
_context3.n = 5;
|
|
911
|
+
return providerInstance.getBalance(address);
|
|
912
|
+
case 5:
|
|
913
|
+
balance = _context3.v;
|
|
914
|
+
return _context3.a(2, successResponse({
|
|
915
|
+
balance: formatAmount(balance.toString(), 18),
|
|
916
|
+
_rawBalance: balance.toString(),
|
|
917
|
+
_decimal: 18
|
|
918
|
+
}));
|
|
919
|
+
}
|
|
920
|
+
}, _callee3, this);
|
|
921
|
+
}));
|
|
922
|
+
function getBalance(_x3) {
|
|
923
|
+
return _getBalance.apply(this, arguments);
|
|
924
|
+
}
|
|
925
|
+
return getBalance;
|
|
926
|
+
}();
|
|
927
|
+
_proto.transfer = /*#__PURE__*/function () {
|
|
928
|
+
var _transfer = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
|
|
929
|
+
var privateKey, contractAddress, rpcUrl, args, _yield$this$getContra2, contract, providerInstance, gasFeeData, nonce, recipientAddress, prio, max, value, gasLimit, decimals, noFeeProvided, estimate, fee, signParams, signedTx, broadcast, _t3;
|
|
930
|
+
return _regenerator().w(function (_context4) {
|
|
931
|
+
while (1) switch (_context4.n) {
|
|
932
|
+
case 0:
|
|
933
|
+
privateKey = _ref4.privateKey, contractAddress = _ref4.contractAddress, rpcUrl = _ref4.rpcUrl, args = /*#__PURE__*/_objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
934
|
+
_context4.n = 1;
|
|
935
|
+
return this.getContract({
|
|
936
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl,
|
|
937
|
+
privateKey: privateKey,
|
|
938
|
+
contractAddress: contractAddress
|
|
939
|
+
});
|
|
940
|
+
case 1:
|
|
941
|
+
_yield$this$getContra2 = _context4.v;
|
|
942
|
+
contract = _yield$this$getContra2.contract;
|
|
943
|
+
providerInstance = _yield$this$getContra2.providerInstance;
|
|
944
|
+
gasFeeData = _yield$this$getContra2.gasFeeData;
|
|
945
|
+
nonce = _yield$this$getContra2.nonce;
|
|
946
|
+
_context4.n = 2;
|
|
947
|
+
return this.wallet.validAddress({
|
|
948
|
+
address: args.recipientAddress
|
|
949
|
+
});
|
|
950
|
+
case 2:
|
|
951
|
+
recipientAddress = _context4.v;
|
|
952
|
+
if (recipientAddress.isValid) {
|
|
953
|
+
_context4.n = 3;
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
throw new Error("address not valid");
|
|
957
|
+
case 3:
|
|
958
|
+
if (!(args.maxPriorityFeePerGas && args.maxFeePerGas)) {
|
|
959
|
+
_context4.n = 4;
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
prio = BigInt(args.maxPriorityFeePerGas);
|
|
963
|
+
max = BigInt(args.maxFeePerGas);
|
|
964
|
+
if (!(max < prio)) {
|
|
965
|
+
_context4.n = 4;
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
throw new Error("maxFeePerGas must be >= maxPriorityFeePerGas");
|
|
969
|
+
case 4:
|
|
970
|
+
if (!(args.gasPrice && (args.maxFeePerGas || args.maxPriorityFeePerGas))) {
|
|
971
|
+
_context4.n = 5;
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
throw new Error("Cannot use gasPrice with EIP-1559 fee fields");
|
|
975
|
+
case 5:
|
|
976
|
+
if (!contractAddress) {
|
|
977
|
+
_context4.n = 11;
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
if (contract) {
|
|
981
|
+
_context4.n = 6;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
throw new Error("contract not valid");
|
|
985
|
+
case 6:
|
|
986
|
+
_context4.n = 7;
|
|
987
|
+
return contract.decimals();
|
|
988
|
+
case 7:
|
|
989
|
+
decimals = _context4.v;
|
|
990
|
+
value = parseAmount(args.amount.toString(), decimals);
|
|
991
|
+
if (!args.gasLimit) {
|
|
992
|
+
_context4.n = 8;
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
_t3 = BigInt(args.gasLimit);
|
|
996
|
+
_context4.n = 10;
|
|
997
|
+
break;
|
|
998
|
+
case 8:
|
|
999
|
+
_context4.n = 9;
|
|
1000
|
+
return contract.transfer.estimateGas(args.recipientAddress, value);
|
|
1001
|
+
case 9:
|
|
1002
|
+
_t3 = _context4.v;
|
|
1003
|
+
case 10:
|
|
1004
|
+
gasLimit = _t3;
|
|
1005
|
+
_context4.n = 12;
|
|
1006
|
+
break;
|
|
1007
|
+
case 11:
|
|
1008
|
+
value = parseEther(args.amount.toString());
|
|
1009
|
+
gasLimit = args.gasLimit ? BigInt(args.gasLimit) : 21000n;
|
|
1010
|
+
case 12:
|
|
1011
|
+
// DEFAULT FEE
|
|
1012
|
+
noFeeProvided = !args.gasPrice && !args.maxFeePerGas && !args.maxPriorityFeePerGas;
|
|
1013
|
+
if (!noFeeProvided) {
|
|
1014
|
+
_context4.n = 17;
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
_context4.n = 13;
|
|
1018
|
+
return this.estimateGas({
|
|
1019
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl,
|
|
1020
|
+
recipientAddress: args.recipientAddress,
|
|
1021
|
+
amount: args.amount.toString(),
|
|
1022
|
+
data: args.data
|
|
1023
|
+
});
|
|
1024
|
+
case 13:
|
|
1025
|
+
estimate = _context4.v;
|
|
1026
|
+
gasLimit = BigInt(estimate.gasLimit);
|
|
1027
|
+
// ===== LEGACY =====
|
|
1028
|
+
if (!(estimate.model === "LEGACY")) {
|
|
1029
|
+
_context4.n = 15;
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
if (estimate.gasPrice) {
|
|
1033
|
+
_context4.n = 14;
|
|
1034
|
+
break;
|
|
1035
|
+
}
|
|
1036
|
+
throw new Error("LEGACY estimate missing gasPrice");
|
|
1037
|
+
case 14:
|
|
1038
|
+
args.gasPrice = estimate.gasPrice; // wei
|
|
1039
|
+
return _context4.a(2, this.transfer(_extends({
|
|
1040
|
+
privateKey: privateKey,
|
|
1041
|
+
contractAddress: contractAddress,
|
|
1042
|
+
rpcUrl: rpcUrl
|
|
1043
|
+
}, args)));
|
|
1044
|
+
case 15:
|
|
1045
|
+
// ===== EIP-1559 =====
|
|
1046
|
+
fee = estimate.fees.regular;
|
|
1047
|
+
if (!(!(fee != null && fee.maxFeePerGas) || !(fee != null && fee.maxPriorityFeePerGas))) {
|
|
1048
|
+
_context4.n = 16;
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
throw new Error("EIP1559 estimate missing fee fields");
|
|
1052
|
+
case 16:
|
|
1053
|
+
args.maxFeePerGas = fee.maxFeePerGas;
|
|
1054
|
+
args.maxPriorityFeePerGas = fee.maxPriorityFeePerGas;
|
|
1055
|
+
case 17:
|
|
1056
|
+
_context4.n = 18;
|
|
1057
|
+
return this.buildSignParams({
|
|
1058
|
+
args: _extends({}, args, {
|
|
1059
|
+
privateKey: privateKey,
|
|
1060
|
+
gasLimit: gasLimit
|
|
1061
|
+
}),
|
|
1062
|
+
nonce: nonce,
|
|
1063
|
+
gasFeeData: gasFeeData,
|
|
1064
|
+
recipientAddress: recipientAddress,
|
|
1065
|
+
value: value,
|
|
1066
|
+
contractAddress: contractAddress
|
|
1067
|
+
});
|
|
1068
|
+
case 18:
|
|
1069
|
+
signParams = _context4.v;
|
|
1070
|
+
_context4.n = 19;
|
|
1071
|
+
return this.wallet.signTransaction(signParams);
|
|
1072
|
+
case 19:
|
|
1073
|
+
signedTx = _context4.v;
|
|
1074
|
+
_context4.n = 20;
|
|
1075
|
+
return providerInstance.broadcastTransaction(signedTx);
|
|
1076
|
+
case 20:
|
|
1077
|
+
broadcast = _context4.v;
|
|
1078
|
+
return _context4.a(2, successResponse(_extends({}, broadcast)));
|
|
1079
|
+
}
|
|
1080
|
+
}, _callee4, this);
|
|
1081
|
+
}));
|
|
1082
|
+
function transfer(_x4) {
|
|
1083
|
+
return _transfer.apply(this, arguments);
|
|
1084
|
+
}
|
|
1085
|
+
return transfer;
|
|
1086
|
+
}();
|
|
1087
|
+
_proto.getTransaction = /*#__PURE__*/function () {
|
|
1088
|
+
var _getTransaction = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref5) {
|
|
1089
|
+
var hash, rpcUrl, withReceipt, _yield$this$getContra3, providerInstance, _yield$Promise$all, _tx, receipt, memo, tx, _t4;
|
|
1090
|
+
return _regenerator().w(function (_context5) {
|
|
1091
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
1092
|
+
case 0:
|
|
1093
|
+
hash = _ref5.hash, rpcUrl = _ref5.rpcUrl, withReceipt = _ref5.withReceipt;
|
|
1094
|
+
_context5.n = 1;
|
|
1095
|
+
return this.getContract({
|
|
1096
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl
|
|
1097
|
+
});
|
|
1098
|
+
case 1:
|
|
1099
|
+
_yield$this$getContra3 = _context5.v;
|
|
1100
|
+
providerInstance = _yield$this$getContra3.providerInstance;
|
|
1101
|
+
_context5.p = 2;
|
|
1102
|
+
if (!withReceipt) {
|
|
1103
|
+
_context5.n = 4;
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
_context5.n = 3;
|
|
1107
|
+
return Promise.all([providerInstance.getTransaction(hash), providerInstance.getTransactionReceipt(hash)]);
|
|
1108
|
+
case 3:
|
|
1109
|
+
_yield$Promise$all = _context5.v;
|
|
1110
|
+
_tx = _yield$Promise$all[0];
|
|
1111
|
+
receipt = _yield$Promise$all[1];
|
|
1112
|
+
memo = _tx != null && _tx.data && _tx.data !== "0x" ? ethers.ethers.toUtf8String(_tx.data) : null;
|
|
1113
|
+
return _context5.a(2, successResponse({
|
|
1114
|
+
transaction: _tx,
|
|
1115
|
+
receipt: receipt,
|
|
1116
|
+
memo: memo
|
|
1117
|
+
}));
|
|
1118
|
+
case 4:
|
|
1119
|
+
_context5.n = 5;
|
|
1120
|
+
return providerInstance.getTransaction(hash);
|
|
1121
|
+
case 5:
|
|
1122
|
+
tx = _context5.v;
|
|
1123
|
+
return _context5.a(2, successResponse({
|
|
1124
|
+
transaction: tx
|
|
1125
|
+
}));
|
|
1126
|
+
case 6:
|
|
1127
|
+
_context5.p = 6;
|
|
1128
|
+
_t4 = _context5.v;
|
|
1129
|
+
throw _t4;
|
|
1130
|
+
case 7:
|
|
1131
|
+
return _context5.a(2);
|
|
1132
|
+
}
|
|
1133
|
+
}, _callee5, this, [[2, 6]]);
|
|
1134
|
+
}));
|
|
1135
|
+
function getTransaction(_x5) {
|
|
1136
|
+
return _getTransaction.apply(this, arguments);
|
|
1137
|
+
}
|
|
1138
|
+
return getTransaction;
|
|
1139
|
+
}();
|
|
1140
|
+
_proto.getTokenInfo = /*#__PURE__*/function () {
|
|
1141
|
+
var _getTokenInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref6) {
|
|
1142
|
+
var contractAddress, rpcUrl, _yield$this$getContra4, contract, _yield$Promise$all2, name, symbol, decimals, totalSupply, data;
|
|
1143
|
+
return _regenerator().w(function (_context6) {
|
|
1144
|
+
while (1) switch (_context6.n) {
|
|
1145
|
+
case 0:
|
|
1146
|
+
contractAddress = _ref6.contractAddress, rpcUrl = _ref6.rpcUrl;
|
|
1147
|
+
_context6.n = 1;
|
|
1148
|
+
return this.getContract({
|
|
1149
|
+
contractAddress: contractAddress,
|
|
1150
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl
|
|
1151
|
+
});
|
|
1152
|
+
case 1:
|
|
1153
|
+
_yield$this$getContra4 = _context6.v;
|
|
1154
|
+
contract = _yield$this$getContra4.contract;
|
|
1155
|
+
if (!contract) {
|
|
1156
|
+
_context6.n = 3;
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
_context6.n = 2;
|
|
1160
|
+
return Promise.all([contract.name(), contract.symbol(), contract.decimals(), contract.totalSupply()]);
|
|
1161
|
+
case 2:
|
|
1162
|
+
_yield$Promise$all2 = _context6.v;
|
|
1163
|
+
name = _yield$Promise$all2[0];
|
|
1164
|
+
symbol = _yield$Promise$all2[1];
|
|
1165
|
+
decimals = _yield$Promise$all2[2];
|
|
1166
|
+
totalSupply = _yield$Promise$all2[3];
|
|
1167
|
+
data = {
|
|
1168
|
+
name: name,
|
|
1169
|
+
symbol: symbol,
|
|
1170
|
+
decimals: decimals,
|
|
1171
|
+
totalSupply: formatAmount(totalSupply.toString(), decimals).toString()
|
|
1172
|
+
};
|
|
1173
|
+
return _context6.a(2, successResponse(_extends({}, data)));
|
|
1174
|
+
case 3:
|
|
1175
|
+
throw new Error('Contract not found');
|
|
1176
|
+
case 4:
|
|
1177
|
+
return _context6.a(2);
|
|
1178
|
+
}
|
|
1179
|
+
}, _callee6, this);
|
|
1180
|
+
}));
|
|
1181
|
+
function getTokenInfo(_x6) {
|
|
1182
|
+
return _getTokenInfo.apply(this, arguments);
|
|
1183
|
+
}
|
|
1184
|
+
return getTokenInfo;
|
|
1185
|
+
}();
|
|
1186
|
+
_proto.smartContractCall = /*#__PURE__*/function () {
|
|
1187
|
+
var _smartContractCall = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(args) {
|
|
1188
|
+
var _args$rpcUrl;
|
|
1189
|
+
var _yield$this$getContra5, contract, gasFeeData, nonce, tx, overrides, _t5;
|
|
1190
|
+
return _regenerator().w(function (_context7) {
|
|
1191
|
+
while (1) switch (_context7.p = _context7.n) {
|
|
1192
|
+
case 0:
|
|
1193
|
+
_context7.n = 1;
|
|
1194
|
+
return this.getContract({
|
|
1195
|
+
rpcUrl: (_args$rpcUrl = args.rpcUrl) != null ? _args$rpcUrl : this.config.rpcUrl,
|
|
1196
|
+
contractAddress: args.contractAddress,
|
|
1197
|
+
abi: args.contractAbi,
|
|
1198
|
+
privateKey: args.privateKey
|
|
1199
|
+
});
|
|
1200
|
+
case 1:
|
|
1201
|
+
_yield$this$getContra5 = _context7.v;
|
|
1202
|
+
contract = _yield$this$getContra5.contract;
|
|
1203
|
+
gasFeeData = _yield$this$getContra5.gasFeeData;
|
|
1204
|
+
nonce = _yield$this$getContra5.nonce;
|
|
1205
|
+
_context7.p = 2;
|
|
1206
|
+
overrides = {};
|
|
1207
|
+
if (args.methodType === 'read') {
|
|
1208
|
+
overrides = {};
|
|
1209
|
+
} else if (args.methodType === 'write') {
|
|
1210
|
+
overrides = {
|
|
1211
|
+
gasPrice: args.gasPrice ? parseGwei(args.gasPrice) : gasFeeData == null ? void 0 : gasFeeData.gasPrice,
|
|
1212
|
+
nonce: args.nonce || nonce,
|
|
1213
|
+
value: args.value ? parseEther(args.value.toString()) : 0
|
|
1214
|
+
};
|
|
1215
|
+
if (args.gasLimit) {
|
|
1216
|
+
overrides.gasLimit = args.gasLimit;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
if (!(args.params.length > 0)) {
|
|
1220
|
+
_context7.n = 4;
|
|
1221
|
+
break;
|
|
1222
|
+
}
|
|
1223
|
+
_context7.n = 3;
|
|
1224
|
+
return contract == null ? void 0 : contract[args.method].apply(contract, args.params.concat([overrides]));
|
|
1225
|
+
case 3:
|
|
1226
|
+
tx = _context7.v;
|
|
1227
|
+
_context7.n = 6;
|
|
1228
|
+
break;
|
|
1229
|
+
case 4:
|
|
1230
|
+
_context7.n = 5;
|
|
1231
|
+
return contract == null ? void 0 : contract[args.method](overrides);
|
|
1232
|
+
case 5:
|
|
1233
|
+
tx = _context7.v;
|
|
1234
|
+
case 6:
|
|
1235
|
+
return _context7.a(2, successResponse({
|
|
1236
|
+
data: tx
|
|
1237
|
+
}));
|
|
1238
|
+
case 7:
|
|
1239
|
+
_context7.p = 7;
|
|
1240
|
+
_t5 = _context7.v;
|
|
1241
|
+
throw _t5;
|
|
1242
|
+
case 8:
|
|
1243
|
+
return _context7.a(2);
|
|
1244
|
+
}
|
|
1245
|
+
}, _callee7, this, [[2, 7]]);
|
|
1246
|
+
}));
|
|
1247
|
+
function smartContractCall(_x7) {
|
|
1248
|
+
return _smartContractCall.apply(this, arguments);
|
|
1249
|
+
}
|
|
1250
|
+
return smartContractCall;
|
|
1251
|
+
}();
|
|
1252
|
+
_proto.estimateGas = /*#__PURE__*/function () {
|
|
1253
|
+
var _estimateGas = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(_ref7) {
|
|
1254
|
+
var rpcUrl, recipientAddress, amount, data, _yield$this$getContra6, providerInstance, _block$baseFeePerGas, _feeData$maxPriorityF, network, chainId, tx, _yield$Promise$all3, feeData, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, applyMultiplier, isEip1559, baseGasPrice, regularGasPrice, expressGasPrice, instantGasPrice, _regularFee, _expressFee, _instantFee, baseFee, priorityFee, block, regularPriority, regularMaxFee, expressPriority, expressMaxFee, instantPriority, instantMaxFee, MAX_GAS_GWEI, cap, regularFee, expressFee, instantFee, _t6;
|
|
1255
|
+
return _regenerator().w(function (_context8) {
|
|
1256
|
+
while (1) switch (_context8.p = _context8.n) {
|
|
1257
|
+
case 0:
|
|
1258
|
+
rpcUrl = _ref7.rpcUrl, recipientAddress = _ref7.recipientAddress, amount = _ref7.amount, data = _ref7.data;
|
|
1259
|
+
_context8.n = 1;
|
|
1260
|
+
return this.getContract({
|
|
1261
|
+
rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl
|
|
1262
|
+
});
|
|
1263
|
+
case 1:
|
|
1264
|
+
_yield$this$getContra6 = _context8.v;
|
|
1265
|
+
providerInstance = _yield$this$getContra6.providerInstance;
|
|
1266
|
+
_context8.p = 2;
|
|
1267
|
+
_context8.n = 3;
|
|
1268
|
+
return providerInstance.getNetwork();
|
|
1269
|
+
case 3:
|
|
1270
|
+
network = _context8.v;
|
|
1271
|
+
chainId = Number(network.chainId);
|
|
1272
|
+
tx = {
|
|
1273
|
+
to: recipientAddress,
|
|
1274
|
+
value: parseEther(amount.toString()),
|
|
1275
|
+
data: data ? ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(data)) : '0x'
|
|
1276
|
+
};
|
|
1277
|
+
_context8.n = 4;
|
|
1278
|
+
return Promise.all([providerInstance.getFeeData(), providerInstance.estimateGas(tx)]);
|
|
1279
|
+
case 4:
|
|
1280
|
+
_yield$Promise$all3 = _context8.v;
|
|
1281
|
+
feeData = _yield$Promise$all3[0];
|
|
1282
|
+
gasLimit = _yield$Promise$all3[1];
|
|
1283
|
+
gasPrice = feeData.gasPrice, maxFeePerGas = feeData.maxFeePerGas, maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
1284
|
+
applyMultiplier = function applyMultiplier(base, mul) {
|
|
1285
|
+
return base * BigInt(Math.floor(mul * 10)) / 10n;
|
|
1286
|
+
}; // feeData IS AUTO CHECK EIP OR LEGACY
|
|
1287
|
+
isEip1559 = maxFeePerGas !== null && maxPriorityFeePerGas !== null;
|
|
1288
|
+
if (isEip1559) {
|
|
1289
|
+
_context8.n = 5;
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
baseGasPrice = BigInt(gasPrice != null ? gasPrice : 0n);
|
|
1293
|
+
regularGasPrice = baseGasPrice; // wallet "slow"
|
|
1294
|
+
expressGasPrice = baseGasPrice * 110n / 100n; // +10%
|
|
1295
|
+
instantGasPrice = baseGasPrice * 125n / 100n; // +25%
|
|
1296
|
+
_regularFee = gasLimit * regularGasPrice;
|
|
1297
|
+
_expressFee = gasLimit * expressGasPrice;
|
|
1298
|
+
_instantFee = gasLimit * instantGasPrice;
|
|
1299
|
+
return _context8.a(2, successResponse({
|
|
1300
|
+
chainId: chainId,
|
|
1301
|
+
gasLimit: gasLimit.toString(),
|
|
1302
|
+
gasPrice: baseGasPrice.toString(),
|
|
1303
|
+
gasPriceGwei: formatGwei(baseGasPrice),
|
|
1304
|
+
model: "LEGACY",
|
|
1305
|
+
fees: {
|
|
1306
|
+
regular: formatEther(_regularFee),
|
|
1307
|
+
express: formatEther(_expressFee),
|
|
1308
|
+
instant: formatEther(_instantFee)
|
|
1309
|
+
}
|
|
1310
|
+
}));
|
|
1311
|
+
case 5:
|
|
1312
|
+
_context8.n = 6;
|
|
1313
|
+
return providerInstance.getBlock("latest");
|
|
1314
|
+
case 6:
|
|
1315
|
+
block = _context8.v;
|
|
1316
|
+
baseFee = BigInt((_block$baseFeePerGas = block.baseFeePerGas) != null ? _block$baseFeePerGas : 0n);
|
|
1317
|
+
priorityFee = BigInt((_feeData$maxPriorityF = feeData.maxPriorityFeePerGas) != null ? _feeData$maxPriorityF : parseGwei(DEFAULT_PRIORITY));
|
|
1318
|
+
regularPriority = priorityFee;
|
|
1319
|
+
regularMaxFee = baseFee + regularPriority;
|
|
1320
|
+
expressPriority = applyMultiplier(priorityFee, 1.2);
|
|
1321
|
+
expressMaxFee = applyMultiplier(baseFee, 1.2) + expressPriority;
|
|
1322
|
+
instantPriority = applyMultiplier(priorityFee, 1.5);
|
|
1323
|
+
instantMaxFee = applyMultiplier(baseFee, 1.5) + instantPriority;
|
|
1324
|
+
MAX_GAS_GWEI = 100n * 1000000000n;
|
|
1325
|
+
cap = function cap(v) {
|
|
1326
|
+
return v > MAX_GAS_GWEI ? MAX_GAS_GWEI : v;
|
|
1327
|
+
};
|
|
1328
|
+
regularFee = gasLimit * cap(regularMaxFee);
|
|
1329
|
+
expressFee = gasLimit * cap(expressMaxFee);
|
|
1330
|
+
instantFee = gasLimit * cap(instantMaxFee);
|
|
1331
|
+
return _context8.a(2, successResponse({
|
|
1332
|
+
chainId: chainId,
|
|
1333
|
+
gasLimit: gasLimit.toString(),
|
|
1334
|
+
baseFeeGwei: formatGwei(baseFee),
|
|
1335
|
+
priorityFeeGwei: formatGwei(priorityFee),
|
|
1336
|
+
model: "EIP1559",
|
|
1337
|
+
fees: {
|
|
1338
|
+
regular: {
|
|
1339
|
+
perCoin: formatEther(regularFee),
|
|
1340
|
+
maxPriorityFeePerGas: regularPriority.toString(),
|
|
1341
|
+
maxFeePerGas: regularMaxFee.toString()
|
|
1342
|
+
},
|
|
1343
|
+
express: {
|
|
1344
|
+
perCoin: formatEther(expressFee),
|
|
1345
|
+
maxPriorityFeePerGas: expressPriority.toString(),
|
|
1346
|
+
maxFeePerGas: expressMaxFee.toString()
|
|
1347
|
+
},
|
|
1348
|
+
instant: {
|
|
1349
|
+
perCoin: formatEther(instantFee),
|
|
1350
|
+
maxPriorityFeePerGas: instantPriority.toString(),
|
|
1351
|
+
maxFeePerGas: instantMaxFee.toString()
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}));
|
|
1355
|
+
case 7:
|
|
1356
|
+
_context8.p = 7;
|
|
1357
|
+
_t6 = _context8.v;
|
|
1358
|
+
throw _t6;
|
|
1359
|
+
case 8:
|
|
1360
|
+
return _context8.a(2);
|
|
1361
|
+
}
|
|
1362
|
+
}, _callee8, this, [[2, 7]]);
|
|
1363
|
+
}));
|
|
1364
|
+
function estimateGas(_x8) {
|
|
1365
|
+
return _estimateGas.apply(this, arguments);
|
|
1366
|
+
}
|
|
1367
|
+
return estimateGas;
|
|
1368
|
+
}();
|
|
1369
|
+
_proto.buildSignParams = /*#__PURE__*/function () {
|
|
1370
|
+
var _buildSignParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(_ref8) {
|
|
1371
|
+
var args, nonce, gasFeeData, recipientAddress, value, contractAddress, txBase, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12;
|
|
1372
|
+
return _regenerator().w(function (_context9) {
|
|
1373
|
+
while (1) switch (_context9.n) {
|
|
1374
|
+
case 0:
|
|
1375
|
+
args = _ref8.args, nonce = _ref8.nonce, gasFeeData = _ref8.gasFeeData, recipientAddress = _ref8.recipientAddress, value = _ref8.value, contractAddress = _ref8.contractAddress;
|
|
1376
|
+
_t7 = _extends;
|
|
1377
|
+
_t8 = recipientAddress.address;
|
|
1378
|
+
_t9 = cryptoLib.BigNumber(value.toString());
|
|
1379
|
+
_t0 = args.data ? ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(args.data)) : '0x';
|
|
1380
|
+
_t1 = args.nonce;
|
|
1381
|
+
if (_t1) {
|
|
1382
|
+
_context9.n = 2;
|
|
1383
|
+
break;
|
|
1384
|
+
}
|
|
1385
|
+
_context9.n = 1;
|
|
1386
|
+
return nonce;
|
|
1387
|
+
case 1:
|
|
1388
|
+
_t1 = _context9.v;
|
|
1389
|
+
case 2:
|
|
1390
|
+
_t10 = _t1;
|
|
1391
|
+
_t11 = args.gasLimit ? cryptoLib.BigNumber(args.gasLimit) : cryptoLib.BigNumber(21000);
|
|
1392
|
+
_t12 = Number(this.currentChain.id);
|
|
1393
|
+
txBase = _t7({
|
|
1394
|
+
to: _t8,
|
|
1395
|
+
value: _t9,
|
|
1396
|
+
data: _t0,
|
|
1397
|
+
nonce: _t10,
|
|
1398
|
+
gasLimit: _t11,
|
|
1399
|
+
chainId: _t12
|
|
1400
|
+
}, contractAddress ? {
|
|
1401
|
+
contractAddress: contractAddress
|
|
1402
|
+
} : {});
|
|
1403
|
+
if (!args.gasPrice) {
|
|
1404
|
+
_context9.n = 3;
|
|
1405
|
+
break;
|
|
1406
|
+
}
|
|
1407
|
+
return _context9.a(2, {
|
|
1408
|
+
privateKey: args.privateKey,
|
|
1409
|
+
data: _extends({}, txBase, {
|
|
1410
|
+
gasPrice: cryptoLib.BigNumber(parseGwei(args.gasPrice).toString()),
|
|
1411
|
+
type: 0
|
|
1412
|
+
})
|
|
1413
|
+
});
|
|
1414
|
+
case 3:
|
|
1415
|
+
return _context9.a(2, {
|
|
1416
|
+
privateKey: args.privateKey,
|
|
1417
|
+
data: _extends({}, txBase, {
|
|
1418
|
+
type: 2,
|
|
1419
|
+
maxPriorityFeePerGas: cryptoLib.BigNumber(args.maxPriorityFeePerGas ? args.maxPriorityFeePerGas : gasFeeData.maxPriorityFeePerGas.toString()),
|
|
1420
|
+
maxFeePerGas: cryptoLib.BigNumber(args.maxFeePerGas ? args.maxFeePerGas : gasFeeData.maxFeePerGas.toString())
|
|
1421
|
+
})
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
}, _callee9, this);
|
|
1425
|
+
}));
|
|
1426
|
+
function buildSignParams(_x9) {
|
|
1427
|
+
return _buildSignParams.apply(this, arguments);
|
|
1428
|
+
}
|
|
1429
|
+
return buildSignParams;
|
|
1430
|
+
}();
|
|
1431
|
+
return EvmWallet;
|
|
1432
|
+
}(BaseWallet);
|
|
1433
|
+
|
|
1434
|
+
var successResponse$1 = function successResponse(args) {
|
|
1435
|
+
return args;
|
|
1436
|
+
};
|
|
1437
|
+
var BtcWallet = /*#__PURE__*/function (_BaseWallet) {
|
|
1438
|
+
function BtcWallet(config) {
|
|
1439
|
+
var _this;
|
|
1440
|
+
_this = _BaseWallet.call(this, config) || this;
|
|
1441
|
+
_this.wallet = _this.config.cluster === "testnet" ? new coinBitcoin.TBtcWallet() : new coinBitcoin.BtcWallet();
|
|
1442
|
+
return _this;
|
|
1443
|
+
}
|
|
1444
|
+
_inheritsLoose(BtcWallet, _BaseWallet);
|
|
1445
|
+
var _proto = BtcWallet.prototype;
|
|
1446
|
+
_proto.generateWallet = /*#__PURE__*/function () {
|
|
1447
|
+
var _generateWallet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
1448
|
+
var mnemonic, derivationPath, hdPath, getMnemonic, derivePrivateKey, _yield$this$wallet$ge, address, publicKey, _t;
|
|
1449
|
+
return _regenerator().w(function (_context) {
|
|
1450
|
+
while (1) switch (_context.n) {
|
|
1451
|
+
case 0:
|
|
1452
|
+
mnemonic = _ref.mnemonic, derivationPath = _ref.derivationPath;
|
|
1453
|
+
hdPath = derivationPath || "m/44'/0'/0'/0/0";
|
|
1454
|
+
if (!(mnemonic != null)) {
|
|
1455
|
+
_context.n = 1;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
_t = mnemonic;
|
|
1459
|
+
_context.n = 3;
|
|
1460
|
+
break;
|
|
1461
|
+
case 1:
|
|
1462
|
+
_context.n = 2;
|
|
1463
|
+
return this.generateMnemonic(12);
|
|
1464
|
+
case 2:
|
|
1465
|
+
_t = _context.v;
|
|
1466
|
+
case 3:
|
|
1467
|
+
getMnemonic = _t;
|
|
1468
|
+
_context.n = 4;
|
|
1469
|
+
return this.wallet.getDerivedPrivateKey({
|
|
1470
|
+
mnemonic: getMnemonic,
|
|
1471
|
+
hdPath: hdPath
|
|
1472
|
+
});
|
|
1473
|
+
case 4:
|
|
1474
|
+
derivePrivateKey = _context.v;
|
|
1475
|
+
_context.n = 5;
|
|
1476
|
+
return this.wallet.getNewAddress({
|
|
1477
|
+
privateKey: derivePrivateKey
|
|
1478
|
+
});
|
|
1479
|
+
case 5:
|
|
1480
|
+
_yield$this$wallet$ge = _context.v;
|
|
1481
|
+
address = _yield$this$wallet$ge.address;
|
|
1482
|
+
publicKey = _yield$this$wallet$ge.publicKey;
|
|
1483
|
+
return _context.a(2, successResponse$1({
|
|
1484
|
+
address: address,
|
|
1485
|
+
publicKey: publicKey,
|
|
1486
|
+
privateKey: derivePrivateKey
|
|
1487
|
+
}));
|
|
1488
|
+
}
|
|
1489
|
+
}, _callee, this);
|
|
1490
|
+
}));
|
|
1491
|
+
function generateWallet(_x) {
|
|
1492
|
+
return _generateWallet.apply(this, arguments);
|
|
1493
|
+
}
|
|
1494
|
+
return generateWallet;
|
|
1495
|
+
}();
|
|
1496
|
+
return BtcWallet;
|
|
1497
|
+
}(BaseWallet);
|
|
1498
|
+
|
|
1499
|
+
var _excluded$1 = ["privateKey", "contractAddress", "rpcUrl"];
|
|
1500
|
+
var provider$1 = function provider(rpcUrl) {
|
|
1501
|
+
return new solanaWeb3.Connection(rpcUrl);
|
|
1502
|
+
};
|
|
1503
|
+
var ACCOUNT_LAYOUT = /*#__PURE__*/BufferLayout.struct([/*#__PURE__*/BufferLayout.blob(32, 'mint'), /*#__PURE__*/BufferLayout.blob(32, 'owner'), /*#__PURE__*/BufferLayout.nu64('amount'), /*#__PURE__*/BufferLayout.blob(93)]);
|
|
1504
|
+
var CLUSTER_ENV = {
|
|
1505
|
+
"mainnet-beta": splTokenRegistry.ENV.MainnetBeta,
|
|
1506
|
+
"testnet": splTokenRegistry.ENV.Testnet,
|
|
1507
|
+
"devnet": splTokenRegistry.ENV.Devnet
|
|
1508
|
+
};
|
|
1509
|
+
var SolWallet = /*#__PURE__*/function (_BaseWallet) {
|
|
1510
|
+
function SolWallet(config) {
|
|
1511
|
+
var _this;
|
|
1512
|
+
_this = _BaseWallet.call(this, config) || this;
|
|
1513
|
+
_this.wallet = new coinSolana.SolWallet();
|
|
1514
|
+
return _this;
|
|
1515
|
+
}
|
|
1516
|
+
_inheritsLoose(SolWallet, _BaseWallet);
|
|
1517
|
+
var _proto = SolWallet.prototype;
|
|
1518
|
+
_proto.generateWallet = /*#__PURE__*/function () {
|
|
1519
|
+
var _generateWallet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
1520
|
+
var mnemonic, derivationPath, hdPath, getMnemonic, derivePrivateKey, _yield$this$wallet$ge, address, publicKey, _t;
|
|
1521
|
+
return _regenerator().w(function (_context) {
|
|
1522
|
+
while (1) switch (_context.n) {
|
|
1523
|
+
case 0:
|
|
1524
|
+
mnemonic = _ref.mnemonic, derivationPath = _ref.derivationPath;
|
|
1525
|
+
hdPath = derivationPath || "m/44'/501'/0'/0'";
|
|
1526
|
+
if (!(mnemonic != null)) {
|
|
1527
|
+
_context.n = 1;
|
|
1528
|
+
break;
|
|
1529
|
+
}
|
|
1530
|
+
_t = mnemonic;
|
|
1531
|
+
_context.n = 3;
|
|
1532
|
+
break;
|
|
1533
|
+
case 1:
|
|
1534
|
+
_context.n = 2;
|
|
1535
|
+
return this.generateMnemonic(12);
|
|
1536
|
+
case 2:
|
|
1537
|
+
_t = _context.v;
|
|
1538
|
+
case 3:
|
|
1539
|
+
getMnemonic = _t;
|
|
1540
|
+
_context.n = 4;
|
|
1541
|
+
return this.wallet.getDerivedPrivateKey({
|
|
1542
|
+
mnemonic: getMnemonic,
|
|
1543
|
+
hdPath: hdPath
|
|
1544
|
+
});
|
|
1545
|
+
case 4:
|
|
1546
|
+
derivePrivateKey = _context.v;
|
|
1547
|
+
_context.n = 5;
|
|
1548
|
+
return this.wallet.getNewAddress({
|
|
1549
|
+
privateKey: derivePrivateKey
|
|
1550
|
+
});
|
|
1551
|
+
case 5:
|
|
1552
|
+
_yield$this$wallet$ge = _context.v;
|
|
1553
|
+
address = _yield$this$wallet$ge.address;
|
|
1554
|
+
publicKey = _yield$this$wallet$ge.publicKey;
|
|
1555
|
+
return _context.a(2, successResponse({
|
|
1556
|
+
address: address,
|
|
1557
|
+
publicKey: publicKey,
|
|
1558
|
+
privateKey: derivePrivateKey
|
|
1559
|
+
}));
|
|
1560
|
+
}
|
|
1561
|
+
}, _callee, this);
|
|
1562
|
+
}));
|
|
1563
|
+
function generateWallet(_x) {
|
|
1564
|
+
return _generateWallet.apply(this, arguments);
|
|
1565
|
+
}
|
|
1566
|
+
return generateWallet;
|
|
1567
|
+
}();
|
|
1568
|
+
_proto.getBalance = /*#__PURE__*/function () {
|
|
1569
|
+
var _getBalance = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
|
|
1570
|
+
var rpcUrl, contractAddress, address, connection, recipientAddress, publicKey, mintPubkey, tokenAccountAddress, accountInfo, rawBalance, balance, _t2;
|
|
1571
|
+
return _regenerator().w(function (_context2) {
|
|
1572
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
1573
|
+
case 0:
|
|
1574
|
+
rpcUrl = _ref2.rpcUrl, contractAddress = _ref2.contractAddress, address = _ref2.address;
|
|
1575
|
+
connection = provider$1(rpcUrl != null ? rpcUrl : this.config.rpcUrl);
|
|
1576
|
+
_context2.p = 1;
|
|
1577
|
+
_context2.n = 2;
|
|
1578
|
+
return this.wallet.validAddress({
|
|
1579
|
+
address: address
|
|
1580
|
+
});
|
|
1581
|
+
case 2:
|
|
1582
|
+
recipientAddress = _context2.v;
|
|
1583
|
+
if (recipientAddress.isValid) {
|
|
1584
|
+
_context2.n = 3;
|
|
1585
|
+
break;
|
|
1586
|
+
}
|
|
1587
|
+
throw new Error("address not valid");
|
|
1588
|
+
case 3:
|
|
1589
|
+
publicKey = new solanaWeb3.PublicKey(recipientAddress.address);
|
|
1590
|
+
if (!contractAddress) {
|
|
1591
|
+
_context2.n = 8;
|
|
1592
|
+
break;
|
|
1593
|
+
}
|
|
1594
|
+
mintPubkey = new solanaWeb3.PublicKey(contractAddress); // get token by account
|
|
1595
|
+
_context2.n = 4;
|
|
1596
|
+
return splToken.getAssociatedTokenAddress(mintPubkey, publicKey);
|
|
1597
|
+
case 4:
|
|
1598
|
+
tokenAccountAddress = _context2.v;
|
|
1599
|
+
_context2.n = 5;
|
|
1600
|
+
return connection.getAccountInfo(tokenAccountAddress);
|
|
1601
|
+
case 5:
|
|
1602
|
+
accountInfo = _context2.v;
|
|
1603
|
+
if (accountInfo) {
|
|
1604
|
+
_context2.n = 6;
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1607
|
+
return _context2.a(2, successResponse({
|
|
1608
|
+
balance: "0"
|
|
1609
|
+
}));
|
|
1610
|
+
case 6:
|
|
1611
|
+
_context2.n = 7;
|
|
1612
|
+
return connection.getTokenAccountBalance(tokenAccountAddress);
|
|
1613
|
+
case 7:
|
|
1614
|
+
rawBalance = _context2.v;
|
|
1615
|
+
return _context2.a(2, successResponse({
|
|
1616
|
+
balance: formatAmount(rawBalance.value.amount, rawBalance.value.decimals),
|
|
1617
|
+
_rawBalance: rawBalance.value.amount,
|
|
1618
|
+
_decimal: rawBalance.value.decimals
|
|
1619
|
+
}));
|
|
1620
|
+
case 8:
|
|
1621
|
+
_context2.n = 9;
|
|
1622
|
+
return connection.getBalance(publicKey);
|
|
1623
|
+
case 9:
|
|
1624
|
+
balance = _context2.v;
|
|
1625
|
+
return _context2.a(2, successResponse({
|
|
1626
|
+
balance: formatAmount(balance.toString(), 9),
|
|
1627
|
+
_rawBalance: parseAmount(balance, 9),
|
|
1628
|
+
_decimal: 9
|
|
1629
|
+
}));
|
|
1630
|
+
case 10:
|
|
1631
|
+
_context2.p = 10;
|
|
1632
|
+
_t2 = _context2.v;
|
|
1633
|
+
throw _t2;
|
|
1634
|
+
case 11:
|
|
1635
|
+
return _context2.a(2);
|
|
1636
|
+
}
|
|
1637
|
+
}, _callee2, this, [[1, 10]]);
|
|
1638
|
+
}));
|
|
1639
|
+
function getBalance(_x2) {
|
|
1640
|
+
return _getBalance.apply(this, arguments);
|
|
1641
|
+
}
|
|
1642
|
+
return getBalance;
|
|
1643
|
+
}();
|
|
1644
|
+
_proto.transfer = /*#__PURE__*/function () {
|
|
1645
|
+
var _transfer = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref3) {
|
|
1646
|
+
var privateKey, contractAddress, rpcUrl, args, connection, _args$amount2, recipientAddress, fromAccount, _yield$this$getRecomm, computeUnitLimit, computeUnitPrice, _yield$connection$get, blockhash, _args$amount, mintPubkey, fromPubkey, recipientPubkey, fromTokenAccount, recipientTokenAccount, decimals, fromTokenBal, mintAccountInfo, parsed, recipientAtaInfo, recipientHasATA, shouldCreateATA, rawTokenAmount, params, _signedTx, _rawTx, txid, lamports, solParams, signedTx, rawTx, broadcast, _t5;
|
|
1647
|
+
return _regenerator().w(function (_context3) {
|
|
1648
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
1649
|
+
case 0:
|
|
1650
|
+
privateKey = _ref3.privateKey, contractAddress = _ref3.contractAddress, rpcUrl = _ref3.rpcUrl, args = /*#__PURE__*/_objectWithoutPropertiesLoose(_ref3, _excluded$1);
|
|
1651
|
+
connection = provider$1(rpcUrl != null ? rpcUrl : this.config.rpcUrl);
|
|
1652
|
+
_context3.p = 1;
|
|
1653
|
+
_context3.n = 2;
|
|
1654
|
+
return this.wallet.validAddress({
|
|
1655
|
+
address: args.recipientAddress
|
|
1656
|
+
});
|
|
1657
|
+
case 2:
|
|
1658
|
+
recipientAddress = _context3.v;
|
|
1659
|
+
if (recipientAddress.isValid) {
|
|
1660
|
+
_context3.n = 3;
|
|
1661
|
+
break;
|
|
1662
|
+
}
|
|
1663
|
+
throw new Error("address not valid");
|
|
1664
|
+
case 3:
|
|
1665
|
+
_context3.n = 4;
|
|
1666
|
+
return this.wallet.getNewAddress({
|
|
1667
|
+
privateKey: privateKey
|
|
1668
|
+
});
|
|
1669
|
+
case 4:
|
|
1670
|
+
fromAccount = _context3.v;
|
|
1671
|
+
_context3.n = 5;
|
|
1672
|
+
return this.getRecommendedFees(connection);
|
|
1673
|
+
case 5:
|
|
1674
|
+
_yield$this$getRecomm = _context3.v;
|
|
1675
|
+
computeUnitLimit = _yield$this$getRecomm.computeUnitLimit;
|
|
1676
|
+
computeUnitPrice = _yield$this$getRecomm.computeUnitPrice;
|
|
1677
|
+
if (args.gasLimit) computeUnitLimit = args.gasLimit;
|
|
1678
|
+
if (args.gasPrice) computeUnitPrice = parseInt(args.gasPrice, 10);
|
|
1679
|
+
// get latest blockhash
|
|
1680
|
+
_context3.n = 6;
|
|
1681
|
+
return connection.getLatestBlockhash();
|
|
1682
|
+
case 6:
|
|
1683
|
+
_yield$connection$get = _context3.v;
|
|
1684
|
+
blockhash = _yield$connection$get.blockhash;
|
|
1685
|
+
if (!contractAddress) {
|
|
1686
|
+
_context3.n = 19;
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
mintPubkey = new solanaWeb3.PublicKey(contractAddress);
|
|
1690
|
+
fromPubkey = new solanaWeb3.PublicKey(fromAccount.address);
|
|
1691
|
+
recipientPubkey = new solanaWeb3.PublicKey(recipientAddress.address); // Associated Token Accounts (computed, not necessarily exist)
|
|
1692
|
+
_context3.n = 7;
|
|
1693
|
+
return splToken.getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
1694
|
+
case 7:
|
|
1695
|
+
fromTokenAccount = _context3.v;
|
|
1696
|
+
_context3.n = 8;
|
|
1697
|
+
return splToken.getAssociatedTokenAddress(mintPubkey, recipientPubkey);
|
|
1698
|
+
case 8:
|
|
1699
|
+
recipientTokenAccount = _context3.v;
|
|
1700
|
+
// Try to read decimals from sender token account first, fallback to token supply
|
|
1701
|
+
decimals = 0;
|
|
1702
|
+
_context3.p = 9;
|
|
1703
|
+
_context3.n = 10;
|
|
1704
|
+
return connection.getTokenAccountBalance(fromTokenAccount);
|
|
1705
|
+
case 10:
|
|
1706
|
+
fromTokenBal = _context3.v;
|
|
1707
|
+
decimals = fromTokenBal.value.decimals;
|
|
1708
|
+
_context3.n = 15;
|
|
1709
|
+
break;
|
|
1710
|
+
case 11:
|
|
1711
|
+
_context3.p = 11;
|
|
1712
|
+
_context3.p = 12;
|
|
1713
|
+
_context3.n = 13;
|
|
1714
|
+
return connection.getParsedAccountInfo(mintPubkey);
|
|
1715
|
+
case 13:
|
|
1716
|
+
mintAccountInfo = _context3.v;
|
|
1717
|
+
// parsed data path may vary; handle gracefully
|
|
1718
|
+
// if parsed exists:
|
|
1719
|
+
if (mintAccountInfo.value && mintAccountInfo.value.data.parsed) {
|
|
1720
|
+
parsed = mintAccountInfo.value.data.parsed;
|
|
1721
|
+
decimals = parsed.info.decimals || 0;
|
|
1722
|
+
}
|
|
1723
|
+
_context3.n = 15;
|
|
1724
|
+
break;
|
|
1725
|
+
case 14:
|
|
1726
|
+
_context3.p = 14;
|
|
1727
|
+
throw new Error("Failed to determine token decimals for mint " + contractAddress);
|
|
1728
|
+
case 15:
|
|
1729
|
+
_context3.n = 16;
|
|
1730
|
+
return connection.getAccountInfo(recipientTokenAccount);
|
|
1731
|
+
case 16:
|
|
1732
|
+
recipientAtaInfo = _context3.v;
|
|
1733
|
+
recipientHasATA = !!recipientAtaInfo; // decide whether to create ATA: user can pass args.createAssociatedAddress
|
|
1734
|
+
shouldCreateATA = !!args.createAssociatedAddress && !recipientHasATA; // compute token amount (smallest unit)
|
|
1735
|
+
// args.amount is assumed token amount in human units (eg. 1.5 USDC)
|
|
1736
|
+
rawTokenAmount = BigInt(Math.round(((_args$amount = args.amount) != null ? _args$amount : 0) * Math.pow(10, decimals))); // Build params for OKX wallet signTransaction (tokenTransfer)
|
|
1737
|
+
params = {
|
|
1738
|
+
privateKey: privateKey,
|
|
1739
|
+
data: {
|
|
1740
|
+
type: "tokenTransfer",
|
|
1741
|
+
payer: fromAccount.address,
|
|
1742
|
+
from: fromAccount.address,
|
|
1743
|
+
to: recipientAddress.address,
|
|
1744
|
+
blockHash: blockhash,
|
|
1745
|
+
mint: contractAddress,
|
|
1746
|
+
amount: rawTokenAmount.toString(),
|
|
1747
|
+
decimal: decimals,
|
|
1748
|
+
createAssociatedAddress: !!shouldCreateATA,
|
|
1749
|
+
token2022: !!args.token2022,
|
|
1750
|
+
computeUnitLimit: computeUnitLimit,
|
|
1751
|
+
computeUnitPrice: computeUnitPrice
|
|
1752
|
+
}
|
|
1753
|
+
}; // sign & broadcast
|
|
1754
|
+
_context3.n = 17;
|
|
1755
|
+
return this.wallet.signTransaction(params);
|
|
1756
|
+
case 17:
|
|
1757
|
+
_signedTx = _context3.v;
|
|
1758
|
+
// OKX returns base58 signed tx — decode and broadcast
|
|
1759
|
+
_rawTx = cryptoLib.base.fromBase58(_signedTx);
|
|
1760
|
+
_context3.n = 18;
|
|
1761
|
+
return connection.sendRawTransaction(_rawTx, {
|
|
1762
|
+
skipPreflight: false,
|
|
1763
|
+
maxRetries: 3
|
|
1764
|
+
});
|
|
1765
|
+
case 18:
|
|
1766
|
+
txid = _context3.v;
|
|
1767
|
+
return _context3.a(2, successResponse({
|
|
1768
|
+
hash: txid
|
|
1769
|
+
}));
|
|
1770
|
+
case 19:
|
|
1771
|
+
// ---------- NATIVE SOL FLOW ----------
|
|
1772
|
+
lamports = Math.round(((_args$amount2 = args.amount) != null ? _args$amount2 : 0) * solanaWeb3.LAMPORTS_PER_SOL);
|
|
1773
|
+
solParams = {
|
|
1774
|
+
privateKey: privateKey,
|
|
1775
|
+
data: {
|
|
1776
|
+
type: "transfer",
|
|
1777
|
+
payer: fromAccount.address,
|
|
1778
|
+
from: fromAccount.address,
|
|
1779
|
+
to: recipientAddress.address,
|
|
1780
|
+
blockHash: blockhash,
|
|
1781
|
+
amount: lamports,
|
|
1782
|
+
computeUnitLimit: computeUnitLimit,
|
|
1783
|
+
computeUnitPrice: computeUnitPrice
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
_context3.n = 20;
|
|
1787
|
+
return this.wallet.signTransaction(solParams);
|
|
1788
|
+
case 20:
|
|
1789
|
+
signedTx = _context3.v;
|
|
1790
|
+
rawTx = cryptoLib.base.fromBase58(signedTx);
|
|
1791
|
+
_context3.n = 21;
|
|
1792
|
+
return connection.sendRawTransaction(rawTx, {
|
|
1793
|
+
skipPreflight: false,
|
|
1794
|
+
maxRetries: 3
|
|
1795
|
+
});
|
|
1796
|
+
case 21:
|
|
1797
|
+
broadcast = _context3.v;
|
|
1798
|
+
return _context3.a(2, successResponse({
|
|
1799
|
+
hash: broadcast
|
|
1800
|
+
}));
|
|
1801
|
+
case 22:
|
|
1802
|
+
_context3.p = 22;
|
|
1803
|
+
_t5 = _context3.v;
|
|
1804
|
+
throw _t5;
|
|
1805
|
+
case 23:
|
|
1806
|
+
return _context3.a(2);
|
|
1807
|
+
}
|
|
1808
|
+
}, _callee3, this, [[12, 14], [9, 11], [1, 22]]);
|
|
1809
|
+
}));
|
|
1810
|
+
function transfer(_x3) {
|
|
1811
|
+
return _transfer.apply(this, arguments);
|
|
1812
|
+
}
|
|
1813
|
+
return transfer;
|
|
1814
|
+
}();
|
|
1815
|
+
_proto.getTokenInfo = /*#__PURE__*/function () {
|
|
1816
|
+
var _getTokenInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
|
|
1817
|
+
var contractAddress, rpcUrl, _ref4$cluster, cluster, _mintInfo$value, _parsedMint$decimals, _parsedMint$supply, connection, mintAddress, mintInfo, parsedMint, decimals, supplyRaw, tokenName, tokenSymbol, tokenLogo, _CLUSTER_ENV$cluster, env, _provider, tokenList, tokenMap, token, data, _t6, _t7;
|
|
1818
|
+
return _regenerator().w(function (_context4) {
|
|
1819
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
1820
|
+
case 0:
|
|
1821
|
+
contractAddress = _ref4.contractAddress, rpcUrl = _ref4.rpcUrl, _ref4$cluster = _ref4.cluster, cluster = _ref4$cluster === void 0 ? "mainnet-beta" : _ref4$cluster;
|
|
1822
|
+
_context4.p = 1;
|
|
1823
|
+
connection = provider$1(rpcUrl != null ? rpcUrl : this.config.rpcUrl);
|
|
1824
|
+
mintAddress = new solanaWeb3.PublicKey(contractAddress); // --- step 1: fetch mint info dari RPC ---
|
|
1825
|
+
_context4.n = 2;
|
|
1826
|
+
return connection.getParsedAccountInfo(mintAddress);
|
|
1827
|
+
case 2:
|
|
1828
|
+
mintInfo = _context4.v;
|
|
1829
|
+
parsedMint = mintInfo == null || (_mintInfo$value = mintInfo.value) == null || (_mintInfo$value = _mintInfo$value.data) == null || (_mintInfo$value = _mintInfo$value.parsed) == null ? void 0 : _mintInfo$value.info;
|
|
1830
|
+
decimals = (_parsedMint$decimals = parsedMint == null ? void 0 : parsedMint.decimals) != null ? _parsedMint$decimals : 0;
|
|
1831
|
+
supplyRaw = (_parsedMint$supply = parsedMint == null ? void 0 : parsedMint.supply) != null ? _parsedMint$supply : "0"; // --- step 2: coba ambil info dari TokenListProvider ---
|
|
1832
|
+
tokenName = "";
|
|
1833
|
+
tokenSymbol = "";
|
|
1834
|
+
tokenLogo = "";
|
|
1835
|
+
_context4.p = 3;
|
|
1836
|
+
env = (_CLUSTER_ENV$cluster = CLUSTER_ENV[cluster]) != null ? _CLUSTER_ENV$cluster : splTokenRegistry.ENV.MainnetBeta;
|
|
1837
|
+
_context4.n = 4;
|
|
1838
|
+
return new splTokenRegistry.TokenListProvider().resolve();
|
|
1839
|
+
case 4:
|
|
1840
|
+
_provider = _context4.v;
|
|
1841
|
+
tokenList = _provider.filterByChainId(env).getList();
|
|
1842
|
+
tokenMap = new Map(tokenList.map(function (item) {
|
|
1843
|
+
return [item.address, item];
|
|
1844
|
+
}));
|
|
1845
|
+
token = tokenMap.get(mintAddress.toBase58());
|
|
1846
|
+
if (token) {
|
|
1847
|
+
tokenName = token.name;
|
|
1848
|
+
tokenSymbol = token.symbol;
|
|
1849
|
+
tokenLogo = token.logoURI || "";
|
|
1850
|
+
}
|
|
1851
|
+
_context4.n = 6;
|
|
1852
|
+
break;
|
|
1853
|
+
case 5:
|
|
1854
|
+
_context4.p = 5;
|
|
1855
|
+
_t6 = _context4.v;
|
|
1856
|
+
console.warn("TokenListProvider failed:", _t6);
|
|
1857
|
+
case 6:
|
|
1858
|
+
// --- step 3: fallback kalau name/symbol kosong ---
|
|
1859
|
+
if (!tokenName) tokenName = contractAddress.slice(0, 6) + "...";
|
|
1860
|
+
if (!tokenSymbol) tokenSymbol = "SPL";
|
|
1861
|
+
data = {
|
|
1862
|
+
name: tokenName,
|
|
1863
|
+
symbol: tokenSymbol,
|
|
1864
|
+
address: contractAddress,
|
|
1865
|
+
decimals: decimals,
|
|
1866
|
+
logoUrl: tokenLogo || "",
|
|
1867
|
+
totalSupply: (Number(supplyRaw) / Math.pow(10, decimals)).toString()
|
|
1868
|
+
};
|
|
1869
|
+
return _context4.a(2, successResponse(_extends({}, data)));
|
|
1870
|
+
case 7:
|
|
1871
|
+
_context4.p = 7;
|
|
1872
|
+
_t7 = _context4.v;
|
|
1873
|
+
throw _t7;
|
|
1874
|
+
case 8:
|
|
1875
|
+
return _context4.a(2);
|
|
1876
|
+
}
|
|
1877
|
+
}, _callee4, this, [[3, 5], [1, 7]]);
|
|
1878
|
+
}));
|
|
1879
|
+
function getTokenInfo(_x4) {
|
|
1880
|
+
return _getTokenInfo.apply(this, arguments);
|
|
1881
|
+
}
|
|
1882
|
+
return getTokenInfo;
|
|
1883
|
+
}();
|
|
1884
|
+
_proto.getRecommendedFees = /*#__PURE__*/function () {
|
|
1885
|
+
var _getRecommendedFees = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(connection) {
|
|
1886
|
+
var computeUnitLimit, computeUnitPrice, fees, sorted;
|
|
1887
|
+
return _regenerator().w(function (_context5) {
|
|
1888
|
+
while (1) switch (_context5.p = _context5.n) {
|
|
1889
|
+
case 0:
|
|
1890
|
+
computeUnitLimit = 140000; // default
|
|
1891
|
+
computeUnitPrice = 0; // default = 0 (without priority fee)
|
|
1892
|
+
_context5.p = 1;
|
|
1893
|
+
_context5.n = 2;
|
|
1894
|
+
return connection.getRecentPrioritizationFees();
|
|
1895
|
+
case 2:
|
|
1896
|
+
fees = _context5.v;
|
|
1897
|
+
if (fees.length > 0) {
|
|
1898
|
+
// Ambil median biar stabil
|
|
1899
|
+
sorted = fees.map(function (f) {
|
|
1900
|
+
return f.prioritizationFee;
|
|
1901
|
+
}).sort(function (a, b) {
|
|
1902
|
+
return a - b;
|
|
1903
|
+
});
|
|
1904
|
+
computeUnitPrice = sorted[Math.floor(sorted.length / 2)] || 0;
|
|
1905
|
+
}
|
|
1906
|
+
_context5.n = 4;
|
|
1907
|
+
break;
|
|
1908
|
+
case 3:
|
|
1909
|
+
_context5.p = 3;
|
|
1910
|
+
console.warn("Failed to fetch prioritization fees, fallback to defaults");
|
|
1911
|
+
case 4:
|
|
1912
|
+
return _context5.a(2, {
|
|
1913
|
+
computeUnitLimit: computeUnitLimit,
|
|
1914
|
+
computeUnitPrice: computeUnitPrice
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
}, _callee5, null, [[1, 3]]);
|
|
1918
|
+
}));
|
|
1919
|
+
function getRecommendedFees(_x5) {
|
|
1920
|
+
return _getRecommendedFees.apply(this, arguments);
|
|
1921
|
+
}
|
|
1922
|
+
return getRecommendedFees;
|
|
1923
|
+
}();
|
|
1924
|
+
return SolWallet;
|
|
1925
|
+
}(BaseWallet);
|
|
1926
|
+
|
|
1927
|
+
// src/services/wallet-registry.ts
|
|
1928
|
+
var WalletRegistry = {
|
|
1929
|
+
EVM: EvmWallet,
|
|
1930
|
+
BTC: BtcWallet,
|
|
1931
|
+
SOL: SolWallet
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
var CryptoClientSdk = /*#__PURE__*/function () {
|
|
1935
|
+
function CryptoClientSdk(_ref) {
|
|
1936
|
+
var network = _ref.network,
|
|
1937
|
+
chainId = _ref.chainId,
|
|
1938
|
+
rpcUrl = _ref.rpcUrl;
|
|
1939
|
+
this.network = network;
|
|
1940
|
+
this.chainId = chainId;
|
|
1941
|
+
this.rpcUrl = rpcUrl;
|
|
1942
|
+
}
|
|
1943
|
+
var _proto = CryptoClientSdk.prototype;
|
|
1944
|
+
_proto.getWallet = function getWallet() {
|
|
1945
|
+
var WalletClass = WalletRegistry[this.network];
|
|
1946
|
+
var config = {
|
|
1947
|
+
chainId: this.chainId,
|
|
1948
|
+
rpcUrl: this.rpcUrl
|
|
1949
|
+
};
|
|
1950
|
+
return new WalletClass(config);
|
|
1951
|
+
};
|
|
1952
|
+
return CryptoClientSdk;
|
|
1953
|
+
}();
|
|
1954
|
+
|
|
1955
|
+
exports.ACCOUNT_LAYOUT = ACCOUNT_LAYOUT;
|
|
1956
|
+
exports.BaseWallet = BaseWallet;
|
|
1957
|
+
exports.BtcWallet = BtcWallet;
|
|
1958
|
+
exports.CLUSTER_ENV = CLUSTER_ENV;
|
|
1959
|
+
exports.CryptoClientSdk = CryptoClientSdk;
|
|
1960
|
+
exports.EvmWallet = EvmWallet;
|
|
1961
|
+
exports.SolWallet = SolWallet;
|
|
1962
|
+
//# sourceMappingURL=crypto-wallet-sdk.cjs.development.js.map
|