@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
@@ -7,17 +7,20 @@ import {IRegistry} from "../registry/IRegistry.sol";
7
7
  import {IStaking} from "./IStaking.sol";
8
8
 
9
9
  import {Amount, AmountLib} from "../type/Amount.sol";
10
+ import {ChainId, ChainIdLib} from "../type/ChainId.sol";
10
11
  import {Blocknumber, BlocknumberLib} from "../type/Blocknumber.sol";
11
12
  import {KeyValueStore} from "../shared/KeyValueStore.sol";
12
- import {KEEP_STATE} from "../type/StateId.sol";
13
13
  import {NftId, NftIdLib} from "../type/NftId.sol";
14
14
  import {NftIdSet} from "../shared/NftIdSet.sol";
15
- import {PROTOCOL, STAKE, TARGET} from "../type/ObjectType.sol";
15
+ import {ObjectType} from "../type/ObjectType.sol";
16
+ import {PROTOCOL} from "../type/ObjectType.sol";
17
+ import {Seconds, SecondsLib} from "../type/Seconds.sol";
18
+ import {StakingLib} from "./StakingLib.sol";
19
+ import {StakingLifecycle} from "./StakingLifecycle.sol";
16
20
  import {StakingReader} from "./StakingReader.sol";
17
21
  import {TargetManagerLib} from "./TargetManagerLib.sol";
18
22
  import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
19
- import {StakingLifecycle} from "./StakingLifecycle.sol";
20
- import {UFixed} from "../type/UFixed.sol";
23
+ import {UFixed, UFixedLib} from "../type/UFixed.sol";
21
24
 
22
25
 
23
26
  contract StakingStore is
@@ -26,51 +29,44 @@ contract StakingStore is
26
29
  StakingLifecycle
27
30
  {
28
31
 
29
- event LogStakingStoreReserveBalanceIncreased(NftId targetNftId, Amount dipAmount, Amount reserveBalance, Blocknumber lastUpdatedIn);
30
- event LogStakingStoreReserveBalanceDecreased(NftId targetNftId, Amount dipAmount, Amount reserveBalance, Blocknumber lastUpdatedIn);
31
-
32
- event LogStakingStoreTotalValueLockedIncreased(NftId targetNftId, address token, Amount amount, Amount newBalance, Blocknumber lastUpdatedIn);
33
- event LogStakingStoreTotalValueLockedDecreased(NftId targetNftId, address token, Amount amount, Amount newBalance, Blocknumber lastUpdatedIn);
34
-
35
- event LogStakingStoreStakesIncreased(NftId nftId, Amount addedAmount, Amount newBalance, Blocknumber lastUpdatedIn);
36
- event LogStakingStoreStakesDecreased(NftId nftId, Amount addedAmount, Amount newBalance, Blocknumber lastUpdatedIn);
37
-
38
- event LogStakingStoreRewardsIncreased(NftId nftId, Amount addedAmount, Amount newBalance, Blocknumber lastUpdatedIn);
39
- event LogStakingStoreRewardsDecreased(NftId nftId, Amount addedAmount, Amount newBalance, Blocknumber lastUpdatedIn);
32
+ // token
33
+ error ErrorStakingStoreTokenNotRegistered(ChainId chainId, address token);
34
+ error ErrorStakingStoreTokenAlreadyAdded(ChainId chainId, address token);
35
+ error ErrorStakingStoreTokenUnknown(ChainId chainId, address token);
40
36
 
41
- event LogStakingStoreRewardsRestaked(NftId nftId, Amount amount, Amount rewardAmount, Amount rewardIncrementAmount, Amount newBalance, Blocknumber lastUpdatedIn);
37
+ // target
38
+ error ErrorStakingStoreTargetNotInitialized(NftId targetNftId);
42
39
 
43
40
  // in/decreasing reward reserves
44
41
  error ErrorStakingStoreNotTarget(NftId targetNftId);
45
- error ErrorStakingStoreRewardReservesInsufficient(NftId targetNftId, Amount dipAmount, Amount reservesBalanceAmount);
42
+ error ErrorStakingStoreRewardReservesInsufficient(NftId targetNftId, Amount reserveAmount, Amount claimedAmount);
46
43
 
47
- // creating and updating of balance
48
- error ErrorStakingStoreBalanceAlreadyInitialized(NftId nftId);
49
- error ErrorStakingStoreBalanceNotInitialized(NftId nftId);
44
+ // stakes
45
+ error ErrorStakingStoreStakesExceedingTargetMaxAmount(NftId targetNftId, Amount maxStakedAmount, Amount newIStaking);
46
+ error ErrorStakingStoreStakeNotInitialized(NftId nftId);
50
47
 
51
- // update balance
52
- error ErrorStakingStoreTvlBalanceNotInitialized(NftId nftId);
48
+ // creating and updating of staking balance
49
+ error ErrorStakingStoreStakeBalanceAlreadyInitialized(NftId nftId);
50
+ error ErrorStakingStoreStakeBalanceNotInitialized(NftId nftI);
51
+
52
+ // creating and updating of tvl balance
53
+ error ErrorStakingStoreTvlBalanceAlreadyInitialized(NftId nftId, address token);
54
+ error ErrorStakingStoreTvlBalanceNotInitialized(NftId nftId, address token);
53
55
 
54
56
  IRegistry private _registry;
55
57
  NftIdSet private _targetNftIdSet;
56
58
  StakingReader private _reader;
57
59
 
58
- // staking rate
59
- mapping(uint256 chainId => mapping(address token => UFixed stakingRate)) private _stakingRate;
60
-
61
- // total, stake and reward balances
62
- mapping(NftId nftId => Amount stakes) private _stakeBalance;
63
- mapping(NftId nftId => Amount rewards) private _rewardBalance;
64
- mapping(NftId nftId => Amount reserves) private _reserveBalance;
60
+ // stakes
61
+ mapping(NftId stakeNftId => IStaking.StakeInfo) private _stakeInfo;
65
62
 
66
- mapping(NftId nftId => Timestamp lastUpdatedAt) private _lastUpdatedAt;
67
- mapping(NftId nftId => Blocknumber lastUpdatedIn) private _lastUpdatedIn;
63
+ // targets
64
+ mapping(NftId targetNftId => IStaking.TargetInfo) private _targetInfo;
65
+ mapping(NftId targetNftId => mapping(address token => IStaking.TvlInfo)) private _tvlInfo;
66
+ mapping(NftId targetNftId => address [] token) private _targetToken;
68
67
 
69
- // total value locked balance
70
- mapping(NftId nftId => mapping(address token => Amount tvl)) private _tvlBalance;
71
- mapping(NftId nftId => mapping(address token => Amount tvlInDip)) private _tvlInDip;
72
- mapping(NftId nftId => Amount tvlRequiredDip) private _tvlRequiredDip;
73
- mapping(NftId nftId => Blocknumber lastUpdatedIn) private _tvlLastUpdatedIn;
68
+ // staking rate
69
+ mapping(ChainId chainId => mapping(address token => IStaking.TokenInfo)) private _tokenInfo;
74
70
 
75
71
 
76
72
  constructor(IRegistry registry, StakingReader reader)
@@ -80,61 +76,183 @@ contract StakingStore is
80
76
  setAuthority(registry.getAuthority());
81
77
 
82
78
  // set internal variables
83
- _registry = registry; //TODO if keeps registry -> RegistryLinked and checks registry address
79
+ _registry = registry;
84
80
  _reader = reader;
85
81
  _targetNftIdSet = new NftIdSet();
86
82
 
87
83
  // register protocol target
88
84
  _createTarget(
89
85
  NftIdLib.toNftId(1101),
90
- IStaking.TargetInfo({
91
- objectType: PROTOCOL(),
92
- chainId: 1,
93
- lockingPeriod: TargetManagerLib.getDefaultLockingPeriod(),
94
- rewardRate: TargetManagerLib.getDefaultRewardRate()}));
86
+ PROTOCOL(),
87
+ TargetManagerLib.getDefaultLockingPeriod(),
88
+ TargetManagerLib.getDefaultRewardRate(),
89
+ false); // no parameter check
95
90
  }
