-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import "../core/base/Controllable.sol"; | ||
import "../interfaces/IInterChainAdapter.sol"; | ||
import "../interfaces/IChildTokenFactory.sol"; | ||
import "./lzApp/NonblockingLzApp.sol"; | ||
|
||
/// @author Jude (https://github.com/iammrjude) | ||
contract LayerZeroInterChainAdapter is Controllable, IInterChainAdapter, NonblockingLzApp { | ||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* CONSTANTS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
bytes public constant PAYLOAD = "\x01\x02\x03\x04"; | ||
|
||
/// @dev Version of LayerZeroInterChainAdapter implementation | ||
string public constant VERSION = "1.0.0"; | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* INITIALIZATION */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
function initialize(address platform_, address _lzEndpoint) external initializer { | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter LayerZeroInterChainAdapter.initialize(address,address)._lzEndpoint is not in mixedCase
|
||
__Controllable_init(platform_); | ||
__NonblockingLzApp_init(_lzEndpoint); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* RESTRICTED ACTIONS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc IInterChainAdapter | ||
function sendMessage(Message memory message) external {} | ||
|
||
/// @inheritdoc IInterChainAdapter | ||
function interChainAdapterId() external returns (string memory) {} | ||
|
||
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)); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* VIEW FUNCTIONS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc IInterChainAdapter | ||
function endpoint() external view returns (address) {} | ||
|
||
function estimateFee( | ||
uint16 _dstChainId, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter LayerZeroInterChainAdapter.estimateFee(uint16,bool,bytes)._dstChainId is not in mixedCase
|
||
bool _useZro, | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter LayerZeroInterChainAdapter.estimateFee(uint16,bool,bytes)._useZro is not in mixedCase
|
||
bytes calldata _adapterParams | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter LayerZeroInterChainAdapter.estimateFee(uint16,bool,bytes)._adapterParams is not in mixedCase
|
||
) public view returns (uint nativeFee, uint zroFee) { | ||
return lzEndpoint.estimateFees(_dstChainId, address(this), PAYLOAD, _useZro, _adapterParams); | ||
} | ||
Check warning Code scanning / Slither Unused return Medium |
||
|
||
function getOracle(uint16 remoteChainId) external view returns (address _oracle) { | ||
bytes memory bytesOracle = | ||
lzEndpoint.getConfig(lzEndpoint.getSendVersion(address(this)), remoteChainId, address(this), 6); | ||
assembly { | ||
_oracle := mload(add(bytesOracle, 32)) | ||
} | ||
} | ||
Check warning Code scanning / Slither Assembly usage Warning |
||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* INTERNAL LOGIC */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
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); | ||
// address parentToken = IChildTokenFactory(_getStorage().childTokenFactory).getParentTokenOf(token); | ||
// if (mint) mintToken(childToken, toAddress, amountOrTokenId, nft); | ||
// if (!mint) unlockToken(parentToken, toAddress, amountOrTokenId, nft); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,15 @@ import "../core/base/Controllable.sol"; | |
import "../interfaces/IBridge.sol"; | ||
import "../interfaces/IChildERC20.sol"; | ||
import "../interfaces/IChildERC721.sol"; | ||
import "../interfaces/IChildTokenFactory.sol"; | ||
import "./lzApp/NonblockingLzApp.sol"; | ||
import "../interfaces/IInterChainAdapter.sol"; | ||
|
||
/// @title Stability Bridge | ||
/// @author Jude (https://github.com/iammrjude) | ||
contract Bridge is Controllable, IBridge, NonblockingLzApp { | ||
contract Bridge is Controllable, IBridge { | ||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* CONSTANTS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
bytes public constant PAYLOAD = "\x01\x02\x03\x04"; | ||
|
||
/// @inheritdoc IControllable | ||
string public constant VERSION = "1.0.0"; | ||
|
||
|
@@ -42,9 +39,8 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp { | |
/* INITIALIZATION */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
function initialize(address platform_, address _lzEndpoint) external initializer { | ||
function initialize(address platform_) external initializer { | ||
__Controllable_init(platform_); | ||
__NonblockingLzApp_init(_lzEndpoint); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
|
@@ -75,22 +71,6 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp { | |
/// @inheritdoc IBridge | ||
function getTarget(address token, uint64 chainTo) external view returns (address targetToken, bytes32 linkHash) {} | ||
|
||
function estimateFee( | ||
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(uint16 remoteChainId) external view returns (address _oracle) { | ||
bytes memory bytesOracle = | ||
lzEndpoint.getConfig(lzEndpoint.getSendVersion(address(this)), remoteChainId, address(this), 6); | ||
assembly { | ||
_oracle := mload(add(bytesOracle, 32)) | ||
} | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* RESTRICTED ACTIONS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
@@ -135,7 +115,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp { | |
if (!success) revert TokenTransferFailed(); | ||
} | ||
bytes memory payload = abi.encode(msg.sender, amountOrTokenId, token, nft, true); | ||
_lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value); | ||
// _lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value); | ||
} | ||
|
||
function burnToken(address token, uint amountOrTokenId, uint16 chainTo, bool nft) public payable { | ||
|
@@ -145,13 +125,7 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp { | |
IChildERC20(token).burn(msg.sender, amountOrTokenId); | ||
} | ||
bytes memory payload = abi.encode(msg.sender, amountOrTokenId, token, nft, false); | ||
_lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value); | ||
} | ||
|
||
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)); | ||
// _lzSend(chainTo, payload, payable(msg.sender), address(0x0), bytes(""), msg.value); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
|
@@ -181,13 +155,4 @@ contract Bridge is Controllable, IBridge, NonblockingLzApp { | |
if (!success) revert TokenTransferFailed(); | ||
} | ||
} | ||
|
||
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); | ||
address parentToken = IChildTokenFactory(_getStorage().childTokenFactory).getParentTokenOf(token); | ||
if (mint) mintToken(childToken, toAddress, amountOrTokenId, nft); | ||
if (!mint) unlockToken(parentToken, toAddress, amountOrTokenId, nft); | ||
} | ||
} | ||
Check warning Code scanning / Slither Contracts that lock Ether Medium
Contract locking ether found:
Contract Bridge has payable functions: - IBridge.interChainTransfer(address,uint256,uint64) - Bridge.interChainTransfer(address,uint256,uint64) - Bridge.lockToken(address,uint256,uint16,bool) - Bridge.burnToken(address,uint256,uint16,bool) But does not have a function to withdraw the ether |