@defisaver/automation-sdk 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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 -265
- 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 +144 -100
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +100 -55
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +165 -127
- package/esm/services/triggerService.d.ts +8 -8
- package/esm/services/triggerService.js +125 -95
- 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.d.ts +9 -1
- package/esm/types/enums.js +24 -12
- package/esm/types/index.js +2 -1
- package/package.json +12 -8
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/constants/index.ts +10 -0
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +24 -0
- package/src/services/strategySubService.ts +30 -0
- package/src/services/subDataService.ts +104 -67
- package/src/services/triggerService.ts +86 -85
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/src/types/enums.ts +9 -0
- package/tsconfig.json +1 -1
- package/umd/index.js +7142 -4138
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
|
@@ -1,60 +1,66 @@
|
|
|
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.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.makerCloseSubData = {
|
|
32
38
|
encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr) {
|
|
33
|
-
const _daiAddr = daiAddr || getAssetInfo('DAI', chainId).address;
|
|
39
|
+
const _daiAddr = daiAddr || (0, tokens_1.getAssetInfo)('DAI', chainId).address;
|
|
34
40
|
// @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)) {
|
|
41
|
+
const _mcdCdpManagerAddr = mcdCdpManagerAddr || (0, sdk_1.otherAddresses)(chainId).McdCdpManager;
|
|
42
|
+
const vaultIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', vaultId.toString());
|
|
43
|
+
const daiAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _daiAddr);
|
|
44
|
+
const mcdManagerAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _mcdCdpManagerAddr);
|
|
45
|
+
if ((0, utils_1.compareAddresses)(closeToAssetAddr, _daiAddr)) {
|
|
40
46
|
// Close to DAI strategy
|
|
41
47
|
return [vaultIdEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
42
48
|
}
|
|
43
49
|
// Close to collateral strategy
|
|
44
|
-
const collAddrEncoded =
|
|
50
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', closeToAssetAddr);
|
|
45
51
|
return [vaultIdEncoded, collAddrEncoded, daiAddrEncoded, mcdManagerAddrEncoded];
|
|
46
52
|
},
|
|
47
53
|
decode(subData) {
|
|
48
|
-
const vaultId = +
|
|
54
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
49
55
|
// if closing to collateral, asset addr will be 2nd param out of 4
|
|
50
56
|
// if closing to DAI, will return 2nd param out of 3, which will be DAI addr
|
|
51
|
-
const closeToAssetAddr =
|
|
57
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString().toLowerCase();
|
|
52
58
|
return {
|
|
53
59
|
vaultId, closeToAssetAddr,
|
|
54
60
|
};
|
|
55
61
|
},
|
|
56
62
|
};
|
|
57
|
-
|
|
63
|
+
exports.makerLeverageManagementSubData = {
|
|
58
64
|
// encode: (vaultId:number, repayFrom, boostFrom, boostTo, repayTo, boostEnabled) => [
|
|
59
65
|
// vaultId,
|
|
60
66
|
// new Dec(repayFrom).mul(1e16).toString(),
|
|
@@ -64,25 +70,25 @@ export const makerLeverageManagementSubData = {
|
|
|
64
70
|
// boostEnabled,
|
|
65
71
|
// ],
|
|
66
72
|
decode: (subData) => {
|
|
67
|
-
const vaultId = +
|
|
68
|
-
const weiRatio =
|
|
69
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
73
|
+
const vaultId = +web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
74
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
75
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
70
76
|
return { vaultId, targetRatio };
|
|
71
77
|
},
|
|
72
78
|
};
|
|
73
|
-
|
|
79
|
+
exports.liquityLeverageManagementSubData = {
|
|
74
80
|
decode: (subData) => {
|
|
75
|
-
const weiRatio =
|
|
76
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
81
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
82
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
77
83
|
return { targetRatio };
|
|
78
84
|
},
|
|
79
85
|
};
|
|
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 =
|
|
86
|
+
exports.liquityCloseSubData = {
|
|
87
|
+
encode(closeToAssetAddr, chainId = enums_1.ChainId.Ethereum, collAddr, debtAddr) {
|
|
88
|
+
const _collAddr = collAddr || (0, tokens_1.getAssetInfo)('WETH', chainId).address;
|
|
89
|
+
const _debtAddr = debtAddr || (0, tokens_1.getAssetInfo)('LUSD', chainId).address;
|
|
90
|
+
const collAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _collAddr);
|
|
91
|
+
const debtAddrEncoded = web3_eth_abi_1.default.encodeParameter('address', _debtAddr);
|
|
86
92
|
// if (compareAddresses(closeToAssetAddr, daiAddr)) { // TODO - Uhm, wth?
|
|
87
93
|
// // close to LUSD strategy
|
|
88
94
|
// return [daiAddrEncoded, mcdManagerAddrEncoded];
|
|
@@ -91,149 +97,149 @@ export const liquityCloseSubData = {
|
|
|
91
97
|
return [collAddrEncoded, debtAddrEncoded];
|
|
92
98
|
},
|
|
93
99
|
decode(subData) {
|
|
94
|
-
const closeToAssetAddr =
|
|
95
|
-
const debtAddr =
|
|
100
|
+
const closeToAssetAddr = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString().toLowerCase();
|
|
101
|
+
const debtAddr = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString().toLowerCase();
|
|
96
102
|
return { closeToAssetAddr, debtAddr };
|
|
97
103
|
},
|
|
98
104
|
};
|
|
99
|
-
|
|
105
|
+
exports.aaveV2LeverageManagementSubData = {
|
|
100
106
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
101
107
|
return [
|
|
102
|
-
new
|
|
103
|
-
new
|
|
104
|
-
new
|
|
105
|
-
new
|
|
108
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
109
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
110
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
111
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
106
112
|
// @ts-ignore // TODO
|
|
107
113
|
boostEnabled,
|
|
108
114
|
];
|
|
109
115
|
},
|
|
110
116
|
decode(subData) {
|
|
111
|
-
const ratioWei =
|
|
112
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
117
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
118
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
113
119
|
return { targetRatio };
|
|
114
120
|
},
|
|
115
121
|
};
|
|
116
|
-
|
|
122
|
+
exports.aaveV3LeverageManagementSubData = {
|
|
117
123
|
decode(subData) {
|
|
118
|
-
const ratioWei =
|
|
119
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
124
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
125
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
120
126
|
return { targetRatio };
|
|
121
127
|
},
|
|
122
128
|
};
|
|
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 =
|
|
129
|
+
exports.aaveV3QuotePriceSubData = {
|
|
130
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
131
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
132
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
133
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
134
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
135
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
130
136
|
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
131
137
|
},
|
|
132
138
|
decode(subData) {
|
|
133
|
-
const collAsset =
|
|
134
|
-
const collAssetId = Number(
|
|
135
|
-
const debtAsset =
|
|
136
|
-
const debtAssetId = Number(
|
|
139
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
140
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
141
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
142
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
137
143
|
return {
|
|
138
144
|
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
139
145
|
};
|
|
140
146
|
},
|
|
141
147
|
};
|
|
142
|
-
|
|
148
|
+
exports.compoundV2LeverageManagementSubData = {
|
|
143
149
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
144
150
|
return [
|
|
145
|
-
new
|
|
146
|
-
new
|
|
147
|
-
new
|
|
148
|
-
new
|
|
151
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
152
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
153
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
154
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
149
155
|
// @ts-ignore // TODO
|
|
150
156
|
boostEnabled,
|
|
151
157
|
];
|
|
152
158
|
},
|
|
153
159
|
decode(subData) {
|
|
154
|
-
const weiRatio =
|
|
155
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
160
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
161
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
156
162
|
return { targetRatio };
|
|
157
163
|
},
|
|
158
164
|
};
|
|
159
|
-
|
|
165
|
+
exports.compoundV3LeverageManagementSubData = {
|
|
160
166
|
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
161
167
|
return [
|
|
162
168
|
market,
|
|
163
169
|
baseToken,
|
|
164
|
-
new
|
|
165
|
-
new
|
|
166
|
-
new
|
|
167
|
-
new
|
|
170
|
+
new decimal_js_1.default(triggerRepayRatio).mul(1e16).toString(),
|
|
171
|
+
new decimal_js_1.default(triggerBoostRatio).mul(1e16).toString(),
|
|
172
|
+
new decimal_js_1.default(targetBoostRatio).mul(1e16).toString(),
|
|
173
|
+
new decimal_js_1.default(targetRepayRatio).mul(1e16).toString(),
|
|
168
174
|
// @ts-ignore // TODO
|
|
169
175
|
boostEnabled, isEOA,
|
|
170
176
|
];
|
|
171
177
|
},
|
|
172
178
|
decode(subData) {
|
|
173
|
-
const weiRatio =
|
|
174
|
-
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
179
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
180
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
175
181
|
return { targetRatio };
|
|
176
182
|
},
|
|
177
183
|
};
|
|
178
|
-
|
|
184
|
+
exports.morphoAaveV2LeverageManagementSubData = {
|
|
179
185
|
encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled) {
|
|
180
186
|
return [
|
|
181
|
-
ratioPercentageToWei(triggerRepayRatio),
|
|
182
|
-
ratioPercentageToWei(triggerBoostRatio),
|
|
183
|
-
ratioPercentageToWei(targetBoostRatio),
|
|
184
|
-
ratioPercentageToWei(targetRepayRatio),
|
|
187
|
+
(0, utils_1.ratioPercentageToWei)(triggerRepayRatio),
|
|
188
|
+
(0, utils_1.ratioPercentageToWei)(triggerBoostRatio),
|
|
189
|
+
(0, utils_1.ratioPercentageToWei)(targetBoostRatio),
|
|
190
|
+
(0, utils_1.ratioPercentageToWei)(targetRepayRatio),
|
|
185
191
|
// @ts-ignore
|
|
186
192
|
boostEnabled,
|
|
187
193
|
];
|
|
188
194
|
},
|
|
189
195
|
decode(subData) {
|
|
190
|
-
const ratioWei =
|
|
191
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
196
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint128', subData[1]);
|
|
197
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
192
198
|
return { targetRatio };
|
|
193
199
|
},
|
|
194
200
|
};
|
|
195
|
-
|
|
201
|
+
exports.cBondsRebondSubData = {
|
|
196
202
|
encode(bondId) {
|
|
197
|
-
const bondIdEncoded =
|
|
203
|
+
const bondIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', bondId);
|
|
198
204
|
return [bondIdEncoded];
|
|
199
205
|
},
|
|
200
206
|
decode(subData) {
|
|
201
|
-
const bondId =
|
|
207
|
+
const bondId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
202
208
|
return { bondId };
|
|
203
209
|
},
|
|
204
210
|
};
|
|
205
|
-
|
|
211
|
+
exports.liquityPaybackUsingChickenBondSubData = {
|
|
206
212
|
/**
|
|
207
213
|
* @param sourceId bondId or subId
|
|
208
214
|
* @param sourceType 0 for bond, 1 for subId
|
|
209
215
|
* @param chainId
|
|
210
216
|
*/
|
|
211
|
-
encode: (sourceId, sourceType, chainId = ChainId.Ethereum) => {
|
|
212
|
-
const sourceIdEncoded =
|
|
213
|
-
const sourceTypeEncoded =
|
|
214
|
-
const lusdAddressEncoded =
|
|
215
|
-
const bLusdAddressEncoded =
|
|
217
|
+
encode: (sourceId, sourceType, chainId = enums_1.ChainId.Ethereum) => {
|
|
218
|
+
const sourceIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceId);
|
|
219
|
+
const sourceTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint256', sourceType);
|
|
220
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('LUSD', chainId).address);
|
|
221
|
+
const bLusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', (0, tokens_1.getAssetInfo)('bLUSD', chainId).address);
|
|
216
222
|
return [sourceIdEncoded, sourceTypeEncoded, lusdAddressEncoded, bLusdAddressEncoded];
|
|
217
223
|
},
|
|
218
224
|
decode: (subData) => {
|
|
219
|
-
const sourceId =
|
|
220
|
-
const sourceType =
|
|
225
|
+
const sourceId = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]).toString();
|
|
226
|
+
const sourceType = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]).toString();
|
|
221
227
|
return { sourceId, sourceType };
|
|
222
228
|
},
|
|
223
229
|
};
|
|
224
|
-
|
|
230
|
+
exports.exchangeDcaSubData = {
|
|
225
231
|
encode: (fromToken, toToken, amount, interval) => {
|
|
226
|
-
const sellTokenEncoded =
|
|
227
|
-
const buyTokenEncoded =
|
|
228
|
-
const amountEncoded =
|
|
229
|
-
const intervalEncoded =
|
|
232
|
+
const sellTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', fromToken);
|
|
233
|
+
const buyTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', toToken);
|
|
234
|
+
const amountEncoded = web3_eth_abi_1.default.encodeParameter('uint256', amount);
|
|
235
|
+
const intervalEncoded = web3_eth_abi_1.default.encodeParameter('uint256', interval);
|
|
230
236
|
return [sellTokenEncoded, buyTokenEncoded, amountEncoded, intervalEncoded];
|
|
231
237
|
},
|
|
232
238
|
decode: (subData, chainId) => {
|
|
233
|
-
const fromToken =
|
|
234
|
-
const toToken =
|
|
235
|
-
const amount = assetAmountInEth(
|
|
236
|
-
const interval =
|
|
239
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
240
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
241
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
242
|
+
const interval = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]).toString();
|
|
237
243
|
return {
|
|
238
244
|
fromToken,
|
|
239
245
|
toToken,
|
|
@@ -242,47 +248,79 @@ export const exchangeDcaSubData = {
|
|
|
242
248
|
};
|
|
243
249
|
},
|
|
244
250
|
};
|
|
245
|
-
|
|
251
|
+
exports.exchangeLimitOrderSubData = {
|
|
246
252
|
encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType) {
|
|
247
253
|
return [
|
|
248
254
|
fromToken,
|
|
249
255
|
toToken,
|
|
250
256
|
amount,
|
|
251
257
|
targetPrice,
|
|
252
|
-
new
|
|
253
|
-
new
|
|
258
|
+
new decimal_js_1.default(goodUntil).toString(),
|
|
259
|
+
new decimal_js_1.default(orderType).toString(),
|
|
254
260
|
];
|
|
255
261
|
},
|
|
256
262
|
decode: (subData, chainId) => {
|
|
257
|
-
const fromToken =
|
|
258
|
-
const toToken =
|
|
259
|
-
const amount = assetAmountInEth(
|
|
263
|
+
const fromToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]).toString();
|
|
264
|
+
const toToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]).toString();
|
|
265
|
+
const amount = (0, tokens_1.assetAmountInEth)(web3_eth_abi_1.default.decodeParameter('uint256', subData[2]).toString(), (0, tokens_1.getAssetInfoByAddress)(fromToken, chainId).symbol);
|
|
260
266
|
return { fromToken, toToken, amount };
|
|
261
267
|
},
|
|
262
268
|
};
|
|
263
|
-
|
|
269
|
+
exports.sparkLeverageManagementSubData = {
|
|
264
270
|
decode(subData) {
|
|
265
|
-
const ratioWei =
|
|
266
|
-
const targetRatio = weiToRatioPercentage(ratioWei);
|
|
271
|
+
const ratioWei = web3_eth_abi_1.default.decodeParameter('uint256', subData[0]);
|
|
272
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(ratioWei);
|
|
267
273
|
return { targetRatio };
|
|
268
274
|
},
|
|
269
275
|
};
|
|
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 =
|
|
276
|
+
exports.sparkQuotePriceSubData = {
|
|
277
|
+
encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = constants_1.ZERO_ADDRESS) {
|
|
278
|
+
const encodedColl = web3_eth_abi_1.default.encodeParameter('address', collAsset);
|
|
279
|
+
const encodedCollId = web3_eth_abi_1.default.encodeParameter('uint8', collAssetId);
|
|
280
|
+
const encodedDebt = web3_eth_abi_1.default.encodeParameter('address', debtAsset);
|
|
281
|
+
const encodedDebtId = web3_eth_abi_1.default.encodeParameter('uint8', debtAssetId);
|
|
282
|
+
const encodedNullAddress = web3_eth_abi_1.default.encodeParameter('address', nullAddress);
|
|
277
283
|
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
278
284
|
},
|
|
279
285
|
decode(subData) {
|
|
280
|
-
const collAsset =
|
|
281
|
-
const collAssetId = Number(
|
|
282
|
-
const debtAsset =
|
|
283
|
-
const debtAssetId = Number(
|
|
286
|
+
const collAsset = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
287
|
+
const collAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[1]));
|
|
288
|
+
const debtAsset = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
289
|
+
const debtAssetId = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[3]));
|
|
284
290
|
return {
|
|
285
291
|
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
286
292
|
};
|
|
287
293
|
},
|
|
288
294
|
};
|
|
295
|
+
exports.liquityDsrPaybackSubData = {
|
|
296
|
+
encode: (targetRatio) => {
|
|
297
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
298
|
+
const lusdAddress = (0, tokens_1.getAssetInfo)('LUSD').address;
|
|
299
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
300
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
301
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
302
|
+
const lusdAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', lusdAddress);
|
|
303
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, lusdAddressEncoded];
|
|
304
|
+
},
|
|
305
|
+
decode: (subData) => {
|
|
306
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
307
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
308
|
+
return { targetRatio };
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
exports.liquityDsrSupplySubData = {
|
|
312
|
+
encode: (targetRatio) => {
|
|
313
|
+
const daiAddress = (0, tokens_1.getAssetInfo)('DAI').address;
|
|
314
|
+
const wethAddress = (0, tokens_1.getAssetInfo)('WETH').address;
|
|
315
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', enums_1.RatioState.UNDER);
|
|
316
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
317
|
+
const daiAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', daiAddress);
|
|
318
|
+
const wethAddressEncoded = web3_eth_abi_1.default.encodeParameter('address', wethAddress);
|
|
319
|
+
return [ratioStateEncoded, targetRatioEncoded, daiAddressEncoded, wethAddressEncoded];
|
|
320
|
+
},
|
|
321
|
+
decode: (subData) => {
|
|
322
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
323
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
324
|
+
return { targetRatio };
|
|
325
|
+
},
|
|
326
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import type { RatioState } from '../types/enums';
|
|
2
|
+
import type { RatioState, OrderType } from '../types/enums';
|
|
3
3
|
export declare const chainlinkPriceTrigger: {
|
|
4
4
|
encode(tokenAddr: EthereumAddress, price: string, state: RatioState): string[];
|
|
5
5
|
decode(triggerData: string[]): {
|
|
@@ -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
|
};
|
|
@@ -105,9 +105,9 @@ export declare const exchangeTimestampTrigger: {
|
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
export declare const exchangeOffchainPriceTrigger: {
|
|
108
|
-
encode(targetPrice: string, goodUntil: number, fromTokenDecimals: number): string[];
|
|
108
|
+
encode(targetPrice: string, goodUntil: number, orderType: OrderType, fromTokenDecimals: number): string[];
|
|
109
109
|
decode(triggerData: string[], fromTokenDecimals: number, toTokenDecimals: number): {
|
|
110
|
-
orderType:
|
|
110
|
+
orderType: OrderType;
|
|
111
111
|
targetPrice: string;
|
|
112
112
|
goodUntil: any;
|
|
113
113
|
};
|
|
@@ -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
|
};
|