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

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

TargetChainSwap

1
event TargetChainSwap(uint256 indexed _swapId, address _receiver, uint8 _chainId, SwapInfo _swapInfo);
Copied!
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

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

OneInchSwapFailed

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

State-Changing Functions

setOneInchAggregator

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

setProxyAccount

1
function setProxyAccount(address _addr, bool _flag)
Copied!
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

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

setAnyswapRouter

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

setAnyTokenMapping

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

swap

1
function swap(
2
uint256 fromTokenAmount,
3
SwapInfo[] calldata swapInfos,
4
SwapInfo[] calldata targetChainSwapInfo,
5
address receiver
6
)
Copied!
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

1
function swapForByProxy(
2
uint256 _swapId,
3
uint256 fromTokenAmount,
4
SwapInfo[] calldata swapInfos,
5
address receiver
6
)
Copied!
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

1
function swapForByOperator(
2
uint256 _swapId,
3
uint256 fromTokenAmount,
4
SwapInfo[] calldata swapInfos,
5
address receiver
6
)
Copied!
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

1
event LogWithdraw(
2
address indexed _assetAddress,
3
address _from,
4
uint amount
5
);
Copied!
Emitted each time withdraw finished.

State-Changing Functions

withdraw

1
function withdraw(address _assetAddress, uint amount)
Copied!
Allow owner to withdraw asset in the contract.