Skip to main content

SynthSwapper

Replacement of Virtual Synths in favor of gas savings. Allows swapping synths via the Synthetix protocol or Gondola's pools. The Bridge.sol contract will deploy minimal clones of this contract upon initiating any cross-asset swaps.

Functions#

constructor#

function constructor(
) public

Deploys this contract and sets the owner. Note that when creating clones of this contract, the owner will be constant and cannot be changed.

swapSynth#

function swapSynth(
bytes32 sourceKey,
uint256 synthAmount,
bytes32 destKey
) external returns (uint256)

Swaps the synth to another synth via the Synthetix protocol.

Parameters:#

NameTypeDescription
sourceKeybytes32currency key of the source synth
synthAmountuint256amount of the synth to swap
destKeybytes32currency key of the destination synth

Return Values:#

NameTypeDescription
amountbytes32of the destination synth received

swapSynthToToken#

function swapSynthToToken(
contract ISwap swap,
contract IERC20 tokenFrom,
uint8 tokenFromIndex,
uint8 tokenToIndex,
uint256 tokenFromAmount,
uint256 minAmount,
uint256 deadline,
address recipient
) external returns (contract IERC20, uint256)

Approves the given tokenFrom and swaps it to another token via the given swap pool.

Parameters:#

NameTypeDescription
swapcontract ISwapthe address of a pool to swap through
tokenFromcontract IERC20the address of the stored synth
tokenFromIndexuint8the index of the token to swap from
tokenToIndexuint8the token the user wants to swap to
tokenFromAmountuint256the amount of the token to swap
minAmountuint256the min amount the user would like to receive, or revert.
deadlineuint256latest timestamp to accept this transaction
recipientaddressthe address of the recipient

withdraw#

function withdraw(
contract IERC20 token,
address recipient,
uint256 withdrawAmount,
bool shouldDestroy
) external

Withdraws the given amount of token to the recipient.

Parameters:#

NameTypeDescription
tokencontract IERC20the address of the token to withdraw
recipientaddressthe address of the account to receive the token
withdrawAmountuint256the amount of the token to withdraw
shouldDestroyboolwhether this contract should be destroyed after this call

destroy#

function destroy(
) external

Destroys this contract. Only owner can call this function.

_destroy#

function _destroy(
) internal