Skip to content

Exchanger

Description

Performs all the heavy lifting internally of exchange and settle functionality.

Source: contracts/Exchanger.sol

Architecture

Exchanger architture graph

Structs

ExchangeEntrySettlement

Source

Field Type Description
src bytes32 TBA
amount uint256 TBA
dest bytes32 TBA
reclaim uint256 TBA
rebate uint256 TBA
srcRoundIdAtPeriodEnd uint256 TBA
destRoundIdAtPeriodEnd uint256 TBA
timestamp uint256 TBA

Variables

CIRCUIT_BREAKER_SUSPENSION_REASON

Source

Type: uint256

CONTRACT_NAME

Source

Type: bytes32

lastExchangeRate

Source

Type: mapping(bytes32 => uint256)

Constructor

constructor

Source

Details

Signature

constructor(address _owner, address _resolver)

Visibility

public

State Mutability

``

Views

calculateAmountAfterSettlement

Source

Details

Signature

calculateAmountAfterSettlement(address from, bytes32 currencyKey, uint256 amount, uint256 refunded) view returns (uint256 amountAfterSettlement)

Visibility

public

State Mutability

view

feeRateForExchange

Source

Determine the effective fee rate for the exchange, taking into considering swing trading.

Details

Signature

feeRateForExchange(bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) view returns (uint256 exchangeFeeRate)

Visibility

external

State Mutability

view

getAmountsForExchange

Source

Details

Signature

getAmountsForExchange(uint256 sourceAmount, bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) view returns (uint256 amountReceived, uint256 fee, uint256 exchangeFeeRate)

Visibility

external

State Mutability

view

hasWaitingPeriodOrSettlementOwing

Source

Details

Signature

hasWaitingPeriodOrSettlementOwing(address account, bytes32 currencyKey) view returns (bool)

Visibility

external

State Mutability

view

isSynthRateInvalid

Source

Details

Signature

isSynthRateInvalid(bytes32 currencyKey) view returns (bool)

Visibility

external

State Mutability

view

maxSecsLeftInWaitingPeriod

Source

Returns the maximum number of seconds remaining in the waiting period for all exchanges into the given synth (currencyKey) by the account.

This number must be 0 in order for settle() to succeed.

Details

Signature

maxSecsLeftInWaitingPeriod(address account, bytes32 currencyKey) view returns (uint256)

Visibility

public

State Mutability

view

priceDeviationThresholdFactor

Source

Type: uint256

Details

Signature

priceDeviationThresholdFactor() view returns (uint256)

Visibility

external

State Mutability

view

resolverAddressesRequired

Source

Details

Signature

resolverAddressesRequired() view returns (bytes32[] addresses)

Visibility

public

State Mutability

view

settlementOwing

Source

Returns the total amount to be reclaimed or rebated for the given account and synth (currencyKey). Note: this function can be called at any time, even while the waiting period has not expired.

Details

Signature

settlementOwing(address account, bytes32 currencyKey) view returns (uint256 reclaimAmount, uint256 rebateAmount, uint256 numEntries)

Visibility

public

State Mutability

view

tradingRewardsEnabled

Source

Details

Signature

tradingRewardsEnabled() view returns (bool)

Visibility

external

State Mutability

view

waitingPeriodSecs

Source

Type: uint256

Details

Signature

waitingPeriodSecs() view returns (uint256)

Visibility

external

State Mutability

view

Restricted Functions

exchange

Source

Details

Signature

exchange(address exchangeForAddress, address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress, bool virtualSynth, address rewardAddress, bytes32 trackingCode) returns (uint256 amountReceived, contract IVirtualSynth vSynth)

Visibility

external

State Mutability

``

Modifiers

resetLastExchangeRate

Source

Details

Signature

resetLastExchangeRate(bytes32[] currencyKeys)

Visibility

external

State Mutability

``

Requires

Modifiers

setLastExchangeRateForSynth

Source

Details

Signature

setLastExchangeRateForSynth(bytes32 currencyKey, uint256 rate)

Visibility

external

State Mutability

``

Requires

Modifiers

Internal Functions

_convert

Source

Details

Signature

_convert(bytes32 sourceCurrencyKey, address from, uint256 sourceAmountAfterSettlement, bytes32 destinationCurrencyKey, uint256 amountReceived, address recipient, bool virtualSynth) returns (contract IVirtualSynth vSynth)

Visibility

internal

State Mutability

``

_createVirtualSynth

Source

Details

Signature

_createVirtualSynth(contract IERC20, address, uint256, bytes32) returns (contract IVirtualSynth)

Visibility

internal

State Mutability

``

_ensureCanExchange

Source

Details

Signature

_ensureCanExchange(bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey) view

Visibility

internal

State Mutability

view

Requires

_exchange

Source

Details

Signature

_exchange(address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress, bool virtualSynth) returns (uint256 amountReceived, uint256 fee, contract IVirtualSynth vSynth)

Visibility

internal

State Mutability

``

_feeRateForExchange

Source

Details

Signature

_feeRateForExchange(bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) view returns (uint256 exchangeFeeRate)

Visibility

internal

State Mutability

view

_getAmountReceivedForExchange

Source

Details

Signature

_getAmountReceivedForExchange(uint256 destinationAmount, uint256 exchangeFeeRate) pure returns (uint256 amountReceived)

Visibility

internal

State Mutability

pure

_getAmountsForExchangeMinusFees

Source

Details

Signature

