Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Sep 8, 2024
1 parent 33aca5c commit 804c24f
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 182 deletions.
2 changes: 1 addition & 1 deletion contracts/instance/Instance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract Instance is
IRegistry registry,
VersionPart release,
address initialOwner,
bool tokenRegistryDisabled
bool tokenRegistryDisabled // only disable for testing
)
external
initializer()
Expand Down
19 changes: 17 additions & 2 deletions contracts/registry/RegistryAuthorization.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IRegistry} from "../registry/IRegistry.sol";
import {IStaking} from "../staking/IStaking.sol";

import {Authorization} from "../authorization/Authorization.sol";
import {POOL, REGISTRY, STAKING} from "../../contracts/type/ObjectType.sol";
import {COMPONENT, POOL, REGISTRY, STAKING} from "../../contracts/type/ObjectType.sol";
import {PUBLIC_ROLE} from "../type/RoleId.sol";
import {ReleaseRegistry} from "./ReleaseRegistry.sol";
import {RegistryAdmin} from "./RegistryAdmin.sol";
Expand All @@ -21,7 +21,6 @@ import {VersionPartLib} from "../type/Version.sol";
contract RegistryAuthorization
is Authorization
{

/// @dev gif core roles
string public constant GIF_ADMIN_ROLE_NAME = "GifAdminRole";
string public constant GIF_MANAGER_ROLE_NAME = "GifManagerRole";
Expand Down Expand Up @@ -77,6 +76,14 @@ contract RegistryAuthorization
maxMemberCount: maxReleases,
name: STAKING_SERVICE_ROLE_NAME}));

_addRole(
RoleIdLib.toGenericServiceRoleId(COMPONENT()),
_toRoleInfo({
adminRoleId: ADMIN_ROLE(),
roleType: RoleType.Core,
maxMemberCount: maxReleases,
name: COMPONENT_SERVICE_ROLE_NAME}));

