Skip to content

Commit

Permalink
Check if pair is supported before transferring tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofziobro committed Nov 13, 2023
1 parent 729444a commit ede52ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions azero/contracts/membrane/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,19 @@ pub mod membrane {
dest_receiver_address: [u8; 32],
) -> Result<(), MembraneError> {
let sender = self.env().caller();

let dest_token_address = self
.supported_pairs
.get(src_token_address)
.ok_or(MembraneError::UnsupportedPair)?;

self.transfer_from_tx(
src_token_address.into(),
sender,
self.env().account_id(),
amount,
)?;

let dest_token_address = self
.supported_pairs
.get(src_token_address)
.ok_or(MembraneError::UnsupportedPair)?;

self.env().emit_event(CrosschainTransferRequest {
dest_token_address,
amount,
Expand Down
8 changes: 5 additions & 3 deletions eth/contracts/Membrane.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ contract Membrane {
address sender = msg.sender;

IERC20 token = IERC20(bytes32ToAddress(srcTokenAddress));
// lock tokens in this contract
// message sender needs to give approval else this tx will revert
token.transferFrom(sender, address(this), amount);

// check if the token is supported
bytes32 destTokenAddress = supportedPairs[srcTokenAddress];
require(destTokenAddress != 0x0, "Unsupported pair");

// lock tokens in this contract
// message sender needs to give approval else this tx will revert
token.transferFrom(sender, address(this), amount);

emit CrosschainTransferRequest(
destTokenAddress,
amount,
Expand Down

0 comments on commit ede52ca

Please sign in to comment.