Address Contract Verified
Address
0xe7682d936B8EBCC7081e476cD268d3A73F6299aa
Balance
0 ETH
Nonce
1
Code Size
5264 bytes
Creator
0xf7f716d7...e7EE at tx 0x210d0e88...d8ca4b
Indexed Transactions
0
Contract Bytecode
5264 bytes
0x6080604052600436106100d25760003560e01c8063bd64ace51161007f578063e240890a11610059578063e240890a14610235578063e91833b814610248578063ed9772b614610268578063fc0c546a1461028857600080fd5b8063bd64ace5146101b9578063d4eb5ded146101fe578063e062d9351461022257600080fd5b8063530e784f116100b0578063530e784f146101645780638da5cb5b146101845780638e15f473146101a457600080fd5b8063054564f0146100d757806307c9cd451461010a5780632630c12f1461012c575b600080fd5b3480156100e357600080fd5b506100f76100f236600461123c565b6102a8565b6040519081526020015b60405180910390f35b34801561011657600080fd5b5061012a610125366004611266565b6102d9565b005b34801561013857600080fd5b5060015461014c906001600160a01b031681565b6040516001600160a01b039091168152602001610101565b34801561017057600080fd5b5061012a61017f36600461127f565b6104b3565b34801561019057600080fd5b5060025461014c906001600160a01b031681565b3480156101b057600080fd5b506100f7610592565b3480156101c557600080fd5b506101d96101d4366004611266565b61061e565b604080516001600160a01b039094168452602084019290925290820152606001610101565b34801561020a57600080fd5b5061021361065b565b604051610101939291906112dd565b61012a610230366004611353565b6107fc565b61012a610243366004611266565b610afc565b34801561025457600080fd5b506100f7610263366004611266565b610d48565b34801561027457600080fd5b5061012a610283366004611353565b610e41565b34801561029457600080fd5b5060005461014c906001600160a01b031681565b600460205281600052604060002081815481106102c457600080fd5b90600052602060002001600091509150505481565b600354811061032f5760405162461bcd60e51b815260206004820152601560248201527f496e76616c6964206c697374696e6720696e646578000000000000000000000060448201526064015b60405180910390fd5b336001600160a01b03166003828154811061034c5761034c611375565b60009182526020909120600390910201546001600160a01b0316146103b35760405162461bcd60e51b815260206004820152601060248201527f4e6f7420796f7572206c697374696e67000000000000000000000000000000006044820152606401610326565b600054600380546001600160a01b039092169163a9059cbb913391859081106103de576103de611375565b60009182526020909120600160039092020101546040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610455573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610479919061138b565b5061048381611134565b604051819033907f4d0bc0926e497b516a2828d2cbd7260db3d2ac3df9b8bae2c985a6ab752f82aa90600090a350565b6002546001600160a01b0316331461050d5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e65720000000000000000006044820152606401610326565b6001600160a01b0381166105635760405162461bcd60e51b815260206004820152601660248201527f496e76616c6964206f7261636c652061646472657373000000000000000000006044820152606401610326565b6001805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b600154604080517f98d5fdca00000000000000000000000000000000000000000000000000000000815290516000926001600160a01b0316916398d5fdca9160048083019260209291908290030181865afa1580156105f5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061061991906113ad565b905090565b6003818154811061062e57600080fd5b60009182526020909120600390910201805460018201546002909201546001600160a01b03909116925083565b600354606090819081908067ffffffffffffffff81111561067e5761067e6113c6565b6040519080825280602002602001820160405280156106a7578160200160208202803683370190505b5093508067ffffffffffffffff8111156106c3576106c36113c6565b6040519080825280602002602001820160405280156106ec578160200160208202803683370190505b5092508067ffffffffffffffff811115610708576107086113c6565b604051908082528060200260200182016040528015610731578160200160208202803683370190505b50915060005b818110156107f55760006003828154811061075457610754611375565b60009182526020909120600390910201805487519192506001600160a01b03169087908490811061078757610787611375565b60200260200101906001600160a01b031690816001600160a01b03168152505080600101548583815181106107be576107be611375565b60200260200101818152505080600201548483815181106107e1576107e1611375565b602090810291909101015250600101610737565b5050909192565b600354821061084d5760405162461bcd60e51b815260206004820152601560248201527f496e76616c6964206c697374696e6720696e64657800000000000000000000006044820152606401610326565b60006003838154811061086257610862611375565b90600052602060002090600302019050600082118015610886575080600101548211155b6108d25760405162461bcd60e51b815260206004820152600e60248201527f496e76616c696420616d6f756e740000000000000000000000000000000000006044820152606401610326565b600081600101548383600201546108e991906113f2565b6108f3919061140f565b905060006108ff610592565b905060008161091684670de0b6b3a76400006113f2565b610920919061140f565b9050803410156109725760405162461bcd60e51b815260206004820152601560248201527f496e73756666696369656e74204554482073656e7400000000000000000000006044820152606401610326565b60005460405163a9059cbb60e01b8152336004820152602481018790526001600160a01b039091169063a9059cbb906044016020604051808303816000875af11580156109c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109e7919061138b565b5083546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015610a21573d6000803e3d6000fd5b5084846001016000828254610a369190611431565b9250508190555082846002016000828254610a519190611431565b90915550506001840154600003610a6b57610a6b86611134565b80341115610aab57336108fc610a818334611431565b6040518115909202916000818181858888f19350505050158015610aa9573d6000803e3d6000fd5b505b835460408051878152602081018490526001600160a01b039092169133917f6faf93231a456e552dbc9961f58d9713ee4f2e69d15f1975b050ef0911053a7b910160405180910390a3505050505050565b6003548110610b4d5760405162461bcd60e51b815260206004820152601560248201527f496e76616c6964206c697374696e6720696e64657800000000000000000000006044820152606401610326565b600060038281548110610b6257610b62611375565b906000526020600020906003020190506000610b7c610592565b90506000818360020154670de0b6b3a7640000610b9991906113f2565b610ba3919061140f565b905080341015610bf55760405162461bcd60e51b815260206004820152601560248201527f496e73756666696369656e74204554482073656e7400000000000000000000006044820152606401610326565b600054600184015460405163a9059cbb60e01b815233600482015260248101919091526001600160a01b039091169063a9059cbb906044016020604051808303816000875af1158015610c4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c70919061138b565b5082546040516001600160a01b039091169082156108fc029083906000818181858888f19350505050158015610caa573d6000803e3d6000fd5b50610cb484611134565b80341115610cf457336108fc610cca8334611431565b6040518115909202916000818181858888f19350505050158015610cf2573d6000803e3d6000fd5b505b8254600184015460408051918252602082018490526001600160a01b039092169133917f6faf93231a456e552dbc9961f58d9713ee4f2e69d15f1975b050ef0911053a7b910160405180910390a350505050565b6000808211610d995760405162461bcd60e51b815260206004820181905260248201527f416d6f756e74206d7573742062652067726561746572207468616e207a65726f6044820152606401610326565b6000610da3610592565b905060008111610df55760405162461bcd60e51b815260206004820152601560248201527f496e76616c6964205452582f45544820707269636500000000000000000000006044820152606401610326565b6000670de0b6b3a7640000610e0d85620f42406113f2565b610e17919061140f565b9050600082610e2e83670de0b6b3a76400006113f2565b610e38919061140f565b95945050505050565b60008211610e915760405162461bcd60e51b815260206004820181905260248201527f416d6f756e74206d7573742062652067726561746572207468616e207a65726f6044820152606401610326565b6000546040517f70a0823100000000000000000000000000000000000000000000000000000000815233600482015283916001600160a01b0316906370a0823190602401602060405180830381865afa158015610ef2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1691906113ad565b1015610f645760405162461bcd60e51b815260206004820152601460248201527f496e73756666696369656e742062616c616e63650000000000000000000000006044820152606401610326565b6000546040517f23b872dd000000000000000000000000000000000000000000000000000000008152336004820152306024820152604481018490526001600160a01b03909116906323b872dd906064016020604051808303816000875af1158015610fd4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff8919061138b565b50604080516060810182523380825260208083018681528385018681526003805460018082018355600083815297517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b928402928301805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0390921691909117905593517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85c82015591517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85d90920191909155928452600490915292909120905490916110e191611431565b8154600181018355600092835260209283902001556040805184815291820183905233917fcf412bfe866866664047e9f9e38cc21c13173a37c85de5d29b65f1822231ec00910160405180910390a25050565b60035460009061114690600190611431565b90506003818154811061115b5761115b611375565b90600052602060002090600302016003838154811061117c5761117c611375565b6000918252602090912082546003928302909101805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03909216919091178155600180840154908201556002928301549201919091558054806111df576111df611444565b600082815260208120600360001990930192830201805473ffffffffffffffffffffffffffffffffffffffff19168155600181018290556002015590555050565b80356001600160a01b038116811461123757600080fd5b919050565b6000806040838503121561124f57600080fd5b61125883611220565b946020939093013593505050565b60006020828403121561127857600080fd5b5035919050565b60006020828403121561129157600080fd5b61129a82611220565b9392505050565b600081518084526020840193506020830160005b828110156112d35781518652602095860195909101906001016112b5565b5093949350505050565b6060808252845190820181905260009060208601906080840190835b818110156113205783516001600160a01b03168352602093840193909201916001016112f9565b5050838103602085015261133481876112a1565b915050828103604084015261134981856112a1565b9695505050505050565b6000806040838503121561136657600080fd5b50508035926020909101359150565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561139d57600080fd5b8151801515811461129a57600080fd5b6000602082840312156113bf57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417611409576114096113dc565b92915050565b60008261142c57634e487b7160e01b600052601260045260246000fd5b500490565b81810381811115611409576114096113dc565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220de8d6822bf566ba045bfb0d787455f4f616b8ecffcebcb81957834611ccf607f64736f6c634300081a0033
Verified Source Code Full Match
Compiler: v0.8.26+commit.8a97fa7a
EVM: paris
Optimization: Yes (1000 runs)
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SwapMarket.sol 208 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title TokenSwapETH - A decentralized token marketplace using ETH
/// @notice This contract allows users to list and purchase tokens using ETH.
/// @dev Prices are converted using a TRX/ETH price oracle.
interface IPriceOracle {
function getPrice() external view returns (uint256);
}
contract TokenSwapETH {
IERC20 public token;
IPriceOracle public priceOracle; // External price oracle contract
address public owner;
struct TokenListing {
address seller;
uint256 amount; // In token's smallest units (18 decimals)
uint256 priceInTRX; // In TRX's smallest units (6 decimals)
}
TokenListing[] public tokenListings;
mapping(address => uint256[]) public sellerListings;
event TokensListed(
address indexed seller,
uint256 amount,
uint256 priceInTRX
);
event TokensPurchased(
address indexed buyer,
address indexed seller,
uint256 amount,
uint256 totalPriceETH
);
event TokensCancelSell(
address indexed seller,
uint256 indexed listingIndex
);
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
/// @notice Contract constructor to initialize token and price oracle
/// @param _token Address of the ERC20 token
/// @param _priceOracle Address of the TRX/ETH price oracle
constructor(address _token, address _priceOracle) {
token = IERC20(_token);
priceOracle = IPriceOracle(_priceOracle);
owner = msg.sender;
}
/// @notice Fetches the latest TRX/ETH price from the oracle
/// @return The TRX/ETH conversion rate
function getLatestPrice() public view returns (uint256) {
return priceOracle.getPrice();
}
/// @notice Retrieves all token listings
/// @return sellers Array of seller addresses
/// @return amounts Array of token amounts
/// @return prices Array of prices in TRX
function getTokenListings()
external
view
returns (
address[] memory sellers,
uint256[] memory amounts,
uint256[] memory prices
)
{
uint256 numListings = tokenListings.length;
sellers = new address[](numListings);
amounts = new uint256[](numListings);
prices = new uint256[](numListings);
for (uint256 i = 0; i < numListings; i++) {
TokenListing storage listing = tokenListings[i];
sellers[i] = listing.seller;
amounts[i] = listing.amount;
prices[i] = listing.priceInTRX;
}
}
/// @notice Allows a user to list tokens for sale
/// @param amount The number of tokens to sell (18 decimals)
/// @param priceInTRX The price in TRX (6 decimals)
function sellTokens(uint256 amount, uint256 priceInTRX) external {
require(amount > 0, "Amount must be greater than zero");
require(token.balanceOf(msg.sender) >= amount, "Insufficient balance");
token.transferFrom(msg.sender, address(this), amount);
tokenListings.push(TokenListing(msg.sender, amount, priceInTRX));
sellerListings[msg.sender].push(tokenListings.length - 1);
emit TokensListed(msg.sender, amount, priceInTRX);
}
/// @notice Purchases the entire listing for ETH
/// @param listingIndex The index of the listing
function buyWholeListing(uint256 listingIndex) external payable {
require(listingIndex < tokenListings.length, "Invalid listing index");
TokenListing storage listing = tokenListings[listingIndex];
uint256 trxEthPrice = getLatestPrice();
uint256 priceInETH = (listing.priceInTRX * 1e18) / trxEthPrice;
require(msg.value >= priceInETH, "Insufficient ETH sent");
token.transfer(msg.sender, listing.amount);
payable(listing.seller).transfer(priceInETH);
deleteTokenListing(listingIndex);
if (msg.value > priceInETH) {
payable(msg.sender).transfer(msg.value - priceInETH);
}
emit TokensPurchased(
msg.sender,
listing.seller,
listing.amount,
priceInETH
);
}
/// @notice Purchases a portion of a token listing
/// @param listingIndex The index of the listing
/// @param amount The amount of tokens to buy
function buyPartialListing(
uint256 listingIndex,
uint256 amount
) external payable {
require(listingIndex < tokenListings.length, "Invalid listing index");
TokenListing storage listing = tokenListings[listingIndex];
require(amount > 0 && amount <= listing.amount, "Invalid amount");
uint256 priceInTRX = (listing.priceInTRX * amount) / listing.amount;
uint256 trxEthPrice = getLatestPrice();
uint256 priceInETH = (priceInTRX * 1e18) / trxEthPrice;
require(msg.value >= priceInETH, "Insufficient ETH sent");
token.transfer(msg.sender, amount);
payable(listing.seller).transfer(priceInETH);
listing.amount -= amount;
listing.priceInTRX -= priceInTRX;
if (listing.amount == 0) {
deleteTokenListing(listingIndex);
}
if (msg.value > priceInETH) {
payable(msg.sender).transfer(msg.value - priceInETH);
}
emit TokensPurchased(msg.sender, listing.seller, amount, priceInETH);
}
/// @notice Cancels a token listing
/// @param listingIndex The index of the listing
function cancelSell(uint256 listingIndex) external {
require(listingIndex < tokenListings.length, "Invalid listing index");
require(
tokenListings[listingIndex].seller == msg.sender,
"Not your listing"
);
token.transfer(msg.sender, tokenListings[listingIndex].amount);
deleteTokenListing(listingIndex);
emit TokensCancelSell(msg.sender, listingIndex);
}
function deleteTokenListing(uint256 listingIndex) private {
uint256 lastIndex = tokenListings.length - 1;
tokenListings[listingIndex] = tokenListings[lastIndex];
tokenListings.pop();
}
/// @notice Updates the price oracle address
/// @param _priceOracle The new oracle address
function setPriceOracle(address _priceOracle) external onlyOwner {
require(_priceOracle != address(0), "Invalid oracle address");
priceOracle = IPriceOracle(_priceOracle);
}
/// @notice Checks the ETH equivalent price for a given token amount
/// @param amount The amount of tokens
/// @return priceInETH The price in ETH
function checkPriceInETH(uint256 amount) external view returns (uint256) {
require(amount > 0, "Amount must be greater than zero");
uint256 trxEthPrice = getLatestPrice();
require(trxEthPrice > 0, "Invalid TRX/ETH price");
uint256 priceInTRX = (amount * 1e6) / 1e18;
uint256 priceInETH = (priceInTRX * 1e18) / trxEthPrice;
return priceInETH;
}
}
Read Contract
checkPriceInETH 0xe91833b8 → uint256
getLatestPrice 0x8e15f473 → uint256
getTokenListings 0xd4eb5ded → address[], uint256[], uint256[]
owner 0x8da5cb5b → address
priceOracle 0x2630c12f → address
sellerListings 0x054564f0 → uint256
token 0xfc0c546a → address
tokenListings 0xbd64ace5 → address, uint256, uint256
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
buyPartialListing 0xe062d935
uint256 listingIndex
uint256 amount
buyWholeListing 0xe240890a
uint256 listingIndex
cancelSell 0x07c9cd45
uint256 listingIndex
sellTokens 0xed9772b6
uint256 amount
uint256 priceInTRX
setPriceOracle 0x530e784f
address _priceOracle
Recent Transactions
No transactions found for this address