Skip to content

Commit

Permalink
check token is whitelisted during product registration (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Aug 27, 2024
1 parent 5c2eac0 commit 98fe508
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
28 changes: 7 additions & 21 deletions contracts/shared/Component.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import {IAccessManaged} from "@openzeppelin/contracts/access/manager/IAccessMana
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import {Amount} from "../type/Amount.sol";
import {ContractLib} from "./ContractLib.sol";
import {IComponent} from "./IComponent.sol";
import {IComponents} from "../instance/module/IComponents.sol";
import {IComponentService} from "./IComponentService.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IRelease} from "../registry/IRelease.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType, COMPONENT, STAKING} from "../type/ObjectType.sol";
import {ObjectType, COMPONENT} from "../type/ObjectType.sol";
import {Registerable} from "../shared/Registerable.sol";
import {TokenHandler} from "../shared/TokenHandler.sol";
import {Version, VersionLib, VersionPart} from "../type/Version.sol";
import {Version, VersionLib} from "../type/Version.sol";


abstract contract Component is
Expand All @@ -42,6 +39,7 @@ abstract contract Component is


function _getComponentStorage() private pure returns (ComponentStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := COMPONENT_LOCATION_V1
}
Expand All @@ -63,21 +61,6 @@ abstract contract Component is
virtual
onlyInitializing()
{
address tokenRegistry = IRegistry(registry).getTokenRegistryAddress();
VersionPart release = IRelease(authority).getRelease();

// special case for staking: component intitialization happens before
// GIF core contract setup is complete. at that time token registry
// is not yet available. therefore we skip the check for staking.
if (componentType != STAKING()) {

// FIXME: move to component registration
// check if provided token is whitelisted and active
// if (!ContractLib.isActiveToken(tokenRegistry, token, block.chainid, release)) {
// revert ErrorComponentTokenInvalid(token);
// }
}

if (bytes(name).length == 0) {
revert ErrorComponentNameLengthZero();
}
Expand Down Expand Up @@ -181,7 +164,10 @@ abstract contract Component is
function _nftTransferFrom(address from, address to, uint256 tokenId, address operator)
internal
virtual
{ }
// solhint-disable-next-line no-empty-blocks
{
// empty default implementation
}


/// @dev Sets the components wallet to the specified address.
Expand Down
13 changes: 13 additions & 0 deletions contracts/shared/ComponentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {IRegisterable} from "../shared/IRegisterable.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IRegistryService} from "../registry/IRegistryService.sol";

import {AccessManagerCloneable} from "../authorization/AccessManagerCloneable.sol";
import {Amount, AmountLib} from "../type/Amount.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {Fee, FeeLib} from "../type/Fee.sol";
Expand Down Expand Up @@ -489,6 +490,18 @@ contract ComponentService is
componentAddress,
requiredType);

{
// check if provided token is whitelisted and active
if (!ContractLib.isActiveToken(
getRegistry().getTokenRegistryAddress(),
token,
block.chainid,
AccessManagerCloneable(authority()).getRelease())
) {
revert ErrorComponentServiceTokenInvalid(token);
}
}

// get instance supporting contracts (as function return values)
instanceReader = instance.getInstanceReader();
instanceAdmin = instance.getInstanceAdmin();
Expand Down
3 changes: 0 additions & 3 deletions contracts/shared/IComponent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ interface IComponent is
IRegisterable,
ITransferInterceptor
{

error ErrorComponentTokenInvalid(address token);

error ErrorComponentProductNftIdZero();
error ErrorComponentProductNftIdNonzero();
error ErrorComponentNameLengthZero();
Expand Down
2 changes: 2 additions & 0 deletions contracts/shared/IComponentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {VersionPart} from "../type/Version.sol";
interface IComponentService is
IService
{
error ErrorComponentServiceTokenInvalid(address token);

error ErrorComponentServiceNotInstanceLinkedComponent(address component);
error ErrorComponentServiceSenderNotRegistered(address sender);
error ErrorComponentServiceNotComponent(address component);
Expand Down

0 comments on commit 98fe508

Please sign in to comment.