Skip to content

Commit d33ba4f

Browse files
authored
feat: add native fee restriction (#280)
* feat: add native fee restriction * tests: add tests * chore: formatting * test: fix ACL test * chore: clippy * chore: rust warning unused variable * Change sender_id to signer_id * Move this up * Linting * Optimizations * clippy + short-circuit * formatting
1 parent 33c2fcb commit d33ba4f

File tree

3 files changed

+508
-3
lines changed

3 files changed

+508
-3
lines changed

near/omni-bridge/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub enum Role {
8888
MetadataManager,
8989
UnrestrictedRelayer,
9090
TokenControllerUpdater,
91+
NativeFeeRestricted,
9192
}
9293

9394
#[ext_contract(ext_token)]
@@ -198,6 +199,17 @@ impl FungibleTokenReceiver for Contract {
198199
) -> PromiseOrValue<U128> {
199200
let parsed_msg: InitTransferMsg = serde_json::from_str(&msg).sdk_expect("ERR_PARSE_MSG");
200201
let token_id = env::predecessor_account_id();
202+
203+
// User has to pay for storage and we can't trust sender_id.
204+
let signer_id = env::signer_account_id();
205+
206+
// Avoid extra storage read by verifying native fee before checking the role
207+
if parsed_msg.native_token_fee.0 > 0
208+
&& self.acl_has_role(Role::NativeFeeRestricted.into(), signer_id.clone())
209+
{
210+
env::panic_str("ERR_ACCOUNT_RESTRICTED_FROM_USING_NATIVE_FEE");
211+
}
212+
201213
require!(
202214
parsed_msg.recipient.get_chain() != ChainKind::Near,
203215
"ERR_INVALID_RECIPIENT_CHAIN"
@@ -224,9 +236,6 @@ impl FungibleTokenReceiver for Contract {
224236
"ERR_INVALID_FEE"
225237
);
226238

227-
// User has to pay for storage and we can't trust sender_id.
228-
let signer_id = env::signer_account_id();
229-
230239
let mut required_storage_balance =
231240
self.add_transfer_message(transfer_message.clone(), signer_id.clone());
232241
required_storage_balance = required_storage_balance

near/omni-tests/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod fin_transfer;
22
mod helpers;
33
mod init_transfer;
4+
mod native_fee_role;
45
mod omni_token;

0 commit comments

Comments
 (0)