@gearbox-protocol/sdk 1.7.10 → 1.7.11
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/core/trade.d.ts +4 -3
- package/lib/core/trade.js +37 -4
- package/package.json +1 -1
package/lib/core/trade.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
1
|
+
import { BigNumber, Signer } from "ethers";
|
|
2
2
|
import { AdapterInterface } from "../contracts/adapters";
|
|
3
3
|
import { PathFinderResult, SwapOperation } from "../pathfinder/core";
|
|
4
4
|
import { ICreditFacade } from "../types";
|
|
@@ -35,8 +35,9 @@ export declare class Trade implements BaseTradeInterface {
|
|
|
35
35
|
getAdapterInterface(): AdapterInterface;
|
|
36
36
|
getContractAddress(): string;
|
|
37
37
|
getAdapterAddress(): string;
|
|
38
|
-
execute(): Promise<EVMTx>;
|
|
39
|
-
protected
|
|
38
|
+
execute(signer: Signer): Promise<EVMTx>;
|
|
39
|
+
protected _executeOnSigner(call: PathFinderResult["calls"][0], signer: Signer): Promise<TXSwap>;
|
|
40
|
+
protected _executeOnCreditFacade(calls: PathFinderResult["calls"]): Promise<TXSwap>;
|
|
40
41
|
toString(): string;
|
|
41
42
|
getFromAmount(slippage: number): BigNumber;
|
|
42
43
|
getToAmount(slippage: number): BigNumber;
|
package/lib/core/trade.js
CHANGED
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Trade = void 0;
|
|
40
|
+
var txParser_1 = require("../parsers/txParser");
|
|
40
41
|
var decimals_1 = require("../tokens/decimals");
|
|
41
42
|
var token_1 = require("../tokens/token");
|
|
42
43
|
var formatter_1 = require("../utils/formatter");
|
|
@@ -73,15 +74,47 @@ var Trade = /** @class */ (function () {
|
|
|
73
74
|
Trade.prototype.getAdapterAddress = function () {
|
|
74
75
|
return this.helper.adapterAddress;
|
|
75
76
|
};
|
|
76
|
-
Trade.prototype.execute = function () {
|
|
77
|
-
|
|
77
|
+
Trade.prototype.execute = function (signer) {
|
|
78
|
+
if (this.tradePath.calls.length < 1)
|
|
79
|
+
throw new Error("No path to execute");
|
|
80
|
+
return this.tradePath.calls.length === 1
|
|
81
|
+
? this._executeOnSigner(this.tradePath.calls[0], signer)
|
|
82
|
+
: this._executeOnCreditFacade(this.tradePath.calls);
|
|
78
83
|
};
|
|
79
|
-
Trade.prototype.
|
|
84
|
+
Trade.prototype._executeOnSigner = function (call, signer) {
|
|
80
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
86
|
var receipt;
|
|
82
87
|
return __generator(this, function (_a) {
|
|
83
88
|
switch (_a.label) {
|
|
84
|
-
case 0:
|
|
89
|
+
case 0:
|
|
90
|
+
console.log(txParser_1.TxParser.parseMultiCall(this.tradePath.calls));
|
|
91
|
+
return [4 /*yield*/, signer.sendTransaction({
|
|
92
|
+
to: call.target,
|
|
93
|
+
data: call.callData,
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
receipt = _a.sent();
|
|
97
|
+
return [2 /*return*/, new transactions_1.TXSwap({
|
|
98
|
+
txHash: receipt.hash,
|
|
99
|
+
protocol: this.helper.contractAddress,
|
|
100
|
+
operation: OPERATION_NAMES[this.operationName],
|
|
101
|
+
amountFrom: this.sourceAmount,
|
|
102
|
+
amountTo: this.expectedAmount,
|
|
103
|
+
tokenFrom: this.tokenFrom,
|
|
104
|
+
tokenTo: this.tokenTo,
|
|
105
|
+
creditManager: this.helper.creditManager,
|
|
106
|
+
timestamp: 0,
|
|
107
|
+
})];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
Trade.prototype._executeOnCreditFacade = function (calls) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
114
|
+
var receipt;
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
switch (_a.label) {
|
|
117
|
+
case 0: return [4 /*yield*/, this.creditFacade.multicall(calls)];
|
|
85
118
|
case 1:
|
|
86
119
|
receipt = _a.sent();
|
|
87
120
|
return [2 /*return*/, new transactions_1.TXSwap({
|