@openocean.finance/openocean-sdk 1.6.21 → 1.6.22
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/Swap.d.ts +1 -1
- package/lib/swapSdk/Swap.js +48 -40
- package/package.json +1 -1
package/lib/swapSdk/Swap.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class Swap {
|
|
|
21
21
|
_createTransaction(opt: any, wallet: any): Promise<any>;
|
|
22
22
|
sendNearTransaction(): Promise<void>;
|
|
23
23
|
sendCosmosTransaction(): Promise<void>;
|
|
24
|
-
getGasOld(): Promise<number>;
|
|
24
|
+
getGasOld(): Promise<number | undefined>;
|
|
25
25
|
getGasNew(): Promise<number | undefined>;
|
|
26
26
|
sendEthTransactionNew(): Promise<void>;
|
|
27
27
|
sendEthTransaction(): Promise<void>;
|
package/lib/swapSdk/Swap.js
CHANGED
|
@@ -555,10 +555,11 @@ var Swap = /** @class */ (function () {
|
|
|
555
555
|
};
|
|
556
556
|
Swap.prototype.getGasOld = function () {
|
|
557
557
|
return __awaiter(this, void 0, void 0, function () {
|
|
558
|
-
var _a, inToken, inAmount, data, to, gmxFee, value, gas;
|
|
558
|
+
var _a, inToken, inAmount, data, to, gmxFee, value, gas, e_5;
|
|
559
559
|
return __generator(this, function (_b) {
|
|
560
560
|
switch (_b.label) {
|
|
561
561
|
case 0:
|
|
562
|
+
_b.trys.push([0, 2, , 3]);
|
|
562
563
|
_a = this.res, inToken = _a.inToken, inAmount = _a.inAmount, data = _a.data, to = _a.to, gmxFee = _a.gmxFee;
|
|
563
564
|
value = wallet_1.chainsObj.isNativeToken(this.chain.key, inToken.address)
|
|
564
565
|
? inAmount
|
|
@@ -572,13 +573,18 @@ var Swap = /** @class */ (function () {
|
|
|
572
573
|
case 1:
|
|
573
574
|
gas = _b.sent();
|
|
574
575
|
return [2 /*return*/, Math.ceil(gas * 1.25)];
|
|
576
|
+
case 2:
|
|
577
|
+
e_5 = _b.sent();
|
|
578
|
+
this.errorCallback(e_5);
|
|
579
|
+
return [3 /*break*/, 3];
|
|
580
|
+
case 3: return [2 /*return*/];
|
|
575
581
|
}
|
|
576
582
|
});
|
|
577
583
|
});
|
|
578
584
|
};
|
|
579
585
|
Swap.prototype.getGasNew = function () {
|
|
580
586
|
return __awaiter(this, void 0, void 0, function () {
|
|
581
|
-
var _a, inToken, inAmount, outAmount, outToken, data, to, gmxFee, myWallet, contract, invitee, path, amounts, swapAddr, swapExtraData, value, gas,
|
|
587
|
+
var _a, inToken, inAmount, outAmount, outToken, data, to, gmxFee, myWallet, contract, invitee, path, amounts, swapAddr, swapExtraData, value, gas, e_6;
|
|
582
588
|
return __generator(this, function (_b) {
|
|
583
589
|
switch (_b.label) {
|
|
584
590
|
case 0:
|
|
@@ -605,8 +611,9 @@ var Swap = /** @class */ (function () {
|
|
|
605
611
|
gas = _b.sent();
|
|
606
612
|
return [2 /*return*/, Math.ceil(gas * 1.5)];
|
|
607
613
|
case 2:
|
|
608
|
-
|
|
609
|
-
|
|
614
|
+
e_6 = _b.sent();
|
|
615
|
+
this.errorCallback(e_6);
|
|
616
|
+
console.log('getGasNew error', e_6);
|
|
610
617
|
return [3 /*break*/, 3];
|
|
611
618
|
case 3: return [2 /*return*/];
|
|
612
619
|
}
|
|
@@ -615,11 +622,10 @@ var Swap = /** @class */ (function () {
|
|
|
615
622
|
};
|
|
616
623
|
Swap.prototype.sendEthTransactionNew = function () {
|
|
617
624
|
return __awaiter(this, void 0, void 0, function () {
|
|
618
|
-
var _a, inToken, inAmount, outAmount, outToken, data, to, ethGasPrice, gasPrice, gmxFee, myWallet, contract, invitee, path, amounts, swapAddr, swapExtraData, swapParams, maxFeePerGas, maxPriorityFeePerGas;
|
|
619
|
-
var _b;
|
|
625
|
+
var _a, inToken, inAmount, outAmount, outToken, data, to, ethGasPrice, gasPrice, gmxFee, myWallet, contract, invitee, path, amounts, swapAddr, swapExtraData, gas, swapParams, maxFeePerGas, maxPriorityFeePerGas;
|
|
620
626
|
var _this = this;
|
|
621
|
-
return __generator(this, function (
|
|
622
|
-
switch (
|
|
627
|
+
return __generator(this, function (_b) {
|
|
628
|
+
switch (_b.label) {
|
|
623
629
|
case 0:
|
|
624
630
|
_a = this.res, inToken = _a.inToken, inAmount = _a.inAmount, outAmount = _a.outAmount, outToken = _a.outToken, data = _a.data, to = _a.to, ethGasPrice = _a.ethGasPrice, gasPrice = _a.gasPrice, gmxFee = _a.gmxFee;
|
|
625
631
|
console.log('sendEthTransactionNew', JSON.stringify(this.res));
|
|
@@ -630,15 +636,17 @@ var Swap = /** @class */ (function () {
|
|
|
630
636
|
amounts = [inAmount, outAmount];
|
|
631
637
|
swapAddr = to;
|
|
632
638
|
swapExtraData = data;
|
|
633
|
-
_b = {
|
|
634
|
-
from: this.wallet.address
|
|
635
|
-
};
|
|
636
639
|
return [4 /*yield*/, this.getGasNew()];
|
|
637
640
|
case 1:
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
641
|
+
gas = _b.sent();
|
|
642
|
+
if (!gas)
|
|
643
|
+
return [2 /*return*/];
|
|
644
|
+
swapParams = {
|
|
645
|
+
from: this.wallet.address,
|
|
646
|
+
gas: gas,
|
|
647
|
+
to: to,
|
|
648
|
+
data: data,
|
|
649
|
+
};
|
|
642
650
|
if (ethGasPrice) {
|
|
643
651
|
maxFeePerGas = ethGasPrice.maxFeePerGas, maxPriorityFeePerGas = ethGasPrice.maxPriorityFeePerGas;
|
|
644
652
|
if (maxFeePerGas && maxPriorityFeePerGas) {
|
|
@@ -675,7 +683,7 @@ var Swap = /** @class */ (function () {
|
|
|
675
683
|
};
|
|
676
684
|
Swap.prototype.sendEthTransaction = function () {
|
|
677
685
|
return __awaiter(this, void 0, void 0, function () {
|
|
678
|
-
var _a, inToken, inAmount, data, to, ethGasPrice, gasPrice, estimatedGas, gmxFee, swapParams, maxFeePerGas, maxPriorityFeePerGas, safeTxHash,
|
|
686
|
+
var _a, inToken, inAmount, data, to, ethGasPrice, gasPrice, estimatedGas, gmxFee, swapParams, maxFeePerGas, maxPriorityFeePerGas, safeTxHash, e_7, gas, e_8;
|
|
679
687
|
var _this = this;
|
|
680
688
|
return __generator(this, function (_b) {
|
|
681
689
|
switch (_b.label) {
|
|
@@ -722,8 +730,8 @@ var Swap = /** @class */ (function () {
|
|
|
722
730
|
this.getGnosisSafeTransaction(safeTxHash);
|
|
723
731
|
return [3 /*break*/, 4];
|
|
724
732
|
case 3:
|
|
725
|
-
|
|
726
|
-
this.errorCallback((
|
|
733
|
+
e_7 = _b.sent();
|
|
734
|
+
this.errorCallback((e_7 && e_7.message) || e_7);
|
|
727
735
|
return [3 /*break*/, 4];
|
|
728
736
|
case 4: return [2 /*return*/];
|
|
729
737
|
case 5:
|
|
@@ -742,11 +750,11 @@ var Swap = /** @class */ (function () {
|
|
|
742
750
|
swapParams.gas = gas;
|
|
743
751
|
return [3 /*break*/, 9];
|
|
744
752
|
case 8:
|
|
745
|
-
|
|
746
|
-
if (
|
|
747
|
-
|
|
753
|
+
e_8 = _b.sent();
|
|
754
|
+
if (e_8 && e_8.message.indexOf("JSON-RPC error.") != -1) {
|
|
755
|
+
e_8 = JSON.parse(e_8.message.split("JSON-RPC error.")[1]);
|
|
748
756
|
}
|
|
749
|
-
this.errorCallback((
|
|
757
|
+
this.errorCallback((e_8 && e_8.message) || e_8);
|
|
750
758
|
return [3 /*break*/, 9];
|
|
751
759
|
case 9:
|
|
752
760
|
console.log('sendEthTransaction swapParams', JSON.stringify(swapParams));
|
|
@@ -769,7 +777,7 @@ var Swap = /** @class */ (function () {
|
|
|
769
777
|
};
|
|
770
778
|
Swap.prototype.signEthTransactionByLedger = function (swapParams) {
|
|
771
779
|
return __awaiter(this, void 0, void 0, function () {
|
|
772
|
-
var account, myWallet, gasPrice, txParams, serializedTx, signature, signedTx, hash,
|
|
780
|
+
var account, myWallet, gasPrice, txParams, serializedTx, signature, signedTx, hash, e_9;
|
|
773
781
|
var _a;
|
|
774
782
|
return __generator(this, function (_b) {
|
|
775
783
|
switch (_b.label) {
|
|
@@ -813,8 +821,8 @@ var Swap = /** @class */ (function () {
|
|
|
813
821
|
this.transactionHashCallback(hash);
|
|
814
822
|
return [3 /*break*/, 6];
|
|
815
823
|
case 5:
|
|
816
|
-
|
|
817
|
-
this.errorCallback(
|
|
824
|
+
e_9 = _b.sent();
|
|
825
|
+
this.errorCallback(e_9);
|
|
818
826
|
return [3 /*break*/, 6];
|
|
819
827
|
case 6: return [2 /*return*/];
|
|
820
828
|
}
|
|
@@ -853,7 +861,7 @@ var Swap = /** @class */ (function () {
|
|
|
853
861
|
};
|
|
854
862
|
Swap.prototype.sendTronTransaction = function () {
|
|
855
863
|
return __awaiter(this, void 0, void 0, function () {
|
|
856
|
-
var _a, inToken, outToken, inAmount, outAmount, minOutAmount, addresses, calldata, offsets, gasLimitsAndValues, abi, contract, _contract, swapParams,
|
|
864
|
+
var _a, inToken, outToken, inAmount, outAmount, minOutAmount, addresses, calldata, offsets, gasLimitsAndValues, abi, contract, _contract, swapParams, e_10;
|
|
857
865
|
var _this = this;
|
|
858
866
|
return __generator(this, function (_b) {
|
|
859
867
|
switch (_b.label) {
|
|
@@ -938,8 +946,8 @@ var Swap = /** @class */ (function () {
|
|
|
938
946
|
_b.sent();
|
|
939
947
|
return [3 /*break*/, 5];
|
|
940
948
|
case 4:
|
|
941
|
-
|
|
942
|
-
this.errorCallback(
|
|
949
|
+
e_10 = _b.sent();
|
|
950
|
+
this.errorCallback(e_10 || e_10.message);
|
|
943
951
|
return [3 /*break*/, 5];
|
|
944
952
|
case 5: return [2 /*return*/];
|
|
945
953
|
}
|
|
@@ -948,7 +956,7 @@ var Swap = /** @class */ (function () {
|
|
|
948
956
|
};
|
|
949
957
|
Swap.prototype.sendTerraTransaction = function () {
|
|
950
958
|
return __awaiter(this, void 0, void 0, function () {
|
|
951
|
-
var data, address, gasPrices, msg, _a, fee, accountInfo,
|
|
959
|
+
var data, address, gasPrices, msg, _a, fee, accountInfo, e_11;
|
|
952
960
|
var _this = this;
|
|
953
961
|
return __generator(this, function (_b) {
|
|
954
962
|
switch (_b.label) {
|
|
@@ -990,8 +998,8 @@ var Swap = /** @class */ (function () {
|
|
|
990
998
|
});
|
|
991
999
|
return [3 /*break*/, 7];
|
|
992
1000
|
case 6:
|
|
993
|
-
|
|
994
|
-
this.errorCallback(
|
|
1001
|
+
e_11 = _b.sent();
|
|
1002
|
+
this.errorCallback(e_11.message || e_11);
|
|
995
1003
|
return [3 /*break*/, 7];
|
|
996
1004
|
case 7: return [2 /*return*/];
|
|
997
1005
|
}
|
|
@@ -1000,7 +1008,7 @@ var Swap = /** @class */ (function () {
|
|
|
1000
1008
|
};
|
|
1001
1009
|
Swap.prototype.approveOnt = function (transaction, _amount, inToken) {
|
|
1002
1010
|
return __awaiter(this, void 0, void 0, function () {
|
|
1003
|
-
var scriptHash, operation, gasLimit, args, params, result,
|
|
1011
|
+
var scriptHash, operation, gasLimit, args, params, result, e_12;
|
|
1004
1012
|
return __generator(this, function (_a) {
|
|
1005
1013
|
switch (_a.label) {
|
|
1006
1014
|
case 0:
|
|
@@ -1033,10 +1041,10 @@ var Swap = /** @class */ (function () {
|
|
|
1033
1041
|
this.sendOntTransactionSdk(transaction);
|
|
1034
1042
|
return [3 /*break*/, 3];
|
|
1035
1043
|
case 2:
|
|
1036
|
-
|
|
1044
|
+
e_12 = _a.sent();
|
|
1037
1045
|
// tslint:disable-next-line:no-console
|
|
1038
|
-
console.log("onScCall error:",
|
|
1039
|
-
this.errorCallback((
|
|
1046
|
+
console.log("onScCall error:", e_12);
|
|
1047
|
+
this.errorCallback((e_12 && e_12.message) || e_12);
|
|
1040
1048
|
return [3 /*break*/, 3];
|
|
1041
1049
|
case 3: return [2 /*return*/];
|
|
1042
1050
|
}
|
|
@@ -1045,7 +1053,7 @@ var Swap = /** @class */ (function () {
|
|
|
1045
1053
|
};
|
|
1046
1054
|
Swap.prototype.sendOntTransactionSdk = function (transaction) {
|
|
1047
1055
|
return __awaiter(this, void 0, void 0, function () {
|
|
1048
|
-
var scriptHash, operation, gasLimit, args, params, result,
|
|
1056
|
+
var scriptHash, operation, gasLimit, args, params, result, e_13;
|
|
1049
1057
|
return __generator(this, function (_a) {
|
|
1050
1058
|
switch (_a.label) {
|
|
1051
1059
|
case 0:
|
|
@@ -1076,8 +1084,8 @@ var Swap = /** @class */ (function () {
|
|
|
1076
1084
|
}
|
|
1077
1085
|
return [3 /*break*/, 3];
|
|
1078
1086
|
case 2:
|
|
1079
|
-
|
|
1080
|
-
this.errorCallback((
|
|
1087
|
+
e_13 = _a.sent();
|
|
1088
|
+
this.errorCallback((e_13 && e_13.message) || e_13);
|
|
1081
1089
|
return [3 /*break*/, 3];
|
|
1082
1090
|
case 3: return [2 /*return*/];
|
|
1083
1091
|
}
|
|
@@ -1086,7 +1094,7 @@ var Swap = /** @class */ (function () {
|
|
|
1086
1094
|
};
|
|
1087
1095
|
Swap.prototype.getTerraFee = function (address, msg, gasPrices) {
|
|
1088
1096
|
return __awaiter(this, void 0, void 0, function () {
|
|
1089
|
-
var terra, accountInfo, fee,
|
|
1097
|
+
var terra, accountInfo, fee, e_14;
|
|
1090
1098
|
return __generator(this, function (_a) {
|
|
1091
1099
|
switch (_a.label) {
|
|
1092
1100
|
case 0:
|
|
@@ -1116,7 +1124,7 @@ var Swap = /** @class */ (function () {
|
|
|
1116
1124
|
accountInfo: accountInfo,
|
|
1117
1125
|
}];
|
|
1118
1126
|
case 3:
|
|
1119
|
-
|
|
1127
|
+
e_14 = _a.sent();
|
|
1120
1128
|
return [2 /*return*/, null];
|
|
1121
1129
|
case 4: return [2 /*return*/];
|
|
1122
1130
|
}
|