Skip to content

Commit

Permalink
finish withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
olga24912 committed Jan 23, 2025
1 parent b5aa15e commit c2770e5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion near/omni-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use omni_types::prover_args::VerifyProofArgs;
use omni_types::prover_result::ProverResult;
use omni_types::{
BasicMetadata, ChainKind, Fee, InitTransferMsg, MetadataPayload, Nonce, OmniAddress,
PayloadType, SignRequest, TransferId, TransferMessage, TransferMessagePayload, UpdateFee,
PayloadType, SignRequest, TransferId, TransferMessage, TransferMessagePayload, UpdateFee, H160,
};
use std::str::FromStr;
use storage::{Decimals, TransferMessageStorage, TransferMessageStorageValue, NEP141_DEPOSIT};

mod errors;
Expand All @@ -47,6 +48,7 @@ const BIND_TOKEN_CALLBACK_GAS: Gas = Gas::from_tgas(25);
const BIND_TOKEN_REFUND_GAS: Gas = Gas::from_tgas(5);
const FT_TRANSFER_CALL_GAS: Gas = Gas::from_tgas(125);
const FT_TRANSFER_GAS: Gas = Gas::from_tgas(5);
const UPDATE_CONTROLLER_GAS: Gas = Gas::from_tgas(5);
const WNEAR_WITHDRAW_GAS: Gas = Gas::from_tgas(10);
const STORAGE_BALANCE_OF_GAS: Gas = Gas::from_tgas(3);
const STORAGE_DEPOSIT_GAS: Gas = Gas::from_tgas(3);
Expand Down Expand Up @@ -83,6 +85,7 @@ pub enum Role {
UpgradableCodeDeployer,
MetadataManager,
UnrestrictedRelayer,
TokenControllerUpdater,
}

#[ext_contract(ext_token)]
Expand Down Expand Up @@ -125,6 +128,8 @@ pub trait ExtToken {
decimals: Option<u8>,
icon: Option<String>,
);

fn update_controller(&mut self);
}

#[ext_contract(ext_signer)]
Expand Down Expand Up @@ -803,6 +808,43 @@ impl Contract {
Self::refund(predecessor_account_id, refund_amount);
}

pub fn finish_withdraw(
&mut self,
#[serializer(borsh)] sender_id: AccountId,
#[serializer(borsh)] amount: u128,
#[serializer(borsh)] recipient: String,
) {
let token_id = env::predecessor_account_id();
require!(self.deployed_tokens.contains(&token_id));
let parsed_msg = InitTransferMsg {
recipient: OmniAddress::Eth(
H160::from_str(&recipient).sdk_expect("Error on recipient parsing"),
),
fee: U128(0),
native_token_fee: U128(0),
};

self.current_origin_nonce += 1;
let destination_nonce = self.get_next_destination_nonce(ChainKind::Eth);

let transfer_message = TransferMessage {
origin_nonce: self.current_origin_nonce,
token: OmniAddress::Near(token_id.clone()),
amount: U128(amount),
recipient: parsed_msg.recipient,
fee: Fee {
fee: parsed_msg.fee,
native_fee: parsed_msg.native_token_fee,
},
sender: OmniAddress::Near(sender_id.clone()),
msg: String::new(),
destination_nonce,
};

let _ = self.add_transfer_message(transfer_message.clone(), sender_id.clone());
env::log_str(&OmniBridgeEvent::InitTransferEvent { transfer_message }.to_log_string());
}

pub fn get_token_address(
&self,
chain_kind: ChainKind,
Expand Down Expand Up @@ -912,6 +954,18 @@ impl Contract {
pub fn get_mpc_account(&self) -> AccountId {
self.mpc_signer.clone()
}

#[access_control_any(roles(Role::DAO, Role::TokenControllerUpdater))]
pub fn update_tokens_controller(
&self,
#[serializer(borsh)] tokens_accounts_id: Vec<AccountId>,
) {
for token_id in tokens_accounts_id {
ext_token::ext(token_id)
.with_static_gas(UPDATE_CONTROLLER_GAS)
.update_controller();
}
}
}

impl Contract {
Expand Down
2 changes: 1 addition & 1 deletion near/omni-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use omni_ft::{MetadataManagment, MintAndBurn, UpgradeAndMigrate};
use omni_types::{BasicMetadata, OmniAddress};
const OUTER_UPGRADE_GAS: Gas = Gas::from_tgas(15);
const NO_DEPOSIT: NearToken = NearToken::from_yoctonear(0);
const CURRENT_STATE_VERSION: u32 = 1;
const CURRENT_STATE_VERSION: u32 = 3;

pub mod omni_ft;

Expand Down
Binary file modified near/res/omni_bridge.wasm
Binary file not shown.
Binary file modified near/res/omni_token.wasm
Binary file not shown.
Binary file modified near/res/token_deployer.wasm
Binary file not shown.

0 comments on commit c2770e5

Please sign in to comment.