@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.
Files changed (2) hide show
  1. package/lib/swapSdk/Swap.js +41 -77
  2. package/package.json +1 -1
@@ -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, _a, setupTransaction, swapTransaction, cleanupTransaction, list, recentBlock_1, transactions, i, _i, transactions_1, transaction_1, txid, transaction, signed, signature, result, bytes, _b, msg, data, bytes, e_1;
195
- return __generator(this, function (_c) {
196
- switch (_c.label) {
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
- _c.label = 1;
199
+ _b.label = 1;
200
200
  case 1:
201
- _c.trys.push([1, 19, , 20]);
202
- if (!(res.dex == "jupiter")) return [3 /*break*/, 11];
203
- _a = JSON.parse(res.transaction), setupTransaction = _a.setupTransaction, swapTransaction = _a.swapTransaction, cleanupTransaction = _a.cleanupTransaction;
204
- list = [
205
- setupTransaction,
206
- swapTransaction,
207
- cleanupTransaction,
208
- ].filter(Boolean);
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*/, 13];
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 12:
253
- result = _c.sent();
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*/, 17];
260
- case 13:
261
- if (!this.wallet.sdk.isSlopeWallet) return [3 /*break*/, 15];
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 14:
264
- _b = _c.sent(), msg = _b.msg, data = _b.data;
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*/, 17];
272
- case 15: return [4 /*yield*/, this.wallet.sdk.signTransaction(transaction)];
273
- case 16:
274
- signed = _c.sent();
275
- _c.label = 17;
276
- case 17: return [4 /*yield*/, this.wallet.connection.sendRawTransaction(signed.serialize({
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 18:
284
- signature = _c.sent();
247
+ case 8:
248
+ signature = _b.sent();
285
249
  // this.receiptCallback(signature)
286
250
  this.transactionHashCallback(signature);
287
- return [3 /*break*/, 20];
288
- case 19:
289
- e_1 = _c.sent();
251
+ return [3 /*break*/, 10];
252
+ case 9:
253
+ e_1 = _b.sent();
290
254
  this.errorCallback(e_1.message);
291
- return [3 /*break*/, 20];
292
- case 20: return [2 /*return*/];
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, transaction_2, hash, error_2;
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
- transaction_2 = { hash: "" };
441
+ transaction_1 = { hash: "" };
478
442
  if (txResult && txResult.length === 1) {
479
- transaction_2 = txResult[txResult.length - 1].transaction || {};
443
+ transaction_1 = txResult[txResult.length - 1].transaction || {};
480
444
  }
481
445
  else if (txResult && txResult.length > 1) {
482
- transaction_2 = txResult.filter(function (item) {
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 (transaction_2 && transaction_2.length) {
492
- transaction_2 = transaction_2[0].transaction;
455
+ if (transaction_1 && transaction_1.length) {
456
+ transaction_1 = transaction_1[0].transaction;
493
457
  }
494
458
  }
495
- console.log('signAndSendTransactions', transaction_2);
496
- hash = transaction_2.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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/openocean-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Openocean sdk",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {