From 9a62243565a6ac007e9cf42619eec3eba3373bd5 Mon Sep 17 00:00:00 2001 From: Foivos Date: Mon, 18 Nov 2024 16:08:09 +0200 Subject: [PATCH 1/2] expose set_flow limit for the operator --- .changeset/short-bananas-promise.md | 5 +++ move/its/sources/events.move | 15 +++++++ move/its/sources/its.move | 43 +++++++++++++++++++++ move/its/sources/types/coin_management.move | 24 ++++++------ move/its/sources/versioned/its_v0.move | 10 +++++ 5 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 .changeset/short-bananas-promise.md diff --git a/.changeset/short-bananas-promise.md b/.changeset/short-bananas-promise.md new file mode 100644 index 00000000..f5fdbffb --- /dev/null +++ b/.changeset/short-bananas-promise.md @@ -0,0 +1,5 @@ +--- +'@axelar-network/axelar-cgp-sui': patch +--- + +added access to set flow limit on its and a corresponding event diff --git a/move/its/sources/events.move b/move/its/sources/events.move index 8bbb7231..f0c54e7c 100644 --- a/move/its/sources/events.move +++ b/move/its/sources/events.move @@ -48,6 +48,11 @@ public struct UnregisteredCoinReceived has copy, drop { decimals: u8, } +public struct FlowLimitSet has copy, drop { + token_id: TokenId, + flow_limit: u64, +} + // ----------------- // Package Functions // ----------------- @@ -124,3 +129,13 @@ public(package) fun unregistered_coin_received( decimals, }); } + +public(package) fun flow_limit_set( + token_id: TokenId, + flow_limit: u64, +) { + event::emit(FlowLimitSet { + token_id, + flow_limit + }); +} diff --git a/move/its/sources/its.move b/move/its/sources/its.move index 3e76e718..de1447d7 100644 --- a/move/its/sources/its.move +++ b/move/its/sources/its.move @@ -232,6 +232,21 @@ public fun burn_as_distributor( ); } +public fun set_flow_limit( + self: &mut ITS, + channel: &Channel, + token_id: TokenId, + limit: u64, +) { + let value = self.value_mut!(b"mint_to_as_distributor"); + + value.set_flow_limit( + channel, + token_id, + limit, + ); +} + // --------------- // Owner Functions // --------------- @@ -307,6 +322,7 @@ fun version_control(): VersionControl { b"burn_as_distributor", b"set_trusted_addresses", b"register_transaction", + b"set_flow_limit", ].map!(|function_name| function_name.to_ascii_string()), ]) } @@ -827,3 +843,30 @@ fun test_set_trusted_address() { sui::test_utils::destroy(its); sui::test_utils::destroy(owner_cap); } + +#[test] +fun test_set_flow_limit() { + let ctx = &mut tx_context::dummy(); + let mut its = create_for_testing(ctx); + let symbol = b"COIN"; + let decimals = 9; + let limit = 1234; + + let ( + treasury_cap, + coin_metadata, + ) = its::coin::create_treasury_and_metadata(symbol, decimals, ctx); + let coin_info = its::coin_info::from_metadata( + coin_metadata, + ); + let mut coin_management = its::coin_management::new_with_cap(treasury_cap); + + let channel = channel::new(ctx); + coin_management.add_operator(channel.to_address()); + + let token_id = register_coin(&mut its, coin_info, coin_management); + its.set_flow_limit(&channel, token_id, limit); + + sui::test_utils::destroy(its); + channel.destroy(); +} diff --git a/move/its/sources/types/coin_management.move b/move/its/sources/types/coin_management.move index b6197a17..01b8ffe6 100644 --- a/move/its/sources/types/coin_management.move +++ b/move/its/sources/types/coin_management.move @@ -73,19 +73,6 @@ public fun add_operator(self: &mut CoinManagement, operator: address) { self.operator.fill(operator); } -/// Adds a rate limit to the `CoinManagement`. -/// Note that this rate limit will be calculated for the remote decimals of the -/// token, not for the native decimals. -/// To be used by the designated operator of the contract. -public fun set_flow_limit( - self: &mut CoinManagement, - channel: &Channel, - flow_limit: u64, -) { - assert!(self.operator.contains(&channel.to_address()), ENotOperator); - self.flow_limit.set_flow_limit(flow_limit); -} - // === Protected Methods === /// Takes the given amount of Coins from user. Returns the amount that the ITS @@ -134,6 +121,17 @@ public(package) fun mint( public(package) fun burn(self: &mut CoinManagement, balance: Balance) { self.treasury_cap.borrow_mut().supply_mut().decrease_supply(balance); } + +/// Adds a rate limit to the `CoinManagement`. +public(package) fun set_flow_limit( + self: &mut CoinManagement, + channel: &Channel, + flow_limit: u64, +) { + assert!(self.operator.contains(&channel.to_address()), ENotOperator); + self.flow_limit.set_flow_limit(flow_limit); +} + // === Views === /// Checks if the given address is a `distributor`. diff --git a/move/its/sources/versioned/its_v0.move b/move/its/sources/versioned/its_v0.move index be83fd93..e8d50f06 100644 --- a/move/its/sources/versioned/its_v0.move +++ b/move/its/sources/versioned/its_v0.move @@ -494,6 +494,16 @@ public(package) fun burn_as_distributor( coin_management.burn(coin.into_balance()); } +public(package) fun set_flow_limit( + self: &mut ITS_v0, + channel: &Channel, + token_id: TokenId, + limit: u64, +) { + self.coin_management_mut(token_id).set_flow_limit(channel, limit); + events::flow_limit_set(token_id, limit); +} + // ----------------- // Private Functions // ----------------- From 4f9d8017bd7d1897b67993d6523ee883e3e5b156 Mon Sep 17 00:00:00 2001 From: Foivos Date: Wed, 20 Nov 2024 14:32:47 +0200 Subject: [PATCH 2/2] Update move/its/sources/its.move Co-authored-by: Milap Sheth --- move/its/sources/its.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/move/its/sources/its.move b/move/its/sources/its.move index 9b65bb15..38fd761b 100644 --- a/move/its/sources/its.move +++ b/move/its/sources/its.move @@ -238,7 +238,7 @@ public fun set_flow_limit( token_id: TokenId, limit: u64, ) { - let value = self.value_mut!(b"mint_to_as_distributor"); + let value = self.value_mut!(b"set_flow_limit"); value.set_flow_limit( channel,