@venusprotocol/protocol-reserve 1.0.0-dev.5 → 1.0.0-dev.7

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.
Files changed (182) hide show
  1. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
  2. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  3. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +2 -2
  4. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  5. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  6. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  7. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
  8. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  9. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  10. package/artifacts/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol/ReentrancyGuardUpgradeable.dbg.json +1 -1
  11. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol/IERC20Upgradeable.dbg.json +1 -1
  12. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.dbg.json +4 -0
  13. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/{draft-IERC20PermitUpgradeable.sol → IERC20PermitUpgradeable.sol}/IERC20PermitUpgradeable.json +1 -1
  14. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol/SafeERC20Upgradeable.dbg.json +1 -1
  15. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol/SafeERC20Upgradeable.json +2 -2
  16. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  17. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +2 -2
  18. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  19. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
  20. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
  21. package/artifacts/@venusprotocol/isolated-pools/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.dbg.json +1 -1
  22. package/artifacts/build-info/5e0d0fa03533470b2e430f8020bc271c.json +1 -0
  23. package/artifacts/contracts/Interfaces/ComptrollerInterface.sol/ComptrollerInterface.dbg.json +1 -1
  24. package/artifacts/contracts/Interfaces/IIncomeDestination.sol/IIncomeDestination.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces/IProtocolShareReserve.sol/IProtocolShareReserve.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces/IVToken.sol/IVToken.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces/PoolRegistryInterface.sol/PoolRegistryInterface.dbg.json +1 -1
  28. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.dbg.json +1 -1
  29. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.json +91 -56
  30. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.dbg.json +1 -1
  31. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.json +2 -2
  32. package/contracts/Interfaces/IProtocolShareReserve.sol +5 -1
  33. package/contracts/ProtocolReserve/ProtocolShareReserve.sol +106 -89
  34. package/contracts/Test/Mocks/MockToken.sol +5 -1
  35. package/deploy/1-deploy.ts +64 -0
  36. package/deployments/bscmainnet/.chainId +1 -0
  37. package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
  38. package/deployments/bscmainnet/ProtocolShareReserve.json +1054 -0
  39. package/deployments/bscmainnet/ProtocolShareReserve_Implementation.json +1264 -0
  40. package/deployments/bscmainnet/ProtocolShareReserve_Proxy.json +277 -0
  41. package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  42. package/deployments/bscmainnet/solcInputs/45a7e25696ff2229490239636d073de0.json +90 -0
  43. package/deployments/bscmainnet/solcInputs/c87a4970e440c0598abee31750358915.json +90 -0
  44. package/deployments/bscmainnet/solcInputs/f7c7133e4506082d7aa8242a8f52a4c9.json +87 -0
  45. package/deployments/bsctestnet/.chainId +1 -0
  46. package/deployments/bsctestnet/DefaultProxyAdmin.json +257 -0
  47. package/deployments/bsctestnet/ProtocolShareReserve.json +1054 -0
  48. package/deployments/bsctestnet/ProtocolShareReserve_Implementation.json +1264 -0
  49. package/deployments/bsctestnet/ProtocolShareReserve_Proxy.json +277 -0
  50. package/deployments/bsctestnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  51. package/deployments/bsctestnet/solcInputs/45a7e25696ff2229490239636d073de0.json +90 -0
  52. package/deployments/bsctestnet/solcInputs/c87a4970e440c0598abee31750358915.json +90 -0
  53. package/deployments/bsctestnet/solcInputs/f7c7133e4506082d7aa8242a8f52a4c9.json +87 -0
  54. package/package.json +56 -61
  55. package/typechain/{@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.ts → AccessControlledV8.d.ts} +125 -128
  56. package/typechain/ComptrollerInterface.d.ts +101 -0
  57. package/typechain/ContextUpgradeable.d.ts +92 -0
  58. package/typechain/ERC20.d.ts +441 -0
  59. package/typechain/IAccessControl.d.ts +333 -0
  60. package/typechain/IAccessControlManagerV8.d.ts +504 -0
  61. package/typechain/IERC20.d.ts +324 -0
  62. package/typechain/{@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.ts → IERC20Metadata.d.ts} +146 -169
  63. package/typechain/IERC20PermitUpgradeable.d.ts +187 -0
  64. package/typechain/IERC20Upgradeable.d.ts +324 -0
  65. package/typechain/IIncomeDestination.d.ts +122 -0
  66. package/typechain/IProtocolShareReserve.d.ts +127 -0
  67. package/typechain/IVToken.d.ts +98 -0
  68. package/typechain/Initializable.d.ts +92 -0
  69. package/typechain/MaxLoopsLimitHelper.d.ts +128 -0
  70. package/typechain/MockToken.d.ts +469 -0
  71. package/typechain/{@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.ts → Ownable2StepUpgradeable.d.ts} +102 -105
  72. package/typechain/OwnableUpgradeable.d.ts +193 -0
  73. package/typechain/PoolRegistryInterface.d.ts +121 -0
  74. package/typechain/{contracts/ProtocolReserve/ProtocolShareReserve.ts → ProtocolShareReserve.d.ts} +566 -474
  75. package/typechain/ReentrancyGuardUpgradeable.d.ts +92 -0
  76. package/typechain/common.d.ts +35 -0
  77. package/typechain/factories/{@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8__factory.ts → AccessControlledV8__factory.ts} +5 -6
  78. package/typechain/factories/{contracts/Interfaces/ComptrollerInterface__factory.ts → ComptrollerInterface__factory.ts} +5 -6
  79. package/typechain/factories/{@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable__factory.ts → ContextUpgradeable__factory.ts} +5 -6
  80. package/typechain/factories/{@openzeppelin/contracts/token/ERC20/ERC20__factory.ts → ERC20__factory.ts} +21 -33
  81. package/typechain/factories/{@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8__factory.ts → IAccessControlManagerV8__factory.ts} +5 -6
  82. package/typechain/factories/{@openzeppelin/contracts/access/IAccessControl__factory.ts → IAccessControl__factory.ts} +5 -6
  83. package/typechain/factories/{@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata__factory.ts → IERC20Metadata__factory.ts} +5 -6
  84. package/typechain/factories/{@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable__factory.ts → IERC20PermitUpgradeable__factory.ts} +5 -6
  85. package/typechain/factories/{@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable__factory.ts → IERC20Upgradeable__factory.ts} +5 -6
  86. package/typechain/factories/{@openzeppelin/contracts/token/ERC20/IERC20__factory.ts → IERC20__factory.ts} +4 -8
  87. package/typechain/factories/{contracts/Interfaces/IIncomeDestination__factory.ts → IIncomeDestination__factory.ts} +5 -6
  88. package/typechain/factories/{contracts/Interfaces/IProtocolShareReserve__factory.ts → IProtocolShareReserve__factory.ts} +5 -6
  89. package/typechain/factories/{contracts/Interfaces/IVToken__factory.ts → IVToken__factory.ts} +4 -8
  90. package/typechain/factories/{@openzeppelin/contracts-upgradeable/proxy/utils/Initializable__factory.ts → Initializable__factory.ts} +4 -8
  91. package/typechain/factories/{@venusprotocol/isolated-pools/contracts/MaxLoopsLimitHelper__factory.ts → MaxLoopsLimitHelper__factory.ts} +5 -6
  92. package/typechain/factories/{contracts/Test/Mocks/MockToken__factory.ts → MockToken__factory.ts} +24 -36
  93. package/typechain/factories/{@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable__factory.ts → Ownable2StepUpgradeable__factory.ts} +5 -6
  94. package/typechain/factories/{@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable__factory.ts → OwnableUpgradeable__factory.ts} +5 -6
  95. package/typechain/factories/{contracts/Interfaces/PoolRegistryInterface__factory.ts → PoolRegistryInterface__factory.ts} +5 -6
  96. package/typechain/factories/ProtocolShareReserve__factory.ts +869 -0
  97. package/typechain/factories/{@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable__factory.ts → ReentrancyGuardUpgradeable__factory.ts} +5 -6
  98. package/typechain/index.ts +42 -55
  99. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.dbg.json +0 -4
  100. package/artifacts/build-info/5cf1d710d672d6156aed4b51f9ea6217.json +0 -1
  101. package/artifacts/contracts/Interfaces/IPrime.sol/IPrime.dbg.json +0 -4
  102. package/artifacts/contracts/Interfaces/IPrime.sol/IPrime.json +0 -74
  103. package/contracts/Interfaces/IPrime.sol +0 -12
  104. package/contracts/interfaces/IProtocolShareReserve.sol +0 -12
  105. package/contracts/test/Mocks/MockToken.sol +0 -22
  106. package/typechain/@openzeppelin/contracts/access/IAccessControl.ts +0 -343
  107. package/typechain/@openzeppelin/contracts/access/index.ts +0 -4
  108. package/typechain/@openzeppelin/contracts/index.ts +0 -11
  109. package/typechain/@openzeppelin/contracts/token/ERC20/ERC20.ts +0 -466
  110. package/typechain/@openzeppelin/contracts/token/ERC20/IERC20.ts +0 -344
  111. package/typechain/@openzeppelin/contracts/token/ERC20/extensions/index.ts +0 -4
  112. package/typechain/@openzeppelin/contracts/token/ERC20/index.ts +0 -10
  113. package/typechain/@openzeppelin/contracts/token/index.ts +0 -8
  114. package/typechain/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.ts +0 -190
  115. package/typechain/@openzeppelin/contracts-upgradeable/access/index.ts +0 -5
  116. package/typechain/@openzeppelin/contracts-upgradeable/index.ts +0 -20
  117. package/typechain/@openzeppelin/contracts-upgradeable/proxy/index.ts +0 -8
  118. package/typechain/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.ts +0 -72
  119. package/typechain/@openzeppelin/contracts-upgradeable/proxy/utils/index.ts +0 -4
  120. package/typechain/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.ts +0 -72
  121. package/typechain/@openzeppelin/contracts-upgradeable/security/index.ts +0 -4
  122. package/typechain/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.ts +0 -344
  123. package/typechain/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.ts +0 -195
  124. package/typechain/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol/index.ts +0 -4
  125. package/typechain/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/index.ts +0 -8
  126. package/typechain/@openzeppelin/contracts-upgradeable/token/ERC20/index.ts +0 -9
  127. package/typechain/@openzeppelin/contracts-upgradeable/token/index.ts +0 -8
  128. package/typechain/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.ts +0 -72
  129. package/typechain/@openzeppelin/contracts-upgradeable/utils/index.ts +0 -4
  130. package/typechain/@openzeppelin/index.ts +0 -11
  131. package/typechain/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.ts +0 -530
  132. package/typechain/@venusprotocol/governance-contracts/contracts/Governance/index.ts +0 -5
  133. package/typechain/@venusprotocol/governance-contracts/contracts/index.ts +0 -8
  134. package/typechain/@venusprotocol/governance-contracts/index.ts +0 -8
  135. package/typechain/@venusprotocol/index.ts +0 -11
  136. package/typechain/@venusprotocol/isolated-pools/contracts/MaxLoopsLimitHelper.ts +0 -119
  137. package/typechain/@venusprotocol/isolated-pools/contracts/index.ts +0 -4
  138. package/typechain/@venusprotocol/isolated-pools/index.ts +0 -8
  139. package/typechain/common.ts +0 -48
  140. package/typechain/contracts/Interfaces/ComptrollerInterface.ts +0 -90
  141. package/typechain/contracts/Interfaces/IIncomeDestination.ts +0 -112
  142. package/typechain/contracts/Interfaces/IPrime.ts +0 -205
  143. package/typechain/contracts/Interfaces/IProtocolShareReserve.ts +0 -122
  144. package/typechain/contracts/Interfaces/IVToken.ts +0 -87
  145. package/typechain/contracts/Interfaces/PoolRegistryInterface.ts +0 -110
  146. package/typechain/contracts/Interfaces/index.ts +0 -9
  147. package/typechain/contracts/ProtocolReserve/index.ts +0 -4
  148. package/typechain/contracts/Test/Mocks/MockToken.ts +0 -498
  149. package/typechain/contracts/Test/Mocks/index.ts +0 -4
  150. package/typechain/contracts/Test/index.ts +0 -8
  151. package/typechain/contracts/index.ts +0 -14
  152. package/typechain/factories/@openzeppelin/contracts/access/index.ts +0 -4
  153. package/typechain/factories/@openzeppelin/contracts/index.ts +0 -5
  154. package/typechain/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +0 -4
  155. package/typechain/factories/@openzeppelin/contracts/token/ERC20/index.ts +0 -6
  156. package/typechain/factories/@openzeppelin/contracts/token/index.ts +0 -4
  157. package/typechain/factories/@openzeppelin/contracts-upgradeable/access/index.ts +0 -5
  158. package/typechain/factories/@openzeppelin/contracts-upgradeable/index.ts +0 -8
  159. package/typechain/factories/@openzeppelin/contracts-upgradeable/proxy/index.ts +0 -4
  160. package/typechain/factories/@openzeppelin/contracts-upgradeable/proxy/utils/index.ts +0 -4
  161. package/typechain/factories/@openzeppelin/contracts-upgradeable/security/index.ts +0 -4
  162. package/typechain/factories/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol/index.ts +0 -4
  163. package/typechain/factories/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/index.ts +0 -4
  164. package/typechain/factories/@openzeppelin/contracts-upgradeable/token/ERC20/index.ts +0 -5
  165. package/typechain/factories/@openzeppelin/contracts-upgradeable/token/index.ts +0 -4
  166. package/typechain/factories/@openzeppelin/contracts-upgradeable/utils/index.ts +0 -4
  167. package/typechain/factories/@openzeppelin/index.ts +0 -5
  168. package/typechain/factories/@venusprotocol/governance-contracts/contracts/Governance/index.ts +0 -5
  169. package/typechain/factories/@venusprotocol/governance-contracts/contracts/index.ts +0 -4
  170. package/typechain/factories/@venusprotocol/governance-contracts/index.ts +0 -4
  171. package/typechain/factories/@venusprotocol/index.ts +0 -5
  172. package/typechain/factories/@venusprotocol/isolated-pools/contracts/index.ts +0 -4
  173. package/typechain/factories/@venusprotocol/isolated-pools/index.ts +0 -4
  174. package/typechain/factories/contracts/Interfaces/IPrime__factory.ts +0 -87
  175. package/typechain/factories/contracts/Interfaces/index.ts +0 -9
  176. package/typechain/factories/contracts/ProtocolReserve/ProtocolShareReserve__factory.ts +0 -843
  177. package/typechain/factories/contracts/ProtocolReserve/index.ts +0 -4
  178. package/typechain/factories/contracts/Test/Mocks/index.ts +0 -4
  179. package/typechain/factories/contracts/Test/index.ts +0 -4
  180. package/typechain/factories/contracts/index.ts +0 -6
  181. package/typechain/factories/index.ts +0 -6
  182. package/typechain/hardhat.d.ts +0 -231
