@openocean.finance/openocean-sdk 1.7.60 → 1.7.62
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.
|
@@ -37,100 +37,142 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.transactionSenderAndConfirmationWaiter = transactionSenderAndConfirmationWaiter;
|
|
40
|
+
var web3_js_1 = require("@solana/web3.js");
|
|
40
41
|
var sleep = function (time) {
|
|
41
42
|
return new Promise(function (resolve) { return setTimeout(resolve, time); });
|
|
42
43
|
};
|
|
43
|
-
function
|
|
44
|
+
function sendAndConfirm(connection, serializedTransaction, providedBlockhash) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
var
|
|
46
|
+
var current, maxSendAttempts, attempt, signature, confirmation, err_1, nowHeight, _1, backoffMs;
|
|
46
47
|
var _a;
|
|
47
48
|
return __generator(this, function (_b) {
|
|
48
49
|
switch (_b.label) {
|
|
49
50
|
case 0:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})];
|
|
51
|
+
current = providedBlockhash;
|
|
52
|
+
maxSendAttempts = 5;
|
|
53
|
+
attempt = 0;
|
|
54
|
+
_b.label = 1;
|
|
55
55
|
case 1:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
if (!(attempt < maxSendAttempts)) return [3 /*break*/, 14];
|
|
57
|
+
attempt += 1;
|
|
58
|
+
_b.label = 2;
|
|
59
59
|
case 2:
|
|
60
|
-
_b.
|
|
61
|
-
return [
|
|
62
|
-
|
|
63
|
-
})];
|
|
60
|
+
_b.trys.push([2, 7, , 8]);
|
|
61
|
+
if (!!current) return [3 /*break*/, 4];
|
|
62
|
+
return [4 /*yield*/, connection.getLatestBlockhash("confirmed")];
|
|
64
63
|
case 3:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
current = _b.sent();
|
|
65
|
+
_b.label = 4;
|
|
66
|
+
case 4: return [4 /*yield*/, connection.sendRawTransaction(serializedTransaction, {
|
|
67
|
+
skipPreflight: false,
|
|
68
|
+
maxRetries: 0,
|
|
69
|
+
})];
|
|
70
|
+
case 5:
|
|
71
|
+
signature = _b.sent();
|
|
72
|
+
return [4 /*yield*/, connection.confirmTransaction({
|
|
73
|
+
signature: signature,
|
|
74
|
+
blockhash: current.blockhash,
|
|
75
|
+
lastValidBlockHeight: current.lastValidBlockHeight,
|
|
76
|
+
}, "confirmed")];
|
|
77
|
+
case 6:
|
|
78
|
+
confirmation = _b.sent();
|
|
79
|
+
if (!((_a = confirmation === null || confirmation === void 0 ? void 0 : confirmation.value) === null || _a === void 0 ? void 0 : _a.err)) {
|
|
80
|
+
return [2 /*return*/, signature];
|
|
81
|
+
}
|
|
82
|
+
return [3 /*break*/, 8];
|
|
83
|
+
case 7:
|
|
84
|
+
err_1 = _b.sent();
|
|
85
|
+
// If blockhash expired, refresh and retry
|
|
86
|
+
if (err_1 instanceof web3_js_1.TransactionExpiredBlockheightExceededError ||
|
|
87
|
+
/Blockhash.*expired/i.test(String((err_1 === null || err_1 === void 0 ? void 0 : err_1.message) || ""))) {
|
|
88
|
+
current = undefined; // force refresh
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// For other transient errors, keep current blockhash but backoff
|
|
92
|
+
}
|
|
93
|
+
return [3 /*break*/, 8];
|
|
94
|
+
case 8:
|
|
95
|
+
_b.trys.push([8, 11, , 12]);
|
|
96
|
+
if (!current) return [3 /*break*/, 10];
|
|
97
|
+
return [4 /*yield*/, connection.getBlockHeight("confirmed")];
|
|
98
|
+
case 9:
|
|
99
|
+
nowHeight = _b.sent();
|
|
100
|
+
if (nowHeight > current.lastValidBlockHeight) {
|
|
101
|
+
current = undefined; // refresh on next loop
|
|
102
|
+
}
|
|
103
|
+
_b.label = 10;
|
|
104
|
+
case 10: return [3 /*break*/, 12];
|
|
105
|
+
case 11:
|
|
106
|
+
_1 = _b.sent();
|
|
107
|
+
return [3 /*break*/, 12];
|
|
108
|
+
case 12:
|
|
109
|
+
backoffMs = Math.min(5000, 500 * Math.pow(2, attempt - 1));
|
|
110
|
+
return [4 /*yield*/, sleep(backoffMs)];
|
|
111
|
+
case 13:
|
|
112
|
+
_b.sent();
|
|
113
|
+
return [3 /*break*/, 1];
|
|
114
|
+
case 14: return [2 /*return*/, undefined];
|
|
70
115
|
}
|
|
71
116
|
});
|
|
72
117
|
});
|
|
73
118
|
}
|
|
74
|
-
function
|
|
119
|
+
function waitForTransaction(connection, signature) {
|
|
75
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var
|
|
121
|
+
var maxAttempts, i, resp, _2;
|
|
77
122
|
return __generator(this, function (_a) {
|
|
78
123
|
switch (_a.label) {
|
|
79
124
|
case 0:
|
|
80
|
-
|
|
81
|
-
|
|
125
|
+
maxAttempts = 5;
|
|
126
|
+
i = 0;
|
|
82
127
|
_a.label = 1;
|
|
83
128
|
case 1:
|
|
84
|
-
|
|
85
|
-
|
|
129
|
+
if (!(i < maxAttempts)) return [3 /*break*/, 8];
|
|
130
|
+
_a.label = 2;
|
|
131
|
+
case 2:
|
|
132
|
+
_a.trys.push([2, 4, , 5]);
|
|
133
|
+
return [4 /*yield*/, connection.getTransaction(signature, {
|
|
86
134
|
commitment: "confirmed",
|
|
87
135
|
maxSupportedTransactionVersion: 0,
|
|
88
136
|
})];
|
|
89
|
-
case 2:
|
|
90
|
-
response = _a.sent();
|
|
91
|
-
console.log('getTransaction', response);
|
|
92
|
-
if (!!response) return [3 /*break*/, 5];
|
|
93
|
-
return [4 /*yield*/, sleep(3000)];
|
|
94
137
|
case 3:
|
|
138
|
+
resp = _a.sent();
|
|
139
|
+
if (resp)
|
|
140
|
+
return [2 /*return*/, resp];
|
|
141
|
+
return [3 /*break*/, 5];
|
|
142
|
+
case 4:
|
|
143
|
+
_2 = _a.sent();
|
|
144
|
+
return [3 /*break*/, 5];
|
|
145
|
+
case 5: return [4 /*yield*/, sleep(1000 * (i + 1))];
|
|
146
|
+
case 6:
|
|
95
147
|
_a.sent();
|
|
96
|
-
|
|
97
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
98
|
-
case 5: return [2 /*return*/, response];
|
|
99
|
-
case 6: return [3 /*break*/, 10];
|
|
148
|
+
_a.label = 7;
|
|
100
149
|
case 7:
|
|
101
|
-
|
|
102
|
-
return [
|
|
103
|
-
case 8:
|
|
104
|
-
_a.sent();
|
|
105
|
-
return [4 /*yield*/, getTransaction(connection, txid, n++)];
|
|
106
|
-
case 9: return [2 /*return*/, _a.sent()];
|
|
107
|
-
case 10: return [2 /*return*/];
|
|
150
|
+
i += 1;
|
|
151
|
+
return [3 /*break*/, 1];
|
|
152
|
+
case 8: return [2 /*return*/, undefined];
|
|
108
153
|
}
|
|
109
154
|
});
|
|
110
155
|
});
|
|
111
156
|
}
|
|
112
157
|
function transactionSenderAndConfirmationWaiter(_a) {
|
|
113
158
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
114
|
-
var
|
|
159
|
+
var signature, response;
|
|
115
160
|
var connection = _b.connection, serializedTransaction = _b.serializedTransaction;
|
|
116
161
|
return __generator(this, function (_c) {
|
|
117
162
|
switch (_c.label) {
|
|
118
|
-
case 0: return [4 /*yield*/,
|
|
163
|
+
case 0: return [4 /*yield*/, sendAndConfirm(connection, serializedTransaction)];
|
|
119
164
|
case 1:
|
|
120
|
-
|
|
121
|
-
if (!
|
|
122
|
-
throw new Error(
|
|
165
|
+
signature = _c.sent();
|
|
166
|
+
if (!signature) {
|
|
167
|
+
throw new Error("Transaction not confirmed.");
|
|
123
168
|
}
|
|
124
|
-
return [4 /*yield*/,
|
|
169
|
+
return [4 /*yield*/, waitForTransaction(connection, signature)];
|
|
125
170
|
case 2:
|
|
126
|
-
_c.sent();
|
|
127
|
-
return [4 /*yield*/, getTransaction(connection, txid, 0)];
|
|
128
|
-
case 3:
|
|
129
171
|
response = _c.sent();
|
|
130
172
|
if (!response) {
|
|
131
|
-
throw new Error(
|
|
173
|
+
throw new Error("Transaction not confirmed.");
|
|
132
174
|
}
|
|
133
|
-
return [2 /*return*/, { response: response, txid:
|
|
175
|
+
return [2 /*return*/, { response: response, txid: signature }];
|
|
134
176
|
}
|
|
135
177
|
});
|
|
136
178
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openocean.finance/openocean-sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.62",
|
|
4
4
|
"description": "Openocean sdk",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@looksrare/sdk": "^0.12.1",
|
|
29
29
|
"@mysten/sui": "^1.17.0",
|
|
30
30
|
"@ont-dev/ontology-dapi": "^0.7.3",
|
|
31
|
-
"@openocean.finance/wallet": "^1.10.
|
|
31
|
+
"@openocean.finance/wallet": "^1.10.58",
|
|
32
32
|
"@solana/web3.js": "^1.98.0",
|
|
33
33
|
"@terra-money/terra.js": "^3.1.10",
|
|
34
34
|
"@uniswap/v2-core": "^1.0.1",
|