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

lastExchangeRate

Source

Type: mapping(bytes32 => uint256)

Constructor

constructor

Source

Details

Signature

constructor(address _owner, address _resolver)

Visibility

public

State Mutability

undefined

Restricted Functions

exchange

Source

Details

Signature

exchange(address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress) returns (uint256 amountReceived)

Visibility

external

State Mutability

undefined

Modifiers

exchangeOnBehalf

Source

Details

Signature

exchangeOnBehalf(address exchangeForAddress, address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey) returns (uint256 amountReceived)

Visibility

external

State Mutability

undefined

Requires

Modifiers

exchangeOnBehalfWithTracking

Source

Details

Signature

exchangeOnBehalfWithTracking(address exchangeForAddress, address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address originator, bytes32 trackingCode) returns (uint256 amountReceived)

Visibility

external

State Mutability

undefined

Requires

Modifiers

exchangeWithTracking

Source

Details

Signature

exchangeWithTracking(address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress, address originator, bytes32 trackingCode) returns (uint256 amountReceived)

Visibility

external

State Mutability

undefined

Modifiers

exchangeWithVirtual

Source

Details

Signature

exchangeWithVirtual(address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress, bytes32 trackingCode) returns (uint256 amountReceived, contract IVirtualSynth vSynth)

Visibility

external

State Mutability

undefined

Modifiers

setLastExchangeRateForSynth

Source

Details

Signature

setLastExchangeRateForSynth(bytes32 currencyKey, uint256 rate)

Visibility

external

State Mutability

undefined

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

undefined

_createVirtualSynth

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_emitTrackingEvent

Source

Details

Signature

_emitTrackingEvent(bytes32 trackingCode, bytes32 toCurrencyKey, uint256 toAmount)

Visibility

internal

State Mutability

undefined

_ensureCanExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

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

undefined

_feeRateForExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_getAmountReceivedForExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_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

undefined

_getExchangeEntry

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_internalSettle

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

Requires

_isDeviationAboveThreshold

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_isSynthRateInvalid

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_processTradingRewards

Source

Details

Signature

_processTradingRewards(uint256 fee, address originator)

Visibility

internal

State Mutability

undefined

_settleAndCalcSourceAmountRemaining

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_settlementOwing

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_suspendIfRateInvalid

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

_updateSNXIssuedDebtOnExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

appendExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

Emits

debtCache

Source

Details

Signature

debtCache() view returns (contract IExchangerInternalDebtCache)

Visibility

internal

State Mutability

undefined

delegateApprovals

Source

Details

Signature

delegateApprovals() view returns (contract IDelegateApprovals)

Visibility

internal

State Mutability

undefined

exchangeRates

Source

Details

Signature

exchangeRates() view returns (contract IExchangeRates)

Visibility

internal

State Mutability

undefined

exchangeState

Source

Details

Signature

exchangeState() view returns (contract IExchangeState)

Visibility

internal

State Mutability

undefined

feePool

Source

Details

Signature

feePool() view returns (contract IFeePool)

Visibility

internal

State Mutability

undefined

getRoundIdsAtPeriodEnd

Source

Details

Signature

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

Visibility

internal

State Mutability

undefined

issuer

Source

Details

Signature

issuer() view returns (contract IIssuer)

Visibility

internal

State Mutability

undefined

reclaim

Source

Details

Signature

reclaim(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

undefined

refund

Source

Details

Signature

refund(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

undefined

secsLeftInWaitingPeriodForExchange

Source

Details

Signature

secsLeftInWaitingPeriodForExchange(uint256 timestamp) view returns (uint256)

Visibility

internal

State Mutability

undefined

synthetix

Source

Details

Signature

synthetix() view returns (contract ISynthetix)

Visibility

internal

State Mutability

undefined

systemStatus

Source

Details

Signature

systemStatus() view returns (contract ISystemStatus)

Visibility

internal

State Mutability

undefined

tradingRewards

Source

Details

Signature

tradingRewards() view returns (contract ITradingRewards)

Visibility

internal

State Mutability

undefined

External Functions

calculateAmountAfterSettlement

Source

Details

Signature

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

Visibility

public

State Mutability

undefined

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

undefined

getAmountsForExchange

Source

Details

Signature

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

Visibility

external

State Mutability

undefined

hasWaitingPeriodOrSettlementOwing

Source

Details

Signature

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

Visibility

external

State Mutability

undefined

isSynthRateInvalid

Source

Details

Signature

isSynthRateInvalid(bytes32 currencyKey) view returns (bool)

Visibility

external

State Mutability

undefined

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

undefined

priceDeviationThresholdFactor

Source

Type: uint256

Details

Signature

priceDeviationThresholdFactor() view returns (uint256)

Visibility

external

State Mutability

undefined

resolverAddressesRequired

Source

Details

Signature

resolverAddressesRequired() view returns (bytes32[] addresses)

Visibility

public

State Mutability

undefined

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

undefined

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

undefined

suspendSynthWithInvalidRate

Source

Details

Signature

suspendSynthWithInvalidRate(bytes32 currencyKey)

Visibility

external

State Mutability

undefined

Requires

tradingRewardsEnabled

Source

Details

Signature

tradingRewardsEnabled() view returns (bool)

Visibility

external

State Mutability

undefined

waitingPeriodSecs

Source

Type: uint256

Details

Signature

waitingPeriodSecs() view returns (uint256)

Visibility

external

State Mutability

undefined

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)