@etherisc/gif-next 0.0.2-e79d227-681 → 0.0.2-e7a5428-226

Sign up to get free protection for your applications and to get access to all the features.
Files changed (504) hide show
  1. package/README.md +57 -1
  2. package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.dbg.json +4 -0
  3. package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.json +1075 -0
  4. package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.dbg.json +4 -0
  5. package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.json +790 -0
  6. package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.dbg.json +4 -0
  7. package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.json +843 -0
  8. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
  9. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +640 -269
  10. package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.dbg.json +4 -0
  11. package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.json +1289 -0
  12. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
  13. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.json +202 -5
  14. package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
  15. package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +409 -33
  16. package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
  17. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
  18. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.json +525 -213
  19. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
  20. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.json +179 -19
  21. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
  22. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.json +246 -16
  23. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
  24. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +420 -27
  25. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
  26. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +105 -185
  27. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
  28. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +381 -46
  29. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  30. package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +58 -127
  31. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  32. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +533 -218
  33. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  34. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +150 -82
  35. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  36. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +37 -106
  37. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  38. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +379 -79
  39. package/artifacts/contracts/examples/fire/DamageLevel.sol/DamageLevelLib.dbg.json +1 -1
  40. package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.dbg.json +1 -1
  41. package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.json +183 -128
  42. package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.dbg.json +1 -1
  43. package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.json +355 -52
  44. package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.dbg.json +1 -1
  45. package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.json +324 -250
  46. package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.dbg.json +1 -1
  47. package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.json +380 -45
  48. package/artifacts/contracts/examples/fire/FireUSD.sol/FireUSD.dbg.json +1 -1
  49. package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.dbg.json +1 -1
  50. package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.json +191 -182
  51. package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.dbg.json +4 -0
  52. package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.json +805 -0
  53. package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.dbg.json +1 -1
  54. package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.json +94 -100
  55. package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.dbg.json +1 -1
  56. package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.json +196 -155
  57. package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.dbg.json +4 -0
  58. package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.json +805 -0
  59. package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.dbg.json +1 -1
  60. package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.json +600 -296
  61. package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.dbg.json +4 -0
  62. package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.json +805 -0
  63. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
  64. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +88 -45
  65. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  66. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +482 -50
  67. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +373 -13
  69. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  70. package/artifacts/contracts/instance/Instance.sol/Instance.json +493 -85
  71. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
  72. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +1017 -334
  73. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
  74. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +380 -52
  75. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  76. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +914 -554
  77. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +377 -80
  79. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  80. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +83 -57
  81. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  82. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +690 -566
  83. package/artifacts/contracts/instance/RiskSet.sol/RiskSet.dbg.json +1 -1
  84. package/artifacts/contracts/instance/RiskSet.sol/RiskSet.json +141 -85
  85. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
  86. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +8 -8
  87. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  88. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
  89. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
  90. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
  91. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.json +2 -2
  92. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
  93. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +16 -5
  94. package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.dbg.json +4 -0
  95. package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.json +168 -0
  96. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  97. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  98. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  99. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  100. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  101. package/artifacts/contracts/mock/Dip.sol/Dip.dbg.json +1 -1
  102. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
  103. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +77 -81
  104. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
  105. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +379 -47
  106. package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
  107. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
  108. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +41 -45
  109. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
  110. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.json +56 -3
  111. package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
  112. package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +61 -65
  113. package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
  114. package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +120 -68
  115. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
  116. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +99 -55
  117. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
  118. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +102 -114
  119. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
  120. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +355 -52
  121. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  122. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +304 -226
  123. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  124. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +120 -76
  125. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  126. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +200 -89
  127. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  128. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +59 -63
  129. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  130. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +333 -169
  131. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  132. package/artifacts/contracts/pool/Pool.sol/Pool.json +72 -76
  133. package/artifacts/contracts/pool/PoolLib.sol/PoolLib.dbg.json +4 -0
  134. package/artifacts/contracts/pool/PoolLib.sol/PoolLib.json +522 -0
  135. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  136. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +574 -360
  137. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  138. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +146 -74
  139. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  140. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +293 -63
  141. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  142. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +106 -46
  143. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
  144. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.json +193 -182
  145. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
  146. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +380 -45
  147. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  148. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +292 -195
  149. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  150. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +127 -99
  151. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  152. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.json +235 -4
  153. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  154. package/artifacts/contracts/product/IClaimService.sol/IClaimService.json +181 -19
  155. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  156. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.json +160 -68
  157. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  158. package/artifacts/contracts/product/IPricingService.sol/IPricingService.json +77 -3
  159. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  160. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.json +168 -157
  161. package/artifacts/contracts/product/IRiskService.sol/IRiskService.dbg.json +1 -1
  162. package/artifacts/contracts/product/IRiskService.sol/IRiskService.json +258 -22
  163. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  164. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +278 -187
  165. package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.dbg.json +4 -0
  166. package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.json +783 -0
  167. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  168. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +129 -85
  169. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  170. package/artifacts/contracts/product/PricingService.sol/PricingService.json +135 -126
  171. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  172. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +103 -75
  173. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  174. package/artifacts/contracts/product/Product.sol/Product.json +187 -176
  175. package/artifacts/contracts/product/RiskService.sol/RiskService.dbg.json +1 -1
  176. package/artifacts/contracts/product/RiskService.sol/RiskService.json +326 -91
  177. package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.dbg.json +1 -1
  178. package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.json +103 -47
  179. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  180. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  181. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  182. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +54 -19
  183. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  184. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +56 -3
  185. package/artifacts/contracts/registry/IRelease.sol/IRelease.dbg.json +4 -0
  186. package/artifacts/contracts/{authorization/AccessAdmin.sol/IAccessManagedChecker.json → registry/IRelease.sol/IRelease.json} +6 -6
  187. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  188. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  189. package/artifacts/contracts/registry/Registry.sol/Registry.json +92 -57
  190. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
  191. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +727 -479
  192. package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.dbg.json +4 -0
  193. package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.json +1061 -0
  194. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  195. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +75 -39
  196. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  197. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +79 -43
  198. package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.dbg.json +4 -0
  199. package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.json +2152 -0
  200. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
  201. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.json +2 -2
  202. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
  203. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +386 -64
  204. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
  205. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +437 -26
  206. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  207. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +120 -60
  208. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  209. package/artifacts/contracts/shared/Component.sol/Component.json +60 -50
  210. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  211. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +247 -531
  212. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  213. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +111 -95
  214. package/artifacts/contracts/shared/ContractLib.sol/ContractLib.dbg.json +1 -1
  215. package/artifacts/contracts/shared/ContractLib.sol/ContractLib.json +178 -34
  216. package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.dbg.json +1 -1
  217. package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.dbg.json +1 -1
  218. package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.dbg.json +4 -0
  219. package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.json +40 -0
  220. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  221. package/artifacts/contracts/shared/IComponent.sol/IComponent.json +41 -31
  222. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
  223. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +155 -382
  224. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
  225. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.json +41 -45
  226. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  227. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.json +6 -6
  228. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  229. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  230. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +19 -0
  231. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  232. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  233. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +139 -1
  234. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  235. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  236. package/artifacts/contracts/shared/IService.sol/IService.json +56 -3
  237. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +1 -1
  238. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.json +2 -2
  239. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
  240. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.json +60 -64
  241. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  242. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.json +6 -6
  243. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  244. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
  245. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.json +2 -2
  246. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  247. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +21 -2
  248. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  249. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  250. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  251. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +137 -62
  252. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  253. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  254. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  255. package/artifacts/contracts/shared/Service.sol/Service.json +51 -11
  256. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  257. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +63 -162
  258. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.dbg.json +1 -1
  259. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.json +118 -29
  260. package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.dbg.json +1 -1
  261. package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.json +32 -32
  262. package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
  263. package/artifacts/contracts/staking/IStaking.sol/IStaking.json +1026 -101
  264. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  265. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.json +214 -110
  266. package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
  267. package/artifacts/contracts/staking/Staking.sol/Staking.json +1218 -214
  268. package/artifacts/contracts/staking/StakingLib.sol/StakingLib.dbg.json +4 -0
  269. package/artifacts/contracts/staking/StakingLib.sol/StakingLib.json +470 -0
  270. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
  271. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.json +2 -2
  272. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
  273. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +139 -61
  274. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
  275. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +174 -217
  276. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  277. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +253 -174
  278. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
  279. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +87 -55
  280. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
  281. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +957 -603
  282. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
  283. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +101 -51
  284. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  285. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  286. package/artifacts/contracts/type/Amount.sol/AmountLib.json +11 -11
  287. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  288. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.json +45 -19
  289. package/artifacts/contracts/type/ChainId.sol/ChainIdLib.dbg.json +4 -0
  290. package/artifacts/contracts/type/ChainId.sol/ChainIdLib.json +193 -0
  291. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  292. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.json +2 -2
  293. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  294. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.json +2 -2
  295. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  296. package/artifacts/contracts/type/Fee.sol/FeeLib.json +94 -38
  297. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  298. package/artifacts/contracts/type/Key32.sol/Key32Lib.json +2 -2
  299. package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.dbg.json +1 -1
  300. package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.json +2 -2
  301. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  302. package/artifacts/contracts/type/NftId.sol/NftIdLib.json +2 -2
  303. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  304. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.json +2 -2
  305. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  306. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.json +33 -31
  307. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  308. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.json +2 -2
  309. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  310. package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
  311. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
  312. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.json +2 -2
  313. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  314. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.json +30 -6
  315. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  316. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.json +42 -157
  317. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  318. package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +45 -2
  319. package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
  320. package/artifacts/contracts/type/Selector.sol/SelectorLib.json +21 -2
  321. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
  322. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.json +2 -2
  323. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  324. package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
  325. package/artifacts/contracts/type/String.sol/StrLib.json +50 -2
  326. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  327. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +3 -3
  328. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  329. package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +61 -37
  330. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  331. package/artifacts/contracts/type/Version.sol/VersionLib.json +2 -21
  332. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  333. package/artifacts/contracts/type/Version.sol/VersionPartLib.json +101 -2
  334. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
  335. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.json +10 -0
  336. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  337. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +65 -27
  338. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  339. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +15 -2
  340. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
  341. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.json +10 -0
  342. package/contracts/accounting/AccountingService.sol +274 -0
  343. package/contracts/accounting/AccountingServiceManager.sol +38 -0
  344. package/contracts/accounting/IAccountingService.sol +47 -0
  345. package/contracts/authorization/AccessAdmin.sol +422 -258
  346. package/contracts/authorization/AccessAdminLib.sol +396 -0
  347. package/contracts/authorization/AccessManagerCloneable.sol +146 -4
  348. package/contracts/authorization/Authorization.sol +142 -262
  349. package/contracts/authorization/IAccess.sol +25 -7
  350. package/contracts/authorization/IAccessAdmin.sol +87 -80
  351. package/contracts/authorization/IAuthorization.sol +9 -43
  352. package/contracts/authorization/IServiceAuthorization.sol +55 -17
  353. package/contracts/authorization/ServiceAuthorization.sol +248 -34
  354. package/contracts/distribution/BasicDistribution.sol +16 -14
  355. package/contracts/distribution/BasicDistributionAuthorization.sol +29 -9
  356. package/contracts/distribution/Distribution.sol +38 -75
  357. package/contracts/distribution/DistributionService.sol +181 -87
  358. package/contracts/distribution/DistributionServiceManager.sol +1 -1
  359. package/contracts/distribution/IDistributionComponent.sol +3 -10
  360. package/contracts/distribution/IDistributionService.sol +34 -19
  361. package/contracts/examples/fire/FirePool.sol +6 -6
  362. package/contracts/examples/fire/FirePoolAuthorization.sol +2 -1
  363. package/contracts/examples/fire/FireProduct.sol +15 -13
  364. package/contracts/examples/fire/FireProductAuthorization.sol +2 -1
  365. package/contracts/examples/unpermissioned/SimpleDistribution.sol +34 -11
  366. package/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol +28 -0
  367. package/contracts/examples/unpermissioned/SimpleOracle.sol +4 -8
  368. package/contracts/examples/unpermissioned/SimplePool.sol +7 -13
  369. package/contracts/examples/unpermissioned/SimplePoolAuthorization.sol +28 -0
  370. package/contracts/examples/unpermissioned/SimpleProduct.sol +119 -27
  371. package/contracts/examples/unpermissioned/SimpleProductAuthorization.sol +28 -0
  372. package/contracts/instance/BundleSet.sol +4 -4
  373. package/contracts/instance/IInstance.sol +92 -19
  374. package/contracts/instance/IInstanceService.sol +52 -9
  375. package/contracts/instance/Instance.sol +163 -57
  376. package/contracts/instance/InstanceAdmin.sol +271 -166
  377. package/contracts/instance/InstanceAuthorizationV3.sol +89 -40
  378. package/contracts/instance/InstanceReader.sol +422 -369
  379. package/contracts/instance/InstanceService.sol +252 -176
  380. package/contracts/instance/InstanceServiceManager.sol +1 -1
  381. package/contracts/instance/InstanceStore.sol +13 -2
  382. package/contracts/instance/RiskSet.sol +21 -14
  383. package/contracts/instance/base/BalanceStore.sol +4 -6
  384. package/contracts/instance/base/ObjectCounter.sol +1 -2
  385. package/contracts/instance/base/ObjectLifecycle.sol +6 -8
  386. package/contracts/instance/base/ObjectSet.sol +7 -8
  387. package/contracts/instance/base/ObjectSetHelperLib.sol +30 -0
  388. package/contracts/instance/module/IBundle.sol +6 -5
  389. package/contracts/instance/module/IComponents.sol +19 -7
  390. package/contracts/instance/module/IDistribution.sol +21 -8
  391. package/contracts/instance/module/IPolicy.sol +28 -8
  392. package/contracts/instance/module/IRisk.sol +4 -0
  393. package/contracts/oracle/BasicOracle.sol +2 -4
  394. package/contracts/oracle/BasicOracleAuthorization.sol +15 -8
  395. package/contracts/oracle/IOracle.sol +9 -4
  396. package/contracts/oracle/Oracle.sol +3 -5
  397. package/contracts/oracle/OracleService.sol +24 -23
  398. package/contracts/oracle/OracleServiceManager.sol +1 -1
  399. package/contracts/pool/BasicPool.sol +3 -16
  400. package/contracts/pool/BasicPoolAuthorization.sol +29 -16
  401. package/contracts/pool/BundleService.sol +67 -104
  402. package/contracts/pool/BundleServiceManager.sol +1 -1
  403. package/contracts/pool/IBundleService.sol +27 -33
  404. package/contracts/pool/IPoolService.sol +57 -40
  405. package/contracts/pool/Pool.sol +13 -25
  406. package/contracts/pool/PoolLib.sol +341 -0
  407. package/contracts/pool/PoolService.sol +203 -201
  408. package/contracts/pool/PoolServiceManager.sol +1 -1
  409. package/contracts/product/ApplicationService.sol +86 -18
  410. package/contracts/product/ApplicationServiceManager.sol +1 -1
  411. package/contracts/product/BasicProduct.sol +3 -3
  412. package/contracts/product/BasicProductAuthorization.sol +32 -11
  413. package/contracts/product/ClaimService.sol +187 -171
  414. package/contracts/product/ClaimServiceManager.sol +1 -1
  415. package/contracts/product/IApplicationService.sol +24 -2
  416. package/contracts/product/IClaimService.sol +18 -5
  417. package/contracts/product/IPolicyService.sol +20 -8
  418. package/contracts/product/IPricingService.sol +1 -0
  419. package/contracts/product/IProductComponent.sol +4 -1
  420. package/contracts/product/IRiskService.sol +25 -10
  421. package/contracts/product/PolicyService.sol +110 -198
  422. package/contracts/product/PolicyServiceLib.sol +139 -0
  423. package/contracts/product/PolicyServiceManager.sol +1 -1
  424. package/contracts/product/PricingService.sol +52 -46
  425. package/contracts/product/PricingServiceManager.sol +3 -3
  426. package/contracts/product/Product.sol +93 -27
  427. package/contracts/product/RiskService.sol +119 -36
  428. package/contracts/product/RiskServiceManager.sol +1 -1
  429. package/contracts/registry/ChainNft.sol +4 -2
  430. package/contracts/registry/IRegistry.sol +23 -24
  431. package/contracts/registry/IRelease.sol +29 -0
  432. package/contracts/registry/Registry.sol +22 -11
  433. package/contracts/registry/RegistryAdmin.sol +100 -363
  434. package/contracts/registry/RegistryAuthorization.sol +309 -0
  435. package/contracts/registry/RegistryService.sol +4 -4
  436. package/contracts/registry/RegistryServiceManager.sol +1 -1
  437. package/contracts/registry/ReleaseAdmin.sol +195 -0
  438. package/contracts/registry/ReleaseLifecycle.sol +2 -0
  439. package/contracts/registry/ReleaseRegistry.sol +157 -117
  440. package/contracts/registry/ServiceAuthorizationV3.sol +194 -27
  441. package/contracts/registry/TokenRegistry.sol +61 -59
  442. package/contracts/shared/Component.sol +34 -37
  443. package/contracts/shared/ComponentService.sol +314 -433
  444. package/contracts/shared/ComponentServiceManager.sol +1 -1
  445. package/contracts/shared/ContractLib.sol +164 -76
  446. package/contracts/shared/IComponent.sol +1 -10
  447. package/contracts/shared/IComponentService.sol +22 -41
  448. package/contracts/shared/IInstanceLinkedComponent.sol +0 -11
  449. package/contracts/shared/IKeyValueStore.sol +1 -1
  450. package/contracts/shared/INftOwnable.sol +2 -0
  451. package/contracts/shared/IRegisterable.sol +15 -5
  452. package/contracts/shared/IService.sol +3 -5
  453. package/contracts/shared/InitializableERC165.sol +9 -1
  454. package/contracts/shared/InstanceLinkedComponent.sol +7 -18
  455. package/contracts/shared/KeyValueStore.sol +3 -3
  456. package/contracts/shared/NftOwnable.sol +8 -6
  457. package/contracts/shared/PolicyHolder.sol +4 -3
  458. package/contracts/shared/Registerable.sol +42 -19
  459. package/contracts/shared/RegistryLinked.sol +1 -1
  460. package/contracts/shared/Service.sol +13 -30
  461. package/contracts/shared/TokenHandler.sol +45 -92
  462. package/contracts/staking/IStaking.sol +155 -64
  463. package/contracts/staking/IStakingService.sol +45 -75
  464. package/contracts/staking/Staking.sol +444 -203
  465. package/contracts/staking/{StakeManagerLib.sol → StakingLib.sol} +55 -84
  466. package/contracts/staking/StakingManager.sol +1 -2
  467. package/contracts/staking/StakingReader.sol +41 -80
  468. package/contracts/staking/StakingService.sol +62 -181
  469. package/contracts/staking/StakingServiceManager.sol +6 -4
  470. package/contracts/staking/StakingStore.sol +697 -329
  471. package/contracts/staking/TargetManagerLib.sol +1 -1
  472. package/contracts/type/Amount.sol +4 -0
  473. package/contracts/type/Blocknumber.sol +15 -15
  474. package/contracts/type/ChainId.sol +101 -0
  475. package/contracts/type/Fee.sol +8 -8
  476. package/contracts/type/NftId.sol +3 -3
  477. package/contracts/type/ObjectType.sol +67 -38
  478. package/contracts/type/RiskId.sol +9 -3
  479. package/contracts/type/RoleId.sol +63 -45
  480. package/contracts/type/Seconds.sol +14 -0
  481. package/contracts/type/Selector.sol +5 -0
  482. package/contracts/type/String.sol +12 -0
  483. package/contracts/type/Timestamp.sol +4 -7
  484. package/contracts/type/UFixed.sol +35 -127
  485. package/contracts/type/Version.sol +54 -5
  486. package/contracts/upgradeability/IVersionable.sol +3 -0
  487. package/contracts/upgradeability/ProxyManager.sol +26 -12
  488. package/contracts/upgradeability/UpgradableProxyWithAdmin.sol +12 -2
  489. package/contracts/upgradeability/Versionable.sol +6 -3
  490. package/package.json +2 -2
  491. package/artifacts/contracts/authorization/AccessAdmin.sol/IAccessManagedChecker.dbg.json +0 -4
  492. package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.dbg.json +0 -4
  493. package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.json +0 -1196
  494. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +0 -4
  495. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +0 -129
  496. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +0 -4
  497. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.json +0 -474
  498. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +0 -4
  499. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +0 -440
  500. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +0 -4
  501. package/artifacts/contracts/type/UFixed.sol/MathLib.json +0 -16
  502. package/contracts/authorization/ReleaseAccessManager.sol +0 -38
  503. package/contracts/instance/module/IAccess.sol +0 -46
  504. package/contracts/shared/ComponentVerifyingService.sol +0 -128
