@gearbox-protocol/periphery-v3 1.7.0-next.74 → 1.7.0-next.76
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/contracts/test/equivalence/CreditAccountsEquivalenceTest.t.sol +7 -4
- package/contracts/test/equivalence/CreditSuiteEquivalenceTest.t.sol +3 -4
- package/contracts/test/equivalence/GaugeEquivalenceTest.t.sol +3 -4
- package/contracts/test/equivalence/PoolsEquivalenceTest.t.sol +3 -4
- package/contracts/{data/Types.sol → test/interfaces/IDataCompressorV3.sol} +49 -5
- package/package.json +1 -1
- package/contracts/data/DataCompressorV3.sol +0 -669
- package/contracts/data/ZapperRegister.sol +0 -46
- package/contracts/interfaces/IDataCompressorV3.sol +0 -55
- package/contracts/interfaces/IZapperRegister.sol +0 -11
- package/contracts/test/DC_Test.sol +0 -132
- package/contracts/tokens/ERC20Metadata.sol +0 -17
|
@@ -5,11 +5,14 @@ pragma solidity ^0.8.17;
|
|
|
5
5
|
|
|
6
6
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
7
7
|
import {Test} from "forge-std/Test.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
IDataCompressorV3,
|
|
10
|
+
CreditAccountData as CreditAccountDataOld,
|
|
11
|
+
TokenBalance
|
|
12
|
+
} from "../interfaces/IDataCompressorV3.sol";
|
|
9
13
|
import {MarketCompressor} from "../../compressors/MarketCompressor.sol";
|
|
10
14
|
import {CreditAccountCompressor} from "../../compressors/CreditAccountCompressor.sol";
|
|
11
15
|
import {MarketData} from "../../types/MarketData.sol";
|
|
12
|
-
import {CreditAccountData as CreditAccountDataOld, TokenBalance} from "../../data/Types.sol";
|
|
13
16
|
import {CreditAccountData, TokenInfo} from "../../types/CreditAccountState.sol";
|
|
14
17
|
import {MarketFilter, CreditAccountFilter} from "../../types/Filters.sol";
|
|
15
18
|
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
|
|
@@ -21,7 +24,7 @@ import "forge-std/console.sol";
|
|
|
21
24
|
contract CreditAccountsEquivalenceTest is Test {
|
|
22
25
|
using Address for address;
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
IDataCompressorV3 public dc3;
|
|
25
28
|
MarketCompressor public mc;
|
|
26
29
|
CreditAccountCompressor public cac;
|
|
27
30
|
|
|
@@ -53,7 +56,7 @@ contract CreditAccountsEquivalenceTest is Test {
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
mc = MarketCompressor(marketCompressor);
|
|
56
|
-
dc3 =
|
|
59
|
+
dc3 = IDataCompressorV3(dataCompressor);
|
|
57
60
|
cac = CreditAccountCompressor(creditAccountCompressor);
|
|
58
61
|
|
|
59
62
|
// Update all price feeds before running the test
|
|
@@ -5,17 +5,16 @@ pragma solidity ^0.8.17;
|
|
|
5
5
|
|
|
6
6
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
7
7
|
import {Test} from "forge-std/Test.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {IDataCompressorV3, CreditManagerData} from "../interfaces/IDataCompressorV3.sol";
|
|
9
9
|
import {MarketCompressor} from "../../compressors/MarketCompressor.sol";
|
|
10
10
|
import {MarketData} from "../../types/MarketData.sol";
|
|
11
|
-
import {CreditManagerData} from "../../data/Types.sol";
|
|
12
11
|
import {MarketFilter} from "../../types/Filters.sol";
|
|
13
12
|
import "forge-std/console.sol";
|
|
14
13
|
|
|
15
14
|
contract CreditSuiteEquivalenceTest is Test {
|
|
16
15
|
using Address for address;
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
IDataCompressorV3 public dc3;
|
|
19
18
|
MarketCompressor public mc;
|
|
20
19
|
|
|
21
20
|
function _findCreditManager(address cmAddr, CreditManagerData[] memory creditManagersOld)
|
|
@@ -46,7 +45,7 @@ contract CreditSuiteEquivalenceTest is Test {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
mc = MarketCompressor(marketCompressor);
|
|
49
|
-
dc3 =
|
|
48
|
+
dc3 = IDataCompressorV3(dataCompressor);
|
|
50
49
|
|
|
51
50
|
MarketFilter memory filter =
|
|
52
51
|
MarketFilter({configurators: new address[](0), pools: new address[](0), underlying: address(0)});
|
|
@@ -5,17 +5,16 @@ pragma solidity ^0.8.17;
|
|
|
5
5
|
|
|
6
6
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
7
7
|
import {Test} from "forge-std/Test.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {IDataCompressorV3, GaugeInfo as GaugeInfoOld} from "../interfaces/IDataCompressorV3.sol";
|
|
9
9
|
import {GaugeCompressor} from "../../compressors/GaugeCompressor.sol";
|
|
10
10
|
import {GaugeInfo} from "../../types/RateKeeperState.sol";
|
|
11
|
-
import {GaugeInfo as GaugeInfoOld} from "../../data/Types.sol";
|
|
12
11
|
import {MarketFilter} from "../../types/Filters.sol";
|
|
13
12
|
import "forge-std/console.sol";
|
|
14
13
|
|
|
15
14
|
contract GaugeCompressorEquivalenceTest is Test {
|
|
16
15
|
using Address for address;
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
IDataCompressorV3 public dc3;
|
|
19
18
|
GaugeCompressor public gc;
|
|
20
19
|
|
|
21
20
|
function test_GCE_01_GaugeCompressor_equivalence() public {
|
|
@@ -34,7 +33,7 @@ contract GaugeCompressorEquivalenceTest is Test {
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
gc = GaugeCompressor(gaugeCompressor);
|
|
37
|
-
dc3 =
|
|
36
|
+
dc3 = IDataCompressorV3(dataCompressor);
|
|
38
37
|
|
|
39
38
|
MarketFilter memory filter =
|
|
40
39
|
MarketFilter({configurators: new address[](0), pools: new address[](0), underlying: address(0)});
|
|
@@ -5,17 +5,16 @@ pragma solidity ^0.8.17;
|
|
|
5
5
|
|
|
6
6
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
7
7
|
import {Test} from "forge-std/Test.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {IDataCompressorV3, PoolData} from "../interfaces/IDataCompressorV3.sol";
|
|
9
9
|
import {MarketCompressor} from "../../compressors/MarketCompressor.sol";
|
|
10
10
|
import {MarketData} from "../../types/MarketData.sol";
|
|
11
|
-
import {PoolData} from "../../data/Types.sol";
|
|
12
11
|
import {MarketFilter} from "../../types/Filters.sol";
|
|
13
12
|
import "forge-std/console.sol";
|
|
14
13
|
|
|
15
14
|
contract PoolsEquivalenceTest is Test {
|
|
16
15
|
using Address for address;
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
IDataCompressorV3 public dc3;
|
|
19
18
|
MarketCompressor public mc;
|
|
20
19
|
|
|
21
20
|
function test_PCE_01_PoolCompressor_equivalence() public {
|
|
@@ -33,7 +32,7 @@ contract PoolsEquivalenceTest is Test {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
mc = MarketCompressor(marketCompressor);
|
|
36
|
-
dc3 =
|
|
35
|
+
dc3 = IDataCompressorV3(dataCompressor);
|
|
37
36
|
|
|
38
37
|
MarketFilter memory filter =
|
|
39
38
|
MarketFilter({configurators: new address[](0), pools: new address[](0), underlying: address(0)});
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2023
|
|
1
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
4
2
|
pragma solidity ^0.8.17;
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
|
|
5
|
+
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
|
|
8
6
|
|
|
9
7
|
struct TokenBalance {
|
|
10
8
|
address token;
|
|
@@ -177,3 +175,49 @@ struct GaugeInfo {
|
|
|
177
175
|
bool epochFrozen;
|
|
178
176
|
GaugeQuotaParams[] quotaParams;
|
|
179
177
|
}
|
|
178
|
+
|
|
179
|
+
interface IDataCompressorV3 is IVersion {
|
|
180
|
+
/// @dev Returns CreditAccountData for all opened accounts for particular borrower
|
|
181
|
+
/// @param borrower Borrower address
|
|
182
|
+
/// @param priceUpdates Price updates for price on demand oracles
|
|
183
|
+
function getCreditAccountsByBorrower(address borrower, PriceUpdate[] memory priceUpdates)
|
|
184
|
+
external
|
|
185
|
+
returns (CreditAccountData[] memory);
|
|
186
|
+
|
|
187
|
+
/// @dev Returns CreditAccountData for all opened accounts for particular borrower
|
|
188
|
+
/// @param creditManager Address
|
|
189
|
+
/// @param priceUpdates Price updates for price on demand oracles
|
|
190
|
+
function getCreditAccountsByCreditManager(address creditManager, PriceUpdate[] memory priceUpdates)
|
|
191
|
+
external
|
|
192
|
+
returns (CreditAccountData[] memory);
|
|
193
|
+
|
|
194
|
+
/// @dev Returns CreditAccountData for all accounts with hf <1
|
|
195
|
+
/// @param priceUpdates Price updates for price on demand oracles
|
|
196
|
+
function getLiquidatableCreditAccounts(PriceUpdate[] memory priceUpdates)
|
|
197
|
+
external
|
|
198
|
+
returns (CreditAccountData[] memory result);
|
|
199
|
+
|
|
200
|
+
/// @dev Returns CreditAccountData for a particular Credit Account account, based on creditManager and borrower
|
|
201
|
+
/// @param creditAccount Address of credit account
|
|
202
|
+
/// @param priceUpdates Price updates for price on demand oracles
|
|
203
|
+
function getCreditAccountData(address creditAccount, PriceUpdate[] memory priceUpdates)
|
|
204
|
+
external
|
|
205
|
+
returns (CreditAccountData memory);
|
|
206
|
+
|
|
207
|
+
/// @dev Returns CreditManagerData for all Credit Managers
|
|
208
|
+
function getCreditManagersV3List() external view returns (CreditManagerData[] memory);
|
|
209
|
+
|
|
210
|
+
/// @dev Returns CreditManagerData for a particular _creditManager
|
|
211
|
+
/// @param creditManager CreditManager address
|
|
212
|
+
function getCreditManagerData(address creditManager) external view returns (CreditManagerData memory);
|
|
213
|
+
|
|
214
|
+
/// @dev Returns PoolData for a particular pool
|
|
215
|
+
/// @param _pool Pool address
|
|
216
|
+
function getPoolData(address _pool) external view returns (PoolData memory);
|
|
217
|
+
|
|
218
|
+
/// @dev Returns PoolData for all registered pools
|
|
219
|
+
function getPoolsV3List() external view returns (PoolData[] memory);
|
|
220
|
+
|
|
221
|
+
/// @dev Returns GaugeInfo for all registered gauges
|
|
222
|
+
function getGaugesV3Data(address staker) external view returns (GaugeInfo[] memory result);
|
|
223
|
+
}
|
package/package.json
CHANGED
|
@@ -1,669 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2023
|
|
4
|
-
pragma solidity ^0.8.10;
|
|
5
|
-
pragma experimental ABIEncoderV2;
|
|
6
|
-
|
|
7
|
-
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
8
|
-
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
9
|
-
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
|
|
10
|
-
import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v3/contracts/libraries/Constants.sol";
|
|
11
|
-
|
|
12
|
-
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
13
|
-
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
|
|
14
|
-
import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol";
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
ICreditManagerV3,
|
|
18
|
-
CollateralDebtData,
|
|
19
|
-
CollateralCalcTask
|
|
20
|
-
} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
21
|
-
import {ICreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol";
|
|
22
|
-
import {ICreditConfiguratorV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditConfiguratorV3.sol";
|
|
23
|
-
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
|
|
24
|
-
import {IUpdatablePriceFeed} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeed.sol";
|
|
25
|
-
import {IPriceOracleV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPriceOracleV3.sol";
|
|
26
|
-
import {ICreditAccountV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditAccountV3.sol";
|
|
27
|
-
import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
|
|
28
|
-
import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";
|
|
29
|
-
import {PoolV3} from "@gearbox-protocol/core-v3/contracts/pool/PoolV3.sol";
|
|
30
|
-
|
|
31
|
-
import {CreditManagerV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditManagerV3.sol";
|
|
32
|
-
|
|
33
|
-
import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol";
|
|
34
|
-
import {IBotListV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IBotListV3.sol";
|
|
35
|
-
import {IGaugeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IGaugeV3.sol";
|
|
36
|
-
|
|
37
|
-
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
|
|
38
|
-
|
|
39
|
-
import {IDataCompressorV3} from "../interfaces/IDataCompressorV3.sol";
|
|
40
|
-
import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
|
|
41
|
-
|
|
42
|
-
import {
|
|
43
|
-
COUNT,
|
|
44
|
-
QUERY,
|
|
45
|
-
CreditAccountData,
|
|
46
|
-
CreditManagerData,
|
|
47
|
-
PoolData,
|
|
48
|
-
TokenBalance,
|
|
49
|
-
ContractAdapter,
|
|
50
|
-
QuotaInfo,
|
|
51
|
-
GaugeInfo,
|
|
52
|
-
GaugeQuotaParams,
|
|
53
|
-
CreditManagerDebtParams,
|
|
54
|
-
ZapperInfo,
|
|
55
|
-
LinearModel
|
|
56
|
-
} from "./Types.sol";
|
|
57
|
-
|
|
58
|
-
// EXCEPTIONS
|
|
59
|
-
import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
|
|
60
|
-
|
|
61
|
-
import {IZapperRegister} from "../interfaces/IZapperRegister.sol";
|
|
62
|
-
|
|
63
|
-
/// @title Data compressor 3.0.
|
|
64
|
-
/// @notice Collects data from various contracts for use in the dApp
|
|
65
|
-
/// Do not use for data from data compressor for state-changing functions
|
|
66
|
-
contract DataCompressorV3 is IDataCompressorV3, ContractsRegisterTrait {
|
|
67
|
-
// Contract version
|
|
68
|
-
uint256 public constant version = 3_00;
|
|
69
|
-
bytes32 public constant contractType = "DATA_COMPRESSOR";
|
|
70
|
-
|
|
71
|
-
IZapperRegister public zapperRegister;
|
|
72
|
-
|
|
73
|
-
error CreditManagerIsNotV3Exception();
|
|
74
|
-
|
|
75
|
-
constructor(address _addressProvider) ContractsRegisterTrait(_addressProvider) {
|
|
76
|
-
// zapperRegister = IZapperRegister(IAddressProviderV3(_addressProvider).getAddressOrRevert("ZAPPER_REGISTER", 3_00));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// @dev Returns CreditAccountData for all opened accounts for particular borrower
|
|
80
|
-
/// @param borrower Borrower address
|
|
81
|
-
/// @param priceUpdates Price updates for priceFeedsOnDemand
|
|
82
|
-
function getCreditAccountsByBorrower(address borrower, PriceUpdate[] memory priceUpdates)
|
|
83
|
-
external
|
|
84
|
-
override
|
|
85
|
-
returns (CreditAccountData[] memory result)
|
|
86
|
-
{
|
|
87
|
-
return _queryCreditAccounts(_listCreditManagersV3(), borrower, false, priceUpdates);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getCreditAccountsByCreditManager(address creditManager, PriceUpdate[] memory priceUpdates)
|
|
91
|
-
external
|
|
92
|
-
override
|
|
93
|
-
registeredCreditManagerOnly(creditManager)
|
|
94
|
-
returns (CreditAccountData[] memory result)
|
|
95
|
-
{
|
|
96
|
-
if (!_isContractV3(creditManager)) revert CreditManagerIsNotV3Exception();
|
|
97
|
-
|
|
98
|
-
address[] memory creditManagers = new address[](1);
|
|
99
|
-
creditManagers[0] = creditManager;
|
|
100
|
-
return _queryCreditAccounts(creditManagers, address(0), false, priceUpdates);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getLiquidatableCreditAccounts(PriceUpdate[] memory priceUpdates)
|
|
104
|
-
external
|
|
105
|
-
override
|
|
106
|
-
returns (CreditAccountData[] memory result)
|
|
107
|
-
{
|
|
108
|
-
return _queryCreditAccounts(_listCreditManagersV3(), address(0), true, priceUpdates);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/// @notice Query credit accounts data by parameters
|
|
112
|
-
/// @param borrower Borrower address, all borrowers if address(0)
|
|
113
|
-
/// @param liquidatableOnly If true, returns only liquidatable accounts
|
|
114
|
-
/// @param priceUpdates Price updates for priceFeedsOnDemand
|
|
115
|
-
function _queryCreditAccounts(
|
|
116
|
-
address[] memory creditManagers,
|
|
117
|
-
address borrower,
|
|
118
|
-
bool liquidatableOnly,
|
|
119
|
-
PriceUpdate[] memory priceUpdates
|
|
120
|
-
) internal returns (CreditAccountData[] memory result) {
|
|
121
|
-
uint256 maxAccounts;
|
|
122
|
-
for (uint256 i; i < creditManagers.length; ++i) {
|
|
123
|
-
maxAccounts += ICreditManagerV3(creditManagers[i]).creditAccountsLen();
|
|
124
|
-
}
|
|
125
|
-
result = new CreditAccountData[](maxAccounts);
|
|
126
|
-
|
|
127
|
-
uint256 numAccounts;
|
|
128
|
-
for (uint256 i; i < creditManagers.length; ++i) {
|
|
129
|
-
address creditManager = creditManagers[i];
|
|
130
|
-
_updatePrices(creditManager, priceUpdates);
|
|
131
|
-
|
|
132
|
-
address[] memory creditAccounts = ICreditManagerV3(creditManager).creditAccounts();
|
|
133
|
-
for (uint256 j; j < creditAccounts.length; ++j) {
|
|
134
|
-
address creditAccount = creditAccounts[j];
|
|
135
|
-
if (borrower != address(0) && _getAccountOwner(creditManager, creditAccount) != borrower) continue;
|
|
136
|
-
if (liquidatableOnly && !_isLiquidatable(creditManager, creditAccount)) continue;
|
|
137
|
-
result[numAccounts++] = _getCreditAccountData(creditManager, creditAccount);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
assembly {
|
|
142
|
-
mstore(result, numAccounts)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/// @dev Returns CreditAccountData for a particular Credit Account account, based on creditManager and borrower
|
|
147
|
-
/// @param _creditAccount Credit account address
|
|
148
|
-
/// @param priceUpdates Price updates for priceFeedsOnDemand
|
|
149
|
-
function getCreditAccountData(address _creditAccount, PriceUpdate[] memory priceUpdates)
|
|
150
|
-
public
|
|
151
|
-
returns (CreditAccountData memory result)
|
|
152
|
-
{
|
|
153
|
-
ICreditAccountV3 creditAccount = ICreditAccountV3(_creditAccount);
|
|
154
|
-
|
|
155
|
-
address _cm = creditAccount.creditManager();
|
|
156
|
-
_ensureRegisteredCreditManager(_cm);
|
|
157
|
-
|
|
158
|
-
if (!_isContractV3(_cm)) revert CreditManagerIsNotV3Exception();
|
|
159
|
-
|
|
160
|
-
_updatePrices(_cm, priceUpdates);
|
|
161
|
-
|
|
162
|
-
return _getCreditAccountData(_cm, _creditAccount);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function _getCreditAccountData(address _cm, address _creditAccount)
|
|
166
|
-
internal
|
|
167
|
-
view
|
|
168
|
-
returns (CreditAccountData memory result)
|
|
169
|
-
{
|
|
170
|
-
ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
|
|
171
|
-
ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
|
|
172
|
-
// ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
|
|
173
|
-
result.creditFacade = address(creditFacade);
|
|
174
|
-
result.cfVersion = _getVersion(address(creditFacade));
|
|
175
|
-
|
|
176
|
-
address borrower = _getAccountOwner(address(creditManager), _creditAccount);
|
|
177
|
-
|
|
178
|
-
result.borrower = borrower;
|
|
179
|
-
result.creditManager = _cm;
|
|
180
|
-
result.addr = _creditAccount;
|
|
181
|
-
|
|
182
|
-
result.underlying = _getUnderlying(creditManager);
|
|
183
|
-
result.cmName = _getName(_cm);
|
|
184
|
-
|
|
185
|
-
address pool = _getPool(_cm);
|
|
186
|
-
result.baseBorrowRate = _getBaseInterestRate(pool);
|
|
187
|
-
|
|
188
|
-
uint256 collateralTokenCount = _getCollateralTokensCount(address(creditManager));
|
|
189
|
-
|
|
190
|
-
result.enabledTokensMask = creditManager.enabledTokensMaskOf(_creditAccount);
|
|
191
|
-
|
|
192
|
-
result.balances = new TokenBalance[](collateralTokenCount);
|
|
193
|
-
|
|
194
|
-
uint256 quotaRevenue = 0;
|
|
195
|
-
{
|
|
196
|
-
uint256 forbiddenTokenMask = creditFacade.forbiddenTokenMask();
|
|
197
|
-
uint256 quotedTokensMask = creditManager.quotedTokensMask();
|
|
198
|
-
IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(pool);
|
|
199
|
-
|
|
200
|
-
unchecked {
|
|
201
|
-
for (uint256 i = 0; i < collateralTokenCount; ++i) {
|
|
202
|
-
TokenBalance memory balance;
|
|
203
|
-
uint256 tokenMask = 1 << i;
|
|
204
|
-
|
|
205
|
-
(balance.token,) = creditManager.collateralTokenByMask(tokenMask);
|
|
206
|
-
balance.balance = IERC20(balance.token).balanceOf(_creditAccount);
|
|
207
|
-
|
|
208
|
-
balance.isForbidden = tokenMask & forbiddenTokenMask == 0 ? false : true;
|
|
209
|
-
balance.isEnabled = tokenMask & result.enabledTokensMask == 0 ? false : true;
|
|
210
|
-
|
|
211
|
-
balance.isQuoted = tokenMask & quotedTokensMask == 0 ? false : true;
|
|
212
|
-
|
|
213
|
-
if (balance.isQuoted) {
|
|
214
|
-
(balance.quota, balance.quotaCumulativeIndexLU) = pqk.getQuota(_creditAccount, balance.token);
|
|
215
|
-
balance.quotaRate = pqk.getQuotaRate(balance.token);
|
|
216
|
-
|
|
217
|
-
quotaRevenue += balance.quota * balance.quotaRate;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
result.balances[i] = balance;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
result.aggregatedBorrowRate =
|
|
226
|
-
result.baseBorrowRate + (result.debt == 0 ? 0 : RAY * quotaRevenue / PERCENTAGE_FACTOR / result.debt);
|
|
227
|
-
|
|
228
|
-
// uint256 debt;
|
|
229
|
-
// uint256 cumulativeIndexNow;
|
|
230
|
-
// uint256 cumulativeIndexLastUpdate;
|
|
231
|
-
// uint128 cumulativeQuotaInterest;
|
|
232
|
-
// uint256 accruedInterest;
|
|
233
|
-
// uint256 accruedFees;
|
|
234
|
-
// uint256 totalDebtUSD;
|
|
235
|
-
// uint256 totalValue;
|
|
236
|
-
// uint256 totalValueUSD;
|
|
237
|
-
// uint256 twvUSD;
|
|
238
|
-
// uint256 enabledTokensMask;
|
|
239
|
-
// uint256 quotedTokensMask;
|
|
240
|
-
// address[] quotedTokens;
|
|
241
|
-
|
|
242
|
-
for (uint256 i = 0; i < 2;) {
|
|
243
|
-
try creditManager.calcDebtAndCollateral(
|
|
244
|
-
_creditAccount, i == 0 ? CollateralCalcTask.DEBT_ONLY : CollateralCalcTask.DEBT_COLLATERAL
|
|
245
|
-
) returns (CollateralDebtData memory collateralDebtData) {
|
|
246
|
-
result.accruedInterest = collateralDebtData.accruedInterest;
|
|
247
|
-
result.accruedFees = collateralDebtData.accruedFees;
|
|
248
|
-
|
|
249
|
-
result.totalDebtUSD = collateralDebtData.totalDebtUSD;
|
|
250
|
-
result.totalValueUSD = collateralDebtData.totalValueUSD;
|
|
251
|
-
result.twvUSD = collateralDebtData.twvUSD;
|
|
252
|
-
result.healthFactor = collateralDebtData.totalDebtUSD != 0
|
|
253
|
-
? collateralDebtData.twvUSD * PERCENTAGE_FACTOR / collateralDebtData.totalDebtUSD
|
|
254
|
-
: type(uint16).max;
|
|
255
|
-
result.totalValue = collateralDebtData.totalValue;
|
|
256
|
-
result.isSuccessful = true;
|
|
257
|
-
} catch {
|
|
258
|
-
result.priceFeedsNeeded = _getPriceFeedFailedList(_cm, result.balances);
|
|
259
|
-
result.isSuccessful = false;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
unchecked {
|
|
263
|
-
++i;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
(result.debt, result.cumulativeIndexLastUpdate, result.cumulativeQuotaInterest,,,, result.since,) =
|
|
268
|
-
CreditManagerV3(_cm).creditAccountInfo(_creditAccount);
|
|
269
|
-
|
|
270
|
-
result.expirationDate = creditFacade.expirationDate();
|
|
271
|
-
|
|
272
|
-
result.activeBots = IBotListV3(CreditFacadeV3(address(creditFacade)).botList()).activeBots(_creditAccount);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function _listCreditManagersV3() internal view returns (address[] memory result) {
|
|
276
|
-
address[] memory creditManagers = IContractsRegister(contractsRegister).getCreditManagers();
|
|
277
|
-
uint256 maxManagers = creditManagers.length;
|
|
278
|
-
|
|
279
|
-
result = new address[](maxManagers);
|
|
280
|
-
uint256 numManagers;
|
|
281
|
-
for (uint256 i; i < maxManagers; ++i) {
|
|
282
|
-
address creditManager = creditManagers[i];
|
|
283
|
-
if (!_isContractV3(creditManager)) continue;
|
|
284
|
-
result[numManagers++] = creditManager;
|
|
285
|
-
}
|
|
286
|
-
assembly {
|
|
287
|
-
mstore(result, numManagers)
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function _isContractV3(address _cm) internal view returns (bool) {
|
|
292
|
-
uint256 cmVersion = _getVersion(_cm);
|
|
293
|
-
return cmVersion >= 3_00 && cmVersion < 3_99;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/// @dev Returns CreditManagerData for all Credit Managers
|
|
297
|
-
function getCreditManagersV3List() external view returns (CreditManagerData[] memory result) {
|
|
298
|
-
address[] memory creditManagers = _listCreditManagersV3();
|
|
299
|
-
uint256 len = creditManagers.length;
|
|
300
|
-
|
|
301
|
-
result = new CreditManagerData[](len);
|
|
302
|
-
|
|
303
|
-
unchecked {
|
|
304
|
-
for (uint256 i = 0; i < len; ++i) {
|
|
305
|
-
result[i] = getCreditManagerData(creditManagers[i]);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/// @dev Returns CreditManagerData for a particular _cm
|
|
311
|
-
/// @param _cm CreditManager address
|
|
312
|
-
function getCreditManagerData(address _cm) public view returns (CreditManagerData memory result) {
|
|
313
|
-
ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
|
|
314
|
-
ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
|
|
315
|
-
ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
|
|
316
|
-
|
|
317
|
-
result.addr = _cm;
|
|
318
|
-
result.name = _getName(_cm);
|
|
319
|
-
result.cfVersion = _getVersion(address(creditFacade));
|
|
320
|
-
|
|
321
|
-
result.creditFacade = address(creditFacade);
|
|
322
|
-
result.creditConfigurator = address(creditConfigurator);
|
|
323
|
-
|
|
324
|
-
result.underlying = _getUnderlying(creditManager);
|
|
325
|
-
|
|
326
|
-
{
|
|
327
|
-
result.pool = _getPool(_cm);
|
|
328
|
-
IPoolV3 pool = IPoolV3(result.pool);
|
|
329
|
-
result.totalDebt = pool.creditManagerBorrowed(_cm);
|
|
330
|
-
result.totalDebtLimit = pool.creditManagerDebtLimit(_cm);
|
|
331
|
-
|
|
332
|
-
result.baseBorrowRate = _getBaseInterestRate(address(pool));
|
|
333
|
-
result.availableToBorrow = pool.creditManagerBorrowable(_cm);
|
|
334
|
-
// result.lirm = _getInterestRateModel(address(pool));
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
(result.minDebt, result.maxDebt) = creditFacade.debtLimits();
|
|
338
|
-
|
|
339
|
-
{
|
|
340
|
-
uint256 collateralTokenCount = _getCollateralTokensCount(address(creditManager));
|
|
341
|
-
|
|
342
|
-
result.collateralTokens = new address[](collateralTokenCount);
|
|
343
|
-
result.liquidationThresholds = new uint256[](collateralTokenCount);
|
|
344
|
-
|
|
345
|
-
unchecked {
|
|
346
|
-
for (uint256 i = 0; i < collateralTokenCount; ++i) {
|
|
347
|
-
(result.collateralTokens[i], result.liquidationThresholds[i]) =
|
|
348
|
-
creditManager.collateralTokenByMask(1 << i);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
address[] memory allowedAdapters = creditConfigurator.allowedAdapters();
|
|
354
|
-
uint256 len = allowedAdapters.length;
|
|
355
|
-
result.adapters = new ContractAdapter[](len);
|
|
356
|
-
|
|
357
|
-
unchecked {
|
|
358
|
-
for (uint256 i = 0; i < len; ++i) {
|
|
359
|
-
address allowedAdapter = allowedAdapters[i];
|
|
360
|
-
|
|
361
|
-
result.adapters[i] = ContractAdapter({
|
|
362
|
-
targetContract: creditManager.adapterToContract(allowedAdapter),
|
|
363
|
-
adapter: allowedAdapter
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
result.degenNFT = creditFacade.degenNFT();
|
|
369
|
-
result.isDegenMode = result.degenNFT != address(0);
|
|
370
|
-
// (, result.isIncreaseDebtForbidden,,) = creditFacade.params(); // V2 only: true if increasing debt is forbidden
|
|
371
|
-
result.forbiddenTokenMask = creditFacade.forbiddenTokenMask(); // V2 only: mask which forbids some particular tokens
|
|
372
|
-
result.maxEnabledTokensLength = creditManager.maxEnabledTokens(); // V2 only: a limit on enabled tokens imposed for security
|
|
373
|
-
{
|
|
374
|
-
(
|
|
375
|
-
result.feeInterest,
|
|
376
|
-
result.feeLiquidation,
|
|
377
|
-
result.liquidationDiscount,
|
|
378
|
-
result.feeLiquidationExpired,
|
|
379
|
-
result.liquidationDiscountExpired
|
|
380
|
-
) = creditManager.fees();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
result.quotas = _getQuotas(result.pool);
|
|
384
|
-
|
|
385
|
-
result.isPaused = _getPaused(address(creditFacade));
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/// @dev Returns PoolData for a particular pool
|
|
389
|
-
/// @param _pool Pool address
|
|
390
|
-
function getPoolData(address _pool) public view registeredPoolOnly(_pool) returns (PoolData memory result) {
|
|
391
|
-
PoolV3 pool = PoolV3(_pool);
|
|
392
|
-
|
|
393
|
-
result.addr = _pool;
|
|
394
|
-
result.expectedLiquidity = pool.expectedLiquidity();
|
|
395
|
-
result.availableLiquidity = pool.availableLiquidity();
|
|
396
|
-
|
|
397
|
-
result.dieselRate_RAY = pool.convertToAssets(RAY);
|
|
398
|
-
result.baseInterestIndex = pool.baseInterestIndex();
|
|
399
|
-
result.baseInterestRate = _getBaseInterestRate(address(pool));
|
|
400
|
-
result.underlying = pool.underlyingToken();
|
|
401
|
-
result.dieselToken = address(pool);
|
|
402
|
-
(result.symbol, result.name) = _getSymbolAndName(_pool);
|
|
403
|
-
|
|
404
|
-
result.dieselRate_RAY = pool.convertToAssets(RAY);
|
|
405
|
-
result.withdrawFee = pool.withdrawFee();
|
|
406
|
-
result.baseInterestIndexLU = pool.baseInterestIndexLU();
|
|
407
|
-
result.lastBaseInterestUpdate = pool.lastBaseInterestUpdate();
|
|
408
|
-
// result.cumulativeIndex_RAY = pool.calcLinearCumulative_RAY();
|
|
409
|
-
|
|
410
|
-
// Borrowing limits
|
|
411
|
-
result.totalBorrowed = pool.totalBorrowed();
|
|
412
|
-
result.totalDebtLimit = pool.totalDebtLimit();
|
|
413
|
-
|
|
414
|
-
address[] memory creditManagers = pool.creditManagers();
|
|
415
|
-
uint256 len = creditManagers.length;
|
|
416
|
-
result.creditManagerDebtParams = new CreditManagerDebtParams[](len);
|
|
417
|
-
|
|
418
|
-
unchecked {
|
|
419
|
-
for (uint256 i; i < len; ++i) {
|
|
420
|
-
address creditManager = creditManagers[i];
|
|
421
|
-
result.creditManagerDebtParams[i] = CreditManagerDebtParams({
|
|
422
|
-
creditManager: creditManager,
|
|
423
|
-
borrowed: pool.creditManagerBorrowed(creditManager),
|
|
424
|
-
limit: pool.creditManagerDebtLimit(creditManager),
|
|
425
|
-
availableToBorrow: pool.creditManagerBorrowable(creditManager)
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
result.totalSupply = pool.totalSupply();
|
|
431
|
-
result.totalAssets = pool.totalAssets();
|
|
432
|
-
result.supplyRate = pool.supplyRate();
|
|
433
|
-
|
|
434
|
-
result.version = _getVersion(address(pool));
|
|
435
|
-
|
|
436
|
-
result.quotas = _getQuotas(_pool);
|
|
437
|
-
// result.lirm = _getInterestRateModel(_pool);
|
|
438
|
-
result.isPaused = _getPaused(_pool);
|
|
439
|
-
|
|
440
|
-
// Adding zappers
|
|
441
|
-
address[] memory zappers = zapperRegister.zappers(address(pool));
|
|
442
|
-
len = zappers.length;
|
|
443
|
-
result.zappers = new ZapperInfo[](len);
|
|
444
|
-
|
|
445
|
-
unchecked {
|
|
446
|
-
for (uint256 i; i < len; ++i) {
|
|
447
|
-
address tokenIn = IZapper(zappers[i]).tokenIn();
|
|
448
|
-
address tokenOut = IZapper(zappers[i]).tokenOut();
|
|
449
|
-
result.zappers[i] = ZapperInfo({tokenIn: tokenIn, tokenOut: tokenOut, zapper: zappers[i]});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
result.poolQuotaKeeper = address(_getPoolQuotaKeeper(_pool));
|
|
454
|
-
result.gauge = _getGauge(IPoolQuotaKeeperV3(result.poolQuotaKeeper));
|
|
455
|
-
|
|
456
|
-
return result;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/// @dev Returns PoolData for all registered pools
|
|
460
|
-
function getPoolsV3List() external view returns (PoolData[] memory result) {
|
|
461
|
-
address[] memory poolsV3 = _listPoolsV3();
|
|
462
|
-
uint256 len = poolsV3.length;
|
|
463
|
-
result = new PoolData[](len);
|
|
464
|
-
|
|
465
|
-
unchecked {
|
|
466
|
-
for (uint256 i = 0; i < len; ++i) {
|
|
467
|
-
result[i] = getPoolData(poolsV3[i]);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function _listPoolsV3() internal view returns (address[] memory result) {
|
|
473
|
-
address[] memory pools = IContractsRegister(contractsRegister).getPools();
|
|
474
|
-
uint256 maxPools = pools.length;
|
|
475
|
-
|
|
476
|
-
result = new address[](maxPools);
|
|
477
|
-
uint256 numPools;
|
|
478
|
-
|
|
479
|
-
for (uint256 i; i < maxPools; ++i) {
|
|
480
|
-
address pool = pools[i];
|
|
481
|
-
if (!_isContractV3(pool)) continue;
|
|
482
|
-
result[numPools++] = pool;
|
|
483
|
-
}
|
|
484
|
-
assembly {
|
|
485
|
-
mstore(result, numPools)
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function _updatePrices(address, PriceUpdate[] memory priceUpdates) internal {
|
|
490
|
-
for (uint256 i; i < priceUpdates.length; ++i) {
|
|
491
|
-
IUpdatablePriceFeed(priceUpdates[i].priceFeed).updatePrice(priceUpdates[i].data);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function _getPriceFeedFailedList(address _cm, TokenBalance[] memory balances)
|
|
496
|
-
internal
|
|
497
|
-
view
|
|
498
|
-
returns (address[] memory priceFeedFailed)
|
|
499
|
-
{
|
|
500
|
-
uint256 len = balances.length;
|
|
501
|
-
|
|
502
|
-
IPriceOracleV3 priceOracle = _getPriceOracle(_cm);
|
|
503
|
-
|
|
504
|
-
uint256 index;
|
|
505
|
-
|
|
506
|
-
/// It counts on the first iteration how many price feeds failed and then fill the array on the second iteration
|
|
507
|
-
for (uint256 op = COUNT; op <= QUERY; ++op) {
|
|
508
|
-
if (op == QUERY && index == 0) {
|
|
509
|
-
break;
|
|
510
|
-
} else {
|
|
511
|
-
priceFeedFailed = new address[](index);
|
|
512
|
-
index = 0;
|
|
513
|
-
}
|
|
514
|
-
unchecked {
|
|
515
|
-
for (uint256 i = 0; i < len; ++i) {
|
|
516
|
-
TokenBalance memory balance = balances[i];
|
|
517
|
-
|
|
518
|
-
if (balance.balance > 1 && balance.isEnabled) {
|
|
519
|
-
try priceOracle.getPrice(balance.token) returns (uint256) {}
|
|
520
|
-
catch {
|
|
521
|
-
if (op == QUERY) priceFeedFailed[index] = balance.token;
|
|
522
|
-
++index;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function _getPoolQuotaKeeper(address pool) internal view returns (IPoolQuotaKeeperV3) {
|
|
531
|
-
return IPoolQuotaKeeperV3(IPoolV3(pool).poolQuotaKeeper());
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
function _getPriceOracle(address _cm) internal view returns (IPriceOracleV3) {
|
|
535
|
-
return IPriceOracleV3(ICreditManagerV3(_cm).priceOracle());
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function _getBaseInterestRate(address pool) internal view returns (uint256) {
|
|
539
|
-
return IPoolV3(pool).baseInterestRate();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function _getAccountOwner(address cm, address creditAccount) internal view returns (address) {
|
|
543
|
-
return ICreditManagerV3(cm).getBorrowerOrRevert(creditAccount);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function _isLiquidatable(address cm, address creditAccount) internal view returns (bool) {
|
|
547
|
-
try ICreditManagerV3(cm).isLiquidatable(creditAccount, PERCENTAGE_FACTOR) returns (bool value) {
|
|
548
|
-
return value;
|
|
549
|
-
} catch {
|
|
550
|
-
return true;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function _getVersion(address versionedContract) internal view returns (uint256) {
|
|
555
|
-
return IVersion(versionedContract).version();
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function _getCreditFacade(address cm) internal view returns (ICreditFacadeV3) {
|
|
559
|
-
return ICreditFacadeV3(ICreditManagerV3(cm).creditFacade());
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function _getSymbolAndName(address token) internal view returns (string memory symbol, string memory name) {
|
|
563
|
-
symbol = IERC20Metadata(token).symbol();
|
|
564
|
-
name = _getName(token);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// function _getInterestRateModel(address pool) internal view returns (LinearModel memory) {
|
|
568
|
-
// return address(0); //getLIRMData(IPoolV3(pool).interestRateModel());
|
|
569
|
-
// }
|
|
570
|
-
|
|
571
|
-
function _getQuotedTokens(IPoolQuotaKeeperV3 pqk) internal view returns (address[] memory result) {
|
|
572
|
-
result = pqk.quotedTokens();
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
function _getPool(address cnt) internal view returns (address) {
|
|
576
|
-
return ICreditManagerV3(cnt).pool();
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
function _getName(address _cm) internal view returns (string memory) {
|
|
580
|
-
return IERC20Metadata(_cm).name();
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function _getCollateralTokensCount(address _cm) internal view returns (uint256) {
|
|
584
|
-
return ICreditManagerV3(_cm).collateralTokensCount();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function _getGauge(IPoolQuotaKeeperV3 pqk) internal view returns (address) {
|
|
588
|
-
return pqk.gauge();
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
function _getPaused(address pausableContract) internal view returns (bool) {
|
|
592
|
-
return Pausable(pausableContract).paused();
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
function _getUnderlying(ICreditManagerV3 cm) internal view returns (address) {
|
|
596
|
-
return cm.underlying();
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function _getQuotas(address _pool) internal view returns (QuotaInfo[] memory quotas) {
|
|
600
|
-
IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(_pool);
|
|
601
|
-
|
|
602
|
-
address[] memory quotaTokens = _getQuotedTokens(pqk);
|
|
603
|
-
uint256 len = quotaTokens.length;
|
|
604
|
-
quotas = new QuotaInfo[](len);
|
|
605
|
-
unchecked {
|
|
606
|
-
for (uint256 i; i < len; ++i) {
|
|
607
|
-
quotas[i].token = quotaTokens[i];
|
|
608
|
-
(
|
|
609
|
-
quotas[i].rate,
|
|
610
|
-
,
|
|
611
|
-
quotas[i].quotaIncreaseFee,
|
|
612
|
-
quotas[i].totalQuoted,
|
|
613
|
-
quotas[i].limit,
|
|
614
|
-
quotas[i].isActive
|
|
615
|
-
) = pqk.getTokenQuotaParams(quotaTokens[i]);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function getGaugesV3Data(address staker) external view override returns (GaugeInfo[] memory result) {
|
|
621
|
-
address[] memory poolsV3 = _listPoolsV3();
|
|
622
|
-
uint256 len = poolsV3.length;
|
|
623
|
-
result = new GaugeInfo[](len);
|
|
624
|
-
|
|
625
|
-
unchecked {
|
|
626
|
-
for (uint256 i; i < len; ++i) {
|
|
627
|
-
GaugeInfo memory gaugeInfo = result[i];
|
|
628
|
-
IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(poolsV3[i]);
|
|
629
|
-
address gauge = _getGauge(pqk);
|
|
630
|
-
gaugeInfo.addr = gauge;
|
|
631
|
-
gaugeInfo.pool = _getPool(gauge);
|
|
632
|
-
(gaugeInfo.symbol, gaugeInfo.name) = _getSymbolAndName(gaugeInfo.pool);
|
|
633
|
-
gaugeInfo.underlying = IPoolV3(gaugeInfo.pool).asset();
|
|
634
|
-
|
|
635
|
-
address[] memory quotaTokens = _getQuotedTokens(pqk);
|
|
636
|
-
uint256 quotaTokensLen = quotaTokens.length;
|
|
637
|
-
gaugeInfo.quotaParams = new GaugeQuotaParams[](quotaTokensLen);
|
|
638
|
-
|
|
639
|
-
gaugeInfo.currentEpoch = IGaugeV3(gauge).epochLastUpdate();
|
|
640
|
-
gaugeInfo.epochFrozen = IGaugeV3(gauge).epochFrozen();
|
|
641
|
-
|
|
642
|
-
for (uint256 j; j < quotaTokensLen; ++j) {
|
|
643
|
-
GaugeQuotaParams memory quotaParams = gaugeInfo.quotaParams[j];
|
|
644
|
-
address token = quotaTokens[j];
|
|
645
|
-
quotaParams.token = token;
|
|
646
|
-
|
|
647
|
-
(
|
|
648
|
-
quotaParams.rate,
|
|
649
|
-
,
|
|
650
|
-
quotaParams.quotaIncreaseFee,
|
|
651
|
-
quotaParams.totalQuoted,
|
|
652
|
-
quotaParams.limit,
|
|
653
|
-
quotaParams.isActive
|
|
654
|
-
) = pqk.getTokenQuotaParams(token);
|
|
655
|
-
|
|
656
|
-
(
|
|
657
|
-
quotaParams.minRate,
|
|
658
|
-
quotaParams.maxRate,
|
|
659
|
-
quotaParams.totalVotesLpSide,
|
|
660
|
-
quotaParams.totalVotesCaSide
|
|
661
|
-
) = IGaugeV3(gauge).quotaRateParams(token);
|
|
662
|
-
|
|
663
|
-
(quotaParams.stakerVotesLpSide, quotaParams.stakerVotesCaSide) =
|
|
664
|
-
IGaugeV3(gauge).userTokenVotes(staker, token);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2023
|
|
4
|
-
pragma solidity ^0.8.10;
|
|
5
|
-
|
|
6
|
-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
7
|
-
import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
|
|
8
|
-
import {IZapperRegister} from "../interfaces/IZapperRegister.sol";
|
|
9
|
-
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
|
|
10
|
-
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
11
|
-
import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";
|
|
12
|
-
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
|
|
13
|
-
|
|
14
|
-
contract ZapperRegister is ContractsRegisterTrait, SanityCheckTrait, ACLTrait, IZapperRegister {
|
|
15
|
-
using EnumerableSet for EnumerableSet.AddressSet;
|
|
16
|
-
|
|
17
|
-
// Contract version
|
|
18
|
-
uint256 public constant version = 3_00;
|
|
19
|
-
|
|
20
|
-
mapping(address => EnumerableSet.AddressSet) internal _zappersMap;
|
|
21
|
-
|
|
22
|
-
constructor(address acl, address contractsRegister) ACLTrait(acl) ContractsRegisterTrait(contractsRegister) {}
|
|
23
|
-
|
|
24
|
-
function addZapper(address zapper) external nonZeroAddress(zapper) configuratorOnly {
|
|
25
|
-
address pool = IZapper(zapper).pool();
|
|
26
|
-
_ensureRegisteredPool(pool);
|
|
27
|
-
|
|
28
|
-
EnumerableSet.AddressSet storage zapperSet = _zappersMap[pool];
|
|
29
|
-
if (!zapperSet.contains(zapper)) {
|
|
30
|
-
zapperSet.add(zapper);
|
|
31
|
-
emit AddZapper(zapper);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function removeZapper(address zapper) external nonZeroAddress(zapper) configuratorOnly {
|
|
36
|
-
EnumerableSet.AddressSet storage zapperSet = _zappersMap[IZapper(zapper).pool()];
|
|
37
|
-
if (zapperSet.contains(zapper)) {
|
|
38
|
-
zapperSet.remove(zapper);
|
|
39
|
-
emit RemoveZapper(zapper);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function zappers(address pool) external view override returns (address[] memory) {
|
|
44
|
-
return _zappersMap[pool].values();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2023
|
|
4
|
-
pragma solidity ^0.8.10;
|
|
5
|
-
|
|
6
|
-
import {CreditAccountData, CreditManagerData, PoolData, GaugeInfo} from "../data/Types.sol";
|
|
7
|
-
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
|
|
8
|
-
|
|
9
|
-
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
|
|
10
|
-
|
|
11
|
-
interface IDataCompressorV3 is IVersion {
|
|
12
|
-
/// @dev Returns CreditAccountData for all opened accounts for particular borrower
|
|
13
|
-
/// @param borrower Borrower address
|
|
14
|
-
/// @param priceUpdates Price updates for price on demand oracles
|
|
15
|
-
function getCreditAccountsByBorrower(address borrower, PriceUpdate[] memory priceUpdates)
|
|
16
|
-
external
|
|
17
|
-
returns (CreditAccountData[] memory);
|
|
18
|
-
|
|
19
|
-
/// @dev Returns CreditAccountData for all opened accounts for particular borrower
|
|
20
|
-
/// @param creditManager Address
|
|
21
|
-
/// @param priceUpdates Price updates for price on demand oracles
|
|
22
|
-
function getCreditAccountsByCreditManager(address creditManager, PriceUpdate[] memory priceUpdates)
|
|
23
|
-
external
|
|
24
|
-
returns (CreditAccountData[] memory);
|
|
25
|
-
|
|
26
|
-
/// @dev Returns CreditAccountData for all accounts with hf <1
|
|
27
|
-
/// @param priceUpdates Price updates for price on demand oracles
|
|
28
|
-
function getLiquidatableCreditAccounts(PriceUpdate[] memory priceUpdates)
|
|
29
|
-
external
|
|
30
|
-
returns (CreditAccountData[] memory result);
|
|
31
|
-
|
|
32
|
-
/// @dev Returns CreditAccountData for a particular Credit Account account, based on creditManager and borrower
|
|
33
|
-
/// @param creditAccount Address of credit account
|
|
34
|
-
/// @param priceUpdates Price updates for price on demand oracles
|
|
35
|
-
function getCreditAccountData(address creditAccount, PriceUpdate[] memory priceUpdates)
|
|
36
|
-
external
|
|
37
|
-
returns (CreditAccountData memory);
|
|
38
|
-
|
|
39
|
-
/// @dev Returns CreditManagerData for all Credit Managers
|
|
40
|
-
function getCreditManagersV3List() external view returns (CreditManagerData[] memory);
|
|
41
|
-
|
|
42
|
-
/// @dev Returns CreditManagerData for a particular _creditManager
|
|
43
|
-
/// @param creditManager CreditManager address
|
|
44
|
-
function getCreditManagerData(address creditManager) external view returns (CreditManagerData memory);
|
|
45
|
-
|
|
46
|
-
/// @dev Returns PoolData for a particular pool
|
|
47
|
-
/// @param _pool Pool address
|
|
48
|
-
function getPoolData(address _pool) external view returns (PoolData memory);
|
|
49
|
-
|
|
50
|
-
/// @dev Returns PoolData for all registered pools
|
|
51
|
-
function getPoolsV3List() external view returns (PoolData[] memory);
|
|
52
|
-
|
|
53
|
-
/// @dev Returns GaugeInfo for all registered gauges
|
|
54
|
-
function getGaugesV3Data(address staker) external view returns (GaugeInfo[] memory result);
|
|
55
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2023
|
|
4
|
-
pragma solidity ^0.8.10;
|
|
5
|
-
|
|
6
|
-
interface IZapperRegister {
|
|
7
|
-
event AddZapper(address);
|
|
8
|
-
event RemoveZapper(address);
|
|
9
|
-
|
|
10
|
-
function zappers(address pool) external view returns (address[] memory);
|
|
11
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Foundation, 2023.
|
|
4
|
-
pragma solidity ^0.8.17;
|
|
5
|
-
|
|
6
|
-
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
7
|
-
|
|
8
|
-
import {PriceUpdate} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeedStore.sol";
|
|
9
|
-
|
|
10
|
-
import {DataCompressorV3} from "../data/DataCompressorV3.sol";
|
|
11
|
-
import {IDataCompressorV3} from "../interfaces/IDataCompressorV3.sol";
|
|
12
|
-
import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter} from "../data/Types.sol";
|
|
13
|
-
|
|
14
|
-
import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
|
|
15
|
-
|
|
16
|
-
import "forge-std/console.sol";
|
|
17
|
-
|
|
18
|
-
address constant ap = 0x9ea7b04Da02a5373317D745c1571c84aaD03321D;
|
|
19
|
-
|
|
20
|
-
contract DCTest {
|
|
21
|
-
DataCompressorV3 public dc3;
|
|
22
|
-
|
|
23
|
-
uint256 chainId;
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
NetworkDetector nd = new NetworkDetector();
|
|
27
|
-
chainId = nd.chainId();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
modifier liveTestOnly() {
|
|
31
|
-
if (chainId == 1) {
|
|
32
|
-
_;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function setUp() public liveTestOnly {
|
|
37
|
-
dc3 = new DataCompressorV3(ap);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _printPools(PoolData[] memory pools) internal view {
|
|
41
|
-
uint256 len = pools.length;
|
|
42
|
-
unchecked {
|
|
43
|
-
for (uint256 i; i < len; ++i) {
|
|
44
|
-
PoolData memory pool = pools[i];
|
|
45
|
-
console.log("\n\n");
|
|
46
|
-
console.log(IERC20Metadata(pool.underlying).symbol(), pool.addr);
|
|
47
|
-
console.log("-------------------------------");
|
|
48
|
-
|
|
49
|
-
console.log("dieselToken: ", pool.dieselToken);
|
|
50
|
-
///
|
|
51
|
-
console.log("baseInterestIndex: ", pool.baseInterestIndex);
|
|
52
|
-
console.log("availableLiquidity: ", pool.availableLiquidity);
|
|
53
|
-
console.log("expectedLiquidity: ", pool.expectedLiquidity);
|
|
54
|
-
//
|
|
55
|
-
console.log("totalBorrowed: ", pool.totalBorrowed);
|
|
56
|
-
console.log("totalDebtLimit: ", pool.totalDebtLimit);
|
|
57
|
-
// CreditManagerDebtParams[] creditManagerDebtParams;
|
|
58
|
-
console.log("totalAssets: ", pool.totalAssets);
|
|
59
|
-
console.log("totalSupply: ", pool.totalSupply);
|
|
60
|
-
console.log("supplyRate", pool.supplyRate);
|
|
61
|
-
console.log("baseInterestRate: ", pool.baseInterestRate);
|
|
62
|
-
console.log("dieselRate_RAY: ", pool.dieselRate_RAY);
|
|
63
|
-
console.log("withdrawFee", pool.withdrawFee);
|
|
64
|
-
console.log("lastBaseInterestUpdate:", pool.lastBaseInterestUpdate);
|
|
65
|
-
console.log("baseInterestIndexLU:", pool.baseInterestIndexLU);
|
|
66
|
-
console.log("version: ", pool.version);
|
|
67
|
-
// QuotaInfo[] quotas;
|
|
68
|
-
// LinearModel lirm;
|
|
69
|
-
console.log("isPaused", pool.isPaused);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function _printCreditManagers(CreditManagerData[] memory cms) internal view {
|
|
75
|
-
uint256 len = cms.length;
|
|
76
|
-
unchecked {
|
|
77
|
-
for (uint256 i; i < len; ++i) {
|
|
78
|
-
CreditManagerData memory cm = cms[i];
|
|
79
|
-
console.log("\n\n");
|
|
80
|
-
console.log(IERC20Metadata(cm.underlying).symbol(), cm.addr);
|
|
81
|
-
console.log("-------------------------------");
|
|
82
|
-
console.log("cfVersion: ", cm.cfVersion);
|
|
83
|
-
console.log("creditFacace: ", cm.creditFacade); // V2 only: address of creditFacade
|
|
84
|
-
console.log("creditConfigurator: ", cm.creditConfigurator); // V2 only: address of creditConfigurator
|
|
85
|
-
console.log("pool: ", cm.pool);
|
|
86
|
-
console.log("totalDebt: ", cm.totalDebt);
|
|
87
|
-
console.log("totalDebtLimit: ", cm.totalDebtLimit);
|
|
88
|
-
console.log("baseBorrowRate: ", cm.baseBorrowRate);
|
|
89
|
-
console.log("minDebt: ", cm.minDebt);
|
|
90
|
-
console.log("maxDebt: ", cm.maxDebt);
|
|
91
|
-
console.log("availableToBorrow: ", cm.availableToBorrow);
|
|
92
|
-
// address[] collateralTokens);
|
|
93
|
-
// ContractAdapter[] adapters);
|
|
94
|
-
// uint256[] liquidationThresholds);
|
|
95
|
-
console.log("isDegenMode: ", cm.isDegenMode); // V2 only: true if contract is in Degen mode
|
|
96
|
-
console.log("degenNFT: ", cm.degenNFT); // V2 only: degenNFT, address(0) if not in degen mode
|
|
97
|
-
console.log("forbiddenTokenMask: ", cm.forbiddenTokenMask); // V2 only: mask which forbids some particular tokens
|
|
98
|
-
console.log("maxEnabledTokensLength: ", cm.maxEnabledTokensLength); // V2 only: in V1 as many tokens as the CM can support (256)
|
|
99
|
-
console.log("feeInterest: ", cm.feeInterest); // Interest fee protocol charges: fee = interest accrues * feeInterest
|
|
100
|
-
console.log("feeLiquidation: ", cm.feeLiquidation); // Liquidation fee protocol charges: fee = totalValue * feeLiquidation
|
|
101
|
-
console.log("liquidationDiscount: ", cm.liquidationDiscount); // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
|
|
102
|
-
console.log("feeLiquidationExpired: ", cm.feeLiquidationExpired); // Liquidation fee protocol charges on expired accounts
|
|
103
|
-
console.log("liquidationDiscountExpired: ", cm.liquidationDiscountExpired); // Multiplier for the amount the liquidator has to pay when closing an expired account
|
|
104
|
-
// V3 Fileds
|
|
105
|
-
// QuotaInfo[] quotas);
|
|
106
|
-
// LinearModel lirm);
|
|
107
|
-
console.log("sPaused: ", cm.isPaused);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function test_dc_01_pools() public view liveTestOnly {
|
|
113
|
-
PoolData[] memory pools = dc3.getPoolsV3List();
|
|
114
|
-
console.log("\nV3 pools");
|
|
115
|
-
_printPools(pools);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function test_dc_02_credit_managers() public view liveTestOnly {
|
|
119
|
-
CreditManagerData[] memory cms = dc3.getCreditManagersV3List();
|
|
120
|
-
console.log("\n\nV3 credit managers");
|
|
121
|
-
_printCreditManagers(cms);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function test_dc_03_credit_accounts() public liveTestOnly {
|
|
125
|
-
CreditAccountData[] memory cas = dc3.getCreditAccountsByBorrower(address(this), new PriceUpdate[](0));
|
|
126
|
-
console.log("V3 credit accounts", cas.length);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// function test_dc_04_borrower() public liveTestOnly {
|
|
130
|
-
// dc3.getCreditAccountsByBorrower(0xf13df765f3047850Cede5aA9fDF20a12A75f7F70, new PriceUpdate[](0));
|
|
131
|
-
// }
|
|
132
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Foundation, 2024.
|
|
4
|
-
pragma solidity ^0.8.17;
|
|
5
|
-
|
|
6
|
-
/// @title ERC20Metadata
|
|
7
|
-
contract ERC20Metadata {
|
|
8
|
-
string public name;
|
|
9
|
-
string public symbol;
|
|
10
|
-
uint8 public immutable decimals;
|
|
11
|
-
|
|
12
|
-
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
|
|
13
|
-
name = name_;
|
|
14
|
-
symbol = symbol_;
|
|
15
|
-
decimals = decimals_;
|
|
16
|
-
}
|
|
17
|
-
}
|