Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movement voyager integration #3002

Merged
merged 6 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ fbef3d1a-8b84-4eb5-937c-06f78b1a1347
db.sqlite
db.sqlite3*

*/.movement
move/*/build
.tsup
87 changes: 82 additions & 5 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [

"generated/rust/contracts",
"generated/rust/protos",
"generated/rust/aptos-move-ibc",

"hubble",

Expand Down Expand Up @@ -80,9 +81,11 @@ members = [

"voyager/modules/client/cometbls",
"voyager/modules/client/ethereum",
"voyager/modules/client/movement",

"voyager/modules/consensus/cometbls",
"voyager/modules/consensus/ethereum",
"voyager/modules/consensus/movement",

"voyager/modules/transaction/cosmos-sdk",
"voyager/modules/transaction/ethereum",
Expand Down Expand Up @@ -115,6 +118,7 @@ lto = "thin"
opt-level = 3

[workspace.dependencies]
aptos-move-ibc = { path = "generated/rust/aptos-move-ibc", default-features = false }
aptos-verifier = { path = "lib/aptos-verifier", default-features = false }
arbitrum-verifier = { path = "lib/arbitrum-verifier", default-features = false }
beacon-api = { path = "lib/beacon-api", default-features = false }
Expand Down Expand Up @@ -173,6 +177,7 @@ aptos-rest-client = { git = "https://github.com/unionlabs/aptos-core" }
aptos-types = { git = "https://github.com/unionlabs/aptos-core" }
axum = { version = "0.6.20", default-features = false }
base64 = { version = "0.21", default-features = false }
bcs = { version = "0.1.6", default-features = false }
bip32 = { version = "0.5.0", default-features = false }
bitvec = { version = "1.0.1", default-features = false }
borsh = { version = "1.5.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ucs00-pingpong/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn execute(
match msg {
ExecuteMsg::Initiate { channel_id, packet } => {
let config = CONFIG.load(deps.storage)?;
let ibc_packet = packet.reverse(&config, env.block.height, channel_id);
let ibc_packet = packet.reverse(&config, env.block.time.nanos(), channel_id);
Ok(Response::default().add_message(ibc_packet))
}
}
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ucs00-pingpong/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn do_ibc_packet_receive(
packet: UCS00PingPong,
) -> Result<IbcReceiveResponse, ContractError> {
let config = CONFIG.load(deps.storage)?;
let ibc_packet = packet.reverse(&config, env.block.height, dest_channel_id);
let ibc_packet = packet.reverse(&config, env.block.time.nanos(), dest_channel_id);
let res = IbcReceiveResponse::new()
.set_ack(ack_success())
.add_message(ibc_packet)
Expand Down
40 changes: 15 additions & 25 deletions cosmwasm/ucs00-pingpong/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,49 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{IbcMsg, IbcTimeout, IbcTimeoutBlock};
use cosmwasm_std::{IbcMsg, IbcTimeout, Timestamp};
use ethabi::{ParamType, Token};

use crate::{state::Config, ContractError};

#[cw_serde]
pub struct UCS00PingPong {
pub ping: bool,
pub counterparty_timeout_revision_number: u64,
pub counterparty_timeout_revision_height: u64,
// /// in seconds
// pub counterparty_timeout: u64,
}

impl UCS00PingPong {
pub fn decode(bz: impl AsRef<[u8]>) -> Result<Self, ContractError> {
let values = ethabi::decode(
&[ParamType::Bool, ParamType::Int(64), ParamType::Int(64)],
bz.as_ref(),
)
.map_err(|_| ContractError::EthAbiDecoding)?;
let values = ethabi::decode(&[ParamType::Bool /*ParamType::Int(64)*/], bz.as_ref())
.map_err(|_| ContractError::EthAbiDecoding)?;
match &values[..] {
&[Token::Bool(ping), Token::Int(timeout_revision_number), Token::Int(timeout_revision_height)] => {
Ok(UCS00PingPong {
ping,
counterparty_timeout_revision_number: timeout_revision_number.as_u64(),
counterparty_timeout_revision_height: timeout_revision_height.as_u64(),
})
}
&[Token::Bool(ping),/* Token::Int(timeout) */] => Ok(UCS00PingPong {
ping,
// counterparty_timeout: timeout.as_u64(),
}),
_ => Err(ContractError::EthAbiDecoding),
}
}

pub fn encode(&self) -> Vec<u8> {
ethabi::encode(&[
Token::Bool(self.ping),
Token::Int(self.counterparty_timeout_revision_number.into()),
Token::Int(self.counterparty_timeout_revision_height.into()),
// Token::Int(self.counterparty_timeout.into()),
])
}
}

impl UCS00PingPong {
pub fn reverse(&self, config: &Config, current_block: u64, channel_id: String) -> IbcMsg {
pub fn reverse(&self, config: &Config, current_timestamp: u64, channel_id: String) -> IbcMsg {
let counterparty_packet = UCS00PingPong {
ping: !self.ping,
counterparty_timeout_revision_number: config.revision_number,
counterparty_timeout_revision_height: config.number_of_block_before_pong_timeout
+ current_block,
// counterparty_timeout: config.seconds_before_timeout * 1_000_000_000 + current_timestamp,
};
IbcMsg::SendPacket {
channel_id,
data: counterparty_packet.encode().into(),
timeout: IbcTimeout::with_block(IbcTimeoutBlock {
revision: self.counterparty_timeout_revision_number,
height: self.counterparty_timeout_revision_height,
}),
timeout: IbcTimeout::with_timestamp(Timestamp::from_nanos(
current_timestamp + config.seconds_before_timeout * 1_000_000_000,
)),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions cosmwasm/ucs00-pingpong/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use cw_storage_plus::Item;

#[cw_serde]
pub struct Config {
pub number_of_block_before_pong_timeout: u64,
pub revision_number: u64,
pub seconds_before_timeout: u64,
}

pub const CONFIG: Item<Config> = Item::new("config");
2 changes: 1 addition & 1 deletion cosmwasm/ucs01-relay-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ mod tests {

let parsed = serde_json_wasm::from_str::<Memo>(memo).expect("works");

assert_eq!(parsed, Memo::None {})
assert_eq!(parsed, Memo::None {});
}
}
1 change: 1 addition & 0 deletions cosmwasm/ucs01-relay/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ impl<'a> TransferProtocol for Ucs01Protocol<'a> {
}

#[cfg(test)]
#[allow(deprecated)] // TODO: Remove usage of mock_info
aeryz marked this conversation as resolved.
Show resolved Hide resolved
mod tests {
use cosmwasm_std::{
testing::{message_info, mock_dependencies, mock_env},
Expand Down
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ pedersen
permissioned
permissionless
permissionlessly
persistable
pflag
phang
pingpong
Expand Down
13 changes: 13 additions & 0 deletions generated/rust/aptos-move-ibc/Cargo.toml

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

Loading
Loading