@@ -4,29 +4,31 @@ pragma solidity ^0.8.20;
4
4
  import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
5
 
6
6
  import {IRegistry} from "../registry/IRegistry.sol";
7
- import {IRegistryService} from "../registry/IRegistryService.sol";
7
+ import {IRelease} from "../registry/IRelease.sol";
8
8
  import {IStaking} from "./IStaking.sol";
9
+ import {IStakingService} from "./IStakingService.sol";
9
10
  import {IVersionable} from "../upgradeability/IVersionable.sol";
10
11
 
11
12
  import {Amount, AmountLib} from "../type/Amount.sol";
13
+ import {Blocknumber} from "../type/Blocknumber.sol";
14
+ import {ChainId, ChainIdLib} from "../type/ChainId.sol";
12
15
  import {Component} from "../shared/Component.sol";
13
16
  import {IComponent} from "../shared/IComponent.sol";
14
- import {IComponentService} from "../shared/IComponentService.sol";
15
17
  import {NftId} from "../type/NftId.sol";
16
- import {ObjectType, COMPONENT, STAKING} from "../type/ObjectType.sol";
17
- import {Seconds} from "../type/Seconds.sol";
18
- import {StakeManagerLib} from "./StakeManagerLib.sol";
18
+ import {ObjectType, PROTOCOL, STAKE, STAKING, TARGET} from "../type/ObjectType.sol";
19
+ import {Seconds, SecondsLib} from "../type/Seconds.sol";
20
+ import {Registerable} from "../shared/Registerable.sol";
21
+ import {StakingLib} from "./StakingLib.sol";
19
22
  import {StakingReader} from "./StakingReader.sol";
