XY Finance
Search…
Smart Contracts
XY Finance deploys smart contracts of Swapper (X Swap) on most mainstream chains and benefits all types of users in terms of secure cross-chain swaps.

Swapper

Code

To enable ease of access to the content of the smart contracts (its code, data, status, etc.) and ascertain how they work and how they are programmed on the network, here we give you (users and institutions alike) the APIs and custom-fit UIs to suit your needs and provide you with a sense of security. The link Swapper.sol below offers a collection of our code and functions. The smart contract accounts, deployed to the network, will interact with you when you submit transactions that execute functions that are defined on the smart contracts per se. Just like a regular, typical contract, our smart contracts define rules and will automatically implement them via the code.

Address

The notion of smart contracts can be thought of as a program that resides at a particular address on the Ethereum blockchain.Swapper (X Swap) is then deployed at the following address: 0x935BbF5c69225E3EDa7C3aA542A7Baa5c5c30094
Currently, this address is on the Ethereum blockchain, the Binance Smart Chain (BSC) mainnet, as well as the Polygon Network. It was built from commit a71a896.

Events

SourceChainSwap

event SourceChainSwap(uint256 indexed _swapId, address _sender, uint8 _chainId, SwapInfo _swapInfo, uint256 _fromTokenAmount);
This will be submitted/sent out whenever a source-chain swap is completed.

TargetChainSwap

event TargetChainSwap(uint256 indexed _swapId, address _receiver, uint8 _chainId, SwapInfo _swapInfo);
This will be submitted/sent out by the time all source chain swaps are completed so as to keep a record of the target chain swap path for processors to do swaps on the target chain.

SwapForCompleted

event SwapForCompleted(uint256 indexed _swapId, address _receiver, address _toToken, uint256 _toTokenAmount);
This will be submitted/sent out Emitted whenever a target-chain swap is completed.

OneInchSwapFailed

event OneInchSwapFailed(address _token);
This will be submitted/sent out whenever a 1inch-DeFi/DEX-aggregator swap ends up unsuccessful.

State-Changing Functions

setOneInchAggregator

function setOneInchAggregator(address payable _oneInchAggregator)
Have a 1inch-aggregator contract address configured.

setProxyAccount

function setProxyAccount(address _addr, bool _flag)
Set our whitelist proxy address (simple address).
The cross-chain cash process is as follows. user -> swapper -> proxy address -> bridge deposit address -> target chain swapper -> target chain user address

setOperatorAccount

function setOperatorAccount(address _addr, bool _flag)
Set operator address who has right to call swapForByOperator function.

setAnyswapRouter

function setAnyswapRouter(address _addr)
Set anyswap V3 router address, a contract to interact with to do cross chain bridge on anyswap V3.

setAnyTokenMapping

function setAnyTokenMapping(address token, address anyToken)
Set anyswap V3 router contract and correspond token contract mapping. For example: the USDC router -> anyUSDC token address.

swap

function swap(
uint256 fromTokenAmount,
SwapInfo[] calldata swapInfos,
SwapInfo[] calldata targetChainSwapInfo,
address receiver
)
Execute source chain side swap. The swapInfos are generated by server containing source chain part of best routing path.
The targetChainSwapInfo only emit events to record target chain swap path.
This function should be called by user.

swapForByProxy

function swapForByProxy(
uint256 _swapId,
uint256 fromTokenAmount,
SwapInfo[] calldata swapInfos,
address receiver
)
Execute target chain side swap. The swapInfos are generated by server containing target chain part of best routing path. After swap finished, last swap info will send target chain tokens to receiver (user address).
Can be called only by whitelisted proxies.

swapForByOperator

function swapForByOperator(
uint256 _swapId,
uint256 fromTokenAmount,
SwapInfo[] calldata swapInfos,
address receiver
)
The same mechanism as swapForByProxy, except that this is for anyswap V3 bridge.

Withdrawable

Code

Allow owner to withdraw all assets in the contract.

Events

LogWithdraw

event LogWithdraw(
address indexed _assetAddress,
address _from,
uint amount
);
Emitted each time withdraw finished.

State-Changing Functions

withdraw

function withdraw(address _assetAddress, uint amount)
Allow owner to withdraw asset in the contract.
Copy link
Outline
Swapper
Code
Address
Events
SourceChainSwap
TargetChainSwap
SwapForCompleted
OneInchSwapFailed
State-Changing Functions
setOneInchAggregator
setProxyAccount
setOperatorAccount
setAnyswapRouter
setAnyTokenMapping
swap
swapForByProxy
swapForByOperator
Withdrawable
Code
Events
LogWithdraw
State-Changing Functions
withdraw