@gearbox-protocol/sdk 1.20.2 → 1.20.3
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 -6
- package/lib/core/trade.js +0 -10
- package/lib/core/wcOperation/abstractOperations.d.ts +23 -0
- package/lib/core/wcOperation/abstractOperations.js +39 -0
- package/lib/core/wcOperation/index.d.ts +11 -0
- package/lib/core/wcOperation/index.js +30 -0
- package/lib/core/wcOperation/operations.d.ts +88 -0
- package/lib/core/wcOperation/operations.js +146 -0
- package/lib/core/wcOperation/types.d.ts +15 -0
- package/lib/core/wcOperation/types.js +2 -0
- package/lib/parsers/abstractParser.d.ts +1 -1
- package/package.json +1 -1
- package/lib/core/wcOperation.d.ts +0 -54
- package/lib/core/wcOperation.js +0 -76
package/lib/core/trade.d.ts
CHANGED
|
@@ -15,13 +15,13 @@ interface BaseTradeInterface {
|
|
|
15
15
|
export interface TradeProps extends BaseTradeInterface {
|
|
16
16
|
adapter: BaseAdapter;
|
|
17
17
|
tradePath: PathFinderResult;
|
|
18
|
-
creditFacade:
|
|
18
|
+
creditFacade: string;
|
|
19
19
|
}
|
|
20
20
|
export declare type TradeOperations = "farmWithdraw" | "farmDeposit" | "swap" | "unknownOperation";
|
|
21
21
|
export declare class Trade implements BaseTradeInterface {
|
|
22
22
|
protected helper: BaseAdapter;
|
|
23
23
|
protected tradePath: PathFinderResult;
|
|
24
|
-
protected creditFacade:
|
|
24
|
+
protected creditFacade: string;
|
|
25
25
|
readonly swapType: SwapOperation;
|
|
26
26
|
readonly sourceAmount: BigNumber;
|
|
27
27
|
readonly expectedAmount: BigNumber;
|
|
@@ -36,11 +36,9 @@ export declare class Trade implements BaseTradeInterface {
|
|
|
36
36
|
getAdapterAddress(): string;
|
|
37
37
|
execute(signer: Signer): Promise<EVMTx>;
|
|
38
38
|
toString(): string;
|
|
39
|
-
getFromAmount(slippage: number): BigNumber;
|
|
40
|
-
getToAmount(slippage: number): BigNumber;
|
|
41
39
|
static getOperationName(tokenInAddress: string, tokenOutAddress: string): TradeOperations;
|
|
42
40
|
static executeMulticallPath(creditFacade: string | ICreditFacade, signer: Signer, calls: Array<MultiCall>): Promise<import("@ethersproject/abstract-provider").TransactionResponse>;
|
|
43
|
-
static executeOnSigner
|
|
44
|
-
static executeOnCreditFacade
|
|
41
|
+
private static executeOnSigner;
|
|
42
|
+
private static executeOnCreditFacade;
|
|
45
43
|
}
|
|
46
44
|
export {};
|
package/lib/core/trade.js
CHANGED
|
@@ -108,16 +108,6 @@ var Trade = /** @class */ (function () {
|
|
|
108
108
|
var decimalsTo = decimals_1.decimals[symbolTo];
|
|
109
109
|
return "".concat(this.operationName, " ").concat((0, formatter_1.formatBN)(this.sourceAmount, decimalsFrom), " ").concat(symbolFrom, " \u21D2 ").concat((0, formatter_1.formatBN)(this.expectedAmount, decimalsTo), " ").concat(symbolTo, " on ").concat(this.helper.name);
|
|
110
110
|
};
|
|
111
|
-
Trade.prototype.getFromAmount = function (slippage) {
|
|
112
|
-
return this.expectedAmount
|
|
113
|
-
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
114
|
-
.div(constants_1.PERCENTAGE_FACTOR + slippage);
|
|
115
|
-
};
|
|
116
|
-
Trade.prototype.getToAmount = function (slippage) {
|
|
117
|
-
return this.expectedAmount
|
|
118
|
-
.mul(constants_1.PERCENTAGE_FACTOR + slippage)
|
|
119
|
-
.div(constants_1.PERCENTAGE_FACTOR);
|
|
120
|
-
};
|
|
121
111
|
Trade.getOperationName = function (tokenInAddress, tokenOutAddress) {
|
|
122
112
|
var tokenInSymbol = token_1.tokenSymbolByAddress[tokenInAddress];
|
|
123
113
|
var tokenOutSymbol = token_1.tokenSymbolByAddress[tokenOutAddress];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TransactionRequest } from "@ethersproject/abstract-provider";
|
|
2
|
+
import { BytesLike } from "ethers";
|
|
3
|
+
import { RawTransaction } from ".";
|
|
4
|
+
export interface BaseWcOperationProps {
|
|
5
|
+
raw: RawTransaction;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class BaseWcOperation {
|
|
8
|
+
readonly id: number;
|
|
9
|
+
raw: RawTransaction;
|
|
10
|
+
abstract readonly kind: string;
|
|
11
|
+
constructor({ raw }: BaseWcOperationProps);
|
|
12
|
+
}
|
|
13
|
+
export interface SupportedWcOperationProps extends BaseWcOperationProps {
|
|
14
|
+
tx: TransactionRequest;
|
|
15
|
+
operation: string;
|
|
16
|
+
calldata: BytesLike;
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class SupportedWcOperation extends BaseWcOperation {
|
|
19
|
+
tx: TransactionRequest;
|
|
20
|
+
operation: string;
|
|
21
|
+
protected calldata: BytesLike;
|
|
22
|
+
constructor(props: SupportedWcOperationProps);
|
|
23
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SupportedWcOperation = exports.BaseWcOperation = void 0;
|
|
19
|
+
var BaseWcOperation = /** @class */ (function () {
|
|
20
|
+
function BaseWcOperation(_a) {
|
|
21
|
+
var raw = _a.raw;
|
|
22
|
+
this.id = raw.id;
|
|
23
|
+
this.raw = raw;
|
|
24
|
+
}
|
|
25
|
+
return BaseWcOperation;
|
|
26
|
+
}());
|
|
27
|
+
exports.BaseWcOperation = BaseWcOperation;
|
|
28
|
+
var SupportedWcOperation = /** @class */ (function (_super) {
|
|
29
|
+
__extends(SupportedWcOperation, _super);
|
|
30
|
+
function SupportedWcOperation(props) {
|
|
31
|
+
var _this = _super.call(this, props) || this;
|
|
32
|
+
_this.operation = props.operation;
|
|
33
|
+
_this.tx = props.tx;
|
|
34
|
+
_this.calldata = props.calldata;
|
|
35
|
+
return _this;
|
|
36
|
+
}
|
|
37
|
+
return SupportedWcOperation;
|
|
38
|
+
}(BaseWcOperation));
|
|
39
|
+
exports.SupportedWcOperation = SupportedWcOperation;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApproveWCOperation, FailedWCOperation, LpWCOperation, SwapWCOperation } from "./operations";
|
|
2
|
+
export * from "./operations";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export declare type AllWCOperations = FailedWCOperation | ApproveWCOperation | SwapWCOperation | LpWCOperation;
|
|
5
|
+
export declare type SupportedWCOperations = ApproveWCOperation | SwapWCOperation | LpWCOperation;
|
|
6
|
+
export declare class WcOperationCreator {
|
|
7
|
+
static newSwapOperation: typeof SwapWCOperation.create;
|
|
8
|
+
static newLPOperation: typeof LpWCOperation.create;
|
|
9
|
+
static newUnsupportedOperation: typeof FailedWCOperation.create;
|
|
10
|
+
static newApproveOperation: typeof ApproveWCOperation.create;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.WcOperationCreator = void 0;
|
|
18
|
+
var operations_1 = require("./operations");
|
|
19
|
+
__exportStar(require("./operations"), exports);
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
var WcOperationCreator = /** @class */ (function () {
|
|
22
|
+
function WcOperationCreator() {
|
|
23
|
+
}
|
|
24
|
+
WcOperationCreator.newSwapOperation = operations_1.SwapWCOperation.create;
|
|
25
|
+
WcOperationCreator.newLPOperation = operations_1.LpWCOperation.create;
|
|
26
|
+
WcOperationCreator.newUnsupportedOperation = operations_1.FailedWCOperation.create;
|
|
27
|
+
WcOperationCreator.newApproveOperation = operations_1.ApproveWCOperation.create;
|
|
28
|
+
return WcOperationCreator;
|
|
29
|
+
}());
|
|
30
|
+
exports.WcOperationCreator = WcOperationCreator;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { CreditManagerData } from "../creditManager";
|
|
3
|
+
import { BaseWcOperation, BaseWcOperationProps, SupportedWcOperation, SupportedWcOperationProps } from "./abstractOperations";
|
|
4
|
+
import { RawTransaction } from "./types";
|
|
5
|
+
export declare type FailedWCOperationType = "unsupported" | "bad_request" | "unsupported_tokens";
|
|
6
|
+
interface FailedWCOperationProps extends BaseWcOperationProps {
|
|
7
|
+
message: string;
|
|
8
|
+
kind: FailedWCOperationType;
|
|
9
|
+
}
|
|
10
|
+
export declare class FailedWCOperation extends BaseWcOperation {
|
|
11
|
+
kind: FailedWCOperationType;
|
|
12
|
+
message: string;
|
|
13
|
+
constructor({ raw, kind, message }: FailedWCOperationProps);
|
|
14
|
+
static create(props: FailedWCOperationProps): FailedWCOperation;
|
|
15
|
+
}
|
|
16
|
+
declare type ApproveWCOperationType = "approve";
|
|
17
|
+
interface ApproveWcOperationProps extends SupportedWcOperationProps {
|
|
18
|
+
kind: ApproveWCOperationType;
|
|
19
|
+
to: string;
|
|
20
|
+
from: string;
|
|
21
|
+
}
|
|
22
|
+
interface CreateApproveWCOperation {
|
|
23
|
+
to: string;
|
|
24
|
+
args: [string, BigNumber];
|
|
25
|
+
raw: RawTransaction;
|
|
26
|
+
creditManager: CreditManagerData;
|
|
27
|
+
}
|
|
28
|
+
export declare class ApproveWCOperation extends SupportedWcOperation {
|
|
29
|
+
kind: ApproveWCOperationType;
|
|
30
|
+
to: string;
|
|
31
|
+
from: string;
|
|
32
|
+
constructor(props: ApproveWcOperationProps);
|
|
33
|
+
static create({ to: token, args, raw, creditManager, }: CreateApproveWCOperation): FailedWCOperation | ApproveWCOperation;
|
|
34
|
+
}
|
|
35
|
+
declare type SwapWCOperationType = "swap";
|
|
36
|
+
interface SwapWCOperationProps extends SupportedWcOperationProps {
|
|
37
|
+
kind: SwapWCOperationType;
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
amountFrom: BigNumber;
|
|
41
|
+
amountTo: BigNumber;
|
|
42
|
+
}
|
|
43
|
+
interface CreateSwapWCOperationProps {
|
|
44
|
+
adapter: string;
|
|
45
|
+
operation: string;
|
|
46
|
+
from: string;
|
|
47
|
+
to: string;
|
|
48
|
+
amountFrom: BigNumber;
|
|
49
|
+
amountTo: BigNumber;
|
|
50
|
+
raw: RawTransaction;
|
|
51
|
+
}
|
|
52
|
+
export declare class SwapWCOperation extends SupportedWcOperation {
|
|
53
|
+
kind: SwapWCOperationType;
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
amountFrom: BigNumber;
|
|
57
|
+
amountTo: BigNumber;
|
|
58
|
+
constructor(props: SwapWCOperationProps);
|
|
59
|
+
static create(params: CreateSwapWCOperationProps): SwapWCOperation;
|
|
60
|
+
}
|
|
61
|
+
declare type LpWCOperationType = "lp";
|
|
62
|
+
declare type LpType = "withdraw" | "deposit";
|
|
63
|
+
interface LpWCOperationProps extends SupportedWcOperationProps {
|
|
64
|
+
kind: LpWCOperationType;
|
|
65
|
+
from: string;
|
|
66
|
+
amountFrom: BigNumber;
|
|
67
|
+
farm: string;
|
|
68
|
+
lpOperationType: LpType;
|
|
69
|
+
}
|
|
70
|
+
interface CreateLpWCOperation {
|
|
71
|
+
adapter: string;
|
|
72
|
+
operation: string;
|
|
73
|
+
from: string;
|
|
74
|
+
amountFrom: BigNumber;
|
|
75
|
+
farm: string;
|
|
76
|
+
type: LpType;
|
|
77
|
+
raw: RawTransaction;
|
|
78
|
+
}
|
|
79
|
+
export declare class LpWCOperation extends SupportedWcOperation {
|
|
80
|
+
kind: LpWCOperationType;
|
|
81
|
+
from: string;
|
|
82
|
+
amountFrom: BigNumber;
|
|
83
|
+
farm: string;
|
|
84
|
+
lpOperationType: LpType;
|
|
85
|
+
constructor(props: LpWCOperationProps);
|
|
86
|
+
static create(params: CreateLpWCOperation): LpWCOperation;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.LpWCOperation = exports.SwapWCOperation = exports.ApproveWCOperation = exports.FailedWCOperation = void 0;
|
|
19
|
+
var types_1 = require("../../types");
|
|
20
|
+
var abstractOperations_1 = require("./abstractOperations");
|
|
21
|
+
var FailedWCOperation = /** @class */ (function (_super) {
|
|
22
|
+
__extends(FailedWCOperation, _super);
|
|
23
|
+
function FailedWCOperation(_a) {
|
|
24
|
+
var raw = _a.raw, kind = _a.kind, message = _a.message;
|
|
25
|
+
var _this = _super.call(this, { raw: raw }) || this;
|
|
26
|
+
_this.kind = kind;
|
|
27
|
+
_this.message = message;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
FailedWCOperation.create = function (props) {
|
|
31
|
+
return new FailedWCOperation(props);
|
|
32
|
+
};
|
|
33
|
+
return FailedWCOperation;
|
|
34
|
+
}(abstractOperations_1.BaseWcOperation));
|
|
35
|
+
exports.FailedWCOperation = FailedWCOperation;
|
|
36
|
+
var ApproveWCOperation = /** @class */ (function (_super) {
|
|
37
|
+
__extends(ApproveWCOperation, _super);
|
|
38
|
+
function ApproveWCOperation(props) {
|
|
39
|
+
var _this = _super.call(this, props) || this;
|
|
40
|
+
_this.kind = props.kind;
|
|
41
|
+
_this.from = props.from;
|
|
42
|
+
_this.to = props.to;
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
ApproveWCOperation.create = function (_a) {
|
|
46
|
+
var token = _a.to, args = _a.args, raw = _a.raw, creditManager = _a.creditManager;
|
|
47
|
+
try {
|
|
48
|
+
var spender = args[0], amount = args[1];
|
|
49
|
+
var cmi = types_1.ICreditManager__factory.createInterface();
|
|
50
|
+
var cfi = types_1.ICreditFacade__factory.createInterface();
|
|
51
|
+
var target = creditManager.version === 1
|
|
52
|
+
? creditManager.address
|
|
53
|
+
: creditManager.creditFacade;
|
|
54
|
+
var calldata = creditManager.version === 1
|
|
55
|
+
? cmi.encodeFunctionData("approve", [spender, token])
|
|
56
|
+
: cfi.encodeFunctionData("approve", [spender, token, amount]);
|
|
57
|
+
var tx = {
|
|
58
|
+
to: target,
|
|
59
|
+
data: calldata,
|
|
60
|
+
};
|
|
61
|
+
return new ApproveWCOperation({
|
|
62
|
+
raw: raw,
|
|
63
|
+
operation: "approveToken",
|
|
64
|
+
kind: "approve",
|
|
65
|
+
tx: tx,
|
|
66
|
+
calldata: calldata,
|
|
67
|
+
to: target,
|
|
68
|
+
from: spender,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error(e);
|
|
73
|
+
return FailedWCOperation.create({
|
|
74
|
+
raw: raw,
|
|
75
|
+
kind: "bad_request",
|
|
76
|
+
message: "Bad approve inputs",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return ApproveWCOperation;
|
|
81
|
+
}(abstractOperations_1.SupportedWcOperation));
|
|
82
|
+
exports.ApproveWCOperation = ApproveWCOperation;
|
|
83
|
+
var SwapWCOperation = /** @class */ (function (_super) {
|
|
84
|
+
__extends(SwapWCOperation, _super);
|
|
85
|
+
function SwapWCOperation(props) {
|
|
86
|
+
var _this = _super.call(this, props) || this;
|
|
87
|
+
_this.kind = props.kind;
|
|
88
|
+
_this.to = props.to;
|
|
89
|
+
_this.from = props.from;
|
|
90
|
+
_this.amountFrom = props.amountFrom;
|
|
91
|
+
_this.amountTo = props.amountTo;
|
|
92
|
+
return _this;
|
|
93
|
+
}
|
|
94
|
+
SwapWCOperation.create = function (params) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
var calldata = (_b = (_a = params.raw) === null || _a === void 0 ? void 0 : _a.params[0]) === null || _b === void 0 ? void 0 : _b.data;
|
|
97
|
+
return new SwapWCOperation({
|
|
98
|
+
kind: "swap",
|
|
99
|
+
operation: params.operation,
|
|
100
|
+
raw: params.raw,
|
|
101
|
+
calldata: calldata,
|
|
102
|
+
tx: {
|
|
103
|
+
to: params.adapter,
|
|
104
|
+
data: calldata,
|
|
105
|
+
},
|
|
106
|
+
from: params.from,
|
|
107
|
+
to: params.to,
|
|
108
|
+
amountFrom: params.amountFrom,
|
|
109
|
+
amountTo: params.amountTo,
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
return SwapWCOperation;
|
|
113
|
+
}(abstractOperations_1.SupportedWcOperation));
|
|
114
|
+
exports.SwapWCOperation = SwapWCOperation;
|
|
115
|
+
var LpWCOperation = /** @class */ (function (_super) {
|
|
116
|
+
__extends(LpWCOperation, _super);
|
|
117
|
+
function LpWCOperation(props) {
|
|
118
|
+
var _this = _super.call(this, props) || this;
|
|
119
|
+
_this.kind = props.kind;
|
|
120
|
+
_this.from = props.from;
|
|
121
|
+
_this.amountFrom = props.amountFrom;
|
|
122
|
+
_this.farm = props.farm;
|
|
123
|
+
_this.lpOperationType = props.lpOperationType;
|
|
124
|
+
return _this;
|
|
125
|
+
}
|
|
126
|
+
LpWCOperation.create = function (params) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
var calldata = (_b = (_a = params.raw) === null || _a === void 0 ? void 0 : _a.params[0]) === null || _b === void 0 ? void 0 : _b.data;
|
|
129
|
+
return new LpWCOperation({
|
|
130
|
+
kind: "lp",
|
|
131
|
+
operation: params.operation,
|
|
132
|
+
raw: params.raw,
|
|
133
|
+
calldata: calldata,
|
|
134
|
+
tx: {
|
|
135
|
+
to: params.adapter,
|
|
136
|
+
data: calldata,
|
|
137
|
+
},
|
|
138
|
+
from: params.from,
|
|
139
|
+
amountFrom: params.amountFrom,
|
|
140
|
+
farm: params.farm,
|
|
141
|
+
lpOperationType: params.type,
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
return LpWCOperation;
|
|
145
|
+
}(abstractOperations_1.SupportedWcOperation));
|
|
146
|
+
exports.LpWCOperation = LpWCOperation;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TransactionRequest } from "@ethersproject/abstract-provider";
|
|
2
|
+
import { BigNumber } from "ethers";
|
|
3
|
+
import { FunctionFragment } from "ethers/lib/utils";
|
|
4
|
+
export interface RawTransaction {
|
|
5
|
+
id: number;
|
|
6
|
+
method: "eth_sendTransaction";
|
|
7
|
+
params: [TransactionRequest];
|
|
8
|
+
}
|
|
9
|
+
export interface TxInfo {
|
|
10
|
+
from?: string;
|
|
11
|
+
to?: string;
|
|
12
|
+
amountFrom?: BigNumber;
|
|
13
|
+
amountTo?: BigNumber;
|
|
14
|
+
functionFragment: FunctionFragment;
|
|
15
|
+
}
|
|
@@ -10,7 +10,7 @@ export declare class AbstractParser {
|
|
|
10
10
|
protected ifc: utils.Interface;
|
|
11
11
|
adapterName: string;
|
|
12
12
|
constructor(contract: string);
|
|
13
|
-
parseSelector(calldata:
|
|
13
|
+
parseSelector(calldata: BytesLike): ParseSelectorResult;
|
|
14
14
|
decodeFunctionData(functionFragment: FunctionFragment | string, data: BytesLike): Result;
|
|
15
15
|
encodeFunctionResult(functionFragment: FunctionFragment | string, data: Array<any>): string;
|
|
16
16
|
tokenSymbol(address: string): SupportedToken;
|
package/package.json
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { TransactionRequest } from "@ethersproject/abstract-provider";
|
|
2
|
-
import { BigNumber, BytesLike } from "ethers";
|
|
3
|
-
import { FunctionFragment } from "ethers/lib/utils";
|
|
4
|
-
export declare type TxType = "unsupported" | "swap" | "approve" | "lp";
|
|
5
|
-
export declare type LpOperationType = "withdraw" | "deposit";
|
|
6
|
-
export interface RawTransaction {
|
|
7
|
-
id: number;
|
|
8
|
-
method: "eth_sendTransaction";
|
|
9
|
-
params: [TransactionRequest];
|
|
10
|
-
}
|
|
11
|
-
export interface TxInfo {
|
|
12
|
-
from?: string;
|
|
13
|
-
to?: string;
|
|
14
|
-
amountFrom?: BigNumber;
|
|
15
|
-
amountTo?: BigNumber;
|
|
16
|
-
functionFragment: FunctionFragment;
|
|
17
|
-
}
|
|
18
|
-
export declare class WcSwapOperation {
|
|
19
|
-
readonly id: number;
|
|
20
|
-
operation?: string;
|
|
21
|
-
from?: string;
|
|
22
|
-
to?: string;
|
|
23
|
-
amountFrom?: BigNumber;
|
|
24
|
-
amountTo?: BigNumber;
|
|
25
|
-
tx?: TransactionRequest;
|
|
26
|
-
raw: RawTransaction;
|
|
27
|
-
kind: TxType;
|
|
28
|
-
protected calldata?: BytesLike;
|
|
29
|
-
isPending: boolean;
|
|
30
|
-
farm?: string;
|
|
31
|
-
lpOperationType?: LpOperationType;
|
|
32
|
-
static tokens: Record<string, boolean>;
|
|
33
|
-
constructor(raw: RawTransaction, kind: TxType);
|
|
34
|
-
static NewSwapOperation(params: {
|
|
35
|
-
adapter: string;
|
|
36
|
-
operation: string;
|
|
37
|
-
from: string;
|
|
38
|
-
to: string;
|
|
39
|
-
amountFrom: BigNumber;
|
|
40
|
-
amountTo: BigNumber;
|
|
41
|
-
raw: RawTransaction;
|
|
42
|
-
}): WcSwapOperation;
|
|
43
|
-
static NewLPOperation(params: {
|
|
44
|
-
adapter: string;
|
|
45
|
-
operation: string;
|
|
46
|
-
from: string;
|
|
47
|
-
amountFrom: BigNumber;
|
|
48
|
-
farm: string;
|
|
49
|
-
type: LpOperationType;
|
|
50
|
-
raw: RawTransaction;
|
|
51
|
-
}): WcSwapOperation;
|
|
52
|
-
static NewUnsupportedOperation(raw: RawTransaction): WcSwapOperation;
|
|
53
|
-
static NewApproveOperation(creditManager: string, raw: RawTransaction, token: string): WcSwapOperation;
|
|
54
|
-
}
|
package/lib/core/wcOperation.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WcSwapOperation = void 0;
|
|
4
|
-
var types_1 = require("../types");
|
|
5
|
-
var WcSwapOperation = /** @class */ (function () {
|
|
6
|
-
function WcSwapOperation(raw, kind) {
|
|
7
|
-
this.id = raw.id;
|
|
8
|
-
this.raw = raw;
|
|
9
|
-
this.kind = kind;
|
|
10
|
-
this.isPending = false;
|
|
11
|
-
}
|
|
12
|
-
WcSwapOperation.NewSwapOperation = function (params) {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
var newOperation = new WcSwapOperation(params.raw, "swap");
|
|
15
|
-
newOperation.operation = params.operation;
|
|
16
|
-
newOperation.from = params.from;
|
|
17
|
-
newOperation.to = params.to;
|
|
18
|
-
newOperation.amountFrom = params.amountFrom;
|
|
19
|
-
newOperation.amountTo = params.amountTo;
|
|
20
|
-
newOperation.raw = params.raw;
|
|
21
|
-
newOperation.calldata = (_b = (_a = params.raw) === null || _a === void 0 ? void 0 : _a.params[0]) === null || _b === void 0 ? void 0 : _b.data;
|
|
22
|
-
newOperation.tx = {
|
|
23
|
-
to: params.adapter,
|
|
24
|
-
data: newOperation.calldata,
|
|
25
|
-
};
|
|
26
|
-
return newOperation;
|
|
27
|
-
};
|
|
28
|
-
WcSwapOperation.NewLPOperation = function (params) {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
var newOperation = new WcSwapOperation(params.raw, "lp");
|
|
31
|
-
newOperation.operation = params.operation;
|
|
32
|
-
newOperation.from = params.from;
|
|
33
|
-
newOperation.amountFrom = params.amountFrom;
|
|
34
|
-
newOperation.raw = params.raw;
|
|
35
|
-
newOperation.calldata = (_b = (_a = params.raw) === null || _a === void 0 ? void 0 : _a.params[0]) === null || _b === void 0 ? void 0 : _b.data;
|
|
36
|
-
newOperation.farm = params.farm;
|
|
37
|
-
newOperation.tx = {
|
|
38
|
-
to: params.adapter,
|
|
39
|
-
data: newOperation.calldata,
|
|
40
|
-
};
|
|
41
|
-
newOperation.lpOperationType = params.type;
|
|
42
|
-
return newOperation;
|
|
43
|
-
};
|
|
44
|
-
WcSwapOperation.NewUnsupportedOperation = function (raw) {
|
|
45
|
-
return new WcSwapOperation(raw, "unsupported");
|
|
46
|
-
};
|
|
47
|
-
WcSwapOperation.NewApproveOperation = function (creditManager, raw, token) {
|
|
48
|
-
var _a, _b;
|
|
49
|
-
var operation = new WcSwapOperation(raw, "approve");
|
|
50
|
-
operation.to = token;
|
|
51
|
-
operation.calldata = (_a = raw === null || raw === void 0 ? void 0 : raw.params[0]) === null || _a === void 0 ? void 0 : _a.data;
|
|
52
|
-
var tokenI = types_1.IERC20__factory.createInterface();
|
|
53
|
-
try {
|
|
54
|
-
var spender = tokenI.decodeFunctionData("approve", ((_b = raw === null || raw === void 0 ? void 0 : raw.params[0]) === null || _b === void 0 ? void 0 : _b.data) || "")[0];
|
|
55
|
-
var cmi = types_1.ICreditManager__factory.createInterface();
|
|
56
|
-
operation.from = spender;
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
operation.calldata = cmi.encodeFunctionData("approve", [
|
|
59
|
-
spender,
|
|
60
|
-
operation.to,
|
|
61
|
-
]);
|
|
62
|
-
operation.tx = {
|
|
63
|
-
to: creditManager,
|
|
64
|
-
data: operation.calldata,
|
|
65
|
-
};
|
|
66
|
-
return operation;
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
console.error(e);
|
|
70
|
-
return WcSwapOperation.NewUnsupportedOperation(raw);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
WcSwapOperation.tokens = {};
|
|
74
|
-
return WcSwapOperation;
|
|
75
|
-
}());
|
|
76
|
-
exports.WcSwapOperation = WcSwapOperation;
|