_getAmountsForExchangeMinusFees(uint256 sourceAmount, bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) view returns (uint256 amountReceived, uint256 fee, uint256 exchangeFeeRate, uint256 sourceRate, uint256 destinationRate)

Visibility

internal

State Mutability

view

_getExchangeEntry

Source

Details

Signature

_getExchangeEntry(address account, bytes32 currencyKey, uint256 index) view returns (struct IExchangeState.ExchangeEntry)

Visibility

internal

State Mutability

view

_internalSettle

Source

Details

Signature

_internalSettle(address from, bytes32 currencyKey, bool updateCache) returns (uint256 reclaimed, uint256 refunded, uint256 numEntriesSettled)

Visibility

internal

State Mutability

``

Requires

_isDeviationAboveThreshold

Source

Details

Signature

_isDeviationAboveThreshold(uint256 base, uint256 comparison) view returns (bool)

Visibility

internal

State Mutability

view

_isSynthRateInvalid

Source

Details

Signature

_isSynthRateInvalid(bytes32 currencyKey, uint256 currentRate) view returns (bool)

Visibility

internal

State Mutability

view

_settleAndCalcSourceAmountRemaining

Source

Details

Signature

_settleAndCalcSourceAmountRemaining(uint256 sourceAmount, address from, bytes32 sourceCurrencyKey) returns (uint256 sourceAmountAfterSettlement)

Visibility

internal

State Mutability

``

_settlementOwing

Source

Details

Signature

_settlementOwing(address account, bytes32 currencyKey) view returns (uint256 reclaimAmount, uint256 rebateAmount, uint256 numEntries, struct Exchanger.ExchangeEntrySettlement[])

Visibility

internal

State Mutability

view

_suspendIfRateInvalid

Source

Details

Signature

_suspendIfRateInvalid(bytes32 currencyKey, uint256 rate) returns (bool circuitBroken)

Visibility

internal

State Mutability

``

_updateSNXIssuedDebtOnExchange

Source

Details

Signature

_updateSNXIssuedDebtOnExchange(bytes32[2] currencyKeys, uint256[2] currencyRates)

Visibility

internal

State Mutability

``

appendExchange

Source

Details

Signature

appendExchange(address account, bytes32 src, uint256 amount, bytes32 dest, uint256 amountReceived, uint256 exchangeFeeRate)

Visibility

internal

State Mutability

``

Emits

debtCache

Source

Details

Signature

debtCache() view returns (contract IExchangerInternalDebtCache)

Visibility

internal

State Mutability

view

delegateApprovals

Source

Details

Signature

delegateApprovals() view returns (contract IDelegateApprovals)

Visibility

internal

State Mutability

view

exchangeRates

Source

Details

Signature

exchangeRates() view returns (contract IExchangeRates)

Visibility

internal

State Mutability

view

exchangeState

Source

Details

Signature

exchangeState() view returns (contract IExchangeState)

Visibility

internal

State Mutability

view

feePool

Source

Details

Signature

feePool() view returns (contract IFeePool)

Visibility

internal

State Mutability

view

getRoundIdsAtPeriodEnd

Source

Details

Signature

getRoundIdsAtPeriodEnd(struct IExchangeState.ExchangeEntry exchangeEntry) view returns (uint256 srcRoundIdAtPeriodEnd, uint256 destRoundIdAtPeriodEnd)

Visibility

internal

State Mutability

view

issuer

Source

Details

Signature

issuer() view returns (contract IIssuer)

Visibility

internal

State Mutability

view

reclaim

Source

Details

Signature

reclaim(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

``

refund

Source

Details

Signature

refund(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

``

secsLeftInWaitingPeriodForExchange

Source

Details

Signature

secsLeftInWaitingPeriodForExchange(uint256 timestamp) view returns (uint256)

Visibility

internal

State Mutability

view

synthetix

Source

Details

Signature

synthetix() view returns (contract ISynthetix)

Visibility

internal

State Mutability

view

systemStatus

Source

Details

Signature

systemStatus() view returns (contract ISystemStatus)

Visibility

internal

State Mutability

view

tradingRewards

Source

Details

Signature

tradingRewards() view returns (contract ITradingRewards)

Visibility

internal

State Mutability

view

External Functions

settle

Source

Settle processes all exchanges into the given synth, calculating any reclaimed or refunded amounts via settlementOwing and burning any reclaim and issuing any refund. This function may be called by anyone - the msg.sender is irrelevant.

Details

Signature

settle(address from, bytes32 currencyKey) returns (uint256 reclaimed, uint256 refunded, uint256 numEntriesSettled)

Visibility

external

State Mutability

``

suspendSynthWithInvalidRate

Source

Details

Signature

suspendSynthWithInvalidRate(bytes32 currencyKey)

Visibility

external

State Mutability

``

Requires

Modifiers

onlyExchangeRates

Source

onlySynthetixorSynth

Source

Events

ExchangeEntryAppended

Source

Signature: ExchangeEntryAppended(address account, bytes32 src, uint256 amount, bytes32 dest, uint256 amountReceived, uint256 exchangeFeeRate, uint256 roundIdForSrc, uint256 roundIdForDest)

ExchangeEntrySettled

Source

Signature: ExchangeEntrySettled(address from, bytes32 src, uint256 amount, bytes32 dest, uint256 reclaim, uint256 rebate, uint256 srcRoundIdAtPeriodEnd, uint256 destRoundIdAtPeriodEnd, uint256 exchangeTimestamp)