diff --git a/near/omni-bridge/src/lib.rs b/near/omni-bridge/src/lib.rs index 6cc933f8..3dfce780 100644 --- a/near/omni-bridge/src/lib.rs +++ b/near/omni-bridge/src/lib.rs @@ -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; @@ -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); @@ -83,6 +85,7 @@ pub enum Role { UpgradableCodeDeployer, MetadataManager, UnrestrictedRelayer, + TokenControllerUpdater, } #[ext_contract(ext_token)] @@ -125,6 +128,8 @@ pub trait ExtToken { decimals: Option, icon: Option, ); + + fn update_controller(&mut self); } #[ext_contract(ext_signer)] @@ -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, @@ -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, + ) { + for token_id in tokens_accounts_id { + ext_token::ext(token_id) + .with_static_gas(UPDATE_CONTROLLER_GAS) + .update_controller(); + } + } } impl Contract { diff --git a/near/omni-token/src/lib.rs b/near/omni-token/src/lib.rs index 4a7852c9..114c8127 100644 --- a/near/omni-token/src/lib.rs +++ b/near/omni-token/src/lib.rs @@ -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; diff --git a/near/res/omni_bridge.wasm b/near/res/omni_bridge.wasm index 35019648..c6ac633b 100755 Binary files a/near/res/omni_bridge.wasm and b/near/res/omni_bridge.wasm differ diff --git a/near/res/omni_token.wasm b/near/res/omni_token.wasm index c5058897..20c09814 100755 Binary files a/near/res/omni_token.wasm and b/near/res/omni_token.wasm differ diff --git a/near/res/token_deployer.wasm b/near/res/token_deployer.wasm index b4ce504f..abfe39af 100755 Binary files a/near/res/token_deployer.wasm and b/near/res/token_deployer.wasm differ