@venusprotocol/protocol-reserve 1.0.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 (280) hide show
  1. package/README.md +75 -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 +4 -0
  5. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +183 -0
  6. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +4 -0
  7. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +297 -0
  8. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +4 -0
  9. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +194 -0
  10. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +4 -0
  11. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +233 -0
  12. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
  13. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
  14. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
  15. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
  16. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
  17. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
  18. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
  19. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
  20. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
  21. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
  22. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +4 -0
  23. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +10 -0
  24. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +4 -0
  25. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +115 -0
  26. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +4 -0
  27. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +76 -0
  28. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +4 -0
  29. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +24 -0
  30. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +4 -0
  31. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +63 -0
  32. package/artifacts/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol/ReentrancyGuardUpgradeable.dbg.json +4 -0
  33. package/artifacts/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol/ReentrancyGuardUpgradeable.json +24 -0
  34. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol/IERC20Upgradeable.dbg.json +4 -0
  35. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol/IERC20Upgradeable.json +194 -0
  36. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.dbg.json +4 -0
  37. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol/IERC20PermitUpgradeable.json +86 -0
  38. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol/SafeERC20Upgradeable.dbg.json +4 -0
  39. package/artifacts/@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol/SafeERC20Upgradeable.json +10 -0
  40. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +4 -0
  41. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +10 -0
  42. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +4 -0
  43. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +24 -0
  44. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +4 -0
  45. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +181 -0
  46. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +4 -0
  47. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +282 -0
  48. package/artifacts/@venusprotocol/isolated-pools/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.dbg.json +4 -0
  49. package/artifacts/@venusprotocol/isolated-pools/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.json +59 -0
  50. package/artifacts/@venusprotocol/oracle/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +4 -0
  51. package/artifacts/@venusprotocol/oracle/contracts/ResilientOracle.sol/ResilientOracle.json +649 -0
  52. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +4 -0
  53. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +40 -0
  54. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +4 -0
  55. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/OracleInterface.json +30 -0
  56. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +4 -0
  57. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +75 -0
  58. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +4 -0
  59. package/artifacts/@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol/TwapInterface.json +49 -0
  60. package/artifacts/@venusprotocol/oracle/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +4 -0
  61. package/artifacts/@venusprotocol/oracle/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +246 -0
  62. package/artifacts/@venusprotocol/solidity-utilities/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.dbg.json +4 -0
  63. package/artifacts/@venusprotocol/solidity-utilities/contracts/MaxLoopsLimitHelper.sol/MaxLoopsLimitHelper.json +59 -0
  64. package/artifacts/build-info/09a7fbe40ee8fdfd62afe79292e77863.json +1 -0
  65. package/artifacts/contracts/Interfaces/IComptroller.sol/IComptroller.dbg.json +4 -0
  66. package/artifacts/contracts/Interfaces/IComptroller.sol/IComptroller.json +56 -0
  67. package/artifacts/contracts/Interfaces/IConverterNetwork.sol/IConverterNetwork.dbg.json +4 -0
  68. package/artifacts/contracts/Interfaces/IConverterNetwork.sol/IConverterNetwork.json +127 -0
  69. package/artifacts/contracts/Interfaces/IIncomeDestination.sol/IIncomeDestination.dbg.json +4 -0
  70. package/artifacts/contracts/Interfaces/IIncomeDestination.sol/IIncomeDestination.json +29 -0
  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/IPrime.sol/IPrime.dbg.json +4 -0
  74. package/artifacts/contracts/Interfaces/IPrime.sol/IPrime.json +74 -0
  75. package/artifacts/contracts/Interfaces/IProtocolShareReserve.sol/IProtocolShareReserve.dbg.json +4 -0
  76. package/artifacts/contracts/Interfaces/IProtocolShareReserve.sol/IProtocolShareReserve.json +34 -0
  77. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFund.dbg.json +4 -0
  78. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFund.json +77 -0
  79. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFundGetters.dbg.json +4 -0
  80. package/artifacts/contracts/Interfaces/IRiskFund.sol/IRiskFundGetters.json +24 -0
  81. package/artifacts/contracts/Interfaces/IRiskFundConverter.sol/IRiskFundConverter.dbg.json +4 -0
  82. package/artifacts/contracts/Interfaces/IRiskFundConverter.sol/IRiskFundConverter.json +48 -0
  83. package/artifacts/contracts/Interfaces/IShortfall.sol/IShortfall.dbg.json +4 -0
  84. package/artifacts/contracts/Interfaces/IShortfall.sol/IShortfall.json +24 -0
  85. package/artifacts/contracts/Interfaces/IVToken.sol/IVToken.dbg.json +4 -0
  86. package/artifacts/contracts/Interfaces/IVToken.sol/IVToken.json +24 -0
  87. package/artifacts/contracts/Interfaces/IXVSVault.sol/IXVSVault.dbg.json +4 -0
  88. package/artifacts/contracts/Interfaces/IXVSVault.sol/IXVSVault.json +24 -0
  89. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.dbg.json +4 -0
  90. package/artifacts/contracts/ProtocolReserve/ProtocolShareReserve.sol/ProtocolShareReserve.json +892 -0
  91. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/MaxLoopsLimitHelpersStorage.dbg.json +4 -0
  92. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/MaxLoopsLimitHelpersStorage.json +24 -0
  93. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/ReserveHelpersStorage.dbg.json +4 -0
  94. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/ReserveHelpersStorage.json +139 -0
  95. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV1Storage.dbg.json +4 -0
  96. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV1Storage.json +178 -0
  97. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV2Storage.dbg.json +4 -0
  98. package/artifacts/contracts/ProtocolReserve/RiskFundStorage.sol/RiskFundV2Storage.json +191 -0
  99. package/artifacts/contracts/ProtocolReserve/RiskFundV2.sol/RiskFundV2.dbg.json +4 -0
  100. package/artifacts/contracts/ProtocolReserve/RiskFundV2.sol/RiskFundV2.json +582 -0
  101. package/artifacts/contracts/ProtocolReserve/XVSVaultTreasury.sol/XVSVaultTreasury.dbg.json +4 -0
  102. package/artifacts/contracts/ProtocolReserve/XVSVaultTreasury.sol/XVSVaultTreasury.json +315 -0
  103. package/artifacts/contracts/Test/Mocks/MockACM.sol/MockACM.dbg.json +4 -0
  104. package/artifacts/contracts/Test/Mocks/MockACM.sol/MockACM.json +369 -0
  105. package/artifacts/contracts/Test/Mocks/MockArraySorter.sol/MockArraySorter.dbg.json +4 -0
  106. package/artifacts/contracts/Test/Mocks/MockArraySorter.sol/MockArraySorter.json +40 -0
  107. package/artifacts/contracts/Test/Mocks/MockConverter.sol/MockConverter.dbg.json +4 -0
  108. package/artifacts/contracts/Test/Mocks/MockConverter.sol/MockConverter.json +1199 -0
  109. package/artifacts/contracts/Test/Mocks/MockDeflationaryToken.sol/MockDeflatingToken.dbg.json +4 -0
  110. package/artifacts/contracts/Test/Mocks/MockDeflationaryToken.sol/MockDeflatingToken.json +332 -0
  111. package/artifacts/contracts/Test/Mocks/MockRiskFundConverter.sol/MockRiskFundConverter.dbg.json +4 -0
  112. package/artifacts/contracts/Test/Mocks/MockRiskFundConverter.sol/MockRiskFundConverter.json +1559 -0
  113. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.dbg.json +4 -0
  114. package/artifacts/contracts/Test/Mocks/MockToken.sol/MockToken.json +333 -0
  115. package/artifacts/contracts/TokenConverter/AbstractTokenConverter.sol/AbstractTokenConverter.dbg.json +4 -0
  116. package/artifacts/contracts/TokenConverter/AbstractTokenConverter.sol/AbstractTokenConverter.json +1085 -0
  117. package/artifacts/contracts/TokenConverter/ConverterNetwork.sol/ConverterNetwork.dbg.json +4 -0
  118. package/artifacts/contracts/TokenConverter/ConverterNetwork.sol/ConverterNetwork.json +457 -0
  119. package/artifacts/contracts/TokenConverter/IAbstractTokenConverter.sol/IAbstractTokenConverter.dbg.json +4 -0
  120. package/artifacts/contracts/TokenConverter/IAbstractTokenConverter.sol/IAbstractTokenConverter.json +344 -0
  121. package/artifacts/contracts/TokenConverter/RiskFundConverter.sol/RiskFundConverter.dbg.json +4 -0
  122. package/artifacts/contracts/TokenConverter/RiskFundConverter.sol/RiskFundConverter.json +1429 -0
  123. package/artifacts/contracts/TokenConverter/SingleTokenConverter.sol/SingleTokenConverter.dbg.json +4 -0
  124. package/artifacts/contracts/TokenConverter/SingleTokenConverter.sol/SingleTokenConverter.json +1145 -0
  125. package/contracts/Interfaces/IComptroller.sol +10 -0
  126. package/contracts/Interfaces/IConverterNetwork.sol +46 -0
  127. package/contracts/Interfaces/IIncomeDestination.sol +6 -0
  128. package/contracts/Interfaces/IPoolRegistry.sol +10 -0
  129. package/contracts/Interfaces/IPrime.sol +12 -0
  130. package/contracts/Interfaces/IProtocolShareReserve.sol +16 -0
  131. package/contracts/Interfaces/IRiskFund.sol +28 -0
  132. package/contracts/Interfaces/IRiskFundConverter.sol +8 -0
  133. package/contracts/Interfaces/IShortfall.sol +11 -0
  134. package/contracts/Interfaces/IVToken.sol +6 -0
  135. package/contracts/Interfaces/IXVSVault.sol +9 -0
  136. package/contracts/ProtocolReserve/ProtocolShareReserve.sol +547 -0
  137. package/contracts/ProtocolReserve/RiskFundStorage.sol +67 -0
  138. package/contracts/ProtocolReserve/RiskFundV2.sol +220 -0
  139. package/contracts/ProtocolReserve/XVSVaultTreasury.sol +95 -0
  140. package/contracts/Test/Mocks/MockACM.sol +93 -0
  141. package/contracts/Test/Mocks/MockArraySorter.sol +14 -0
  142. package/contracts/Test/Mocks/MockConverter.sol +69 -0
  143. package/contracts/Test/Mocks/MockDeflationaryToken.sol +113 -0
  144. package/contracts/Test/Mocks/MockRiskFundConverter.sol +45 -0
  145. package/contracts/Test/Mocks/MockToken.sol +30 -0
  146. package/contracts/TokenConverter/AbstractTokenConverter.sol +1022 -0
  147. package/contracts/TokenConverter/ConverterNetwork.sol +242 -0
  148. package/contracts/TokenConverter/IAbstractTokenConverter.sol +132 -0
  149. package/contracts/TokenConverter/RiskFundConverter.sol +436 -0
  150. package/contracts/TokenConverter/SingleTokenConverter.sol +77 -0
  151. package/contracts/Utils/ArrayHelpers.sol +41 -0
  152. package/contracts/Utils/Constants.sol +11 -0
  153. package/contracts/Utils/Validators.sol +26 -0
  154. package/deploy/001-risk-fund-converter.ts +124 -0
  155. package/deploy/1-deploy.ts +64 -0
  156. package/deployments/bscmainnet/.chainId +1 -0
  157. package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
  158. package/deployments/bscmainnet/ProtocolShareReserve.json +1126 -0
  159. package/deployments/bscmainnet/ProtocolShareReserve_Implementation.json +1400 -0
  160. package/deployments/bscmainnet/ProtocolShareReserve_Proxy.json +261 -0
  161. package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  162. package/deployments/bscmainnet/solcInputs/aee5f1db1180ece295e59c8f036fe600.json +90 -0
  163. package/deployments/bsctestnet/.chainId +1 -0
  164. package/deployments/bsctestnet/DefaultProxyAdmin.json +257 -0
  165. package/deployments/bsctestnet/ProtocolShareReserve.json +1126 -0
  166. package/deployments/bsctestnet/ProtocolShareReserve_Implementation.json +1400 -0
  167. package/deployments/bsctestnet/ProtocolShareReserve_Proxy.json +261 -0
  168. package/deployments/bsctestnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  169. package/deployments/bsctestnet/solcInputs/aee5f1db1180ece295e59c8f036fe600.json +90 -0
  170. package/package.json +119 -0
  171. package/typechain/AbstractTokenConverter.d.ts +1516 -0
  172. package/typechain/AccessControl.d.ts +388 -0
  173. package/typechain/AccessControlledV8.d.ts +341 -0
  174. package/typechain/BoundValidatorInterface.d.ts +126 -0
  175. package/typechain/ContextUpgradeable.d.ts +92 -0
  176. package/typechain/ConverterNetwork.d.ts +721 -0
  177. package/typechain/ERC165.d.ts +116 -0
  178. package/typechain/ERC20.d.ts +441 -0
  179. package/typechain/IAbstractTokenConverter.d.ts +606 -0
  180. package/typechain/IAccessControl.d.ts +333 -0
  181. package/typechain/IAccessControlManagerV8.d.ts +504 -0
  182. package/typechain/IComptroller.d.ts +136 -0
  183. package/typechain/IConverterNetwork.d.ts +292 -0
  184. package/typechain/IERC165.d.ts +116 -0
  185. package/typechain/IERC20.d.ts +324 -0
  186. package/typechain/IERC20Metadata.d.ts +363 -0
  187. package/typechain/IERC20PermitUpgradeable.d.ts +187 -0
  188. package/typechain/IERC20Upgradeable.d.ts +324 -0
  189. package/typechain/IIncomeDestination.d.ts +122 -0
  190. package/typechain/IPoolRegistry.d.ts +155 -0
  191. package/typechain/IPrime.d.ts +197 -0
  192. package/typechain/IProtocolShareReserve.d.ts +127 -0
  193. package/typechain/IRiskFund.d.ts +200 -0
  194. package/typechain/IRiskFundConverter.d.ts +138 -0
  195. package/typechain/IRiskFundGetters.d.ts +103 -0
  196. package/typechain/IShortfall.d.ts +110 -0
  197. package/typechain/IVToken.d.ts +98 -0
  198. package/typechain/IXVSVault.d.ts +95 -0
  199. package/typechain/Initializable.d.ts +92 -0
  200. package/typechain/MaxLoopsLimitHelper.d.ts +128 -0
  201. package/typechain/MaxLoopsLimitHelpersStorage.d.ts +101 -0
  202. package/typechain/MockACM.d.ts +615 -0
  203. package/typechain/MockArraySorter.d.ts +118 -0
  204. package/typechain/MockConverter.d.ts +1705 -0
  205. package/typechain/MockDeflatingToken.d.ts +486 -0
  206. package/typechain/MockRiskFundConverter.d.ts +2193 -0
  207. package/typechain/MockToken.d.ts +505 -0
  208. package/typechain/OracleInterface.d.ts +98 -0
  209. package/typechain/Ownable2StepUpgradeable.d.ts +261 -0
  210. package/typechain/OwnableUpgradeable.d.ts +193 -0
  211. package/typechain/PausableUpgradeable.d.ts +129 -0
  212. package/typechain/ProtocolShareReserve.d.ts +1332 -0
  213. package/typechain/ReentrancyGuardUpgradeable.d.ts +92 -0
  214. package/typechain/ReserveHelpersStorage.d.ts +300 -0
  215. package/typechain/ResilientOracle.d.ts +1022 -0
  216. package/typechain/ResilientOracleInterface.d.ts +192 -0
  217. package/typechain/RiskFundConverter.d.ts +1949 -0
  218. package/typechain/RiskFundV1Storage.d.ts +353 -0
  219. package/typechain/RiskFundV2.d.ts +893 -0
  220. package/typechain/RiskFundV2Storage.d.ts +372 -0
  221. package/typechain/SingleTokenConverter.d.ts +1598 -0
  222. package/typechain/TwapInterface.d.ts +124 -0
  223. package/typechain/VBep20Interface.d.ts +379 -0
  224. package/typechain/XVSVaultTreasury.d.ts +515 -0
  225. package/typechain/common.d.ts +35 -0
  226. package/typechain/factories/AbstractTokenConverter__factory.ts +1105 -0
  227. package/typechain/factories/AccessControl__factory.ts +227 -0
  228. package/typechain/factories/AccessControlledV8__factory.ts +196 -0
  229. package/typechain/factories/BoundValidatorInterface__factory.ts +59 -0
  230. package/typechain/factories/ContextUpgradeable__factory.ts +39 -0
  231. package/typechain/factories/ConverterNetwork__factory.ts +502 -0
  232. package/typechain/factories/ERC165__factory.ts +39 -0
  233. package/typechain/factories/ERC20__factory.ts +340 -0
  234. package/typechain/factories/IAbstractTokenConverter__factory.ts +364 -0
  235. package/typechain/factories/IAccessControlManagerV8__factory.ts +301 -0
  236. package/typechain/factories/IAccessControl__factory.ts +198 -0
  237. package/typechain/factories/IComptroller__factory.ts +68 -0
  238. package/typechain/factories/IConverterNetwork__factory.ts +142 -0
  239. package/typechain/factories/IERC165__factory.ts +42 -0
  240. package/typechain/factories/IERC20Metadata__factory.ts +248 -0
  241. package/typechain/factories/IERC20PermitUpgradeable__factory.ts +105 -0
  242. package/typechain/factories/IERC20Upgradeable__factory.ts +209 -0
  243. package/typechain/factories/IERC20__factory.ts +203 -0
  244. package/typechain/factories/IIncomeDestination__factory.ts +44 -0
  245. package/typechain/factories/IPoolRegistry__factory.ts +66 -0
  246. package/typechain/factories/IPrime__factory.ts +83 -0
  247. package/typechain/factories/IProtocolShareReserve__factory.ts +53 -0
  248. package/typechain/factories/IRiskFundConverter__factory.ts +63 -0
  249. package/typechain/factories/IRiskFundGetters__factory.ts +39 -0
  250. package/typechain/factories/IRiskFund__factory.ts +89 -0
  251. package/typechain/factories/IShortfall__factory.ts +36 -0
  252. package/typechain/factories/IVToken__factory.ts +36 -0
  253. package/typechain/factories/IXVSVault__factory.ts +36 -0
  254. package/typechain/factories/Initializable__factory.ts +36 -0
  255. package/typechain/factories/MaxLoopsLimitHelper__factory.ts +74 -0
  256. package/typechain/factories/MaxLoopsLimitHelpersStorage__factory.ts +75 -0
  257. package/typechain/factories/MockACM__factory.ts +411 -0
  258. package/typechain/factories/MockArraySorter__factory.ts +85 -0
  259. package/typechain/factories/MockConverter__factory.ts +1242 -0
  260. package/typechain/factories/MockDeflatingToken__factory.ts +389 -0
  261. package/typechain/factories/MockRiskFundConverter__factory.ts +1625 -0
  262. package/typechain/factories/MockToken__factory.ts +398 -0
  263. package/typechain/factories/OracleInterface__factory.ts +45 -0
  264. package/typechain/factories/Ownable2StepUpgradeable__factory.ts +134 -0
  265. package/typechain/factories/OwnableUpgradeable__factory.ts +91 -0
  266. package/typechain/factories/PausableUpgradeable__factory.ts +78 -0
  267. package/typechain/factories/ProtocolShareReserve__factory.ts +957 -0
  268. package/typechain/factories/ReentrancyGuardUpgradeable__factory.ts +43 -0
  269. package/typechain/factories/ReserveHelpersStorage__factory.ts +188 -0
  270. package/typechain/factories/ResilientOracleInterface__factory.ts +94 -0
  271. package/typechain/factories/ResilientOracle__factory.ts +710 -0
  272. package/typechain/factories/RiskFundConverter__factory.ts +1491 -0
  273. package/typechain/factories/RiskFundV1Storage__factory.ts +223 -0
  274. package/typechain/factories/RiskFundV2Storage__factory.ts +236 -0
  275. package/typechain/factories/RiskFundV2__factory.ts +624 -0
  276. package/typechain/factories/SingleTokenConverter__factory.ts +1200 -0
  277. package/typechain/factories/TwapInterface__factory.ts +61 -0
  278. package/typechain/factories/VBep20Interface__factory.ts +261 -0
  279. package/typechain/factories/XVSVaultTreasury__factory.ts +365 -0
  280. package/typechain/index.ts +112 -0
