Description:
Decentralized Finance (DeFi) protocol contract providing Swap functionality.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
address constant SPX = 0xE0f63A424a4439cBE457D80E4f4b51aD25b2c56C;
address constant POOL = 0x52c77b0CB827aFbAD022E6d6CAF2C44452eDbc39;
address constant ZROUTER = 0x00000000008892d085e0611eb8C8BDc9FD856fD3;
interface IZROUTER {
function swapV2(
address to,
bool exactOut,
address tokenIn,
address tokenOut,
uint256 swapAmount,
uint256 amountLimit,
uint256 deadline
) external payable returns (uint256 amountIn, uint256 amountOut);
}
interface IV2Pool {
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32);
}
contract SPXBurner {
event OwnershipTransferred(address, address);
error Unauthorized();
error PriceNotSet();
error PriceStale();
address public owner;
uint256 public price;
uint256 public lastUpdate;
uint256 public maxSlippage = 500; // 5% in bps
uint256 public maxAge = 1 hours;
constructor() payable {
owner = msg.sender;
}
receive() external payable {
unchecked {
require(price != 0, PriceNotSet());
require(block.timestamp <= lastUpdate + maxAge, PriceStale());
uint256 minOut = (msg.value * price * (10000 - maxSlippage)) / 1e22;
IZROUTER(ZROUTER).swapV2{value: msg.value}(
address(0xdead),
false,
address(0),
SPX,
msg.value,
minOut,
block.timestamp
);
}
}
function syncPrice() public payable {
(uint112 reserve0, uint112 reserve1,) = IV2Pool(POOL).getReserves();
price = (reserve1 * 1e18) / reserve0;
lastUpdate = block.timestamp;
}
function setMaxSlippage(uint256 bps) public payable {
require(msg.sender == owner, Unauthorized());
maxSlippage = bps;
}
function setMaxAge(uint256 age) public payable {
require(msg.sender == owner, Unauthorized());
maxAge = age;
}
function transferOwnership(address to) public payable {
require(msg.sender == owner, Unauthorized());
emit OwnershipTransferred(msg.sender, owner = to);
}
}
Submitted on: 2025-10-25 17:15:02
Comments
Log in to comment.
No comments yet.