Skip to content

Commit

Permalink
Adds Missing Events to TokenGateway (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Jun 28, 2024
1 parent e8cd91b commit 7cccc53
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 82 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion evm/abi/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ impl TryFrom<EvmHostEvents> for ismp::events::Event {
fisherman: vetoed.fisherman.as_bytes().to_vec(),
})),
EvmHostEvents::HostFrozenFilter(_) |
EvmHostEvents::HostUnfrozenFilter(_) |
EvmHostEvents::HostParamsUpdatedFilter(_) |
EvmHostEvents::PostResponseFundedFilter(_) |
EvmHostEvents::RequestFundedFilter(_) => Err(anyhow!("Unsupported Event!"))?,
Expand Down
52 changes: 11 additions & 41 deletions evm/abi/src/generated/evm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,13 @@ pub mod evm_host {
::std::vec![
::ethers::core::abi::ethabi::Event {
name: ::std::borrow::ToOwned::to_owned("HostFrozen"),
inputs: ::std::vec![],
inputs: ::std::vec![
::ethers::core::abi::ethabi::EventParam {
name: ::std::borrow::ToOwned::to_owned("frozen"),
kind: ::ethers::core::abi::ethabi::ParamType::Bool,
indexed: false,
},
],
anonymous: false,
},
],
Expand Down Expand Up @@ -1563,16 +1569,6 @@ pub mod evm_host {
},
],
),
(
::std::borrow::ToOwned::to_owned("HostUnfrozen"),
::std::vec![
::ethers::core::abi::ethabi::Event {
name: ::std::borrow::ToOwned::to_owned("HostUnfrozen"),
inputs: ::std::vec![],
anonymous: false,
},
],
),
(
::std::borrow::ToOwned::to_owned("PostRequestEvent"),
::std::vec![
Expand Down Expand Up @@ -2466,12 +2462,6 @@ pub mod evm_host {
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, HostParamsUpdatedFilter> {
self.0.event()
}
///Gets the contract's `HostUnfrozen` event
pub fn host_unfrozen_filter(
&self,
) -> ::ethers::contract::builders::Event<::std::sync::Arc<M>, M, HostUnfrozenFilter> {
self.0.event()
}
///Gets the contract's `PostRequestEvent` event
pub fn post_request_event_filter(
&self,
Expand Down Expand Up @@ -2937,8 +2927,10 @@ pub mod evm_host {
Eq,
Hash,
)]
#[ethevent(name = "HostFrozen", abi = "HostFrozen()")]
pub struct HostFrozenFilter;
#[ethevent(name = "HostFrozen", abi = "HostFrozen(bool)")]
pub struct HostFrozenFilter {
pub frozen: bool,
}
#[derive(
Clone,
::ethers::contract::EthEvent,
Expand Down Expand Up @@ -2967,18 +2959,6 @@ pub mod evm_host {
Eq,
Hash,
)]
#[ethevent(name = "HostUnfrozen", abi = "HostUnfrozen()")]
pub struct HostUnfrozenFilter;
#[derive(
Clone,
::ethers::contract::EthEvent,
::ethers::contract::EthDisplay,
Default,
Debug,
PartialEq,
Eq,
Hash,
)]
#[ethevent(
name = "PostRequestEvent",
abi = "PostRequestEvent(bytes,bytes,bytes,bytes,uint256,uint256,bytes,uint256)"
Expand Down Expand Up @@ -3160,7 +3140,6 @@ pub mod evm_host {
GetRequestTimeoutHandledFilter(GetRequestTimeoutHandledFilter),
HostFrozenFilter(HostFrozenFilter),
HostParamsUpdatedFilter(HostParamsUpdatedFilter),
HostUnfrozenFilter(HostUnfrozenFilter),
PostRequestEventFilter(PostRequestEventFilter),
PostRequestHandledFilter(PostRequestHandledFilter),
PostRequestTimeoutHandledFilter(PostRequestTimeoutHandledFilter),
Expand Down Expand Up @@ -3191,9 +3170,6 @@ pub mod evm_host {
if let Ok(decoded) = HostParamsUpdatedFilter::decode_log(log) {
return Ok(EvmHostEvents::HostParamsUpdatedFilter(decoded));
}
if let Ok(decoded) = HostUnfrozenFilter::decode_log(log) {
return Ok(EvmHostEvents::HostUnfrozenFilter(decoded));
}
if let Ok(decoded) = PostRequestEventFilter::decode_log(log) {
return Ok(EvmHostEvents::PostRequestEventFilter(decoded));
}
Expand Down Expand Up @@ -3236,7 +3212,6 @@ pub mod evm_host {
::core::fmt::Display::fmt(element, f),
Self::HostFrozenFilter(element) => ::core::fmt::Display::fmt(element, f),
Self::HostParamsUpdatedFilter(element) => ::core::fmt::Display::fmt(element, f),
Self::HostUnfrozenFilter(element) => ::core::fmt::Display::fmt(element, f),
Self::PostRequestEventFilter(element) => ::core::fmt::Display::fmt(element, f),
Self::PostRequestHandledFilter(element) => ::core::fmt::Display::fmt(element, f),
Self::PostRequestTimeoutHandledFilter(element) =>
Expand Down Expand Up @@ -3277,11 +3252,6 @@ pub mod evm_host {
Self::HostParamsUpdatedFilter(value)
}
}
impl ::core::convert::From<HostUnfrozenFilter> for EvmHostEvents {
fn from(value: HostUnfrozenFilter) -> Self {
Self::HostUnfrozenFilter(value)
}
}
impl ::core::convert::From<PostRequestEventFilter> for EvmHostEvents {
fn from(value: PostRequestEventFilter) -> Self {
Self::PostRequestEventFilter(value)
Expand Down
4 changes: 2 additions & 2 deletions evm/abi/src/generated/host_manager.rs

Large diffs are not rendered by default.

17 changes: 6 additions & 11 deletions evm/src/hosts/EvmHost.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,8 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
// Emitted when a POST response is funded
event PostResponseFunded(bytes32 commitment, uint256 newFee);

// Emitted when the host has now been frozen
event HostFrozen();

// Emitted when the host is unfrozen
event HostUnfrozen();
// Emitted when the host has either been frozen or unfrozen
event HostFrozen(bool frozen);

// Emitted when the host params is updated
event HostParamsUpdated(HostParams oldParams, HostParams newParams);
Expand Down Expand Up @@ -563,14 +560,12 @@ abstract contract EvmHost is IIsmpHost, IHostManager, Context {
* @dev set the new state of the bridge
* @param newState new state
*/
function setFrozenState(bool newState) public restrict(_hostParams.admin) {
function setFrozenState(bool newState) public {
if (_msgSender() != _hostParams.admin || _msgSender() != _hostParams.handler) revert UnauthorizedAction();

_frozen = newState;

if (newState) {
emit HostFrozen();
} else {
emit HostUnfrozen();
}
emit HostFrozen({frozen: newState});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion evm/src/modules/Registrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract TokenRegistrar is BaseIsmpModule {
SafeERC20.safeIncreaseAllowance(IERC20(feeToken), _params.host, fee);
DispatchPost memory request = DispatchPost({
dest: IIsmpHost(_params.host).hyperbridge(),
to: bytes("registrar"),
to: bytes("registry"),
body: data,
timeout: 0,
fee: 0,
Expand Down
47 changes: 46 additions & 1 deletion evm/src/modules/TokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ contract TokenGateway is BaseIsmpModule {
// User assets could not be delivered and have been refunded.
event AssetRefunded(bytes32 commitment, address indexed beneficiary, uint256 amount, bytes32 indexed assetId);

// A new asset has been registered
event AssetRegistered(
// ERC20 token contract address for the asset
address erc20,
// ERC6160 token contract address for the asset
address erc6160,
// Asset's name
string name,
// Asset's symbol
string symbol,
// Registered asset identifier
bytes32 assetId,
// The initial supply of asset
uint256 initialSupply,
// Initial beneficiary of the total supply
address beneficiary
);

// Contract parameters have been updated by Hyperbridge governance
event ParamsUpdated(TokenGatewayParams oldParams, TokenGatewayParams newParams);

// An asset has been deregistered
event AssetRemoved(bytes32 assetId);

// An asset owner has requested to change the admin of their asset
event AssetAdminChanged(address asset, address newAdmin);

// Action is unauthorized
error UnauthorizedAction();

Expand Down Expand Up @@ -596,7 +623,11 @@ contract TokenGateway is BaseIsmpModule {
function handleGovernance(PostRequest calldata request) private {
if (!request.source.equals(IIsmpHost(_params.host).hyperbridge())) revert UnauthorizedAction();

_params = abi.decode(request.body[1:], (TokenGatewayParams));
TokenGatewayParams memory params = abi.decode(request.body[1:], (TokenGatewayParams));

emit ParamsUpdated({oldParams: _params, newParams: params});

_params = params;
}

function handleCreateAsset(PostRequest calldata request) private {
Expand All @@ -617,6 +648,8 @@ contract TokenGateway is BaseIsmpModule {
for (uint256 i = 0; i < length; ++i) {
delete _erc20s[deregister.assetIds[i]];
delete _erc6160s[deregister.assetIds[i]];

emit AssetRemoved({assetId: deregister.assetIds[i]});
}
}

Expand All @@ -632,6 +665,8 @@ contract TokenGateway is BaseIsmpModule {
if (erc6160Address == address(0)) revert UnknownAsset();

IERC6160Ext20(erc6160Address).changeAdmin(asset.newAdmin);

emit AssetAdminChanged({asset: erc6160Address, newAdmin: asset.newAdmin});
}

// Creates a new entry for the provided asset in the mappings. If there's no existing
Expand All @@ -654,6 +689,16 @@ contract TokenGateway is BaseIsmpModule {
}
_erc20s[identifier] = asset.erc20;
_erc6160s[identifier] = asset.erc6160;

emit AssetRegistered({
erc20: asset.erc20,
erc6160: asset.erc6160,
name: asset.name,
symbol: asset.symbol,
assetId: identifier,
beneficiary: asset.beneficiary,
initialSupply: asset.initialSupply
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/hyperclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mmr-primitives = { workspace = true }
sp-mmr-primitives = { workspace = true }
hex = "0.4.3"
gql_client = "=1.0.7"
hex_fmt = {version = "0.3.0", default-features = false }

[features]
default = ["std"]
Expand All @@ -66,7 +67,6 @@ testing = []
[dev-dependencies]
json = { package = "serde_json", version = "1.0.114", default-features = false }
wasm-bindgen-test = "0.3.24"
hex = { version = "0.4.3", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
ethers = { workspace = true, features = ["ws"], default-features = true }
Expand Down
8 changes: 4 additions & 4 deletions modules/hyperclient/src/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub async fn query_request_status_from_indexer(
MessageStatusWithMetadata::HyperbridgeFinalized {
finalized_height: data.height.low_u64(),
meta,
calldata,
calldata: calldata.into(),
}
} else {
MessageStatusWithMetadata::HyperbridgeDelivered {
Expand All @@ -314,7 +314,7 @@ pub async fn query_request_status_from_indexer(
Status::TIMED_OUT => MessageStatusWithMetadata::Timeout,
Status::Other(_) => MessageStatusWithMetadata::Pending,
};
return Ok(Some(status))
return Ok(Some(status));
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@ pub async fn query_response_status_from_indexer(
MessageStatusWithMetadata::HyperbridgeFinalized {
finalized_height: data.height.low_u64(),
meta,
calldata,
calldata: calldata.into(),
}
} else {
MessageStatusWithMetadata::HyperbridgeDelivered {
Expand All @@ -470,7 +470,7 @@ pub async fn query_response_status_from_indexer(
Status::TIMED_OUT => MessageStatusWithMetadata::Timeout,
Status::Other(_) => MessageStatusWithMetadata::Pending,
};
return Ok(Some(status))
return Ok(Some(status));
}
};

Expand Down
12 changes: 6 additions & 6 deletions modules/hyperclient/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn query_request_status_internal(
.ok()
.flatten()
{
return Ok(status.clone())
return Ok(status.clone());
}
if relayer_address != H160::zero() {
// This means the message has gotten the destination chain
Expand Down Expand Up @@ -82,7 +82,7 @@ pub async fn query_response_status_internal(
.ok()
.flatten()
{
return Ok(status.clone())
return Ok(status.clone());
}
if response_receipt_relayer != H160::zero() {
return Ok(MessageStatusWithMetadata::DestinationDelivered { meta: Default::default() });
Expand Down Expand Up @@ -341,7 +341,7 @@ pub async fn timeout_request_stream(
let calldata = source_client.encode(message)?;

Ok(Some((
Ok(TimeoutStatus::TimeoutMessage { calldata }),
Ok(TimeoutStatus::TimeoutMessage { calldata: calldata.into() }),
TimeoutStreamState::End,
)))
},
Expand Down Expand Up @@ -703,7 +703,7 @@ pub async fn request_status_stream(
Ok(MessageStatusWithMetadata::HyperbridgeFinalized {
finalized_height: height,
meta: Default::default(),
calldata,
calldata: calldata.into(),
}),
PostStreamState::HyperbridgeFinalized(latest_height),
)));
Expand All @@ -722,7 +722,7 @@ pub async fn request_status_stream(
Ok(MessageStatusWithMetadata::HyperbridgeFinalized {
finalized_height: update.latest_height,
meta: meta.clone(),
calldata,
calldata: calldata.into(),
}),
PostStreamState::HyperbridgeFinalized(meta.block_number),
)));
Expand Down Expand Up @@ -750,7 +750,7 @@ pub async fn request_status_stream(
Ok(MessageStatusWithMetadata::HyperbridgeFinalized {
finalized_height: event.event.latest_height,
meta: event.meta,
calldata,
calldata: calldata.into(),
}),
PostStreamState::HyperbridgeFinalized(
event.meta.block_number,
Expand Down
2 changes: 1 addition & 1 deletion modules/hyperclient/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub async fn test_timeout_request() -> Result<(), anyhow::Error> {
TypedTransaction::Legacy(TransactionRequest {
to: Some(NameOrAddress::Address(source_chain.handler_address)),
gas_price: Some(gas_price * 5), // experiment with higher?
data: Some(calldata.into()),
data: Some(calldata.0.into()),
..Default::default()
}),
None,
Expand Down
Loading

0 comments on commit 7cccc53

Please sign in to comment.