@@ -9,7 +9,6 @@ import { MaxLoopsLimitHelper } from "@venusprotocol/isolated-pools/contracts/Max
9
9
  import { IProtocolShareReserve } from "../Interfaces/IProtocolShareReserve.sol";
10
10
  import { ComptrollerInterface } from "../Interfaces/ComptrollerInterface.sol";
11
11
  import { PoolRegistryInterface } from "../Interfaces/PoolRegistryInterface.sol";
12
- import { IPrime } from "../Interfaces/IPrime.sol";
13
12
  import { IVToken } from "../Interfaces/IVToken.sol";
14
13
  import { IIncomeDestination } from "../Interfaces/IIncomeDestination.sol";
15
14
 
@@ -27,17 +26,17 @@ contract ProtocolShareReserve is
27
26
  using SafeERC20Upgradeable for IERC20Upgradeable;
28
27
 
29
28
  /// @notice protocol income is categorized into two schemas.
30
- /// The first schema is the default one
31
- /// The second schema is for spread income from prime markets in core protocol
29
+ /// The first schema is for spread income
30
+ /// The second schema is for liquidation income
32
31
  enum Schema {
33
- DEFAULT,
34
- SPREAD_PRIME_CORE
32
+ PROTOCOL_RESERVES,
33
+ ADDITIONAL_REVENUE
35
34
  }
