Skip to content

Commit

Permalink
revert IBridge to initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
iammrjude committed Dec 15, 2023
1 parent 7f7ed7e commit 6bc533e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 48 deletions.
32 changes: 8 additions & 24 deletions src/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
function getTarget(address token, uint64 chainTo) external view returns (address targetToken, bytes32 linkHash) {}

function estimateFee(
uint64 _dstChainId,
uint16 _dstChainId,
bool _useZro,
bytes calldata _adapterParams
) public view returns (uint nativeFee, uint zroFee) {
return lzEndpoint.estimateFees(_dstChainId, address(this), PAYLOAD, _useZro, _adapterParams);
}

function getOracle(uint64 remoteChainId) external view returns (address _oracle) {
function getOracle(uint16 remoteChainId) external view returns (address _oracle) {
bytes memory bytesOracle =
lzEndpoint.getConfig(lzEndpoint.getSendVersion(address(this)), remoteChainId, address(this), 6);
assembly {
Expand All @@ -96,26 +96,10 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @inheritdoc IBridge
function interChainTransfer(
address token,
uint amountOrTokenId,
uint64 chainTo,
bool nft,
bool lock
) external payable {
if (lock) lockToken(token, amountOrTokenId, chainTo, nft);
if (!lock) burnToken(token, amountOrTokenId, chainTo, nft);
}
function interChainTransfer(address token, uint amountOrTokenId, uint64 chainTo) external payable {}

/// @inheritdoc IBridge
function interChainReceive(
uint64 srcChainId,
bytes memory srcAddress,
uint64 nonce,
bytes memory payload
) external {
_nonblockingLzReceive(srcChainId, srcAddress, nonce, payload);
}
function interChainReceive(address token, uint amountOrTokenId, uint64 chainFrom) external {}

/// @inheritdoc IBridge
function addLink(Link memory link_) external onlyOperator {
Expand Down Expand Up @@ -143,7 +127,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
/// @inheritdoc IBridge
function enableAdapter(string memory adapterId) external {}

function lockToken(address token, uint amountOrTokenId, uint64 chainTo, bool nft) public payable {
function lockToken(address token, uint amountOrTokenId, uint16 chainTo, bool nft) public payable {
if (nft) {
IERC721(token).safeTransferFrom(msg.sender, address(this), amountOrTokenId);
} else {
Expand All @@ -154,7 +138,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
_lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value);
}

function burnToken(address token, uint amountOrTokenId, uint64 chainTo, bool nft) public payable {
function burnToken(address token, uint amountOrTokenId, uint16 chainTo, bool nft) public payable {
if (nft) {
IChildERC721(token).burn(amountOrTokenId);
} else {
Expand All @@ -164,7 +148,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
_lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value);
}

function setOracle(uint64 dstChainId, address oracle) external onlyOwner {
function setOracle(uint16 dstChainId, address oracle) external onlyOwner {
uint TYPE_ORACLE = 6;
// set the Oracle
lzEndpoint.setConfig(lzEndpoint.getSendVersion(address(this)), dstChainId, TYPE_ORACLE, abi.encode(oracle));
Expand Down Expand Up @@ -198,7 +182,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp {
}
}

function _nonblockingLzReceive(uint64, bytes memory, uint64, bytes memory _payload) internal override {
function _nonblockingLzReceive(uint16, bytes memory, uint64, bytes memory _payload) internal override {
(address toAddress, uint amountOrTokenId, address token, bool nft, bool mint) =
abi.decode(_payload, (address, uint, address, bool, bool));
address childToken = IChildTokenFactory(_getStorage().childTokenFactory).getChildTokenOf(token);
Expand Down
32 changes: 8 additions & 24 deletions src/interfaces/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,14 @@ interface IBridge {
/// @param token Address of input token
/// @param amountOrTokenId Amount for ERC-20 or tokenId for ERC-721
/// @param chainTo Target chain ID
/// @param nft Specify if the token is ERC-20 or ERC-721
/// @param lock Specify if the action is to lock or burn
function interChainTransfer(
address token,
uint amountOrTokenId,
uint64 chainTo,
bool nft,
bool lock
) external payable;

/// @notice Allows the contract to receive inter-chain messages.
/// @dev This function is designed to handle messages originating from another chain.
/// @param srcChainId The ID of the source chain from which the message originates.
/// @param srcAddress The address on the source chain that initiated the message.
/// @param nonce A unique identifier for the message to prevent replay attacks.
/// @param payload The data payload containing information or instructions from the source chain.
/// @dev Emits an event signaling the successful reception of the inter-chain message.
/// @dev Access to this function may be restricted to specific roles or conditions.
function interChainReceive(
uint64 srcChainId,
bytes memory srcAddress,
uint64 nonce,
bytes memory payload
) external;
function interChainTransfer(address token, uint amountOrTokenId, uint64 chainTo) external payable;

/// @notice Receive tokens from another blockchain.
/// Only adapters can call this.
/// @param token Address of output token for bridging
/// @param amountOrTokenId Amount for ERC-20 or tokenId for ERC-721
/// @param chainFrom Source chain ID
function interChainReceive(address token, uint amountOrTokenId, uint64 chainFrom) external;

/// @notice Add new link to the bridge
/// Only operator can call this.
Expand Down

0 comments on commit 6bc533e

Please sign in to comment.