Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/fix-its-intercha…
Browse files Browse the repository at this point in the history
…in-transfer-event
  • Loading branch information
Foivos committed Nov 20, 2024
2 parents adc67e5 + cd52fed commit 3cbeb9f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 13 deletions.
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 @@ -128,6 +133,16 @@ 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
});
}

// ---------
// Test Only
Expand Down
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 @@ -847,6 +863,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 @@ -478,6 +478,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

0 comments on commit 3cbeb9f

Please sign in to comment.