96
91
 
97
92
 
98
- //--- staking rate specific functions -----------------------------------//
93
+ //--- token management --------------------------------------------------//
94
+
95
+ /// @dev Registers a token for tvl management.
96
+ function addToken(
97
+ ChainId chainId,
98
+ address token
99
+ )
100
+ external
101
+ restricted() // token registry via staking
102
+ {
103
+ // checks
104
+ IStaking.TokenInfo storage info = _tokenInfo[chainId][token];
105
+
106
+ // check token is not yet registered
107
+ if (info.lastUpdateIn.gtz()) {
108
+ revert ErrorStakingStoreTokenAlreadyAdded(chainId, token);
109
+ }
110
+
111
+ info.stakingRate = UFixedLib.zero();
112
+ info.lastUpdateIn = BlocknumberLib.current();
113
+
114
+ // logging
115
+ emit IStaking.LogStakingTokenAdded(chainId, token);
116
+ }
117
+
99
118
 
119
+ /// @dev Sets the staking rate for the token.
100
120
  function setStakingRate(
101
- uint256 chainId,
121
+ ChainId chainId,
102
122
  address token,
103
123
  UFixed stakingRate
104
124
  )
105
125
  external
106
- restricted()
126
+ restricted() // staking
127
+ returns (
128
+ UFixed oldStakingRate,
129
+ Blocknumber lastUpdatedIn
130
+ )
107
131
  {
108
- _stakingRate[chainId][token] = stakingRate;
132
+ IStaking.TokenInfo storage info = _tokenInfo[chainId][token];
133
+ if (info.lastUpdateIn.eqz()) {
134
+ revert ErrorStakingStoreTokenUnknown(chainId, token);
135
+ }
136
+
137
+ // get previous values
138
+ oldStakingRate = info.stakingRate;
139
+ lastUpdatedIn = info.lastUpdateIn;
140
+
141
+ // update values
142
+ info.stakingRate = stakingRate;
143
+ info.lastUpdateIn = BlocknumberLib.current();
109
144
  }
110
145
 
111
- //--- target specific functions -----------------------------------------//
146
+ //--- target management -------------------------------------------------//
112
147
 
113
148
  function createTarget(
114
149
  NftId targetNftId,
115
- IStaking.TargetInfo memory targetInfo
150
+ ObjectType objectType,
151
+ Seconds lockingPeriod,
152
+ UFixed rewardRate
116
153
  )
117
154
  external
118
- restricted()
155
+ restricted() // staking
119
156
  {
120
- _createTarget(targetNftId, targetInfo);
157
+ _createTarget(targetNftId, objectType, lockingPeriod, rewardRate, true);
121
158
  }
122
159
 
123
160
 
