From 639ed2793752400dad8c14f4e3d29348d68a37c8 Mon Sep 17 00:00:00 2001 From: Dennis Fang Date: Mon, 28 Oct 2024 22:48:16 -0700 Subject: [PATCH] modify cosmwasm gateway contracts to invoke a configured hook address when calling the hyperlane mailbox --- .../fast-transfer-gateway/src/contract.rs | 1 + .../fast-transfer-gateway/src/execute.rs | 10 +- .../fast-transfer-gateway/src/query.rs | 6 +- .../fast-transfer-gateway/tests/common/mod.rs | 1 + .../tests/test_initiate_settlement.rs | 4 +- .../tests/test_initiate_timeout.rs | 2 +- .../tests/test_instantiate.rs | 2 + cosmwasm/packages/gofast/.idea/editor.xml | 483 ++++++++++++++++++ cosmwasm/packages/gofast/.idea/gofast.iml | 10 + cosmwasm/packages/gofast/.idea/modules.xml | 8 + cosmwasm/packages/gofast/.idea/vcs.xml | 6 + cosmwasm/packages/gofast/.idea/workspace.xml | 104 ++++ cosmwasm/packages/gofast/src/gateway.rs | 2 + cosmwasm/scripts/deploy.ts | 4 + cosmwasm/scripts/fill.ts | 1 + cosmwasm/scripts/settle.ts | 1 + 16 files changed, 631 insertions(+), 14 deletions(-) create mode 100644 cosmwasm/packages/gofast/.idea/editor.xml create mode 100644 cosmwasm/packages/gofast/.idea/gofast.iml create mode 100644 cosmwasm/packages/gofast/.idea/modules.xml create mode 100644 cosmwasm/packages/gofast/.idea/vcs.xml create mode 100644 cosmwasm/packages/gofast/.idea/workspace.xml diff --git a/cosmwasm/contracts/fast-transfer-gateway/src/contract.rs b/cosmwasm/contracts/fast-transfer-gateway/src/contract.rs index 6b59fa4..8c7a842 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/src/contract.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/src/contract.rs @@ -42,6 +42,7 @@ pub fn instantiate( token_denom: msg.token_denom, address_prefix: msg.address_prefix, mailbox_addr: msg.mailbox_addr, + hook_addr: msg.hook_addr, }; CONFIG.save(deps.storage, &config)?; diff --git a/cosmwasm/contracts/fast-transfer-gateway/src/execute.rs b/cosmwasm/contracts/fast-transfer-gateway/src/execute.rs index b286b20..961db9d 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/src/execute.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/src/execute.rs @@ -4,7 +4,7 @@ use cosmwasm_std::{ }; use cw_ownable::assert_owner; use go_fast::{gateway::Config, FastTransferOrder}; -use hyperlane::mailbox::{get_default_hook, DispatchMsg, ExecuteMsg as MailboxExecuteMsg}; +use hyperlane::mailbox::{DispatchMsg, ExecuteMsg as MailboxExecuteMsg}; use crate::{ error::{ContractError, ContractResponse}, @@ -114,8 +114,6 @@ pub fn initiate_settlement( let remote_contract_address = remote_contract_address.unwrap(); - let default_hook = get_default_hook(deps.as_ref(), config.mailbox_addr.clone())?; - let settle_orders_message = SettleOrdersMessage { repayment_address, order_ids, @@ -127,7 +125,7 @@ pub fn initiate_settlement( dest_domain: source_domain, recipient_addr: remote_contract_address.clone(), msg_body: settle_orders_message.encode(), - hook: Some(default_hook), + hook: Some(config.hook_addr.clone()), metadata: None, }))?, funds: info.funds, @@ -169,8 +167,6 @@ pub fn initiate_timeout( let remote_contract_address = remote_contract_address.unwrap(); - let default_hook = get_default_hook(deps.as_ref(), config.mailbox_addr.clone())?; - let timeout_orders_message = TimeoutOrdersMessage { order_ids }; let msg = WasmMsg::Execute { @@ -179,7 +175,7 @@ pub fn initiate_timeout( dest_domain: source_domain, recipient_addr: remote_contract_address.clone(), msg_body: timeout_orders_message.encode(), - hook: Some(default_hook), + hook: Some(config.hook_addr.clone()), metadata: None, }))?, funds: info.funds, diff --git a/cosmwasm/contracts/fast-transfer-gateway/src/query.rs b/cosmwasm/contracts/fast-transfer-gateway/src/query.rs index 8eba695..768584c 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/src/query.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/src/query.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{Addr, Coin, Deps, HexBinary, Order, StdError, StdResult}; use go_fast::gateway::{Config, OrderFill, RemoteDomain}; -use hyperlane::mailbox::{get_default_hook, quote_dispatch, DispatchMsg}; +use hyperlane::mailbox::{quote_dispatch, DispatchMsg}; use crate::{ helpers::encode_settle_order_data, @@ -64,13 +64,11 @@ pub fn quote_initiate_settlement( let remote_contract_address = remote_contract_address.unwrap(); - let default_hook = get_default_hook(deps, config.mailbox_addr.clone())?; - let dispatch_msg = DispatchMsg { dest_domain: source_domain, recipient_addr: remote_contract_address.clone(), msg_body: encode_settle_order_data(repayment_address, order_ids), - hook: Some(default_hook), + hook: Some(config.hook_addr.clone()), metadata: None, }; diff --git a/cosmwasm/contracts/fast-transfer-gateway/tests/common/mod.rs b/cosmwasm/contracts/fast-transfer-gateway/tests/common/mod.rs index 419743c..3678044 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/tests/common/mod.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/tests/common/mod.rs @@ -29,6 +29,7 @@ pub fn default_instantiate() -> (OwnedDeps, token_denom: "uusdc".to_string(), address_prefix: "osmo".to_string(), mailbox_addr: "mailbox_contract_address".into(), + hook_addr: "hook_contract_address".into(), }, ) .unwrap(); diff --git a/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_settlement.rs b/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_settlement.rs index 82033f6..2fea198 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_settlement.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_settlement.rs @@ -57,7 +57,7 @@ fn test_initiate_settlement() { ) .unwrap(), hook: Some( - "osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into() + "hook_contract_address".into() ), metadata: None })) @@ -129,7 +129,7 @@ fn test_initiate_settlement_multiple_orders() { ) .unwrap(), hook: Some( - "osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into() + "hook_contract_address".into() ), metadata: None })) diff --git a/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_timeout.rs b/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_timeout.rs index 59ebe6d..e0ceab5 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_timeout.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/tests/test_initiate_timeout.rs @@ -81,7 +81,7 @@ fn test_initiate_timeout() { ) .unwrap(), hook: Some( - "osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into() + "hook_contract_address".into() ), metadata: None })) diff --git a/cosmwasm/contracts/fast-transfer-gateway/tests/test_instantiate.rs b/cosmwasm/contracts/fast-transfer-gateway/tests/test_instantiate.rs index 7134129..6f8cde2 100644 --- a/cosmwasm/contracts/fast-transfer-gateway/tests/test_instantiate.rs +++ b/cosmwasm/contracts/fast-transfer-gateway/tests/test_instantiate.rs @@ -20,6 +20,7 @@ fn test_instantiate() { token_denom: "uusdc".to_string(), address_prefix: "osmo".to_string(), mailbox_addr: "mailbox_contract_address".into(), + hook_addr: "hook_contract_address".into(), local_domain: 1, }; @@ -31,6 +32,7 @@ fn test_instantiate() { assert_eq!(config.token_denom, instantiate_msg.token_denom); assert_eq!(config.address_prefix, instantiate_msg.address_prefix); assert_eq!(config.mailbox_addr, instantiate_msg.mailbox_addr); + assert_eq!(config.hook_addr, instantiate_msg.hook_addr); let local_domain = LOCAL_DOMAIN.load(deps.as_ref().storage).unwrap(); assert_eq!(local_domain, 1); diff --git a/cosmwasm/packages/gofast/.idea/editor.xml b/cosmwasm/packages/gofast/.idea/editor.xml new file mode 100644 index 0000000..55d1bc1 --- /dev/null +++ b/cosmwasm/packages/gofast/.idea/editor.xml @@ -0,0 +1,483 @@ + + + + + \ No newline at end of file diff --git a/cosmwasm/packages/gofast/.idea/gofast.iml b/cosmwasm/packages/gofast/.idea/gofast.iml new file mode 100644 index 0000000..ca5ba2d --- /dev/null +++ b/cosmwasm/packages/gofast/.idea/gofast.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/cosmwasm/packages/gofast/.idea/modules.xml b/cosmwasm/packages/gofast/.idea/modules.xml new file mode 100644 index 0000000..479272f --- /dev/null +++ b/cosmwasm/packages/gofast/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/cosmwasm/packages/gofast/.idea/vcs.xml b/cosmwasm/packages/gofast/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/cosmwasm/packages/gofast/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/cosmwasm/packages/gofast/.idea/workspace.xml b/cosmwasm/packages/gofast/.idea/workspace.xml new file mode 100644 index 0000000..9a5f395 --- /dev/null +++ b/cosmwasm/packages/gofast/.idea/workspace.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1730175640537 + + + + + + \ No newline at end of file diff --git a/cosmwasm/packages/gofast/src/gateway.rs b/cosmwasm/packages/gofast/src/gateway.rs index 67164b0..3d7b403 100644 --- a/cosmwasm/packages/gofast/src/gateway.rs +++ b/cosmwasm/packages/gofast/src/gateway.rs @@ -8,6 +8,7 @@ pub struct Config { pub token_denom: String, pub address_prefix: String, pub mailbox_addr: String, + pub hook_addr: String, } #[cw_serde] @@ -28,6 +29,7 @@ pub struct InstantiateMsg { pub token_denom: String, pub address_prefix: String, pub mailbox_addr: String, + pub hook_addr: String, pub local_domain: u32, } diff --git a/cosmwasm/scripts/deploy.ts b/cosmwasm/scripts/deploy.ts index 84168ae..7387f2c 100644 --- a/cosmwasm/scripts/deploy.ts +++ b/cosmwasm/scripts/deploy.ts @@ -13,6 +13,8 @@ const tokenDenom = "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4"; const mailboxAddr = "osmo1jjf788v9m5pcqghe0ky2hf4llxxe37dqz6609eychuwe3xzzq9eql969h3"; +const hookAddr = + "osmo13yswqchwtmv2ln9uz4w3865sfy5k8x0wg9qrv4vxflxjg0kuwwyqqpvqxz"; const remoteDomain = 42161; const remoteAddr = "000000000000000000000000F7ceC3d387384bB6cE5792dAb161a65cFaCf8aB4"; @@ -21,6 +23,7 @@ interface InstantiateMsg { token_denom: string; address_prefix: string; mailbox_addr: string; + hook_addr: string, remote_domain: number; remote_addr: string; } @@ -57,6 +60,7 @@ async function main() { token_denom: tokenDenom, address_prefix: CHAIN_PREFIX, mailbox_addr: mailboxAddr, + hook_addr: hookAddr, remote_domain: remoteDomain, remote_addr: remoteAddr, }; diff --git a/cosmwasm/scripts/fill.ts b/cosmwasm/scripts/fill.ts index 52e27c7..53f0286 100644 --- a/cosmwasm/scripts/fill.ts +++ b/cosmwasm/scripts/fill.ts @@ -21,6 +21,7 @@ interface InstantiateMsg { token_denom: string; address_prefix: string; mailbox_addr: string; + hook_addr: string; remote_domain: number; remote_addr: string; } diff --git a/cosmwasm/scripts/settle.ts b/cosmwasm/scripts/settle.ts index 97060bd..1fcf2ee 100644 --- a/cosmwasm/scripts/settle.ts +++ b/cosmwasm/scripts/settle.ts @@ -21,6 +21,7 @@ interface InstantiateMsg { token_denom: string; address_prefix: string; mailbox_addr: string; + hook_addr: string; remote_domain: number; remote_addr: string; }