@openocean.finance/openocean-sdk 1.2.53 → 1.2.55
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/Approve.js +51 -47
- package/lib/swapSdk/index.js +25 -5
- package/package.json +2 -2
package/lib/swapSdk/Approve.js
CHANGED
|
@@ -57,7 +57,7 @@ var Approve = /** @class */ (function () {
|
|
|
57
57
|
}
|
|
58
58
|
Approve.prototype.send = function (reqApproveVo, address) {
|
|
59
59
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var web3, data, safeTxHash, e_1, hash, e_2, _a, _b, gasAmount, error_1, json;
|
|
60
|
+
var _gasPrice, web3, data, safeTxHash, e_1, hash, e_2, _a, _b, gasAmount, error_1, json;
|
|
61
61
|
var _this = this;
|
|
62
62
|
return __generator(this, function (_c) {
|
|
63
63
|
switch (_c.label) {
|
|
@@ -66,13 +66,17 @@ var Approve = /** @class */ (function () {
|
|
|
66
66
|
this.key = 0;
|
|
67
67
|
this.approveContract = reqApproveVo.approveContract;
|
|
68
68
|
this.tokenAddress = reqApproveVo.tokenAddress;
|
|
69
|
+
return [4 /*yield*/, this.wallet.sdk.eth.getGasPrice()];
|
|
70
|
+
case 1:
|
|
71
|
+
_gasPrice = _c.sent();
|
|
72
|
+
reqApproveVo.gasPrice = (0, bignumber_js_1.default)(_gasPrice).comparedTo(reqApproveVo.gasPrice) > 0 ? _gasPrice : reqApproveVo.gasPrice;
|
|
69
73
|
if (String(reqApproveVo.gasPrice).indexOf('.') > -1 || Number(reqApproveVo.gasPrice) < Math.pow(10, 6)) {
|
|
70
74
|
reqApproveVo.gasPrice = new bignumber_js_1.default(reqApproveVo.gasPrice + '').times(Math.pow(10, 9)).toFixed(0);
|
|
71
75
|
}
|
|
72
76
|
if (reqApproveVo.decimals) {
|
|
73
77
|
reqApproveVo.amount = (0, bignumber_js_1.default)(reqApproveVo.amount).times(Math.pow(10, reqApproveVo.decimals)).toFixed(0);
|
|
74
78
|
}
|
|
75
|
-
if (!(this.wallet.key === "GnosisSafeWallet")) return [3 /*break*/,
|
|
79
|
+
if (!(this.wallet.key === "GnosisSafeWallet")) return [3 /*break*/, 6];
|
|
76
80
|
web3 = new web3_1.default();
|
|
77
81
|
data = web3.eth.abi.encodeFunctionCall({
|
|
78
82
|
inputs: [
|
|
@@ -89,9 +93,9 @@ var Approve = /** @class */ (function () {
|
|
|
89
93
|
type: "function",
|
|
90
94
|
}, [this.approveContract, reqApproveVo.amount]);
|
|
91
95
|
console.log("data", this.approveContract, reqApproveVo.amount, data);
|
|
92
|
-
_c.label =
|
|
93
|
-
case
|
|
94
|
-
_c.trys.push([
|
|
96
|
+
_c.label = 2;
|
|
97
|
+
case 2:
|
|
98
|
+
_c.trys.push([2, 4, , 5]);
|
|
95
99
|
return [4 /*yield*/, this.wallet.sdk.txs.send({
|
|
96
100
|
txs: [
|
|
97
101
|
{
|
|
@@ -101,31 +105,31 @@ var Approve = /** @class */ (function () {
|
|
|
101
105
|
},
|
|
102
106
|
],
|
|
103
107
|
})];
|
|
104
|
-
case
|
|
108
|
+
case 3:
|
|
105
109
|
safeTxHash = (_c.sent()).safeTxHash;
|
|
106
110
|
console.log("safeTxHash", safeTxHash);
|
|
107
111
|
setTimeout(function () {
|
|
108
112
|
console.log("successCallback");
|
|
109
113
|
_this.successCallback(1);
|
|
110
114
|
}, 3000);
|
|
111
|
-
return [3 /*break*/,
|
|
112
|
-
case
|
|
115
|
+
return [3 /*break*/, 5];
|
|
116
|
+
case 4:
|
|
113
117
|
e_1 = _c.sent();
|
|
114
118
|
setTimeout(function () {
|
|
115
119
|
_this.errorCallback(e_1);
|
|
116
120
|
}, 500);
|
|
117
|
-
return [3 /*break*/,
|
|
118
|
-
case
|
|
119
|
-
case 5:
|
|
120
|
-
if (!(this.wallet.key === "LedgerWallet")) return [3 /*break*/, 6];
|
|
121
|
-
this.signEthTransactionByLedger(reqApproveVo, address);
|
|
122
|
-
return [3 /*break*/, 23];
|
|
121
|
+
return [3 /*break*/, 5];
|
|
122
|
+
case 5: return [3 /*break*/, 24];
|
|
123
123
|
case 6:
|
|
124
|
-
if (!(this.wallet.key === "
|
|
125
|
-
this.
|
|
126
|
-
|
|
124
|
+
if (!(this.wallet.key === "LedgerWallet")) return [3 /*break*/, 7];
|
|
125
|
+
this.signEthTransactionByLedger(reqApproveVo, address);
|
|
126
|
+
return [3 /*break*/, 24];
|
|
127
127
|
case 7:
|
|
128
|
-
|
|
128
|
+
if (!(this.wallet.key === "TronLink")) return [3 /*break*/, 15];
|
|
129
|
+
this.approveContract = "TRtQA3D9BFRLFw3rajKBziAof2eAWkAL7B";
|
|
130
|
+
_c.label = 8;
|
|
131
|
+
case 8:
|
|
132
|
+
_c.trys.push([8, 13, , 14]);
|
|
129
133
|
hash = "";
|
|
130
134
|
this.amount = reqApproveVo.amount + "";
|
|
131
135
|
if (!([
|
|
@@ -133,71 +137,71 @@ var Approve = /** @class */ (function () {
|
|
|
133
137
|
"TCFLL5dx5ZJdKnWuesXxi1VPwjLVmWZZy9",
|
|
134
138
|
"TKfjV9RNKJJCqPvBtK8L7Knykh7DNWvnYt",
|
|
135
139
|
"TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR"
|
|
136
|
-
].indexOf(this.tokenAddress) >= 0)) return [3 /*break*/,
|
|
140
|
+
].indexOf(this.tokenAddress) >= 0)) return [3 /*break*/, 10];
|
|
137
141
|
return [4 /*yield*/, this.contract.methods
|
|
138
142
|
.approve(this.approveContract)
|
|
139
143
|
.send({ feeLimit: 100000000 })];
|
|
140
|
-
case 8:
|
|
141
|
-
hash = _c.sent();
|
|
142
|
-
return [3 /*break*/, 11];
|
|
143
144
|
case 9:
|
|
145
|
+
hash = _c.sent();
|
|
146
|
+
return [3 /*break*/, 12];
|
|
147
|
+
case 10:
|
|
144
148
|
console.log('send approve', this.amount);
|
|
145
149
|
return [4 /*yield*/, this.contract.methods
|
|
146
150
|
.approve(this.approveContract, this.amount)
|
|
147
151
|
.send({ feeLimit: 100000000 })];
|
|
148
|
-
case 10:
|
|
149
|
-
hash = _c.sent();
|
|
150
|
-
_c.label = 11;
|
|
151
152
|
case 11:
|
|
153
|
+
hash = _c.sent();
|
|
154
|
+
_c.label = 12;
|
|
155
|
+
case 12:
|
|
152
156
|
console.log('hash', hash);
|
|
153
157
|
this.successCallback(1);
|
|
154
|
-
return [3 /*break*/,
|
|
155
|
-
case
|
|
158
|
+
return [3 /*break*/, 14];
|
|
159
|
+
case 13:
|
|
156
160
|
e_2 = _c.sent();
|
|
157
161
|
this.errorCallback(e_2);
|
|
158
|
-
return [3 /*break*/,
|
|
159
|
-
case
|
|
160
|
-
case
|
|
161
|
-
if (!!reqApproveVo.amount) return [3 /*break*/,
|
|
162
|
+
return [3 /*break*/, 14];
|
|
163
|
+
case 14: return [3 /*break*/, 24];
|
|
164
|
+
case 15:
|
|
165
|
+
if (!!reqApproveVo.amount) return [3 /*break*/, 17];
|
|
162
166
|
_a = reqApproveVo;
|
|
163
167
|
return [4 /*yield*/, this.contract.methods.totalSupply().call()];
|
|
164
|
-
case 15:
|
|
165
|
-
_a.amount = _c.sent();
|
|
166
|
-
_c.label = 16;
|
|
167
168
|
case 16:
|
|
168
|
-
|
|
169
|
+
_a.amount = _c.sent();
|
|
170
|
+
_c.label = 17;
|
|
171
|
+
case 17:
|
|
172
|
+
if (!(this.tokenAddress === "0xfa17b330bcc4e7f3e2456996d89a5a54ab044831")) return [3 /*break*/, 19];
|
|
169
173
|
_b = reqApproveVo;
|
|
170
174
|
return [4 /*yield*/, this.contract.methods
|
|
171
175
|
.balanceOf(this.account)
|
|
172
176
|
.call()];
|
|
173
|
-
case
|
|
177
|
+
case 18:
|
|
174
178
|
_b.amount = _c.sent();
|
|
175
179
|
if (Number(reqApproveVo.amount) == 0) {
|
|
176
180
|
this.errorCallback("Insufficient Balance.");
|
|
177
181
|
return [2 /*return*/];
|
|
178
182
|
}
|
|
179
|
-
_c.label = 18;
|
|
180
|
-
case 18:
|
|
181
|
-
this.amount = reqApproveVo.amount + "";
|
|
182
|
-
gasAmount = "80000";
|
|
183
183
|
_c.label = 19;
|
|
184
184
|
case 19:
|
|
185
|
-
|
|
185
|
+
this.amount = reqApproveVo.amount + "";
|
|
186
|
+
gasAmount = "80000";
|
|
187
|
+
_c.label = 20;
|
|
188
|
+
case 20:
|
|
189
|
+
_c.trys.push([20, 22, , 23]);
|
|
186
190
|
return [4 /*yield*/, this.contract.methods
|
|
187
191
|
.approve(this.approveContract, this.amount)
|
|
188
192
|
.estimateGas({
|
|
189
193
|
from: this.account,
|
|
190
194
|
})];
|
|
191
|
-
case 20:
|
|
192
|
-
gasAmount = _c.sent();
|
|
193
|
-
return [3 /*break*/, 22];
|
|
194
195
|
case 21:
|
|
196
|
+
gasAmount = _c.sent();
|
|
197
|
+
return [3 /*break*/, 23];
|
|
198
|
+
case 22:
|
|
195
199
|
error_1 = _c.sent();
|
|
196
200
|
setTimeout(function () {
|
|
197
201
|
_this.errorCallback(error_1);
|
|
198
202
|
}, 500);
|
|
199
203
|
return [2 /*return*/];
|
|
200
|
-
case
|
|
204
|
+
case 23:
|
|
201
205
|
json = {
|
|
202
206
|
from: address,
|
|
203
207
|
};
|
|
@@ -220,8 +224,8 @@ var Approve = /** @class */ (function () {
|
|
|
220
224
|
_this.receiptCallback(receipt);
|
|
221
225
|
_this.getSuccess(receipt);
|
|
222
226
|
});
|
|
223
|
-
_c.label =
|
|
224
|
-
case
|
|
227
|
+
_c.label = 24;
|
|
228
|
+
case 24: return [2 /*return*/];
|
|
225
229
|
}
|
|
226
230
|
});
|
|
227
231
|
});
|
package/lib/swapSdk/index.js
CHANGED
|
@@ -78,11 +78,31 @@ var SwapSdk = /** @class */ (function () {
|
|
|
78
78
|
};
|
|
79
79
|
SwapSdk.prototype.fastSwap = function (swapData) {
|
|
80
80
|
var _this = this;
|
|
81
|
-
return new Promise(function (resolve, reject) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.
|
|
85
|
-
|
|
81
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
82
|
+
var chainId;
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
if (!(this.chain.compiler == 'EVM')) return [3 /*break*/, 2];
|
|
87
|
+
return [4 /*yield*/, this.wallet.sdk.eth.getChainId()];
|
|
88
|
+
case 1:
|
|
89
|
+
chainId = _a.sent();
|
|
90
|
+
console.log('chainId', chainId, swapData.chainId);
|
|
91
|
+
if (chainId != swapData.chainId || !chainId) {
|
|
92
|
+
reject({
|
|
93
|
+
message: "Please be aware: Your wallet's network is different from OpenOcean's. Switch networks before sending transaction."
|
|
94
|
+
});
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
_a.label = 2;
|
|
98
|
+
case 2:
|
|
99
|
+
this.swap(swapData)
|
|
100
|
+
.on('transactionHash', resolve)
|
|
101
|
+
.on('error', reject);
|
|
102
|
+
return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); });
|
|
86
106
|
};
|
|
87
107
|
SwapSdk.prototype.getGas = function (swapData) {
|
|
88
108
|
var swap = new Swap_1.Swap(swapData, this.wallet, this.chain);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openocean.finance/openocean-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.55",
|
|
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.
|
|
51
|
+
"@openocean.finance/wallet": "^1.5.26",
|
|
52
52
|
"@solana/web3.js": "1.31.0",
|
|
53
53
|
"@uniswap/v2-core": "^1.0.1",
|
|
54
54
|
"@walletconnect/web3-provider": "^1.7.8",
|