Verified contractExactMIT
NexaSend
Address0xb2c09d2c48988624878f7d0e8302372ae7b53cde
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,412,235
- Creation transaction
- 0x4ae3fe3739…771a8a0798
NexaSend.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
/**
* @title NexaSend
* @notice Pays a recipient and Nexa's fee in one transaction, on Ethereum, BNB Chain and TRON.
*
* Deliberately tiny, so it is easy to audit:
* - No owner, no admin, no storage, no upgrades, nothing to pause or configure. Once deployed it can never change.
* - It never holds money: the coin sent with a call, or the tokens the caller approved, go straight out to the
* recipient and the fee address in the same call. Sending coins to the contract any other way is refused.
* - Tokens are only ever taken from the caller (msg.sender), never from anyone else, so an approval given to it can
* only be used by the wallet that gave it, in a send that wallet signs.
* - The fee can never be more than 1% of the amount, whatever the app or the server asks.
* - Token transfers are checked by the recipient's balance actually going up by the amount, which also works for
* tokens that return nothing or the wrong value (USDT on Ethereum and TRON).
*
* Compile with optimizer on (200 runs) and evmVersion "paris" (no PUSH0), so the same source runs on all three.
*/
contract NexaSend {
/// The most the fee may be, in basis points of the amount sent (100 = 1%).
uint256 public constant MAX_FEE_BPS = 100;
/// One send: `token` is the zero address for the network's own coin (ETH, BNB, TRX).
event Sent(address indexed from, address indexed token, address indexed to, uint256 amount, address feeTo, uint256 fee);
error ZeroAddress();
error FeeTooHigh();
error NothingToSend();
error PaymentFailed();
error NotAToken();
error TransferFailed();
/**
* @notice Sends the network's own coin: msg.value is the amount plus the fee.
* @param to The recipient (gets msg.value - fee).
* @param feeTo Where the fee goes (ignored when fee is 0).
* @param fee Nexa's fee, in the coin's smallest unit.
*/
function sendNative(address payable to, address payable feeTo, uint256 fee) external payable {
if (to == address(0)) revert ZeroAddress();
if (msg.value <= fee) revert NothingToSend();
uint256 amount = msg.value - fee;
_checkFee(amount, fee, feeTo);
_pay(to, amount);
if (fee != 0) _pay(feeTo, fee);
emit Sent(msg.sender, address(0), to, amount, feeTo, fee);
}
/**
* @notice Sends a token the caller approved this contract for (at least amount + fee).
* @param token The token contract (USDT, USDC).
* @param to The recipient (gets exactly `amount`).
* @param amount What the recipient gets, in the token's smallest unit.
* @param feeTo Where the fee goes (ignored when fee is 0).
* @param fee Nexa's fee, in the token's smallest unit.
*/
function sendToken(address token, address to, uint256 amount, address feeTo, uint256 fee) external {
if (to == address(0)) revert ZeroAddress();
if (amount == 0) revert NothingToSend();
if (token.code.length == 0) revert NotAToken();
_checkFee(amount, fee, feeTo);
_pull(token, to, amount);
if (fee != 0) _pull(token, feeTo, fee);
emit Sent(msg.sender, token, to, amount, feeTo, fee);
}
function _checkFee(uint256 amount, uint256 fee, address feeTo) private pure {
if (fee == 0) return;
if (feeTo == address(0)) revert ZeroAddress();
// fee / amount <= MAX_FEE_BPS / 10000, without dividing (no rounding in the caller's favour or against it).
if (fee * 10_000 > amount * MAX_FEE_BPS) revert FeeTooHigh();
}
function _pay(address payable to, uint256 value) private {
(bool ok, ) = to.call{value: value}("");
if (!ok) revert PaymentFailed();
}
/// transferFrom(msg.sender, to, value), checked by `to`'s balance rising by exactly `value`.
function _pull(address token, address to, uint256 value) private {
uint256 before = _balanceOf(token, to);
(bool ok, ) = token.call(abi.encodeWithSelector(0x23b872dd, msg.sender, to, value));
if (!ok || _balanceOf(token, to) != before + value) revert TransferFailed();
}
function _balanceOf(address token, address who) private view returns (uint256) {
(bool ok, bytes memory data) = token.staticcall(abi.encodeWithSelector(0x70a08231, who));
if (!ok || data.length < 32) revert NotAToken();
return abi.decode(data, (uint256));
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.