Skip to content

Commit

Permalink
Check is token is active in deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
byteZorvin committed Jul 29, 2024
1 parent 085eb7a commit 0bf46e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/bridge/token_bridge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ pub mod TokenBridge {
.read()
.consume_message_from_appchain(appchain_bridge, payload.span());
}

fn accept_deposit(self: @ContractState, token: ContractAddress, amount: u256) {
self.is_servicing_token(token);
let caller = get_caller_address();
let dispatcher = IERC20Dispatcher { contract_address: token };
assert(dispatcher.balance_of(caller) == amount, 'Not enough balance');
dispatcher.transfer_from(caller, get_contract_address(), amount);
}
}


Expand Down Expand Up @@ -352,14 +360,6 @@ pub mod TokenBridge {
}


fn accept_deposit(token: ContractAddress, amount: u256) {
let caller = get_caller_address();
let dispatcher = IERC20Dispatcher { contract_address: token };
assert(dispatcher.balance_of(caller) == amount, 'Not enough balance');
dispatcher.transfer_from(caller, get_contract_address(), amount);
}


#[abi(embed_v0)]
impl TokenBrdigeAdminImpl of ITokenBridgeAdmin<ContractState> {
fn set_appchain_token_bridge(ref self: ContractState, appchain_bridge: ContractAddress) {
Expand Down Expand Up @@ -478,7 +478,7 @@ pub mod TokenBridge {
appchain_recipient: ContractAddress
) {
let no_message: Span<felt252> = array![].span();
accept_deposit(token, amount);
self.accept_deposit(token, amount);
let nonce = self
.send_deposit_message(
token,
Expand Down Expand Up @@ -512,7 +512,7 @@ pub mod TokenBridge {
appchain_recipient: ContractAddress,
message: Span<felt252>
) {
accept_deposit(token, amount);
self.accept_deposit(token, amount);
let nonce = self
.send_deposit_message(
token,
Expand Down
2 changes: 2 additions & 0 deletions src/constants.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// These constants have been take from this [Starkgate Bridge contract constants](https://github.com/starknet-io/starkgate-contracts/blob/cairo-1/src/solidity/StarkgateConstants.sol#L4)

// Starknet L1 handler selectors.
pub const HANDLE_TOKEN_DEPOSIT_SELECTOR: felt252 =
774397379524139446221206168840917193112228400237242521560346153613428128537;
Expand Down

0 comments on commit 0bf46e8

Please sign in to comment.