EcosystemNFTsDocs

Footer

Xchange

  • Swap
  • Liquidity
  • Loans
  • Fund
  • Vote

Tokens

  • X7R
  • X7DAO
  • X7D
  • X7101-X7105

Explore

  • Dashboard
  • Guides
  • Integration
  • Whitepaper
  • Breakdowns
  • Onchains
  • FAQs

Community

  • Telegram
  • Twitter
  • Discord
  • Warpcast
  • Blog
  • Links

Permissionless Trustless Decentralized Exchange

Launch your project on Xchange with 10-1000x the initial liquidity across multiple blockchains where anyone can Swap, Borrow and Lend!

X7 Finance·Trust No One. Trust Code. Long Live DeFi.
  • Telegram
  • Twitter
  • Discordś
  • Warpcast
  • YouTube
  • Reddit
  • GitHub
  • Pioneer 1488 avatar
    Guides
    View
  • Pioneer 1488 avatar
    Integration
    View
  • Pioneer 1488 avatar
    Whitepaper
    View
  • Pioneer 1488 avatar
    Breakdowns
    View
  • Pioneer 1488 avatar
    Onchains
    View
  • Pioneer 1488 avatar
    FAQ
    View
    • X7R Token Contract
    • X7DAO Token Contract
    • X7100 Token Contract
    • X7D
    • X7DAO Discount Authority
    • X7DAO Liquidity Hub
    • X7 Ecosystem Splitter
    • X7 Liquidity Loan Terms
    • X7 Lending Pool
    • X7 Lending Pool Reserve
    • X7 Lending Discount Authority
    • X7 Liquidity Treasury
    • X7 Profit Share Splitter
    • X7R Discount Authority
    • X7R Liquidity Hub
    • X7 Token Burner
    • X7 Token Timelock
    • X7 Treasury Splitter V3
    • X7100 Discount Authority
    • X7100 Liquidity Hub
    • X7 Borrowing Maxi NFT
    • X7 Dex Maxi NFT
    • X7 Ecosystem Maxi NFT
    • X7 Liquidity Maxi NFT
    • X7 Pioneer NFT
    • X7 Magister NFT
    • Xchange Factory
    • Xchange Pair
    • X7R Token Contract
    • X7DAO Token Contract
    • X7100 Token Contract
    • X7D
    • X7DAO Discount Authority
    • X7DAO Liquidity Hub
    • X7 Ecosystem Splitter
    • X7 Liquidity Loan Terms
    • X7 Lending Pool
    • X7 Lending Pool Reserve
    • X7 Lending Discount Authority
    • X7 Profit Share Splitter
    • X7R Discount Authority
    • X7R Liquidity Hub
    • X7 Token Burner
    • X7 Token Timelock
    • X7 Treasury Splitter V3
    • X7100 Discount Authority
    • X7100 Liquidity Hub
    • X7 Borrowing Maxi
    • X7 Dex Maxi
    • X7 Ecosystem Maxi
    • X7 Liquidity Maxi NFT
    • X7 Pioneer NFT
    • X7 Magister NFT
    • Xchange Factory
    • Xchange Pair
    • X7R Token Contract
    • X7DAO Token Contract
    • X7100 Token Contract
    • X7D
    • X7DAO Discount Authority
    • X7DAO Liquidity Hub
    • X7 Ecosystem Splitter
    • X7 Liquidity Loan Terms
    • X7 Lending Pool
    • X7 Lending Pool Reserve
    • X7 Lending Discount Authority
    • X7 Profit Share Splitter
    • X7R Discount Authority
    • X7R Liquidity Hub
    • X7 Token Burner
    • X7 Token Timelock
    • X7 Treasury Splitter V3
    • X7100 Discount Authority
    • X7100 Liquidity Hub
    • X7 Borrowing Maxi
    • X7 Dex Maxi
    • X7 Ecosystem Maxi
    • X7 Liquidity Maxi NFT
    • X7 Pioneer NFT
    • X7 Magister NFT
    • Xchange Factory
    • Xchange Pair
Contracts
breakdowns

X7 Liquidity Treasury Contract

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.

