@openocean.finance/openocean-sdk 1.3.0 → 1.3.2
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/lib/swapSdk/Swap.js +41 -77
- package/package.json +1 -1
package/lib/swapSdk/Swap.js
CHANGED
|
@@ -191,105 +191,69 @@ var Swap = /** @class */ (function () {
|
|
|
191
191
|
};
|
|
192
192
|
Swap.prototype.sendSolanaTransaction = function () {
|
|
193
193
|
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
-
var res,
|
|
195
|
-
return __generator(this, function (
|
|
196
|
-
switch (
|
|
194
|
+
var res, transaction, signed, signature, result, bytes, _a, msg, data, bytes, e_1;
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
197
|
case 0:
|
|
198
198
|
res = this.res;
|
|
199
|
-
|
|
199
|
+
_b.label = 1;
|
|
200
200
|
case 1:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return [4 /*yield*/, this.wallet.connection.getLatestBlockhash()];
|
|
210
|
-
case 2:
|
|
211
|
-
recentBlock_1 = _c.sent();
|
|
212
|
-
transactions = list.map(function (tx) {
|
|
213
|
-
var transaction = web3_js_1.Transaction.from(Buffer.from(tx, "base64"));
|
|
214
|
-
transaction.recentBlockhash = recentBlock_1.blockhash;
|
|
215
|
-
return transaction;
|
|
216
|
-
});
|
|
217
|
-
return [4 /*yield*/, this.wallet.sdk.signAllTransactions(transactions)];
|
|
218
|
-
case 3: return [4 /*yield*/, _c.sent()];
|
|
219
|
-
case 4:
|
|
220
|
-
_c.sent();
|
|
221
|
-
i = 0;
|
|
222
|
-
_i = 0, transactions_1 = transactions;
|
|
223
|
-
_c.label = 5;
|
|
224
|
-
case 5:
|
|
225
|
-
if (!(_i < transactions_1.length)) return [3 /*break*/, 10];
|
|
226
|
-
transaction_1 = transactions_1[_i];
|
|
227
|
-
i++;
|
|
228
|
-
return [4 /*yield*/, this.wallet.connection.sendRawTransaction(transaction_1.serialize({ requireAllSignatures: false }))];
|
|
229
|
-
case 6:
|
|
230
|
-
txid = _c.sent();
|
|
231
|
-
if (!(i < list.length)) return [3 /*break*/, 8];
|
|
232
|
-
return [4 /*yield*/, this.wallet.connection.confirmTransaction(txid)];
|
|
233
|
-
case 7:
|
|
234
|
-
_c.sent();
|
|
235
|
-
return [3 /*break*/, 9];
|
|
236
|
-
case 8:
|
|
237
|
-
this.transactionHashCallback(txid);
|
|
238
|
-
_c.label = 9;
|
|
239
|
-
case 9:
|
|
240
|
-
_i++;
|
|
241
|
-
return [3 /*break*/, 5];
|
|
242
|
-
case 10: return [2 /*return*/];
|
|
243
|
-
case 11:
|
|
244
|
-
transaction = web3_js_1.Transaction.from(Buffer.from(res.transaction, res.dex == "jupiter" ? "base64" : "hex"));
|
|
201
|
+
_b.trys.push([1, 9, , 10]);
|
|
202
|
+
transaction = '';
|
|
203
|
+
if (res.dexId == 6) {
|
|
204
|
+
transaction = web3_js_1.VersionedTransaction.deserialize(Buffer.from(res.transaction, 'hex'));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
transaction = web3_js_1.Transaction.from(Buffer.from(res.transaction, "hex"));
|
|
208
|
+
}
|
|
245
209
|
signed = null;
|
|
246
210
|
signature = null;
|
|
247
|
-
if (!this.wallet.sdk.isCoin98) return [3 /*break*/,
|
|
211
|
+
if (!this.wallet.sdk.isCoin98) return [3 /*break*/, 3];
|
|
248
212
|
return [4 /*yield*/, this.wallet.sdk.request({
|
|
249
213
|
method: "sol_sign",
|
|
250
214
|
params: [transaction],
|
|
251
215
|
})];
|
|
252
|
-
case
|
|
253
|
-
result =
|
|
216
|
+
case 2:
|
|
217
|
+
result = _b.sent();
|
|
254
218
|
console.log("Got signature, submitting transaction");
|
|
255
219
|
bytes = bs58.decode(result.signature);
|
|
256
220
|
transaction.signatures[0].signature = bytes;
|
|
257
221
|
transaction.feePayer = this.wallet.customPublicKey;
|
|
258
222
|
signed = transaction;
|
|
259
|
-
return [3 /*break*/,
|
|
260
|
-
case
|
|
261
|
-
if (!this.wallet.sdk.isSlopeWallet) return [3 /*break*/,
|
|
223
|
+
return [3 /*break*/, 7];
|
|
224
|
+
case 3:
|
|
225
|
+
if (!this.wallet.sdk.isSlopeWallet) return [3 /*break*/, 5];
|
|
262
226
|
return [4 /*yield*/, this.wallet.sdk.signTransaction(bs58.encode(transaction.serializeMessage()))];
|
|
263
|
-
case
|
|
264
|
-
|
|
227
|
+
case 4:
|
|
228
|
+
_a = _b.sent(), msg = _a.msg, data = _a.data;
|
|
265
229
|
if (msg !== "ok")
|
|
266
230
|
return [2 /*return*/];
|
|
267
231
|
bytes = bs58.decode(data.signature);
|
|
268
232
|
transaction.signatures[0].signature = bytes;
|
|
269
233
|
transaction.feePayer = this.wallet.customPublicKey;
|
|
270
234
|
signed = transaction;
|
|
271
|
-
return [3 /*break*/,
|
|
272
|
-
case
|
|
273
|
-
case
|
|
274
|
-
signed =
|
|
275
|
-
|
|
276
|
-
case
|
|
235
|
+
return [3 /*break*/, 7];
|
|
236
|
+
case 5: return [4 /*yield*/, this.wallet.sdk.signTransaction(transaction)];
|
|
237
|
+
case 6:
|
|
238
|
+
signed = _b.sent();
|
|
239
|
+
_b.label = 7;
|
|
240
|
+
case 7: return [4 /*yield*/, this.wallet.connection.sendRawTransaction(signed.serialize({
|
|
277
241
|
verifySignatures: false,
|
|
278
242
|
requireAllSignatures: false
|
|
279
243
|
}), {
|
|
280
244
|
skipPreflight: true,
|
|
281
245
|
preflightCommitment: "confirmed",
|
|
282
246
|
})];
|
|
283
|
-
case
|
|
284
|
-
signature =
|
|
247
|
+
case 8:
|
|
248
|
+
signature = _b.sent();
|
|
285
249
|
// this.receiptCallback(signature)
|
|
286
250
|
this.transactionHashCallback(signature);
|
|
287
|
-
return [3 /*break*/,
|
|
288
|
-
case
|
|
289
|
-
e_1 =
|
|
251
|
+
return [3 /*break*/, 10];
|
|
252
|
+
case 9:
|
|
253
|
+
e_1 = _b.sent();
|
|
290
254
|
this.errorCallback(e_1.message);
|
|
291
|
-
return [3 /*break*/,
|
|
292
|
-
case
|
|
255
|
+
return [3 /*break*/, 10];
|
|
256
|
+
case 10: return [2 /*return*/];
|
|
293
257
|
}
|
|
294
258
|
});
|
|
295
259
|
});
|
|
@@ -408,7 +372,7 @@ var Swap = /** @class */ (function () {
|
|
|
408
372
|
};
|
|
409
373
|
Swap.prototype.sendNearTransaction = function () {
|
|
410
374
|
return __awaiter(this, void 0, void 0, function () {
|
|
411
|
-
var transaction, wallet_2, transactions, currentTransactions, e_3, err, txResult,
|
|
375
|
+
var transaction, wallet_2, transactions, currentTransactions, e_3, err, txResult, transaction_1, hash, error_2;
|
|
412
376
|
var _this = this;
|
|
413
377
|
return __generator(this, function (_a) {
|
|
414
378
|
switch (_a.label) {
|
|
@@ -474,12 +438,12 @@ var Swap = /** @class */ (function () {
|
|
|
474
438
|
case 7:
|
|
475
439
|
txResult = _a.sent();
|
|
476
440
|
console.log('signAndSendTransactions', txResult);
|
|
477
|
-
|
|
441
|
+
transaction_1 = { hash: "" };
|
|
478
442
|
if (txResult && txResult.length === 1) {
|
|
479
|
-
|
|
443
|
+
transaction_1 = txResult[txResult.length - 1].transaction || {};
|
|
480
444
|
}
|
|
481
445
|
else if (txResult && txResult.length > 1) {
|
|
482
|
-
|
|
446
|
+
transaction_1 = txResult.filter(function (item) {
|
|
483
447
|
var _a = (item && item.transaction || {}).actions, actions = _a === void 0 ? [] : _a;
|
|
484
448
|
var _actions = actions.filter(function (fc) {
|
|
485
449
|
var _a = fc.FunctionCall, FunctionCall = _a === void 0 ? {} : _a;
|
|
@@ -488,12 +452,12 @@ var Swap = /** @class */ (function () {
|
|
|
488
452
|
});
|
|
489
453
|
return _actions && _actions.length > 0;
|
|
490
454
|
});
|
|
491
|
-
if (
|
|
492
|
-
|
|
455
|
+
if (transaction_1 && transaction_1.length) {
|
|
456
|
+
transaction_1 = transaction_1[0].transaction;
|
|
493
457
|
}
|
|
494
458
|
}
|
|
495
|
-
console.log('signAndSendTransactions',
|
|
496
|
-
hash =
|
|
459
|
+
console.log('signAndSendTransactions', transaction_1);
|
|
460
|
+
hash = transaction_1.hash;
|
|
497
461
|
this.transactionHashCallback(hash);
|
|
498
462
|
_a.label = 8;
|
|
499
463
|
case 8: return [3 /*break*/, 10];
|