36
35
 
37
36
  struct DistributionConfig {
38
37
  Schema schema;
39
38
  /// @dev percenatge is represented without any scale
40
- uint256 percentage;
39
+ uint8 percentage;
41
40
  address destination;
42
41
  }
43
42
 
@@ -53,13 +52,10 @@ contract ProtocolShareReserve is
53
52
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
54
53
  address public immutable vBNB;
55
54
 
56
- /// @notice address of Prime contract
57
- address public prime;
58
-
59
55
  /// @notice address of pool registry contract
60
56
  address public poolRegistry;
61
57
 
62
- uint256 private constant MAX_PERCENT = 100;
58
+ uint8 public constant MAX_PERCENT = 100;
63
59
 
64
60
  /// @notice comptroller => asset => schema => balance
65
61
  mapping(address => mapping(address => mapping(Schema => uint256))) public assetsReserves;
@@ -73,9 +69,6 @@ contract ProtocolShareReserve is
73
69
  /// @notice Emitted when pool registry address is updated
74
70
  event PoolRegistryUpdated(address indexed oldPoolRegistry, address indexed newPoolRegistry);
75
71
 
76
- /// @notice Emitted when prime address is updated
77
- event PrimeUpdated(address indexed oldPrime, address indexed newPrime);
78
-
79
72
  /// @notice Event emitted after the updation of the assets reserves.