function breakLP(address lpToken) public onlyOwner nonReentrant { uint256 liquidity = IERC20(lpToken).balanceOf(address(this)); require(liquidity > 0, "Insufficient LP balance"); IXchangeV2Pair pair = IXchangeV2Pair(lpToken); (address token0, address token1) = (pair.token0(), pair.token1()); IERC20(lpToken).approve(routerAddress, liquidity); IXchangeV2Router02(routerAddress).removeLiquidity( token0, token1, liquidity, 0, 0, address(this), block.timestamp ); }

breakLP breaks a liquidity pool (LP) token into its underlying assets (token0 and token1). It checks the contract's balance of the LP token, approves the router to remove liquidity, and splits the LP token into its individual tokens.

function breakMultipleLPAndSendETH(address[] calldata lpTokens) external onlyOwner nonReentrant { for (uint256 i = 0; i < lpTokens.length; i++) { breakLP(lpTokens[i]); } uint256 wethBalance = IERC20(WETH).balanceOf(address(this)); if (wethBalance > 0) { IWETH(WETH).withdraw(wethBalance); } uint256 ethBalance = address(this).balance; (bool success, ) = payable(remoteAddress).call{ value: ethBalance }(""); require(success, "ETH Transfer Failed"); }

breakMultipleLPAndSendETH allows the owner to break multiple LP tokens and convert any WETH balance to ETH. The ETH is then transferred to the remote address. This is useful for liquidating multiple LP tokens and sending the ETH to a specified wallet.

function emergencyWithdrawToken(address token) external onlyOwner { uint256 balanceToken = IERC20(token).balanceOf(address(this)); require(balanceToken > 0, "No token balance"); IERC20(token).transfer(msg.sender, balanceToken); }

The emergencyWithdrawToken function allows the owner to withdraw any ERC20 tokens from the contract in an emergency situation.

function withdrawETH() external onlyOwner { uint256 balance = address(this).balance; require(balance > 0, "No ETH balance"); (bool success, ) = payable(msg.sender).call{ value: balance }(""); require(success, "ETH Transfer Failed"); }

The withdrawETH function allows the owner to withdraw any ETH held by the contract to their own wallet.

function unwrapWETH() external onlyOwner { uint256 balance = IERC20(WETH).balanceOf(address(this)); if (balance > 0) IWETH(WETH).withdraw(balance); } function wrapWETH() external onlyOwner { uint256 balance = address(this).balance; if (balance > 0) IWETH(WETH).deposit{ value: balance }(); }

These functions allow the owner to convert between WETH and ETH. The unwrapWETH function converts WETH back to ETH, while wrapWETH deposits ETH and wraps it as WETH.

function convertWrappedToToken(address token) external onlyOwner { uint256 amount = IERC20(WETH).balanceOf(address(this)); _swapTokensForTokens(WETH, token, amount); }

The convertWrappedToToken function swaps WETH held by the contract for any specified ERC20 token. It utilizes the internal _swapTokensForTokens function to perform the token swap using the DEX router.

function _swapTokensForTokens(address from, address to, uint256 amount) internal { address[] memory path = new address[](from == WETH || to == WETH ? 2 : 3); path[0] = from; path[1] = (from == WETH || to == WETH) ? to : WETH; if (from != WETH && to != WETH) path[2] = to; IERC20(from).approve(routerAddress, amount); IXchangeV2Router02(routerAddress).swapExactTokensForTokensSupportingFeeOnTransferTokens( amount, 0, path, address(this), block.timestamp ); }

This internal _swapTokensForTokens function handles token swaps, allowing the contract to convert between WETH and any other token using the DEX router.

Previous
← X7 Lending Discount Authority
Next
X7 Profit Share Splitter →

-

  • Pioneer 1488 avatar
    Guides
    View
  • Pioneer 1488 avatar
    Integration
    View
  • Pioneer 1488 avatar
    Whitepaper
    View
  • Pioneer 1488 avatar
    Breakdowns
    View
  • Pioneer 1488 avatar
    Onchains
    View
  • Pioneer 1488 avatar
    FAQ
    View