SynthSwapper
Replacement of Virtual Synths in favor of gas savings. Allows swapping synths via the Synthetix protocol or Saddle's pools. The Bridge.sol
contract will deploy minimal clones of this contract upon initiating any cross-asset swaps.
Functions:
Function constructor()
constructor()
Initializes the contract when deploying this directly. This prevents others from calling initialize() on the target contract and setting themself as the owner.
Function initialize()
initialize()
Sets the owner
as the caller of this function
Function swapSynth(bytes32 sourceKey, uint256 synthAmount, bytes32 destKey) → uint256
swapSynth(bytes32 sourceKey, uint256 synthAmount, bytes32 destKey) → uint256
Swaps the synth to another synth via the Synthetix protocol.
Parameters:
sourceKey
: currency key of the source synthsynthAmount
: amount of the synth to swapdestKey
: currency key of the destination synth
Return Values:
amount of the destination synth received
Function swapSynthToToken(contract ISwap swap, contract IERC20 tokenFrom, uint8 tokenFromIndex, uint8 tokenToIndex, uint256 tokenFromAmount, uint256 minAmount, uint256 deadline, address recipient) → contract IERC20, uint256
swapSynthToToken(contract ISwap swap, contract IERC20 tokenFrom, uint8 tokenFromIndex, uint8 tokenToIndex, uint256 tokenFromAmount, uint256 minAmount, uint256 deadline, address recipient) → contract IERC20, uint256
Approves the given tokenFrom
and swaps it to another token via the given swap
pool.
Parameters:
swap
: the address of a pool to swap throughtokenFrom
: the address of the stored synthtokenFromIndex
: the index of the token to swap fromtokenToIndex
: the token the user wants to swap totokenFromAmount
: the amount of the token to swapminAmount
: the min amount the user would like to receive, or revert.deadline
: latest timestamp to accept this transactionrecipient
: the address of the recipient
Function withdraw(contract IERC20 token, address recipient, uint256 withdrawAmount, bool shouldDestroy)
withdraw(contract IERC20 token, address recipient, uint256 withdrawAmount, bool shouldDestroy)
Withdraws the given amount of token
to the recipient
.
Parameters:
token
: the address of the token to withdrawrecipient
: the address of the account to receive the tokenwithdrawAmount
: the amount of the token to withdrawshouldDestroy
: whether this contract should be destroyed after this call
Function destroy()
destroy()
Destroys this contract. Only owner can call this function.
Last updated