@gearbox-protocol/sdk 1.3.3 → 1.5.0
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/tokens/tokenType.d.ts +10 -9
- package/lib/tokens/tokenType.js +10 -9
- 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,106 @@
|
|
|
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.CurveAdapterParser = void 0;
|
|
19
|
+
var contracts_1 = require("../contracts/contracts");
|
|
20
|
+
var types_1 = require("../types");
|
|
21
|
+
var formatter_1 = require("../utils/formatter");
|
|
22
|
+
var abstractParser_1 = require("./abstractParser");
|
|
23
|
+
var CurveAdapterParser = /** @class */ (function (_super) {
|
|
24
|
+
__extends(CurveAdapterParser, _super);
|
|
25
|
+
function CurveAdapterParser(contract, isContract) {
|
|
26
|
+
var _this = _super.call(this, contract) || this;
|
|
27
|
+
var contractName = "";
|
|
28
|
+
var nCoins = contracts_1.contractParams[contract].tokens.length;
|
|
29
|
+
switch (nCoins) {
|
|
30
|
+
case 2:
|
|
31
|
+
_this.ifc = types_1.ICurveV1_2AssetsAdapter__factory.createInterface();
|
|
32
|
+
contractName = "Curve2AssetsAdapter";
|
|
33
|
+
break;
|
|
34
|
+
case 3:
|
|
35
|
+
_this.ifc = types_1.ICurveV1_3AssetsAdapter__factory.createInterface();
|
|
36
|
+
contractName = "Curve3AssetsAdapter";
|
|
37
|
+
break;
|
|
38
|
+
case 4:
|
|
39
|
+
_this.ifc = types_1.ICurveV1_4AssetsAdapter__factory.createInterface();
|
|
40
|
+
contractName = "Curve4AssetsAdapter";
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("Unsupported curve contract ".concat(contract));
|
|
44
|
+
}
|
|
45
|
+
_this.lpToken = contracts_1.contractParams[contract].lpToken;
|
|
46
|
+
if (!isContract)
|
|
47
|
+
_this.adapterName = contractName;
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
CurveAdapterParser.prototype.parse = function (calldata) {
|
|
51
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
52
|
+
switch (functionFragment.name) {
|
|
53
|
+
case "exchange":
|
|
54
|
+
case "exchange_underlying": {
|
|
55
|
+
var _b = this.decodeFunctionData(functionFragment, calldata), i = _b[0], j = _b[1], dx = _b[2], min_dy = _b[3];
|
|
56
|
+
var iSym = this.getTokenByIndex(i);
|
|
57
|
+
var jSym = this.getTokenByIndex(j);
|
|
58
|
+
return "".concat(functionName, "(i ,j: ").concat(iSym, " => ").concat(jSym, ", dx: ").concat(this.formatBN(dx, iSym), ", min_dy: ").concat(this.formatBN(min_dy, jSym), ")");
|
|
59
|
+
}
|
|
60
|
+
case "exchange_all":
|
|
61
|
+
case "exchange_all_underlying": {
|
|
62
|
+
var _c = this.decodeFunctionData(functionFragment, calldata), i = _c[0], j = _c[1], rateMinRAY = _c[2];
|
|
63
|
+
return "".concat(functionName, "(i: ").concat(this.getTokenByIndex(i), ", j: ").concat(this.getTokenByIndex(j), ", rateMinRAY: ").concat((0, formatter_1.formatBN)(rateMinRAY, 27));
|
|
64
|
+
}
|
|
65
|
+
case "add_liquidity_one_coin": {
|
|
66
|
+
var _d = this.decodeFunctionData(functionFragment, calldata), amount = _d[0], i = _d[1], minAmount = _d[2];
|
|
67
|
+
var iSym = this.getTokenByIndex(i);
|
|
68
|
+
return "".concat(functionName, "(amount: ").concat(this.formatBN(amount, iSym), ", i: ").concat(iSym, ", minAmount: ").concat(this.formatBN(minAmount, this.lpToken), ")");
|
|
69
|
+
}
|
|
70
|
+
case "add_all_liquidity_one_coin":
|
|
71
|
+
case "remove_all_liquidity_one_coin": {
|
|
72
|
+
var _e = this.decodeFunctionData(functionFragment, calldata), i = _e[0], rateMinRAY = _e[1];
|
|
73
|
+
return "".concat(functionName, "(i: ").concat(this.getTokenByIndex(i), ", rateMinRAY: ").concat((0, formatter_1.formatBN)(rateMinRAY, 27), ")");
|
|
74
|
+
}
|
|
75
|
+
case "add_liquidity": {
|
|
76
|
+
var _f = this.decodeFunctionData(functionFragment, calldata), amounts = _f[0], minAmount = _f[1];
|
|
77
|
+
return "".concat(functionName, "(amounts: [").concat(this.convertAmounts(amounts), "], minAmount: ").concat(this.formatBN(minAmount, this.lpToken), ")");
|
|
78
|
+
}
|
|
79
|
+
case "remove_liquidity": {
|
|
80
|
+
var _g = this.decodeFunctionData(functionFragment, calldata), amount = _g[0], min_amounts = _g[1];
|
|
81
|
+
return "".concat(functionName, "(amount: ").concat(this.formatBN(amount, this.lpToken), ", min_amounts: [").concat(this.convertAmounts(min_amounts), "])");
|
|
82
|
+
}
|
|
83
|
+
case "remove_liquidity_imbalance": {
|
|
84
|
+
var _h = this.decodeFunctionData(functionFragment, calldata), amounts = _h[0], maxBurnAmount = _h[1];
|
|
85
|
+
return "".concat(functionName, "(amounts: [").concat(this.convertAmounts(amounts), "], max_burn_amount: ").concat(this.formatBN(maxBurnAmount, this.lpToken), ")");
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
CurveAdapterParser.prototype.getTokenByIndex = function (index) {
|
|
92
|
+
return contracts_1.contractParams[this.contract]
|
|
93
|
+
.tokens[index];
|
|
94
|
+
};
|
|
95
|
+
CurveAdapterParser.prototype.convertAmounts = function (amounts) {
|
|
96
|
+
var _this = this;
|
|
97
|
+
return amounts
|
|
98
|
+
.map(function (a, coin) {
|
|
99
|
+
var sym = _this.getTokenByIndex(coin);
|
|
100
|
+
return "".concat(sym, ": ").concat(_this.formatBN(a, sym));
|
|
101
|
+
})
|
|
102
|
+
.join(", ");
|
|
103
|
+
};
|
|
104
|
+
return CurveAdapterParser;
|
|
105
|
+
}(abstractParser_1.AbstractParser));
|
|
106
|
+
exports.CurveAdapterParser = CurveAdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 curveAdapterParser_1 = require("./curveAdapterParser");
|
|
7
|
+
describe("CurveAdapterParser test", function () {
|
|
8
|
+
it("stake / withdraw functions works well", function () {
|
|
9
|
+
var parser = new curveAdapterParser_1.CurveAdapterParser("CURVE_FRAX_POOL", false);
|
|
10
|
+
var ifc = types_1.ICurveV1_2AssetsAdapter__factory.createInterface();
|
|
11
|
+
var parsed = parser.parse(ifc.encodeFunctionData("exchange", [0, 1, constants_1.WAD.mul(3), constants_1.WAD.mul(32)]));
|
|
12
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].exchange(i ,j: FRAX => 3Crv, dx: 3.00 [3000000000000000000], min_dy: 32.00 [32000000000000000000])", "Curve2AssetsAdapter: Incorrect parse exchange");
|
|
13
|
+
parsed = parser.parse(ifc.encodeFunctionData("exchange_underlying", [
|
|
14
|
+
0,
|
|
15
|
+
1,
|
|
16
|
+
constants_1.WAD.mul(3),
|
|
17
|
+
constants_1.WAD.mul(32),
|
|
18
|
+
]));
|
|
19
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].exchange_underlying(i ,j: FRAX => 3Crv, dx: 3.00 [3000000000000000000], min_dy: 32.00 [32000000000000000000])", "Curve2AssetsAdapter: Incorrect parse exchange_underlying");
|
|
20
|
+
parsed = parser.parse(ifc.encodeFunctionData("add_liquidity_one_coin", [
|
|
21
|
+
constants_1.WAD.mul(3),
|
|
22
|
+
0,
|
|
23
|
+
constants_1.WAD.mul(2),
|
|
24
|
+
]));
|
|
25
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].add_liquidity_one_coin(amount: 3.00 [3000000000000000000], i: FRAX, minAmount: 2.00 [2000000000000000000])", "Curve2AssetsAdapter: Incorrect parse add_liquidity_one_coin");
|
|
26
|
+
parsed = parser.parse(ifc.encodeFunctionData("add_all_liquidity_one_coin", [0, constants_1.RAY.mul(912)]));
|
|
27
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].add_all_liquidity_one_coin(i: FRAX, rateMinRAY: 912.00)", "Curve2AssetsAdapter: Incorrect parse add_all_liquidity_one_coin");
|
|
28
|
+
parsed = parser.parse(ifc.encodeFunctionData("remove_all_liquidity_one_coin", [
|
|
29
|
+
0,
|
|
30
|
+
constants_1.RAY.mul(721),
|
|
31
|
+
]));
|
|
32
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].remove_all_liquidity_one_coin(i: FRAX, rateMinRAY: 721.00)", "Curve2AssetsAdapter: Incorrect parse remove_all_liquidity_one_coin");
|
|
33
|
+
parsed = parser.parse(ifc.encodeFunctionData("add_liquidity", [
|
|
34
|
+
[constants_1.WAD.mul(100), constants_1.WAD.mul(100)],
|
|
35
|
+
constants_1.WAD.mul(80),
|
|
36
|
+
]));
|
|
37
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].add_liquidity(amounts: [FRAX: 100.00 [100000000000000000000], 3Crv: 100.00 [100000000000000000000]], minAmount: 80.00 [80000000000000000000])", "Curve2AssetsAdapter: Incorrect parse add_liquidity");
|
|
38
|
+
parsed = parser.parse(ifc.encodeFunctionData("remove_liquidity", [
|
|
39
|
+
constants_1.WAD.mul(120),
|
|
40
|
+
[constants_1.WAD.mul(100), constants_1.WAD.mul(100)],
|
|
41
|
+
]));
|
|
42
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].remove_liquidity(amount: 120.00 [120000000000000000000], min_amounts: [FRAX: 100.00 [100000000000000000000], 3Crv: 100.00 [100000000000000000000]])", "Curve2AssetsAdapter: Incorrect parse remove_liquidity");
|
|
43
|
+
parsed = parser.parse(ifc.encodeFunctionData("remove_liquidity_imbalance", [
|
|
44
|
+
[constants_1.WAD.mul(100), constants_1.WAD.mul(100)],
|
|
45
|
+
constants_1.WAD.mul(80),
|
|
46
|
+
]));
|
|
47
|
+
(0, chai_1.expect)(parsed).to.be.eq("Curve2AssetsAdapter[CURVE_FRAX_POOL].remove_liquidity_imbalance(amounts: [FRAX: 100.00 [100000000000000000000], 3Crv: 100.00 [100000000000000000000]], max_burn_amount: 80.00 [80000000000000000000])", "Curve2AssetsAdapter: Incorrect parse remove_liquidity_imbalance");
|
|
48
|
+
});
|
|
49
|
+
});
|
package/lib/{types/contracts/test/suites/mainnet/IPriceFeedsRegistry.js → parsers/iParser.js}
RENAMED
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
2
|
+
import { AbstractParser } from "./abstractParser";
|
|
3
|
+
import { IParser } from "./iParser";
|
|
4
|
+
export declare class LidoAdapterParser extends AbstractParser implements IParser {
|
|
5
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
6
|
+
parse(calldata: string): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.LidoAdapterParser = void 0;
|
|
19
|
+
var types_1 = require("../types");
|
|
20
|
+
var abstractParser_1 = require("./abstractParser");
|
|
21
|
+
var LidoAdapterParser = /** @class */ (function (_super) {
|
|
22
|
+
__extends(LidoAdapterParser, _super);
|
|
23
|
+
function LidoAdapterParser(contract, isContract) {
|
|
24
|
+
var _this = _super.call(this, contract) || this;
|
|
25
|
+
_this.ifc = types_1.ILidoV1Adapter__factory.createInterface();
|
|
26
|
+
if (!isContract)
|
|
27
|
+
_this.adapterName = "LidoV1Adapter";
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
LidoAdapterParser.prototype.parse = function (calldata) {
|
|
31
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
32
|
+
switch (functionFragment.name) {
|
|
33
|
+
case "submit": {
|
|
34
|
+
var amount = this.decodeFunctionData(functionFragment, calldata)[0];
|
|
35
|
+
return "".concat(functionName, "(amount: ").concat(this.formatBN(amount, "STETH"), ")");
|
|
36
|
+
}
|
|
37
|
+
case "submitAll": {
|
|
38
|
+
return "".concat(functionName, "()");
|
|
39
|
+
}
|
|
40
|
+
default:
|
|
41
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return LidoAdapterParser;
|
|
45
|
+
}(abstractParser_1.AbstractParser));
|
|
46
|
+
exports.LidoAdapterParser = LidoAdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 lidoAdapterParser_1 = require("./lidoAdapterParser");
|
|
7
|
+
describe("LidoAdapterParser test", function () {
|
|
8
|
+
it("submit & submitAll function works well", function () {
|
|
9
|
+
var parser = new lidoAdapterParser_1.LidoAdapterParser("LIDO_STETH_GATEWAY", false);
|
|
10
|
+
var ifc = types_1.ILidoV1Adapter__factory.createInterface();
|
|
11
|
+
var parsed = parser.parse(ifc.encodeFunctionData("submit", [constants_1.WAD.mul(1020)]));
|
|
12
|
+
(0, chai_1.expect)(parsed).to.be.eq("LidoV1Adapter[LIDO_STETH_GATEWAY].submit(amount: 1.02K [1020000000000000000000])", "Incorrect parse submit(amount)");
|
|
13
|
+
parser = new lidoAdapterParser_1.LidoAdapterParser("LIDO_STETH_GATEWAY", true);
|
|
14
|
+
parsed = parser.parse(ifc.encodeFunctionData("submitAll"));
|
|
15
|
+
(0, chai_1.expect)(parsed).to.be.eq("Contract[LIDO_STETH_GATEWAY].submitAll()", "Incorrect parse submitAll()");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
2
|
+
import { NetworkType } from "../core/constants";
|
|
3
|
+
import { SupportedToken } from "../tokens/token";
|
|
4
|
+
import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
|
|
5
|
+
import { IParser } from "./iParser";
|
|
6
|
+
export interface AdapterForParser {
|
|
7
|
+
adapter: string;
|
|
8
|
+
contract: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class TxParser {
|
|
11
|
+
protected static parsers: Record<string, IParser>;
|
|
12
|
+
static parse(address: string, calldata: string): string;
|
|
13
|
+
static parseMultiCall(calls: Array<MultiCallStruct>): Array<string>;
|
|
14
|
+
static addAdapters(adapters: Array<AdapterForParser>): Promise<void>;
|
|
15
|
+
static addContracts(network: NetworkType): void;
|
|
16
|
+
static addCreditFacades(creditFacade: string, underlying: SupportedToken): void;
|
|
17
|
+
protected static addParser(address: string, contract: SupportedContract, adapterType: number, isContract: boolean): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.TxParser = void 0;
|
|
40
|
+
var adapters_1 = require("../contracts/adapters");
|
|
41
|
+
var contracts_1 = require("../contracts/contracts");
|
|
42
|
+
var convexBaseRewardPoolAdapterParser_1 = require("./convexBaseRewardPoolAdapterParser");
|
|
43
|
+
var convexBoosterAdapterParser_1 = require("./convexBoosterAdapterParser");
|
|
44
|
+
var creditFacadeParser_1 = require("./creditFacadeParser");
|
|
45
|
+
var curveAdapterParser_1 = require("./curveAdapterParser");
|
|
46
|
+
var lidoAdapterParser_1 = require("./lidoAdapterParser");
|
|
47
|
+
var uniV2AdapterParser_1 = require("./uniV2AdapterParser");
|
|
48
|
+
var uniV3AdapterParser_1 = require("./uniV3AdapterParser");
|
|
49
|
+
var yearnV2AdapterParser_1 = require("./yearnV2AdapterParser");
|
|
50
|
+
var TxParser = /** @class */ (function () {
|
|
51
|
+
function TxParser() {
|
|
52
|
+
}
|
|
53
|
+
TxParser.parse = function (address, calldata) {
|
|
54
|
+
var parser = this.parsers[address];
|
|
55
|
+
if (!parser)
|
|
56
|
+
throw new Error("Can find parser for ".concat(address));
|
|
57
|
+
return parser.parse(calldata);
|
|
58
|
+
};
|
|
59
|
+
TxParser.parseMultiCall = function (calls) {
|
|
60
|
+
return calls.map(function (call) {
|
|
61
|
+
return TxParser.parse(call.target, call.callData.toString());
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
TxParser.addAdapters = function (adapters) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var _i, adapters_2, a, contract;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
for (_i = 0, adapters_2 = adapters; _i < adapters_2.length; _i++) {
|
|
69
|
+
a = adapters_2[_i];
|
|
70
|
+
contract = contracts_1.contractsByAddress[a.contract.toLowerCase()];
|
|
71
|
+
TxParser.addParser(a.adapter, contract, contracts_1.contractParams[contract].type, false);
|
|
72
|
+
}
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
TxParser.addContracts = function (network) {
|
|
78
|
+
for (var _i = 0, _a = Object.keys(contracts_1.contractParams); _i < _a.length; _i++) {
|
|
79
|
+
var c = _a[_i];
|
|
80
|
+
var address = contracts_1.contractsByNetwork[network][c];
|
|
81
|
+
TxParser.addParser(address, c, contracts_1.contractParams[c].type, true);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
TxParser.addCreditFacades = function (creditFacade, underlying) {
|
|
85
|
+
this.parsers[creditFacade.toLowerCase()] = new creditFacadeParser_1.CreditFacadeParser(underlying);
|
|
86
|
+
};
|
|
87
|
+
TxParser.addParser = function (address, contract, adapterType, isContract) {
|
|
88
|
+
switch (adapters_1.AdapterInterface[adapterType]) {
|
|
89
|
+
case "UNISWAP_V2_ROUTER":
|
|
90
|
+
TxParser.parsers[address] = new uniV2AdapterParser_1.UniswapV2AdapterParser(contract, isContract);
|
|
91
|
+
break;
|
|
92
|
+
case "UNISWAP_V3_ROUTER":
|
|
93
|
+
TxParser.parsers[address] = new uniV3AdapterParser_1.UniswapV3AdapterParser(contract, isContract);
|
|
94
|
+
break;
|
|
95
|
+
case "CURVE_V1_EXCHANGE_ONLY":
|
|
96
|
+
case "CURVE_V1_2ASSETS":
|
|
97
|
+
case "CURVE_V1_3ASSETS":
|
|
98
|
+
case "CURVE_V1_4ASSETS":
|
|
99
|
+
case "CURVE_V1_STECRV_POOL":
|
|
100
|
+
case "CURVE_V1_WRAPPER":
|
|
101
|
+
TxParser.parsers[address] = new curveAdapterParser_1.CurveAdapterParser(contract, isContract);
|
|
102
|
+
break;
|
|
103
|
+
case "YEARN_V2":
|
|
104
|
+
TxParser.parsers[address] = new yearnV2AdapterParser_1.YearnV2AdapterParser(contract, isContract);
|
|
105
|
+
break;
|
|
106
|
+
case "CONVEX_V1_BASE_REWARD_POOL":
|
|
107
|
+
TxParser.parsers[address] = new convexBaseRewardPoolAdapterParser_1.ConvexBaseRewardPoolAdapterParser(contract, isContract);
|
|
108
|
+
break;
|
|
109
|
+
case "CONVEX_V1_BOOSTER":
|
|
110
|
+
TxParser.parsers[address] = new convexBoosterAdapterParser_1.ConvexBoosterAdapterParser(contract, isContract);
|
|
111
|
+
break;
|
|
112
|
+
case "CONVEX_V1_CLAIM_ZAP":
|
|
113
|
+
break;
|
|
114
|
+
case "LIDO_V1":
|
|
115
|
+
TxParser.parsers[address] = new lidoAdapterParser_1.LidoAdapterParser(contract, isContract);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
TxParser.parsers = {};
|
|
120
|
+
return TxParser;
|
|
121
|
+
}());
|
|
122
|
+
exports.TxParser = TxParser;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
2
|
+
import { AbstractParser } from "./abstractParser";
|
|
3
|
+
import { IParser } from "./iParser";
|
|
4
|
+
export declare class UniswapV2AdapterParser extends AbstractParser implements IParser {
|
|
5
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
6
|
+
parse(calldata: string): string;
|
|
7
|
+
protected _parse(calldata: string): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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.UniswapV2AdapterParser = void 0;
|
|
19
|
+
var types_1 = require("../types");
|
|
20
|
+
var formatter_1 = require("../utils/formatter");
|
|
21
|
+
var abstractParser_1 = require("./abstractParser");
|
|
22
|
+
var UniswapV2AdapterParser = /** @class */ (function (_super) {
|
|
23
|
+
__extends(UniswapV2AdapterParser, _super);
|
|
24
|
+
function UniswapV2AdapterParser(contract, isContract) {
|
|
25
|
+
var _this = _super.call(this, contract) || this;
|
|
26
|
+
_this.ifc = types_1.IUniswapV2Adapter__factory.createInterface();
|
|
27
|
+
if (!isContract)
|
|
28
|
+
_this.adapterName = "UniswapV2Adapter";
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
UniswapV2AdapterParser.prototype.parse = function (calldata) {
|
|
32
|
+
return this._parse(calldata);
|
|
33
|
+
};
|
|
34
|
+
// parseTxInfo(calldata: string): TxInfo {}
|
|
35
|
+
UniswapV2AdapterParser.prototype._parse = function (calldata) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
38
|
+
switch (functionFragment.name) {
|
|
39
|
+
case "swapExactTokensForTokens": {
|
|
40
|
+
var _b = this.decodeFunctionData(functionFragment, calldata), amountIn = _b[0], amountOutMin = _b[1], path = _b[2];
|
|
41
|
+
var pathStr = path
|
|
42
|
+
.map(function (r) { return _this.tokenSymbol(r); })
|
|
43
|
+
.join(" => ");
|
|
44
|
+
var tokenIn = this.tokenSymbol(path[0]);
|
|
45
|
+
var tokenOut = this.tokenSymbol(path[path.length - 1]);
|
|
46
|
+
var amountInStr = this.formatBN(amountIn, tokenIn);
|
|
47
|
+
var amountOutStr = this.formatBN(amountOutMin, tokenOut);
|
|
48
|
+
return "".concat(functionName, "(amountIn: ").concat(amountInStr, ", amountOutMin: ").concat(amountOutStr, ", path: [").concat(pathStr, "])");
|
|
49
|
+
}
|
|
50
|
+
case "swapTokensForExactTokens": {
|
|
51
|
+
var _c = this.decodeFunctionData(functionFragment, calldata), amountOut = _c[0], amountInMax = _c[1], path = _c[2];
|
|
52
|
+
var pathStr = path
|
|
53
|
+
.map(function (r) { return _this.tokenSymbol(r); })
|
|
54
|
+
.join(" => ");
|
|
55
|
+
var tokenIn = this.tokenSymbol(path[0]);
|
|
56
|
+
var tokenOut = this.tokenSymbol(path[path.length - 1]);
|
|
57
|
+
var amountOutStr = this.formatBN(amountOut, tokenIn);
|
|
58
|
+
var amountInMaxStr = this.formatBN(amountInMax, tokenOut);
|
|
59
|
+
return "".concat(functionName, "(amountOut: ").concat(amountOutStr, ", amountInMax: ").concat(amountInMaxStr, ", path: [").concat(pathStr, "])");
|
|
60
|
+
}
|
|
61
|
+
case "swapAllTokensForTokens": {
|
|
62
|
+
var _d = this.decodeFunctionData(functionFragment, calldata), rateMinRAY = _d[0], path = _d[1];
|
|
63
|
+
return "".concat(functionName, "(rate: ").concat((0, formatter_1.formatBN)(rateMinRAY, 27), ", path: [").concat(path
|
|
64
|
+
.map(function (r) { return _this.tokenSymbol(r); })
|
|
65
|
+
.join(" => "), "])");
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return UniswapV2AdapterParser;
|
|
72
|
+
}(abstractParser_1.AbstractParser));
|
|
73
|
+
exports.UniswapV2AdapterParser = UniswapV2AdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var chai_1 = require("chai");
|
|
4
|
+
var ethers_1 = require("ethers");
|
|
5
|
+
var constants_1 = require("../core/constants");
|
|
6
|
+
var token_1 = require("../tokens/token");
|
|
7
|
+
var types_1 = require("../types");
|
|
8
|
+
var uniV2AdapterParser_1 = require("./uniV2AdapterParser");
|
|
9
|
+
describe("UniswapV2AdapterParser test", function () {
|
|
10
|
+
it("swap functions works well", function () {
|
|
11
|
+
var parser = new uniV2AdapterParser_1.UniswapV2AdapterParser("UNISWAP_V2_ROUTER", false);
|
|
12
|
+
var ifc = types_1.IUniswapV2Adapter__factory.createInterface();
|
|
13
|
+
var parsed = parser.parse(ifc.encodeFunctionData("swapExactTokensForTokens", [
|
|
14
|
+
constants_1.WAD.mul(180000),
|
|
15
|
+
ethers_1.BigNumber.from(1e6).mul(45),
|
|
16
|
+
[
|
|
17
|
+
token_1.tokenDataByNetwork.Mainnet.DAI,
|
|
18
|
+
token_1.tokenDataByNetwork.Mainnet.WETH,
|
|
19
|
+
token_1.tokenDataByNetwork.Mainnet.USDC,
|
|
20
|
+
],
|
|
21
|
+
constants_1.DUMB_ADDRESS,
|
|
22
|
+
45000,
|
|
23
|
+
]));
|
|
24
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV2Adapter[UNISWAP_V2_ROUTER].swapExactTokensForTokens(amountIn: 180.00K [180000000000000000000000], amountOutMin: 45.00 [45000000], path: [DAI => WETH => USDC])", "Incorrect parse swapExactTokensForTokens");
|
|
25
|
+
parsed = parser.parse(ifc.encodeFunctionData("swapTokensForExactTokens", [
|
|
26
|
+
ethers_1.BigNumber.from(1e6).mul(234500),
|
|
27
|
+
constants_1.WAD.mul(17700),
|
|
28
|
+
[
|
|
29
|
+
token_1.tokenDataByNetwork.Mainnet.USDC,
|
|
30
|
+
token_1.tokenDataByNetwork.Mainnet.DAI,
|
|
31
|
+
token_1.tokenDataByNetwork.Mainnet.FRAX,
|
|
32
|
+
],
|
|
33
|
+
constants_1.DUMB_ADDRESS,
|
|
34
|
+
45033,
|
|
35
|
+
]));
|
|
36
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV2Adapter[UNISWAP_V2_ROUTER].swapTokensForExactTokens(amountOut: 234.50K [234500000000], amountInMax: 17.70K [17700000000000000000000], path: [USDC => DAI => FRAX])", "Incorrect parse swapTokensForExactTokens");
|
|
37
|
+
parsed = parser.parse(ifc.encodeFunctionData("swapAllTokensForTokens", [
|
|
38
|
+
constants_1.RAY.mul(3240),
|
|
39
|
+
[
|
|
40
|
+
token_1.tokenDataByNetwork.Mainnet.USDC,
|
|
41
|
+
token_1.tokenDataByNetwork.Mainnet.DAI,
|
|
42
|
+
token_1.tokenDataByNetwork.Mainnet.FRAX,
|
|
43
|
+
],
|
|
44
|
+
45033,
|
|
45
|
+
]));
|
|
46
|
+
(0, chai_1.expect)(parsed).to.be.eq("UniswapV2Adapter[UNISWAP_V2_ROUTER].swapAllTokensForTokens(rate: 3.24K, path: [USDC => DAI => FRAX])", "Incorrect parse swapAllTokensForTokens");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SupportedContract } from "../contracts/contracts";
|
|
2
|
+
import { AbstractParser } from "./abstractParser";
|
|
3
|
+
import { IParser } from "./iParser";
|
|
4
|
+
export declare class UniswapV3AdapterParser extends AbstractParser implements IParser {
|
|
5
|
+
constructor(contract: SupportedContract, isContract: boolean);
|
|
6
|
+
parse(calldata: string): string;
|
|
7
|
+
trackInputPath(path: string): string;
|
|
8
|
+
trackOutputPath(path: string): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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.UniswapV3AdapterParser = void 0;
|
|
19
|
+
var types_1 = require("../types");
|
|
20
|
+
var abstractParser_1 = require("./abstractParser");
|
|
21
|
+
var UniswapV3AdapterParser = /** @class */ (function (_super) {
|
|
22
|
+
__extends(UniswapV3AdapterParser, _super);
|
|
23
|
+
function UniswapV3AdapterParser(contract, isContract) {
|
|
24
|
+
var _this = _super.call(this, contract) || this;
|
|
25
|
+
_this.ifc = types_1.IUniswapV3Adapter__factory.createInterface();
|
|
26
|
+
if (!isContract)
|
|
27
|
+
_this.adapterName = "UniswapV3Adapter";
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
UniswapV3AdapterParser.prototype.parse = function (calldata) {
|
|
31
|
+
var _a = this.parseSelector(calldata), functionFragment = _a.functionFragment, functionName = _a.functionName;
|
|
32
|
+
switch (functionFragment.name) {
|
|
33
|
+
case "exactInputSingle": {
|
|
34
|
+
var _b = this.decodeFunctionData(functionFragment, calldata)[0], tokenIn = _b[0], tokenOut = _b[1], fee = _b[2], amountIn = _b[5], amountOutMinimum = _b[6];
|
|
35
|
+
var tokenInSym = this.tokenSymbol(tokenIn);
|
|
36
|
+
var tokenOutSym = this.tokenSymbol(tokenOut);
|
|
37
|
+
var amountInStr = this.formatBN(amountIn, tokenIn);
|
|
38
|
+
var amountOutMinimumStr = this.formatBN(amountOutMinimum, tokenOut);
|
|
39
|
+
return "".concat(functionName, "(amountIn: ").concat(amountInStr, ", amountOutMinimum: ").concat(amountOutMinimumStr, ", path: ").concat(tokenInSym, " ==(fee: ").concat(fee, ")==> ").concat(tokenOutSym, ")");
|
|
40
|
+
}
|
|
41
|
+
case "exactInput": {
|
|
42
|
+
var _c = this.decodeFunctionData(functionFragment, calldata).params, amountIn = _c.amountIn, amountOutMinimum = _c.amountOutMinimum, path = _c.path;
|
|
43
|
+
var pathStr = this.trackInputPath(path);
|
|
44
|
+
var amountInStr = this.formatBN(amountIn, this.tokenSymbol("0x".concat(path.replace("0x", "").slice(0, 40))));
|
|
45
|
+
var amountOutMinimumStr = this.formatBN(amountOutMinimum, this.tokenSymbol("0x".concat(path.slice(-40, path.length))));
|
|
46
|
+
return "".concat(functionName, "(amountIn: ").concat(amountInStr, ", amountOutMinimum: ").concat(amountOutMinimumStr, ", path: ").concat(pathStr);
|
|
47
|
+
}
|
|
48
|
+
case "exactOutput": {
|
|
49
|
+
var _d = this.decodeFunctionData(functionFragment, calldata).params, amountInMaximum = _d.amountInMaximum, amountOut = _d.amountOut, path = _d.path;
|
|
50
|
+
var pathStr = this.trackOutputPath(path);
|
|
51
|
+
var amountInMaximumStr = this.formatBN(amountInMaximum, this.tokenSymbol("0x".concat(path.slice(-40, path.length))));
|
|
52
|
+
var amountOutStr = this.formatBN(amountOut, this.tokenSymbol("0x".concat(path.replace("0x", "").slice(0, 40))));
|
|
53
|
+
return "".concat(functionName, "(amountInMaximum: ").concat(amountInMaximumStr, ", amountOut: ").concat(amountOutStr, ", path: ").concat(pathStr);
|
|
54
|
+
}
|
|
55
|
+
case "exactOutputSingle": {
|
|
56
|
+
var _e = this.decodeFunctionData(functionFragment, calldata)[0], tokenIn = _e[0], tokenOut = _e[1], fee = _e[2], amountOut = _e[5], amountInMaximum = _e[6];
|
|
57
|
+
var tokenInSym = this.tokenSymbol(tokenIn);
|
|
58
|
+
var tokenOutSym = this.tokenSymbol(tokenOut);
|
|
59
|
+
var amountInMaximumStr = this.formatBN(amountInMaximum, tokenInSym);
|
|
60
|
+
var amountOutStr = this.formatBN(amountOut, tokenOutSym);
|
|
61
|
+
return "".concat(functionName, "(amountInMaximum: ").concat(amountInMaximumStr, ", amountOut: ").concat(amountOutStr, ", path: ").concat(tokenInSym, " ==(fee: ").concat(fee, ")==> ").concat(tokenOutSym, ")");
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return "".concat(functionName, ": Unknown operation ").concat(functionFragment.name, " with calldata ").concat(calldata);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
UniswapV3AdapterParser.prototype.trackInputPath = function (path) {
|
|
68
|
+
var result = "";
|
|
69
|
+
var pointer = path.startsWith("0x") ? 2 : 0;
|
|
70
|
+
while (pointer <= path.length - 40) {
|
|
71
|
+
var from = "0x".concat(path.slice(pointer, pointer + 40)).toLowerCase();
|
|
72
|
+
result += this.tokenSymbol(from) || from;
|
|
73
|
+
pointer += 40;
|
|
74
|
+
if (pointer > path.length - 6)
|
|
75
|
+
return result;
|
|
76
|
+
var fee = parseInt(path.slice(pointer, pointer + 6), 16);
|
|
77
|
+
pointer += 6;
|
|
78
|
+
result += " ==(fee: ".concat(fee, ")==> ");
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
UniswapV3AdapterParser.prototype.trackOutputPath = function (path) {
|
|
83
|
+
var result = "";
|
|
84
|
+
var pointer = path.length;
|
|
85
|
+
while (pointer >= 40) {
|
|
86
|
+
pointer -= 40;
|
|
87
|
+
var from = "0x".concat(path.slice(pointer, pointer + 40));
|
|
88
|
+
result += this.tokenSymbol(from) || from;
|
|
89
|
+
if (pointer < 6)
|
|
90
|
+
return result;
|
|
91
|
+
pointer -= 6;
|
|
92
|
+
var fee = parseInt(path.slice(pointer, pointer + 6), 16);
|
|
93
|
+
result += " ==(fee: ".concat(fee, ")==> ");
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
return UniswapV3AdapterParser;
|
|
98
|
+
}(abstractParser_1.AbstractParser));
|
|
99
|
+
exports.UniswapV3AdapterParser = UniswapV3AdapterParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|