@venusprotocol/protocol-reserve 1.1.0-dev.1 → 1.2.0-converters.1

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 (295) hide show
  1. package/README.md +17 -0
  2. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
  3. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
  4. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
  5. package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.dbg.json +4 -0
  6. package/artifacts/@openzeppelin/contracts/access/Ownable.sol/Ownable.json +63 -0
  7. package/artifacts/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.dbg.json +4 -0
  8. package/artifacts/@openzeppelin/contracts/interfaces/IERC1967.sol/IERC1967.json +56 -0
  9. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.dbg.json +4 -0
  10. package/artifacts/@openzeppelin/contracts/interfaces/draft-IERC1822.sol/IERC1822Proxiable.json +24 -0
  11. package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol/ERC1967Upgrade.dbg.json +4 -0
  12. package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol/ERC1967Upgrade.json +56 -0
  13. package/artifacts/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.dbg.json +4 -0
  14. package/artifacts/@openzeppelin/contracts/proxy/Proxy.sol/Proxy.json +19 -0
  15. package/artifacts/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.dbg.json +4 -0
  16. package/artifacts/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.json +80 -0
  17. package/artifacts/@openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.dbg.json +4 -0
  18. package/artifacts/{contracts/Interfaces/ComptrollerInterface.sol/ComptrollerInterface.json → @openzeppelin/contracts/proxy/beacon/IBeacon.sol/IBeacon.json} +5 -5
  19. package/artifacts/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.dbg.json +4 -0
  20. package/artifacts/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json +113 -0
  21. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  22. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  23. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  24. package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.dbg.json +4 -0
  25. package/artifacts/@openzeppelin/contracts/utils/Address.sol/Address.json +10 -0
  26. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  27. package/artifacts/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.dbg.json +4 -0
  28. package/artifacts/@openzeppelin/contracts/utils/StorageSlot.sol/StorageSlot.json +10 -0
  29. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
  30. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
  31. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
  32. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
  33. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
  34. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
  35. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
  36. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
  37. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +4 -0
  38. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +10 -0
  39. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
  40. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  41. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  42. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +4 -0
  43. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +63 -0
  44. package/artifacts/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol/ReentrancyGuardUpgradeable.dbg.json +1 -1
  45. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol/IERC20Upgradeable.dbg.json +1 -1
  46. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.dbg.json +1 -1
  47. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol/SafeERC20Upgradeable.dbg.json +1 -1
  48. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  49. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  50. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
  51. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
  52. package/artifacts/@venusprotocol/oracle/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +4 -0
  53. package/artifacts/@venusprotocol/oracle/contracts/ResilientOracle.sol/ResilientOracle.json +649 -0
  54. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +4 -0
  55. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +40 -0
  56. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +4 -0
  57. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/OracleInterface.json +30 -0
  58. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +4 -0
  59. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +75 -0
  60. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +4 -0
  61. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/TwapInterface.json +49 -0
  62. package/artifacts/@venusprotocol/oracle/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +4 -0
  63. package/artifacts/@venusprotocol/oracle/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +246 -0
  64. package/artifacts/@venusprotocol/solidity-utilities/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.dbg.json +1 -1
  65. package/artifacts/build-info/d38b6776f8d2919af17221fcc74eb552.json +1 -0
  66. package/artifacts/contracts/Interfaces/IComptroller.sol/IComptroller.dbg.json +4 -0
  67. package/artifacts/contracts/Interfaces/IComptroller.sol/IComptroller.json +56 -0
  68. package/artifacts/contracts/Interfaces/IConverterNetwork.sol/IConverterNetwork.dbg.json +4 -0
  69. package/artifacts/contracts/Interfaces/IConverterNetwork.sol/IConverterNetwork.json +127 -0
  70. package/artifacts/contracts/Interfaces/IIncomeDestination.sol/IIncomeDestination.dbg.json +1 -1
  71. package/artifacts/contracts/Interfaces/IPoolRegistry.sol/IPoolRegistry.dbg.json +4 -0
  72. package/artifacts/contracts/Interfaces/IPoolRegistry.sol/IPoolRegistry.json +54 -0
  73. package/artifacts/contracts/Interfaces/IProtocolShareReserve.sol/IProtocolShareReserve.dbg.json +1 -1
  74. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFund.dbg.json +4 -0
  75. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFund.json +77 -0
  76. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFundGetters.dbg.json +4 -0
  77. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFundGetters.json +24 -0
  78. package/artifacts/contracts/Interfaces/IRiskFundConverter.sol/IRiskFundConverter.dbg.json +4 -0
  79. package/artifacts/contracts/Interfaces/{PoolRegistryInterface.sol/PoolRegistryInterface.json → IRiskFundConverter.sol/IRiskFundConverter.json} +23 -10
  80. package/artifacts/contracts/Interfaces/IShortfall.sol/IShortfall.dbg.json +4 -0
  81. package/artifacts/contracts/Interfaces/IShortfall.sol/IShortfall.json +24 -0
  82. package/artifacts/contracts/Interfaces/IVToken.sol/IVToken.dbg.json +1 -1
  83. package/artifacts/contracts/Interfaces/IXVSVault.sol/IXVSVault.dbg.json +4 -0
  84. package/artifacts/contracts/Interfaces/IXVSVault.sol/IXVSVault.json +24 -0
  85. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.dbg.json +1 -1
  86. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.json +16 -16
  87. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/MaxLoopsLimitHelpersStorage.dbg.json +4 -0
  88. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/MaxLoopsLimitHelpersStorage.json +24 -0
  89. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/ReserveHelpersStorage.dbg.json +4 -0
  90. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/ReserveHelpersStorage.json +139 -0
  91. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV1Storage.dbg.json +4 -0
  92. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV1Storage.json +178 -0
  93. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV2Storage.dbg.json +4 -0
  94. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV2Storage.json +191 -0
  95. package/artifacts/contracts/ProtocolReserve/RiskFundV2.sol/RiskFundV2.dbg.json +4 -0
  96. package/artifacts/contracts/ProtocolReserve/RiskFundV2.sol/RiskFundV2.json +582 -0
  97. package/artifacts/contracts/ProtocolReserve/XVSVaultTreasury.sol/XVSVaultTreasury.dbg.json +4 -0
  98. package/artifacts/contracts/ProtocolReserve/XVSVaultTreasury.sol/XVSVaultTreasury.json +315 -0
  99. package/artifacts/contracts/Test/Mocks/MockACM.sol/MockACM.dbg.json +4 -0
  100. package/artifacts/contracts/Test/Mocks/MockACM.sol/MockACM.json +369 -0
  101. package/artifacts/contracts/Test/Mocks/MockArraySorter.sol/MockArraySorter.dbg.json +4 -0
  102. package/artifacts/contracts/Test/Mocks/MockArraySorter.sol/MockArraySorter.json +40 -0
  103. package/artifacts/contracts/Test/Mocks/MockConverter.sol/MockConverter.dbg.json +4 -0
  104. package/artifacts/contracts/Test/Mocks/MockConverter.sol/MockConverter.json +1395 -0
  105. package/artifacts/contracts/Test/Mocks/MockDeflationaryToken.sol/MockDeflatingToken.dbg.json +4 -0
  106. package/artifacts/contracts/Test/Mocks/MockDeflationaryToken.sol/MockDeflatingToken.json +332 -0
  107. package/artifacts/contracts/Test/Mocks/MockRiskFundConverter.sol/MockRiskFundConverter.dbg.json +4 -0
  108. package/artifacts/contracts/Test/Mocks/MockRiskFundConverter.sol/MockRiskFundConverter.json +1761 -0
  109. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.dbg.json +1 -1
  110. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.json +20 -2
  111. package/artifacts/contracts/TokenConverter/AbstractTokenConverter.sol/AbstractTokenConverter.dbg.json +4 -0
  112. package/artifacts/contracts/TokenConverter/AbstractTokenConverter.sol/AbstractTokenConverter.json +1276 -0
  113. package/artifacts/contracts/TokenConverter/ConverterNetwork.sol/ConverterNetwork.dbg.json +4 -0
  114. package/artifacts/contracts/TokenConverter/ConverterNetwork.sol/ConverterNetwork.json +457 -0
  115. package/artifacts/contracts/TokenConverter/IAbstractTokenConverter.sol/IAbstractTokenConverter.dbg.json +4 -0
  116. package/artifacts/contracts/TokenConverter/IAbstractTokenConverter.sol/IAbstractTokenConverter.json +446 -0
  117. package/artifacts/contracts/TokenConverter/RiskFundConverter.sol/RiskFundConverter.dbg.json +4 -0
  118. package/artifacts/contracts/TokenConverter/RiskFundConverter.sol/RiskFundConverter.json +1631 -0
  119. package/artifacts/contracts/TokenConverter/SingleTokenConverter.sol/SingleTokenConverter.dbg.json +4 -0
  120. package/artifacts/contracts/TokenConverter/SingleTokenConverter.sol/SingleTokenConverter.json +1390 -0
  121. package/contracts/Interfaces/IComptroller.sol +10 -0
  122. package/contracts/Interfaces/IConverterNetwork.sol +46 -0
  123. package/contracts/Interfaces/IPoolRegistry.sol +10 -0
  124. package/contracts/Interfaces/IRiskFund.sol +28 -0
  125. package/contracts/Interfaces/IRiskFundConverter.sol +8 -0
  126. package/contracts/Interfaces/IShortfall.sol +11 -0
  127. package/contracts/Interfaces/IXVSVault.sol +9 -0
  128. package/contracts/ProtocolReserve/ProtocolShareReserve.sol +14 -13
  129. package/contracts/ProtocolReserve/RiskFundStorage.sol +67 -0
  130. package/contracts/ProtocolReserve/RiskFundV2.sol +220 -0
  131. package/contracts/ProtocolReserve/XVSVaultTreasury.sol +95 -0
  132. package/contracts/Test/Mocks/MockACM.sol +94 -0
  133. package/contracts/Test/Mocks/MockArraySorter.sol +14 -0
  134. package/contracts/Test/Mocks/MockConverter.sol +70 -0
  135. package/contracts/Test/Mocks/MockDeflationaryToken.sol +113 -0
  136. package/contracts/Test/Mocks/MockRiskFundConverter.sol +45 -0
  137. package/contracts/Test/Mocks/MockToken.sol +4 -0
  138. package/contracts/Test/imports.sol +11 -0
  139. package/contracts/TokenConverter/AbstractTokenConverter.sol +1168 -0
  140. package/contracts/TokenConverter/ConverterNetwork.sol +243 -0
  141. package/contracts/TokenConverter/IAbstractTokenConverter.sol +178 -0
  142. package/contracts/TokenConverter/RiskFundConverter.sol +449 -0
  143. package/contracts/TokenConverter/SingleTokenConverter.sol +102 -0
  144. package/contracts/Utils/ArrayHelpers.sol +41 -0
  145. package/contracts/Utils/Constants.sol +8 -0
  146. package/contracts/Utils/Validators.sol +26 -0
  147. package/deployments/bscmainnet.json +2039 -0
  148. package/deployments/bscmainnet_addresses.json +10 -0
  149. package/deployments/bsctestnet/BTCBPrimeConverter.json +218 -0
  150. package/deployments/bsctestnet/ConverterNetwork.json +723 -0
  151. package/deployments/bsctestnet/ConverterNetwork_Implementation.json +823 -0
  152. package/deployments/bsctestnet/ConverterNetwork_Proxy.json +277 -0
  153. package/deployments/bsctestnet/ETHPrimeConverter.json +218 -0
  154. package/deployments/bsctestnet/ProtocolShareReserve_Implementation.json +79 -73
  155. package/deployments/bsctestnet/RiskFundConverter.json +2035 -0
  156. package/deployments/bsctestnet/RiskFundConverter_Implementation.json +2563 -0
  157. package/deployments/bsctestnet/RiskFundConverter_Proxy.json +403 -0
  158. package/deployments/bsctestnet/RiskFundV2_Implementation.json +1049 -0
  159. package/deployments/bsctestnet/SingleTokenConverterBeacon.json +206 -0
  160. package/deployments/bsctestnet/SingleTokenConverterImp.json +2164 -0
  161. package/deployments/bsctestnet/USDCPrimeConverter.json +218 -0
  162. package/deployments/bsctestnet/USDTPrimeConverter.json +218 -0
  163. package/deployments/bsctestnet/XVSVaultConverter.json +218 -0
  164. package/deployments/bsctestnet/XVSVaultTreasury.json +579 -0
  165. package/deployments/bsctestnet/XVSVaultTreasury_Implementation.json +603 -0
  166. package/deployments/bsctestnet/XVSVaultTreasury_Proxy.json +281 -0
  167. package/deployments/bsctestnet/solcInputs/5d85b28b6a601f301b9d986a9cab69e1.json +168 -0
  168. package/deployments/bsctestnet/solcInputs/ddce8674a6dbb661f5732619dd799a66.json +228 -0
  169. package/deployments/bsctestnet/solcInputs/f4de763d185e08f2949b0be700500ede.json +144 -0
  170. package/deployments/bsctestnet.json +10088 -0
  171. package/deployments/bsctestnet_addresses.json +27 -0
  172. package/deployments/ethereum.json +5 -0
  173. package/deployments/ethereum_addresses.json +5 -0
  174. package/deployments/sepolia.json +5 -0
  175. package/deployments/sepolia_addresses.json +5 -0
  176. package/dist/deploy/001-psr.d.ts +2 -0
  177. package/dist/deploy/001-psr.d.ts.map +1 -0
  178. package/dist/deploy/001-psr.js +68 -0
  179. package/dist/deploy/001-psr.js.map +1 -0
  180. package/dist/deploy/002-risk-fund-converter.d.ts +4 -0
  181. package/dist/deploy/002-risk-fund-converter.d.ts.map +1 -0
  182. package/dist/deploy/002-risk-fund-converter.js +80 -0
  183. package/dist/deploy/002-risk-fund-converter.js.map +1 -0
  184. package/dist/deploy/003-xvs-vault-teasury.d.ts +2 -0
  185. package/dist/deploy/003-xvs-vault-teasury.d.ts.map +1 -0
  186. package/dist/deploy/003-xvs-vault-teasury.js +43 -0
  187. package/dist/deploy/003-xvs-vault-teasury.js.map +1 -0
  188. package/dist/deploy/004-single-token-converter.d.ts +4 -0
  189. package/dist/deploy/004-single-token-converter.d.ts.map +1 -0
  190. package/dist/deploy/004-single-token-converter.js +62 -0
  191. package/dist/deploy/004-single-token-converter.js.map +1 -0
  192. package/dist/deploy/005-converter-network.d.ts +2 -0
  193. package/dist/deploy/005-converter-network.d.ts.map +1 -0
  194. package/dist/deploy/005-converter-network.js +41 -0
  195. package/dist/deploy/005-converter-network.js.map +1 -0
  196. package/dist/hardhat.config.d.ts +15 -0
  197. package/dist/hardhat.config.d.ts.map +1 -0
  198. package/dist/hardhat.config.js +216 -0
  199. package/dist/hardhat.config.js.map +1 -0
  200. package/package.json +23 -21
  201. package/typechain/AbstractTokenConverter.d.ts +1775 -0
  202. package/typechain/AccessControl.d.ts +388 -0
  203. package/typechain/BeaconProxy.d.ts +126 -0
  204. package/typechain/BoundValidatorInterface.d.ts +126 -0
  205. package/typechain/ConverterNetwork.d.ts +723 -0
  206. package/typechain/{PoolRegistryInterface.d.ts → ERC165.d.ts} +20 -25
  207. package/typechain/ERC1967Upgrade.d.ts +126 -0
  208. package/typechain/IAbstractTokenConverter.d.ts +773 -0
  209. package/typechain/IBeacon.d.ts +101 -0
  210. package/typechain/IComptroller.d.ts +136 -0
  211. package/typechain/IConverterNetwork.d.ts +292 -0
  212. package/typechain/IERC165.d.ts +116 -0
  213. package/typechain/{ComptrollerInterface.d.ts → IERC1822Proxiable.d.ts} +11 -11
  214. package/typechain/IERC1967.d.ts +126 -0
  215. package/typechain/IPoolRegistry.d.ts +155 -0
  216. package/typechain/IRiskFund.d.ts +200 -0
  217. package/typechain/IRiskFundConverter.d.ts +138 -0
  218. package/typechain/IRiskFundGetters.d.ts +103 -0
  219. package/typechain/IShortfall.d.ts +110 -0
  220. package/typechain/IXVSVault.d.ts +95 -0
  221. package/typechain/MaxLoopsLimitHelpersStorage.d.ts +101 -0
  222. package/typechain/MockACM.d.ts +615 -0
  223. package/typechain/MockArraySorter.d.ts +118 -0
  224. package/typechain/MockConverter.d.ts +1969 -0
  225. package/typechain/MockDeflatingToken.d.ts +486 -0
  226. package/typechain/MockRiskFundConverter.d.ts +2479 -0
  227. package/typechain/MockToken.d.ts +36 -0
  228. package/typechain/OracleInterface.d.ts +98 -0
  229. package/typechain/Ownable.d.ts +181 -0
  230. package/typechain/PausableUpgradeable.d.ts +129 -0
  231. package/typechain/ProtocolShareReserve.d.ts +6 -6
  232. package/typechain/Proxy.d.ts +78 -0
  233. package/typechain/ReserveHelpersStorage.d.ts +300 -0
  234. package/typechain/ResilientOracle.d.ts +1034 -0
  235. package/typechain/ResilientOracleInterface.d.ts +192 -0
  236. package/typechain/RiskFundConverter.d.ts +2235 -0
  237. package/typechain/RiskFundV1Storage.d.ts +353 -0
  238. package/typechain/RiskFundV2.d.ts +893 -0
  239. package/typechain/RiskFundV2Storage.d.ts +372 -0
  240. package/typechain/SingleTokenConverter.d.ts +1944 -0
  241. package/typechain/TwapInterface.d.ts +124 -0
  242. package/typechain/UpgradeableBeacon.d.ts +240 -0
  243. package/typechain/VBep20Interface.d.ts +379 -0
  244. package/typechain/XVSVaultTreasury.d.ts +515 -0
  245. package/typechain/factories/AbstractTokenConverter__factory.ts +1297 -0
  246. package/typechain/factories/AccessControl__factory.ts +227 -0
  247. package/typechain/factories/BeaconProxy__factory.ts +133 -0
  248. package/typechain/factories/BoundValidatorInterface__factory.ts +59 -0
  249. package/typechain/factories/ConverterNetwork__factory.ts +502 -0
  250. package/typechain/factories/ERC165__factory.ts +39 -0
  251. package/typechain/factories/ERC1967Upgrade__factory.ts +71 -0
  252. package/typechain/factories/IAbstractTokenConverter__factory.ts +466 -0
  253. package/typechain/factories/IBeacon__factory.ts +36 -0
  254. package/typechain/factories/IComptroller__factory.ts +68 -0
  255. package/typechain/factories/IConverterNetwork__factory.ts +142 -0
  256. package/typechain/factories/{ComptrollerInterface__factory.ts → IERC165__factory.ts} +14 -15
  257. package/typechain/factories/IERC1822Proxiable__factory.ts +39 -0
  258. package/typechain/factories/IERC1967__factory.ts +68 -0
  259. package/typechain/factories/IPoolRegistry__factory.ts +66 -0
  260. package/typechain/factories/{PoolRegistryInterface__factory.ts → IRiskFundConverter__factory.ts} +28 -19
  261. package/typechain/factories/IRiskFundGetters__factory.ts +39 -0
  262. package/typechain/factories/IRiskFund__factory.ts +89 -0
  263. package/typechain/factories/IShortfall__factory.ts +36 -0
  264. package/typechain/factories/IXVSVault__factory.ts +36 -0
  265. package/typechain/factories/MaxLoopsLimitHelpersStorage__factory.ts +75 -0
  266. package/typechain/factories/MockACM__factory.ts +411 -0
  267. package/typechain/factories/MockArraySorter__factory.ts +85 -0
  268. package/typechain/factories/MockConverter__factory.ts +1439 -0
  269. package/typechain/factories/MockDeflatingToken__factory.ts +389 -0
  270. package/typechain/factories/MockRiskFundConverter__factory.ts +1828 -0
  271. package/typechain/factories/MockToken__factory.ts +19 -1
  272. package/typechain/factories/OracleInterface__factory.ts +45 -0
  273. package/typechain/factories/Ownable__factory.ts +75 -0
  274. package/typechain/factories/PausableUpgradeable__factory.ts +78 -0
  275. package/typechain/factories/ProtocolShareReserve__factory.ts +15 -15
  276. package/typechain/factories/Proxy__factory.ts +28 -0
  277. package/typechain/factories/ReserveHelpersStorage__factory.ts +188 -0
  278. package/typechain/factories/ResilientOracleInterface__factory.ts +94 -0
  279. package/typechain/factories/ResilientOracle__factory.ts +710 -0
  280. package/typechain/factories/RiskFundConverter__factory.ts +1694 -0
  281. package/typechain/factories/RiskFundV1Storage__factory.ts +223 -0
  282. package/typechain/factories/RiskFundV2Storage__factory.ts +236 -0
  283. package/typechain/factories/RiskFundV2__factory.ts +624 -0
  284. package/typechain/factories/SingleTokenConverter__factory.ts +1441 -0
  285. package/typechain/factories/TwapInterface__factory.ts +61 -0
  286. package/typechain/factories/UpgradeableBeacon__factory.ts +163 -0
  287. package/typechain/factories/VBep20Interface__factory.ts +261 -0
  288. package/typechain/factories/XVSVaultTreasury__factory.ts +365 -0
  289. package/typechain/index.ts +84 -4
  290. package/artifacts/build-info/0bf08ffb3b10e68a2b3f4538fccc61c5.json +0 -1
  291. package/artifacts/contracts/Interfaces/ComptrollerInterface.sol/ComptrollerInterface.dbg.json +0 -4
  292. package/artifacts/contracts/Interfaces/PoolRegistryInterface.sol/PoolRegistryInterface.dbg.json +0 -4
  293. package/contracts/Interfaces/ComptrollerInterface.sol +0 -6
  294. package/contracts/Interfaces/PoolRegistryInterface.sol +0 -7
  295. package/deploy/1-deploy.ts +0 -64
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ interface IComptroller {
5
+ function isComptroller() external view returns (bool);
6
+
7
+ function markets(address) external view returns (bool);
8
+
9
+ function getAllMarkets() external view returns (address[] memory);
10
+ }
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import { IAbstractTokenConverter } from "../TokenConverter/IAbstractTokenConverter.sol";
5
+
6
+ /**
7
+ * @title IConverterNetwork
8
+ * @author Venus
9
+ * @notice Interface implemented by `ConverterNetwork`.
10
+ */
11
+ interface IConverterNetwork {
12
+ /// @notice Adds new converter to the array
13
+ /// @param _tokenConverter Address of the token converter
14
+ function addTokenConverter(IAbstractTokenConverter _tokenConverter) external;
15
+
16
+ /// @notice Removes converter from the array
17
+ /// @param _tokenConverter Address of the token converter
18
+ function removeTokenConverter(IAbstractTokenConverter _tokenConverter) external;
19
+
20
+ /// @notice Used to get the array of converters supporting conversions, arranged in descending order based on token balances
21
+ /// @param _tokenAddressIn Address of tokenIn
22
+ /// @param _tokenAddressOut Address of tokenOut
23
+ /// @return converters Array of the conveters on the basis of the tokens pair
24
+ /// @return convertersBalance Array of balances with respect to token out
25
+ function findTokenConverters(address _tokenAddressIn, address _tokenAddressOut)
26
+ external
27
+ returns (address[] memory converters, uint256[] memory convertersBalance);
28
+
29
+ /// @notice Used to get the array of converters supporting conversions, arranged in descending order based on token balances
30
+ /// @param _tokenAddressIn Address of tokenIn
31
+ /// @param _tokenAddressOut Address of tokenOut
32
+ /// @return converters Array of the conveters on the basis of the tokens pair
33
+ /// @return convertersBalance Array of balances with respect to token out
34
+ function findTokenConvertersForConverters(address _tokenAddressIn, address _tokenAddressOut)
35
+ external
36
+ returns (address[] memory converters, uint256[] memory convertersBalance);
37
+
38
+ /// @notice This function returns the array containing all the converters addresses
39
+ /// @return Array containing all the converters addresses
40
+ function getAllConverters() external view returns (IAbstractTokenConverter[] memory);
41
+
42
+ /// @notice This function checks for given address is converter or not
43
+ /// @param _tokenConverter Address of the token converter
44
+ /// @return boolean true if given address is converter otherwise false
45
+ function isTokenConverter(address _tokenConverter) external view returns (bool);
46
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ interface IPoolRegistry {
5
+ /// @notice Get VToken in the Pool for an Asset
6
+ function getVTokenForAsset(address comptroller, address asset) external view returns (address);
7
+
8
+ /// @notice Get the addresss of the Pools supported that include a market for the provided asset
9
+ function getPoolsSupportedByAsset(address asset) external view returns (address[] memory);
10
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /**
5
+ * @title IRiskFund
6
+ * @author Venus
7
+ * @notice Interface implemented by `RiskFund`.
8
+ */
9
+ interface IRiskFund {
10
+ function transferReserveForAuction(address comptroller, uint256 amount) external returns (uint256);
11
+
12
+ function updatePoolState(
13
+ address comptroller,
14
+ address asset,
15
+ uint256 amount
16
+ ) external;
17
+
18
+ function getPoolsBaseAssetReserves(address comptroller) external view returns (uint256);
19
+ }
20
+
21
+ /**
22
+ * @title IRiskFundGetters
23
+ * @author Venus
24
+ * @notice Interface implemented by `RiskFund` for getter methods.
25
+ */
26
+ interface IRiskFundGetters {
27
+ function convertibleBaseAsset() external view returns (address);
28
+ }
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ interface IRiskFundConverter {
5
+ function updateAssetsState(address comptroller, address asset) external;
6
+
7
+ function getPools(address asset) external view returns (address[] memory);
8
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /**
5
+ * @title IShortfall
6
+ * @author Venus
7
+ * @notice Interface implemented by `Shortfall`.
8
+ */
9
+ interface IShortfall {
10
+ function convertibleBaseAsset() external returns (address);
11
+ }
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /// @title IXVSVaultProxy
5
+ /// @author Venus
6
+ /// @notice Interface implemented by `XVSVault`.
7
+ interface IXVSVault {
8
+ function xvsStore() external view returns (address);
9
+ }
@@ -7,8 +7,8 @@ import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/
7
7
  import { MaxLoopsLimitHelper } from "@venusprotocol/solidity-utilities/contracts/MaxLoopsLimitHelper.sol";
8
8
 
9
9
  import { IProtocolShareReserve } from "../Interfaces/IProtocolShareReserve.sol";
10
- import { ComptrollerInterface } from "../Interfaces/ComptrollerInterface.sol";
11
- import { PoolRegistryInterface } from "../Interfaces/PoolRegistryInterface.sol";
10
+ import { IComptroller } from "../Interfaces/IComptroller.sol";
11
+ import { IPoolRegistry } from "../Interfaces/IPoolRegistry.sol";
12
12
  import { IVToken } from "../Interfaces/IVToken.sol";
13
13
  import { IIncomeDestination } from "../Interfaces/IIncomeDestination.sol";
14
14
 
@@ -36,7 +36,7 @@ contract ProtocolShareReserve is
36
36
  struct DistributionConfig {
37
37
  Schema schema;
38
38
  /// @dev percenatge is represented without any scale
39
- uint8 percentage;
39
+ uint16 percentage;
40
40
  address destination;
41
41
  }
42
42
 
@@ -55,7 +55,7 @@ contract ProtocolShareReserve is
55
55
  /// @notice address of pool registry contract
56
56
  address public poolRegistry;
57
57
 
58
- uint8 public constant MAX_PERCENT = 100;
58
+ uint16 public constant MAX_PERCENT = 1e4;
59
59
 
60
60
  /// @notice comptroller => asset => schema => balance
61
61
  mapping(address => mapping(address => mapping(Schema => uint256))) public assetsReserves;
@@ -69,7 +69,7 @@ contract ProtocolShareReserve is
69
69
  /// @notice Emitted when pool registry address is updated
70
70
  event PoolRegistryUpdated(address indexed oldPoolRegistry, address indexed newPoolRegistry);
71
71
 
72
- /// @notice Event emitted after the updation of the assets reserves.
72
+ /// @notice Event emitted after updating of the assets reserves.
73
73
  event AssetsReservesUpdated(
74
74
  address indexed comptroller,
75
75
  address indexed asset,
@@ -99,16 +99,16 @@ contract ProtocolShareReserve is
99
99
  /// @notice Event emitted when distribution configuration is updated
100
100
  event DistributionConfigUpdated(
101
101
  address indexed destination,
102
- uint8 oldPercentage,
103
- uint8 newPercentage,
102
+ uint16 oldPercentage,
103
+ uint16 newPercentage,
104
104
  Schema schema
105
105
  );
106
106
 
107
107
  /// @notice Event emitted when distribution configuration is added
108
- event DistributionConfigAdded(address indexed destination, uint8 percentage, Schema schema);
108
+ event DistributionConfigAdded(address indexed destination, uint16 percentage, Schema schema);
109
109
 
110
110
  /// @notice Event emitted when distribution configuration is removed
111
- event DistributionConfigRemoved(address indexed destination, uint8 percentage, Schema schema);
111
+ event DistributionConfigRemoved(address indexed destination, uint16 percentage, Schema schema);
112
112
 
113
113
  /**
114
114
  * @dev Constructor to initialize the immutable variables
@@ -149,6 +149,7 @@ contract ProtocolShareReserve is
149
149
  /**
150
150
  * @dev Pool registry setter.
151
151
  * @param _poolRegistry Address of the pool registry
152
+ * @custom:error ZeroAddressNotAllowed is thrown when pool registry address is zero
152
153
  */
153
154
  function setPoolRegistry(address _poolRegistry) external onlyOwner {
154
155
  if (_poolRegistry == address(0)) revert InvalidAddress();
@@ -313,7 +314,7 @@ contract ProtocolShareReserve is
313
314
 
314
315
  /**
315
316
  * @dev Update the reserve of the asset for the specific pool after transferring to the protocol share reserve.
316
- * @param comptroller Comptroller address(pool)
317
+ * @param comptroller Comptroller address (pool)
317
318
  * @param asset Asset address.
318
319
  * @param incomeType type of income
319
320
  */
@@ -322,11 +323,11 @@ contract ProtocolShareReserve is
322
323
  address asset,
323
324
  IncomeType incomeType
324
325
  ) public override(IProtocolShareReserve) nonReentrant {
325
- if (!ComptrollerInterface(comptroller).isComptroller()) revert InvalidAddress();
326
+ if (!IComptroller(comptroller).isComptroller()) revert InvalidAddress();
326
327
  if (asset == address(0)) revert InvalidAddress();
327
328
  if (
328
329
  comptroller != CORE_POOL_COMPTROLLER &&
329
- PoolRegistryInterface(poolRegistry).getVTokenForAsset(comptroller, asset) == address(0)
330
+ IPoolRegistry(poolRegistry).getVTokenForAsset(comptroller, asset) == address(0)
330
331
  ) revert InvalidAddress();
331
332
 
332
333
  Schema schema = _getSchema(incomeType);
@@ -424,7 +425,7 @@ contract ProtocolShareReserve is
424
425
  */
425
426
  function _ensurePercentages() internal view {
426
427
  uint256 totalSchemas = uint256(type(Schema).max) + 1;
427
- uint8[] memory totalPercentages = new uint8[](totalSchemas);
428
+ uint16[] memory totalPercentages = new uint16[](totalSchemas);
428
429
 
429
430
  uint256 distributionTargetsLength = distributionTargets.length;
430
431
  for (uint256 i = 0; i < distributionTargetsLength; ) {
@@ -0,0 +1,67 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
5
+ import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
6
+
7
+ /// @title ReserveHelpersStorage
8
+ /// @author Venus
9
+ /// @dev Reserve helpers storage
10
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
11
+ contract ReserveHelpersStorage is Ownable2StepUpgradeable {
12
+ /// @notice Deprecated slot for assetReserves mapping
13
+ bytes32 private __deprecatedSlot1;
14
+
15
+ /// @notice Available asset's fund per pool in RiskFund
16
+ /// Comptroller(pool) -> Asset -> amount
17
+ mapping(address => mapping(address => uint256)) public poolAssetsFunds;
18
+
19
+ /// @notice Deprecated slot for poolRegistry address
20
+ bytes32 private __deprecatedSlot2;
21
+ /// @notice Deprecated slot for status variable
22
+ bytes32 private __deprecatedSlot3;
23
+
24
+ /// @dev This empty reserved space is put in place to allow future versions to add new
25
+ /// variables without shifting down storage in the inheritance chain.
26
+ uint256[46] private __gap;
27
+ }
28
+
29
+ /// @title MaxLoopsLimitHelpersStorage
30
+ /// @author Venus
31
+ /// @dev Max loop limit helpers storage
32
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
33
+ contract MaxLoopsLimitHelpersStorage {
34
+ /// @notice Limit for the loops to avoid the DOS
35
+ /// @notice This state is deprecated, using it to prevent storage collision
36
+ uint256 public maxLoopsLimit;
37
+
38
+ /// @dev This empty reserved space is put in place to allow future versions to add new
39
+ /// variables without shifting down storage in the inheritance chain.
40
+ /// See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
41
+ uint256[49] private __gap;
42
+ }
43
+
44
+ /// @title RiskFundV1Storage
45
+ /// @author Venus
46
+ /// @dev Risk fund V1 storage
47
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
48
+ contract RiskFundV1Storage is ReserveHelpersStorage, MaxLoopsLimitHelpersStorage {
49
+ /// @notice Address of base asset
50
+ address public convertibleBaseAsset;
51
+ /// @notice Address of shortfall contract
52
+ address public shortfall;
53
+
54
+ /// @notice This state is deprecated, using it to prevent storage collision
55
+ address private pancakeSwapRouter;
56
+ /// @notice This state is deprecated, using it to prevent storage collision
57
+ uint256 private minAmountToConvert;
58
+ }
59
+
60
+ /// @title RiskFundV2Storage
61
+ /// @author Venus
62
+ /// @dev Risk fund V2 storage
63
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
64
+ contract RiskFundV2Storage is RiskFundV1Storage, ReentrancyGuardUpgradeable {
65
+ /// @notice Risk fund converter address
66
+ address public riskFundConverter;
67
+ }
@@ -0,0 +1,220 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
5
+ import { AccessControlledV8 } from "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
6
+ import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
7
+
8
+ import { IRiskFund } from "../Interfaces/IRiskFund.sol";
9
+ import { IRiskFundConverter } from "../Interfaces/IRiskFundConverter.sol";
10
+
11
+ import { ensureNonzeroAddress, ensureNonzeroValue } from "../Utils/Validators.sol";
12
+
13
+ import { RiskFundV2Storage } from "./RiskFundStorage.sol";
14
+
15
+ /// @title RiskFundV2
16
+ /// @author Venus
17
+ /// @notice Contract with basic features to hold base asset for different Comptrollers
18
+ /// @dev This contract does not support BNB
19
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
20
+ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
21
+ using SafeERC20Upgradeable for IERC20Upgradeable;
22
+
23
+ /// @notice Emitted when convertible base asset address is updated
24
+ event ConvertibleBaseAssetUpdated(address indexed oldConvertibleBaseAsset, address indexed newConvertibleBaseAsset);
25
+
26
+ /// @notice Emitted when risk fund converter address is updated
27
+ event RiskFundConverterUpdated(address indexed oldRiskFundConverter, address indexed newRiskFundConverter);
28
+
29
+ /// @notice Emitted when shortfall contract address is updated
30
+ event ShortfallContractUpdated(address indexed oldShortfallContract, address indexed newShortfallContract);
31
+
32
+ /// @notice Emitted when reserves are transferred for auction
33
+ event TransferredReserveForAuction(address indexed comptroller, uint256 amount);
34
+
35
+ /// @notice Emitted when pool asset states is updated with amount transferred to this contract
36
+ event PoolAssetsIncreased(address indexed comptroller, address indexed asset, uint256 amount);
37
+
38
+ /// @notice Emitted when pool asset states is updated with amount transferred from this contract on sweeping tokens
39
+ event PoolAssetsDecreased(address indexed comptroller, address indexed asset, uint256 amount);
40
+
41
+ /// @notice Event emitted when tokens are swept
42
+ event SweepToken(address indexed token, address indexed to, uint256 amount);
43
+
44
+ /// @notice Error is thrown when updatePoolState is not called by riskFundConverter
45
+ error InvalidRiskFundConverter();
46
+
47
+ /// @notice Error is thrown when transferReserveForAuction is called by non shortfall address
48
+ error InvalidShortfallAddress();
49
+
50
+ /// @notice thrown when amount entered is greater than balance
51
+ error InsufficientBalance();
52
+
53
+ /// @notice Error is thrown when pool reserve is less than the amount needed
54
+ error InsufficientPoolReserve(address comptroller, uint256 amount, uint256 poolReserve);
55
+
56
+ /// @dev Convertible base asset setter
57
+ /// @param convertibleBaseAsset_ Address of the convertible base asset
58
+ /// @custom:event ConvertibleBaseAssetUpdated emit on success
59
+ /// @custom:error ZeroAddressNotAllowed is thrown when convertible base asset address is zero
60
+ /// @custom:access Only Governance
61
+ function setConvertibleBaseAsset(address convertibleBaseAsset_) external onlyOwner {
62
+ ensureNonzeroAddress(convertibleBaseAsset_);
63
+ emit ConvertibleBaseAssetUpdated(convertibleBaseAsset, convertibleBaseAsset_);
64
+ convertibleBaseAsset = convertibleBaseAsset_;
65
+ }
66
+
67
+ /// @dev Risk fund converter setter
68
+ /// @param riskFundConverter_ Address of the risk fund converter
69
+ /// @custom:event RiskFundConverterUpdated emit on success
70
+ /// @custom:error ZeroAddressNotAllowed is thrown when risk fund converter address is zero
71
+ /// @custom:access Only Governance
72
+ function setRiskFundConverter(address riskFundConverter_) external onlyOwner {
73
+ ensureNonzeroAddress(riskFundConverter_);
74
+ emit RiskFundConverterUpdated(riskFundConverter, riskFundConverter_);
75
+ riskFundConverter = riskFundConverter_;
76
+ }
77
+
78
+ /// @dev Shortfall contract address setter
79
+ /// @param shortfallContractAddress_ Address of the auction contract
80
+ /// @custom:event ShortfallContractUpdated emit on success
81
+ /// @custom:error ZeroAddressNotAllowed is thrown when shortfall contract address is zero
82
+ /// @custom:access Only Governance
83
+ function setShortfallContractAddress(address shortfallContractAddress_) external onlyOwner {
84
+ ensureNonzeroAddress(shortfallContractAddress_);
85
+ emit ShortfallContractUpdated(shortfall, shortfallContractAddress_);
86
+ shortfall = shortfallContractAddress_;
87
+ }
88
+
89
+ /// @dev Transfer tokens for auction to shortfall contract
90
+ /// @param comptroller Comptroller of the pool
91
+ /// @param amount Amount to be transferred to the shortfall
92
+ /// @return Amount of tokens transferred to the shortfall
93
+ /// @custom:event TransferredReserveForAuction emit on success
94
+ /// @custom:error InvalidShortfallAddress is thrown when caller is not shortfall contract
95
+ /// @custom:error InsufficientPoolReserve is thrown when pool reserve is less than the amount needed
96
+ /// @custom:access Only Shortfall contract
97
+ function transferReserveForAuction(address comptroller, uint256 amount)
98
+ external
99
+ override
100
+ nonReentrant
101
+ returns (uint256)
102
+ {
103
+ uint256 poolReserve = poolAssetsFunds[comptroller][convertibleBaseAsset];
104
+
105
+ if (msg.sender != shortfall) {
106
+ revert InvalidShortfallAddress();
107
+ }
108
+ if (amount > poolReserve) {
109
+ revert InsufficientPoolReserve(comptroller, amount, poolReserve);
110
+ }
111
+
112
+ unchecked {
113
+ poolAssetsFunds[comptroller][convertibleBaseAsset] = poolReserve - amount;
114
+ }
115
+
116
+ IERC20Upgradeable(convertibleBaseAsset).safeTransfer(shortfall, amount);
117
+ emit TransferredReserveForAuction(comptroller, amount);
118
+
119
+ return amount;
120
+ }
121
+
122
+ /// @notice Function to sweep baseAsset for pool, Tokens are sent to address(to)
123
+ /// @param tokenAddress Address of the asset(token)
124
+ /// @param to Address to which assets will be transferred
125
+ /// @param amount Amount need to sweep for the pool
126
+ /// @custom:event Emits SweepToken event on success
127
+ /// @custom:error ZeroAddressNotAllowed is thrown when tokenAddress/to address is zero
128
+ /// @custom:error ZeroValueNotAllowed is thrown when amount is zero
129
+ /// @custom:access Only Governance
130
+ function sweepToken(
131
+ address tokenAddress,
132
+ address to,
133
+ uint256 amount
134
+ ) external onlyOwner nonReentrant {
135
+ ensureNonzeroAddress(tokenAddress);
136
+ ensureNonzeroAddress(to);
137
+ ensureNonzeroValue(amount);
138
+
139
+ IERC20Upgradeable token = IERC20Upgradeable(tokenAddress);
140
+ preSweepToken(tokenAddress, amount);
141
+ token.safeTransfer(to, amount);
142
+
143
+ emit SweepToken(tokenAddress, to, amount);
144
+ }
145
+
146
+ /**
147
+ * @notice Get the Amount of the Base asset in the risk fund for the specific pool.
148
+ * @param comptroller Comptroller address(pool).
149
+ * @return Base Asset's reserve in risk fund.
150
+ */
151
+ function getPoolsBaseAssetReserves(address comptroller) external view returns (uint256) {
152
+ return poolAssetsFunds[comptroller][convertibleBaseAsset];
153
+ }
154
+
155
+ /// @dev Update the reserve of the asset for the specific pool after transferring to risk fund
156
+ /// @param comptroller Comptroller address (pool)
157
+ /// @param asset Address of the asset(token)
158
+ /// @param amount Amount transferred for the pool
159
+ /// @custom:event PoolAssetsIncreased emits on success
160
+ /// @custom:error InvalidRiskFundConverter is thrown if caller is not riskFundConverter contract
161
+ /// @custom:access Only RiskFundConverter contract
162
+ function updatePoolState(
163
+ address comptroller,
164
+ address asset,
165
+ uint256 amount
166
+ ) public {
167
+ if (msg.sender != riskFundConverter) {
168
+ revert InvalidRiskFundConverter();
169
+ }
170
+
171
+ poolAssetsFunds[comptroller][asset] += amount;
172
+ emit PoolAssetsIncreased(comptroller, asset, amount);
173
+ }
174
+
175
+ /// @dev Operations to perform before sweeping tokens
176
+ /// @param tokenAddress Address of the token
177
+ /// @param amount Amount transferred to address(to)
178
+ /// @custom:error InsufficientBalance is thrown when amount entered is greater than balance
179
+ function preSweepToken(address tokenAddress, uint256 amount) internal {
180
+ uint256 balance = IERC20Upgradeable(tokenAddress).balanceOf(address(this));
181
+ if (amount > balance) revert InsufficientBalance();
182
+
183
+ address[] memory pools = IRiskFundConverter(riskFundConverter).getPools(tokenAddress);
184
+
185
+ uint256 assetReserves;
186
+ uint256 poolsLength = pools.length;
187
+ for (uint256 i; i < poolsLength; ) {
188
+ assetReserves += poolAssetsFunds[pools[i]][tokenAddress];
189
+ unchecked {
190
+ ++i;
191
+ }
192
+ }
193
+
194
+ uint256 balanceDiff = balance - assetReserves;
195
+
196
+ if (balanceDiff < amount) {
197
+ uint256 amountDiff;
198
+ unchecked {
199
+ amountDiff = amount - balanceDiff;
200
+ }
201
+ uint256 distributedShare;
202
+ for (uint256 i; i < poolsLength; ) {
203
+ if (poolAssetsFunds[pools[i]][tokenAddress] != 0) {
204
+ uint256 poolAmountShare;
205
+ if (i < (poolsLength - 1)) {
206
+ poolAmountShare = (poolAssetsFunds[pools[i]][tokenAddress] * amount) / assetReserves;
207
+ distributedShare += poolAmountShare;
208
+ } else {
209
+ poolAmountShare = amountDiff - distributedShare;
210
+ }
211
+ poolAssetsFunds[pools[i]][tokenAddress] -= poolAmountShare;
212
+ emit PoolAssetsDecreased(pools[i], tokenAddress, poolAmountShare);
213
+ }
214
+ unchecked {
215
+ ++i;
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
5
+ import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
6
+ import { AccessControlledV8 } from "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
7
+ import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
8
+
9
+ import { ensureNonzeroAddress, ensureNonzeroValue } from "../Utils/Validators.sol";
10
+ import { IXVSVault } from "../Interfaces/IXVSVault.sol";
11
+
12
+ /// @title XVSVaultTreasury
13
+ /// @author Venus
14
+ /// @notice XVSVaultTreasury stores the tokens sent by SingleTokenConverter(XVS) and funds XVSVault
15
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
16
+ contract XVSVaultTreasury is AccessControlledV8, ReentrancyGuardUpgradeable {
17
+ using SafeERC20Upgradeable for IERC20Upgradeable;
18
+
19
+ /// @notice The xvs token address
20
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
21
+ address public immutable XVS_ADDRESS;
22
+
23
+ /// @notice The xvsvault address
24
+ address public xvsVault;
25
+
26
+ /// @notice Emitted when XVS vault address is updated
27
+ event XVSVaultUpdated(address indexed oldXVSVault, address indexed newXVSVault);
28
+
29
+ /// @notice Emitted when funds transferred to XVSStore address
30
+ event FundsTransferredToXVSStore(address indexed xvsStore, uint256 amountMantissa);
31
+
32
+ /// @notice Thrown when given input amount is zero
33
+ error InsufficientBalance();
34
+
35
+ /// @custom:oz-upgrades-unsafe-allow constructor
36
+ /// @param xvsAddress_ XVS token address
37
+ constructor(address xvsAddress_) {
38
+ ensureNonzeroAddress(xvsAddress_);
39
+ XVS_ADDRESS = xvsAddress_;
40
+
41
+ // Note that the contract is upgradeable. Use initialize() or reinitializers
42
+ // to set the state variables.
43
+ _disableInitializers();
44
+ }
45
+
46
+ /// @param accessControlManager_ Access control manager contract address
47
+ /// @param xvsVault_ XVSVault address
48
+ /// @custom:event XVSVaultUpdated emits on success
49
+ /// @custom:error ZeroAddressNotAllowed is thrown when XVS vault address is zero
50
+ function initialize(address accessControlManager_, address xvsVault_) public initializer {
51
+ __AccessControlled_init(accessControlManager_);
52
+ __ReentrancyGuard_init();
53
+ _setXVSVault(xvsVault_);
54
+ }
55
+
56
+ /// @dev XVS vault setter
57
+ /// @param xvsVault_ Address of the XVS vault
58
+ /// @custom:event XVSVaultUpdated emits on success
59
+ /// @custom:error ZeroAddressNotAllowed is thrown when XVS vault address is zero
60
+ function setXVSVault(address xvsVault_) external onlyOwner {
61
+ _setXVSVault(xvsVault_);
62
+ }
63
+
64
+ /// @notice This function transfers funds to the XVS vault
65
+ /// @param amountMantissa Amount to be sent to XVS vault
66
+ /// @custom:event FundsTransferredToXVSStore emits on success
67
+ /// @custom:error InsufficientBalance is thrown when amount entered is greater than balance
68
+ /// @custom:access Restricted by ACM
69
+ function fundXVSVault(uint256 amountMantissa) external nonReentrant {
70
+ _checkAccessAllowed("fundXVSVault(uint256)");
71
+ ensureNonzeroValue(amountMantissa);
72
+
73
+ uint256 balance = IERC20Upgradeable(XVS_ADDRESS).balanceOf(address(this));
74
+
75
+ if (balance < amountMantissa) {
76
+ revert InsufficientBalance();
77
+ }
78
+
79
+ address xvsStore = IXVSVault(xvsVault).xvsStore();
80
+ ensureNonzeroAddress(xvsStore);
81
+ IERC20Upgradeable(XVS_ADDRESS).safeTransfer(xvsStore, amountMantissa);
82
+
83
+ emit FundsTransferredToXVSStore(xvsStore, amountMantissa);
84
+ }
85
+
86
+ /// @dev XVS vault setter
87
+ /// @param xvsVault_ Address of the XVS vault
88
+ /// @custom:event XVSVaultUpdated emits on success
89
+ /// @custom:error ZeroAddressNotAllowed is thrown when XVS vault address is zero
90
+ function _setXVSVault(address xvsVault_) internal {
91
+ ensureNonzeroAddress(xvsVault_);
92
+ emit XVSVaultUpdated(xvsVault, xvsVault_);
93
+ xvsVault = xvsVault_;
94
+ }
95
+ }