20
23
  import {StakingStore} from "./StakingStore.sol";
21
- import {TargetManagerLib} from "./TargetManagerLib.sol";
22
- import {Timestamp} from "../type/Timestamp.sol";
23
24
  import {TokenHandler} from "../shared/TokenHandler.sol";
24
25
  import {TokenHandlerDeployerLib} from "../shared/TokenHandlerDeployerLib.sol";
25
26
  import {TokenRegistry} from "../registry/TokenRegistry.sol";
26
27
  import {UFixed} from "../type/UFixed.sol";
27
- import {Version, VersionLib} from "../type/Version.sol";
28
+ import {Version, VersionLib, VersionPart, VersionPartLib} from "../type/Version.sol";
28
29
  import {Versionable} from "../upgradeability/Versionable.sol";
29
30
 
31
+
30
32
  contract Staking is
31
33
  Component,
32
34
  Versionable,
@@ -38,108 +40,277 @@ contract Staking is
38
40
  bytes32 public constant STAKING_LOCATION_V1 = 0xafe8d4462b2ed26a47154f4b8f6d1497d2f772496965791d25bd456e342b7f00;
39
41
 
40
42
  struct StakingStorage {
41
- IRegistryService _registryService;
42
43
  TokenRegistry _tokenRegistry;
43
44
  TokenHandler _tokenHandler;
45
+ IStakingService _stakingService;
44
46
  StakingStore _store;
45
47
  StakingReader _reader;
46
48
  NftId _protocolNftId;
47
49
  }
