@gearbox-protocol/sdk 1.3.4 → 1.5.1
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/apy/index.d.ts +1 -0
- package/lib/core/adapter.d.ts +34 -0
- package/lib/core/adapter.js +76 -0
- package/lib/core/assets.d.ts +34 -0
- package/lib/core/assets.js +98 -0
- package/lib/core/constants.d.ts +1 -0
- package/lib/core/constants.js +3 -1
- package/lib/core/creditAccount.d.ts +14 -5
- package/lib/core/creditAccount.js +35 -3
- package/lib/core/creditManager.d.ts +12 -3
- package/lib/core/creditManager.js +34 -36
- package/lib/core/strategy.d.ts +15 -5
- package/lib/core/strategy.js +42 -7
- package/lib/core/trade.d.ts +49 -0
- package/lib/core/trade.js +70 -0
- package/lib/core/wcOperation.d.ts +54 -0
- package/lib/core/wcOperation.js +76 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/parsers/abstractParser.d.ts +18 -0
- package/lib/parsers/abstractParser.js +32 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +9 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +60 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.js +24 -0
- package/lib/parsers/convexBoosterAdapterParser.d.ts +10 -0
- package/lib/parsers/convexBoosterAdapterParser.js +62 -0
- package/lib/parsers/convexBoosterAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/convexBoosterAdapterParser.spec.js +20 -0
- package/lib/parsers/creditFacadeParser.d.ts +9 -0
- package/lib/parsers/creditFacadeParser.js +66 -0
- package/lib/parsers/creditFacadeParser.spec.d.ts +1 -0
- package/lib/parsers/creditFacadeParser.spec.js +27 -0
- package/lib/parsers/curveAdapterParser.d.ts +12 -0
- package/lib/parsers/curveAdapterParser.js +106 -0
- package/lib/parsers/curveAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/curveAdapterParser.spec.js +49 -0
- package/lib/parsers/iParser.d.ts +3 -0
- package/lib/{types/contracts/test/suites/mainnet/IPriceFeedsRegistry.js → parsers/iParser.js} +0 -0
- package/lib/parsers/lidoAdapterParser.d.ts +7 -0
- package/lib/parsers/lidoAdapterParser.js +46 -0
- package/lib/parsers/lidoAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/lidoAdapterParser.spec.js +17 -0
- package/lib/parsers/txParser.d.ts +18 -0
- package/lib/parsers/txParser.js +122 -0
- package/lib/parsers/uniV2AdapterParser.d.ts +8 -0
- package/lib/parsers/uniV2AdapterParser.js +73 -0
- package/lib/parsers/uniV2AdapterParser.spec.d.ts +1 -0
- package/lib/parsers/uniV2AdapterParser.spec.js +48 -0
- package/lib/parsers/uniV3AdapterParser.d.ts +9 -0
- package/lib/parsers/uniV3AdapterParser.js +99 -0
- package/lib/parsers/uniV3AdapterParser.spec.d.ts +1 -0
- package/lib/parsers/uniV3AdapterParser.spec.js +82 -0
- package/lib/parsers/yearnAdapterParser.spec.d.ts +1 -0
- package/lib/parsers/yearnAdapterParser.spec.js +36 -0
- package/lib/parsers/yearnV2AdapterParser.d.ts +7 -0
- package/lib/parsers/yearnV2AdapterParser.js +54 -0
- package/lib/tokens/convex.d.ts +4 -2
- package/lib/tokens/convex.js +10 -1
- package/lib/tokens/decimals.d.ts +2 -0
- package/lib/tokens/decimals.js +62 -0
- package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExtended.d.ts +66 -2
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_2AssetsAdapter.d.ts +620 -0
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_2AssetsAdapter.js +2 -0
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_3AssetsAdapter.d.ts +622 -0
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_3AssetsAdapter.js +2 -0
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_4AssetsAdapter.d.ts +648 -0
- package/lib/types/contracts/interfaces/adapters/curve/ICurveV1_4AssetsAdapter.js +2 -0
- package/lib/types/contracts/interfaces/adapters/curve/index.d.ts +3 -0
- package/lib/types/contracts/interfaces/adapters/index.d.ts +2 -0
- package/lib/types/contracts/interfaces/adapters/yearn/IYearnV2Adapter.d.ts +330 -0
- package/lib/types/contracts/interfaces/adapters/yearn/IYearnV2Adapter.js +2 -0
- package/lib/types/contracts/interfaces/adapters/yearn/index.d.ts +1 -0
- package/lib/types/contracts/interfaces/adapters/yearn/index.js +2 -0
- package/lib/types/contracts/pathfinder/interfaces/IClosePathResolver.d.ts +28 -7
- package/lib/types/contracts/pathfinder/interfaces/IDepositor.sol/IDepositor.d.ts +30 -9
- package/lib/types/contracts/pathfinder/interfaces/IDepositor.sol/IDepositorOptions.d.ts +31 -10
- package/lib/types/contracts/pathfinder/interfaces/ILPWorker.sol/ILPWorker.d.ts +28 -7
- package/lib/types/contracts/pathfinder/interfaces/ILPWorker.sol/ILPWorkerOptions.d.ts +28 -7
- package/lib/types/contracts/pathfinder/interfaces/IPathFinder.d.ts +24 -0
- package/lib/types/contracts/pathfinder/interfaces/IPathFinderComponent.d.ts +50 -0
- package/lib/types/contracts/pathfinder/interfaces/IPathFinderComponent.js +2 -0
- package/lib/types/contracts/pathfinder/interfaces/IPathResolver.d.ts +29 -8
- package/lib/types/contracts/pathfinder/interfaces/ISwapAggregator.d.ts +99 -15
- package/lib/types/contracts/pathfinder/interfaces/ISwapper.d.ts +17 -1
- package/lib/types/contracts/pathfinder/interfaces/IWithdrawer.sol/IWithdrawer.d.ts +53 -9
- package/lib/types/contracts/pathfinder/interfaces/IWithdrawer.sol/IWithdrawerOptions.d.ts +53 -9
- package/lib/types/contracts/pathfinder/interfaces/index.d.ts +1 -0
- package/lib/types/contracts/test/suites/mainnet/ITokenTestSuite.d.ts +110 -18
- package/lib/types/contracts/test/suites/mainnet/SupportedContracts.sol/ISupportedContracts.d.ts +50 -0
- package/lib/types/contracts/test/suites/mainnet/SupportedContracts.sol/ISupportedContracts.js +2 -0
- package/lib/types/contracts/test/suites/mainnet/SupportedContracts.sol/index.d.ts +1 -0
- package/lib/types/contracts/test/suites/mainnet/SupportedContracts.sol/index.js +2 -0
- package/lib/types/contracts/test/suites/mainnet/Tokens.sol/IToken.d.ts +60 -0
- package/lib/types/contracts/test/suites/mainnet/Tokens.sol/IToken.js +2 -0
- package/lib/types/contracts/test/suites/mainnet/Tokens.sol/index.d.ts +1 -0
- package/lib/types/contracts/test/suites/mainnet/Tokens.sol/index.js +2 -0
- package/lib/types/contracts/test/suites/mainnet/index.d.ts +4 -1
- package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExtended__factory.js +62 -0
- package/lib/types/factories/contracts/{test/suites/mainnet/IPriceFeedsRegistry__factory.d.ts → interfaces/adapters/curve/ICurveV1_2AssetsAdapter__factory.d.ts} +4 -4
- package/lib/types/factories/contracts/interfaces/adapters/curve/ICurveV1_2AssetsAdapter__factory.js +1066 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/ICurveV1_3AssetsAdapter__factory.d.ts +32 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/ICurveV1_3AssetsAdapter__factory.js +1066 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/ICurveV1_4AssetsAdapter__factory.d.ts +32 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/ICurveV1_4AssetsAdapter__factory.js +1066 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/index.d.ts +3 -0
- package/lib/types/factories/contracts/interfaces/adapters/curve/index.js +7 -1
- package/lib/types/factories/contracts/interfaces/adapters/index.d.ts +1 -0
- package/lib/types/factories/contracts/interfaces/adapters/index.js +2 -1
- package/lib/types/factories/contracts/interfaces/adapters/yearn/IYearnV2Adapter__factory.d.ts +46 -0
- package/lib/types/factories/contracts/interfaces/adapters/yearn/IYearnV2Adapter__factory.js +487 -0
- package/lib/types/factories/contracts/interfaces/adapters/yearn/index.d.ts +1 -0
- package/lib/types/factories/contracts/interfaces/adapters/yearn/index.js +8 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/IClosePathResolver__factory.d.ts +12 -2
- package/lib/types/factories/contracts/pathfinder/interfaces/IClosePathResolver__factory.js +54 -8
- package/lib/types/factories/contracts/pathfinder/interfaces/IDepositor.sol/IDepositorOptions__factory.js +138 -32
- package/lib/types/factories/contracts/pathfinder/interfaces/IDepositor.sol/IDepositor__factory.js +110 -24
- package/lib/types/factories/contracts/pathfinder/interfaces/ILPWorker.sol/ILPWorkerOptions__factory.js +54 -8
- package/lib/types/factories/contracts/pathfinder/interfaces/ILPWorker.sol/ILPWorker__factory.js +54 -8
- package/lib/types/factories/contracts/pathfinder/interfaces/IPathFinderComponent__factory.d.ts +18 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/IPathFinderComponent__factory.js +48 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/IPathFinder__factory.js +32 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/IPathResolver__factory.d.ts +12 -2
- package/lib/types/factories/contracts/pathfinder/interfaces/IPathResolver__factory.js +82 -16
- package/lib/types/factories/contracts/pathfinder/interfaces/ISwapAggregator__factory.js +877 -56
- package/lib/types/factories/contracts/pathfinder/interfaces/ISwapper__factory.d.ts +12 -2
- package/lib/types/factories/contracts/pathfinder/interfaces/ISwapper__factory.js +26 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/IWithdrawer.sol/IWithdrawerOptions__factory.js +365 -24
- package/lib/types/factories/contracts/pathfinder/interfaces/IWithdrawer.sol/IWithdrawer__factory.js +355 -24
- package/lib/types/factories/contracts/pathfinder/interfaces/index.d.ts +1 -0
- package/lib/types/factories/contracts/pathfinder/interfaces/index.js +3 -1
- package/lib/types/factories/contracts/support/MultiCall.sol/Multicall2__factory.d.ts +1 -1
- package/lib/types/factories/contracts/support/MultiCall.sol/Multicall2__factory.js +1 -1
- package/lib/types/factories/contracts/test/suites/mainnet/ITokenTestSuite__factory.d.ts +2 -12
- package/lib/types/factories/contracts/test/suites/mainnet/ITokenTestSuite__factory.js +140 -12
- package/lib/types/factories/contracts/test/suites/mainnet/SupportedContracts.sol/ISupportedContracts__factory.d.ts +22 -0
- package/lib/types/factories/contracts/test/suites/mainnet/{IPriceFeedsRegistry__factory.js → SupportedContracts.sol/ISupportedContracts__factory.js} +25 -17
- package/lib/types/factories/contracts/test/suites/mainnet/SupportedContracts.sol/index.d.ts +1 -0
- package/lib/types/factories/contracts/test/suites/mainnet/SupportedContracts.sol/index.js +8 -0
- package/lib/types/factories/contracts/test/suites/mainnet/Tokens.sol/IToken__factory.d.ts +22 -0
- package/lib/types/factories/contracts/test/suites/mainnet/Tokens.sol/IToken__factory.js +79 -0
- package/lib/types/factories/contracts/test/suites/mainnet/Tokens.sol/index.d.ts +1 -0
- package/lib/types/factories/contracts/test/suites/mainnet/Tokens.sol/index.js +8 -0
- package/lib/types/factories/contracts/test/suites/mainnet/index.d.ts +2 -1
- package/lib/types/factories/contracts/test/suites/mainnet/index.js +26 -3
- package/lib/types/index.d.ts +14 -2
- package/lib/types/index.js +17 -5
- package/lib/utils/math.d.ts +1 -0
- package/lib/utils/math.js +5 -1
- package/package.json +6 -2
- package/lib/types/contracts/test/suites/mainnet/IPriceFeedsRegistry.d.ts +0 -42
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trade = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var tradeTypes_1 = require("../pathfinder/tradeTypes");
|
|
6
|
+
var formatter_1 = require("../utils/formatter");
|
|
7
|
+
var adapter_1 = require("./adapter");
|
|
8
|
+
var constants_1 = require("./constants");
|
|
9
|
+
var Trade = /** @class */ (function () {
|
|
10
|
+
function Trade(_a) {
|
|
11
|
+
var tradePath = _a.tradePath, adapter = _a.adapter;
|
|
12
|
+
this.helper = adapter;
|
|
13
|
+
this.tradePath = tradePath;
|
|
14
|
+
this.swapType = tradeTypes_1.SwapType.ExactInput;
|
|
15
|
+
this.expectedAmount = ethers_1.BigNumber.from(0);
|
|
16
|
+
this.rate = ethers_1.BigNumber.from(0);
|
|
17
|
+
this.tokenFrom = "";
|
|
18
|
+
this.tokenTo = "";
|
|
19
|
+
this.operationName = "";
|
|
20
|
+
}
|
|
21
|
+
Trade.connect = function (_a) {
|
|
22
|
+
var tradePath = _a.tradePath, adapter = _a.adapter;
|
|
23
|
+
return new Trade({
|
|
24
|
+
tradePath: tradePath,
|
|
25
|
+
adapter: adapter,
|
|
26
|
+
swapType: tradeTypes_1.SwapType.ExactInput,
|
|
27
|
+
expectedAmount: ethers_1.BigNumber.from(0),
|
|
28
|
+
rate: ethers_1.BigNumber.from(0),
|
|
29
|
+
tokenFrom: "",
|
|
30
|
+
tokenTo: "",
|
|
31
|
+
operationName: "",
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Trade.prototype.getName = function () {
|
|
35
|
+
return this.helper.name;
|
|
36
|
+
};
|
|
37
|
+
Trade.prototype.getAdapterInterface = function () {
|
|
38
|
+
return this.helper.adapterInterface;
|
|
39
|
+
};
|
|
40
|
+
Trade.prototype.getContractAddress = function () {
|
|
41
|
+
return this.helper.contractAddress;
|
|
42
|
+
};
|
|
43
|
+
Trade.prototype.getAdapterAddress = function () {
|
|
44
|
+
return this.helper.adapterAddress;
|
|
45
|
+
};
|
|
46
|
+
Trade.prototype.execute = function (slippage, signer) {
|
|
47
|
+
return this.helper.execute({ tradePath: this.tradePath, slippage: slippage, signer: signer });
|
|
48
|
+
};
|
|
49
|
+
Trade.prototype.toString = function (tokenData) {
|
|
50
|
+
var result = this.helper.type === adapter_1.AdapterType.Swap
|
|
51
|
+
? "Swap "
|
|
52
|
+
: "".concat(this.operationName || "Farm", " ");
|
|
53
|
+
var fromToken = tokenData[this.tokenFrom];
|
|
54
|
+
var toToken = tokenData[this.tokenTo];
|
|
55
|
+
result += "".concat((0, formatter_1.formatBN)(this.tradePath.amount, fromToken.decimals), " ").concat(fromToken.symbol, " \u21D2 ").concat((0, formatter_1.formatBN)(this.expectedAmount, toToken.decimals), " ").concat(toToken.symbol, " on ").concat(this.helper.name);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
Trade.prototype.getFromAmount = function (slippage) {
|
|
59
|
+
return this.expectedAmount
|
|
60
|
+
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
61
|
+
.div(constants_1.PERCENTAGE_FACTOR + slippage);
|
|
62
|
+
};
|
|
63
|
+
Trade.prototype.getToAmount = function (slippage) {
|
|
64
|
+
return this.expectedAmount
|
|
65
|
+
.mul(constants_1.PERCENTAGE_FACTOR + slippage)
|
|
66
|
+
.div(constants_1.PERCENTAGE_FACTOR);
|
|
67
|
+
};
|
|
68
|
+
return Trade;
|
|
69
|
+
}());
|
|
70
|
+
exports.Trade = Trade;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 SwapOperation {
|
|
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
|
+
}): SwapOperation;
|
|
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
|
+
}): SwapOperation;
|
|
52
|
+
static NewUnsupportedOperation(raw: RawTransaction): SwapOperation;
|
|
53
|
+
static NewApproveOperation(creditManager: string, raw: RawTransaction, token: string): SwapOperation;
|
|
54
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SwapOperation = void 0;
|
|
4
|
+
var types_1 = require("../types");
|
|
5
|
+
var SwapOperation = /** @class */ (function () {
|
|
6
|
+
function SwapOperation(raw, kind) {
|
|
7
|
+
this.id = raw.id;
|
|
8
|
+
this.raw = raw;
|
|
9
|
+
this.kind = kind;
|
|
10
|
+
this.isPending = false;
|
|
11
|
+
}
|
|
12
|
+
SwapOperation.NewSwapOperation = function (params) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
var newOperation = new SwapOperation(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
|
+
SwapOperation.NewLPOperation = function (params) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
var newOperation = new SwapOperation(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
|
+
SwapOperation.NewUnsupportedOperation = function (raw) {
|
|
45
|
+
return new SwapOperation(raw, "unsupported");
|
|
46
|
+
};
|
|
47
|
+
SwapOperation.NewApproveOperation = function (creditManager, raw, token) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
var operation = new SwapOperation(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 SwapOperation.NewUnsupportedOperation(raw);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
SwapOperation.tokens = {};
|
|
74
|
+
return SwapOperation;
|
|
75
|
+
}());
|
|
76
|
+
exports.SwapOperation = SwapOperation;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./contracts/contracts";
|
|
2
2
|
export * from "./contracts/protocols";
|
|
3
|
+
export * from "./core/adapter";
|
|
4
|
+
export * from "./core/assets";
|
|
3
5
|
export * from "./core/constants";
|
|
4
6
|
export * from "./core/creditAccount";
|
|
5
7
|
export * from "./core/creditManager";
|
|
@@ -11,7 +13,9 @@ export * from "./core/operations";
|
|
|
11
13
|
export * from "./core/pool";
|
|
12
14
|
export * from "./core/strategy";
|
|
13
15
|
export * from "./core/tokenDistributor";
|
|
16
|
+
export * from "./core/trade";
|
|
14
17
|
export * from "./core/transactions";
|
|
18
|
+
export * from "./core/wcOperation";
|
|
15
19
|
export * from "./oracles/oracles";
|
|
16
20
|
export * from "./oracles/priceFeeds";
|
|
17
21
|
export * from "./payload/creditAccount";
|
|
@@ -29,6 +33,7 @@ export * from "./apy";
|
|
|
29
33
|
export { AdapterInterface } from "./contracts/adapters";
|
|
30
34
|
export { getContractName } from "./contracts/contractsRegister";
|
|
31
35
|
export * from "./core/history";
|
|
36
|
+
export * from "./parsers/txParser";
|
|
32
37
|
export * from "./pathfinder/tradeTypes";
|
|
33
38
|
export * from "./strategies/convex";
|
|
34
39
|
export * from "./strategies/creditFacade";
|
|
@@ -40,6 +45,7 @@ export * from "./strategies/yearn";
|
|
|
40
45
|
export * from "./tokens/connectors";
|
|
41
46
|
export * from "./tokens/convex";
|
|
42
47
|
export * from "./tokens/curveLP";
|
|
48
|
+
export * from "./tokens/decimals";
|
|
43
49
|
export * from "./tokens/gear";
|
|
44
50
|
export * from "./tokens/normal";
|
|
45
51
|
export * from "./tokens/token";
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.callRepeater = exports.swapKeyValue = exports.objectEntries = exports.keyToLowercase = exports.getUnderlyingToken = exports.getPoolTokens = exports.TokenType = exports.getContractName = exports.AdapterInterface = void 0;
|
|
18
18
|
__exportStar(require("./contracts/contracts"), exports);
|
|
19
19
|
__exportStar(require("./contracts/protocols"), exports);
|
|
20
|
+
__exportStar(require("./core/adapter"), exports);
|
|
21
|
+
__exportStar(require("./core/assets"), exports);
|
|
20
22
|
__exportStar(require("./core/constants"), exports);
|
|
21
23
|
__exportStar(require("./core/creditAccount"), exports);
|
|
22
24
|
__exportStar(require("./core/creditManager"), exports);
|
|
@@ -28,7 +30,9 @@ __exportStar(require("./core/operations"), exports);
|
|
|
28
30
|
__exportStar(require("./core/pool"), exports);
|
|
29
31
|
__exportStar(require("./core/strategy"), exports);
|
|
30
32
|
__exportStar(require("./core/tokenDistributor"), exports);
|
|
33
|
+
__exportStar(require("./core/trade"), exports);
|
|
31
34
|
__exportStar(require("./core/transactions"), exports);
|
|
35
|
+
__exportStar(require("./core/wcOperation"), exports);
|
|
32
36
|
__exportStar(require("./oracles/oracles"), exports);
|
|
33
37
|
__exportStar(require("./oracles/priceFeeds"), exports);
|
|
34
38
|
__exportStar(require("./payload/creditAccount"), exports);
|
|
@@ -49,6 +53,7 @@ Object.defineProperty(exports, "AdapterInterface", { enumerable: true, get: func
|
|
|
49
53
|
var contractsRegister_1 = require("./contracts/contractsRegister");
|
|
50
54
|
Object.defineProperty(exports, "getContractName", { enumerable: true, get: function () { return contractsRegister_1.getContractName; } });
|
|
51
55
|
__exportStar(require("./core/history"), exports);
|
|
56
|
+
__exportStar(require("./parsers/txParser"), exports);
|
|
52
57
|
__exportStar(require("./pathfinder/tradeTypes"), exports);
|
|
53
58
|
__exportStar(require("./strategies/convex"), exports);
|
|
54
59
|
__exportStar(require("./strategies/creditFacade"), exports);
|
|
@@ -60,6 +65,7 @@ __exportStar(require("./strategies/yearn"), exports);
|
|
|
60
65
|
__exportStar(require("./tokens/connectors"), exports);
|
|
61
66
|
__exportStar(require("./tokens/convex"), exports);
|
|
62
67
|
__exportStar(require("./tokens/curveLP"), exports);
|
|
68
|
+
__exportStar(require("./tokens/decimals"), exports);
|
|
63
69
|
__exportStar(require("./tokens/gear"), exports);
|
|
64
70
|
__exportStar(require("./tokens/normal"), exports);
|
|
65
71
|
__exportStar(require("./tokens/token"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FunctionFragment, Result } from "@ethersproject/abi";
|
|
2
|
+
import { BigNumberish, BytesLike, utils } from "ethers";
|
|
3
|
+
import { SupportedToken } from "../tokens/token";
|
|
4
|
+
interface ParseSelectorResult {
|
|
5
|
+
functionFragment: FunctionFragment;
|
|
6
|
+
functionName: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class AbstractParser {
|
|
9
|
+
readonly contract: string;
|
|
10
|
+
protected ifc: utils.Interface;
|
|
11
|
+
adapterName: string;
|
|
12
|
+
constructor(contract: string);
|
|
13
|
+
parseSelector(calldata: string): ParseSelectorResult;
|
|
14
|
+
decodeFunctionData(functionFragment: FunctionFragment | string, data: BytesLike): Result;
|
|
15
|
+
tokenSymbol(address: string): SupportedToken;
|
|
16
|
+
formatBN(amount: BigNumberish, token: SupportedToken): string;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractParser = void 0;
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var decimals_1 = require("../tokens/decimals");
|
|
6
|
+
var token_1 = require("../tokens/token");
|
|
7
|
+
var formatter_1 = require("../utils/formatter");
|
|
8
|
+
var AbstractParser = /** @class */ (function () {
|
|
9
|
+
function AbstractParser(contract) {
|
|
10
|
+
this.contract = contract;
|
|
11
|
+
this.adapterName = "Contract";
|
|
12
|
+
}
|
|
13
|
+
AbstractParser.prototype.parseSelector = function (calldata) {
|
|
14
|
+
var functionFragment = this.ifc.getFunction(ethers_1.utils.hexDataSlice(calldata, 0, 4));
|
|
15
|
+
var functionName = "".concat(this.adapterName, "[").concat(this.contract, "].").concat(functionFragment.name);
|
|
16
|
+
return { functionFragment: functionFragment, functionName: functionName };
|
|
17
|
+
};
|
|
18
|
+
AbstractParser.prototype.decodeFunctionData = function (functionFragment, data) {
|
|
19
|
+
return this.ifc.decodeFunctionData(functionFragment, data);
|
|
20
|
+
};
|
|
21
|
+
AbstractParser.prototype.tokenSymbol = function (address) {
|
|
22
|
+
var symbol = token_1.tokenSymbolByAddress[address.toLowerCase()];
|
|
23
|
+
if (!symbol)
|
|
24
|
+
throw new Error("Unknown token: ".concat(address));
|
|
25
|
+
return symbol;
|
|
26
|
+
};
|
|
27
|
+
AbstractParser.prototype.formatBN = function (amount, token) {
|
|
28
|
+
return "".concat((0, formatter_1.formatBN)(amount, decimals_1.decimals[token]), " [").concat(ethers_1.BigNumber.from(amount).toString(), "]");
|
|
29
|
+
};
|
|
30
|
+
return AbstractParser;
|
|
31
|
+
}());
|
|
32
|
+
exports.AbstractParser = AbstractParser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
3
|
+
import { AbstractParser } from "./abstractParser";
|
|
4
|
+
import { IParser } from "./iParser";
|
|
5
|
+
export declare class ConvexBaseRewardPoolAdapterParser extends AbstractParser implements IParser {
|
|
6
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
7
|
+
parse(calldata: string): string;
|
|
8
|
+
formatAmount(amount: BigNumberish): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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.ConvexBaseRewardPoolAdapterParser = void 0;
|
|
19
|
+
var contracts_1 = require("../contracts/contracts");
|
|
20
|
+
var types_1 = require("../types");
|
|
21
|
+
var abstractParser_1 = require("./abstractParser");
|
|
22
|
+
var ConvexBaseRewardPoolAdapterParser = /** @class */ (function (_super) {
|
|
23
|
+
__extends(ConvexBaseRewardPoolAdapterParser, _super);
|
|
24
|
+
function ConvexBaseRewardPoolAdapterParser(contract, isContract) {
|
|
25
|
+
var _this = _super.call(this, contract) || this;
|
|
26
|
+
_this.ifc = types_1.IConvexV1BaseRewardPoolAdapter__factory.createInterface();
|
|
27
|
+
if (!isContract)
|
|
28
|
+
_this.adapterName = "ConvexV1BaseRewardPoolAdapter";
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
ConvexBaseRewardPoolAdapterParser.prototype.parse = function (calldata) {
|
|
32
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
33
|
+
switch (functionFragment.name) {
|
|
34
|
+
case "stake":
|
|
35
|
+
case "stakeAll": {
|
|
36
|
+
var amount = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
37
|
+
var amountStr = amount ? "amount: ".concat(this.formatAmount(amount)) : "";
|
|
38
|
+
return "".concat(functionName, "(").concat(amountStr, ")");
|
|
39
|
+
}
|
|
40
|
+
case "withdraw":
|
|
41
|
+
case "withdrawAndUnwrap": {
|
|
42
|
+
var _b = this.decodeFunctionData(functionFragment, calldata), amount = _b[0], claim = _b[1];
|
|
43
|
+
return "".concat(functionName, "(amount: ").concat(this.formatAmount(amount), ", claim: ").concat(claim, ")");
|
|
44
|
+
}
|
|
45
|
+
case "withdrawAll":
|
|
46
|
+
case "withdrawAllAndUnwrap": {
|
|
47
|
+
var claim = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
48
|
+
return "".concat(functionName, "(claim: ").concat(claim, ")");
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
ConvexBaseRewardPoolAdapterParser.prototype.formatAmount = function (amount) {
|
|
55
|
+
return this.formatBN(amount, contracts_1.contractParams[this.contract]
|
|
56
|
+
.stakedToken);
|
|
57
|
+
};
|
|
58
|
+
return ConvexBaseRewardPoolAdapterParser;
|
|
59
|
+
}(abstractParser_1.AbstractParser));
|
|
60
|
+
exports.ConvexBaseRewardPoolAdapterParser = ConvexBaseRewardPoolAdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var chai_1 = require("chai");
|
|
4
|
+
var constants_1 = require("../core/constants");
|
|
5
|
+
var types_1 = require("../types");
|
|
6
|
+
var convexBaseRewardPoolAdapterParser_1 = require("./convexBaseRewardPoolAdapterParser");
|
|
7
|
+
describe("ConvexV1BaseRewardPoolAdapterParser test", function () {
|
|
8
|
+
it("stake / withdraw functions works well", function () {
|
|
9
|
+
var parser = new convexBaseRewardPoolAdapterParser_1.ConvexBaseRewardPoolAdapterParser("CONVEX_FRAX3CRV_POOL", false);
|
|
10
|
+
var ifc = types_1.IConvexV1BaseRewardPoolAdapter__factory.createInterface();
|
|
11
|
+
var parsed = parser.parse(ifc.encodeFunctionData("stake", [constants_1.WAD.mul(199).div(10)]));
|
|
12
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].stake(amount: 19.90 [19900000000000000000])", "Incorrect parse stake");
|
|
13
|
+
parsed = parser.parse(ifc.encodeFunctionData("stakeAll"));
|
|
14
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].stakeAll()", "Incorrect parse stakeAll");
|
|
15
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdraw", [constants_1.WAD.mul(199).div(1000), false]));
|
|
16
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].withdraw(amount: 0.19 [199000000000000000], claim: false)", "Incorrect parse withdraw");
|
|
17
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdrawAndUnwrap", [constants_1.WAD.mul(2).div(1000), true]));
|
|
18
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].withdrawAndUnwrap(amount: 0.002 [2000000000000000], claim: true)", "Incorrect parse withdrawAndUnwrap");
|
|
19
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdrawAll", [false]));
|
|
20
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].withdrawAll(claim: false)", "Incorrect parse withdrawAll");
|
|
21
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdrawAllAndUnwrap", [true]));
|
|
22
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BaseRewardPoolAdapter[CONVEX_FRAX3CRV_POOL].withdrawAllAndUnwrap(claim: true)", "Incorrect parse withdrawAllAndUnwrap");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
3
|
+
import { AbstractParser } from "./abstractParser";
|
|
4
|
+
import { IParser } from "./iParser";
|
|
5
|
+
export declare class ConvexBoosterAdapterParser extends AbstractParser implements IParser {
|
|
6
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
7
|
+
parse(calldata: string): string;
|
|
8
|
+
formatAmount(amount: BigNumberish, pid: number): string;
|
|
9
|
+
formatPid(pid: number): string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.ConvexBoosterAdapterParser = void 0;
|
|
19
|
+
var convex_1 = require("../tokens/convex");
|
|
20
|
+
var types_1 = require("../types");
|
|
21
|
+
var abstractParser_1 = require("./abstractParser");
|
|
22
|
+
var ConvexBoosterAdapterParser = /** @class */ (function (_super) {
|
|
23
|
+
__extends(ConvexBoosterAdapterParser, _super);
|
|
24
|
+
function ConvexBoosterAdapterParser(contract, isContract) {
|
|
25
|
+
var _this = _super.call(this, contract) || this;
|
|
26
|
+
_this.ifc = types_1.IConvexV1BoosterAdapter__factory.createInterface();
|
|
27
|
+
if (!isContract)
|
|
28
|
+
_this.adapterName = "ConvexV1BoosterAdapter";
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
ConvexBoosterAdapterParser.prototype.parse = function (calldata) {
|
|
32
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
33
|
+
switch (functionFragment.name) {
|
|
34
|
+
case "deposit": {
|
|
35
|
+
var _b = this.decodeFunctionData(functionFragment, calldata), pid = _b[0], amount = _b[1], stake = _b[2];
|
|
36
|
+
return "".concat(functionName, "(pid: ").concat(this.formatPid(pid), ", amount: ").concat(this.formatAmount(amount, pid), ", stake: ").concat(stake, ")");
|
|
37
|
+
}
|
|
38
|
+
case "depositAll": {
|
|
39
|
+
var _c = this.decodeFunctionData(functionFragment, calldata), pid = _c[0], stake = _c[1];
|
|
40
|
+
return "".concat(functionName, "(pid: ").concat(this.formatPid(pid), ", stake: ").concat(stake, ")");
|
|
41
|
+
}
|
|
42
|
+
case "withdraw": {
|
|
43
|
+
var _d = this.decodeFunctionData(functionFragment, calldata), pid = _d[0], amount = _d[1];
|
|
44
|
+
return "".concat(functionName, "(pid: ").concat(this.formatPid(pid), ", amount: ").concat(this.formatAmount(amount, pid), ")");
|
|
45
|
+
}
|
|
46
|
+
case "withdrawAll": {
|
|
47
|
+
var pid = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
48
|
+
return "".concat(functionName, "(pid: ").concat(this.formatPid(pid), ")");
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
ConvexBoosterAdapterParser.prototype.formatAmount = function (amount, pid) {
|
|
55
|
+
return this.formatBN(amount, convex_1.convexLpTokenByPid[pid]);
|
|
56
|
+
};
|
|
57
|
+
ConvexBoosterAdapterParser.prototype.formatPid = function (pid) {
|
|
58
|
+
return "".concat(pid, " [").concat(convex_1.convexPoolByPid[pid], "]");
|
|
59
|
+
};
|
|
60
|
+
return ConvexBoosterAdapterParser;
|
|
61
|
+
}(abstractParser_1.AbstractParser));
|
|
62
|
+
exports.ConvexBoosterAdapterParser = ConvexBoosterAdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var chai_1 = require("chai");
|
|
4
|
+
var constants_1 = require("../core/constants");
|
|
5
|
+
var types_1 = require("../types");
|
|
6
|
+
var convexBoosterAdapterParser_1 = require("./convexBoosterAdapterParser");
|
|
7
|
+
describe("ConvexV1BaseRewardPoolAdapterParser test", function () {
|
|
8
|
+
it("stake / withdraw functions works well", function () {
|
|
9
|
+
var parser = new convexBoosterAdapterParser_1.ConvexBoosterAdapterParser("CONVEX_BOOSTER", false);
|
|
10
|
+
var ifc = types_1.IConvexV1BoosterAdapter__factory.createInterface();
|
|
11
|
+
var parsed = parser.parse(ifc.encodeFunctionData("deposit", [9, constants_1.WAD.mul(19999), false]));
|
|
12
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BoosterAdapter[CONVEX_BOOSTER].deposit(pid: 9 [CONVEX_3CRV_POOL], amount: 19.99K [19999000000000000000000], stake: false)", "Incorrect parse deposit");
|
|
13
|
+
parsed = parser.parse(ifc.encodeFunctionData("depositAll", [32, true]));
|
|
14
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BoosterAdapter[CONVEX_BOOSTER].depositAll(pid: 32 [CONVEX_FRAX3CRV_POOL], stake: true)", "Incorrect parse depositAll");
|
|
15
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdraw", [9, constants_1.WAD.mul(555).div(10)]));
|
|
16
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BoosterAdapter[CONVEX_BOOSTER].withdraw(pid: 9 [CONVEX_3CRV_POOL], amount: 55.50 [55500000000000000000])", "Incorrect parse withdraw");
|
|
17
|
+
parsed = parser.parse(ifc.encodeFunctionData("withdrawAll", [32]));
|
|
18
|
+
(0, chai_1.expect)(parsed).to.be.eq("ConvexV1BoosterAdapter[CONVEX_BOOSTER].withdrawAll(pid: 32 [CONVEX_FRAX3CRV_POOL])", "Incorrect parse withdrawAll");
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { SupportedToken } from "../tokens/token";
|
|
3
|
+
import { AbstractParser } from "./abstractParser";
|
|
4
|
+
import { IParser } from "./iParser";
|
|
5
|
+
export declare class CreditFacadeParser extends AbstractParser implements IParser {
|
|
6
|
+
constructor(token: SupportedToken);
|
|
7
|
+
parse(calldata: string): string;
|
|
8
|
+
formatAmount(amount: BigNumberish): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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.CreditFacadeParser = void 0;
|
|
19
|
+
var types_1 = require("../types");
|
|
20
|
+
var abstractParser_1 = require("./abstractParser");
|
|
21
|
+
var CreditFacadeParser = /** @class */ (function (_super) {
|
|
22
|
+
__extends(CreditFacadeParser, _super);
|
|
23
|
+
function CreditFacadeParser(token) {
|
|
24
|
+
var _this = _super.call(this, token) || this;
|
|
25
|
+
_this.ifc = types_1.ICreditFacadeExtended__factory.createInterface();
|
|
26
|
+
_this.adapterName = "CreditFacade";
|
|
27
|
+
return _this;
|
|
28
|
+
}
|
|
29
|
+
CreditFacadeParser.prototype.parse = function (calldata) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
32
|
+
switch (functionFragment.name) {
|
|
33
|
+
case "addCollateral": {
|
|
34
|
+
var _b = this.decodeFunctionData(functionFragment, calldata), onBehalf = _b[0], token = _b[1], amount = _b[2];
|
|
35
|
+
return "".concat(functionName, "(onBehalf: ").concat(onBehalf, ", token: ").concat(this.tokenSymbol(token), ", amount: ").concat(this.formatAmount(amount), ")");
|
|
36
|
+
}
|
|
37
|
+
case "increaseDebt":
|
|
38
|
+
case "decreaseDebt": {
|
|
39
|
+
var amount = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
40
|
+
return "".concat(functionName, "(amount: ").concat(this.formatAmount(amount), ")");
|
|
41
|
+
}
|
|
42
|
+
case "enableToken":
|
|
43
|
+
case "disableToken": {
|
|
44
|
+
var address = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
45
|
+
return "".concat(functionName, "(token: ").concat(this.tokenSymbol(address), ")");
|
|
46
|
+
}
|
|
47
|
+
case "revertIfReceivedLessThan": {
|
|
48
|
+
var balances = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
49
|
+
var balancesStr = balances
|
|
50
|
+
.map(function (b) {
|
|
51
|
+
var symbol = _this.tokenSymbol(b.token);
|
|
52
|
+
return "".concat(symbol, ": ").concat(_this.formatBN(b.balance, symbol));
|
|
53
|
+
})
|
|
54
|
+
.join(", ");
|
|
55
|
+
return "".concat(functionName, "(").concat(balancesStr, ")");
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
CreditFacadeParser.prototype.formatAmount = function (amount) {
|
|
62
|
+
return this.formatBN(amount, this.contract);
|
|
63
|
+
};
|
|
64
|
+
return CreditFacadeParser;
|
|
65
|
+
}(abstractParser_1.AbstractParser));
|
|
66
|
+
exports.CreditFacadeParser = CreditFacadeParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var chai_1 = require("chai");
|
|
4
|
+
var constants_1 = require("../core/constants");
|
|
5
|
+
var token_1 = require("../tokens/token");
|
|
6
|
+
var types_1 = require("../types");
|
|
7
|
+
var creditFacadeParser_1 = require("./creditFacadeParser");
|
|
8
|
+
describe("CreditFacadeParser test", function () {
|
|
9
|
+
it("all functions works well", function () {
|
|
10
|
+
var parser = new creditFacadeParser_1.CreditFacadeParser("DAI");
|
|
11
|
+
var ifc = types_1.ICreditFacadeExtended__factory.createInterface();
|
|
12
|
+
var parsed = parser.parse(ifc.encodeFunctionData("addCollateral", [
|
|
13
|
+
constants_1.DUMB_ADDRESS,
|
|
14
|
+
token_1.tokenDataByNetwork.Mainnet.WBTC,
|
|
15
|
+
constants_1.WAD.mul(444).div(10),
|
|
16
|
+
]));
|
|
17
|
+
(0, chai_1.expect)(parsed).to.be.eq("CreditFacade[DAI].addCollateral(onBehalf: 0xC4375B7De8af5a38a93548eb8453a498222C4fF2, token: WBTC, amount: 44.40 [44400000000000000000])", "Incorrect parse addCollateral");
|
|
18
|
+
parsed = parser.parse(ifc.encodeFunctionData("increaseDebt", [constants_1.WAD.mul(414).div(10)]));
|
|
19
|
+
(0, chai_1.expect)(parsed).to.be.eq("CreditFacade[DAI].increaseDebt(amount: 41.40 [41400000000000000000])", "Incorrect parse increaseDebt");
|
|
20
|
+
parsed = parser.parse(ifc.encodeFunctionData("decreaseDebt", [constants_1.WAD.mul(334).div(10)]));
|
|
21
|
+
(0, chai_1.expect)(parsed).to.be.eq("CreditFacade[DAI].decreaseDebt(amount: 33.40 [33400000000000000000])", "Incorrect parse decreaseDebt");
|
|
22
|
+
parsed = parser.parse(ifc.encodeFunctionData("enableToken", [token_1.tokenDataByNetwork.Mainnet.WETH]));
|
|
23
|
+
(0, chai_1.expect)(parsed).to.be.eq("CreditFacade[DAI].enableToken(token: WETH)", "Incorrect parse enableToken");
|
|
24
|
+
parsed = parser.parse(ifc.encodeFunctionData("disableToken", [token_1.tokenDataByNetwork.Mainnet.LINK]));
|
|
25
|
+
(0, chai_1.expect)(parsed).to.be.eq("CreditFacade[DAI].disableToken(token: LINK)", "Incorrect parse disableToken");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
3
|
+
import { SupportedToken } from "../tokens/token";
|
|
4
|
+
import { AbstractParser } from "./abstractParser";
|
|
5
|
+
import { IParser } from "./iParser";
|
|
6
|
+
export declare class CurveAdapterParser extends AbstractParser implements IParser {
|
|
7
|
+
protected lpToken: SupportedToken;
|
|
8
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
9
|
+
parse(calldata: string): string;
|
|
10
|
+
getTokenByIndex(index: number): SupportedToken;
|
|
11
|
+
convertAmounts(amounts: Array<BigNumberish>): string;
|
|
12
|
+
}
|