80
73
  event AssetsReservesUpdated(
81
74
  address indexed comptroller,
@@ -106,16 +99,29 @@ contract ProtocolShareReserve is
106
99
  /// @notice Event emitted when distribution configuration is updated
107
100
  event DistributionConfigUpdated(
108
101
  address indexed destination,
109
- uint256 oldPercentage,
110
- uint256 newPercentage,
102
+ uint8 oldPercentage,
103
+ uint8 newPercentage,
111
104
  Schema schema
112
105
  );
113
106
 
114
107
  /// @notice Event emitted when distribution configuration is added
115
- event DistributionConfigAdded(address indexed destination, uint256 percentage, Schema schema);
108
+ event DistributionConfigAdded(address indexed destination, uint8 percentage, Schema schema);
109
+
110
+ /// @notice Event emitted when distribution configuration is removed
111
+ event DistributionConfigRemoved(address indexed destination, uint8 percentage, Schema schema);
116
112
 
113
+ /**
114
+ * @dev Constructor to initialize the immutable variables
115
+ * @param _corePoolComptroller The address of core pool comptroller
116
+ * @param _wbnb The address of WBNB
117
+ * @param _vbnb The address of vBNB
118
+ */
117
119
  /// @custom:oz-upgrades-unsafe-allow constructor
118
- constructor(address _corePoolComptroller, address _wbnb, address _vbnb) {
120
+ constructor(
121
+ address _corePoolComptroller,
122
+ address _wbnb,
123
+ address _vbnb
124
+ ) {
119
125
  if (_corePoolComptroller == address(0)) revert InvalidAddress();
120
126
  if (_wbnb == address(0)) revert InvalidAddress();
121
127
  if (_vbnb == address(0)) revert InvalidAddress();
@@ -150,33 +156,20 @@ contract ProtocolShareReserve is
150
156
  poolRegistry = _poolRegistry;
151
157
  }
152
158
 
153
- /**
154
- * @dev Prime contract address setter.
155
- * @param _prime Address of the prime contract
156
- */
157
- function setPrime(address _prime) external onlyOwner {
158
- if (_prime == address(0)) revert InvalidAddress();
159
- emit PrimeUpdated(prime, _prime);
160
- prime = _prime;
161
- }
162
-
163
159
  /**
164
160
  * @dev Add or update destination targets based on destination address
165
161
  * @param configs configurations of the destinations.
166
162
  */
167
- function addOrUpdateDistributionConfigs(DistributionConfig[] memory configs) external nonReentrant {
163
+ function addOrUpdateDistributionConfigs(DistributionConfig[] calldata configs) external nonReentrant {
168
164
  _checkAccessAllowed("addOrUpdateDistributionConfigs(DistributionConfig[])");
169
165
 
170
- //we need to accrue and release funds to prime before updating the distribution configuration
171
- //because prime relies on getUnreleasedFunds and its return value may change after config update
172
- _accrueAndReleaseFundsToPrime();
173
-
174
166
  for (uint256 i = 0; i < configs.length; ) {
175
167
  DistributionConfig memory _config = configs[i];
176
- require(_config.destination != address(0), "ProtocolShareReserve: Destination address invalid");
168
+ if (_config.destination == address(0)) revert InvalidAddress();
177
169
 
178
170
  bool updated = false;
179
- for (uint256 j = 0; j < distributionTargets.length; ) {
171
+ uint256 distributionTargetsLength = distributionTargets.length;
172
+ for (uint256 j = 0; j < distributionTargetsLength; ) {
180
173
  DistributionConfig storage config = distributionTargets[j];
181
174
 
182
175
  if (_config.schema == config.schema && config.destination == _config.destination) {
@@ -210,14 +203,50 @@ contract ProtocolShareReserve is
210
203
  _ensureMaxLoops(distributionTargets.length);
211
204
  }
212
205
 
206
+ /**
207
+ * @dev Remove destionation target if percentage is 0
208
+ * @param schema schema of the configuration
209
+ * @param destination destination address of the configuration
210
+ */
211
+ function removeDistributionConfig(Schema schema, address destination) external {
212
+ _checkAccessAllowed("removeDistributionConfig(Schema,address)");
213
+
214
+ uint256 distributionIndex;
215
+ bool found = false;
216
+ for (uint256 i = 0; i < distributionTargets.length; ) {
217
+ DistributionConfig storage config = distributionTargets[i];
218
+
219
+ if (schema == config.schema && destination == config.destination && config.percentage == 0) {
220
+ found = true;
221
+ distributionIndex = i;
222
+ break;
223
+ }
224
+
225
+ unchecked {
226
+ ++i;
227
+ }
228
+ }
229
+
230
+ if (found) {
231
+ emit DistributionConfigRemoved(
232
+ distributionTargets[distributionIndex].destination,
233
+ distributionTargets[distributionIndex].percentage,
234
+ distributionTargets[distributionIndex].schema
235
+ );
236
+
237
+ distributionTargets[distributionIndex] = distributionTargets[distributionTargets.length - 1];
238
+ distributionTargets.pop();
239
+ }
240
+
241
+ _ensurePercentages();
242
+ }
243
+
213
244
  /**
214
245
  * @dev Release funds
215
246
  * @param comptroller the comptroller address of the pool
216
247
  * @param assets assets to be released to distribution targets
217
248
  */
218
- function releaseFunds(address comptroller, address[] memory assets) external nonReentrant {
219
- _accruePrimeInterest();
220
-
249
+ function releaseFunds(address comptroller, address[] calldata assets) external nonReentrant {
221
250
  for (uint256 i = 0; i < assets.length; ) {
222
251
  _releaseFund(comptroller, assets[i]);
223
252
 
@@ -240,7 +269,8 @@ contract ProtocolShareReserve is
240
269
  address destination,
241
270
  address asset
242
271
  ) external view returns (uint256) {
243
- for (uint256 i = 0; i < distributionTargets.length; ) {
272
+ uint256 distributionTargetsLength = distributionTargets.length;
273
+ for (uint256 i = 0; i < distributionTargetsLength; ) {
244
274
  DistributionConfig storage _config = distributionTargets[i];
245
275
  if (_config.schema == schema && _config.destination == destination) {
246
276
  uint256 total = assetsReserves[comptroller][asset][schema];
@@ -260,6 +290,27 @@ contract ProtocolShareReserve is
260
290
  return distributionTargets.length;
261
291
  }
262
292
 
293
+ /**
294
+ * @dev Used to find out the percentage distribution for a particular destination based on schema
295
+ * @param destination the destination address of the distribution target
296
+ * @param schema the schema of the distribution target
297
+ * @return percentage percentage distribution
298
+ */
299
+ function getPercentageDistribution(address destination, Schema schema) external view returns (uint256) {
300
+ uint256 distributionTargetsLength = distributionTargets.length;
301
+ for (uint256 i = 0; i < distributionTargetsLength; ) {
302
+ DistributionConfig memory config = distributionTargets[i];
303
+
304
+ if (config.destination == destination && config.schema == schema) {
305
+ return config.percentage;
306
+ }
307
+
308
+ unchecked {
309
+ ++i;
310
+ }
311
+ }
312
+ }
313
+
263
314
  /**
264
315
  * @dev Update the reserve of the asset for the specific pool after transferring to the protocol share reserve.
265
316
  * @param comptroller Comptroller address(pool)
@@ -278,7 +329,7 @@ contract ProtocolShareReserve is
278
329
  PoolRegistryInterface(poolRegistry).getVTokenForAsset(comptroller, asset) == address(0)
279
330
  ) revert InvalidAddress();
280
331
 
281
- Schema schema = getSchema(comptroller, asset, incomeType);
332
+ Schema schema = _getSchema(incomeType);
282
333
  uint256 currentBalance = IERC20Upgradeable(asset).balanceOf(address(this));
283
334
  uint256 assetReserve = totalAssetReserve[asset];
284
335
 
@@ -294,39 +345,6 @@ contract ProtocolShareReserve is
294
345
  }
295
346
  }
296
347
 
297
- /**
298
- * @dev Fetches the list of prime markets and then accrues interest and
299
- * releases the funds to prime for each market
300
- */
301
- function _accrueAndReleaseFundsToPrime() internal {
302
- address[] memory markets = IPrime(prime).getAllMarkets();
303
- for (uint256 i = 0; i < markets.length; ) {
304
- address market = markets[i];
305
- IPrime(prime).accrueInterest(market);
306
- _releaseFund(CORE_POOL_COMPTROLLER, _getUnderlying(market));
307
-
308
- unchecked {
309
- ++i;
310
- }
311
- }
312
- }
313
-
314
- /**
315
- * @dev Fetches the list of prime markets and then accrues interest
316
- * to prime for each market
317
- */
318
- function _accruePrimeInterest() internal {
319
- address[] memory markets = IPrime(prime).getAllMarkets();
320
- for (uint256 i = 0; i < markets.length; ) {
321
- address market = markets[i];
322
- IPrime(prime).accrueInterest(market);
323
-
324
- unchecked {
325
- ++i;
326
- }
327
- }
328
- }
329
-
330
348
  /**
331
349
  * @dev asset from a particular pool to be release to distribution targets
332
350
  * @param comptroller Comptroller address(pool)
@@ -356,10 +374,12 @@ contract ProtocolShareReserve is
356
374
  uint256 transferAmount = (schemaBalances[uint256(_config.schema)] * _config.percentage) / MAX_PERCENT;
357
375
  totalTransferAmounts[uint256(_config.schema)] += transferAmount;
358
376
 
359
- IERC20Upgradeable(asset).safeTransfer(_config.destination, transferAmount);
360
- IIncomeDestination(_config.destination).updateAssetsState(comptroller, asset);
377
+ if (transferAmount != 0) {
378
+ IERC20Upgradeable(asset).safeTransfer(_config.destination, transferAmount);
379
+ IIncomeDestination(_config.destination).updateAssetsState(comptroller, asset);
361
380
 
362
- emit AssetReleased(_config.destination, asset, _config.schema, _config.percentage, transferAmount);
381
+ emit AssetReleased(_config.destination, asset, _config.schema, _config.percentage, transferAmount);
382
+ }
363
383
 
364
384
  unchecked {
365
385
  ++i;
@@ -387,30 +407,27 @@ contract ProtocolShareReserve is
387
407
  }
388
408
 
389
409
  /**
390
- * @dev Returns the schema based on comptroller, asset and income type
391
- * @param comptroller Comptroller address(pool)
392
- * @param asset Asset address.
410
+ * @dev Returns the schema based on income type
393
411
  * @param incomeType type of income
394
412
  * @return schema schema for distribution
395
413
  */
396
- function getSchema(
397
- address comptroller,
398
- address asset,
399
- IncomeType incomeType
400
- ) internal view returns (Schema schema) {
401
- schema = Schema.DEFAULT;
402
- address vToken = IPrime(prime).vTokenForAsset(asset);
414
+ function _getSchema(IncomeType incomeType) internal view returns (Schema schema) {
415
+ schema = Schema.ADDITIONAL_REVENUE;
403
416
 
404
- if (vToken != address(0) && comptroller == CORE_POOL_COMPTROLLER && incomeType == IncomeType.SPREAD) {
405
- schema = Schema.SPREAD_PRIME_CORE;
417
+ if (incomeType == IncomeType.SPREAD) {
418
+ schema = Schema.PROTOCOL_RESERVES;
406
419
  }
407
420
  }
408
421
 
422
+ /**
423
+ * @dev This ensures that the total percentage of all the distribution targets is 100% or 0%
424
+ */
409
425
  function _ensurePercentages() internal view {
410
426
  uint256 totalSchemas = uint256(type(Schema).max) + 1;
411
- uint256[] memory totalPercentages = new uint256[](totalSchemas);
427
+ uint8[] memory totalPercentages = new uint8[](totalSchemas);
412
428
 
413
- for (uint256 i = 0; i < distributionTargets.length; ) {
429
+ uint256 distributionTargetsLength = distributionTargets.length;
430
+ for (uint256 i = 0; i < distributionTargetsLength; ) {
414
431
  DistributionConfig memory config = distributionTargets[i];
415
432
  totalPercentages[uint256(config.schema)] += config.percentage;
416
433
 
@@ -8,7 +8,11 @@ import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
8
8
  contract MockToken is ERC20 {
9
9
  uint8 private immutable _decimals;
10
10
 
11
- constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) {
11
+ constructor(
12
+ string memory name_,
13
+ string memory symbol_,
14
+ uint8 decimals_
15
+ ) ERC20(name_, symbol_) {
12
16
  _decimals = decimals_;
13
17
  }
14
18
 
@@ -0,0 +1,64 @@
1
+ import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
2
+ import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
3
+ import hre, { ethers } from "hardhat";
4
+ import { HardhatRuntimeEnvironment } from "hardhat/types";
5
+
6
+ const ADDRESSES: any = {
7
+ bsctestnet: {
8
+ vBNBAddress: testnetDeployments.Contracts.vBNB,
9
+ comptroller: testnetDeployments.Contracts.Unitroller,
10
+ WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
11
+ timelock: testnetDeployments.Contracts.Timelock,
12
+ acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
13
+ },
14
+ bscmainnet: {
15
+ vBNBAddress: mainnetDeployments.Contracts.vBNB,
16
+ comptroller: mainnetDeployments.Contracts.Unitroller,
17
+ WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
18
+ timelock: mainnetDeployments.Contracts.Timelock,
19
+ acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
20
+ },
21
+ sepolia: {
22
+ vBNBAddress: ethers.constants.AddressZero,
23
+ comptroller: ethers.constants.AddressZero,
24
+ WBNBAddress: ethers.constants.AddressZero,
25
+ timelock: ethers.constants.AddressZero,
26
+ acm: ethers.constants.AddressZero,
27
+ },
28
+ };
29
+
30
+ module.exports = async ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => {
31
+ const { deploy } = deployments;
32
+ const { deployer } = await getNamedAccounts();
33
+
34
+ const networkName = network.name;
35
+
36
+ const { vBNBAddress, comptroller, WBNBAddress, timelock, acm } = ADDRESSES[networkName];
37
+ const loopsLimit = 20;
38
+
39
+ await deploy("ProtocolShareReserve", {
40
+ from: deployer,
41
+ log: true,
42
+ deterministicDeployment: false,
43
+ args: [comptroller, WBNBAddress, vBNBAddress],
44
+ proxy: {
45
+ owner: timelock,
46
+ proxyContract: "OpenZeppelinTransparentProxy",
47
+ execute: {
48
+ methodName: "initialize",
49
+ args: [acm, loopsLimit],
50
+ },
51
+ },
52
+ });
53
+
54
+ const psr = await hre.ethers.getContract("ProtocolShareReserve");
55
+ const psrOwner = await psr.owner();
56
+
57
+ if (psrOwner === deployer) {
58
+ const tx = await psr.transferOwnership(ADDRESSES[networkName].timelock);
59
+ await tx.wait();
60
+ console.log("Transferred ownership of PSR to Timelock");
61
+ }
62
+ };
63
+
64
+ module.exports.tags = ["deploy"];
@@ -0,0 +1 @@
1
+ 56