48
50
 
49
51
 
50
- modifier onlyStake(NftId stakeNftId) {
51
- if (!_getStakingStorage()._store.exists(stakeNftId)) {
52
- revert ErrorStakingNotStake(stakeNftId);
53
- }
52
+ modifier onlyStakeOwner(NftId stakeNftId) {
53
+ _checkTypeAndOwner(stakeNftId, STAKE(), true);
54
54
  _;
55
55
  }
56
56
 
57
57
 
58
58
  modifier onlyTarget(NftId targetNftId) {
59
- if (!_getStakingStorage()._store.getTargetNftIdSet().exists(targetNftId)) {
60
- revert ErrorStakingNotTarget(targetNftId);
61
- }
59
+ _checkTypeAndOwner(targetNftId, TARGET(), false);
62
60
  _;
63
61
  }
64
62
 
63
+ //--- contract intitialization -------------------------------------------
64
+
65
65
  function initializeTokenHandler()
66
66
  external
67
+ virtual
67
68
  {
68
69
  if (msg.sender != address(getRegistry())) {
69
70
  revert ErrorStakingNotRegistry(msg.sender);
70
71
  }
71
72
 
72
73
  StakingStorage storage $ = _getStakingStorage();
74
+ address dipToken = _getStakingStorage()._tokenRegistry.getDipTokenAddress();
73
75
  $._tokenHandler = TokenHandlerDeployerLib.deployTokenHandler(
74
76
  address(getRegistry()),
75
77
  address(this),
76
- address(getToken()),
78
+ dipToken,
77
79
  getRegistry().getAuthority());
78
80
  }
79
81
 
80
- // set/update staking reader
82
+ //--- staking owner functions -------------------------------------------//
83
+
84
+
85
+ /// @inheritdoc IStaking
86
+ function setProtocolLockingPeriod(Seconds newLockingPeriod)
87
+ external
88
+ virtual
89
+ restricted()
90
+ onlyOwner()
91
+ {
92
+ StakingStorage storage $ = _getStakingStorage();
93
+ (
94
+ Seconds oldLockingPeriod,
95
+ Blocknumber lastUpdatedIn
96
+ ) = $._store.setLockingPeriod($._protocolNftId, newLockingPeriod);
97
+
98
+ emit LogStakingProtocolLockingPeriodSet($._protocolNftId, newLockingPeriod, oldLockingPeriod, lastUpdatedIn);
99
+ }
100
+
101
+
102
+ /// @inheritdoc IStaking
103
+ function setProtocolRewardRate(UFixed newRewardRate)
104
+ external
105
+ virtual
106
+ restricted()
107
+ onlyOwner()
108
+ {
109
+ StakingStorage storage $ = _getStakingStorage();
110
+ (
111
+ UFixed oldRewardRate,
112
+ Blocknumber lastUpdatedIn
113
+ ) = $._store.setRewardRate($._protocolNftId, newRewardRate);
114
+
115
+ emit LogStakingProtocolRewardRateSet($._protocolNftId, newRewardRate, oldRewardRate, lastUpdatedIn);
116
+ }
117
+
118
+
119
+ /// @inheritdoc IStaking
120
+ function setStakingRate(
121
+ ChainId chainId,
122
+ address token,
123
+ UFixed stakingRate
124
+ )
125
+ external
126
+ virtual
127
+ restricted()
128
+ onlyOwner()
129
+ {
130
+ (
131
+ UFixed oldStakingRate,
132
+ Blocknumber lastUpdateIn
133
+ ) = _getStakingStorage()._store.setStakingRate(chainId, token, stakingRate);
134
+
135
+ emit LogStakingStakingRateSet(chainId, token, stakingRate, oldStakingRate, lastUpdateIn);
136
+ }
137
+
138
+
139
+ /// @inheritdoc IStaking
140
+ function setStakingService(VersionPart release)
141
+ external
142
+ virtual
143
+ restricted()
144
+ onlyOwner()
145
+ {
146
+ // effects
147
+ StakingStorage storage $ = _getStakingStorage();
148
+ address oldStakingService = address($._stakingService);
149
+ $._stakingService = StakingLib.checkAndGetStakingService(getRegistry(), release);
150
+
151
+ emit LogStakingStakingServiceSet(address($._stakingService), release, oldStakingService);
152
+ }
153
+
154
+
155
+ /// @inheritdoc IStaking
81
156
  function setStakingReader(StakingReader stakingReader)
82
157
  external
83
158
  virtual
159
+ restricted()
84
160
  onlyOwner()
85
161
  {
86
162
  if(stakingReader.getStaking() != IStaking(this)) {
87
163
  revert ErrorStakingStakingReaderStakingMismatch(address(stakingReader.getStaking()));
88
164
  }
89
165
 
166
+ address oldReader = address(_getStakingStorage()._reader);
90
167
  _getStakingStorage()._reader = stakingReader;
168
+
169
+ emit LogStakingStakingReaderSet(address(stakingReader), oldReader);
91
170
  }
92
171
 
93
172
 
94
- // rate management
95
- function setStakingRate(uint256 chainId, address token, UFixed stakingRate)
173
+ /// @inheritdoc IStaking
174
+ function addToken(
175
+ ChainId chainId,
176
+ address token
177
+ )
96
178
  external
97
179
  virtual
180
+ restricted()
181
+ onlyOwner()
182
+ {
183
+ _addToken(
184
+ _getStakingStorage(), chainId, token);
185
+ }
186
+
187
+
188
+ /// @inheritdoc IStaking
189
+ function approveTokenHandler(IERC20Metadata token, Amount amount)
190
+ public
191
+ virtual
192
+ restricted()
98
193
  onlyOwner()
99
194
  {
100
195
  StakingStorage storage $ = _getStakingStorage();
101
-
102
- if (!$._tokenRegistry.isRegistered(chainId, token)) {
103
- revert ErrorStakingTokenNotRegistered(chainId, token);
196
+ Amount oldAllowanceAmount = AmountLib.toAmount(
197
+ token.allowance(
198
+ address(this),
199
+ address($._tokenHandler)));
200
+
201
+ // staking token handler approval via its own implementation in staking service
202
+ $._stakingService.approveTokenHandler(
203
+ token,
204
+ amount);
205
+
206
+ emit LogStakingTokenHandlerApproved(address(token), amount, oldAllowanceAmount);
207
+ }
208
+
209
+ //--- target management -------------------------------------------------//
210
+
211
+
212
+ /// @inheritdoc IStaking
213
+ function refillRewardReserves(NftId targetNftId, Amount dipAmount)
214
+ external
215
+ virtual
216
+ restricted()
217
+ onlyTarget(targetNftId)
218
+ returns (Amount newBalance)
219
+ {
220
+ address transferFrom = msg.sender;
221
+ _refillRewardReserves(targetNftId, dipAmount, transferFrom);
222
+ }
223
+
224
+
225
+ /// @inheritdoc IStaking
226
+ function withdrawRewardReserves(NftId targetNftId, Amount dipAmount)
227
+ external
228
+ virtual
229
+ restricted()
230
+ onlyTarget(targetNftId)
231
+ returns (Amount newBalance)
232
+ {
233
+ address transferTo;
234
+
235
+ // case 1: protocol target: staking owner is recipient
236
+ if (targetNftId == getRegistry().getProtocolNftId()) {
237
+ // verify that the caller is the staking owner
238
+ transferTo = getOwner();
239
+ if (msg.sender != transferTo) {
240
+ revert ErrorStakingNotStakingOwner();
241
+ }
242
+
243
+ // case 2: same chain target: target owner is recipient
244
+ } else if (ChainIdLib.isCurrentChain(targetNftId)) {
245
+ // verify that the caller is the target owner
246
+ transferTo = getRegistry().ownerOf(targetNftId);
247
+ if (msg.sender != transferTo) {
248
+ revert ErrorStakingNotNftOwner(targetNftId);
249
+ }
250
+
251
+ // case 3: cross-chain target: TODO decide how to handle and implement
252
+ } else {
253
+ revert("Cross-chain target not supported");
104
254
  }
105
255
 
106
- UFixed oldStakingRate = $._store.getStakingRate(chainId, token);
107
- $._store.setStakingRate(chainId, token, stakingRate);
256
+ newBalance = _withdrawRewardReserves(targetNftId, dipAmount, transferTo);
257
+ }
258
+
108
259
 
109
- emit LogStakingStakingRateSet(chainId, token, oldStakingRate, stakingRate);
260
+ /// @inheritdoc IStaking
261
+ function refillRewardReservesByService(NftId targetNftId, Amount dipAmount, address transferFrom)
262
+ external
263
+ virtual
264
+ restricted()
265
+ onlyTarget(targetNftId)
266
+ returns (Amount newBalance)
267
+ {
268
+ _refillRewardReserves(targetNftId, dipAmount, transferFrom);
269
+ }
270
+
271
+
272
+ /// @inheritdoc IStaking
273
+ function withdrawRewardReservesByService(NftId targetNftId, Amount dipAmount, address transferTo)
274
+ external
275
+ virtual
276
+ restricted()
277
+ onlyTarget(targetNftId)
278
+ returns (Amount newBalance)
279
+ {
280
+ // check that service does not withdraw from protocol target
281
+ if (targetNftId == getRegistry().getProtocolNftId()) {
282
+ revert ErrorStakingTargetTypeNotSupported(targetNftId, PROTOCOL());
283
+ }
284
+
285
+ // default: on-chain target owner is recipient
286
+ address targetOwner = getRegistry().ownerOf(targetNftId);
287
+ return _withdrawRewardReserves(targetNftId, dipAmount, targetOwner);
110
288
  }
111
289
 
112
- // target management
113
290
 
291
+ /// @inheritdoc IStaking
114
292
  function registerTarget(
115
293
  NftId targetNftId,
116
294
  ObjectType expectedObjectType,
117
- uint256 chainId,
118
295
  Seconds initialLockingPeriod,
119
296
  UFixed initialRewardRate
120
297
  )
121
298
  external
122
299
  virtual
123
- restricted()
300
+ restricted() // staking service
124
301
  {
125
- TargetManagerLib.checkTargetParameters(
126
- getRegistry(),
127
- _getStakingStorage()._reader,
128
- targetNftId,
129
- expectedObjectType,
130
- initialLockingPeriod,
131
- initialRewardRate);
132
-
302
+ // checks done by staking store
133
303
  _getStakingStorage()._store.createTarget(
134
304
  targetNftId,
135
- TargetInfo({
136
- objectType: expectedObjectType,
137
- chainId: chainId,
138
- lockingPeriod: initialLockingPeriod,
139
- rewardRate: initialRewardRate}));
305
+ expectedObjectType,
306
+ initialLockingPeriod,
307
+ initialRewardRate);
308
+
309
+ emit LogStakingTargetCreated(targetNftId, expectedObjectType, initialLockingPeriod, initialRewardRate, AmountLib.max());
140
310
  }
141
311
 
142
312
 
313
+ /// @inheritdoc IStaking
143
314
  function setLockingPeriod(
144
315
  NftId targetNftId,
145
316
  Seconds lockingPeriod
@@ -149,66 +320,56 @@ contract Staking is
149
320
  restricted()
150
321
  onlyTarget(targetNftId)
151
322
  {
152
- (
153
- Seconds oldLockingPeriod,
154
- TargetInfo memory targetInfo
155
- ) = TargetManagerLib.updateLockingPeriod(
156
- this,
157
- targetNftId,
158
- lockingPeriod);
159
-
160
- _getStakingStorage()._store.updateTarget(targetNftId, targetInfo);
323
+ (Seconds oldLockingPeriod, ) = _getStakingStorage()._store.setLockingPeriod(targetNftId, lockingPeriod);
161
324
 
162
- emit LogStakingLockingPeriodSet(targetNftId, oldLockingPeriod, lockingPeriod);
325
+ emit LogStakingTargetLockingPeriodSet(targetNftId, lockingPeriod, oldLockingPeriod);
163
326
  }
164
327
 
165
- // TODO add function to set protocol reward rate: onlyOwner
166
- // get protocol nft id (from where)
167
328
 
329
+ /// @inheritdoc IStaking
168
330
  function setRewardRate(NftId targetNftId, UFixed rewardRate)
169
331
  external
170
332
  virtual
171
333
  restricted()
172
334
  onlyTarget(targetNftId)
173
335
  {
174
- (
175
- UFixed oldRewardRate,
176
- TargetInfo memory targetInfo
177
- ) = TargetManagerLib.updateRewardRate(
178
- this,
179
- targetNftId,
180
- rewardRate);
181
-
182
- _getStakingStorage()._store.updateTarget(targetNftId, targetInfo);
336
+ (UFixed oldRewardRate,) = _getStakingStorage()._store.setRewardRate(targetNftId, rewardRate);
183
337
 
184
- emit LogStakingRewardRateSet(targetNftId, oldRewardRate, rewardRate);
338
+ emit LogStakingTargetRewardRateSet(targetNftId, rewardRate, oldRewardRate);
185
339
  }
186
340
 
187
341
 
188
- function refillRewardReserves(NftId targetNftId, Amount dipAmount)
342
+ /// @inheritdoc IStaking
343
+ function setMaxStakedAmount(NftId targetNftId, Amount maxStakedAmount)
189
344
  external
190
345
  virtual
191
346
  restricted()
192
- returns (Amount newBalance)
347
+ onlyTarget(targetNftId)
193
348
  {
194
- // update book keeping of reward reserves
195
- StakingStorage storage $ = _getStakingStorage();
196
- newBalance = $._store.increaseReserves(targetNftId, dipAmount);
349
+ _getStakingStorage()._store.setMaxStakedAmount(targetNftId, maxStakedAmount);
350
+
351
+ emit LogStakingTargetMaxStakedAmountSet(targetNftId, maxStakedAmount);
197
352
  }
198
353
 
199
354
 
200
- function withdrawRewardReserves(NftId targetNftId, Amount dipAmount)
355
+ /// @inheritdoc IStaking
356
+ function addTargetToken(NftId targetNftId, address token)
201
357
  external
202
358
  virtual
203
359
  restricted()
204
- returns (Amount newBalance)
360
+ onlyTarget(targetNftId)
205
361
  {
206
- // update book keeping of reward reserves
207
362
  StakingStorage storage $ = _getStakingStorage();
208
- newBalance = $._store.decreaseReserves(targetNftId, dipAmount);
363
+ ChainId chainId = ChainIdLib.fromNftId(targetNftId);
364
+ _addToken($, chainId, token);
365
+
366
+ $._store.addTargetToken(targetNftId, token);
367
+
368
+ emit LogStakingTargetTokenAdded(targetNftId, chainId, token);
209
369
  }
210
370
 
211
371
 
372
+ /// @inheritdoc IStaking
212
373
  function increaseTotalValueLocked(NftId targetNftId, address token, Amount amount)
213
374
  external
214
375
  virtual
@@ -216,12 +377,13 @@ contract Staking is
216
377
  returns (Amount newBalance)
217
378
  {
218
379
  StakingStorage storage $ = _getStakingStorage();
219
- uint chainId = $._reader.getTargetInfo(targetNftId).chainId;
220
- UFixed stakingRate = $._reader.getStakingRate(chainId, token);
221
- newBalance = $._store.increaseTotalValueLocked(targetNftId, stakingRate, token, amount);
380
+ newBalance = $._store.increaseTotalValueLocked(targetNftId, token, amount);
381
+
382
+ emit LogStakingTotalValueLockedIncreased(targetNftId, token, amount, newBalance);
222
383
  }
223
384
 
224
385
 
386
+ /// @inheritdoc IStaking
225
387
  function decreaseTotalValueLocked(NftId targetNftId, address token, Amount amount)
226
388
  external
227
389
  virtual
@@ -229,12 +391,14 @@ contract Staking is
229
391
  returns (Amount newBalance)
230
392
  {
231
393
  StakingStorage storage $ = _getStakingStorage();
232
- uint chainId = $._reader.getTargetInfo(targetNftId).chainId;
233
- UFixed stakingRate = $._reader.getStakingRate(chainId, token);
234
- newBalance = $._store.decreaseTotalValueLocked(targetNftId, stakingRate, token, amount);
394
+ newBalance = $._store.decreaseTotalValueLocked(targetNftId, token, amount);
395
+
396
+ emit LogStakingTotalValueLockedDecreased(targetNftId, token, amount, newBalance);
235
397
  }
236
398
 
237
399
 
400
+ // TODO add to interface and implement
401
+ /// inheritdoc IStaking
238
402
  function registerRemoteTarget(NftId targetNftId, TargetInfo memory targetInfo)
239
403
  external
240
404
  virtual
@@ -244,6 +408,8 @@ contract Staking is
244
408
 
245
409
  }
246
410
 
411
+ // TODO add to interface and implement
412
+ /// @inheritdoc IStaking
247
413
  function updateRemoteTvl(NftId targetNftId, address token, Amount amount)
248
414
  external
249
415
  virtual
@@ -255,55 +421,81 @@ contract Staking is
255
421
 
256
422
  //--- staking functions -------------------------------------------------//
257
423
 
424
+ /// @inheritdoc IStaking
258
425
  function createStake(
259
- NftId stakeNftId,
260
426
  NftId targetNftId,
261
- Amount stakeAmount
427
+ Amount stakeAmount,
428
+ address stakeOwner
262
429
  )
263
430
  external
264
431
  virtual
265
- restricted() // only staking service
432
+ restricted()
433
+ onlyTarget(targetNftId)
434
+ returns (NftId stakeNftId)
266
435
  {
436
+ // effects (includes further checks in service)
267
437
  StakingStorage storage $ = _getStakingStorage();
268
- Timestamp lockedUntil = StakeManagerLib.checkCreateParameters(
269
- $._reader,
270
- targetNftId,
271
- stakeAmount);
438
+ stakeNftId = $._stakingService.createStakeObject(targetNftId, stakeOwner);
439
+ $._store.createStake(stakeNftId, targetNftId, stakeOwner, stakeAmount);
272
440
 
273
- // create new stake
274
- $._store.create(
275
- stakeNftId,
276
- StakeInfo({
277
- lockedUntil: lockedUntil}));
278
-
279
- // update target stake balance
280
- $._store.increaseStake(
281
- stakeNftId,
282
- targetNftId,
283
- stakeAmount);
441
+ // interactions
442
+ if (stakeAmount.gtz()) {
443
+ $._stakingService.pullDipToken(stakeAmount, stakeOwner);
444
+ }
284
445
  }
285
446
 
286
447
 
448
+ /// @inheritdoc IStaking
287
449
  function stake(
288
450
  NftId stakeNftId,
289
451
  Amount stakeAmount
290
452
  )
291
453
  external
292
454
  virtual
293
- restricted() // only staking service
294
- onlyStake(stakeNftId)
295
- returns (Amount stakeBalance)
455
+ restricted()
456
+ onlyStakeOwner(stakeNftId)
457
+ returns (Amount newStakeBalance)
296
458
  {
297
459
  StakingStorage storage $ = _getStakingStorage();
298
- stakeBalance = StakeManagerLib.stake(
299
- getRegistry(),
300
- $._reader,
301
- $._store,
302
- stakeNftId,
460
+ $._store.stake(
461
+ stakeNftId,
462
+ true, // update rewards
463
+ true, // restake rewards
464
+ SecondsLib.max(), // max additional locking duration
303
465
  stakeAmount);
466
+
467
+ // collect staked DIP token via staking service
468
+ if (stakeAmount.gtz()) {
469
+ address stakeOwner = getRegistry().ownerOf(stakeNftId);
470
+ $._stakingService.pullDipToken(stakeAmount, stakeOwner);
471
+ }
304
472
  }
305
473
 
306
474
 
475
+ /// @inheritdoc IStaking
476
+ function unstake(NftId stakeNftId)
477
+ external
478
+ virtual
479
+ restricted()
480
+ onlyStakeOwner(stakeNftId)
481
+ returns (Amount unstakedAmount)
482
+ {
483
+ StakingStorage storage $ = _getStakingStorage();
484
+ unstakedAmount = $._store.unstake(
485
+ stakeNftId,
486
+ true, // update rewards
487
+ true, // restake rewards
488
+ AmountLib.max()); // unstake up to this amount
489
+
490
+ // transfer unstaked DIP token via staking service
491
+ if (unstakedAmount.gtz()) {
492
+ address stakeOwner = getRegistry().ownerOf(stakeNftId);
493
+ $._stakingService.pushDipToken(unstakedAmount, stakeOwner);
494
+ }
495
+ }
496
+
497
+
498
+ /// @inheritdoc IStaking
307
499
  function restake(
308
500
  NftId stakeNftId,
309
501
  NftId newTargetNftId
@@ -311,95 +503,79 @@ contract Staking is
311
503
  external
312
504
  virtual
313
505
  restricted() // only staking service
314
- onlyStake(stakeNftId)
315
- returns (NftId newStakeNftId)
506
+ onlyStakeOwner(stakeNftId)
507
+ onlyTarget(newTargetNftId)
508
+ returns (
509
+ NftId newStakeNftId,
510
+ Amount newStakedAmount
511
+ )
316
512
  {
317
- // TODO add check that allows additional staking amount
318
513
  StakingStorage storage $ = _getStakingStorage();
319
514
 
320
- // TODO implement
515
+ // step 1: unstake as much as possible
516
+ newStakedAmount = $._store.unstake(
517
+ stakeNftId,
518
+ true, // update rewards
519
+ true, // restake rewards
520
+ AmountLib.max()); // unstake up to this amount
521
+
522
+ // step 2: create new stake with full unstaked amount
523
+ address stakeOwner = getRegistry().ownerOf(stakeNftId);
524
+ newStakeNftId = $._stakingService.createStakeObject(newTargetNftId, stakeOwner);
525
+ $._store.createStake(newStakeNftId, newTargetNftId, stakeOwner, newStakedAmount);
526
+
527
+ // logging
528
+ emit LogStakingStakeRestaked(newStakeNftId, newTargetNftId, newStakedAmount, stakeOwner, stakeNftId);
321
529
  }
322
530
 
323
531
 
324
532
  function updateRewards(NftId stakeNftId)
325
533
  external
326
534
  virtual
327
- restricted() // only staking service
328
- onlyStake(stakeNftId)
535
+ restricted()
536
+ onlyStakeOwner(stakeNftId)
537
+ returns (Amount newRewardAmount)
329
538
  {
330
539
  StakingStorage storage $ = _getStakingStorage();
331
- _updateRewards($._reader, $._store, stakeNftId);
540
+ $._store.updateRewards(stakeNftId);
332
541
  }
333
542
 
334
543
 
335
544
  function claimRewards(NftId stakeNftId)
336
545
  external
337
546
  virtual
338
- restricted() // only staking service
339
- onlyStake(stakeNftId)
547
+ restricted()
548
+ onlyStakeOwner(stakeNftId)
340
549
  returns (
341
- Amount rewardsClaimedAmount
550
+ Amount claimedAmount
342
551
  )
343
552
  {
344
553
  StakingStorage storage $ = _getStakingStorage();
345
-
346
- // update rewards since last update
347
- NftId targetNftId = _updateRewards($._reader, $._store, stakeNftId);
348
-
349
- // unstake all available rewards
350
- rewardsClaimedAmount = $._store.claimUpTo(
351
- stakeNftId,
352
- targetNftId,
554
+ claimedAmount = $._store.claimRewards(
555
+ stakeNftId,
556
+ true,
353
557
  AmountLib.max());
354
558
 
355
- // update reward reserves
356
- $._store.decreaseReserves(targetNftId, rewardsClaimedAmount);
357
- }
358
-
359
-
360
- function unstake(NftId stakeNftId)
361
- external
362
- virtual
363
- restricted() // only staking service
364
- onlyStake(stakeNftId)
365
- returns (
366
- Amount unstakedAmount,
367
- Amount rewardsClaimedAmount
368
- )
369
- {
370
- StakingStorage storage $ = _getStakingStorage();
371
-
372
- StakeManagerLib.checkUnstakeParameters($._reader, stakeNftId);
373
-
374
- // update rewards since last update
375
- NftId targetNftId = _updateRewards($._reader, $._store, stakeNftId);
376
-
377
- // unstake all available dips
378
- (
379
- unstakedAmount,
380
- rewardsClaimedAmount
381
- ) = $._store.unstakeUpTo(
382
- stakeNftId,
383
- targetNftId,
384
- AmountLib.max(), // unstake all stakes
385
- AmountLib.max()); // claim all rewards
386
-
387
- // update reward reserves
388
- $._store.decreaseReserves(targetNftId, rewardsClaimedAmount);
559
+ // collect staked DIP token by staking service
560
+ if (claimedAmount.gtz()) {
561
+ // interactions
562
+ address stakeOwner = getRegistry().ownerOf(stakeNftId);
563
+ $._stakingService.pushDipToken(claimedAmount, stakeOwner);
564
+ }
389
565
  }
390
566
 
391
567
 
392
568
  //--- view functions ----------------------------------------------------//
393
569
 
394
- function getStakingReader() public view returns (StakingReader reader) {
570
+ function getStakingReader() public virtual view returns (StakingReader reader) {
395
571
  return _getStakingStorage()._reader;
396
572
  }
397
573
 
398
- function getStakingStore() external view returns (StakingStore stakingStore) {
574
+ function getStakingStore() external virtual view returns (StakingStore stakingStore) {
399
575
  return _getStakingStorage()._store;
400
576
  }
401
577
 
402
- function getTokenRegistryAddress() external view returns (address tokenRegistry) {
578
+ function getTokenRegistryAddress() external virtual view returns (address tokenRegistry) {
403
579
  return address(_getStakingStorage()._tokenRegistry);
404
580
  }
405
581
 
@@ -407,96 +583,161 @@ contract Staking is
407
583
  return _getStakingStorage()._tokenHandler;
408
584
  }
409
585
 
410
- // from Versionable
586
+ // from IRegisterable
587
+ function getRelease()
588
+ public
589
+ pure
590
+ virtual override (IRelease, Registerable)
591
+ returns(VersionPart)
592
+ {
593
+ return VersionPartLib.toVersionPart(3);
594
+ }
595
+
596
+ // from IVersionable
411
597
  function getVersion()
412
598
  public
413
599
  pure
414
- virtual override (IVersionable, Versionable)
600
+ virtual override (Component, IVersionable, Versionable)
415
601
  returns(Version)
416
602
  {
417
- return VersionLib.toVersion(GIF_RELEASE,0,0);
603
+ return VersionLib.toVersion(3,0,0);
418
604
  }
419
605
 
420
606
  //--- internal functions ------------------------------------------------//
421
607
 
422
- function _updateRewards(
423
- StakingReader reader,
424
- StakingStore store,
425
- NftId stakeNftId
426
- )
608
+
609
+ function _refillRewardReserves(NftId targetNftId, Amount dipAmount, address transferFrom)
427
610
  internal
428
611
  virtual
429
- returns (NftId targetNftId)
612
+ returns (Amount newBalance)
430
613
  {
431
- UFixed rewardRate;
614
+ // checks + effects
615
+ StakingStorage storage $ = _getStakingStorage();
616
+ newBalance = $._store.refillRewardReserves(targetNftId, dipAmount);
432
617
 
433
- (targetNftId, rewardRate) = reader.getTargetRewardRate(stakeNftId);
434
- (Amount rewardIncrement, ) = StakeManagerLib.calculateRewardIncrease(
435
- reader,
436
- stakeNftId,
437
- rewardRate);
618
+ // interactions
619
+ // collect DIP token from target owner
620
+ if (dipAmount.gtz()) {
621
+ $._stakingService.pullDipToken(dipAmount, transferFrom);
622
+ }
623
+ }
438
624
 
439
- store.updateRewards(
440
- stakeNftId,
441
- targetNftId,
442
- rewardIncrement);
625
+
626
+ function _withdrawRewardReserves(NftId targetNftId, Amount dipAmount, address transferTo)
627
+ internal
628
+ virtual
629
+ returns (Amount newBalance)
630
+ {
631
+ // checks + effects
632
+ StakingStorage storage $ = _getStakingStorage();
633
+ newBalance = $._store.withdrawRewardReserves(targetNftId, dipAmount);
634
+
635
+ // interactions
636
+ // transfer DIP token to designated address
637
+ if (dipAmount.gtz()) {
638
+ $._stakingService.pushDipToken(dipAmount, transferTo);
639
+ }
443
640
  }
444
641
 
445
642
 
446
- function _approveTokenHandler(IERC20Metadata token, Amount amount)
643
+ function _addToken(
644
+ StakingStorage storage $,
645
+ ChainId chainId,
646
+ address token
647
+ )
447
648
  internal
448
- virtual override
649
+ virtual
449
650
  {
450
- IComponentService(_getServiceAddress(COMPONENT())).approveStakingTokenHandler(
451
- token,
452
- amount);
651
+ if ($._store.getTokenInfo(chainId, token).lastUpdateIn.eqz()) {
652
+ $._store.addToken(chainId, token);
653
+ }
453
654
  }
454
655
 
455
656
 
657
+ /// @dev top level initializer (upgradable contract)
456
658
  function _initialize(
457
659
  address owner,
458
660
  bytes memory data
459
661
  )
460
662
  internal
461
663
  virtual override
462
- initializer()
664
+ onlyInitializing()
463
665
  {
464
666
  (
465
667
  address registryAddress,
466
668
  address tokenRegistryAddress,
467
- address stakingStoreAddress,
468
- address stakingOwner
469
- ) = abi.decode(data, (address, address, address, address));
669
+ address stakingStoreAddress
670
+ ) = abi.decode(data, (address, address, address));
470
671
 
471
- // only admin(authority) and dip token address are set in registry at this point
672
+ // wiring to external contracts
472
673
  IRegistry registry = IRegistry(registryAddress);
473
- address authority = registry.getAuthority();
474
- TokenRegistry tokenRegistry = TokenRegistry(tokenRegistryAddress);
475
- address dipTokenAddress = tokenRegistry.getDipTokenAddress();
674
+ StakingStorage storage $ = _getStakingStorage();
675
+ $._protocolNftId = registry.getProtocolNftId();
676
+ $._store = StakingStore(stakingStoreAddress);
677
+ $._reader = StakingStore(stakingStoreAddress).getStakingReader();
678
+ $._tokenRegistry = TokenRegistry(tokenRegistryAddress);
679
+ // staking service has to be set via setStakingService after deploying the first GIF release
476
680
 
477
- _initializeComponent(
478
- authority,
479
- registryAddress,
681
+ __Component_init(
682
+ registry.getAuthority(),
683
+ address(registry),
480
684
  registry.getNftId(), // parent nft id
481
685
  CONTRACT_NAME,
482
- dipTokenAddress,
483
686
  STAKING(),
484
687
  false, // is interceptor
485
- stakingOwner,
688
+ owner,
486
689
  "", // registry data
487
690
  ""); // component data
488
691
 
489
- // wiring to external contracts
490
- StakingStorage storage $ = _getStakingStorage();
491
- $._protocolNftId = getRegistry().getProtocolNftId();
492
- $._store = StakingStore(stakingStoreAddress);
493
- $._reader = StakingStore(stakingStoreAddress).getStakingReader();
494
- $._tokenRegistry = TokenRegistry(tokenRegistryAddress);
692
+ // Protocol target is created in the StakingStore constructor.
693
+ // This allows setting up the protocol target before the full
694
+ // staking authorization setup is in place.
695
+ _checkAndLogProtocolTargetCreation($);
495
696
 
496
697
  _registerInterface(type(IStaking).interfaceId);
497
698
  }
498
699
 
499
700
 
701
+ function _checkAndLogProtocolTargetCreation(StakingStorage storage $)
702
+ internal
703
+ virtual
704
+ {
705
+ TargetInfo memory protocolInfo = $._store.getTargetInfo($._protocolNftId);
706
+
707
+ if (protocolInfo.lastUpdateIn.eqz()) {
708
+ revert ErrorStakingTargetNotFound($._protocolNftId);
709
+ }
710
+
711
+ emit LogStakingTargetCreated($._protocolNftId, protocolInfo.objectType, protocolInfo.lockingPeriod, protocolInfo.rewardRate, protocolInfo.maxStakedAmount);
712
+ }
713
+
714
+
715
+ function _checkTypeAndOwner(NftId nftId, ObjectType expectedObjectType, bool checkOwner)
716
+ internal
717
+ view
718
+ {
719
+ StakingStorage storage $ = _getStakingStorage();
720
+ if (expectedObjectType == STAKE()) {
721
+ if (!$._store.exists(nftId)) {
722
+ revert ErrorStakingNotStake(nftId);
723
+ }
724
+ } else {
725
+ if (expectedObjectType == TARGET()) {
726
+ if (!$._store.getTargetSet().exists(nftId)) {
727
+ revert ErrorStakingNotTarget(nftId);
728
+ }
729
+ }
730
+ }
731
+
732
+ if (checkOwner) {
733
+ address nftOwner = getRegistry().ownerOf(nftId);
734
+ if (msg.sender != nftOwner) {
735
+ revert ErrorStakingNotOwner(nftId, nftOwner, msg.sender);
736
+ }
737
+ }
738
+ }
739
+
740
+
500
741
  function _getStakingStorage() private pure returns (StakingStorage storage $) {
501
742
  assembly {
502
743
  $.slot := STAKING_LOCATION_V1