@etherisc/gif-next 0.0.2-9e6b423-414 → 0.0.2-9f1b659-471
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.dbg.json +1 -1
- package/artifacts/contracts/accounting/AccountingService.sol/AccountingService.json +86 -34
- package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.dbg.json +1 -1
- package/artifacts/contracts/accounting/AccountingServiceManager.sol/AccountingServiceManager.json +73 -35
- package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.dbg.json +1 -1
- package/artifacts/contracts/accounting/IAccountingService.sol/IAccountingService.json +52 -0
- package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
- package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +2 -2
- package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.dbg.json +1 -1
- package/artifacts/contracts/authorization/AccessAdminLib.sol/AccessAdminLib.json +2 -2
- package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
- package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.json +2 -2
- package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
- package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +2 -2
- package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
- package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
- package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
- package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
- package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +2 -2
- package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
- package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +37 -18
- package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
- package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +2 -2
- package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +19 -0
- package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +311 -151
- package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +112 -86
- package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +19 -0
- package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +199 -15
- package/artifacts/contracts/examples/fire/DamageLevel.sol/DamageLevelLib.dbg.json +1 -1
- package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.dbg.json +1 -1
- package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.json +65 -42
- package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.dbg.json +1 -1
- package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.json +16 -16
- package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.dbg.json +1 -1
- package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.json +79 -44
- package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.dbg.json +1 -1
- package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.json +16 -16
- package/artifacts/contracts/examples/fire/FireUSD.sol/FireUSD.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.json +57 -22
- package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleDistributionAuthorization.sol/SimpleDistributionAuthorization.json +2 -2
- package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.json +27 -8
- package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.json +69 -50
- package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimplePoolAuthorization.sol/SimplePoolAuthorization.json +16 -16
- package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.json +248 -68
- package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.dbg.json +1 -1
- package/artifacts/contracts/examples/unpermissioned/SimpleProductAuthorization.sol/SimpleProductAuthorization.json +16 -16
- package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
- package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +2 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +26 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +96 -4
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +37 -12
- package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +2 -2
- package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +16 -16
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +56 -56
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +118 -26
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +69 -31
- package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +106 -98
- package/artifacts/contracts/instance/RiskSet.sol/RiskSet.dbg.json +1 -1
- package/artifacts/contracts/instance/RiskSet.sol/RiskSet.json +101 -88
- package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +8 -8
- package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
- package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.json +2 -2
- package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +2 -2
- package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ObjectSetHelperLib.sol/ObjectSetHelperLib.json +2 -2
- package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
- package/artifacts/contracts/mock/Dip.sol/Dip.dbg.json +1 -1
- package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
- package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +23 -4
- package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
- package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +2 -2
- package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
- package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
- package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +19 -0
- package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
- package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.json +29 -0
- package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
- package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +19 -0
- package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
- package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +49 -20
- package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
- package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +78 -40
- package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
- package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +37 -26
- package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
- package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +19 -19
- package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
- package/artifacts/contracts/pool/BundleService.sol/BundleService.json +280 -119
- package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
- package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +106 -48
- package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
- package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +180 -27
- package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +19 -0
- package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +220 -1
- package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/pool/Pool.sol/Pool.json +19 -0
- package/artifacts/contracts/pool/PoolLib.sol/PoolLib.dbg.json +1 -1
- package/artifacts/contracts/pool/PoolLib.sol/PoolLib.json +36 -52
- package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/pool/PoolService.sol/PoolService.json +292 -65
- package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +94 -52
- package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
- package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +202 -61
- package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
- package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +75 -33
- package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
- package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.json +19 -0
- package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
- package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +19 -19
- package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
- package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +128 -104
- package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
- package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +95 -65
- package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
- package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.json +166 -1
- package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
- package/artifacts/contracts/product/IClaimService.sol/IClaimService.json +50 -10
- package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
- package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.json +55 -0
- package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
- package/artifacts/contracts/product/IPricingService.sol/IPricingService.json +29 -0
- package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.json +19 -0
- package/artifacts/contracts/product/IRiskService.sol/IRiskService.dbg.json +1 -1
- package/artifacts/contracts/product/IRiskService.sol/IRiskService.json +203 -18
- package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
- package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +109 -46
- package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.dbg.json +1 -1
- package/artifacts/contracts/product/PolicyServiceLib.sol/PolicyServiceLib.json +2 -2
- package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
- package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +91 -49
- package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
- package/artifacts/contracts/product/PricingService.sol/PricingService.json +79 -74
- package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
- package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +82 -40
- package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/product/Product.sol/Product.json +19 -0
- package/artifacts/contracts/product/RiskService.sol/RiskService.dbg.json +1 -1
- package/artifacts/contracts/product/RiskService.sol/RiskService.json +231 -46
- package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.dbg.json +1 -1
- package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.json +70 -32
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +18 -7
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +29 -0
- package/artifacts/contracts/registry/IRelease.sol/IRelease.dbg.json +1 -1
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +56 -45
- package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +2 -2
- package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryAuthorization.sol/RegistryAuthorization.json +29 -21
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +41 -12
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +65 -27
- package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.dbg.json +1 -1
- package/artifacts/contracts/registry/ReleaseAdmin.sol/ReleaseAdmin.json +2 -2
- package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
- package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +81 -81
- package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
- package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +17 -17
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +119 -59
- package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/shared/Component.sol/Component.json +19 -0
- package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
- package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +120 -56
- package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
- package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +96 -50
- package/artifacts/contracts/shared/ContractLib.sol/ContractLib.dbg.json +1 -1
- package/artifacts/contracts/shared/ContractLib.sol/ContractLib.json +9 -9
- package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.dbg.json +1 -1
- package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.dbg.json +1 -1
- package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.dbg.json +1 -1
- package/artifacts/contracts/shared/ContractLib.sol/ITokenRegistryHelper.json +2 -2
- package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/shared/IComponent.sol/IComponent.json +19 -0
- package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
- package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +48 -0
- package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
- package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.json +19 -0
- package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.json +6 -6
- package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +19 -0
- package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +19 -0
- package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.json +29 -0
- package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
- package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.json +19 -0
- package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.json +6 -6
- package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
- package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.json +2 -2
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +21 -2
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
- package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.json +19 -0
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.json +29 -0
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.json +2 -2
- package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.json +2 -2
- package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/IStaking.sol/IStaking.json +1146 -53
- package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
- package/artifacts/contracts/staking/IStakingService.sol/IStakingService.json +91 -111
- package/artifacts/contracts/staking/ITargetManager.sol/ITargetManager.dbg.json +4 -0
- package/artifacts/contracts/staking/ITargetManager.sol/ITargetManager.json +69 -0
- package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
- package/artifacts/contracts/staking/Staking.sol/Staking.json +1392 -181
- package/artifacts/contracts/staking/StakingLib.sol/StakingLib.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingLib.sol/StakingLib.json +73 -72
- package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +138 -56
- package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +174 -180
- package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingService.sol/StakingService.json +115 -167
- package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +68 -46
- package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
- package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +1290 -599
- package/artifacts/contracts/staking/TargetManager.sol/TargetManager.dbg.json +4 -0
- package/artifacts/contracts/staking/TargetManager.sol/TargetManager.json +134 -0
- package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
- package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +72 -32
- package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
- package/artifacts/contracts/type/Amount.sol/AmountLib.json +2 -2
- package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.json +45 -19
- package/artifacts/contracts/type/ChainId.sol/ChainIdLib.dbg.json +4 -0
- package/artifacts/contracts/type/ChainId.sol/ChainIdLib.json +193 -0
- package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.json +2 -2
- package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
- package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.json +2 -2
- package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
- package/artifacts/contracts/type/Fee.sol/FeeLib.json +2 -2
- package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
- package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.dbg.json +1 -1
- package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/NftId.sol/NftIdLib.json +2 -2
- package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.json +2 -2
- package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.json +2 -2
- package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
- package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
- package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/RiskId.sol/RiskIdLib.json +2 -2
- package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
- package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +45 -2
- package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
- package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
- package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
- package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +3 -3
- package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
- package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +2 -2
- package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
- package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.json +10 -0
- package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +55 -17
- package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
- package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
- package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.json +10 -0
- package/contracts/accounting/AccountingService.sol +13 -0
- package/contracts/accounting/IAccountingService.sol +2 -0
- package/contracts/authorization/AccessAdmin.sol +5 -5
- package/contracts/authorization/AccessAdminLib.sol +2 -2
- package/contracts/authorization/Authorization.sol +2 -7
- package/contracts/authorization/IAuthorization.sol +0 -1
- package/contracts/authorization/ServiceAuthorization.sol +2 -2
- package/contracts/distribution/BasicDistribution.sol +2 -2
- package/contracts/distribution/Distribution.sol +5 -3
- package/contracts/distribution/DistributionService.sol +27 -21
- package/contracts/distribution/IDistributionService.sol +10 -4
- package/contracts/examples/fire/FireProduct.sol +6 -6
- package/contracts/examples/unpermissioned/SimpleProduct.sol +83 -19
- package/contracts/instance/IInstance.sol +1 -1
- package/contracts/instance/IInstanceService.sol +7 -3
- package/contracts/instance/Instance.sol +6 -4
- package/contracts/instance/InstanceAuthorizationV3.sol +2 -1
- package/contracts/instance/InstanceService.sol +21 -32
- package/contracts/instance/RiskSet.sol +10 -2
- package/contracts/instance/base/BalanceStore.sol +1 -1
- package/contracts/instance/base/ObjectLifecycle.sol +2 -6
- package/contracts/oracle/BasicOracle.sol +1 -1
- package/contracts/oracle/Oracle.sol +2 -2
- package/contracts/oracle/OracleService.sol +4 -4
- package/contracts/pool/BasicPool.sol +3 -14
- package/contracts/pool/BasicPoolAuthorization.sol +1 -2
- package/contracts/pool/BundleService.sol +34 -43
- package/contracts/pool/IBundleService.sol +14 -13
- package/contracts/pool/IPoolService.sol +7 -2
- package/contracts/pool/Pool.sol +4 -14
- package/contracts/pool/PoolLib.sol +10 -22
- package/contracts/pool/PoolService.sol +35 -8
- package/contracts/product/ApplicationService.sol +58 -9
- package/contracts/product/BasicProduct.sol +1 -1
- package/contracts/product/BasicProductAuthorization.sol +2 -0
- package/contracts/product/ClaimService.sol +39 -40
- package/contracts/product/IApplicationService.sol +21 -2
- package/contracts/product/IClaimService.sol +5 -4
- package/contracts/product/IPolicyService.sol +9 -2
- package/contracts/product/IRiskService.sol +18 -3
- package/contracts/product/PolicyService.sol +13 -8
- package/contracts/product/PolicyServiceLib.sol +7 -7
- package/contracts/product/PricingService.sol +22 -25
- package/contracts/product/Product.sol +38 -12
- package/contracts/product/RiskService.sol +48 -12
- package/contracts/registry/IRegistry.sol +11 -9
- package/contracts/registry/Registry.sol +15 -9
- package/contracts/registry/RegistryAuthorization.sol +55 -20
- package/contracts/registry/RegistryService.sol +1 -1
- package/contracts/registry/ReleaseRegistry.sol +8 -3
- package/contracts/registry/ServiceAuthorizationV3.sol +10 -12
- package/contracts/registry/TokenRegistry.sol +52 -49
- package/contracts/shared/Component.sol +6 -2
- package/contracts/shared/ComponentService.sol +15 -6
- package/contracts/shared/ContractLib.sol +3 -2
- package/contracts/shared/IComponent.sol +1 -1
- package/contracts/shared/IComponentService.sol +1 -0
- package/contracts/shared/IKeyValueStore.sol +1 -1
- package/contracts/shared/INftOwnable.sol +2 -0
- package/contracts/shared/InstanceLinkedComponent.sol +4 -4
- package/contracts/shared/KeyValueStore.sol +3 -3
- package/contracts/shared/NftOwnable.sol +2 -0
- package/contracts/shared/PolicyHolder.sol +3 -2
- package/contracts/staking/IStaking.sol +187 -65
- package/contracts/staking/IStakingService.sol +36 -84
- package/contracts/staking/ITargetManager.sol +28 -0
- package/contracts/staking/Staking.sol +458 -210
- package/contracts/staking/StakingLib.sol +38 -124
- package/contracts/staking/StakingManager.sol +1 -2
- package/contracts/staking/StakingReader.sol +45 -74
- package/contracts/staking/StakingService.sol +39 -185
- package/contracts/staking/StakingServiceManager.sol +1 -0
- package/contracts/staking/StakingStore.sol +866 -327
- package/contracts/staking/TargetManager.sol +103 -0
- package/contracts/type/Amount.sol +4 -0
- package/contracts/type/Blocknumber.sol +15 -15
- package/contracts/type/ChainId.sol +101 -0
- package/contracts/type/NftId.sol +3 -3
- package/contracts/type/Seconds.sol +14 -0
- package/contracts/type/Timestamp.sol +4 -2
- package/contracts/type/UFixed.sol +1 -0
- package/contracts/upgradeability/IVersionable.sol +3 -0
- package/contracts/upgradeability/ProxyManager.sol +13 -1
- package/contracts/upgradeability/UpgradableProxyWithAdmin.sol +6 -2
- package/contracts/upgradeability/Versionable.sol +2 -2
- package/package.json +1 -1
- package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +0 -4
- package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.json +0 -485
- package/contracts/shared/ComponentVerifyingService.sol +0 -128
@@ -5,19 +5,23 @@ import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManage
|
|
5
5
|
|
6
6
|
import {IRegistry} from "../registry/IRegistry.sol";
|
7
7
|
import {IStaking} from "./IStaking.sol";
|
8
|
+
import {ITargetManager} from "./ITargetManager.sol";
|
8
9
|
|
9
10
|
import {Amount, AmountLib} from "../type/Amount.sol";
|
11
|
+
import {ChainId, ChainIdLib} from "../type/ChainId.sol";
|
10
12
|
import {Blocknumber, BlocknumberLib} from "../type/Blocknumber.sol";
|
11
13
|
import {KeyValueStore} from "../shared/KeyValueStore.sol";
|
12
|
-
import {KEEP_STATE} from "../type/StateId.sol";
|
13
14
|
import {NftId, NftIdLib} from "../type/NftId.sol";
|
14
15
|
import {NftIdSet} from "../shared/NftIdSet.sol";
|
15
|
-
import {
|
16
|
+
import {ObjectType} from "../type/ObjectType.sol";
|
17
|
+
import {PROTOCOL} from "../type/ObjectType.sol";
|
18
|
+
import {Seconds, SecondsLib} from "../type/Seconds.sol";
|
19
|
+
import {StakingLib} from "./StakingLib.sol";
|
20
|
+
import {StakingLifecycle} from "./StakingLifecycle.sol";
|
16
21
|
import {StakingReader} from "./StakingReader.sol";
|
17
22
|
import {TargetManagerLib} from "./TargetManagerLib.sol";
|
18
23
|
import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
|
19
|
-
import {
|
20
|
-
import {UFixed} from "../type/UFixed.sol";
|
24
|
+
import {UFixed, UFixedLib} from "../type/UFixed.sol";
|
21
25
|
|
22
26
|
|
23
27
|
contract StakingStore is
|
@@ -26,116 +30,290 @@ contract StakingStore is
|
|
26
30
|
StakingLifecycle
|
27
31
|
{
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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);
|
33
|
+
// token
|
34
|
+
error ErrorStakingStoreTokenNotRegistered(ChainId chainId, address token);
|
35
|
+
error ErrorStakingStoreTokenAlreadyAdded(ChainId chainId, address token);
|
36
|
+
error ErrorStakingStoreTokenUnknown(ChainId chainId, address token);
|
40
37
|
|
41
|
-
|
38
|
+
// target
|
39
|
+
error ErrorStakingStoreTargetNotInitialized(NftId targetNftId);
|
40
|
+
error ErrorStakingStoreLimitNotInitialized(NftId targetNftId);
|
42
41
|
|
43
42
|
// in/decreasing reward reserves
|
44
43
|
error ErrorStakingStoreNotTarget(NftId targetNftId);
|
45
|
-
error ErrorStakingStoreRewardReservesInsufficient(NftId targetNftId, Amount
|
44
|
+
error ErrorStakingStoreRewardReservesInsufficient(NftId targetNftId, Amount reserveAmount, Amount claimedAmount);
|
46
45
|
|
47
|
-
//
|
48
|
-
error
|
49
|
-
error
|
46
|
+
// stakes
|
47
|
+
error ErrorStakingStoreStakesExceedingTargetMaxAmount(NftId targetNftId, Amount stakeLimitAmount, Amount newIStaking);
|
48
|
+
error ErrorStakingStoreStakeNotInitialized(NftId nftId);
|
50
49
|
|
51
|
-
//
|
52
|
-
error
|
50
|
+
// creating and updating of staking balance
|
51
|
+
error ErrorStakingStoreStakeBalanceAlreadyInitialized(NftId nftId);
|
52
|
+
error ErrorStakingStoreStakeBalanceNotInitialized(NftId nftI);
|
53
|
+
|
54
|
+
// creating and updating of tvl balance
|
55
|
+
error ErrorStakingStoreTvlBalanceAlreadyInitialized(NftId nftId, address token);
|
56
|
+
error ErrorStakingStoreTvlBalanceNotInitialized(NftId nftId, address token);
|
53
57
|
|
54
58
|
IRegistry private _registry;
|
55
|
-
|
59
|
+
ITargetManager private _targetManager;
|
56
60
|
StakingReader private _reader;
|
61
|
+
NftIdSet private _targetNftIdSet;
|
57
62
|
|
58
|
-
// staking rate
|
59
|
-
mapping(uint256 chainId => mapping(address token => UFixed stakingRate)) private _stakingRate;
|
60
63
|
|
61
|
-
//
|
62
|
-
mapping(NftId
|
63
|
-
mapping(NftId nftId => Amount rewards) private _rewardBalance;
|
64
|
-
mapping(NftId nftId => Amount reserves) private _reserveBalance;
|
64
|
+
// stakes
|
65
|
+
mapping(NftId stakeNftId => IStaking.StakeInfo) private _stakeInfo;
|
65
66
|
|
66
|
-
|
67
|
-
mapping(NftId
|
67
|
+
// targets
|
68
|
+
mapping(NftId targetNftId => IStaking.TargetInfo) private _targetInfo;
|
69
|
+
mapping(NftId targetNftId => IStaking.LimitInfo) private _limitInfo;
|
70
|
+
mapping(NftId targetNftId => mapping(address token => IStaking.TvlInfo)) private _tvlInfo;
|
71
|
+
mapping(NftId targetNftId => address [] token) private _targetToken;
|
68
72
|
|
69
|
-
//
|
70
|
-
mapping(
|
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;
|
73
|
+
// staking rate
|
74
|
+
mapping(ChainId chainId => mapping(address token => IStaking.TokenInfo)) private _tokenInfo;
|
74
75
|
|
75
76
|
|
76
|
-
constructor(
|
77
|
+
constructor(
|
78
|
+
IRegistry registry,
|
79
|
+
StakingReader reader
|
80
|
+
)
|
77
81
|
AccessManaged(msg.sender)
|
78
82
|
{
|
79
83
|
// set final authority
|
80
84
|
setAuthority(registry.getAuthority());
|
81
85
|
|
82
86
|
// set internal variables
|
83
|
-
_registry = registry;
|
87
|
+
_registry = registry;
|
84
88
|
_reader = reader;
|
85
89
|
_targetNftIdSet = new NftIdSet();
|
86
90
|
|
87
91
|
// register protocol target
|
88
92
|
_createTarget(
|
89
93
|
NftIdLib.toNftId(1101),
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
PROTOCOL(),
|
95
|
+
TargetManagerLib.getDefaultLockingPeriod(),
|
96
|
+
TargetManagerLib.getDefaultRewardRate(),
|
97
|
+
false); // no parameter check
|
98
|
+
}
|
99
|
+
|
100
|
+
//--- dependency management ---------------------------------------------//
|
101
|
+
|
102
|
+
function setStakingReader(address reader)
|
103
|
+
external
|
104
|
+
restricted()
|
105
|
+
{
|
106
|
+
address oldReader = address(_reader);
|
107
|
+
_reader = StakingReader(reader);
|
108
|
+
|
109
|
+
emit IStaking.LogStakingStakingReaderSet(reader, oldReader);
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
function setTargetManager(address targetManager)
|
114
|
+
external
|
115
|
+
restricted()
|
116
|
+
{
|
117
|
+
address oldTargetManager = address(_targetManager);
|
118
|
+
_targetManager = ITargetManager(targetManager);
|
119
|
+
|
120
|
+
emit IStaking.LogStakingTargetManagerSet(targetManager, oldTargetManager);
|
96
121
|
}
|
97
122
|
|
123
|
+
//--- token management --------------------------------------------------//
|
124
|
+
|
125
|
+
/// @dev Registers a token for tvl management.
|
126
|
+
function addToken(
|
127
|
+
ChainId chainId,
|
128
|
+
address token
|
129
|
+
)
|
130
|
+
external
|
131
|
+
restricted() // token registry via staking
|
132
|
+
{
|
133
|
+
// checks
|
134
|
+
IStaking.TokenInfo storage info = _tokenInfo[chainId][token];
|
135
|
+
|
136
|
+
// check token is not yet registered
|
137
|
+
if (info.lastUpdateIn.gtz()) {
|
138
|
+
revert ErrorStakingStoreTokenAlreadyAdded(chainId, token);
|
139
|
+
}
|
140
|
+
|
141
|
+
info.stakingRate = UFixedLib.zero();
|
142
|
+
info.lastUpdateIn = BlocknumberLib.current();
|
143
|
+
|
144
|
+
// logging
|
145
|
+
emit IStaking.LogStakingTokenAdded(chainId, token);
|
146
|
+
}
|
98
147
|
|
99
|
-
//--- staking rate specific functions -----------------------------------//
|
100
148
|
|
149
|
+
/// @dev Sets the staking rate for the token.
|
101
150
|
function setStakingRate(
|
102
|
-
|
151
|
+
ChainId chainId,
|
103
152
|
address token,
|
104
153
|
UFixed stakingRate
|
105
154
|
)
|
106
155
|
external
|
107
|
-
restricted()
|
156
|
+
restricted() // staking
|
157
|
+
returns (
|
158
|
+
UFixed oldStakingRate,
|
159
|
+
Blocknumber lastUpdatedIn
|
160
|
+
)
|
108
161
|
{
|
109
|
-
|
162
|
+
IStaking.TokenInfo storage info = _tokenInfo[chainId][token];
|
163
|
+
if (info.lastUpdateIn.eqz()) {
|
164
|
+
revert ErrorStakingStoreTokenUnknown(chainId, token);
|
165
|
+
}
|
166
|
+
|
167
|
+
// get previous values
|
168
|
+
oldStakingRate = info.stakingRate;
|
169
|
+
lastUpdatedIn = info.lastUpdateIn;
|
170
|
+
|
171
|
+
// update values
|
172
|
+
info.stakingRate = stakingRate;
|
173
|
+
info.lastUpdateIn = BlocknumberLib.current();
|
110
174
|
}
|
111
175
|
|
112
|
-
//--- target
|
176
|
+
//--- target management -------------------------------------------------//
|
113
177
|
|
114
178
|
function createTarget(
|
115
179
|
NftId targetNftId,
|
116
|
-
|
180
|
+
ObjectType objectType,
|
181
|
+
Seconds lockingPeriod,
|
182
|
+
UFixed rewardRate
|
117
183
|
)
|
118
184
|
external
|
119
|
-
restricted()
|
185
|
+
restricted() // staking
|
186
|
+
{
|
187
|
+
_createTarget(targetNftId, objectType, lockingPeriod, rewardRate, true);
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
function setLockingPeriod(
|
192
|
+
NftId targetNftId,
|
193
|
+
Seconds lockingPeriod
|
194
|
+
)
|
195
|
+
external
|
196
|
+
restricted() // staking
|
197
|
+
returns (
|
198
|
+
Seconds oldLockingPeriod,
|
199
|
+
Blocknumber lastUpdatedIn
|
200
|
+
)
|
201
|
+
{
|
202
|
+
TargetManagerLib.checkLockingPeriod(targetNftId, lockingPeriod);
|
203
|
+
|
204
|
+
IStaking.TargetInfo storage targetInfo;
|
205
|
+
(targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
|
206
|
+
|
207
|
+
oldLockingPeriod = targetInfo.lockingPeriod;
|
208
|
+
targetInfo.lockingPeriod = lockingPeriod;
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
function setRewardRate(
|
213
|
+
NftId targetNftId,
|
214
|
+
UFixed rewardRate
|
215
|
+
)
|
216
|
+
external
|
217
|
+
restricted() // staking
|
218
|
+
returns (
|
219
|
+
UFixed oldRewardRate,
|
220
|
+
Blocknumber lastUpdatedIn
|
221
|
+
)
|
222
|
+
{
|
223
|
+
TargetManagerLib.checkRewardRate(targetNftId, rewardRate);
|
224
|
+
|
225
|
+
IStaking.TargetInfo storage targetInfo;
|
226
|
+
(targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
|
227
|
+
|
228
|
+
oldRewardRate = targetInfo.rewardRate;
|
229
|
+
targetInfo.rewardRate = rewardRate;
|
230
|
+
}
|
231
|
+
|
232
|
+
|
233
|
+
// TODO refactor to set limits functionality
|
234
|
+
function setMaxStakedAmount(
|
235
|
+
NftId targetNftId,
|
236
|
+
Amount stakeLimitAmount
|
237
|
+
)
|
238
|
+
external
|
239
|
+
restricted() // staking
|
240
|
+
returns (
|
241
|
+
Amount oldLimitAmount,
|
242
|
+
Blocknumber lastUpdatedIn
|
243
|
+
)
|
120
244
|
{
|
121
|
-
|
245
|
+
IStaking.TargetInfo storage targetInfo;
|
246
|
+
(targetInfo, lastUpdatedIn) = _verifyAndUpdateTarget(targetNftId);
|
247
|
+
|
248
|
+
oldLimitAmount = targetInfo.limitAmount;
|
249
|
+
targetInfo.limitAmount = stakeLimitAmount;
|
250
|
+
|
251
|
+
emit IStaking.LogStakingTargetMaxStakedAmountSet(targetNftId, stakeLimitAmount, lastUpdatedIn);
|
252
|
+
|
122
253
|
}
|
123
254
|
|
124
255
|
|
125
|
-
function
|
256
|
+
function setTargetLimits(
|
126
257
|
NftId targetNftId,
|
127
|
-
|
258
|
+
Amount marginAmount,
|
259
|
+
Amount hardLimitAmount
|
128
260
|
)
|
129
261
|
external
|
262
|
+
virtual
|
130
263
|
restricted()
|
131
264
|
{
|
132
|
-
|
133
|
-
|
134
|
-
|
265
|
+
// checks
|
266
|
+
IStaking.LimitInfo storage limitInfo = _getAndVerifyLimit(targetNftId);
|
267
|
+
Blocknumber lastUpdateIn = limitInfo.lastUpdateIn;
|
268
|
+
|
269
|
+
// effects
|
270
|
+
limitInfo.marginAmount = marginAmount;
|
271
|
+
limitInfo.hardLimitAmount = hardLimitAmount;
|
272
|
+
limitInfo.lastUpdateIn = BlocknumberLib.current();
|
273
|
+
|
274
|
+
// logging
|
275
|
+
emit IStaking.LogStakingTargetLimitsUpdated(
|
276
|
+
targetNftId,
|
277
|
+
marginAmount,
|
278
|
+
hardLimitAmount,
|
279
|
+
lastUpdateIn);
|
280
|
+
}
|
281
|
+
|
282
|
+
|
283
|
+
function addTargetToken(
|
284
|
+
NftId targetNftId,
|
285
|
+
address token
|
286
|
+
)
|
287
|
+
external
|
288
|
+
restricted()
|
289
|
+
{
|
290
|
+
// checks
|
291
|
+
|
292
|
+
// skip registering if tvl balance has already been initialized
|
293
|
+
IStaking.TvlInfo storage tvlInfo = _tvlInfo[targetNftId][token];
|
294
|
+
if (tvlInfo.lastUpdateIn.gtz()) {
|
295
|
+
return;
|
296
|
+
}
|
297
|
+
|
298
|
+
// check target exists
|
299
|
+
_getAndVerifyTarget(targetNftId);
|
300
|
+
|
301
|
+
// check token is known for chain id of target
|
302
|
+
ChainId chainId = ChainIdLib.fromNftId(targetNftId);
|
303
|
+
if (_tokenInfo[chainId][token].lastUpdateIn.eqz()) {
|
304
|
+
revert ErrorStakingStoreTokenUnknown(chainId, token);
|
305
|
+
}
|
306
|
+
|
307
|
+
// effects
|
308
|
+
tvlInfo.tvlAmount = AmountLib.zero();
|
309
|
+
tvlInfo.lastUpdateIn = BlocknumberLib.current();
|
310
|
+
|
311
|
+
// add token to list of know tokens for target
|
312
|
+
_targetToken[targetNftId].push(token);
|
135
313
|
}
|
136
314
|
|
137
315
|
|
138
|
-
function
|
316
|
+
function refillRewardReserves(
|
139
317
|
NftId targetNftId,
|
140
318
|
Amount dipAmount
|
141
319
|
)
|
@@ -143,14 +321,26 @@ contract StakingStore is
|
|
143
321
|
restricted()
|
144
322
|
returns (Amount newReserveBalance)
|
145
323
|
{
|
146
|
-
|
147
|
-
|
324
|
+
// checks
|
325
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
|
326
|
+
Blocknumber lastUpdateIn = targetInfo.lastUpdateIn;
|
327
|
+
|
328
|
+
// effects
|
329
|
+
targetInfo.reserveAmount = targetInfo.reserveAmount + dipAmount;
|
330
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
148
331
|
|
149
|
-
|
332
|
+
// logging
|
333
|
+
newReserveBalance = targetInfo.reserveAmount;
|
334
|
+
emit IStaking.LogStakingRewardReservesRefilled(
|
335
|
+
targetNftId,
|
336
|
+
dipAmount,
|
337
|
+
_registry.ownerOf(targetNftId),
|
338
|
+
newReserveBalance,
|
339
|
+
lastUpdateIn);
|
150
340
|
}
|
151
341
|
|
152
342
|
|
153
|
-
function
|
343
|
+
function withdrawRewardReserves(
|
154
344
|
NftId targetNftId,
|
155
345
|
Amount dipAmount
|
156
346
|
)
|
@@ -158,18 +348,20 @@ contract StakingStore is
|
|
158
348
|
restricted()
|
159
349
|
returns (Amount newReserveBalance)
|
160
350
|
{
|
161
|
-
|
162
|
-
|
163
|
-
revert ErrorStakingStoreRewardReservesInsufficient(
|
164
|
-
targetNftId,
|
165
|
-
dipAmount,
|
166
|
-
reserveAmount);
|
167
|
-
}
|
351
|
+
// checks
|
352
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
|
168
353
|
|
169
|
-
|
170
|
-
Blocknumber
|
354
|
+
// effects
|
355
|
+
Blocknumber lastUpdateIn = _decreaseReserves(targetNftId, targetInfo, dipAmount);
|
171
356
|
|
172
|
-
|
357
|
+
// logging
|
358
|
+
newReserveBalance = targetInfo.reserveAmount;
|
359
|
+
emit IStaking.LogStakingRewardReservesWithdrawn(
|
360
|
+
targetNftId,
|
361
|
+
dipAmount,
|
362
|
+
_registry.ownerOf(targetNftId),
|
363
|
+
newReserveBalance,
|
364
|
+
lastUpdateIn);
|
173
365
|
}
|
174
366
|
|
175
367
|
|
@@ -177,7 +369,6 @@ contract StakingStore is
|
|
177
369
|
|
178
370
|
function increaseTotalValueLocked(
|
179
371
|
NftId targetNftId,
|
180
|
-
UFixed stakingRate,
|
181
372
|
address token,
|
182
373
|
Amount amount
|
183
374
|
)
|
@@ -185,32 +376,20 @@ contract StakingStore is
|
|
185
376
|
restricted()
|
186
377
|
returns (Amount newBalance)
|
187
378
|
{
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
// update new tvl balances
|
198
|
-
_tvlBalance[targetNftId][token] = newBalance;
|
199
|
-
_tvlInDip[targetNftId][token] = newDipBalance;
|
200
|
-
|
201
|
-
// update new amount of required dip
|
202
|
-
_tvlRequiredDip[targetNftId] = _tvlRequiredDip[targetNftId] - oldDipBalance + newDipBalance;
|
203
|
-
|
204
|
-
// update last updated in
|
205
|
-
_tvlLastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
|
206
|
-
|
207
|
-
emit LogStakingStoreTotalValueLockedIncreased(targetNftId, token, amount, newBalance, tvlLastUpdatedIn);
|
379
|
+
// checks
|
380
|
+
IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
|
381
|
+
|
382
|
+
// effects
|
383
|
+
// update tvl balance and adapts required stakes if necessary
|
384
|
+
tvlInfo.tvlAmount = tvlInfo.tvlAmount + amount;
|
385
|
+
_checkAndUpdateTargetLimit(targetNftId, token, tvlInfo);
|
386
|
+
tvlInfo.lastUpdateIn = BlocknumberLib.current();
|
387
|
+
newBalance = tvlInfo.tvlAmount;
|
208
388
|
}
|
209
389
|
|
210
390
|
|
211
391
|
function decreaseTotalValueLocked(
|
212
392
|
NftId targetNftId,
|
213
|
-
UFixed stakingRate,
|
214
393
|
address token,
|
215
394
|
Amount amount
|
216
395
|
)
|
@@ -218,389 +397,749 @@ contract StakingStore is
|
|
218
397
|
restricted()
|
219
398
|
returns (Amount newBalance)
|
220
399
|
{
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
400
|
+
// checks
|
401
|
+
IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
|
402
|
+
|
403
|
+
// effects
|
404
|
+
// update tvl balance and adapts required stakes if necessary
|
405
|
+
tvlInfo.tvlAmount = tvlInfo.tvlAmount - amount;
|
406
|
+
_checkAndUpdateTargetLimit(targetNftId, token, tvlInfo);
|
407
|
+
tvlInfo.lastUpdateIn = BlocknumberLib.current();
|
408
|
+
newBalance = tvlInfo.tvlAmount;
|
409
|
+
}
|
410
|
+
|
226
411
|
|
227
|
-
|
228
|
-
|
229
|
-
|
412
|
+
function updateTargetLimit(NftId targetNftId)
|
413
|
+
external
|
414
|
+
restricted()
|
415
|
+
returns (Amount stakeLimitAmount)
|
416
|
+
{
|
417
|
+
return _updateTargetLimit(targetNftId);
|
418
|
+
}
|
230
419
|
|
231
|
-
// update new tvl balances
|
232
|
-
_tvlBalance[targetNftId][token] = newBalance;
|
233
|
-
_tvlInDip[targetNftId][token] = newDipBalance;
|
234
420
|
|
235
|
-
|
236
|
-
|
421
|
+
function _checkAndUpdateTargetLimit(
|
422
|
+
NftId targetNftId,
|
423
|
+
address token,
|
424
|
+
IStaking.TvlInfo storage tvlInfo
|
425
|
+
)
|
426
|
+
internal
|
427
|
+
{
|
428
|
+
// update counter
|
429
|
+
tvlInfo.updatesCounter++;
|
430
|
+
|
431
|
+
// check if upgrade is necessary
|
432
|
+
bool updateRequired = _targetManager.isLimitUpdateRequired(
|
433
|
+
targetNftId,
|
434
|
+
token,
|
435
|
+
tvlInfo.updatesCounter,
|
436
|
+
tvlInfo.tvlBaselineAmount,
|
437
|
+
tvlInfo.tvlAmount);
|
438
|
+
|
439
|
+
if (updateRequired) {
|
440
|
+
// reset baseline and counter
|
441
|
+
tvlInfo.tvlBaselineAmount = tvlInfo.tvlAmount;
|
442
|
+
tvlInfo.updatesCounter = 0;
|
443
|
+
|
444
|
+
// update limit
|
445
|
+
_updateTargetLimit(targetNftId);
|
446
|
+
}
|
447
|
+
}
|
237
448
|
|
238
|
-
// update last updated in
|
239
|
-
_tvlLastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
|
240
449
|
|
241
|
-
|
450
|
+
function _updateTargetLimit(NftId targetNftId)
|
451
|
+
internal
|
452
|
+
returns (Amount limitAmount)
|
453
|
+
{
|
454
|
+
// checks
|
455
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
|
456
|
+
IStaking.LimitInfo storage limitInfo = _getAndVerifyLimit(targetNftId);
|
457
|
+
Blocknumber lastUpdateIn = limitInfo.lastUpdateIn;
|
458
|
+
|
459
|
+
// calculate max stake amount
|
460
|
+
Amount requiredStakeAmount = getRequiredStakeBalance(targetNftId);
|
461
|
+
limitAmount = AmountLib.min(
|
462
|
+
targetInfo.limitAmount,
|
463
|
+
requiredStakeAmount + limitInfo.marginAmount);
|
464
|
+
|
465
|
+
limitAmount = AmountLib.min(
|
466
|
+
limitAmount,
|
467
|
+
limitInfo.hardLimitAmount);
|
468
|
+
|
469
|
+
// effects
|
470
|
+
targetInfo.limitAmount = limitAmount;
|
471
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
472
|
+
|
473
|
+
// logging
|
474
|
+
emit IStaking.LogStakingTargetLimitUpdated(
|
475
|
+
targetNftId,
|
476
|
+
targetInfo.limitAmount,
|
477
|
+
limitInfo.hardLimitAmount,
|
478
|
+
requiredStakeAmount,
|
479
|
+
targetInfo.stakedAmount,
|
480
|
+
lastUpdateIn);
|
242
481
|
}
|
243
482
|
|
244
483
|
//--- stake specific functions -------------------------------------//
|
245
484
|
|
246
|
-
function
|
485
|
+
function createStake(
|
247
486
|
NftId stakeNftId,
|
248
|
-
|
487
|
+
NftId targetNftId,
|
488
|
+
address stakeOwner,
|
489
|
+
Amount stakeAmount
|
249
490
|
)
|
250
491
|
external
|
251
492
|
restricted()
|
493
|
+
returns (Timestamp lockedUntil)
|
252
494
|
{
|
253
|
-
|
254
|
-
|
255
|
-
|
495
|
+
// checks
|
496
|
+
IStaking.StakeInfo storage stakeInfo = _stakeInfo[stakeNftId];
|
497
|
+
if (stakeInfo.lastUpdateIn.gtz()) {
|
498
|
+
revert ErrorStakingStoreStakeBalanceAlreadyInitialized(stakeNftId);
|
499
|
+
}
|
500
|
+
|
501
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(targetNftId);
|
502
|
+
_checkMaxStakedAmount(targetNftId, targetInfo, stakeAmount);
|
503
|
+
|
504
|
+
// effects
|
505
|
+
stakeInfo.targetNftId = targetNftId;
|
506
|
+
stakeInfo.stakedAmount = AmountLib.zero();
|
507
|
+
stakeInfo.rewardAmount = AmountLib.zero();
|
508
|
+
stakeInfo.lockedUntil = TimestampLib.current();
|
509
|
+
_setStakeLastUpdatesToCurrent(stakeInfo);
|
256
510
|
|
257
|
-
|
511
|
+
// logging for creation of empty stake
|
512
|
+
emit IStaking.LogStakingStakeCreated(stakeNftId, stakeInfo.targetNftId, stakeInfo.stakedAmount, stakeInfo.lockedUntil, stakeOwner);
|
513
|
+
|
514
|
+
// process stake amount
|
515
|
+
_stake(stakeNftId, stakeInfo, targetInfo, targetInfo.lockingPeriod, stakeAmount);
|
258
516
|
}
|
259
517
|
|
260
|
-
|
261
|
-
|
262
|
-
|
518
|
+
|
519
|
+
function stake(
|
520
|
+
NftId stakeNftId,
|
521
|
+
bool updateRewards,
|
522
|
+
bool restakeRewards,
|
523
|
+
Seconds additionalLockingPeriod,
|
524
|
+
Amount stakeAmount
|
263
525
|
)
|
264
526
|
external
|
265
527
|
restricted()
|
266
528
|
{
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
529
|
+
// checks
|
530
|
+
IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
|
531
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
|
532
|
+
|
533
|
+
if (updateRewards) {
|
534
|
+
_updateRewards(stakeNftId, stakeInfo, targetInfo);
|
535
|
+
}
|
272
536
|
|
273
|
-
|
537
|
+
if (restakeRewards) {
|
538
|
+
_restakeRewards(stakeNftId, stakeInfo, targetInfo);
|
539
|
+
}
|
274
540
|
|
541
|
+
_stake(stakeNftId, stakeInfo, targetInfo, additionalLockingPeriod, stakeAmount);
|
542
|
+
}
|
275
543
|
|
276
|
-
|
277
|
-
|
278
|
-
NftId
|
279
|
-
|
544
|
+
|
545
|
+
function unstake(
|
546
|
+
NftId stakeNftId,
|
547
|
+
bool updateRewards,
|
548
|
+
bool restakeRewards,
|
549
|
+
Amount maxUnstakeAmount
|
280
550
|
)
|
281
551
|
external
|
282
552
|
restricted()
|
553
|
+
returns (Amount unstakedAmount)
|
283
554
|
{
|
284
|
-
|
555
|
+
// checks
|
556
|
+
IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
|
557
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
|
285
558
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
_rewardBalance[nftId]); // unchanged reward balance
|
559
|
+
if (updateRewards) {
|
560
|
+
_updateRewards(stakeNftId, stakeInfo, targetInfo);
|
561
|
+
}
|
290
562
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
_rewardBalance[targetNftId]);
|
563
|
+
if (restakeRewards) {
|
564
|
+
_restakeRewards(stakeNftId, stakeInfo, targetInfo);
|
565
|
+
}
|
295
566
|
|
296
|
-
|
567
|
+
return _unstake(stakeNftId, stakeInfo, targetInfo, maxUnstakeAmount);
|
297
568
|
}
|
298
569
|
|
299
570
|
|
300
|
-
function
|
301
|
-
NftId nftId,
|
302
|
-
NftId targetNftId,
|
303
|
-
Amount rewardIncrementAmount
|
304
|
-
)
|
571
|
+
function updateRewards(NftId stakeNftId)
|
305
572
|
external
|
306
573
|
restricted()
|
307
574
|
{
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
// move all rewards to stake balance
|
313
|
-
_updateStakeBalance(
|
314
|
-
nftId,
|
315
|
-
stakeAmount + rewardAmount + rewardIncrementAmount, // new stake balance
|
316
|
-
AmountLib.zero()); // new reward balance
|
317
|
-
|
318
|
-
_updateTargetBalance(
|
319
|
-
targetNftId,
|
320
|
-
_stakeBalance[targetNftId] + rewardAmount + rewardIncrementAmount,
|
321
|
-
_rewardBalance[targetNftId] - rewardAmount);
|
322
|
-
|
323
|
-
emit LogStakingStoreRewardsRestaked(nftId, stakeAmount, rewardAmount, rewardIncrementAmount, _stakeBalance[nftId], lastUpdatedIn);
|
575
|
+
// checks
|
576
|
+
IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
|
577
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
|
578
|
+
_updateRewards(stakeNftId, stakeInfo, targetInfo);
|
324
579
|
}
|
325
580
|
|
326
581
|
|
327
|
-
function
|
328
|
-
NftId
|
329
|
-
|
330
|
-
Amount rewardIncrementAmount
|
582
|
+
function restakeRewards(
|
583
|
+
NftId stakeNftId,
|
584
|
+
bool updateRewards
|
331
585
|
)
|
332
586
|
external
|
333
587
|
restricted()
|
334
588
|
{
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
_updateStakeBalance(
|
339
|
-
nftId,
|
340
|
-
_stakeBalance[nftId], // unchanged stake balance
|
341
|
-
_rewardBalance[nftId] + rewardIncrementAmount); // new reward balance
|
589
|
+
// checks
|
590
|
+
IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
|
591
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
|
342
592
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
_rewardBalance[targetNftId] + rewardIncrementAmount);
|
593
|
+
if (updateRewards) {
|
594
|
+
_updateRewards(stakeNftId, stakeInfo, targetInfo);
|
595
|
+
}
|
347
596
|
|
348
|
-
|
597
|
+
_restakeRewards(stakeNftId, stakeInfo, targetInfo);
|
349
598
|
}
|
350
599
|
|
351
600
|
|
352
|
-
function
|
353
|
-
NftId
|
354
|
-
|
601
|
+
function claimRewards(
|
602
|
+
NftId stakeNftId,
|
603
|
+
bool updateRewards,
|
355
604
|
Amount maxClaimAmount
|
356
605
|
)
|
357
606
|
external
|
358
607
|
restricted()
|
359
608
|
returns (Amount claimedAmount)
|
360
609
|
{
|
361
|
-
|
610
|
+
// checks
|
611
|
+
IStaking.StakeInfo storage stakeInfo = _getAndVerifyStake(stakeNftId);
|
612
|
+
IStaking.TargetInfo storage targetInfo = _getAndVerifyTarget(stakeInfo.targetNftId);
|
613
|
+
|
614
|
+
if (updateRewards) {
|
615
|
+
_updateRewards(stakeNftId, stakeInfo, targetInfo);
|
616
|
+
}
|
362
617
|
|
363
|
-
|
364
|
-
|
618
|
+
claimedAmount = _claimRewards(stakeNftId, stakeInfo, targetInfo, maxClaimAmount);
|
619
|
+
}
|
365
620
|
|
366
|
-
|
367
|
-
_updateStakeBalance(
|
368
|
-
nftId,
|
369
|
-
_stakeBalance[nftId], // unchanged stake balance
|
370
|
-
_rewardBalance[nftId] - claimedAmount); // new reward balance
|
621
|
+
//--- view functions -----------------------------------------------//
|
371
622
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
_rewardBalance[targetNftId] - claimedAmount);
|
623
|
+
function getStakingReader() external view returns (StakingReader stakingReader){
|
624
|
+
return _reader;
|
625
|
+
}
|
376
626
|
|
377
|
-
|
627
|
+
function getTargetManager() external view returns (ITargetManager targetManager){
|
628
|
+
return _targetManager;
|
378
629
|
}
|
379
630
|
|
380
631
|
|
381
|
-
function
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
)
|
387
|
-
|
388
|
-
|
389
|
-
returns (
|
390
|
-
Amount unstakedAmount,
|
391
|
-
Amount claimedAmount
|
392
|
-
)
|
632
|
+
function exists(NftId stakeNftId) external view returns (bool) {
|
633
|
+
return _stakeInfo[stakeNftId].lastUpdateIn.gtz();
|
634
|
+
}
|
635
|
+
|
636
|
+
|
637
|
+
function getRequiredStakeBalance(NftId targetNftId)
|
638
|
+
public
|
639
|
+
view
|
640
|
+
returns (Amount requiredStakeAmount)
|
393
641
|
{
|
394
|
-
|
642
|
+
address [] memory tokens = _targetToken[targetNftId];
|
643
|
+
if (tokens.length == 0) {
|
644
|
+
return AmountLib.zero();
|
645
|
+
}
|
395
646
|
|
396
|
-
|
397
|
-
|
398
|
-
|
647
|
+
requiredStakeAmount = AmountLib.zero();
|
648
|
+
ChainId targetChainId = _targetInfo[targetNftId].chainId;
|
649
|
+
address token;
|
650
|
+
Amount tvlAmount;
|
651
|
+
UFixed stakingRate;
|
399
652
|
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
_rewardBalance[nftId] - claimedAmount); // new reward balance
|
653
|
+
for (uint256 i = 0; i < tokens.length; i++) {
|
654
|
+
token = tokens[i];
|
655
|
+
tvlAmount = _tvlInfo[targetNftId][token].tvlAmount;
|
656
|
+
if (tvlAmount.eqz()) { continue; }
|
405
657
|
|
406
|
-
|
407
|
-
|
408
|
-
_stakeBalance[targetNftId] - unstakedAmount,
|
409
|
-
_rewardBalance[targetNftId] - claimedAmount);
|
658
|
+
stakingRate = _tokenInfo[targetChainId][token].stakingRate;
|
659
|
+
if (stakingRate.eqz()) { continue; }
|
410
660
|
|
411
|
-
|
412
|
-
|
661
|
+
requiredStakeAmount = requiredStakeAmount + tvlAmount.multiplyWith(stakingRate);
|
662
|
+
}
|
413
663
|
}
|
414
664
|
|
415
|
-
//--- view functions -----------------------------------------------//
|
416
665
|
|
417
|
-
|
418
|
-
|
666
|
+
/// @dev Returns true iff current stake amount is still locked
|
667
|
+
function isStakeLocked(NftId stakeNftId) public view returns (bool) {
|
668
|
+
return _stakeInfo[stakeNftId].lockedUntil > TimestampLib.current();
|
419
669
|
}
|
420
670
|
|
421
|
-
|
422
|
-
|
423
|
-
|
671
|
+
|
672
|
+
/// @dev Returns the stake infos for the specified stake.
|
673
|
+
function getStakeInfo(NftId stakeNftId) external view returns (IStaking.StakeInfo memory stakeInfo) {
|
674
|
+
return _stakeInfo[stakeNftId];
|
424
675
|
}
|
425
676
|
|
426
|
-
function getStakingRate(uint256 chainId, address token) external view returns (UFixed stakingRate) { return _stakingRate[chainId][token]; }
|
427
677
|
|
428
|
-
|
678
|
+
/// @dev Returns the stake infos for the specified stake.
|
679
|
+
function getStakeTarget(NftId stakeNftId) external view returns (NftId targetNftId) {
|
680
|
+
return _stakeInfo[stakeNftId].targetNftId;
|
681
|
+
}
|
429
682
|
|
430
|
-
function getTotalValueLocked(NftId nftId, address token) external view returns (Amount tvlBalanceAmount) { return _tvlBalance[nftId][token]; }
|
431
|
-
function getRequiredStakeBalance(NftId nftId) external view returns (Amount requiredAmount) { return _tvlRequiredDip[nftId]; }
|
432
683
|
|
433
|
-
|
434
|
-
function
|
435
|
-
|
436
|
-
|
437
|
-
function getBalanceUpdatedIn(NftId nftId) external view returns (Blocknumber blocknumber) { return _lastUpdatedIn[nftId]; }
|
684
|
+
/// @dev Returns the target infos for the specified target.
|
685
|
+
function getTargetInfo(NftId targetNftId) external view returns (IStaking.TargetInfo memory targetInfo) {
|
686
|
+
return _targetInfo[targetNftId];
|
687
|
+
}
|
438
688
|
|
439
689
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
returns (
|
444
|
-
Amount stakeBalance,
|
445
|
-
Amount rewardBalance,
|
446
|
-
Amount reserveBalance,
|
447
|
-
Blocknumber lastUpdatedIn
|
448
|
-
)
|
449
|
-
{
|
450
|
-
stakeBalance = _stakeBalance[nftId];
|
451
|
-
rewardBalance = _rewardBalance[nftId];
|
452
|
-
reserveBalance = _reserveBalance[nftId];
|
453
|
-
lastUpdatedIn = _lastUpdatedIn[nftId];
|
690
|
+
/// @dev Returns the target limit infos for the specified target.
|
691
|
+
function getLimitInfo(NftId targetNftId) external view returns (IStaking.LimitInfo memory limitInfo) {
|
692
|
+
return _limitInfo[targetNftId];
|
454
693
|
}
|
455
694
|
|
456
695
|
|
457
|
-
|
458
|
-
|
459
|
-
|
696
|
+
/// @dev Returns the tvl infos for the specified target.
|
697
|
+
function getTvlInfo(NftId targetNftId, address token) external view returns (IStaking.TvlInfo memory tvlInfo) {
|
698
|
+
return _tvlInfo[targetNftId][token];
|
699
|
+
}
|
700
|
+
|
701
|
+
|
702
|
+
/// @dev Returns the tvl infos for the specified target.
|
703
|
+
function getTokenInfo(ChainId chainId, address token) external view returns (IStaking.TokenInfo memory tokenInfo) {
|
704
|
+
return _tokenInfo[chainId][token];
|
705
|
+
}
|
706
|
+
|
707
|
+
|
708
|
+
function getTargetSet() external view returns (NftIdSet targetNftIdSet) {
|
709
|
+
return _targetNftIdSet;
|
710
|
+
}
|
711
|
+
|
712
|
+
//--- internal functions -----------------------------------------------//
|
713
|
+
|
714
|
+
function _verifyAndUpdateTarget(NftId targetNftId)
|
715
|
+
private
|
460
716
|
returns (
|
461
|
-
|
462
|
-
|
463
|
-
Timestamp lastUpdatedAt
|
717
|
+
IStaking.TargetInfo storage targetInfo,
|
718
|
+
Blocknumber lastUpdatedIn
|
464
719
|
)
|
465
720
|
{
|
466
|
-
|
467
|
-
|
468
|
-
|
721
|
+
// checks
|
722
|
+
targetInfo = _getAndVerifyTarget(targetNftId);
|
723
|
+
lastUpdatedIn = targetInfo.lastUpdateIn;
|
724
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
469
725
|
}
|
470
726
|
|
471
|
-
//--- private functions -------------------------------------------//
|
472
727
|
|
473
728
|
function _createTarget(
|
474
729
|
NftId targetNftId,
|
475
|
-
|
730
|
+
ObjectType objectType,
|
731
|
+
Seconds lockingPeriod,
|
732
|
+
UFixed rewardRate,
|
733
|
+
bool checkParameters
|
476
734
|
)
|
477
735
|
private
|
478
736
|
{
|
479
|
-
|
480
|
-
|
481
|
-
|
737
|
+
// checks
|
738
|
+
if (checkParameters) {
|
739
|
+
TargetManagerLib.checkTargetParameters(
|
740
|
+
_registry,
|
741
|
+
_reader,
|
742
|
+
targetNftId,
|
743
|
+
objectType,
|
744
|
+
lockingPeriod,
|
745
|
+
rewardRate);
|
746
|
+
}
|
747
|
+
|
748
|
+
// effects
|
482
749
|
|
483
|
-
//
|
484
|
-
|
485
|
-
|
750
|
+
// target info
|
751
|
+
IStaking.TargetInfo storage targetInfo = _targetInfo[targetNftId];
|
752
|
+
targetInfo.stakedAmount = AmountLib.zero();
|
753
|
+
targetInfo.rewardAmount = AmountLib.zero();
|
754
|
+
targetInfo.reserveAmount = AmountLib.zero();
|
755
|
+
targetInfo.limitAmount = AmountLib.max();
|
486
756
|
|
757
|
+
targetInfo.objectType = objectType;
|
758
|
+
targetInfo.lockingPeriod = lockingPeriod;
|
759
|
+
targetInfo.rewardRate = rewardRate;
|
760
|
+
targetInfo.chainId = ChainIdLib.fromNftId(targetNftId);
|
761
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
762
|
+
|
763
|
+
// limit info
|
764
|
+
IStaking.LimitInfo storage limitInfo = _limitInfo[targetNftId];
|
765
|
+
limitInfo.marginAmount = AmountLib.zero();
|
766
|
+
limitInfo.hardLimitAmount = AmountLib.max();
|
767
|
+
limitInfo.lastUpdateIn = BlocknumberLib.current();
|
768
|
+
|
769
|
+
// add new target to target set
|
487
770
|
_targetNftIdSet.add(targetNftId);
|
488
771
|
}
|
489
772
|
|
490
|
-
|
773
|
+
|
774
|
+
function _spendRewardReserves(
|
491
775
|
NftId targetNftId,
|
492
|
-
|
776
|
+
IStaking.TargetInfo storage targetInfo,
|
777
|
+
Amount dipAmount
|
493
778
|
)
|
494
779
|
private
|
495
|
-
returns (Blocknumber lastUpdatedIn)
|
496
780
|
{
|
497
|
-
|
498
|
-
revert ErrorStakingStoreNotTarget(targetNftId);
|
499
|
-
}
|
781
|
+
Blocknumber lastUpdateIn = _decreaseReserves(targetNftId, targetInfo, dipAmount);
|
500
782
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
783
|
+
// logging
|
784
|
+
emit IStaking.LogStakingRewardReservesSpent(
|
785
|
+
targetNftId,
|
786
|
+
dipAmount,
|
787
|
+
targetInfo.reserveAmount,
|
788
|
+
lastUpdateIn);
|
505
789
|
}
|
506
790
|
|
507
791
|
|
508
|
-
function
|
792
|
+
function _decreaseReserves(
|
793
|
+
NftId targetNftId,
|
794
|
+
IStaking.TargetInfo storage targetInfo,
|
795
|
+
Amount dipAmount
|
796
|
+
)
|
509
797
|
private
|
798
|
+
returns ( Blocknumber lastUpdateIn)
|
510
799
|
{
|
511
|
-
|
512
|
-
|
800
|
+
lastUpdateIn = targetInfo.lastUpdateIn;
|
801
|
+
|
802
|
+
// check if reserves are sufficient
|
803
|
+
if (dipAmount > targetInfo.reserveAmount) {
|
804
|
+
revert ErrorStakingStoreRewardReservesInsufficient(
|
805
|
+
targetNftId,
|
806
|
+
targetInfo.reserveAmount,
|
807
|
+
dipAmount);
|
808
|
+
}
|
809
|
+
|
810
|
+
// effects
|
811
|
+
targetInfo.reserveAmount = targetInfo.reserveAmount - dipAmount;
|
812
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
813
|
+
}
|
814
|
+
|
815
|
+
|
816
|
+
function _updateRewards(
|
817
|
+
NftId stakeNftId,
|
818
|
+
IStaking.StakeInfo storage stakeInfo,
|
819
|
+
IStaking.TargetInfo storage targetInfo
|
820
|
+
)
|
821
|
+
internal
|
822
|
+
returns (Amount rewardIncreaseAmount)
|
823
|
+
{
|
824
|
+
// return if reward rate is zero
|
825
|
+
if (targetInfo.rewardRate.eqz()) {
|
826
|
+
return rewardIncreaseAmount;
|
513
827
|
}
|
514
828
|
|
515
|
-
//
|
516
|
-
|
517
|
-
|
518
|
-
_reserveBalance[nftId] = AmountLib.zero();
|
829
|
+
// get seconds since last update on stake
|
830
|
+
Seconds duration = SecondsLib.toSeconds(
|
831
|
+
block.timestamp - stakeInfo.lastUpdateAt.toInt());
|
519
832
|
|
520
|
-
//
|
521
|
-
|
522
|
-
|
833
|
+
// return if duration is zero
|
834
|
+
if (duration.eqz()) {
|
835
|
+
return AmountLib.zero();
|
836
|
+
}
|
837
|
+
|
838
|
+
// calculate reward increase since
|
839
|
+
rewardIncreaseAmount = StakingLib.calculateRewardAmount(
|
840
|
+
targetInfo.rewardRate,
|
841
|
+
duration,
|
842
|
+
stakeInfo.stakedAmount);
|
843
|
+
|
844
|
+
// update target + stake
|
845
|
+
targetInfo.rewardAmount = targetInfo.rewardAmount + rewardIncreaseAmount;
|
846
|
+
stakeInfo.rewardAmount = stakeInfo.rewardAmount + rewardIncreaseAmount;
|
847
|
+
_setLastUpdatesToCurrent(stakeInfo, targetInfo);
|
848
|
+
|
849
|
+
// logging
|
850
|
+
emit IStaking.LogStakingStakeRewardsUpdated(
|
851
|
+
stakeNftId,
|
852
|
+
rewardIncreaseAmount,
|
853
|
+
stakeInfo.stakedAmount,
|
854
|
+
stakeInfo.rewardAmount,
|
855
|
+
stakeInfo.lockedUntil);
|
523
856
|
}
|
524
857
|
|
525
858
|
|
526
|
-
function
|
527
|
-
|
859
|
+
function _restakeRewards(
|
860
|
+
NftId stakeNftId,
|
861
|
+
IStaking.StakeInfo storage stakeInfo,
|
862
|
+
IStaking.TargetInfo storage targetInfo
|
863
|
+
)
|
864
|
+
internal
|
865
|
+
returns (Amount restakeAmount)
|
866
|
+
{
|
867
|
+
restakeAmount = stakeInfo.rewardAmount;
|
868
|
+
|
869
|
+
// return if reward amount is zero
|
870
|
+
if (restakeAmount.eqz()) {
|
871
|
+
return restakeAmount;
|
872
|
+
}
|
873
|
+
|
874
|
+
// check restaking amount does not exceed target max staked amount
|
875
|
+
_checkMaxStakedAmount(stakeInfo.targetNftId, targetInfo, restakeAmount);
|
876
|
+
|
877
|
+
// use up reserves for newly staked dips
|
878
|
+
_spendRewardReserves(stakeInfo.targetNftId, targetInfo, restakeAmount);
|
879
|
+
|
880
|
+
// update target + stake
|
881
|
+
targetInfo.stakedAmount = targetInfo.stakedAmount + restakeAmount;
|
882
|
+
targetInfo.rewardAmount = targetInfo.rewardAmount - restakeAmount;
|
883
|
+
stakeInfo.stakedAmount = stakeInfo.stakedAmount + restakeAmount;
|
884
|
+
stakeInfo.rewardAmount = AmountLib.zero();
|
885
|
+
_setLastUpdatesToCurrent(stakeInfo, targetInfo);
|
886
|
+
|
887
|
+
// logging
|
888
|
+
emit IStaking.LogStakingRewardsRestaked(
|
889
|
+
stakeNftId,
|
890
|
+
restakeAmount,
|
891
|
+
stakeInfo.stakedAmount,
|
892
|
+
AmountLib.zero(),
|
893
|
+
stakeInfo.lockedUntil);
|
894
|
+
}
|
895
|
+
|
896
|
+
|
897
|
+
function _stake(
|
898
|
+
NftId stakeNftId,
|
899
|
+
IStaking.StakeInfo storage stakeInfo,
|
900
|
+
IStaking.TargetInfo storage targetInfo,
|
901
|
+
Seconds maxAdditionalLockingPeriod,
|
902
|
+
Amount stakeAmount
|
903
|
+
)
|
904
|
+
internal
|
528
905
|
{
|
529
|
-
if
|
530
|
-
|
906
|
+
// return if reward amount is zero
|
907
|
+
if (stakeAmount.eqz()) {
|
908
|
+
return;
|
909
|
+
}
|
910
|
+
|
911
|
+
// check restaking amount does not exceed target max staked amount
|
912
|
+
_checkMaxStakedAmount(stakeInfo.targetNftId, targetInfo, stakeAmount);
|
913
|
+
|
914
|
+
// update target + stake
|
915
|
+
targetInfo.stakedAmount = targetInfo.stakedAmount + stakeAmount;
|
916
|
+
stakeInfo.stakedAmount = stakeInfo.stakedAmount + stakeAmount;
|
917
|
+
|
918
|
+
// increase locked until if applicable
|
919
|
+
Seconds additionalLockingPeriod = SecondsLib.min(maxAdditionalLockingPeriod, targetInfo.lockingPeriod);
|
920
|
+
if (stakeAmount.gtz() && additionalLockingPeriod.gtz()) {
|
921
|
+
stakeInfo.lockedUntil = stakeInfo.lockedUntil.addSeconds(additionalLockingPeriod);
|
531
922
|
}
|
532
923
|
|
533
|
-
|
534
|
-
_stakeBalance[nftId] = AmountLib.zero();
|
535
|
-
_rewardBalance[nftId] = AmountLib.zero();
|
924
|
+
_setLastUpdatesToCurrent(stakeInfo, targetInfo);
|
536
925
|
|
537
|
-
//
|
538
|
-
|
539
|
-
|
926
|
+
// logging
|
927
|
+
emit IStaking.LogStakingStaked(
|
928
|
+
stakeNftId,
|
929
|
+
stakeAmount,
|
930
|
+
stakeInfo.stakedAmount,
|
931
|
+
stakeInfo.rewardAmount,
|
932
|
+
stakeInfo.lockedUntil);
|
540
933
|
}
|
541
934
|
|
542
935
|
|
543
|
-
function
|
936
|
+
function _claimRewards(
|
544
937
|
NftId stakeNftId,
|
545
|
-
|
546
|
-
|
938
|
+
IStaking.StakeInfo storage stakeInfo,
|
939
|
+
IStaking.TargetInfo storage targetInfo,
|
940
|
+
Amount maxClaimAmount
|
547
941
|
)
|
548
|
-
|
942
|
+
internal
|
943
|
+
returns (Amount claimAmount)
|
549
944
|
{
|
550
|
-
|
551
|
-
_rewardBalance[stakeNftId] = newRewardAmount;
|
945
|
+
claimAmount = AmountLib.min(maxClaimAmount, stakeInfo.rewardAmount);
|
552
946
|
|
553
|
-
|
554
|
-
|
947
|
+
// return if no rewards to claim
|
948
|
+
if (claimAmount.eqz()) {
|
949
|
+
return claimAmount;
|
950
|
+
}
|
951
|
+
|
952
|
+
// effects
|
953
|
+
// use up reserves for claimed rewards
|
954
|
+
_spendRewardReserves(stakeInfo.targetNftId, targetInfo, claimAmount);
|
955
|
+
|
956
|
+
// update target + stake
|
957
|
+
targetInfo.rewardAmount = targetInfo.rewardAmount - claimAmount;
|
958
|
+
stakeInfo.rewardAmount = stakeInfo.rewardAmount - claimAmount;
|
959
|
+
_setLastUpdatesToCurrent(stakeInfo, targetInfo);
|
960
|
+
|
961
|
+
// logging
|
962
|
+
emit IStaking.LogStakingRewardsClaimed(
|
963
|
+
stakeNftId,
|
964
|
+
claimAmount,
|
965
|
+
stakeInfo.stakedAmount,
|
966
|
+
stakeInfo.rewardAmount,
|
967
|
+
stakeInfo.lockedUntil);
|
555
968
|
}
|
556
969
|
|
557
970
|
|
558
|
-
function
|
559
|
-
NftId
|
560
|
-
|
561
|
-
|
971
|
+
function _unstake(
|
972
|
+
NftId stakeNftId,
|
973
|
+
IStaking.StakeInfo storage stakeInfo,
|
974
|
+
IStaking.TargetInfo storage targetInfo,
|
975
|
+
Amount maxUnstakeAmount
|
976
|
+
)
|
977
|
+
internal
|
978
|
+
returns (Amount unstakedAmount)
|
979
|
+
{
|
980
|
+
unstakedAmount = AmountLib.min(maxUnstakeAmount, stakeInfo.stakedAmount);
|
981
|
+
|
982
|
+
// return if no stakes to claim
|
983
|
+
if (unstakedAmount.eqz()) {
|
984
|
+
return unstakedAmount;
|
985
|
+
}
|
986
|
+
|
987
|
+
// check if stake is still locked
|
988
|
+
if (isStakeLocked(stakeNftId)) {
|
989
|
+
revert IStaking.ErrorStakingStakeLocked(stakeNftId, stakeInfo.lockedUntil);
|
990
|
+
}
|
991
|
+
|
992
|
+
// update target + stake
|
993
|
+
targetInfo.stakedAmount = targetInfo.stakedAmount - unstakedAmount;
|
994
|
+
stakeInfo.stakedAmount = stakeInfo.stakedAmount - unstakedAmount;
|
995
|
+
_setLastUpdatesToCurrent(stakeInfo, targetInfo);
|
996
|
+
|
997
|
+
// logging
|
998
|
+
emit IStaking.LogStakingUnstaked(
|
999
|
+
stakeNftId,
|
1000
|
+
unstakedAmount,
|
1001
|
+
stakeInfo.stakedAmount,
|
1002
|
+
stakeInfo.rewardAmount,
|
1003
|
+
stakeInfo.lockedUntil);
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
|
1007
|
+
function _setLastUpdatesToCurrent(
|
1008
|
+
IStaking.StakeInfo storage stakeInfo,
|
1009
|
+
IStaking.TargetInfo storage targetInfo
|
1010
|
+
)
|
1011
|
+
internal
|
1012
|
+
{
|
1013
|
+
targetInfo.lastUpdateIn = BlocknumberLib.current();
|
1014
|
+
_setStakeLastUpdatesToCurrent(stakeInfo);
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
|
1018
|
+
function _setStakeLastUpdatesToCurrent(
|
1019
|
+
IStaking.StakeInfo storage stakeInfo
|
1020
|
+
)
|
1021
|
+
internal
|
1022
|
+
{
|
1023
|
+
stakeInfo.lastUpdateIn = BlocknumberLib.current();
|
1024
|
+
stakeInfo.lastUpdateAt = TimestampLib.current();
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
//--- private stake and target functions --------------------------------//
|
1028
|
+
|
1029
|
+
|
1030
|
+
function _getAndVerifyStake(
|
1031
|
+
NftId stakeNftId
|
1032
|
+
)
|
1033
|
+
private
|
1034
|
+
view
|
1035
|
+
returns (
|
1036
|
+
IStaking.StakeInfo storage stakeInfo
|
1037
|
+
)
|
1038
|
+
{
|
1039
|
+
stakeInfo = _stakeInfo[stakeNftId];
|
1040
|
+
if (stakeInfo.lastUpdateIn.eqz()) {
|
1041
|
+
revert ErrorStakingStoreStakeNotInitialized(stakeNftId);
|
1042
|
+
}
|
1043
|
+
}
|
1044
|
+
|
1045
|
+
|
1046
|
+
function _checkMaxStakedAmount(
|
1047
|
+
NftId targetNftId,
|
1048
|
+
IStaking.TargetInfo storage targetInfo,
|
1049
|
+
Amount additionalstakedAmount
|
562
1050
|
)
|
563
1051
|
private
|
564
1052
|
{
|
565
|
-
|
566
|
-
|
1053
|
+
if (targetInfo.stakedAmount + additionalstakedAmount > targetInfo.limitAmount) {
|
1054
|
+
revert IStaking.ErrorStakingTargetMaxStakedAmountExceeded(
|
1055
|
+
targetNftId,
|
1056
|
+
targetInfo.limitAmount,
|
1057
|
+
targetInfo.stakedAmount + additionalstakedAmount);
|
1058
|
+
}
|
567
1059
|
|
568
|
-
//
|
569
|
-
_lastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
|
1060
|
+
// TODO add check for tvl dependent maximum, see #628
|
570
1061
|
}
|
571
1062
|
|
572
|
-
|
1063
|
+
|
1064
|
+
function _getAndVerifyTarget(
|
1065
|
+
NftId targetNftId
|
1066
|
+
)
|
573
1067
|
private
|
574
1068
|
view
|
575
|
-
returns (
|
1069
|
+
returns (
|
1070
|
+
IStaking.TargetInfo storage targetInfo
|
1071
|
+
)
|
576
1072
|
{
|
577
|
-
|
1073
|
+
targetInfo = _targetInfo[targetNftId];
|
578
1074
|
|
579
|
-
if (
|
580
|
-
revert
|
1075
|
+
if (targetInfo.lastUpdateIn.eqz()) {
|
1076
|
+
revert ErrorStakingStoreTargetNotInitialized(targetNftId);
|
581
1077
|
}
|
582
1078
|
}
|
583
1079
|
|
584
1080
|
|
585
|
-
function
|
586
|
-
NftId targetNftId
|
587
|
-
address token
|
1081
|
+
function _getAndVerifyLimit(
|
1082
|
+
NftId targetNftId
|
588
1083
|
)
|
589
1084
|
private
|
590
1085
|
view
|
591
1086
|
returns (
|
592
|
-
|
593
|
-
Amount oldBalance,
|
594
|
-
Amount oldDipBalance
|
1087
|
+
IStaking.LimitInfo storage limitInfo
|
595
1088
|
)
|
596
1089
|
{
|
597
|
-
|
1090
|
+
limitInfo = _limitInfo[targetNftId];
|
1091
|
+
|
1092
|
+
if (limitInfo.lastUpdateIn.eqz()) {
|
1093
|
+
revert ErrorStakingStoreLimitNotInitialized(targetNftId);
|
1094
|
+
}
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
//--- private tvl functions ------------------------------------------------//
|
1098
|
+
|
1099
|
+
/// @dev Initializes token balance handling for the specified target.
|
1100
|
+
function _createTvlBalance(NftId targetNftId, address token)
|
1101
|
+
private
|
1102
|
+
{
|
1103
|
+
IStaking.TvlInfo storage info = _tvlInfo[targetNftId][token];
|
598
1104
|
|
599
|
-
if (
|
600
|
-
revert
|
1105
|
+
if (info.lastUpdateIn.gtz()) {
|
1106
|
+
revert ErrorStakingStoreTvlBalanceAlreadyInitialized(targetNftId, token);
|
601
1107
|
}
|
602
1108
|
|
603
|
-
|
604
|
-
|
1109
|
+
// set tvl balances to 0 and update last updated in
|
1110
|
+
info.tvlAmount = AmountLib.zero();
|
1111
|
+
info.lastUpdateIn = BlocknumberLib.current();
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
|
1115
|
+
function _updateTvlBalance(
|
1116
|
+
NftId targetNftId,
|
1117
|
+
address token,
|
1118
|
+
Amount newTvlAmount
|
1119
|
+
)
|
1120
|
+
private
|
1121
|
+
returns (
|
1122
|
+
Amount oldTvlAmount,
|
1123
|
+
Blocknumber lastUpdatedIn
|
1124
|
+
)
|
1125
|
+
{
|
1126
|
+
IStaking.TvlInfo storage tvlInfo = _getAndVerifyTvl(targetNftId, token);
|
1127
|
+
oldTvlAmount = tvlInfo.tvlAmount;
|
1128
|
+
lastUpdatedIn = tvlInfo.lastUpdateIn;
|
1129
|
+
|
1130
|
+
tvlInfo.tvlAmount = newTvlAmount;
|
1131
|
+
tvlInfo.lastUpdateIn = BlocknumberLib.current();
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
|
1135
|
+
function _getAndVerifyTvl(NftId targetNftId, address token)
|
1136
|
+
private
|
1137
|
+
view
|
1138
|
+
returns (IStaking.TvlInfo storage tvlInfo)
|
1139
|
+
{
|
1140
|
+
tvlInfo = _tvlInfo[targetNftId][token];
|
1141
|
+
if (tvlInfo.lastUpdateIn.eqz()) {
|
1142
|
+
revert ErrorStakingStoreTvlBalanceNotInitialized(targetNftId, token);
|
1143
|
+
}
|
605
1144
|
}
|
606
1145
|
}
|