@openocean.finance/openocean-sdk 1.2.99 → 1.3.1

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 +42 -77
  2. package/package.json +2 -2
@@ -191,105 +191,70 @@ 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, swapTransactionBuf, 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
+ swapTransactionBuf = Buffer.from(res.transaction, 'base64');
205
+ transaction = web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
206
+ }
207
+ else {
208
+ transaction = web3_js_1.Transaction.from(Buffer.from(res.transaction, "hex"));
209
+ }
245
210
  signed = null;
246
211
  signature = null;
247
- if (!this.wallet.sdk.isCoin98) return [3 /*break*/, 13];
212
+ if (!this.wallet.sdk.isCoin98) return [3 /*break*/, 3];
248
213
  return [4 /*yield*/, this.wallet.sdk.request({
249
214
  method: "sol_sign",
250
215
  params: [transaction],
251
216
  })];
252
- case 12:
253
- result = _c.sent();
217
+ case 2:
218
+ result = _b.sent();
254
219
  console.log("Got signature, submitting transaction");
255
220
  bytes = bs58.decode(result.signature);
256
221
  transaction.signatures[0].signature = bytes;
257
222
  transaction.feePayer = this.wallet.customPublicKey;
258
223
  signed = transaction;
259
- return [3 /*break*/, 17];
260
- case 13:
261
- if (!this.wallet.sdk.isSlopeWallet) return [3 /*break*/, 15];
224
+ return [3 /*break*/, 7];
225
+ case 3:
226
+ if (!this.wallet.sdk.isSlopeWallet) return [3 /*break*/, 5];
262
227
  return [4 /*yield*/, this.wallet.sdk.signTransaction(bs58.encode(transaction.serializeMessage()))];
263
- case 14:
264
- _b = _c.sent(), msg = _b.msg, data = _b.data;
228
+ case 4:
229
+ _a = _b.sent(), msg = _a.msg, data = _a.data;
265
230
  if (msg !== "ok")
266
231
  return [2 /*return*/];
267
232
  bytes = bs58.decode(data.signature);
268
233
  transaction.signatures[0].signature = bytes;
269
234
  transaction.feePayer = this.wallet.customPublicKey;
270
235
  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({
236
+ return [3 /*break*/, 7];
237
+ case 5: return [4 /*yield*/, this.wallet.sdk.signTransaction(transaction)];
238
+ case 6:
239
+ signed = _b.sent();
240
+ _b.label = 7;
241
+ case 7: return [4 /*yield*/, this.wallet.connection.sendRawTransaction(signed.serialize({
277
242
  verifySignatures: false,
278
243
  requireAllSignatures: false
279
244
  }), {
280
245
  skipPreflight: true,
281
246
  preflightCommitment: "confirmed",
282
247
  })];
283
- case 18:
284
- signature = _c.sent();
248
+ case 8:
249
+ signature = _b.sent();
285
250
  // this.receiptCallback(signature)
286
251
  this.transactionHashCallback(signature);
287
- return [3 /*break*/, 20];
288
- case 19:
289
- e_1 = _c.sent();
252
+ return [3 /*break*/, 10];
253
+ case 9:
254
+ e_1 = _b.sent();
290
255
  this.errorCallback(e_1.message);
291
- return [3 /*break*/, 20];
292
- case 20: return [2 /*return*/];
256
+ return [3 /*break*/, 10];
257
+ case 10: return [2 /*return*/];
293
258
  }
294
259
  });
295
260
  });
@@ -408,7 +373,7 @@ var Swap = /** @class */ (function () {
408
373
  };
409
374
  Swap.prototype.sendNearTransaction = function () {
410
375
  return __awaiter(this, void 0, void 0, function () {
411
- var transaction, wallet_2, transactions, currentTransactions, e_3, err, txResult, transaction_2, hash, error_2;
376
+ var transaction, wallet_2, transactions, currentTransactions, e_3, err, txResult, transaction_1, hash, error_2;
412
377
  var _this = this;
413
378
  return __generator(this, function (_a) {
414
379
  switch (_a.label) {
@@ -474,12 +439,12 @@ var Swap = /** @class */ (function () {
474
439
  case 7:
475
440
  txResult = _a.sent();
476
441
  console.log('signAndSendTransactions', txResult);
477
- transaction_2 = { hash: "" };
442
+ transaction_1 = { hash: "" };
478
443
  if (txResult && txResult.length === 1) {
479
- transaction_2 = txResult[txResult.length - 1].transaction || {};
444
+ transaction_1 = txResult[txResult.length - 1].transaction || {};
480
445
  }
481
446
  else if (txResult && txResult.length > 1) {
482
- transaction_2 = txResult.filter(function (item) {
447
+ transaction_1 = txResult.filter(function (item) {
483
448
  var _a = (item && item.transaction || {}).actions, actions = _a === void 0 ? [] : _a;
484
449
  var _actions = actions.filter(function (fc) {
485
450
  var _a = fc.FunctionCall, FunctionCall = _a === void 0 ? {} : _a;
@@ -488,12 +453,12 @@ var Swap = /** @class */ (function () {
488
453
  });
489
454
  return _actions && _actions.length > 0;
490
455
  });
491
- if (transaction_2 && transaction_2.length) {
492
- transaction_2 = transaction_2[0].transaction;
456
+ if (transaction_1 && transaction_1.length) {
457
+ transaction_1 = transaction_1[0].transaction;
493
458
  }
494
459
  }
495
- console.log('signAndSendTransactions', transaction_2);
496
- hash = transaction_2.hash;
460
+ console.log('signAndSendTransactions', transaction_1);
461
+ hash = transaction_1.hash;
497
462
  this.transactionHashCallback(hash);
498
463
  _a.label = 8;
499
464
  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.2.99",
3
+ "version": "1.3.1",
4
4
  "description": "Openocean sdk",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -48,7 +48,7 @@
48
48
  "dependencies": {
49
49
  "@ethersproject/bignumber": "^5.1.1",
50
50
  "@looksrare/sdk": "^0.12.1",
51
- "@openocean.finance/wallet": "^1.5.59",
51
+ "@openocean.finance/wallet": "^1.6.2",
52
52
  "@uniswap/v2-core": "^1.0.1",
53
53
  "@walletconnect/web3-provider": "^1.7.8",
54
54
  "aptos": "^1.3.17",