_addRole(
RoleIdLib.toGenericServiceRoleId(POOL()),
_toRoleInfo({
Expand Down Expand Up @@ -235,6 +242,13 @@ contract RegistryAuthorization
_authorize(functions, IStaking.updateRewards.selector, "updateRewards");
_authorize(functions, IStaking.claimRewards.selector, "claimRewards");

// pool service role
functions = _authorizeForTarget(
STAKING_TARGET_NAME,
RoleIdLib.toGenericServiceRoleId(COMPONENT()));

_authorize(functions, IStaking.addTargetToken.selector, "addTargetToken");

// pool service role
functions = _authorizeForTarget(
STAKING_TARGET_NAME,
Expand Down Expand Up @@ -276,6 +290,7 @@ contract RegistryAuthorization
STAKING_STORE_TARGET_NAME,
getTargetRole(getTarget(STAKING_TARGET_NAME)));

_authorize(functions, StakingStore.addTargetToken.selector, "addTargetToken");
_authorize(functions, StakingStore.addToken.selector, "addToken");
_authorize(functions, StakingStore.setStakingRate.selector, "setStakingRate");
_authorize(functions, StakingStore.createTarget.selector, "createTarget");
Expand Down
7 changes: 6 additions & 1 deletion contracts/registry/ReleaseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {IServiceAuthorization} from "../authorization/IServiceAuthorization.sol"

import {ContractLib} from "../shared/ContractLib.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType, ObjectTypeLib, POOL, RELEASE, REGISTRY, SERVICE, STAKING} from "../type/ObjectType.sol";
import {ObjectType, ObjectTypeLib, COMPONENT, POOL, RELEASE, REGISTRY, SERVICE, STAKING} from "../type/ObjectType.sol";
import {RegistryAdmin} from "./RegistryAdmin.sol";
import {Registry} from "./Registry.sol";
import {ReleaseAdmin} from "./ReleaseAdmin.sol";
Expand Down Expand Up @@ -258,6 +258,11 @@ contract ReleaseRegistry is
_registryAdmin.grantServiceRoleForAllVersions(IService(service), STAKING());
}

service = _registry.getServiceAddress(COMPONENT(), release);
if(service != address(0)) {
_registryAdmin.grantServiceRoleForAllVersions(IService(service), COMPONENT());
}

service = _registry.getServiceAddress(POOL(), release);
if(service != address(0)) {
_registryAdmin.grantServiceRoleForAllVersions(IService(service), POOL());
Expand Down
20 changes: 14 additions & 6 deletions contracts/shared/ComponentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ import {IInstanceLinkedComponent} from "./IInstanceLinkedComponent.sol";
import {InstanceAdmin} from "../instance/InstanceAdmin.sol";
import {InstanceReader} from "../instance/InstanceReader.sol";
import {InstanceStore} from "../instance/InstanceStore.sol";
import {IInstanceService} from "../instance/IInstanceService.sol";
import {IPoolComponent} from "../pool/IPoolComponent.sol";
import {IProductComponent} from "../product/IProductComponent.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IRegistryService} from "../registry/IRegistryService.sol";
import {IStaking} from "../staking/IStaking.sol";
import {IStakingService} from "../staking/IStakingService.sol";

import {AccessManagerCloneable} from "../authorization/AccessManagerCloneable.sol";
import {Amount, AmountLib} from "../type/Amount.sol";
import {ChainIdLib} from "../type/ChainId.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {Fee, FeeLib} from "../type/Fee.sol";
import {KEEP_STATE} from "../type/StateId.sol";
import {NftId, NftIdLib} from "../type/NftId.sol";
import {ObjectType, ACCOUNTING, REGISTRY, COMPONENT, DISTRIBUTION, INSTANCE, ORACLE, POOL, PRODUCT} from "../type/ObjectType.sol";
import {ObjectType, ACCOUNTING, REGISTRY, COMPONENT, DISTRIBUTION, INSTANCE, ORACLE, POOL, PRODUCT, STAKING} from "../type/ObjectType.sol";
import {Service} from "../shared/Service.sol";
import {TokenHandler} from "../shared/TokenHandler.sol";
import {TokenHandlerDeployerLib} from "../shared/TokenHandlerDeployerLib.sol";
Expand All @@ -38,7 +40,7 @@ contract ComponentService is

IAccountingService private _accountingService;
IRegistryService private _registryService;
IInstanceService private _instanceService;
IStaking private _staking;

function _initialize(
address owner,
Expand All @@ -57,7 +59,7 @@ contract ComponentService is

_accountingService = IAccountingService(_getServiceAddress(ACCOUNTING()));
_registryService = IRegistryService(_getServiceAddress(REGISTRY()));
_instanceService = IInstanceService(_getServiceAddress(INSTANCE()));
_staking = IStakingService(_getServiceAddress(STAKING())).getStaking();

_registerInterface(type(IComponentService).interfaceId);
}
Expand Down Expand Up @@ -219,10 +221,16 @@ contract ComponentService is
}

IInstance instance = IInstance(msg.sender);
NftId instanceNftId = registry.getNftIdForAddress(msg.sender);
productNftId = _verifyAndRegister(
instance,
productAddress,
instance.getNftId(), // instance is parent of product to be registered
instanceNftId, // instance is parent of product to be registered
token);

// add product specific token for product to staking
_staking.addTargetToken(
instanceNftId,
token);
}

Expand Down Expand Up @@ -560,8 +568,8 @@ contract ComponentService is
// check if provided token is whitelisted and active
if (!ContractLib.isActiveToken(
getRegistry().getTokenRegistryAddress(),
ChainIdLib.current(),
token,
block.chainid,
AccessManagerCloneable(authority()).getRelease())
) {
revert ErrorComponentServiceTokenInvalid(token);
Expand Down
5 changes: 3 additions & 2 deletions contracts/shared/ContractLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {IPolicyHolder} from "../shared/IPolicyHolder.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IService} from "../shared/IService.sol";

import {ChainId} from "../type/ChainId.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType, INSTANCE, PRODUCT, DISTRIBUTION, ORACLE, POOL} from "../type/ObjectType.sol";
import {VersionPart} from "../type/Version.sol";
Expand All @@ -22,7 +23,7 @@ interface IInstanceAdminHelper {
}

interface ITokenRegistryHelper {
function isActive(uint256 chainId, address token, VersionPart release) external view returns (bool);
function isActive(ChainId chainId, address token, VersionPart release) external view returns (bool);
}

library ContractLib {
Expand Down Expand Up @@ -114,8 +115,8 @@ library ContractLib {

function isActiveToken(
address tokenRegistryAddress,
ChainId chainId,
address token,
uint256 chainId,
VersionPart release
)
external
Expand Down
6 changes: 6 additions & 0 deletions contracts/staking/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ interface IStaking is

// token
event LogStakingTokenAdded(ChainId chainId, address token);
event LogStakingTargetTokenAdded(NftId targetNftId, ChainId chainId, address token);

// total value locked
event LogStakingTotalValueLockedIncreased(NftId targetNftId, address token, Amount amount, Amount newBalance);
event LogStakingTotalValueLockedDecreased(NftId targetNftId, address token, Amount amount, Amount newBalance);

// targets
event LogStakingTargetCreated(NftId targetNftId, ObjectType objectType, Seconds lockingPeriod, UFixed rewardRate, Amount maxStakedAmount);
Expand All @@ -45,6 +50,7 @@ interface IStaking is

// stakes
event LogStakingStakeRegistered(NftId stakeNftId, NftId targetNftId, Amount stakeAmount);
event LogStakingStakeRewardsUpdated(NftId stakeNftId, Amount rewardIncrementAmount, Amount rewardBalanceAmount);
event LogStakingStakeRestaked(NftId stakeNftId, NftId targetNftId, Amount stakeAmount, address owner, NftId oldStakeNftId);

// modifiers
Expand Down
Loading

0 comments on commit 804c24f

Please sign in to comment.