@@ -0,0 +1,436 @@
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 { ResilientOracle } from "@venusprotocol/oracle/contracts/ResilientOracle.sol";
7
+
8
+ import { AbstractTokenConverter } from "./AbstractTokenConverter.sol";
9
+ import { ensureNonzeroAddress, ensureNonzeroValue } from "../Utils/Validators.sol";
10
+ import { IPoolRegistry } from "../Interfaces/IPoolRegistry.sol";
11
+ import { IComptroller } from "../Interfaces/IComptroller.sol";
12
+ import { IRiskFund, IRiskFundGetters } from "../Interfaces/IRiskFund.sol";
13
+ import { IVToken } from "../Interfaces/IVToken.sol";
14
+
15
+ /// @title RiskFundConverter
16
+ /// @author Venus
17
+ /// @notice RiskFundConverter used for token conversions and sends received token to RiskFund
18
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
19
+ contract RiskFundConverter is AbstractTokenConverter {
20
+ using SafeERC20Upgradeable for IERC20Upgradeable;
21
+
22
+ /// @notice Address of the core pool comptroller
23
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
24
+ address public immutable CORE_POOL_COMPTROLLER;
25
+
26
+ ///@notice Address of the vBNB
27
+ ///@dev This address is used to include the BNB market while in getPools method
28
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
29
+ address public immutable VBNB;
30
+
31
+ ///@notice Address of the native wrapped currency
32
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
33
+ address public immutable NATIVE_WRAPPED;
34
+
35
+ /// @notice Store the previous state for the asset transferred to ProtocolShareReserve combined(for all pools)
36
+ mapping(address => uint256) internal assetsReserves;
37
+
38
+ /// @notice Store the asset's reserve per pool in the ProtocolShareReserve
39
+ /// @dev Comptroller(pool) -> Asset -> amount
40
+ mapping(address => mapping(address => uint256)) internal poolsAssetsReserves;
41
+
42
+ /// @notice Address of pool registry contract
43
+ address public poolRegistry;
44
+
45
+ /// @notice The mapping contains the assets for each pool which are sent to RiskFund directly
46
+ /// @dev Comptroller(pool) -> Asset -> bool(should transfer directly on true)
47
+ mapping(address => mapping(address => bool)) public poolsAssetsDirectTransfer;
48
+
49
+ /// @notice Emitted when pool registry address is updated
50
+ event PoolRegistryUpdated(address indexed oldPoolRegistry, address indexed newPoolRegistry);
51
+
52
+ /// @notice Emitted after updating of the assets reserves
53
+ /// amount -> reserve increased by amount
54
+ event AssetsReservesUpdated(address indexed comptroller, address indexed asset, uint256 amount);
55
+
56
+ /// @notice Emmitted after the funds transferred to the destination address
57
+ event AssetTransferredToDestination(address indexed comptroller, address indexed asset, uint256 amount);
58
+
59
+ /// @notice Emitted after the poolsAssetsDirectTransfer mapping is updated
60
+ event PoolAssetsDirectTransferUpdated(address indexed comptroller, address indexed asset, bool value);
61
+
62
+ // Error thrown when comptrollers array length is not equal to assets array length
63
+ error InvalidArguments();
64
+
65
+ /// @notice thrown when amount entered is greater than balance
66
+ error InsufficientBalance();
67
+
68
+ /// @notice thrown when asset does not exist in the pool
69
+ error MarketNotExistInPool(address comptroller, address asset);
70
+
71
+ /// @notice thrown to prevent reentrancy
72
+ /// @dev This error is used to safeguard against reentrancy attacks, ensuring that a certain operation
73
+ /// cannot be called recursively within the same transaction.
74
+ error ReentrancyGuardError();
75
+
76
+ /// @param corePoolComptroller_ Address of the Comptroller pool
77
+ /// @param vBNB_ Address of the vBNB
78
+ /// @param nativeWrapped_ Address of the wrapped native currency
79
+ /// @custom:oz-upgrades-unsafe-allow constructor
80
+ constructor(
81
+ address corePoolComptroller_,
82
+ address vBNB_,
83
+ address nativeWrapped_
84
+ ) {
85
+ ensureNonzeroAddress(corePoolComptroller_);
86
+ ensureNonzeroAddress(vBNB_);
87
+ ensureNonzeroAddress(nativeWrapped_);
88
+
89
+ CORE_POOL_COMPTROLLER = corePoolComptroller_;
90
+ VBNB = vBNB_;
91
+ NATIVE_WRAPPED = nativeWrapped_;
92
+
93
+ // Note that the contract is upgradeable. Use initialize() or reinitializers
94
+ // to set the state variables.
95
+ _disableInitializers();
96
+ }
97
+
98
+ /// @param accessControlManager_ Access control manager contract address
99
+ /// @param priceOracle_ Resilient oracle address
100
+ /// @param destinationAddress_ Address at all incoming tokens will transferred to
101
+ /// @param poolRegistry_ Address of the pool registry
102
+ /// @param comptrollers Addresses of the pools
103
+ /// @param assets Addresses of the assets need to be added for direct transfer
104
+ /// @param values Boolean value to indicate whether direct transfer is allowed for each asset.
105
+ /// @custom:event PoolAssetsDirectTransferUpdated emits on success
106
+ function initialize(
107
+ address accessControlManager_,
108
+ ResilientOracle priceOracle_,
109
+ address destinationAddress_,
110
+ address poolRegistry_,
111
+ address[] calldata comptrollers,
112
+ address[][] calldata assets,
113
+ bool[][] calldata values
114
+ ) public initializer {
115
+ // Initialize AbstractTokenConverter
116
+ __AbstractTokenConverter_init(accessControlManager_, priceOracle_, destinationAddress_);
117
+ ensureNonzeroAddress(poolRegistry_);
118
+ poolRegistry = poolRegistry_;
119
+ _setPoolsAssetsDirectTransfer(comptrollers, assets, values);
120
+ }
121
+
122
+ /// @dev Pool registry setter
123
+ /// @param poolRegistry_ Address of the pool registry
124
+ /// @custom:event PoolRegistryUpdated emits on success
125
+ /// @custom:error ZeroAddressNotAllowed is thrown when pool registry address is zero
126
+ /// @custom:access Only Governance
127
+ function setPoolRegistry(address poolRegistry_) external onlyOwner {
128
+ ensureNonzeroAddress(poolRegistry_);
129
+ emit PoolRegistryUpdated(poolRegistry, poolRegistry_);
130
+ poolRegistry = poolRegistry_;
131
+ }
132
+
133
+ /// @notice Update the poolsAssetsDirectTransfer mapping
134
+ /// @param comptrollers Addresses of the pools
135
+ /// @param assets Addresses of the assets need to be added for direct transfer
136
+ /// @param values Boolean value to indicate whether direct transfer is allowed for each asset.
137
+ /// @custom:event PoolAssetsDirectTransferUpdated emits on success
138
+ /// @custom:access Restricted by ACM
139
+ function setPoolsAssetsDirectTransfer(
140
+ address[] calldata comptrollers,
141
+ address[][] calldata assets,
142
+ bool[][] calldata values
143
+ ) external {
144
+ _checkAccessAllowed("setPoolsAssetsDirectTransfer(address[],address[][],bool[][])");
145
+ _setPoolsAssetsDirectTransfer(comptrollers, assets, values);
146
+ }
147
+
148
+ /// @dev Get the Amount of the asset in the risk fund for the specific pool
149
+ /// @param comptroller Comptroller address (pool)
150
+ /// @param asset Asset address
151
+ /// @return Asset's reserve in risk fund
152
+ /// @custom:error MarketNotExistInPool When asset does not exist in the pool(comptroller)
153
+ /// @custom:error ReentrancyGuardError thrown to prevent reentrancy during the function execution
154
+ function getPoolAssetReserve(address comptroller, address asset) external view returns (uint256) {
155
+ if (_reentrancyGuardEntered()) revert ReentrancyGuardError();
156
+ if (!ensureAssetListed(comptroller, asset)) revert MarketNotExistInPool(comptroller, asset);
157
+
158
+ return poolsAssetsReserves[comptroller][asset];
159
+ }
160
+
161
+ /// @notice Get the balance for specific token
162
+ /// @param tokenAddress Address of the token
163
+ /// @return Reserves of the token the contract has
164
+ function balanceOf(address tokenAddress) public view override returns (uint256) {
165
+ return assetsReserves[tokenAddress];
166
+ }
167
+
168
+ /// @notice Get the array of all pools addresses
169
+ /// @param tokenAddress Address of the token
170
+ /// @return Array of the pools addresses in which token is available
171
+ function getPools(address tokenAddress) public view returns (address[] memory) {
172
+ address[] memory pools = IPoolRegistry(poolRegistry).getPoolsSupportedByAsset(tokenAddress);
173
+
174
+ if (isAssetListedInCore(tokenAddress)) {
175
+ uint256 poolsLength = pools.length;
176
+ address[] memory poolsWithCore = new address[](poolsLength + 1);
177
+
178
+ for (uint256 i; i < poolsLength; ) {
179
+ poolsWithCore[i] = pools[i];
180
+ unchecked {
181
+ ++i;
182
+ }
183
+ }
184
+ poolsWithCore[poolsLength] = CORE_POOL_COMPTROLLER;
185
+ return poolsWithCore;
186
+ }
187
+
188
+ return pools;
189
+ }
190
+
191
+ /// @notice This hook is used to update the state for asset reserves before transferring tokenOut to user
192
+ /// @param tokenOutAddress Address of the asset to be transferred to the user
193
+ /// @param amountOut Amount of tokenAddressOut transferred from this converter
194
+ function _preTransferHook(address tokenOutAddress, uint256 amountOut) internal override {
195
+ assetsReserves[tokenOutAddress] -= amountOut;
196
+ }
197
+
198
+ /// @notice Hook to perform after converting tokens
199
+ /// @dev After transformation poolsAssetsReserves are settled by pool's reserves fraction
200
+ /// @param tokenInAddress Address of the tokenIn
201
+ /// @param tokenOutAddress Address of the tokenOut
202
+ /// @param amountIn Amount of tokenIn transferred
203
+ /// @param amountOut Amount of tokenOut transferred
204
+ /// @custom:event AssetTransferredToDestination emits on success for each pool which has share
205
+ function _postConversionHook(
206
+ address tokenInAddress,
207
+ address tokenOutAddress,
208
+ uint256 amountIn,
209
+ uint256 amountOut
210
+ ) internal override {
211
+ address[] memory pools = getPools(tokenOutAddress);
212
+ uint256 assetReserve = assetsReserves[tokenOutAddress] + amountOut;
213
+ ensureNonzeroValue(assetReserve);
214
+
215
+ uint256 poolsLength = pools.length;
216
+ uint256 distributedOutShare;
217
+ uint256 poolAmountInShare;
218
+ uint256 distributedInShare;
219
+
220
+ for (uint256 i; i < poolsLength; ) {
221
+ uint256 currentPoolsAssetsReserves = poolsAssetsReserves[pools[i]][tokenOutAddress];
222
+ if (currentPoolsAssetsReserves != 0) {
223
+ if (i < (poolsLength - 1)) {
224
+ distributedOutShare += updatePoolAssetsReserve(pools[i], tokenOutAddress, amountOut, assetReserve);
225
+ poolAmountInShare = (amountIn * currentPoolsAssetsReserves) / assetReserve;
226
+ distributedInShare += poolAmountInShare;
227
+ } else {
228
+ uint256 distributedDiff = amountOut - distributedOutShare;
229
+ poolsAssetsReserves[pools[i]][tokenOutAddress] -= distributedDiff;
230
+ emit AssetsReservesUpdated(pools[i], tokenOutAddress, distributedDiff);
231
+ poolAmountInShare = amountIn - distributedInShare;
232
+ }
233
+ emit AssetTransferredToDestination(pools[i], tokenInAddress, poolAmountInShare);
234
+ IRiskFund(destinationAddress).updatePoolState(pools[i], tokenInAddress, poolAmountInShare);
235
+ }
236
+ unchecked {
237
+ ++i;
238
+ }
239
+ }
240
+ }
241
+
242
+ /// @notice Operations to perform before sweeping tokens
243
+ /// @param tokenAddress Address of the token
244
+ /// @param amount Amount transferred to address(to)
245
+ /// @custom:error InsufficientBalance is thrown when amount entered is greater than balance of token
246
+ function preSweepToken(address tokenAddress, uint256 amount) internal override {
247
+ uint256 balance = IERC20Upgradeable(tokenAddress).balanceOf(address(this));
248
+ if (amount > balance) revert InsufficientBalance();
249
+ uint256 balanceDiff = balance - assetsReserves[tokenAddress];
250
+
251
+ if (balanceDiff < amount) {
252
+ uint256 amountDiff;
253
+ unchecked {
254
+ amountDiff = amount - balanceDiff;
255
+ }
256
+
257
+ address[] memory pools = getPools(tokenAddress);
258
+ uint256 assetReserve = assetsReserves[tokenAddress];
259
+ uint256 poolsLength = pools.length;
260
+ uint256 distributedShare;
261
+
262
+ for (uint256 i; i < poolsLength; ) {
263
+ if (poolsAssetsReserves[pools[i]][tokenAddress] != 0) {
264
+ if (i < (poolsLength - 1)) {
265
+ distributedShare += updatePoolAssetsReserve(pools[i], tokenAddress, amountDiff, assetReserve);
266
+ } else {
267
+ uint256 distributedDiff = amountDiff - distributedShare;
268
+ poolsAssetsReserves[pools[i]][tokenAddress] -= distributedDiff;
269
+ emit AssetsReservesUpdated(pools[i], tokenAddress, distributedDiff);
270
+ }
271
+ }
272
+ unchecked {
273
+ ++i;
274
+ }
275
+ }
276
+ assetsReserves[tokenAddress] -= amountDiff;
277
+ }
278
+ }
279
+
280
+ /// @notice Update the poolAssetsReserves upon transferring the tokens
281
+ /// @param pool Address of the pool
282
+ /// @param tokenAddress Address of the token
283
+ /// @param amount Amount transferred to address(to)
284
+ /// @param assetReserve Asset's reserve for the pool
285
+ /// @return poolAmountShare Share of the pool as per it's reserve in compare to total reserves for the asset
286
+ /// @custom:event AssetsReservesUpdated emits on success
287
+ function updatePoolAssetsReserve(
288
+ address pool,
289
+ address tokenAddress,
290
+ uint256 amount,
291
+ uint256 assetReserve
292
+ ) internal returns (uint256 poolAmountShare) {
293
+ poolAmountShare = (poolsAssetsReserves[pool][tokenAddress] * amount) / assetReserve;
294
+ poolsAssetsReserves[pool][tokenAddress] -= poolAmountShare;
295
+ emit AssetsReservesUpdated(pool, tokenAddress, poolAmountShare);
296
+ }
297
+
298
+ /// @notice Update the poolsAssetsDirectTransfer mapping
299
+ /// @param comptrollers Addresses of the pools
300
+ /// @param assets Addresses of the assets need to be added for direct transfer
301
+ /// @param values Boolean value to indicate whether direct transfer is allowed for each asset.
302
+ /// @custom:event PoolAssetsDirectTransferUpdated emits on success
303
+ /// @custom:error InvalidArguments thrown when comptrollers array length is not equal to assets array length
304
+ function _setPoolsAssetsDirectTransfer(
305
+ address[] calldata comptrollers,
306
+ address[][] calldata assets,
307
+ bool[][] calldata values
308
+ ) internal {
309
+ uint256 comptrollersLength = comptrollers.length;
310
+
311
+ if ((comptrollersLength != assets.length) || (comptrollersLength != values.length)) {
312
+ revert InvalidArguments();
313
+ }
314
+
315
+ for (uint256 i; i < comptrollersLength; ) {
316
+ address[] memory poolAssets = assets[i];
317
+ bool[] memory assetsValues = values[i];
318
+ uint256 poolAssetsLength = poolAssets.length;
319
+
320
+ if (poolAssetsLength != assetsValues.length) {
321
+ revert InvalidArguments();
322
+ }
323
+
324
+ for (uint256 j; j < poolAssetsLength; ) {
325
+ poolsAssetsDirectTransfer[comptrollers[i]][poolAssets[j]] = assetsValues[j];
326
+ emit PoolAssetsDirectTransferUpdated(comptrollers[i], poolAssets[j], assetsValues[j]);
327
+ unchecked {
328
+ ++j;
329
+ }
330
+ }
331
+
332
+ unchecked {
333
+ ++i;
334
+ }
335
+ }
336
+ }
337
+
338
+ /// @dev Update the reserve of the asset for the specific pool after transferring to risk fund
339
+ /// and transferring funds to the protocol share reserve
340
+ /// @param comptroller Comptroller address (pool)
341
+ /// @param asset Asset address
342
+ /// @return Amount of asset, for _privateConversion
343
+ /// @custom:event AssetTransferredToDestination emits when poolsAssetsDirectTransfer is enabled for entered comptroller and asset
344
+ /// @custom:error MarketNotExistInPool When asset does not exist in the pool(comptroller)
345
+ function _updateAssetsState(address comptroller, address asset) internal override returns (uint256) {
346
+ if (!ensureAssetListed(comptroller, asset)) revert MarketNotExistInPool(comptroller, asset);
347
+
348
+ IERC20Upgradeable token = IERC20Upgradeable(asset);
349
+ uint256 currentBalance = token.balanceOf(address(this));
350
+ uint256 assetReserve = assetsReserves[asset];
351
+ if (currentBalance > assetReserve) {
352
+ uint256 balanceDifference;
353
+ unchecked {
354
+ balanceDifference = currentBalance - assetReserve;
355
+ }
356
+ if (poolsAssetsDirectTransfer[comptroller][asset]) {
357
+ uint256 previousDestinationBalance = token.balanceOf(destinationAddress);
358
+ token.safeTransfer(destinationAddress, balanceDifference);
359
+ uint256 newDestinationBalance = token.balanceOf(destinationAddress);
360
+
361
+ emit AssetTransferredToDestination(comptroller, asset, balanceDifference);
362
+ IRiskFund(destinationAddress).updatePoolState(
363
+ comptroller,
364
+ asset,
365
+ newDestinationBalance - previousDestinationBalance
366
+ );
367
+ return 0;
368
+ }
369
+ return balanceDifference;
370
+ }
371
+ }
372
+
373
+ /// @dev This hook is used to update states for the converter after the privateConversion
374
+ /// @param comptroller Comptroller address (pool)
375
+ /// @param tokenAddressIn Address of the destination's base asset
376
+ /// @param convertedTokenInBalance Amount of the base asset received after the conversion
377
+ /// @param tokenAddressOut Address of the asset transferred to other converter in exchange of base asset
378
+ /// @param convertedTokenOutBalance Amount of tokenAddressOut transferred from this converter
379
+ function _postPrivateConversionHook(
380
+ address comptroller,
381
+ address tokenAddressIn,
382
+ uint256 convertedTokenInBalance,
383
+ address tokenAddressOut,
384
+ uint256 convertedTokenOutBalance
385
+ ) internal override {
386
+ if (convertedTokenInBalance > 0) {
387
+ emit AssetTransferredToDestination(comptroller, tokenAddressIn, convertedTokenInBalance);
388
+ IRiskFund(destinationAddress).updatePoolState(comptroller, tokenAddressIn, convertedTokenInBalance);
389
+ }
390
+ if (convertedTokenOutBalance > 0) {
391
+ assetsReserves[tokenAddressOut] += convertedTokenOutBalance;
392
+ poolsAssetsReserves[comptroller][tokenAddressOut] += convertedTokenOutBalance;
393
+ emit AssetsReservesUpdated(comptroller, tokenAddressOut, convertedTokenOutBalance);
394
+ }
395
+ }
396
+
397
+ /// @notice This function checks for the given asset is listed in core pool or not
398
+ /// @param tokenAddress Address of the asset
399
+ /// @return isAssetListed true if the asset is listed
400
+ function isAssetListedInCore(address tokenAddress) internal view returns (bool isAssetListed) {
401
+ address[] memory coreMarkets = IComptroller(CORE_POOL_COMPTROLLER).getAllMarkets();
402
+
403
+ uint256 coreMarketsLength = coreMarkets.length;
404
+ for (uint256 i; i < coreMarketsLength; ) {
405
+ isAssetListed = (VBNB == coreMarkets[i])
406
+ ? (tokenAddress == NATIVE_WRAPPED)
407
+ : (IVToken(coreMarkets[i]).underlying() == tokenAddress);
408
+
409
+ if (isAssetListed) {
410
+ break;
411
+ }
412
+
413
+ unchecked {
414
+ ++i;
415
+ }
416
+ }
417
+ }
418
+
419
+ /// @notice This function checks for the given asset is listed or not
420
+ /// @param comptroller Address of the comptroller
421
+ /// @param asset Address of the asset
422
+ /// @return true if the asset is listed
423
+ function ensureAssetListed(address comptroller, address asset) internal view returns (bool) {
424
+ if (comptroller == CORE_POOL_COMPTROLLER) {
425
+ return isAssetListedInCore(asset);
426
+ }
427
+
428
+ return IPoolRegistry(poolRegistry).getVTokenForAsset(comptroller, asset) != address(0);
429
+ }
430
+
431
+ /// @notice Get base asset address of the RiskFund
432
+ /// @return Address of the base asset(RiskFund)
433
+ function _getDestinationBaseAsset() internal view override returns (address) {
434
+ return IRiskFundGetters(destinationAddress).convertibleBaseAsset();
435
+ }
436
+ }
@@ -0,0 +1,77 @@
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 { ResilientOracle } from "@venusprotocol/oracle/contracts/ResilientOracle.sol";
7
+
8
+ import { AbstractTokenConverter } from "./AbstractTokenConverter.sol";
9
+ import { ensureNonzeroAddress } from "../Utils/Validators.sol";
10
+
11
+ /// @title SingleTokenConverter
12
+ /// @author Venus
13
+ /// @notice SingleTokenConverter used for token conversions and sends received tokens
14
+ /// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
15
+ contract SingleTokenConverter is AbstractTokenConverter {
16
+ using SafeERC20Upgradeable for IERC20Upgradeable;
17
+
18
+ /// @notice Address of the BASE_ASSET token
19
+ address public immutable BASE_ASSET;
20
+
21
+ /// @notice Emmitted after the funds transferred to the destination address
22
+ event AssetTransferredToDestination(uint256 amount);
23
+
24
+ /// @custom:oz-upgrades-unsafe-allow constructor
25
+ /// @param baseAsset_ Address of the BASE_ASSET token
26
+ /// @custom:oz-upgrades-unsafe-allow constructor
27
+ constructor(address baseAsset_) {
28
+ ensureNonzeroAddress(baseAsset_);
29
+ BASE_ASSET = baseAsset_;
30
+
31
+ // Note that the contract is upgradeable. Use initialize() or reinitializers
32
+ // to set the state variables.
33
+ _disableInitializers();
34
+ }
35
+
36
+ /// @param accessControlManager_ Access control manager contract address
37
+ /// @param priceOracle_ Resilient oracle address
38
+ /// @param destinationAddress_ Address at all incoming tokens will transferred to
39
+ function initialize(
40
+ address accessControlManager_,
41
+ ResilientOracle priceOracle_,
42
+ address destinationAddress_
43
+ ) public initializer {
44
+ // Initialize AbstractTokenConverter
45
+ __AbstractTokenConverter_init(accessControlManager_, priceOracle_, destinationAddress_);
46
+ }
47
+
48
+ /// @notice Get the balance for specific token
49
+ /// @param tokenAddress Address of the token
50
+ /// @return tokenBalance Balance of the token the contract has
51
+ function balanceOf(address tokenAddress) public view override returns (uint256 tokenBalance) {
52
+ IERC20Upgradeable token = IERC20Upgradeable(tokenAddress);
53
+ tokenBalance = token.balanceOf(address(this));
54
+ }
55
+
56
+ /// @param comptroller Comptroller address (pool)
57
+ /// @param asset Asset address.
58
+ /// @return balanceLeft Amount of asset, for _privateConversion
59
+ // solhint-disable-next-line
60
+ function _updateAssetsState(address comptroller, address asset) internal override returns (uint256 balanceLeft) {
61
+ IERC20Upgradeable token = IERC20Upgradeable(asset);
62
+ uint256 balance = token.balanceOf(address(this));
63
+ balanceLeft = balance;
64
+
65
+ if (asset == BASE_ASSET) {
66
+ balanceLeft = 0;
67
+ token.safeTransfer(destinationAddress, balance);
68
+ emit AssetTransferredToDestination(balance);
69
+ }
70
+ }
71
+
72
+ /// @notice Get base asset address
73
+ /// @return Address of the base asset(BASE_ASSET)
74
+ function _getDestinationBaseAsset() internal view override returns (address) {
75
+ return BASE_ASSET;
76
+ }
77
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /// @notice Used to sort addresses array based on their token balances
5
+ /// @param arr Array of token balances of different addresses
6
+ /// @param addrs Array containing these addresses
7
+ function sort(uint256[] memory arr, address[] memory addrs) pure {
8
+ if (arr.length > 1) {
9
+ return quickSortDescending(arr, addrs, 0, arr.length - 1);
10
+ }
11
+ }
12
+
13
+ /// @notice Used to sort addresses array based on their token balances
14
+ /// @param arr Array of token balances of different addresses
15
+ /// @param addrs Array containing these addresses
16
+ /// @param left index of first value
17
+ /// @param right index of last value
18
+ function quickSortDescending(
19
+ uint256[] memory arr,
20
+ address[] memory addrs,
21
+ uint256 left,
22
+ uint256 right
23
+ ) pure {
24
+ if (left >= right) return;
25
+ uint256 p = arr[(left + right) / 2]; // p = the pivot element
26
+ uint256 i = left;
27
+ uint256 j = right;
28
+ while (i < j) {
29
+ while (arr[i] > p) ++i;
30
+ while (arr[j] < p) --j; // arr[j] < p means p still to the right, so j > 0
31
+ if (arr[i] < arr[j]) {
32
+ (arr[i], arr[j]) = (arr[j], arr[i]);
33
+ (addrs[i], addrs[j]) = (addrs[j], addrs[i]);
34
+ } else {
35
+ ++i;
36
+ }
37
+ }
38
+
39
+ if (j > left) quickSortDescending(arr, addrs, left, j - 1); // j > left, so j > 0
40
+ quickSortDescending(arr, addrs, j + 1, right);
41
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /// @dev The approximate number of blocks per year that is assumed by the interest rate model
5
+ uint256 constant BLOCKS_PER_YEAR = 10_512_000;
6
+
7
+ /// @dev Base unit for computations, usually used in scaling (multiplications, divisions)
8
+ uint256 constant EXP_SCALE = 1e18;
9
+
10
+ /// @dev A unit (literal one) in EXP_SCALE, usually used in additions/subtractions
11
+ uint256 constant MANTISSA_ONE = EXP_SCALE;
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ /// @notice Thrown if the supplied address is a zero address where it is not allowed
5
+ error ZeroAddressNotAllowed();
6
+
7
+ /// @notice Thrown if the supplied value is 0 where it is not allowed
8
+ error ZeroValueNotAllowed();
9
+
10
+ /// @notice Checks if the provided address is nonzero, reverts otherwise
11
+ /// @param address_ Address to check
12
+ /// @custom:error ZeroAddressNotAllowed is thrown if the provided address is a zero address
13
+ function ensureNonzeroAddress(address address_) pure {
14
+ if (address_ == address(0)) {
15
+ revert ZeroAddressNotAllowed();
16
+ }
17
+ }
18
+
19
+ /// @notice Checks if the provided value is nonzero, reverts otherwise
20
+ /// @param value_ Value to check
21
+ /// @custom:error ZeroValueNotAllowed is thrown if the provided value is 0
22
+ function ensureNonzeroValue(uint256 value_) pure {
23
+ if (value_ == 0) {
24
+ revert ZeroValueNotAllowed();
25
+ }
26
+ }