Skip to content

Commit

Permalink
Change storage deposit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Jul 12, 2023
1 parent 3f5295c commit 27b21fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
26 changes: 14 additions & 12 deletions bridge-token-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,8 @@ impl BridgeTokenFactory {

let required_deposit = self.record_proof(&proof);

assert!(
env::attached_deposit()
>= required_deposit + self.bridge_token_storage_deposit_required
);

let Recipient { target, message } = parse_recipient(new_owner_id);

env::log_str(&format!(
"Finish deposit. Target:{} Message:{:?}",
target, message
));

let token = EthAddressHex(token);
let amount_to_transfer: u128;
let fee_amount = self.calculate_deposit_fee_amount(
Expand All @@ -421,10 +411,21 @@ impl BridgeTokenFactory {
);
amount_to_transfer = amount - fee_amount;

let multiplier = if fee_amount > 0 { 1 } else { 2 };
require!(
env::attached_deposit()
>= required_deposit + self.bridge_token_storage_deposit_required * multiplier
);

env::log_str(&format!(
"Finish deposit. Target:{} Message:{:?}",
target, message
));

match message {
Some(message) => ext_bridge_token::ext(self.get_bridge_token_account_id(&token))
.with_static_gas(MINT_GAS)
.with_attached_deposit(env::attached_deposit() - required_deposit)
.with_attached_deposit(self.bridge_token_storage_deposit_required)
.mint(env::current_account_id(), amount.into())
.then(
ext_bridge_token::ext(self.get_bridge_token_account_id(&token))
Expand All @@ -436,12 +437,13 @@ impl BridgeTokenFactory {
let mint_target_promise =
ext_bridge_token::ext(self.get_bridge_token_account_id(&token))
.with_static_gas(MINT_GAS)
.with_attached_deposit(env::attached_deposit() - required_deposit)
.with_attached_deposit(self.bridge_token_storage_deposit_required)
.mint(target, amount_to_transfer.into());

if fee_amount > 0 {
mint_target_promise.then(
ext_bridge_token::ext(self.get_bridge_token_account_id(&token))
.with_attached_deposit(self.bridge_token_storage_deposit_required)
.with_static_gas(MINT_GAS)
.mint(env::current_account_id(), fee_amount.into()),
)
Expand Down
5 changes: 1 addition & 4 deletions bridge-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ impl BridgeToken {
"Only the factory account can init this contract"
);

let mut token = FungibleToken::new(b"t".to_vec());
token.internal_register_account(&env::predecessor_account_id());

Self {
controller: env::predecessor_account_id(),
token,
token: FungibleToken::new(b"t".to_vec()),
name: String::default(),
symbol: String::default(),
reference: String::default(),
Expand Down
Binary file modified res/bridge_token.wasm
Binary file not shown.
Binary file modified res/bridge_token_factory.wasm
Binary file not shown.

0 comments on commit 27b21fc

Please sign in to comment.