@openocean.finance/openocean-sdk 1.5.0 → 1.5.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.
@@ -193,14 +193,14 @@ var Swap = /** @class */ (function () {
193
193
  Swap.prototype.sendSolanaTransaction = function () {
194
194
  var _a, _b;
195
195
  return __awaiter(this, void 0, void 0, function () {
196
- var res, transaction, signed, result, bytes, _c, msg, data, bytes, serializedTransaction, transactionResponse, txId, e_1;
196
+ var res, transaction, signed, result, bytes, _c, msg, data, bytes, serializedTransaction, blockhashWithExpiryBlockHeight, blockhashInfo, lastValidBlockHeight, transactionResponse, e_1;
197
197
  return __generator(this, function (_d) {
198
198
  switch (_d.label) {
199
199
  case 0:
200
200
  res = this.res;
201
201
  _d.label = 1;
202
202
  case 1:
203
- _d.trys.push([1, 12, , 13]);
203
+ _d.trys.push([1, 13, , 14]);
204
204
  transaction = '';
205
205
  if (res.dexId == 6 || res.dexId == 7) {
206
206
  transaction = web3_js_1.VersionedTransaction.deserialize(Buffer.from(res.transaction, 'hex'));
@@ -243,45 +243,48 @@ var Swap = /** @class */ (function () {
243
243
  verifySignatures: false,
244
244
  requireAllSignatures: false
245
245
  });
246
- if (!(res.dexId == 6)) return [3 /*break*/, 9];
247
- return [4 /*yield*/, (0, solanaTransactionSender_1.transactionSenderAndConfirmationWaiter)({
248
- connection: this.wallet.connection,
249
- // connection,
250
- serializedTransaction: serializedTransaction,
251
- blockhashWithExpiryBlockHeight: {
252
- blockhash: transaction.message.recentBlockhash,
253
- lastValidBlockHeight: res.lastValidBlockHeight,
254
- },
255
- })];
256
- case 8:
246
+ blockhashWithExpiryBlockHeight = void 0;
247
+ if (!res.lastValidBlockHeight) return [3 /*break*/, 8];
248
+ blockhashWithExpiryBlockHeight = {
249
+ blockhash: transaction.message.recentBlockhash,
250
+ lastValidBlockHeight: res.lastValidBlockHeight,
251
+ };
252
+ return [3 /*break*/, 11];
253
+ case 8: return [4 /*yield*/, this.wallet.connection.wallet.connection.getRecentBlockhash()];
254
+ case 9:
255
+ blockhashInfo = _d.sent();
256
+ return [4 /*yield*/, this.wallet.connection.getBlockHeight()];
257
+ case 10:
258
+ lastValidBlockHeight = _d.sent();
259
+ blockhashWithExpiryBlockHeight = {
260
+ blockhash: blockhashInfo.blockhash,
261
+ lastValidBlockHeight: lastValidBlockHeight + 150,
262
+ };
263
+ _d.label = 11;
264
+ case 11: return [4 /*yield*/, (0, solanaTransactionSender_1.transactionSenderAndConfirmationWaiter)({
265
+ connection: this.wallet.connection,
266
+ serializedTransaction: serializedTransaction,
267
+ blockhashWithExpiryBlockHeight: blockhashWithExpiryBlockHeight
268
+ })];
269
+ case 12:
257
270
  transactionResponse = _d.sent();
258
271
  if (transactionResponse && transactionResponse.response) {
259
272
  if ((_a = transactionResponse.response.meta) === null || _a === void 0 ? void 0 : _a.err) {
260
273
  this.errorCallback((_b = transactionResponse.response.meta) === null || _b === void 0 ? void 0 : _b.err);
261
274
  }
262
275
  else {
263
- this.transactionHashCallback(transactionResponse.txId);
276
+ this.transactionHashCallback(transactionResponse.txid);
264
277
  }
265
278
  }
266
279
  else {
267
280
  this.errorCallback('Transaction not confirmed.');
268
281
  }
269
- return [3 /*break*/, 11];
270
- case 9: return [4 /*yield*/, this.wallet.connection.sendRawTransaction(serializedTransaction, {
271
- skipPreflight: true,
272
- preflightCommitment: "confirmed",
273
- })];
274
- case 10:
275
- txId = _d.sent();
276
- // this.receiptCallback(signature)
277
- this.transactionHashCallback(txId);
278
- _d.label = 11;
279
- case 11: return [3 /*break*/, 13];
280
- case 12:
282
+ return [3 /*break*/, 14];
283
+ case 13:
281
284
  e_1 = _d.sent();
282
285
  this.errorCallback(e_1.message);
283
- return [3 /*break*/, 13];
284
- case 13: return [2 /*return*/];
286
+ return [3 /*break*/, 14];
287
+ case 14: return [2 /*return*/];
285
288
  }
286
289
  });
287
290
  });
@@ -3,7 +3,7 @@ import { BlockhashWithExpiryBlockHeight, Connection } from "@solana/web3.js";
3
3
  type TransactionSenderAndConfirmationWaiterArgs = {
4
4
  connection: Connection;
5
5
  serializedTransaction: Buffer;
6
- blockhashWithExpiryBlockHeight: BlockhashWithExpiryBlockHeight;
6
+ blockhashWithExpiryBlockHeight?: BlockhashWithExpiryBlockHeight | any;
7
7
  };
8
8
  export declare function transactionSenderAndConfirmationWaiter({ connection, serializedTransaction, blockhashWithExpiryBlockHeight, }: TransactionSenderAndConfirmationWaiterArgs): Promise<any>;
9
9
  export {};
@@ -59,13 +59,13 @@ var wait = function (time) {
59
59
  function transactionSenderAndConfirmationWaiter(_a) {
60
60
  var connection = _a.connection, serializedTransaction = _a.serializedTransaction, blockhashWithExpiryBlockHeight = _a.blockhashWithExpiryBlockHeight;
61
61
  return __awaiter(this, void 0, void 0, function () {
62
- var txid, controller, abortSignal, abortableResender, lastValidBlockHeight, e_1, response;
62
+ var txid, controller, abortSignal, abortableResender, races, lastValidBlockHeight, e_1, response;
63
63
  var _this = this;
64
64
  return __generator(this, function (_b) {
65
65
  switch (_b.label) {
66
66
  case 0: return [4 /*yield*/, connection.sendRawTransaction(serializedTransaction, {
67
67
  skipPreflight: true,
68
- preflightCommitment: "confirmed",
68
+ // preflightCommitment: "confirmed",
69
69
  })];
70
70
  case 1:
71
71
  txid = _b.sent();
@@ -73,7 +73,7 @@ function transactionSenderAndConfirmationWaiter(_a) {
73
73
  controller = new AbortController();
74
74
  abortSignal = controller.signal;
75
75
  abortableResender = function () { return __awaiter(_this, void 0, void 0, function () {
76
- var e_2;
76
+ var id, e_2;
77
77
  return __generator(this, function (_a) {
78
78
  switch (_a.label) {
79
79
  case 0:
@@ -88,11 +88,12 @@ function transactionSenderAndConfirmationWaiter(_a) {
88
88
  _a.trys.push([2, 4, , 5]);
89
89
  return [4 /*yield*/, connection.sendRawTransaction(serializedTransaction, {
90
90
  skipPreflight: true,
91
- preflightCommitment: "confirmed",
91
+ // preflightCommitment: "confirmed",
92
92
  })];
93
93
  case 3:
94
- _a.sent();
94
+ id = _a.sent();
95
95
  console.log('Resender-------------');
96
+ console.log(id);
96
97
  return [3 /*break*/, 5];
97
98
  case 4:
98
99
  e_2 = _a.sent();
@@ -107,34 +108,37 @@ function transactionSenderAndConfirmationWaiter(_a) {
107
108
  case 2:
108
109
  _b.trys.push([2, 4, 5, 6]);
109
110
  abortableResender();
110
- lastValidBlockHeight = blockhashWithExpiryBlockHeight.lastValidBlockHeight - 150;
111
+ races = [
112
+ new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
113
+ var tx;
114
+ var _a;
115
+ return __generator(this, function (_b) {
116
+ switch (_b.label) {
117
+ case 0:
118
+ if (!!abortSignal.aborted) return [3 /*break*/, 3];
119
+ return [4 /*yield*/, wait(2000)];
120
+ case 1:
121
+ _b.sent();
122
+ return [4 /*yield*/, connection.getSignatureStatus(txid, {
123
+ searchTransactionHistory: false,
124
+ })];
125
+ case 2:
126
+ tx = _b.sent();
127
+ if (((_a = tx === null || tx === void 0 ? void 0 : tx.value) === null || _a === void 0 ? void 0 : _a.confirmationStatus) === "confirmed") {
128
+ resolve(tx);
129
+ }
130
+ return [3 /*break*/, 0];
131
+ case 3: return [2 /*return*/];
132
+ }
133
+ });
134
+ }); }),
135
+ ];
136
+ if (blockhashWithExpiryBlockHeight && blockhashWithExpiryBlockHeight.lastValidBlockHeight) {
137
+ lastValidBlockHeight = blockhashWithExpiryBlockHeight.lastValidBlockHeight - 150;
138
+ races.push(connection.confirmTransaction(__assign(__assign({}, blockhashWithExpiryBlockHeight), { lastValidBlockHeight: lastValidBlockHeight, signature: txid, abortSignal: abortSignal }), "confirmed"));
139
+ }
111
140
  // this would throw TransactionExpiredBlockheightExceededError
112
- return [4 /*yield*/, Promise.race([
113
- connection.confirmTransaction(__assign(__assign({}, blockhashWithExpiryBlockHeight), { lastValidBlockHeight: lastValidBlockHeight, signature: txid, abortSignal: abortSignal }), "confirmed"),
114
- new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
115
- var tx;
116
- var _a;
117
- return __generator(this, function (_b) {
118
- switch (_b.label) {
119
- case 0:
120
- if (!!abortSignal.aborted) return [3 /*break*/, 3];
121
- return [4 /*yield*/, wait(2000)];
122
- case 1:
123
- _b.sent();
124
- return [4 /*yield*/, connection.getSignatureStatus(txid, {
125
- searchTransactionHistory: false,
126
- })];
127
- case 2:
128
- tx = _b.sent();
129
- if (((_a = tx === null || tx === void 0 ? void 0 : tx.value) === null || _a === void 0 ? void 0 : _a.confirmationStatus) === "confirmed") {
130
- resolve(tx);
131
- }
132
- return [3 /*break*/, 0];
133
- case 3: return [2 /*return*/];
134
- }
135
- });
136
- }); }),
137
- ])];
141
+ return [4 /*yield*/, Promise.race(races)];
138
142
  case 3:
139
143
  // this would throw TransactionExpiredBlockheightExceededError
140
144
  _b.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/openocean-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Openocean sdk",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "@ethersproject/bignumber": "^5.1.1",
51
51
  "@looksrare/sdk": "^0.12.1",
52
- "@openocean.finance/wallet": "^1.8.0",
52
+ "@openocean.finance/wallet": "^1.8.2",
53
53
  "@uniswap/v2-core": "^1.0.1",
54
54
  "@walletconnect/web3-provider": "^1.7.8",
55
55
  "aptos": "^1.3.17",