Token Swap Mechanism
Key Features
How It Works
function swapZENtoUSDT(uint256 amount) external { require(IERC20(ZEN).balanceOf(msg.sender) >= amount, "Insufficient ZEN balance"); IERC20(ZEN).transferFrom(msg.sender, address(this), amount); uint256 usdtAmount = calculateSwapRate(amount); IERC20(USDT).transfer(msg.sender, usdtAmount); }function calculateSwapRate(uint256 zenAmount) internal view returns (uint256) { uint256 zenPrice = getZENPrice(); // Fetch ZEN price from oracle return (zenAmount * zenPrice) / 1e18; // Convert ZEN to USDT equivalent }function provideLiquidity(uint256 zenAmount, uint256 usdtAmount) external { IERC20(ZEN).transferFrom(msg.sender, address(this), zenAmount); IERC20(USDT).transferFrom(msg.sender, address(this), usdtAmount); liquidityPool.addLiquidity(zenAmount, usdtAmount); }function isSupportedChain(uint256 chainId) external pure returns (bool) { return (chainId == 1 || chainId == 42161 || chainId == 137 || chainId == 56 || chainId == 10); }
Technical Details
Last updated