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

feat(its)!: expose set_flow limit for the operator and add a corresponding event #203

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/short-bananas-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': patch
---

added access to set flow limit on its and a corresponding event
15 changes: 15 additions & 0 deletions move/its/sources/events.move
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public struct UnregisteredCoinReceived<phantom T> has copy, drop {
decimals: u8,
}

public struct FlowLimitSet<phantom T> has copy, drop {
token_id: TokenId,
flow_limit: u64,
}

// -----------------
// Package Functions
// -----------------
Expand Down Expand Up @@ -124,3 +129,13 @@ public(package) fun unregistered_coin_received<T>(
decimals,
});
}

public(package) fun flow_limit_set<T>(
token_id: TokenId,
flow_limit: u64,
) {
event::emit(FlowLimitSet<T> {
token_id,
flow_limit
});
}
43 changes: 43 additions & 0 deletions move/its/sources/its.move
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ public fun burn_as_distributor<T>(
);
}

public fun set_flow_limit<T>(
self: &mut ITS,
channel: &Channel,
token_id: TokenId,
limit: u64,
) {
let value = self.value_mut!(b"set_flow_limit");

value.set_flow_limit<T>(
channel,
token_id,
limit,
);
}

// ---------------
// Owner Functions
// ---------------
Expand Down Expand Up @@ -308,6 +323,7 @@ fun version_control(): VersionControl {
b"set_trusted_addresses",
b"remove_trusted_addresses",
b"register_transaction",
b"set_flow_limit",
].map!(|function_name| function_name.to_ascii_string()),
])
}
Expand Down Expand Up @@ -830,6 +846,33 @@ fun test_set_trusted_address() {
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>(
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<COIN>(&channel, token_id, limit);

sui::test_utils::destroy(its);
channel.destroy();
}

#[test]
fun test_init() {
let mut ts = sui::test_scenario::begin(@0x0);
Expand Down
24 changes: 11 additions & 13 deletions move/its/sources/types/coin_management.move
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@ public fun add_operator<T>(self: &mut CoinManagement<T>, 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<T>(
self: &mut CoinManagement<T>,
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
Expand Down Expand Up @@ -134,6 +121,17 @@ public(package) fun mint<T>(
public(package) fun burn<T>(self: &mut CoinManagement<T>, balance: Balance<T>) {
self.treasury_cap.borrow_mut().supply_mut().decrease_supply(balance);
}

/// Adds a rate limit to the `CoinManagement`.
public(package) fun set_flow_limit<T>(
self: &mut CoinManagement<T>,
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`.
Expand Down
10 changes: 10 additions & 0 deletions move/its/sources/versioned/its_v0.move
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ public(package) fun burn_as_distributor<T>(
coin_management.burn(coin.into_balance());
}

public(package) fun set_flow_limit<T>(
self: &mut ITS_v0,
channel: &Channel,
token_id: TokenId,
limit: u64,
) {
self.coin_management_mut<T>(token_id).set_flow_limit(channel, limit);
events::flow_limit_set<T>(token_id, limit);
}

// -----------------
// Private Functions
// -----------------
Expand Down