@defisaver/automation-sdk 2.0.2 → 2.0.4
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/.eslintrc.js +1 -0
- package/esm/abis/index.js +27 -15
- package/esm/automation/private/Automation.js +9 -6
- package/esm/automation/private/LegacyAutomation.d.ts +5 -5
- package/esm/automation/private/LegacyAutomation.js +30 -23
- package/esm/automation/private/LegacyProtocol.js +4 -1
- package/esm/automation/private/Protocol.js +4 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/private/StrategiesAutomation.js +27 -21
- package/esm/automation/public/ArbitrumStrategies.js +10 -4
- package/esm/automation/public/EthereumStrategies.js +10 -4
- package/esm/automation/public/OptimismStrategies.js +10 -4
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
- package/esm/configuration.js +8 -5
- package/esm/constants/index.js +281 -275
- package/esm/index.js +57 -17
- package/esm/services/contractService.js +22 -14
- package/esm/services/ethereumService.js +18 -10
- package/esm/services/strategiesService.js +132 -105
- package/esm/services/strategySubService.js +90 -61
- package/esm/services/subDataService.d.ts +5 -0
- package/esm/services/subDataService.js +158 -145
- package/esm/services/triggerService.d.ts +5 -5
- package/esm/services/triggerService.js +124 -94
- package/esm/services/utils.js +82 -33
- package/esm/services/utils.test.d.ts +1 -0
- package/esm/services/utils.test.js +362 -0
- package/esm/types/contracts/generated/Erc20.js +2 -1
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
- package/esm/types/contracts/generated/SubStorage.js +2 -1
- package/esm/types/contracts/generated/UniMulticall.js +2 -1
- package/esm/types/contracts/generated/index.js +2 -1
- package/esm/types/contracts/generated/types.js +2 -1
- package/esm/types/enums.js +17 -14
- package/esm/types/index.js +2 -1
- package/package.json +11 -7
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +2 -2
- package/src/services/subDataService.ts +84 -76
- package/src/services/triggerService.ts +83 -83
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/tsconfig.json +1 -1
- package/umd/index.js +7045 -4124
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
|
@@ -1,60 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
10
|
+
const sdk_1 = require("@defisaver/sdk");
|
|
11
|
+
const enums_1 = require("../types/enums");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
exports.makerRepayFromSavingsSubData = {
|
|
9
15
|
encode(vaultId, targetRatioPercentage, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
10
|
-
const _daiAddr = daiAddr || getAssetInfo('DAI', chainId).address;
|
|
16
|
+
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
11
17
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
12
|
-
const _mcdCdpManagerAddr = mcdCdpManagerAddr || otherAddresses(chainId).McdCdpManager;
|
|
13
|
-
const vaultIdEncoded =
|
|
14
|
-
const targetRatioWei = ratioPercentageToWei(targetRatioPercentage);
|
|
15
|
-
const targetRatioEncoded =
|
|
16
|
-
const daiAddrEncoded =
|
|
17
|
-
const mcdManagerAddrEncoded =
|
|
18
|
+
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
19
|
+
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
20
|
+
const targetRatioWei = (0, utils_1.ratioPercentageToWei)(targetRatioPercentage);
|
|
21
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', targetRatioWei);
|
|
22
|
+
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
23
|
+
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
18
24
|
return [vaultIdEncoded, targetRatioEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
19
25
|
},
|
|
20
26
|
decode(subData) {
|
|
21
|
-
const vaultId = +
|
|
22
|
-
const weiRatio =
|
|
23
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
24
|
-
const daiAddr =
|
|
25
|
-
const mcdManagerAddr =
|
|
27
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
28
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
29
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
30
|
+
const daiAddr = web3_eth_abi_1.default.decodeParameter('address', subData[2]).toString();
|
|
31
|
+
const mcdManagerAddr = web3_eth_abi_1.default.decodeParameter('address', subData[3]).toString();
|
|
26
32
|
return {
|
|
27
33
|
vaultId, targetRatio, daiAddr, mcdManagerAddr,
|
|
28
34
|
};
|
|
29
35
|
},
|
|
30
36
|
};
|
|
31
|
-
|
|
37
|
+
exports.liquityRepayFromSavingsSubData = {
|
|
38
|
+
decode(subData) {
|
|
39
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
40
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
41
|
+
return { targetRatio };
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
exports.makerCloseSubData = {
|
|
32
45
|
encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
33
|
-
const _daiAddr = daiAddr || getAssetInfo('DAI', chainId).address;
|
|
46
|
+
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
34
47
|
// @ts-ignore // TODO - this requires change in @defisaver/tokens
|
|
35
|
-
const _mcdCdpManagerAddr = mcdCdpManagerAddr || otherAddresses(chainId).McdCdpManager;
|
|
36
|
-
const vaultIdEncoded =
|
|
37
|
-
const daiAddrEncoded =
|
|
38
|
-
const mcdManagerAddrEncoded =
|
|
39
|
-
if (compareAddresses(closeToAssetAddr, _daiAddr)) {
|
|
48
|
+
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
49
|
+
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
50
|
+
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
51
|
+
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
52
|
+
if ((0, utils_1.compareAddresses)(closeToAssetAddr, _daiAddr)) {
|
|
40
53
|
// Close to DAI strategy
|
|
41
54
|
return [vaultIdEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
42
55
|
}
|
|
43
56
|
// Close to collateral strategy
|
|
44
|
-
const collAddrEncoded =
|
|
57
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', closeToAssetAddr);
|
|
45
58
|
return [vaultIdEncoded, collAddrEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
46
59
|
},
|
|
47
60
|
decode(subData) {
|
|
48
|
-
const vaultId = +
|
|
61
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
49
62
|
// if closing to collateral, asset addr will be 2nd param out of 4
|
|
50
63
|
// if closing to DAI, will return 2nd param out of 3, which will be DAI addr
|
|
51
|
-
const closeToAssetAddr =
|
|
64
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString().toLowerCase();
|
|
52
65
|
return {
|
|
53
66
|
vaultId, closeToAssetAddr,
|
|
54
67
|
};
|
|
55
68
|
},
|
|
56
69
|
};
|
|
57
|
-
|
|
70
|
+
exports.makerLeverageManagementSubData = {
|
|
58
71
|
// encode: (vaultId:number, repayFrom, boostFrom, boostTo, repayTo, boostEnabled) => [
|
|
59
72
|
// vaultId,
|
|
60
73
|
// new Dec(repayFrom).mul(1e16).toString(),
|
|
@@ -64,25 +77,25 @@ export const makerLeverageManagementSubData = {
|
|
|
64
77
|
// boostEnabled,
|
|
65
78
|
// ],
|
|
66
79
|
decode: (subData) => {
|
|
67
|
-
const vaultId = +
|
|
68
|
-
const weiRatio =
|
|
69
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
80
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
81
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
82
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
70
83
|
return { vaultId, targetRatio };
|
|
71
84
|
},
|
|
72
85
|
};
|
|
73
|
-
|
|
86
|
+
exports.liquityLeverageManagementSubData = {
|
|
74
87
|
decode: (subData) => {
|
|
75
|
-
const weiRatio =
|
|
76
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
88
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
89
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
77
90
|
return { targetRatio };
|
|
78
91
|
},
|
|
79
92
|
};
|
|
80
|
-
|
|
81
|
-
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
82
|
-
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
|
83
|
-
const _debtAddr = debtAddr || getAssetInfo('LUSD', chainId).address;
|
|
84
|
-
const collAddrEncoded =
|
|
85
|
-
const debtAddrEncoded =
|
|
93
|
+
exports.liquityCloseSubData = {
|
|
94
|
+
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
95
|
+
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
96
|
+
const _debtAddr = debtAddr || (0, tokens_1.getAssetInfo)('LUSD', chainId).address;
|
|
97
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _collAddr);
|
|
98
|
+
const debtAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _debtAddr);
|
|
86
99
|
// if (compareAddresses(closeToAssetAddr, daiAddr)) { // TODO - Uhm, wth?
|
|
87
100
|
// // close to LUSD strategy
|
|
88
101
|
// return [daiAddrEncoded, mcdManagerAddrEncoded];
|
|
@@ -91,149 +104,149 @@ export const liquityCloseSubData = {
|
|
|
91
104
|
return [collAddrEncoded, debtAddrEncoded];
|
|
92
105
|
},
|
|
93
106
|
decode(subData) {
|
|
94
|
-
const closeToAssetAddr =
|
|
95
|
-
const debtAddr =
|
|
107
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString().toLowerCase();
|
|
108
|
+
const debtAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString().toLowerCase();
|
|
96
109
|
return { closeToAssetAddr, debtAddr };
|
|
97
110
|
},
|
|
98
111
|
};
|
|
99
|
-
|
|
112
|
+
exports.aaveV2LeverageManagementSubData = {
|
|
100
113
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
101
114
|
return [
|
|
102
|
-
new
|
|
103
|
-
new
|
|
104
|
-
new
|
|
105
|
-
new
|
|
115
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
116
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
117
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
118
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
106
119
|
// @ts-ignore // TODO
|
|
107
120
|
boostEnabled,
|
|
108
121
|
];
|
|
109
122
|
},
|
|
110
123
|
decode(subData) {
|
|
111
|
-
const ratioWei =
|
|
112
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
124
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
125
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
113
126
|
return { targetRatio };
|
|
114
127
|
},
|
|
115
128
|
};
|
|
116
|
-
|
|
129
|
+
exports.aaveV3LeverageManagementSubData = {
|
|
117
130
|
decode(subData) {
|
|
118
|
-
const ratioWei =
|
|
119
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
131
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
132
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
120
133
|
return { targetRatio };
|
|
121
134
|
},
|
|
122
135
|
};
|
|
123
|
-
|
|
124
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
|
|
125
|
-
const encodedColl =
|
|
126
|
-
const encodedCollId =
|
|
127
|
-
const encodedDebt =
|
|
128
|
-
const encodedDebtId =
|
|
129
|
-
const encodedNullAddress =
|
|
136
|
+
exports.aaveV3QuotePriceSubData = {
|
|
137
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
138
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
139
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
140
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
141
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
142
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
130
143
|
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
131
144
|
},
|
|
132
145
|
decode(subData) {
|
|
133
|
-
const collAsset =
|
|
134
|
-
const collAssetId = Number(
|
|
135
|
-
const debtAsset =
|
|
136
|
-
const debtAssetId = Number(
|
|
146
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
147
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
148
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
149
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
137
150
|
return {
|
|
138
151
|
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
139
152
|
};
|
|
140
153
|
},
|
|
141
154
|
};
|
|
142
|
-
|
|
155
|
+
exports.compoundV2LeverageManagementSubData = {
|
|
143
156
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
144
157
|
return [
|
|
145
|
-
new
|
|
146
|
-
new
|
|
147
|
-
new
|
|
148
|
-
new
|
|
158
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
159
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
160
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
161
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
149
162
|
// @ts-ignore // TODO
|
|
150
163
|
boostEnabled,
|
|
151
164
|
];
|
|
152
165
|
},
|
|
153
166
|
decode(subData) {
|
|
154
|
-
const weiRatio =
|
|
155
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
167
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
168
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
156
169
|
return { targetRatio };
|
|
157
170
|
},
|
|
158
171
|
};
|
|
159
|
-
|
|
172
|
+
exports.compoundV3LeverageManagementSubData = {
|
|
160
173
|
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
161
174
|
return [
|
|
162
175
|
market,
|
|
163
176
|
baseToken,
|
|
164
|
-
new
|
|
165
|
-
new
|
|
166
|
-
new
|
|
167
|
-
new
|
|
177
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
178
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
179
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
180
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
168
181
|
// @ts-ignore // TODO
|
|
169
182
|
boostEnabled, isEOA,
|
|
170
183
|
];
|
|
171
184
|
},
|
|
172
185
|
decode(subData) {
|
|
173
|
-
const weiRatio =
|
|
174
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
186
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
187
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
175
188
|
return { targetRatio };
|
|
176
189
|
},
|
|
177
190
|
};
|
|
178
|
-
|
|
191
|
+
exports.morphoAaveV2LeverageManagementSubData = {
|
|
179
192
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
180
193
|
return [
|
|
181
|
-
ratioPercentageToWei(triggerRepayRatio),
|
|
182
|
-
ratioPercentageToWei(triggerBoostRatio),
|
|
183
|
-
ratioPercentageToWei(targetBoostRatio),
|
|
184
|
-
ratioPercentageToWei(targetRepayRatio),
|
|
194
|
+
(0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
|
|
195
|
+
(0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
|
|
196
|
+
(0, utils_1.ratioPercentageToWei)(targetBoostRatio),
|
|
197
|
+
(0, utils_1.ratioPercentageToWei)(targetRepayRatio),
|
|
185
198
|
// @ts-ignore
|
|
186
199
|
boostEnabled,
|
|
187
200
|
];
|
|
188
201
|
},
|
|
189
202
|
decode(subData) {
|
|
190
|
-
const ratioWei =
|
|
191
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
203
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
|
|
204
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
192
205
|
return { targetRatio };
|
|
193
206
|
},
|
|
194
207
|
};
|
|
195
|
-
|
|
208
|
+
exports.cBondsRebondSubData = {
|
|
196
209
|
encode(bondId) {
|
|
197
|
-
const bondIdEncoded =
|
|
210
|
+
const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
|
|
198
211
|
return [bondIdEncoded];
|
|
199
212
|
},
|
|
200
213
|
decode(subData) {
|
|
201
|
-
const bondId =
|
|
214
|
+
const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
202
215
|
return { bondId };
|
|
203
216
|
},
|
|
204
217
|
};
|
|
205
|
-
|
|
218
|
+
exports.liquityPaybackUsingChickenBondSubData = {
|
|
206
219
|
/**
|
|
207
220
|
* @param sourceId bondId or subId
|
|
208
221
|
* @param sourceType 0 for bond, 1 for subId
|
|
209
222
|
* @param chainId
|
|
210
223
|
*/
|
|
211
|
-
encode: (sourceId, sourceType, chainId = ChainId.Ethereum) => {
|
|
212
|
-
const sourceIdEncoded =
|
|
213
|
-
const sourceTypeEncoded =
|
|
214
|
-
const lusdAddressEncoded =
|
|
215
|
-
const bLusdAddressEncoded =
|
|
224
|
+
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
225
|
+
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
226
|
+
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
227
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
228
|
+
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
216
229
|
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
217
230
|
},
|
|
218
231
|
decode: (subData) => {
|
|
219
|
-
const sourceId =
|
|
220
|
-
const sourceType =
|
|
232
|
+
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
233
|
+
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
221
234
|
return { sourceId, sourceType };
|
|
222
235
|
},
|
|
223
236
|
};
|
|
224
|
-
|
|
237
|
+
exports.exchangeDcaSubData = {
|
|
225
238
|
encode: (fromToken, toToken, amount, interval) => {
|
|
226
|
-
const sellTokenEncoded =
|
|
227
|
-
const buyTokenEncoded =
|
|
228
|
-
const amountEncoded =
|
|
229
|
-
const intervalEncoded =
|
|
239
|
+
const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
|
|
240
|
+
const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
|
|
241
|
+
const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
|
|
242
|
+
const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
|
|
230
243
|
return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
|
|
231
244
|
},
|
|
232
245
|
decode: (subData, chainId) => {
|
|
233
|
-
const fromToken =
|
|
234
|
-
const toToken =
|
|
235
|
-
const amount = assetAmountInEth(
|
|
236
|
-
const interval =
|
|
246
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
247
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
248
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
249
|
+
const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
|
|
237
250
|
return {
|
|
238
251
|
fromToken,
|
|
239
252
|
toToken,
|
|
@@ -242,79 +255,79 @@ export const exchangeDcaSubData = {
|
|
|
242
255
|
};
|
|
243
256
|
},
|
|
244
257
|
};
|
|
245
|
-
|
|
258
|
+
exports.exchangeLimitOrderSubData = {
|
|
246
259
|
encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
247
260
|
return [
|
|
248
261
|
fromToken,
|
|
249
262
|
toToken,
|
|
250
263
|
amount,
|
|
251
264
|
targetPrice,
|
|
252
|
-
new
|
|
253
|
-
new
|
|
265
|
+
new decimal_js_1.default(goodUntil).toString(),
|
|
266
|
+
new decimal_js_1.default(orderType).toString(),
|
|
254
267
|
];
|
|
255
268
|
},
|
|
256
269
|
decode: (subData, chainId) => {
|
|
257
|
-
const fromToken =
|
|
258
|
-
const toToken =
|
|
259
|
-
const amount = assetAmountInEth(
|
|
270
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
271
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
272
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
260
273
|
return { fromToken, toToken, amount };
|
|
261
274
|
},
|
|
262
275
|
};
|
|
263
|
-
|
|
276
|
+
exports.sparkLeverageManagementSubData = {
|
|
264
277
|
decode(subData) {
|
|
265
|
-
const ratioWei =
|
|
266
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
278
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
279
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
267
280
|
return { targetRatio };
|
|
268
281
|
},
|
|
269
282
|
};
|
|
270
|
-
|
|
271
|
-
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
|
|
272
|
-
const encodedColl =
|
|
273
|
-
const encodedCollId =
|
|
274
|
-
const encodedDebt =
|
|
275
|
-
const encodedDebtId =
|
|
276
|
-
const encodedNullAddress =
|
|
283
|
+
exports.sparkQuotePriceSubData = {
|
|
284
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
285
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
286
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
287
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
288
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
289
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
277
290
|
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
278
291
|
},
|
|
279
292
|
decode(subData) {
|
|
280
|
-
const collAsset =
|
|
281
|
-
const collAssetId = Number(
|
|
282
|
-
const debtAsset =
|
|
283
|
-
const debtAssetId = Number(
|
|
293
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
294
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
295
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
296
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
284
297
|
return {
|
|
285
298
|
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
286
299
|
};
|
|
287
300
|
},
|
|
288
301
|
};
|
|
289
|
-
|
|
302
|
+
exports.liquityDsrPaybackSubData = {
|
|
290
303
|
encode: (targetRatio) => {
|
|
291
|
-
const daiAddress = getAssetInfo('DAI').address;
|
|
292
|
-
const lusdAddress = getAssetInfo('LUSD').address;
|
|
293
|
-
const ratioStateEncoded =
|
|
294
|
-
const targetRatioEncoded =
|
|
295
|
-
const daiAddressEncoded =
|
|
296
|
-
const lusdAddressEncoded =
|
|
304
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
305
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
306
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
307
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
308
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
309
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
297
310
|
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
|
|
298
311
|
},
|
|
299
312
|
decode: (subData) => {
|
|
300
|
-
const weiRatio =
|
|
301
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
313
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
314
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
302
315
|
return { targetRatio };
|
|
303
316
|
},
|
|
304
317
|
};
|
|
305
|
-
|
|
318
|
+
exports.liquityDsrSupplySubData = {
|
|
306
319
|
encode: (targetRatio) => {
|
|
307
|
-
const daiAddress = getAssetInfo('DAI').address;
|
|
308
|
-
const wethAddress = getAssetInfo('WETH').address;
|
|
309
|
-
const ratioStateEncoded =
|
|
310
|
-
const targetRatioEncoded =
|
|
311
|
-
const daiAddressEncoded =
|
|
312
|
-
const wethAddressEncoded =
|
|
320
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
321
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
322
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
323
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
324
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
325
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
313
326
|
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
314
327
|
},
|
|
315
328
|
decode: (subData) => {
|
|
316
|
-
const weiRatio =
|
|
317
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
329
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
330
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
318
331
|
return { targetRatio };
|
|
319
332
|
},
|
|
320
333
|
};
|
|
@@ -27,8 +27,8 @@ export declare const makerRatioTrigger: {
|
|
|
27
27
|
export declare const aaveV3RatioTrigger: {
|
|
28
28
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
|
|
29
29
|
decode(triggerData: string[]): {
|
|
30
|
-
owner:
|
|
31
|
-
market:
|
|
30
|
+
owner: any;
|
|
31
|
+
market: any;
|
|
32
32
|
ratio: number;
|
|
33
33
|
ratioState: number;
|
|
34
34
|
};
|
|
@@ -36,7 +36,7 @@ export declare const aaveV3RatioTrigger: {
|
|
|
36
36
|
export declare const morphoAaveV2RatioTrigger: {
|
|
37
37
|
encode(owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
|
|
38
38
|
decode(triggerData: string[]): {
|
|
39
|
-
owner:
|
|
39
|
+
owner: any;
|
|
40
40
|
ratio: number;
|
|
41
41
|
ratioState: number;
|
|
42
42
|
};
|
|
@@ -115,8 +115,8 @@ export declare const exchangeOffchainPriceTrigger: {
|
|
|
115
115
|
export declare const sparkRatioTrigger: {
|
|
116
116
|
encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
|
|
117
117
|
decode(triggerData: string[]): {
|
|
118
|
-
owner:
|
|
119
|
-
market:
|
|
118
|
+
owner: any;
|
|
119
|
+
market: any;
|
|
120
120
|
ratio: number;
|
|
121
121
|
ratioState: number;
|
|
122
122
|
};
|