diff --git a/precompile/binaries/minlib/cosmos.mv b/precompile/binaries/minlib/cosmos.mv index 4e4bf006..02aab079 100644 Binary files a/precompile/binaries/minlib/cosmos.mv and b/precompile/binaries/minlib/cosmos.mv differ diff --git a/precompile/binaries/stdlib/cosmos.mv b/precompile/binaries/stdlib/cosmos.mv index 4e4bf006..02aab079 100644 Binary files a/precompile/binaries/stdlib/cosmos.mv and b/precompile/binaries/stdlib/cosmos.mv differ diff --git a/precompile/modules/initia_stdlib/sources/cosmos.move b/precompile/modules/initia_stdlib/sources/cosmos.move index 68c1dac3..b0b5f34a 100644 --- a/precompile/modules/initia_stdlib/sources/cosmos.move +++ b/precompile/modules/initia_stdlib/sources/cosmos.move @@ -19,25 +19,49 @@ module initia_std::cosmos { const EINVALID_CALLBACK_ID: u64 = 1; const EINVALID_CALLBACK_FID: u64 = 2; - struct VoteRequest has copy, drop { + public entry fun stargate(sender: &signer, data: vector) { + stargate_internal(signer::address_of(sender), data, disallow_failure()) + } + + /// Stargate message with options + /// + /// Options: + /// - allow_failure() + /// - disallow_failure() + /// - allow_failure_with_callback(id: u64, fid: String) + /// - disallow_failure_with_callback(id: u64, fid: String) + /// + /// The callback function should be defined with the following signature: + /// ```rust + /// public fun callback(id: u64, success: bool); + /// public fun callback(sender: &signer, id: u64, success: bool); + /// ``` + /// + public fun stargate_with_options( + sender: &signer, data: vector, options: Options + ) { + stargate_internal(signer::address_of(sender), data, options) + } + + struct VoteRequestV2 has copy, drop { _type_: String, proposal_id: u64, voter: String, - option: u64, + option: u32, metadata: String } - public entry fun stargate_vote( + public entry fun stargate_vote_v2( sender: &signer, proposal_id: u64, voter: String, - option: u64, + option: u32, metadata: String ) { stargate( sender, json::marshal( - &VoteRequest { + &VoteRequestV2 { _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter, @@ -48,28 +72,30 @@ module initia_std::cosmos { ); } - public entry fun stargate(sender: &signer, data: vector) { - stargate_internal(signer::address_of(sender), data, disallow_failure()) + #[deprecated] + struct VoteRequest has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u64, + metadata: String } - /// Stargate message with options - /// - /// Options: - /// - allow_failure() - /// - disallow_failure() - /// - allow_failure_with_callback(id: u64, fid: String) - /// - disallow_failure_with_callback(id: u64, fid: String) - /// - /// The callback function should be defined with the following signature: - /// ```rust - /// public fun callback(id: u64, success: bool); - /// public fun callback(sender: &signer, id: u64, success: bool); - /// ``` - /// - public fun stargate_with_options( - sender: &signer, data: vector, options: Options + #[deprecated] + public entry fun stargate_vote( + sender: &signer, + proposal_id: u64, + voter: String, + option: u64, + metadata: String ) { - stargate_internal(signer::address_of(sender), data, options) + stargate_vote_v2( + sender, + proposal_id, + voter, + option as u32, + metadata + ) } struct ExecuteRequest has copy, drop { @@ -525,11 +551,11 @@ module initia_std::cosmos { let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); @@ -547,11 +573,11 @@ module initia_std::cosmos { let metadata = utf8(b"metadata"); let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); diff --git a/precompile/modules/initia_stdlib/sources/minitswap.move b/precompile/modules/initia_stdlib/sources/minitswap.move index 64bd12d4..687c03fb 100644 --- a/precompile/modules/initia_stdlib/sources/minitswap.move +++ b/precompile/modules/initia_stdlib/sources/minitswap.move @@ -2464,7 +2464,8 @@ module initia_std::minitswap { vector::append(&mut hex_input, table_key::encode_u256(0x60)); // start position of denom: padded(0x60) vector::append(&mut hex_input, table_key::encode_u256((amount as u256))); vector::append( - &mut hex_input, table_key::encode_u256((0x60 + 32 + denom_bytes_len as u256)) + &mut hex_input, + table_key::encode_u256((0x60 + 32 + denom_bytes_len as u256)) ); // start position of receiver vector::append( &mut hex_input, diff --git a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move index cef30126..8a1b22cb 100644 --- a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move +++ b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move @@ -43,7 +43,10 @@ module cafe::ibc_transfer_tests_helpers { struct OnTimeoutResponse has key {} public fun store_on_callback_request( - sender: address, amount: u64, expected_result: bool, id: u64 + sender: address, + amount: u64, + expected_result: bool, + id: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( @@ -71,7 +74,10 @@ module cafe::ibc_transfer_tests_helpers { } public fun store_on_ack_request( - id: u64, expected_result: bool, sender: address, amount: u64 + id: u64, + expected_result: bool, + sender: address, + amount: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( diff --git a/precompile/modules/minitia_stdlib/sources/address.move b/precompile/modules/minitia_stdlib/sources/address.move index 3b371687..9c3274dd 100644 --- a/precompile/modules/minitia_stdlib/sources/address.move +++ b/precompile/modules/minitia_stdlib/sources/address.move @@ -82,7 +82,7 @@ module minitia_std::address { assert!(addr == from_sdk(addr_sdk), 0) } - // hex string <> address + // hex string <> address native public fun to_string(addr: address): String; native public fun from_string(addr_str: String): address; diff --git a/precompile/modules/minitia_stdlib/sources/cosmos.move b/precompile/modules/minitia_stdlib/sources/cosmos.move index 62d44bd5..0f1bbf31 100644 --- a/precompile/modules/minitia_stdlib/sources/cosmos.move +++ b/precompile/modules/minitia_stdlib/sources/cosmos.move @@ -19,35 +19,6 @@ module minitia_std::cosmos { const EINVALID_CALLBACK_ID: u64 = 1; const EINVALID_CALLBACK_FID: u64 = 2; - struct VoteRequest has copy, drop { - _type_: String, - proposal_id: u64, - voter: String, - option: u64, - metadata: String - } - - public entry fun stargate_vote( - sender: &signer, - proposal_id: u64, - voter: String, - option: u64, - metadata: String - ) { - stargate( - sender, - json::marshal( - &VoteRequest { - _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), - proposal_id, - voter, - option, - metadata - } - ) - ); - } - public entry fun stargate(sender: &signer, data: vector) { stargate_internal(signer::address_of(sender), data, disallow_failure()) } @@ -82,6 +53,61 @@ module minitia_std::cosmos { args: vector // base64 encoded } + struct VoteRequestV2 has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u32, + metadata: String + } + + public entry fun stargate_vote_v2( + sender: &signer, + proposal_id: u64, + voter: String, + option: u32, + metadata: String + ) { + stargate( + sender, + json::marshal( + &VoteRequestV2 { + _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), + proposal_id, + voter, + option, + metadata + } + ) + ); + } + + #[deprecated] + struct VoteRequest has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u64, + metadata: String + } + + #[deprecated] + public entry fun stargate_vote( + sender: &signer, + proposal_id: u64, + voter: String, + option: u64, + metadata: String + ) { + stargate_vote_v2( + sender, + proposal_id, + voter, + option as u32, + metadata + ) + } + public entry fun move_execute( sender: &signer, module_address: address, @@ -525,11 +551,11 @@ module minitia_std::cosmos { let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); @@ -547,11 +573,11 @@ module minitia_std::cosmos { let metadata = utf8(b"metadata"); let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); diff --git a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move index cef30126..8a1b22cb 100644 --- a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move +++ b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move @@ -43,7 +43,10 @@ module cafe::ibc_transfer_tests_helpers { struct OnTimeoutResponse has key {} public fun store_on_callback_request( - sender: address, amount: u64, expected_result: bool, id: u64 + sender: address, + amount: u64, + expected_result: bool, + id: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( @@ -71,7 +74,10 @@ module cafe::ibc_transfer_tests_helpers { } public fun store_on_ack_request( - id: u64, expected_result: bool, sender: address, amount: u64 + id: u64, + expected_result: bool, + sender: address, + amount: u64 ) { let chain_signer = create_signer_for_test(@std); move_to(