Verified contractExactMIT
WILCTronEthereumVault
Address0xe2d6a63d4f932a47aad0b1fcbcd7baf541410d5a
- Balance
0 ETH
- Transactions
7
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- No
- EVM version
- shanghai
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,494,059
- Creation transaction
- 0x35e81b18d1…2ad873dfb7
contracts/WILCTronEthereumVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
/*
* WILC Ethereum -> TRON custody foundation.
* NOT DEPLOYMENT READY.
* Cross-chain gateway must be independently verified.
*/
interface IWILCTronGateway {
function dispatch(
uint32 destination,
bytes32 recipient,
bytes calldata message
) external payable returns (bytes32);
function quoteDispatch(
uint32 destination,
bytes32 recipient,
bytes calldata message
) external view returns (uint256);
}
interface IWILCTronToken {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
contract WILCTronEthereumVault {
IWILCTronToken public immutable token;
IWILCTronGateway public immutable gateway;
uint32 public immutable tronDomain;
bytes32 public trustedTronSender;
bytes32 public tronReceiver;
bool public remoteConfigured;
address public owner;
bool public paused = true;
bool private entered;
bool public publicAccessEnabled;
uint256 public constant ACCEPTANCE_CAP = 10 ** 8;
uint256 public constant MAX_COLLATERAL = 2_400_000_000 * 10 ** 8;
event PublicAccessEnabled();
uint256 public depositNonce;
uint256 public lockedCollateral;
mapping(bytes32 => bool) public processedBurns;
event DepositDispatched(
bytes32 indexed messageId,
address indexed sender,
bytes32 indexed recipient,
uint256 amount,
uint256 nonce
);
event WithdrawalReleased(
bytes32 indexed burnId,
address indexed recipient,
uint256 amount
);
event PauseChanged(bool paused);
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
modifier active() {
require(!paused, "Bridge paused");
require(remoteConfigured, "Remote not configured");
_;
}
modifier nonReentrant() {
require(!entered, "Reentrancy");
entered = true;
_;
entered = false;
}
constructor(
address tokenAddress,
address gatewayAddress,
uint32 destinationDomain,
bytes32 trustedSender,
bytes32 destinationReceiver
) {
require(tokenAddress.code.length > 0, "Invalid token");
require(gatewayAddress.code.length > 0, "Invalid gateway");
require(destinationDomain != 0, "Invalid domain");
require((trustedSender == bytes32(0)) == (destinationReceiver == bytes32(0)), "Partial remote");
token = IWILCTronToken(tokenAddress);
gateway = IWILCTronGateway(gatewayAddress);
tronDomain = destinationDomain;
trustedTronSender = trustedSender;
tronReceiver = destinationReceiver;
remoteConfigured = trustedSender != bytes32(0);
owner = msg.sender;
}
event RemoteConfigured(bytes32 sender, bytes32 receiver);
function configureRemote(
bytes32 trustedSender,
bytes32 destinationReceiver
) external onlyOwner {
require(paused, "Not paused");
require(!remoteConfigured, "Remote already configured");
require(trustedSender != bytes32(0), "Zero sender");
require(destinationReceiver != bytes32(0), "Zero receiver");
trustedTronSender = trustedSender;
tronReceiver = destinationReceiver;
remoteConfigured = true;
emit RemoteConfigured(trustedSender, destinationReceiver);
}
function enablePublicAccess() external onlyOwner {
require(paused, "Not paused");
require(remoteConfigured, "Remote not configured");
require(!publicAccessEnabled, "Already public");
require(lockedCollateral == 0, "Outstanding collateral");
publicAccessEnabled = true;
emit PublicAccessEnabled();
}
function setPaused(bool value) external onlyOwner {
if (!value) require(remoteConfigured, "Remote not configured");
paused = value;
emit PauseChanged(value);
}
/*
* One user bridge submission:
* lock collateral AND dispatch message atomically.
* If dispatch reverts, the entire transaction reverts.
*
* ERC-20 approval may be required beforehand.
*/
function quoteLockForTron(
uint256 amount,
bytes32 recipient
) external view returns (uint256) {
require(amount > 0, "Zero amount");
require(recipient != bytes32(0), "Zero recipient");
require(uint256(recipient) >> 160 == 0, "Invalid TRON recipient encoding");
bytes memory message = abi.encode(
uint8(1),
depositNonce + 1,
msg.sender,
recipient,
amount
);
return gateway.quoteDispatch(
tronDomain,
tronReceiver,
message
);
}
function lockForTron(
uint256 amount,
bytes32 recipient
)
external
payable
active
nonReentrant
returns (bytes32 messageId)
{
require(amount > 0, "Zero amount");
require(recipient != bytes32(0), "Zero recipient");
require(uint256(recipient) >> 160 == 0, "Invalid TRON recipient encoding");
require(
publicAccessEnabled || msg.sender == owner,
"Private acceptance"
);
uint256 cap = publicAccessEnabled
? MAX_COLLATERAL
: ACCEPTANCE_CAP;
require(
lockedCollateral + amount <= cap,
"Collateral cap"
);
uint256 beforeBalance = token.balanceOf(address(this));
require(
token.transferFrom(msg.sender, address(this), amount),
"Token transfer failed"
);
uint256 afterBalance = token.balanceOf(address(this));
require(
afterBalance >= beforeBalance &&
afterBalance - beforeBalance == amount,
"Incorrect collateral received"
);
lockedCollateral += amount;
uint256 nonce = ++depositNonce;
bytes memory message = abi.encode(
uint8(1),
nonce,
msg.sender,
recipient,
amount
);
uint256 requiredFee = gateway.quoteDispatch(
tronDomain,
tronReceiver,
message
);
require(msg.value == requiredFee, "Incorrect message fee");
messageId = gateway.dispatch{value: msg.value}(
tronDomain,
tronReceiver,
message
);
emit DepositDispatched(
messageId,
msg.sender,
recipient,
amount,
nonce
);
}
/*
* Only the authenticated messaging gateway can
* deliver a verified burn message.
*
* Gateway authentication, remote source verification,
* and destination finality are mandatory in production.
*/
function handle(
uint32 origin,
bytes32 sender,
bytes calldata message
) external active nonReentrant {
require(msg.sender == address(gateway), "Not gateway");
require(origin == tronDomain, "Wrong origin");
require(sender == trustedTronSender, "Wrong sender");
(
uint8 action,
uint256 nonce,
address recipient,
uint256 amount
) = abi.decode(
message,
(uint8, uint256, address, uint256)
);
require(action == 2, "Invalid action");
require(nonce > 0, "Invalid nonce");
require(recipient != address(0), "Zero recipient");
require(amount > 0, "Zero amount");
bytes32 burnId = keccak256(
abi.encode(origin, sender, nonce)
);
require(!processedBurns[burnId], "Already processed");
require(lockedCollateral >= amount, "Insufficient collateral");
processedBurns[burnId] = true;
lockedCollateral -= amount;
require(token.transfer(recipient, amount), "Release failed");
emit WithdrawalReleased(burnId, recipient, amount);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "shanghai",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.