Skip to content

Commit

Permalink
Cleanup for not exceed the size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Mar 25, 2024
1 parent 6212597 commit d28d9df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
7 changes: 3 additions & 4 deletions contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ library Assets {
}

// @dev Register a new fungible Polkadot token for an agent
function registerTokenByID(bytes32 tokenID, address token, bytes32 agentID) internal {
function registerTokenByID(bytes32 tokenID, address token, bytes32 agentID) external {
AssetsStorage.Layout storage $ = AssetsStorage.layout();
if ($.tokenRegistryByID[tokenID].isRegistered == true) {
revert TokenAlreadyRegistered();
Expand All @@ -195,11 +195,10 @@ library Assets {
TokenInfo({isRegistered: true, isForeign: true, tokenID: tokenID, agentID: agentID, token: token});
$.tokenRegistry[token] = info;
$.tokenRegistryByID[tokenID] = info;
emit IGateway.TokenRegistered(tokenID, agentID, token);
}

// @dev Get token address by tokenID
function getTokenInfo(bytes32 tokenID) internal view returns (TokenInfo memory) {
function getTokenInfo(bytes32 tokenID) external view returns (TokenInfo memory) {
AssetsStorage.Layout storage $ = AssetsStorage.layout();
if ($.tokenRegistryByID[tokenID].isRegistered == false) {
revert TokenNotRegistered();
Expand All @@ -216,7 +215,7 @@ library Assets {
MultiAddress calldata destinationAddress,
uint128 destinationChainFee,
uint128 amount
) internal returns (Ticket memory ticket) {
) external returns (Ticket memory ticket) {
AssetsStorage.Layout storage $asset = AssetsStorage.layout();

TokenInfo storage info = $asset.tokenRegistry[token];
Expand Down
18 changes: 1 addition & 17 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,6 @@ contract Gateway is IGateway, IInitializable {
_;
}

// handler functions are privileged from agent only
modifier onlyAgent(bytes32 agentID) {
bytes32 _agentID = _ensureAgentAddress(msg.sender);
if (_agentID != agentID) {
revert Unauthorized();
}
_;
}

constructor(
address beefyClient,
address agentExecutor,
Expand Down Expand Up @@ -289,6 +280,7 @@ contract Gateway is IGateway, IInitializable {
(bytes memory result) = abi.decode(returndata, (bytes));
(bytes32 tokenID, address token) = abi.decode(result, (bytes32, address));
Assets.registerTokenByID(tokenID, token, params.agentID);
emit IGateway.ForeignTokenRegistered(tokenID, params.agentID, token);
}
}

Expand Down Expand Up @@ -575,14 +567,6 @@ contract Gateway is IGateway, IInitializable {
}
}

/// @dev Ensure that the specified address is an valid agent
function _ensureAgentAddress(address agent) internal view returns (bytes32 agentID) {
agentID = CoreStorage.layout().agentAddresses[agent];
if (agentID == bytes32(0)) {
revert AgentDoesNotExist();
}
}

/// @dev Invoke some code within an agent
function _invokeOnAgent(address agent, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = (Agent(payable(agent)).invoke(AGENT_EXECUTOR, data));
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/interfaces/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ interface IGateway {
// Emitted when funds are withdrawn from an agent
event AgentFundsWithdrawn(bytes32 indexed agentID, address indexed recipient, uint256 amount);

// Emitted when token registed
event TokenRegistered(bytes32 indexed tokenID, bytes32 agentID, address token);
// Emitted when foreign token from polkadot registed
event ForeignTokenRegistered(bytes32 indexed tokenID, bytes32 agentID, address token);

/**
* Getters
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ contract GatewayTest is Test {
});

vm.expectEmit(true, true, false, false);
emit IGateway.TokenRegistered(bytes32(uint256(1)), assetHubAgentID, address(0));
emit IGateway.ForeignTokenRegistered(bytes32(uint256(1)), assetHubAgentID, address(0));

GatewayMock(address(gateway)).agentExecutePublic(abi.encode(params));
}
Expand Down

0 comments on commit d28d9df

Please sign in to comment.