Skip to content

Exchanger

Description

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

Source: contracts/Exchanger.sol

Architecture

Libraries

Inheritance Graph

graph TD Exchanger[Exchanger] --> MixinSystemSettings[MixinSystemSettings] MixinSystemSettings[MixinSystemSettings] --> MixinResolver[MixinResolver] MixinResolver[MixinResolver] --> Owned[Owned]

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

Constants

CIRCUIT_BREAKER_SUSPENSION_REASON

Source

Type: uint256

Variables

lastExchangeRate

Source

Type: mapping(bytes32 => uint256)

Constructor

constructor

Source

Details

Signature

(address _owner, address _resolver)

Visibility

public

State Mutability

nonpayable

Views

calculateAmountAfterSettlement

Source

Details

Signature

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

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) returns (uint256)

Visibility

external

State Mutability

view

getAmountsForExchange

Source

Details

Signature

getAmountsForExchange(uint256 sourceAmount, bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) returns (uint256, uint256, uint256)

Visibility

external

State Mutability

view

hasWaitingPeriodOrSettlementOwing

Source

Details

Signature

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

Visibility

external

State Mutability

view

isSynthRateInvalid

Source

Details

Signature

isSynthRateInvalid(bytes32 currencyKey) 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) returns (uint256)

Visibility

public

State Mutability

view

priceDeviationThresholdFactor

Source

Type: uint256

Details

Signature

priceDeviationThresholdFactor() returns (uint256)

Visibility

external

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) returns (uint256, uint256, uint256)

Visibility

public

State Mutability

view

waitingPeriodSecs

Source

Type: uint256

Details

Signature

waitingPeriodSecs() returns (uint256)

Visibility

external

State Mutability

view

Restricted Functions

exchange

Source

Details

Signature

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

Visibility

external

State Mutability

nonpayable

Modifiers

exchangeOnBehalf

Source

Details

Signature

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

Visibility

external

State Mutability

nonpayable

Requires

Modifiers

Internal Functions

_ensureCanExchange

Source

Details

Signature

_ensureCanExchange(bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey)

Visibility

internal

State Mutability

view

Requires

_exchange

Source

Details

Signature

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

Visibility

internal

State Mutability

nonpayable

_feeRateForExchange

Source

Details

Signature

_feeRateForExchange(bytes32 , bytes32 destinationCurrencyKey) returns (uint256)

Visibility

internal

State Mutability

view

_getAmountReceivedForExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

pure

_getAmountsForExchangeMinusFees

Source

Details

Signature

_getAmountsForExchangeMinusFees(uint256 sourceAmount, bytes32 sourceCurrencyKey, bytes32 destinationCurrencyKey) returns (uint256, uint256, uint256, uint256, uint256)

Visibility

internal

State Mutability

view

_getExchangeEntry

Source

Details

Signature

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

Visibility

internal

State Mutability

view

_internalSettle

Source

Details

Signature

_internalSettle(address from, bytes32 currencyKey) returns (uint256, uint256, uint256)

Visibility

internal

State Mutability

nonpayable

Requires

_isDeviationAboveThreshold

Source

Details

Signature

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

Visibility

internal

State Mutability

view

_isSynthRateInvalid

Source

Details

Signature

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

Visibility

internal

State Mutability

view

_settlementOwing

Source

Details

Signature

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

Visibility

internal

State Mutability

view

appendExchange

Source

Details

Signature

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

Visibility

internal

State Mutability

nonpayable

Emits

delegateApprovals

Source

Details

Signature

delegateApprovals() returns (contract IDelegateApprovals)

Visibility

internal

State Mutability

view

exchangeRates

Source

Details

Signature

exchangeRates() returns (contract IExchangeRates)

Visibility

internal

State Mutability

view

exchangeState

Source

Details

Signature

exchangeState() returns (contract IExchangeState)

Visibility

internal

State Mutability

view

feePool

Source

Details

Signature

feePool() returns (contract IFeePool)

Visibility

internal

State Mutability

view

getRoundIdsAtPeriodEnd

Source

Details

Signature

getRoundIdsAtPeriodEnd(struct IExchangeState.ExchangeEntry exchangeEntry) returns (uint256, uint256)

Visibility

internal

State Mutability

view

issuer

Source

Details

Signature

issuer() returns (contract IIssuer)

Visibility

internal

State Mutability

view

reclaim

Source

Details

Signature

reclaim(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

nonpayable

refund

Source

Details

Signature

refund(address from, bytes32 currencyKey, uint256 amount)

Visibility

internal

State Mutability

nonpayable

remitFee

Source

Details

Signature

remitFee(uint256 fee, bytes32 currencyKey)

Visibility

internal

State Mutability

nonpayable

secsLeftInWaitingPeriodForExchange

Source

Details

Signature

secsLeftInWaitingPeriodForExchange(uint256 timestamp) returns (uint256)

Visibility

internal

State Mutability

view

synthetix

Source

Details

Signature

synthetix() returns (contract ISynthetix)

Visibility

internal

State Mutability

view

systemStatus

Source

Details

Signature

systemStatus() returns (contract ISystemStatus)

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, uint256, uint256)

Visibility

external

State Mutability

nonpayable

suspendSynthWithInvalidRate

Source

Details

Signature

suspendSynthWithInvalidRate(bytes32 currencyKey)

Visibility

external

State Mutability

nonpayable

Requires

Modifiers

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)