Skip to content

Commit

Permalink
fixup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkuo committed Mar 27, 2024
1 parent 5bbb646 commit 4077a62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 5 additions & 3 deletions crates/sui-framework/packages/bridge/sources/bridge.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module bridge::bridge {
#[test_only]
use sui::{hex, test_scenario, test_utils::{assert_eq, destroy}};
#[test_only]
use bridge::{btc::BTC, eth::ETH, message::create_blocklist_message};
use bridge::treasury::{BTC, ETH};
#[test_only]
use bridge::message::create_blocklist_message;

const MESSAGE_VERSION: u8 = 1;

Expand Down Expand Up @@ -193,7 +195,7 @@ module bridge::bridge {
);

// burn / escrow token, unsupported coins will fail in this step
inner.treasury.burn(token, ctx);
inner.treasury.burn(token);

// Store pending bridge request
inner.bridge_records.push_back(message.key(), BridgeRecord {
Expand Down Expand Up @@ -459,7 +461,7 @@ module bridge::bridge {
}

fun execute_update_asset_price(inner: &mut BridgeInner, payload: UpdateAssetPrice) {
inner.limiter.update_asset_notional_price(
inner.treasury.update_asset_notional_price(
payload.update_asset_price_payload_token_id(),
payload.update_asset_price_payload_new_price()
)
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-framework/packages/bridge/sources/limiter.move
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ module bridge::limiter {

// Compute notional amount
// Upcast to u128 to prevent overflow, to not miss out on small amounts.
let value = (self.notional_values[&treasury::token_id<T>()] as u128);
let value = (treasury.notional_value<T>() as u128);
let notional_amount_with_token_multiplier = value * (amount as u128);

// Check if transfer amount exceed limit
// Upscale them to the token's decimal.
if ((record.total_amount as u128) * (treasury::decimal_multiplier<T>(treasury) as u128) + notional_amount_with_token_multiplier > route_limit_adjusted) {
if ((record.total_amount as u128) * (treasury.decimal_multiplier<T>() as u128) + notional_amount_with_token_multiplier > route_limit_adjusted) {
return false
};

Expand Down
5 changes: 3 additions & 2 deletions crates/sui-framework/packages/bridge/sources/message.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

module bridge::message {
use std::ascii::{Self, String};
use sui::bcs::{Self, BCS};

use bridge::chain_ids;
Expand All @@ -10,9 +11,9 @@ module bridge::message {
use bridge::treasury;

#[test_only]
use sui::{address, balance, coin, hex, test_scenario, test_utils::assert_eq};
use sui::{address, balance, coin, hex, test_scenario, test_utils::{assert_eq, destroy}};
#[test_only]
use bridge::{btc::BTC, eth::ETH, treasury::token_id, usdc::USDC};
use bridge::treasury::{BTC, ETH, USDC};

const CURRENT_MESSAGE_VERSION: u8 = 1;
const ECDSA_ADDRESS_LENGTH: u64 = 20;
Expand Down
13 changes: 5 additions & 8 deletions crates/sui-framework/packages/bridge/sources/treasury.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ module bridge::treasury {
use sui::math;
use sui::object;
use sui::object_bag::{Self, ObjectBag};

use bridge::btc::{Self, BTC};
use bridge::eth::{Self, ETH};
use bridge::usdc::{Self, USDC};
use bridge::usdt::{Self, USDT};
use sui::package;
use sui::package::UpgradeCap;
use sui::vec_map;
use sui::vec_map::VecMap;

const EUnsupportedTokenType: u64 = 0;
const EInvalidUpgradeCap: u64 = 1;
Expand Down Expand Up @@ -135,7 +134,6 @@ module bridge::treasury {
}

public(package) fun create(ctx: &mut TxContext): BridgeTreasury {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
BridgeTreasury {
treasuries: object_bag::new(ctx),
supported_tokens: vec_map::empty(),
Expand All @@ -144,8 +142,7 @@ module bridge::treasury {
}
}

public(package) fun burn<T>(self: &mut BridgeTreasury, token: Coin<T>, ctx: &mut TxContext) {
create_treasury_if_not_exist<T>(self, ctx);
public(package) fun burn<T>(self: &mut BridgeTreasury, token: Coin<T>) {
let treasury = &mut self.treasuries[type_name::get<T>()];
coin::burn(treasury, token);
}
Expand Down

0 comments on commit 4077a62

Please sign in to comment.