Skip to content

Commit

Permalink
fix: use token address instead of id in the payload
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Oct 30, 2024
1 parent 61f9afb commit c7bec0a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions evm/bridge-token-factory/contracts/BridgeTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ contract BridgeTokenFactory is
bytes memory borshEncoded = bytes.concat(
bytes1(uint8(BridgeTypes.PayloadType.TransferMessage)),
Borsh.encodeUint128(payload.nonce),
Borsh.encodeString(payload.token),
bytes1(omniBridgeChainId),
Borsh.encodeAddress(payload.tokenAddress),
Borsh.encodeUint128(payload.amount),
bytes1(omniBridgeChainId),
Borsh.encodeAddress(payload.recipient),
Expand All @@ -149,19 +150,18 @@ contract BridgeTokenFactory is
}

completedTransfers[payload.nonce] = true;
address tokenAddress = nearToEthToken[payload.token];

if (tokenAddress != address(0)) {
BridgeToken(tokenAddress).mint(payload.recipient, payload.amount);
if (isBridgeToken[payload.tokenAddress]) {
BridgeToken(payload.tokenAddress).mint(payload.recipient, payload.amount);
} else {
IERC20(tokenAddress).safeTransfer(payload.recipient, payload.amount);
IERC20(payload.tokenAddress).safeTransfer(payload.recipient, payload.amount);
}

finTransferExtension(payload);

emit BridgeTypes.FinTransfer(
payload.nonce,
payload.token,
payload.tokenAddress,
payload.amount,
payload.recipient,
payload.feeRecipient
Expand Down
4 changes: 2 additions & 2 deletions evm/bridge-token-factory/contracts/BridgeTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.24;
library BridgeTypes {
struct FinTransferPayload {
uint128 nonce;
string token;
address tokenAddress;
uint128 amount;
address recipient;
string feeRecipient;
Expand Down Expand Up @@ -36,7 +36,7 @@ library BridgeTypes {

event FinTransfer(
uint128 indexed nonce,
string token,
address tokenAddress,
uint128 amount,
address recipient,
string feeRecipient
Expand Down
9 changes: 8 additions & 1 deletion near/nep141-locker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,17 @@ impl Contract {
require!(&transfer_message.fee == fee, "Invalid fee");
}

let token_address = self
.get_token_address(
transfer_message.get_destination_chain(),
self.get_token_id(&transfer_message.token),
)
.unwrap_or_else(|| env::panic_str("ERR_FAILED_TO_GET_TOKEN_ADDRESS"));

let transfer_payload = TransferMessagePayload {
prefix: PayloadType::TransferMessage,
nonce,
token: self.get_token_id(&transfer_message.token),
token_address,
amount: U128(transfer_message.amount.0 - transfer_message.fee.fee.0),
recipient: transfer_message.recipient,
fee_recipient,
Expand Down
6 changes: 5 additions & 1 deletion near/omni-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ impl TransferMessage {
pub fn get_transfer_id(&self) -> TransferId {
(self.get_origin_chain(), self.origin_nonce.0)
}

pub fn get_destination_chain(&self) -> ChainKind {
self.recipient.get_chain()
}
}

#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug, Clone)]
Expand All @@ -305,7 +309,7 @@ pub enum PayloadType {
pub struct TransferMessagePayload {
pub prefix: PayloadType,
pub nonce: U128,
pub token: AccountId,
pub token_address: OmniAddress,
pub amount: U128,
pub recipient: OmniAddress,
pub fee_recipient: Option<AccountId>,
Expand Down

0 comments on commit c7bec0a

Please sign in to comment.