Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ci #163

Merged
merged 11 commits into from
Feb 2, 2025
43 changes: 30 additions & 13 deletions near/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ near-plugins = { git = "https://github.com/aurora-is-near/near-plugins", tag = "
omni-types = { path = "omni-types" }
strum_macros = "0.26"
near-workspaces = "0.16.0"
num_enum = "0.7.3"
tokio = "1.40"
anyhow = "1"
schemars = "0.8"
Expand All @@ -45,6 +46,3 @@ ethereum-types = { version = "0.15.1", default-features = false, features = ["rl
rlp = "0.6"
sha3 = "0.10.0"
rstest = "0.24.0"

[patch.crates-io]
cargo-near-build = { git = "https://github.com/near/cargo-near", rev = "2851dc60945bb9da25b38bd46b3ba7b445db33d6" }
28 changes: 19 additions & 9 deletions near/omni-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ impl Contract {
#[payable]
pub fn add_deployed_tokens(&mut self, tokens: Vec<(OmniAddress, AccountId)>) {
require!(
env::attached_deposit() >= NEP141_DEPOSIT.saturating_mul(tokens.len() as u128),
env::attached_deposit()
>= NEP141_DEPOSIT.saturating_mul(tokens.len().try_into().sdk_expect("ERR_CAST")),
"ERR_NOT_ENOUGH_ATTACHED_DEPOSIT"
);

Expand Down Expand Up @@ -944,8 +945,11 @@ impl Contract {

let mut storage_deposit_action_index: usize = 0;
require!(
Self::check_storage_balance_result((storage_deposit_action_index + 1) as u64)
&& storage_deposit_actions[storage_deposit_action_index].account_id == recipient
Self::check_storage_balance_result(
(storage_deposit_action_index + 1)
.try_into()
.sdk_expect("ERR_CAST")
) && storage_deposit_actions[storage_deposit_action_index].account_id == recipient
&& storage_deposit_actions[storage_deposit_action_index].token_id == token,
"STORAGE_ERR: The transfer recipient is omitted"
);
Expand Down Expand Up @@ -997,9 +1001,12 @@ impl Contract {

if transfer_message.fee.fee.0 > 0 {
require!(
Self::check_storage_balance_result((storage_deposit_action_index + 1) as u64)
&& storage_deposit_actions[storage_deposit_action_index].account_id
== predecessor_account_id
Self::check_storage_balance_result(
(storage_deposit_action_index + 1)
.try_into()
.sdk_expect("ERR_CAST")
) && storage_deposit_actions[storage_deposit_action_index].account_id
== predecessor_account_id
&& storage_deposit_actions[storage_deposit_action_index].token_id == token,
"STORAGE_ERR: The fee recipient is omitted"
);
Expand Down Expand Up @@ -1031,9 +1038,12 @@ impl Contract {
let native_token_id = self.get_native_token_id(transfer_message.get_origin_chain());

require!(
Self::check_storage_balance_result((storage_deposit_action_index + 1) as u64)
&& storage_deposit_actions[storage_deposit_action_index].account_id
== predecessor_account_id
Self::check_storage_balance_result(
(storage_deposit_action_index + 1)
.try_into()
.sdk_expect("ERR_CAST")
) && storage_deposit_actions[storage_deposit_action_index].account_id
== predecessor_account_id
&& storage_deposit_actions[storage_deposit_action_index].token_id
== native_token_id,
"STORAGE_ERR: The native fee recipient is omitted"
Expand Down
75 changes: 48 additions & 27 deletions near/omni-bridge/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct TransferMessageStorageValue {
pub owner: AccountId,
}

#[allow(clippy::module_name_repetitions)]
#[near(serializers=[borsh, json])]
#[derive(Debug, Clone)]
pub enum TransferMessageStorage {
Expand Down Expand Up @@ -132,46 +133,57 @@ impl Contract {

pub fn required_balance_for_account(&self) -> NearToken {
let key_len = Self::max_key_len_of_account_id();
let value_len = borsh::to_vec(&StorageBalance {
let value_len: u64 = borsh::to_vec(&StorageBalance {
total: NearToken::from_yoctonear(0),
available: NearToken::from_yoctonear(0),
})
.sdk_expect("ERR_BORSH")
.len() as u64;
.len()
.try_into()
.sdk_expect("ERR_CAST");

env::storage_byte_cost()
.saturating_mul((Self::get_basic_storage() + key_len + value_len).into())
}

pub fn required_balance_for_init_transfer(&self) -> NearToken {
let key_len = borsh::to_vec(&TransferId::default())
.sdk_expect("ERR_BORSH")
.len() as u64;
let max_account_id: AccountId = "a".repeat(64).parse().sdk_expect("ERR_PARSE_ACCOUNT_ID");
let value_len = borsh::to_vec(&TransferMessageStorage::V0(TransferMessageStorageValue {
message: TransferMessage {
origin_nonce: 0,
token: OmniAddress::Near(max_account_id.clone()),
amount: U128(0),
recipient: OmniAddress::Near(max_account_id.clone()),
fee: Fee::default(),
sender: OmniAddress::Near(max_account_id.clone()),
msg: String::new(),
destination_nonce: 0,
},
owner: max_account_id,
}))
.sdk_expect("ERR_BORSH")
.len() as u64;

let key_len: u64 = borsh::to_vec(&TransferId::default())
.sdk_expect("ERR_BORSH")
.len()
.try_into()
.sdk_expect("ERR_CAST");

let value_len: u64 =
borsh::to_vec(&TransferMessageStorage::V0(TransferMessageStorageValue {
message: TransferMessage {
origin_nonce: 0,
token: OmniAddress::Near(max_account_id.clone()),
amount: U128(0),
recipient: OmniAddress::Near(max_account_id.clone()),
fee: Fee::default(),
sender: OmniAddress::Near(max_account_id.clone()),
msg: String::new(),
destination_nonce: 0,
},
owner: max_account_id,
}))
.sdk_expect("ERR_BORSH")
.len()
.try_into()
.sdk_expect("ERR_CAST");

env::storage_byte_cost()
.saturating_mul((Self::get_basic_storage() + key_len + value_len).into())
}

pub fn required_balance_for_fin_transfer(&self) -> NearToken {
let key_len = borsh::to_vec(&(ChainKind::Eth, 0_u128))
let key_len: u64 = borsh::to_vec(&(ChainKind::Eth, 0_u128))
.sdk_expect("ERR_BORSH")
.len() as u64;
.len()
.try_into()
.sdk_expect("ERR_CAST");

let storage_cost =
env::storage_byte_cost().saturating_mul((Self::get_basic_storage() + key_len).into());
Expand All @@ -183,13 +195,17 @@ impl Contract {
pub fn required_balance_for_bind_token(&self) -> NearToken {
let max_token_id: AccountId = "a".repeat(64).parse().sdk_expect("ERR_PARSE_ACCOUNT_ID");

let key_len = borsh::to_vec(&(ChainKind::Near, &max_token_id))
let key_len: u64 = borsh::to_vec(&(ChainKind::Near, &max_token_id))
.sdk_expect("ERR_BORSH")
.len() as u64;
.len()
.try_into()
.sdk_expect("ERR_CAST");

let value_len = borsh::to_vec(&OmniAddress::Near(max_token_id))
let value_len: u64 = borsh::to_vec(&OmniAddress::Near(max_token_id))
.sdk_expect("ERR_BORSH")
.len() as u64;
.len()
.try_into()
.sdk_expect("ERR_CAST");

env::storage_byte_cost()
.saturating_mul((3 * (Self::get_basic_storage() + key_len + value_len)).into())
Expand All @@ -215,6 +231,11 @@ impl Contract {

fn max_key_len_of_account_id() -> u64 {
let max_account_id: AccountId = "a".repeat(64).parse().sdk_expect("ERR_PARSE_ACCOUNT_ID");
borsh::to_vec(&max_account_id).sdk_expect("ERR_BORSH").len() as u64

borsh::to_vec(&max_account_id)
.sdk_expect("ERR_BORSH")
.len()
.try_into()
.sdk_expect("ERR_CAST")
}
}
Loading
Loading