124
- function updateTarget(
125
- NftId targetNftId,
126
- IStaking.TargetInfo memory targetInfo
161
+ function setLockingPeriod(
162
+ NftId targetNftId,
163
+ Seconds lockingPeriod
164
+ )
165
+ external
166
+ restricted() // staking
167
+ returns (
168
+ Seconds oldLockingPeriod,
169
+ Blocknumber lastUpdatedIn
170
+ )
171
+ {
172
+ TargetManagerLib.checkLockingPeriod(targetNftId, lockingPeriod);
173
+
174
+ IStaking.TargetInfo storage targetInfo;
175
+ (targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
176
+
177
+ oldLockingPeriod = targetInfo.lockingPeriod;
178
+ targetInfo.lockingPeriod = lockingPeriod;
179
+ }
180
+
181
+
182
+ function setRewardRate(
183
+ NftId targetNftId,
184
+ UFixed rewardRate
185
+ )
186
+ external
187
+ restricted() // staking
188
+ returns (
189
+ UFixed oldRewardRate,
190
+ Blocknumber lastUpdatedIn
191
+ )
192
+ {
193
+ TargetManagerLib.checkRewardRate(targetNftId, rewardRate);
194
+
195
+ IStaking.TargetInfo storage targetInfo;
196
+ (targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
197
+
198
+ oldRewardRate = targetInfo.rewardRate;
199
+ targetInfo.rewardRate = rewardRate;
200
+ }
201
+
202
+
203
+ function setMaxStakedAmount(
204
+ NftId targetNftId,
205
+ Amount maxStakedAmount
206
+ )
207
+ external
208
+ restricted() // staking
209
+ returns (
210
+ Amount oldMaxStakedAmount,
211
+ Blocknumber lastUpdatedIn
212
+ )
213
+ {
214
+ IStaking.TargetInfo storage targetInfo;
215
+ (targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
216
+
217
+ oldMaxStakedAmount = targetInfo.maxStakedAmount;
218
+ targetInfo.maxStakedAmount = maxStakedAmount;
219
+ }
220
+
221
+
222
+ function addTargetToken(
223
+ NftId targetNftId,
224
+ address token
127
225
  )
128
226
  external
129
227
  restricted()
130
228
  {
131
- _update(
132
- targetNftId.toKey32(TARGET()),
133
- abi.encode(targetInfo), KEEP_STATE());
229
+ // checks
230
+
231
+ // skip registering if tvl balance has already been initialized
232
+ IStaking.TvlInfo storage tvlInfo = _tvlInfo[targetNftId][token];
233
+ if (tvlInfo.lastUpdateIn.gtz()) {
234
+ return;
235
+ }
236
+
237
+ // check target exists
238
+ _getAndVerifyTarget(targetNftId);
239
+
240
+ // check token is known for chain id of target
241
+ ChainId chainId = ChainIdLib.fromNftId(targetNftId);
242
+ if (_tokenInfo[chainId][token].lastUpdateIn.eqz()) {
243
+ revert ErrorStakingStoreTokenUnknown(chainId, token);
244
+ }
245
+
246
+ // effects
247
+ tvlInfo.tvlAmount = AmountLib.zero();
248
+ tvlInfo.lastUpdateIn = BlocknumberLib.current();
249
+
250
+ // add token to list of know tokens for target
251
+ _targetToken[targetNftId].push(token);
134
252
  }
135
253
 
136
254
 
137
- function increaseReserves(
255
+ function refillRewardReserves(
138
256
  NftId targetNftId,
139
257
  Amount dipAmount
140
258
  )
@@ -142,14 +260,26 @@ contract StakingStore is
142
260
  restricted()
143
261
  returns (Amount newReserveBalance)
144
262
  {
145
- newReserveBalance = _reserveBalance[targetNftId] + dipAmount;
146
- Blocknumber lastUpdatedIn = _updateReserves(targetNftId, newReserveBalance);
263
+ // checks
264
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
265
+ Blocknumber lastUpdateIn = targetInfo.lastUpdateIn;
266
+
267
+ // effects
268
+ targetInfo.reserveAmount = targetInfo.reserveAmount + dipAmount;
269
+ targetInfo.lastUpdateIn = BlocknumberLib.current();
147
270
 
148
- emit LogStakingStoreReserveBalanceIncreased(targetNftId, dipAmount, newReserveBalance, lastUpdatedIn);
271
+ // logging
272
+ newReserveBalance = targetInfo.reserveAmount;
273
+ emit IStaking.LogStakingRewardReservesRefilled(
274
+ targetNftId,
275
+ dipAmount,
276
+ _registry.ownerOf(targetNftId),
277
+ newReserveBalance,
278
+ lastUpdateIn);
149
279
  }
150
280
 
151
281
 
152
- function decreaseReserves(
282
+ function withdrawRewardReserves(
153
283
  NftId targetNftId,
154
284
  Amount dipAmount
155
285
  )
@@ -157,18 +287,20 @@ contract StakingStore is
157
287
  restricted()
158
288
  returns (Amount newReserveBalance)
159
289
  {
160
- Amount reserveAmount = _reserveBalance[targetNftId];
161
- if (dipAmount > reserveAmount) {
162
- revert ErrorStakingStoreRewardReservesInsufficient(
163
- targetNftId,
164
- dipAmount,
165
- reserveAmount);
166
- }
290
+ // checks
291
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
167
292
 
168
- newReserveBalance = _reserveBalance[targetNftId] - dipAmount;
169
- Blocknumber lastUpdatedIn = _updateReserves(targetNftId, newReserveBalance);
293
+ // effects
294
+ Blocknumber lastUpdateIn = _decreaseReserves(targetNftId, targetInfo, dipAmount);
170
295
 
171
- emit LogStakingStoreReserveBalanceDecreased(targetNftId, dipAmount, newReserveBalance, lastUpdatedIn);
296
+ // logging
297
+ newReserveBalance = targetInfo.reserveAmount;
298
+ emit IStaking.LogStakingRewardReservesWithdrawn(
299
+ targetNftId,
300
+ dipAmount,
301
+ _registry.ownerOf(targetNftId),
302
+ newReserveBalance,
303
+ lastUpdateIn);
172
304
  }
173
305
 
174
306
 
@@ -176,7 +308,6 @@ contract StakingStore is
176
308
 
177
309
  function increaseTotalValueLocked(
178
310
  NftId targetNftId,
179
- UFixed stakingRate,
180
311
  address token,
181
312
  Amount amount
182
313
  )
@@ -184,32 +315,18 @@ contract StakingStore is
184
315
  restricted()
185
316
  returns (Amount newBalance)
186
317
  {
187
- (
188
- Blocknumber tvlLastUpdatedIn,
189
- Amount oldBalance,
190
- Amount oldDipBalance
191
- ) = _getAndVerifyTvl(targetNftId, token);
192
-
193
- newBalance = oldBalance + amount;
194
- Amount newDipBalance = newBalance.multiplyWith(stakingRate);
318
+ // checks
319
+ IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
195
320
 
196
- // update new tvl balances
197
- _tvlBalance[targetNftId][token] = newBalance;
198
- _tvlInDip[targetNftId][token] = newDipBalance;
199
-
200
- // update new amount of required dip
201
- _tvlRequiredDip[targetNftId] = _tvlRequiredDip[targetNftId] - oldDipBalance + newDipBalance;
202
-
203
- // update last updated in
204
- _tvlLastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
205
-
206
- emit LogStakingStoreTotalValueLockedIncreased(targetNftId, token, amount, newBalance, tvlLastUpdatedIn);
321
+ // effects
322
+ tvlInfo.tvlAmount = tvlInfo.tvlAmount + amount;
323
+ tvlInfo.lastUpdateIn = BlocknumberLib.current();
324
+ newBalance = tvlInfo.tvlAmount;
207
325
  }
208
326
 
209
327
 
210
328
  function decreaseTotalValueLocked(
211
329
  NftId targetNftId,
212
- UFixed stakingRate,
213
330
  address token,
214
331
  Amount amount
215
332
  )
@@ -217,389 +334,640 @@ contract StakingStore is
217
334
  restricted()
218
335
  returns (Amount newBalance)
219
336
  {
220
- (
221
- Blocknumber tvlLastUpdatedIn,
222
- Amount oldBalance,
223
- Amount oldDipBalance
224
- ) = _getAndVerifyTvl(targetNftId, token);
225
-
226
- newBalance = oldBalance - amount;
227
- Amount newDipBalance = AmountLib.toAmount((
228
- stakingRate * newBalance.toUFixed()).toInt());
337
+ // checks
338
+ IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
229
339
 
230
- // update new tvl balances
231
- _tvlBalance[targetNftId][token] = newBalance;
232
- _tvlInDip[targetNftId][token] = newDipBalance;
233
-
234
- // update new amount of required dip
235
- _tvlRequiredDip[targetNftId] = _tvlRequiredDip[targetNftId] - oldDipBalance + newDipBalance;
236
-
237
- // update last updated in
238
- _tvlLastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
239
-
240
- emit LogStakingStoreTotalValueLockedDecreased(targetNftId, token, amount, newBalance, tvlLastUpdatedIn);
340
+ // effects
341
+ tvlInfo.tvlAmount = tvlInfo.tvlAmount - amount;
342
+ tvlInfo.lastUpdateIn = BlocknumberLib.current();
343
+ newBalance = tvlInfo.tvlAmount;
241
344
  }
242
345
 
243
346
  //--- stake specific functions -------------------------------------//
244
347
 
245
- function create(
348
+ function createStake(
246
349
  NftId stakeNftId,
247
- IStaking.StakeInfo memory stakeInfo
350
+ NftId targetNftId,
351
+ address stakeOwner,
352
+ Amount stakeAmount
248
353
  )
249
354
  external
250
355
  restricted()
356
+ returns (Timestamp lockedUntil)
251
357
  {
252
- _create(
253
- stakeNftId.toKey32(STAKE()),
254
- abi.encode(stakeInfo));
358
+ // checks
359
+ IStaking.StakeInfo storage stakeInfo = _stakeInfo[stakeNftId];
360
+ if (stakeInfo.lastUpdateIn.gtz()) {
361
+ revert ErrorStakingStoreStakeBalanceAlreadyInitialized(stakeNftId);
362
+ }
363
+
364
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
365
+ _checkMaxStakedAmount(targetNftId, targetInfo, stakeAmount);
366
+
367
+ // effects
368
+ stakeInfo.targetNftId = targetNftId;
369
+ stakeInfo.stakedAmount = AmountLib.zero();
370
+ stakeInfo.rewardAmount = AmountLib.zero();
371
+ stakeInfo.lockedUntil = TimestampLib.current();
372
+ _setStakeLastUpdatesToCurrent(stakeInfo);
373
+
374
+ // logging for creation of empty stake
375
+ emit IStaking.LogStakingStakeCreated(stakeNftId, stakeInfo.targetNftId, stakeInfo.stakedAmount, stakeInfo.lockedUntil, stakeOwner);
255
376
 
256
- _createStakeBalance(stakeNftId);
377
+ // process stake amount
378
+ _stake(stakeNftId, stakeInfo, targetInfo, targetInfo.lockingPeriod, stakeAmount);
257
379
  }
258
380
 
259
- function update(
260
- NftId stakeNftId,
261
- IStaking.StakeInfo memory stakeInfo
381
+
382
+ function stake(
383
+ NftId stakeNftId,
384
+ bool updateRewards,
385
+ bool restakeRewards,
386
+ Seconds additionalLockingPeriod,
387
+ Amount stakeAmount
262
388
  )
263
389
  external
264
390
  restricted()
265
391
  {
266
- _update(
267
- stakeNftId.toKey32(STAKE()),
268
- abi.encode(stakeInfo),
269
- KEEP_STATE());
270
- }
392
+ // checks
393
+ IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
394
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
271
395
 
272
- //--- general functions --------------------------------------------//
396
+ if (updateRewards) {
397
+ _updateRewards(stakeNftId, stakeInfo, targetInfo);
398
+ }
273
399
 
400
+ if (restakeRewards) {
401
+ _restakeRewards(stakeNftId, stakeInfo, targetInfo);
402
+ }
274
403
 
275
- function increaseStake(
276
- NftId nftId,
277
- NftId targetNftId,
278
- Amount amount
404
+ _stake(stakeNftId, stakeInfo, targetInfo, additionalLockingPeriod, stakeAmount);
405
+ }
406
+
407
+
408
+ function unstake(
409
+ NftId stakeNftId,
410
+ bool updateRewards,
411
+ bool restakeRewards,
412
+ Amount maxUnstakeAmount
279
413
  )
280
414
  external
281
415
  restricted()
416
+ returns (Amount unstakedAmount)
282
417
  {
283
- Blocknumber lastUpdatedIn = _checkBalanceExists(nftId);
418
+ // checks
419
+ IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
420
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
284
421
 
285
- _updateStakeBalance(
286
- nftId,
287
- _stakeBalance[nftId] + amount, // new stake balance
288
- _rewardBalance[nftId]); // unchanged reward balance
422
+ if (updateRewards) {
423
+ _updateRewards(stakeNftId, stakeInfo, targetInfo);
424
+ }
289
425
 
290
- _updateTargetBalance(
291
- targetNftId,
292
- _stakeBalance[targetNftId] + amount,
293
- _rewardBalance[targetNftId]);
426
+ if (restakeRewards) {
427
+ _restakeRewards(stakeNftId, stakeInfo, targetInfo);
428
+ }
294
429
 
295
- emit LogStakingStoreStakesIncreased(nftId, amount, _stakeBalance[nftId], lastUpdatedIn);
430
+ return _unstake(stakeNftId, stakeInfo, targetInfo, maxUnstakeAmount);
296
431
  }
297
432
 
298
433
 
299
- function restakeRewards(
300
- NftId nftId,
301
- NftId targetNftId,
302
- Amount rewardIncrementAmount
303
- )
434
+ function updateRewards(NftId stakeNftId)
304
435
  external
305
436
  restricted()
306
437
  {
307
- Blocknumber lastUpdatedIn = _checkBalanceExists(nftId);
308
- Amount stakeAmount = _stakeBalance[nftId];
309
- Amount rewardAmount = _rewardBalance[nftId];
310
-
311
- // move all rewards to stake balance
312
- _updateStakeBalance(
313
- nftId,
314
- stakeAmount + rewardAmount + rewardIncrementAmount, // new stake balance
315
- AmountLib.zero()); // new reward balance
316
-
317
- _updateTargetBalance(
318
- targetNftId,
319
- _stakeBalance[targetNftId] + rewardAmount + rewardIncrementAmount,
320
- _rewardBalance[targetNftId] - rewardAmount);
321
-
322
- emit LogStakingStoreRewardsRestaked(nftId, stakeAmount, rewardAmount, rewardIncrementAmount, _stakeBalance[nftId], lastUpdatedIn);
438
+ // checks
439
+ IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
440
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
441
+ _updateRewards(stakeNftId, stakeInfo, targetInfo);
323
442
  }
324
443
 
325
444
 
326
- function updateRewards(
327
- NftId nftId,
328
- NftId targetNftId,
329
- Amount rewardIncrementAmount
445
+ function restakeRewards(
446
+ NftId stakeNftId,
447
+ bool updateRewards
330
448
  )
331
449
  external
332
450
  restricted()
333
451
  {
334
- Blocknumber lastUpdatedIn = _checkBalanceExists(nftId);
452
+ // checks
453
+ IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
454
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
335
455
 
336
- // increse rewards by increment
337
- _updateStakeBalance(
338
- nftId,
339
- _stakeBalance[nftId], // unchanged stake balance
340
- _rewardBalance[nftId] + rewardIncrementAmount); // new reward balance
341
-
342
- _updateTargetBalance(
343
- targetNftId,
344
- _stakeBalance[targetNftId],
345
- _rewardBalance[targetNftId] + rewardIncrementAmount);
456
+ if (updateRewards) {
457
+ _updateRewards(stakeNftId, stakeInfo, targetInfo);
458
+ }
346
459
 
347
- emit LogStakingStoreRewardsIncreased(nftId, rewardIncrementAmount, _rewardBalance[nftId], lastUpdatedIn);
460
+ _restakeRewards(stakeNftId, stakeInfo, targetInfo);
348
461
  }
349
462
 
350
463
 
351
- function claimUpTo(
352
- NftId nftId,
353
- NftId targetNftId,
464
+ function claimRewards(
465
+ NftId stakeNftId,
466
+ bool updateRewards,
354
467
  Amount maxClaimAmount
355
468
  )
356
469
  external
357
470
  restricted()
358
471
  returns (Amount claimedAmount)
359
472
  {
360
- Blocknumber lastUpdatedIn = _checkBalanceExists(nftId);
473
+ // checks
474
+ IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
475
+ IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
361
476
 
362
- // determine the claimable rewards amount
363
- claimedAmount = AmountLib.min(maxClaimAmount, _rewardBalance[nftId]);
477
+ if (updateRewards) {
478
+ _updateRewards(stakeNftId, stakeInfo, targetInfo);
479
+ }
364
480
 
365
- // decrease rewards by claimed amount
366
- _updateStakeBalance(
367
- nftId,
368
- _stakeBalance[nftId], // unchanged stake balance
369
- _rewardBalance[nftId] - claimedAmount); // new reward balance
481
+ claimedAmount = _claimRewards(stakeNftId, stakeInfo, targetInfo, maxClaimAmount);
482
+ }
370
483
 
371
- _updateTargetBalance(
372
- targetNftId,
373
- _stakeBalance[targetNftId],
374
- _rewardBalance[targetNftId] - claimedAmount);
484
+ //--- view functions -----------------------------------------------//
375
485
 
376
- emit LogStakingStoreRewardsDecreased(nftId, claimedAmount, _rewardBalance[nftId], lastUpdatedIn);
486
+ function getStakingReader() external view returns (StakingReader stakingReader){
487
+ return _reader;
377
488
  }
378
489
 
379
490
 
380
- function unstakeUpTo(
381
- NftId nftId,
382
- NftId targetNftId,
383
- Amount maxUnstakeAmount,
384
- Amount maxClaimAmount
385
- )
491
+ function exists(NftId stakeNftId) external view returns (bool) {
492
+ return _stakeInfo[stakeNftId].lastUpdateIn.gtz();
493
+ }
494
+
495
+
496
+ function getRequiredStakeBalance(NftId targetNftId)
386
497
  external
387
- restricted()
388
- returns (
389
- Amount unstakedAmount,
390
- Amount claimedAmount
391
- )
498
+ view
499
+ returns (Amount requiredStakedAmount)
392
500
  {
393
- Blocknumber lastUpdatedIn = _checkBalanceExists(nftId);
501
+ address [] memory tokens = _targetToken[targetNftId];
502
+ if (tokens.length == 0) {
503
+ return AmountLib.zero();
504
+ }
394
505
 
395
- // determine amounts
396
- unstakedAmount = AmountLib.min(maxUnstakeAmount, _stakeBalance[nftId]);
397
- claimedAmount = AmountLib.min(maxClaimAmount, _rewardBalance[nftId]);
506
+ requiredStakedAmount = AmountLib.zero();
507
+ ChainId targetChainId = _targetInfo[targetNftId].chainId;
508
+ address token;
509
+ Amount tvlAmount;
510
+ UFixed stakingRate;
398
511
 
399
- // decrease stakes and rewards as determined
400
- _updateStakeBalance(
401
- nftId,
402
- _stakeBalance[nftId] - unstakedAmount, // unchanged stake balance
403
- _rewardBalance[nftId] - claimedAmount); // new reward balance
512
+ for (uint256 i = 0; i < tokens.length; i++) {
513
+ token = tokens[i];
514
+ tvlAmount = _tvlInfo[targetNftId][token].tvlAmount;
515
+ if (tvlAmount.eqz()) { continue; }
404
516
 
405
- _updateTargetBalance(
406
- targetNftId,
407
- _stakeBalance[targetNftId] - unstakedAmount,
408
- _rewardBalance[targetNftId] - claimedAmount);
517
+ stakingRate = _tokenInfo[targetChainId][token].stakingRate;
518
+ if (stakingRate.eqz()) { continue; }
409
519
 
410
- emit LogStakingStoreStakesDecreased(nftId, unstakedAmount, _stakeBalance[nftId], lastUpdatedIn);
411
- emit LogStakingStoreRewardsDecreased(nftId, claimedAmount, _rewardBalance[nftId], lastUpdatedIn);
520
+ requiredStakedAmount = requiredStakedAmount + tvlAmount.multiplyWith(stakingRate);
521
+ }
412
522
  }
413
523
 
414
- //--- view functions -----------------------------------------------//
415
524
 
416
- function getStakingReader() external view returns (StakingReader stakingReader){
417
- return _reader;
525
+ /// @dev Returns true iff current stake amount is still locked
526
+ function isStakeLocked(NftId stakeNftId) public view returns (bool) {
527
+ return _stakeInfo[stakeNftId].lockedUntil > TimestampLib.current();
418
528
  }
419
529
 
420
- // TODO rename
421
- function getTargetNftIdSet() external view returns (NftIdSet targetNftIdSet){
422
- return _targetNftIdSet;
530
+
531
+ /// @dev Returns the stake infos for the specified stake.
532
+ function getStakeInfo(NftId stakeNftId) external view returns (IStaking.StakeInfo memory stakeInfo) {
533
+ return _stakeInfo[stakeNftId];
423
534
  }
424
535
 
425
- function getStakingRate(uint256 chainId, address token) external view returns (UFixed stakingRate) { return _stakingRate[chainId][token]; }
426
536
 
427
- function exists(NftId stakeNftId) external view returns (bool) { return exists(stakeNftId.toKey32(STAKE())); }
537
+ /// @dev Returns the stake infos for the specified stake.
538
+ function getStakeTarget(NftId stakeNftId) external view returns (NftId targetNftId) {
539
+ return _stakeInfo[stakeNftId].targetNftId;
540
+ }
428
541
 
429
- function getTotalValueLocked(NftId nftId, address token) external view returns (Amount tvlBalanceAmount) { return _tvlBalance[nftId][token]; }
430
- function getRequiredStakeBalance(NftId nftId) external view returns (Amount requiredAmount) { return _tvlRequiredDip[nftId]; }
431
542
 
432
- function getReserveBalance(NftId nftId) external view returns (Amount balanceAmount) { return _reserveBalance[nftId]; }
433
- function getStakeBalance(NftId nftId) external view returns (Amount balanceAmount) { return _stakeBalance[nftId]; }
434
- function getRewardBalance(NftId nftId) external view returns (Amount rewardAmount) { return _rewardBalance[nftId]; }
435
- function getBalanceUpdatedAt(NftId nftId) external view returns (Timestamp updatedAt) { return _lastUpdatedAt[nftId]; }
436
- function getBalanceUpdatedIn(NftId nftId) external view returns (Blocknumber blocknumber) { return _lastUpdatedIn[nftId]; }
543
+ /// @dev Returns the target infos for the specified target.
544
+ function getTargetInfo(NftId targetNftId) external view returns (IStaking.TargetInfo memory targetInfo) {
545
+ return _targetInfo[targetNftId];
546
+ }
437
547
 
438
548
 
439
- function getTargetBalances(NftId nftId)
440
- external
441
- view
442
- returns (
443
- Amount stakeBalance,
444
- Amount rewardBalance,
445
- Amount reserveBalance,
446
- Blocknumber lastUpdatedIn
447
- )
448
- {
449
- stakeBalance = _stakeBalance[nftId];
450
- rewardBalance = _rewardBalance[nftId];
451
- reserveBalance = _reserveBalance[nftId];
452
- lastUpdatedIn = _lastUpdatedIn[nftId];
549
+ /// @dev Returns the tvl infos for the specified target.
550
+ function getTvlInfo(NftId targetNftId, address token) external view returns (IStaking.TvlInfo memory tvlInfo) {
551
+ return _tvlInfo[targetNftId][token];
453
552
  }
454
553
 
455
554
 
456
- function getStakeBalances(NftId nftId)
457
- external
458
- view
555
+ /// @dev Returns the tvl infos for the specified target.
556
+ function getTokenInfo(ChainId chainId, address token) external view returns (IStaking.TokenInfo memory tokenInfo) {
557
+ return _tokenInfo[chainId][token];
558
+ }
559
+
560
+
561
+ function getTargetSet() external view returns (NftIdSet targetNftIdSet) {
562
+ return _targetNftIdSet;
563
+ }
564
+
565
+ //--- internal functions -----------------------------------------------//
566
+
567
+ function _verifyAndUpdateTarget(NftId targetNftId)
568
+ private
459
569
  returns (
460
- Amount stakeBalance,
461
- Amount rewardBalance,
462
- Timestamp lastUpdatedAt
570
+ IStaking.TargetInfo storage targetInfo,
571
+ Blocknumber lastUpdatedIn
463
572
  )
464
573
  {
465
- stakeBalance = _stakeBalance[nftId];
466
- rewardBalance = _rewardBalance[nftId];
467
- lastUpdatedAt = _lastUpdatedAt[nftId];
574
+ // checks
575
+ targetInfo = _getAndVerifyTarget(targetNftId);
576
+ lastUpdatedIn = targetInfo.lastUpdateIn;
577
+ targetInfo.lastUpdateIn = BlocknumberLib.current();
468
578
  }
469
579
 
470
- //--- private functions -------------------------------------------//
471
580
 
472
581
  function _createTarget(
473
582
  NftId targetNftId,
474
- IStaking.TargetInfo memory targetInfo
583
+ ObjectType objectType,
584
+ Seconds lockingPeriod,
585
+ UFixed rewardRate,
586
+ bool checkParameters
475
587
  )
476
588
  private
477
589
  {
478
- _create(
479
- targetNftId.toKey32(TARGET()),
480
- abi.encode(targetInfo));
590
+ // checks
591
+ if (checkParameters) {
592
+ TargetManagerLib.checkTargetParameters(
593
+ _registry,
594
+ _reader,
595
+ targetNftId,
596
+ objectType,
597
+ lockingPeriod,
598
+ rewardRate);
599
+ }
600
+
601
+ // effects
602
+ IStaking.TargetInfo storage targetInfo = _targetInfo[targetNftId];
603
+ targetInfo.stakedAmount = AmountLib.zero();
604
+ targetInfo.rewardAmount = AmountLib.zero();
605
+ targetInfo.reserveAmount = AmountLib.zero();
606
+ targetInfo.maxStakedAmount = AmountLib.max();
481
607
 
482
- // initialize tvl and stake balance
483
- _tvlLastUpdatedIn[targetNftId]= BlocknumberLib.currentBlocknumber();
484
- _createTargetBalance(targetNftId);
608
+ targetInfo.objectType = objectType;
609
+ targetInfo.lockingPeriod = lockingPeriod;
610
+ targetInfo.rewardRate = rewardRate;
611
+ targetInfo.chainId = ChainIdLib.fromNftId(targetNftId);
612
+ targetInfo.lastUpdateIn = BlocknumberLib.current();
485
613
 
614
+ // add new target to target set
486
615
  _targetNftIdSet.add(targetNftId);
487
616
  }
488
617
 
489
- function _updateReserves(
618
+
619
+ function _spendRewardReserves(
490
620
  NftId targetNftId,
491
- Amount newRewardBalance
621
+ IStaking.TargetInfo storage targetInfo,
622
+ Amount dipAmount
492
623
  )
493
624
  private
494
- returns (Blocknumber lastUpdatedIn)
495
625
  {
496
- if (_lastUpdatedIn[targetNftId].eqz()) {
497
- revert ErrorStakingStoreNotTarget(targetNftId);
498
- }
626
+ Blocknumber lastUpdateIn = _decreaseReserves(targetNftId, targetInfo, dipAmount);
499
627
 
500
- lastUpdatedIn = _lastUpdatedIn[targetNftId];
501
-
502
- _reserveBalance[targetNftId] = newRewardBalance;
503
- _lastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
628
+ // logging
629
+ emit IStaking.LogStakingRewardReservesSpent(
630
+ targetNftId,
631
+ dipAmount,
632
+ targetInfo.reserveAmount,
633
+ lastUpdateIn);
504
634
  }
505
635
 
506
636
 
507
- function _createTargetBalance(NftId nftId)
637
+ function _decreaseReserves(
638
+ NftId targetNftId,
639
+ IStaking.TargetInfo storage targetInfo,
640
+ Amount dipAmount
641
+ )
508
642
  private
643
+ returns ( Blocknumber lastUpdateIn)
509
644
  {
510
- if (_lastUpdatedIn[nftId].gtz()) {
511
- revert ErrorStakingStoreBalanceAlreadyInitialized(nftId);
645
+ lastUpdateIn = targetInfo.lastUpdateIn;
646
+
647
+ // check if reserves are sufficient
648
+ if (dipAmount > targetInfo.reserveAmount) {
649
+ revert ErrorStakingStoreRewardReservesInsufficient(
650
+ targetNftId,
651
+ targetInfo.reserveAmount,
652
+ dipAmount);
512
653
  }
513
654
 
514
- // set target balances to 0
515
- _stakeBalance[nftId] = AmountLib.zero();
516
- _rewardBalance[nftId] = AmountLib.zero();
517
- _reserveBalance[nftId] = AmountLib.zero();
655
+ // effects
656
+ targetInfo.reserveAmount = targetInfo.reserveAmount - dipAmount;
657
+ targetInfo.lastUpdateIn = BlocknumberLib.current();
658
+ }
659
+
518
660
 
519
- // set last updated in to current block number
520
- // we don't need last updated at timestamp for targets
521
- _lastUpdatedIn[nftId] = BlocknumberLib.currentBlocknumber();
661
+ function _updateRewards(
662
+ NftId stakeNftId,
663
+ IStaking.StakeInfo storage stakeInfo,
664
+ IStaking.TargetInfo storage targetInfo
665
+ )
666
+ internal
667
+ returns (Amount rewardIncreaseAmount)
668
+ {
669
+ // return if reward rate is zero
670
+ if (targetInfo.rewardRate.eqz()) {
671
+ return rewardIncreaseAmount;
672
+ }
673
+
674
+ // get seconds since last update on stake
675
+ Seconds duration = SecondsLib.toSeconds(
676
+ block.timestamp - stakeInfo.lastUpdateAt.toInt());
677
+
678
+ // return if duration is zero
679
+ if (duration.eqz()) {
680
+ return AmountLib.zero();
681
+ }
682
+
683
+ // calculate reward increase since
684
+ rewardIncreaseAmount = StakingLib.calculateRewardAmount(
685
+ targetInfo.rewardRate,
686
+ duration,
687
+ stakeInfo.stakedAmount);
688
+
689
+ // update target + stake
690
+ targetInfo.rewardAmount = targetInfo.rewardAmount + rewardIncreaseAmount;
691
+ stakeInfo.rewardAmount = stakeInfo.rewardAmount + rewardIncreaseAmount;
692
+ _setLastUpdatesToCurrent(stakeInfo, targetInfo);
693
+
694
+ // logging
695
+ emit IStaking.LogStakingStakeRewardsUpdated(
696
+ stakeNftId,
697
+ rewardIncreaseAmount,
698
+ stakeInfo.stakedAmount,
699
+ stakeInfo.rewardAmount,
700
+ stakeInfo.lockedUntil);
522
701
  }
523
702
 
524
703
 
525
- function _createStakeBalance(NftId nftId)
526
- private
704
+ function _restakeRewards(
705
+ NftId stakeNftId,
706
+ IStaking.StakeInfo storage stakeInfo,
707
+ IStaking.TargetInfo storage targetInfo
708
+ )
709
+ internal
710
+ returns (Amount restakeAmount)
711
+ {
712
+ restakeAmount = stakeInfo.rewardAmount;
713
+
714
+ // return if reward amount is zero
715
+ if (restakeAmount.eqz()) {
716
+ return restakeAmount;
717
+ }
718
+
719
+ // check restaking amount does not exceed target max staked amount
720
+ _checkMaxStakedAmount(stakeInfo.targetNftId, targetInfo, restakeAmount);
721
+
722
+ // use up reserves for newly staked dips
723
+ _spendRewardReserves(stakeInfo.targetNftId, targetInfo, restakeAmount);
724
+
725
+ // update target + stake
726
+ targetInfo.stakedAmount = targetInfo.stakedAmount + restakeAmount;
727
+ targetInfo.rewardAmount = targetInfo.rewardAmount - restakeAmount;
728
+ stakeInfo.stakedAmount = stakeInfo.stakedAmount + restakeAmount;
729
+ stakeInfo.rewardAmount = AmountLib.zero();
730
+ _setLastUpdatesToCurrent(stakeInfo, targetInfo);
731
+
732
+ // logging
733
+ emit IStaking.LogStakingRewardsRestaked(
734
+ stakeNftId,
735
+ restakeAmount,
736
+ stakeInfo.stakedAmount,
737
+ AmountLib.zero(),
738
+ stakeInfo.lockedUntil);
739
+ }
740
+
741
+
742
+ function _stake(
743
+ NftId stakeNftId,
744
+ IStaking.StakeInfo storage stakeInfo,
745
+ IStaking.TargetInfo storage targetInfo,
746
+ Seconds maxAdditionalLockingPeriod,
747
+ Amount stakeAmount
748
+ )
749
+ internal
527
750
  {
528
- if (_lastUpdatedIn[nftId].gtz()) {
529
- revert ErrorStakingStoreBalanceAlreadyInitialized(nftId);
751
+ // return if reward amount is zero
752
+ if (stakeAmount.eqz()) {
753
+ return;
530
754
  }
531
755
 
532
- // set stake balances to 0
533
- _stakeBalance[nftId] = AmountLib.zero();
534
- _rewardBalance[nftId] = AmountLib.zero();
756
+ // check restaking amount does not exceed target max staked amount
757
+ _checkMaxStakedAmount(stakeInfo.targetNftId, targetInfo, stakeAmount);
758
+
759
+ // update target + stake
760
+ targetInfo.stakedAmount = targetInfo.stakedAmount + stakeAmount;
761
+ stakeInfo.stakedAmount = stakeInfo.stakedAmount + stakeAmount;
535
762
 
536
- // set last updated at/in to current timestamp/block number
537
- _lastUpdatedAt[nftId] = TimestampLib.blockTimestamp();
538
- _lastUpdatedIn[nftId] = BlocknumberLib.currentBlocknumber();
763
+ // increase locked until if applicable
764
+ Seconds additionalLockingPeriod = SecondsLib.min(maxAdditionalLockingPeriod, targetInfo.lockingPeriod);
765
+ if (stakeAmount.gtz() && additionalLockingPeriod.gtz()) {
766
+ stakeInfo.lockedUntil = stakeInfo.lockedUntil.addSeconds(additionalLockingPeriod);
767
+ }
768
+
769
+ _setLastUpdatesToCurrent(stakeInfo, targetInfo);
770
+
771
+ // logging
772
+ emit IStaking.LogStakingStaked(
773
+ stakeNftId,
774
+ stakeAmount,
775
+ stakeInfo.stakedAmount,
776
+ stakeInfo.rewardAmount,
777
+ stakeInfo.lockedUntil);
539
778
  }
540
779
 
541
780
 
542
- function _updateStakeBalance(
781
+ function _claimRewards(
543
782
  NftId stakeNftId,
544
- Amount newStakeAmount,
545
- Amount newRewardAmount
783
+ IStaking.StakeInfo storage stakeInfo,
784
+ IStaking.TargetInfo storage targetInfo,
785
+ Amount maxClaimAmount
546
786
  )
547
- private
787
+ internal
788
+ returns (Amount claimAmount)
548
789
  {
549
- _stakeBalance[stakeNftId] = newStakeAmount;
550
- _rewardBalance[stakeNftId] = newRewardAmount;
790
+ claimAmount = AmountLib.min(maxClaimAmount, stakeInfo.rewardAmount);
551
791
 
552
- _lastUpdatedAt[stakeNftId] = TimestampLib.blockTimestamp();
553
- _lastUpdatedIn[stakeNftId] = BlocknumberLib.currentBlocknumber();
792
+ // return if no rewards to claim
793
+ if (claimAmount.eqz()) {
794
+ return claimAmount;
795
+ }
796
+
797
+ // effects
798
+ // use up reserves for claimed rewards
799
+ _spendRewardReserves(stakeInfo.targetNftId, targetInfo, claimAmount);
800
+
801
+ // update target + stake
802
+ targetInfo.rewardAmount = targetInfo.rewardAmount - claimAmount;
803
+ stakeInfo.rewardAmount = stakeInfo.rewardAmount - claimAmount;
804
+ _setLastUpdatesToCurrent(stakeInfo, targetInfo);
805
+
806
+ // logging
807
+ emit IStaking.LogStakingRewardsClaimed(
808
+ stakeNftId,
809
+ claimAmount,
810
+ stakeInfo.stakedAmount,
811
+ stakeInfo.rewardAmount,
812
+ stakeInfo.lockedUntil);
554
813
  }
555
814
 
556
815
 
557
- function _updateTargetBalance(
558
- NftId targetNftId,
559
- Amount newStakeAmount,
560
- Amount newRewardAmount
816
+ function _unstake(
817
+ NftId stakeNftId,
818
+ IStaking.StakeInfo storage stakeInfo,
819
+ IStaking.TargetInfo storage targetInfo,
820
+ Amount maxUnstakeAmount
561
821
  )
562
- private
822
+ internal
823
+ returns (Amount unstakedAmount)
563
824
  {
564
- _stakeBalance[targetNftId] = newStakeAmount;
565
- _rewardBalance[targetNftId] = newRewardAmount;
825
+ unstakedAmount = AmountLib.min(maxUnstakeAmount, stakeInfo.stakedAmount);
826
+
827
+ // return if no stakes to claim
828
+ if (unstakedAmount.eqz()) {
829
+ return unstakedAmount;
830
+ }
831
+
832
+ // check if stake is still locked
833
+ if (isStakeLocked(stakeNftId)) {
834
+ revert IStaking.ErrorStakingStakeLocked(stakeNftId, stakeInfo.lockedUntil);
835
+ }
566
836
 
567
- // for targets we don't need the timestamp, just the blocknumber
568
- _lastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
837
+ // update target + stake
838
+ targetInfo.stakedAmount = targetInfo.stakedAmount - unstakedAmount;
839
+ stakeInfo.stakedAmount = stakeInfo.stakedAmount - unstakedAmount;
840
+ _setLastUpdatesToCurrent(stakeInfo, targetInfo);
841
+
842
+ // logging
843
+ emit IStaking.LogStakingUnstaked(
844
+ stakeNftId,
845
+ unstakedAmount,
846
+ stakeInfo.stakedAmount,
847
+ stakeInfo.rewardAmount,
848
+ stakeInfo.lockedUntil);
569
849
  }
570
850
 
571
- function _checkBalanceExists(NftId nftId)
851
+
852
+ function _setLastUpdatesToCurrent(
853
+ IStaking.StakeInfo storage stakeInfo,
854
+ IStaking.TargetInfo storage targetInfo
855
+ )
856
+ internal
857
+ {
858
+ targetInfo.lastUpdateIn = BlocknumberLib.current();
859
+ _setStakeLastUpdatesToCurrent(stakeInfo);
860
+ }
861
+
862
+
863
+ function _setStakeLastUpdatesToCurrent(
864
+ IStaking.StakeInfo storage stakeInfo
865
+ )
866
+ internal
867
+ {
868
+ stakeInfo.lastUpdateIn = BlocknumberLib.current();
869
+ stakeInfo.lastUpdateAt = TimestampLib.current();
870
+ }
871
+
872
+ //--- private stake and target functions --------------------------------//
873
+
874
+
875
+ function _getAndVerifyStake(
876
+ NftId stakeNftId
877
+ )
572
878
  private
573
879
  view
574
- returns (Blocknumber lastUpdatedIn)
880
+ returns (
881
+ IStaking.StakeInfo storage stakeInfo
882
+ )
575
883
  {
576
- lastUpdatedIn = _lastUpdatedIn[nftId];
884
+ stakeInfo = _stakeInfo[stakeNftId];
885
+ if (stakeInfo.lastUpdateIn.eqz()) {
886
+ revert ErrorStakingStoreStakeNotInitialized(stakeNftId);
887
+ }
888
+ }
577
889
 
578
- if (lastUpdatedIn.eqz()) {
579
- revert ErrorStakingStoreBalanceNotInitialized(nftId);
890
+
891
+ function _checkMaxStakedAmount(
892
+ NftId targetNftId,
893
+ IStaking.TargetInfo storage targetInfo,
894
+ Amount additionalstakedAmount
895
+ )
896
+ private
897
+ {
898
+ if (targetInfo.stakedAmount + additionalstakedAmount > targetInfo.maxStakedAmount) {
899
+ revert IStaking.ErrorStakingTargetMaxStakedAmountExceeded(
900
+ targetNftId,
901
+ targetInfo.maxStakedAmount,
902
+ targetInfo.stakedAmount + additionalstakedAmount);
580
903
  }
904
+
905
+ // TODO add check for tvl dependent maximum, see #628
581
906
  }
582
907
 
583
908
 
584
- function _getAndVerifyTvl(
585
- NftId targetNftId,
586
- address token
909
+ function _getAndVerifyTarget(
910
+ NftId targetNftId
587
911
  )
588
912
  private
589
913
  view
590
914
  returns (
591
- Blocknumber tvlLastUpdatedIn,
592
- Amount oldBalance,
593
- Amount oldDipBalance
915
+ IStaking.TargetInfo storage targetInfo
594
916
  )
595
917
  {
596
- tvlLastUpdatedIn = _tvlLastUpdatedIn[targetNftId];
918
+ targetInfo = _targetInfo[targetNftId];
597
919
 
598
- if (tvlLastUpdatedIn.eqz()) {
599
- revert ErrorStakingStoreTvlBalanceNotInitialized(targetNftId);
920
+ if (targetInfo.lastUpdateIn.eqz()) {
921
+ revert ErrorStakingStoreTargetNotInitialized(targetNftId);
600
922
  }
923
+ }
924
+
925
+ //--- private tvl functions ------------------------------------------------//
926
+
927
+ /// @dev Initializes token balance handling for the specified target.
928
+ function _createTvlBalance(NftId targetNftId, address token)
929
+ private
930
+ {
931
+ IStaking.TvlInfo storage info = _tvlInfo[targetNftId][token];
932
+
933
+ if (info.lastUpdateIn.gtz()) {
934
+ revert ErrorStakingStoreTvlBalanceAlreadyInitialized(targetNftId, token);
935
+ }
936
+
937
+ // set tvl balances to 0 and update last updated in
938
+ info.tvlAmount = AmountLib.zero();
939
+ info.lastUpdateIn = BlocknumberLib.current();
940
+ }
941
+
601
942
 
602
- oldBalance = _tvlBalance[targetNftId][token];
603
- oldDipBalance = _tvlInDip[targetNftId][token];
943
+ function _updateTvlBalance(
944
+ NftId targetNftId,
945
+ address token,
946
+ Amount newTvlAmount
947
+ )
948
+ private
949
+ returns (
950
+ Amount oldTvlAmount,
951
+ Blocknumber lastUpdatedIn
952
+ )
953
+ {
954
+ IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
955
+ oldTvlAmount = tvlInfo.tvlAmount;
956
+ lastUpdatedIn = tvlInfo.lastUpdateIn;
957
+
958
+ tvlInfo.tvlAmount = newTvlAmount;
959
+ tvlInfo.lastUpdateIn = BlocknumberLib.current();
960
+ }
961
+
962
+
963
+ function _getAndVerifyTvl(NftId targetNftId, address token)
964
+ private
965
+ view
966
+ returns (IStaking.TvlInfo storage tvlInfo)
967
+ {
968
+ tvlInfo = _tvlInfo[targetNftId][token];
969
+ if (tvlInfo.lastUpdateIn.eqz()) {
970
+ revert ErrorStakingStoreTvlBalanceNotInitialized(targetNftId, token);
971
+ }
604
972
  }
605
973
  }