The X7LiquidityTreasury contract manages liquidity generated by the Xchange Ecosystem. It provides functionalities for handling liquidity pool tokens (LP tokens), swapping tokens, and managing wrapped ETH (WETH) balances. The contract also allows the owner to set remote and router addresses for interacting with external contracts, such as decentralized exchanges.
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
}
interface IXchangeV2Router02 {
function WETH() external pure returns (address);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
}
interface IXchangeV2Pair {
function token0() external view returns (address);
function token1() external view returns (address);
}
interface IWETH {
function deposit() external payable;
function withdraw(uint) external;
}
These interfaces provide essential methods for interacting with external ERC20 tokens, liquidity pools, and decentralized exchanges (DEXes) through the router and WETH contracts.
event RouterAddressUpdated(address indexed oldRouter, address indexed newRouter);
event RemoteAddressUpdated(address indexed oldRemote, address indexed newRemote);
Two key events are emitted in the contract:
RouterAddressUpdated Triggered when the DEX router address is updated. RemoteAddressUpdated Triggered when the remote address for transferring assets is updated.
function setRemoteAddress(address _newRemoteAddress) external onlyOwner {
require(_newRemoteAddress != address(0), "InvalidAddress");
address oldRemote = remoteAddress;
remoteAddress = _newRemoteAddress;
emit RemoteAddressUpdated(oldRemote, _newRemoteAddress);
}
setRemoteAddress allows the owner to set a new remote address. The remote address is where the contract sends ETH after breaking liquidity pools. It requires a non-zero address and emits an event on update.
function setRouterAddress(address _newRouterAddress) external onlyOwner {
require(_newRouterAddress != address(0), "InvalidAddress");
routerAddress = _newRouterAddress;
WETH = IXchangeV2Router02(routerAddress).WETH();
emit RouterAddressUpdated(oldRouter, _newRouterAddress);
}
setRouterAddress updates the router address for the DEX. The router address is used for removing liquidity and token swaps. The function also updates the WETH address used by the router and emits a RouterAddressUpdated event.
