Skip to content

Commit

Permalink
Merge pull request #4 from skip-mev/df/cw-gateway-specify-mailbox-hoo…
Browse files Browse the repository at this point in the history
…k-addr

[API-3499] Invoke configured hook address when dispatching hyperlane message
dhfang authored Oct 30, 2024

Verified

This commit was signed with the committer’s verified signature.
vxern Dorian M. Oszczęda
2 parents 92eebe5 + 10878dd commit 0258c34
Showing 16 changed files with 631 additions and 16 deletions.
1 change: 1 addition & 0 deletions cosmwasm/contracts/fast-transfer-gateway/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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)?;
10 changes: 3 additions & 7 deletions cosmwasm/contracts/fast-transfer-gateway/src/execute.rs
Original file line number Diff line number Diff line change
@@ -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,
6 changes: 2 additions & 4 deletions cosmwasm/contracts/fast-transfer-gateway/src/query.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ pub fn default_instantiate() -> (OwnedDeps<MemoryStorage, MockApi, MockQuerier>,
token_denom: "uusdc".to_string(),
address_prefix: "osmo".to_string(),
mailbox_addr: "mailbox_contract_address".into(),
hook_addr: "hook_contract_address".into(),
},
)
.unwrap();
Original file line number Diff line number Diff line change
@@ -56,9 +56,7 @@ fn test_initiate_settlement() {
"00b8789db0c2da6b48ff31471423dc7ffa2386902c666fa2691e636c29b539936a1234"
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
),
hook: Some("hook_contract_address".into()),
metadata: None
}))
.unwrap(),
@@ -129,7 +127,7 @@ fn test_initiate_settlement_multiple_orders() {
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
"hook_contract_address".into()
),
metadata: None
}))
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ fn test_initiate_timeout() {
)
.unwrap(),
hook: Some(
"osmo12pvc4v625ewl34uqqgm3ezw76durxlky5j4guz8kvhal7em3e5wqz7cnla".into()
"hook_contract_address".into()
),
metadata: None
}))
Original file line number Diff line number Diff line change
@@ -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);
483 changes: 483 additions & 0 deletions cosmwasm/packages/gofast/.idea/editor.xml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions cosmwasm/packages/gofast/.idea/gofast.iml
8 changes: 8 additions & 0 deletions cosmwasm/packages/gofast/.idea/modules.xml
6 changes: 6 additions & 0 deletions cosmwasm/packages/gofast/.idea/vcs.xml
104 changes: 104 additions & 0 deletions cosmwasm/packages/gofast/.idea/workspace.xml
2 changes: 2 additions & 0 deletions cosmwasm/packages/gofast/src/gateway.rs
Original file line number Diff line number Diff line change
@@ -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,
}

4 changes: 4 additions & 0 deletions cosmwasm/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -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,
};
1 change: 1 addition & 0 deletions cosmwasm/scripts/fill.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ interface InstantiateMsg {
token_denom: string;
address_prefix: string;
mailbox_addr: string;
hook_addr: string;
remote_domain: number;
remote_addr: string;
}
1 change: 1 addition & 0 deletions cosmwasm/scripts/settle.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ interface InstantiateMsg {
token_denom: string;
address_prefix: string;
mailbox_addr: string;
hook_addr: string;
remote_domain: number;
remote_addr: string;
}

0 comments on commit 0258c34

Please sign in to comment.