XY Finance
Search…
Smart Contracts
XY Finance contains a main swapper contract to let user and executor do cross chain swap securely.

Swapper

Code

Address

Swapper is deployed at 0x935BbF5c69225E3EDa7C3aA542A7Baa5c5c30094 on Ethereum mainnet、BSC mainnet and Polygon mainnet. It was built from commit a71a896.

Events

SourceChainSwap

event SourceChainSwap(uint256 indexed _swapId, address _sender, uint8 _chainId, SwapInfo _swapInfo, uint256 _fromTokenAmount);
Emitted each time a source chain swap finished.

TargetChainSwap

event TargetChainSwap(uint256 indexed _swapId, address _receiver, uint8 _chainId, SwapInfo _swapInfo);
Emitted each time all source chain swaps finished, just to record the target chain swap path for processor to do swap on target chain.

SwapForCompleted

event SwapForCompleted(uint256 indexed _swapId, address _receiver, address _toToken, uint256 _toTokenAmount);
Emitted each time target chain swap completed.

OneInchSwapFailed

event OneInchSwapFailed(address _token);
Emitted each time 1inch dex aggregator swap failed.

State-Changing Functions

setOneInchAggregator

function setOneInchAggregator(address payable _oneInchAggregator)
Set 1inch aggregator contract address.

setProxyAccount

function setProxyAccount(address _addr, bool _flag)
Set our whitelist proxy address (simple address).
The cross chain cash flow: 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.