Skip to content

Commit d063adf

Browse files
kiselnkarim-enolga24912
authored
Add migration method to withdraw locked NEAR to OmniBridge (#47)
* Add migration method to withdraw locked NEAR to OmniBridge * Simplify `send_to_omni_bridge` * update wasm * Add payable to `send_to_omni_bridge` * deduct the `attached_deposit` * update wasm --------- Co-authored-by: karim-en <karim.alabtakh@nearone.org> Co-authored-by: Olga Kunyavskaya <olga.kunyavskaya@aurora.dev>
1 parent 0729b53 commit d063adf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

nearBridge/res/near_bridge.wasm

4.53 KB
Binary file not shown.

nearBridge/src/lib.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const VERIFY_LOG_ENTRY_GAS: Gas = Gas(Gas::ONE_TERA.0 * 50);
2929
const WNEAR_DEPOSIT_GAS: Gas = Gas(Gas::ONE_TERA.0 * 10);
3030
const WNEAR_STORAGE_DEPOSIT_GAS: Gas = Gas(Gas::ONE_TERA.0 * 5);
3131
const FT_TRANSFER_CALL_GAS: Gas = Gas(Gas::ONE_TERA.0 * 80);
32+
const FT_TRANSFER_GAS: Gas = Gas(Gas::ONE_TERA.0 * 5);
3233

3334
const WNEAR_STORAGE_KEY: &[u8] = b"wnear";
3435

@@ -211,6 +212,34 @@ impl NearBridge {
211212
}
212213
}
213214

215+
pub fn get_avialable_balance(&self) -> U128 {
216+
U128(
217+
env::account_balance()
218+
- env::attached_deposit()
219+
- env::storage_byte_cost() * env::storage_usage() as u128,
220+
)
221+
}
222+
223+
#[access_control_any(roles(Role::DAO))]
224+
#[payable]
225+
pub fn send_to_omni_bridge(&mut self, omni_bridge: AccountId) -> Promise {
226+
let amount = self.get_avialable_balance().0;
227+
let wnear_account_id = self
228+
.get_wnear_account_id()
229+
.unwrap_or_else(|| env::panic_str("WNear address hasn't been set"));
230+
231+
ext_wnear_token::ext(wnear_account_id.clone())
232+
.with_static_gas(WNEAR_DEPOSIT_GAS)
233+
.with_attached_deposit(amount)
234+
.near_deposit()
235+
.then(
236+
ext_wnear_token::ext(wnear_account_id)
237+
.with_static_gas(FT_TRANSFER_GAS)
238+
.with_attached_deposit(ONE_YOCTO)
239+
.ft_transfer(omni_bridge, amount.into(), None),
240+
)
241+
}
242+
214243
/// Checks whether the provided proof is already used
215244
pub fn is_used_proof(&self, #[serializer(borsh)] proof: Proof) -> bool {
216245
self.used_events.contains(&proof.get_key())
@@ -285,6 +314,13 @@ pub trait ExtWNearToken {
285314
msg: String,
286315
) -> PromiseOrValue<U128>;
287316

317+
fn ft_transfer(
318+
&mut self,
319+
receiver_id: AccountId,
320+
amount: U128,
321+
memo: Option<String>,
322+
) -> PromiseOrValue<U128>;
323+
288324
fn near_deposit(&self);
289325
fn storage_deposit(&self, account_id: AccountId);
290326
}

0 commit comments

Comments
 (0)