Skip to content

Depot

Description

Allows anyone with sUSD to deposit their sUSD and users to exchange ETH for sUSD.

sUSD Deposits are put into a FIFO queue which will the depositor will recieve ETH at the ETH rate at the time of the exchange.

Throughout, the contract assumes that sUSD is always worth exactly US$1. So: a) this will only work with sUSD. b) there's a profit opportunity if the sUSD is off its peg.

!!! SNX exchange functionality has been deprecated on MAINNET and is now used as a SNX faucet on the testnets only.

Source: contracts/Depot.sol

Architecture

Libraries

Inheritance Graph

graph TD Depot[Depot] --> SelfDestructible[SelfDestructible] Depot[Depot] --> Pausable[Pausable] Depot[Depot] --> MixinResolver[MixinResolver] SelfDestructible[SelfDestructible] --> Owned[Owned] Pausable[Pausable] --> Owned[Owned] MixinResolver[MixinResolver] --> Owned[Owned]

Structs

SynthDepositEntry

Source

Stores an individual Synth deposit on sale.

Field Type Description
user address payable The depositor.
amount uint256 The quantity of sUSD deposited.

Variables

depositEndIndex

Source

The index one past the last deposit in the deposits queue.

Type: uint256

depositStartIndex

Source

The index of the next deposit to be processed in the deposits queue.

Type: uint256

deposits

Source

Users can deposit sUSD to be sold on the depot. This variable holds the queue of open deposits, which are sold in the order they were deposited.

This queue is stored as an "array" within a mapping: the keys are array indices. Deposits are stored by a contiguous block of keys between depositStartIndex (inclusive) and depositEndIndex (exclusive).

A mapping is used instead of an array in order to avoid having to copy entries around when deposits are deleted, which saves on gas. When a deposit is made it is added to the end of the list, and when a deposit is filled, it is removed from the start of the list. Thus over time the list of deposits slides down the set of array indexes, but the address space of the mapping is large enough that it will never be filled.

Type: mapping(uint256 => struct Depot.SynthDepositEntry)

fundsWallet

Source

The address where ether and synths raised by selling SNX are sent.

It is also where ether is sent if the proceeds of a sale of synths could not be transferred because the recipient is a non-payable contract.

Type: address payable

maxEthPurchase

Source

Type: uint256

minimumDepositAmount

Source

The minimum sUSD quantity required for a deposit to be added to the queue. Initialised to 50.0.

Type: uint256

smallDeposits

Source

Deposits of less than minimumDepositAmount sUSD are not placed on the deposits queue. Instead, they are kept here so that the depositor can withdraw them.

Type: mapping(address => uint256)

totalSellableDeposits

Source

The total quantity of sUSD currently in the deposits queue to be purchased.

Type: uint256

Constructor

constructor

Source

Initialises the various addresses this contract knows, along with the inherited SelfDestructible and Pausable instances.

Details

Signature

(address _owner, address payable _fundsWallet, address _resolver)

Visibility

public

State Mutability

nonpayable

Views

synthetixReceivedForEther

Source

Computes the quantity of SNX received in exchange for a given quantity of Ether at current prices. This is equivalent to:

Q_\text{SNX} = Q_\text{ETH} \times \frac{\pi_\text{ETH}}{\pi_\text{SNX}}
Details

Signature

synthetixReceivedForEther(uint256 amount) returns (uint256)

Visibility

public

State Mutability

view

synthetixReceivedForSynths

Source

Computes the quantity of SNX received in exchange for a given quantity of sUSD at current prices, assuming sUSD are worth $1. This is equivalent to:

Q_\text{SNX} = Q_\text{sUSD} \times \frac{1}{\pi_\text{SNX}}
Details

Signature

synthetixReceivedForSynths(uint256 amount) returns (uint256)

Visibility

public

State Mutability

view

synthsReceivedForEther

Source

Computes the quantity of sUSD received in exchange for a given quantity of ETH at current prices. This is equivalent to:

Q_\text{sUSD} = Q_\text{ETH} \times \pi_\text{SNX}
Details

Signature

synthsReceivedForEther(uint256 amount) returns (uint256)

Visibility

public

State Mutability

view

Restricted Functions

setFundsWallet

Source

Allows the owner to set the fundsWallet address.

Details

Signature

setFundsWallet(address payable _fundsWallet)

Visibility

external

State Mutability

nonpayable

Modifiers

Emits

setMaxEthPurchase

Source

Details

Signature

setMaxEthPurchase(uint256 _maxEthPurchase)

Visibility

external

State Mutability

nonpayable

Modifiers

Emits

setMinimumDepositAmount

Source

Allows the owner to set the minimum deposit amount.

Details

Signature

setMinimumDepositAmount(uint256 _amount)

Visibility

external

State Mutability

nonpayable

Requires

Modifiers

Emits

withdrawSynthetix

Source

  • withdrawSynthetix(uint amount): Only callable by the contract owner. Allows the owner to transfer SNX out of the Depot to themselves.
Details

Signature

withdrawSynthetix(uint256 amount)

Visibility

external

State Mutability

nonpayable

Modifiers

Internal Functions

_exchangeEtherForSNX

Source

Details

Signature

_exchangeEtherForSNX() returns (uint256)

Visibility

internal

State Mutability

nonpayable

Emits

_exchangeEtherForSynths

Source

Details

Signature

_exchangeEtherForSynths() returns (uint256)

Visibility

internal

State Mutability

nonpayable

Requires

_exchangeSynthsForSNX

Source

Details

Signature

_exchangeSynthsForSNX(uint256 synthAmount) returns (uint256)

Visibility

internal

State Mutability

nonpayable

Emits

exchangeRates

Source

Details

Signature

exchangeRates() returns (contract IExchangeRates)

Visibility

internal

State Mutability

view

synthetix

Source

The address of the main Synthetix contract; the depot contains SNX.

Type: Synthetix public

Details

Signature

synthetix() returns (contract IERC20)

Visibility

internal

State Mutability

view

synthsUSD

Source

Details

Signature

synthsUSD() returns (contract IERC20)

Visibility

internal

State Mutability

view

External Functions

depositSynths

Source

  • depositSynths(uint amount): Just an alias to synth.transferFrom(msg.sender, this, amount). This requires the sender to have approved the deposit.
Details

Signature

depositSynths(uint256 amount)

Visibility

external

State Mutability

nonpayable

exchangeEtherForSNX

Source

  • exchangeEtherForSNX() returns (uint): Requires that the contract is not paused, and that the prices are not stale. Converts the received ether to a quantity of SNX with synthetixReceivedForEther. Sends the ether to fundsWallet, sends the converted quantity of SNX to the message sender from the contract's own reserves. Returns the SNX quantity sent. If the contract has insufficient SNX, then the transfer will fail and the transaction will revert.
Details

Signature

exchangeEtherForSNX() returns (uint256)

Visibility

external

State Mutability

payable

Modifiers

exchangeEtherForSNXAtRate

Source

  • exchangeEtherForSNXAtRate(uint guaranteedEtherRate, uint guaranteedSynthetixRate) returns (uint): As exchangeEtherForSynthsAtRate is to exchangeEtherForSynths, this is to exchangeEtherForSNX.
Details

Signature

exchangeEtherForSNXAtRate(uint256 guaranteedEtherRate, uint256 guaranteedSynthetixRate) returns (uint256)

Visibility

external

State Mutability

payable

Requires

Modifiers

exchangeEtherForSynths

Source

Sells sUSD to callers who send ether. The synths are sold from the deposits queue in the order they were deposited.

Purchased quantity: msg.value * usdToEthPrice

Each deposit is sold in turn until the full This function if invoked with a

Requires that the contract is not paused, and that the prices are not stale.

Returns the number of sUSD exchanged. Converts any ether sent to the contract to a quantity of synths at current prices. Fulfils this quantity by iterating through the deposit queue until the entire quantity is found. If a given deposit is insufficient to cover the entire requested amount, it is exhausted and removed from the queue. For each deposit found, the proper quantity of ether is sent to the depositor. If the quantity could not be sent because the target is a non-payable contract, then it is remitted to fundsWallet. Then send the Synths to the recipient. If the whole quantity could not be fulfilled, then the remaining ether is refunded to the purchaser.

  • exchangeEtherForSynths() returns (uint):
Details

Signature

exchangeEtherForSynths() returns (uint256)

Visibility

external

State Mutability

payable

Modifiers

exchangeEtherForSynthsAtRate

Source

  • exchangeEtherForSynthsAtRate(uint guaranteedRate) returns (uint): Allows the caller to specify the current price, and then calls to exchangeEtherForSynths. Reverts if the current price does not match the price provided as an argument. This is intended as a protection against front-running by the contract owner, or otherwise a case where a price update is in flight at the invocation time.
Details

Signature

exchangeEtherForSynthsAtRate(uint256 guaranteedRate) returns (uint256)

Visibility

external

State Mutability

payable

Requires

Modifiers

exchangeSynthsForSNX

Source

  • exchangeSynthsForSNX(uint synthAmount) returns (uint): Identical to exchangeEtherForSNX, but perform the price conversion with synthetixReceivedForSynths. The amount of synths to send is provided as a function argument, and then transferred to fundsWallet with transferFrom, so this function requires the caller to have approved the depot contract to make such a withdrawal. Note that this assumes that sUSD is worth exactly one dollar.
Details

Signature

exchangeSynthsForSNX(uint256 synthAmount) returns (uint256)

Visibility

external

State Mutability

nonpayable

Modifiers

exchangeSynthsForSNXAtRate

Source

  • exchangeSynthsForSNXAtRate(uint synthAmount, uint guaranteedRate) returns (uint): As per exchangeEtherForSNXAtRate.
Details

Signature

exchangeSynthsForSNXAtRate(uint256 synthAmount, uint256 guaranteedRate) returns (uint256)

Visibility

external

State Mutability

nonpayable

Requires

Modifiers

withdrawMyDepositedSynths

Source

  • withdrawMyDepositedSynths(): Withdraws all Synths deposited by the message sender. Iterates through the entire deposit queue; if for a given entry the message sender is the depositor, delete that deposit and and add the deposited quantity of tokens to the pile to be remitted. Then transfer this quantity back to the message sender, along with any tokens in smallDeposits.
Details

Signature

withdrawMyDepositedSynths()

Visibility

external

State Mutability

nonpayable

Requires

Emits

Fallback Function

() (fallback function)

Source

This simply calls exchangeEtherForSynths so that if ether is sent to the contract, it is automatically exchanged for synths.

Details

Signature

()

Visibility

external

State Mutability

payable

Modifiers

Modifiers

rateNotStale

Source

Signature: rateNotStale(bytes32 currencyKey)

Events

ClearedDeposit

Source

Signature: ClearedDeposit(address fromAddress, address toAddress, uint256 fromETHAmount, uint256 toAmount, uint256 depositIndex)

Exchange

Source

Signature: Exchange(string fromCurrency, uint256 fromAmount, string toCurrency, uint256 toAmount)

FundsWalletUpdated

Source

Signature: FundsWalletUpdated(address newFundsWallet)

MaxEthPurchaseUpdated

Source

Signature: MaxEthPurchaseUpdated(uint256 amount)

MinimumDepositAmountUpdated

Source

Signature: MinimumDepositAmountUpdated(uint256 amount)

NonPayableContract

Source

Signature: NonPayableContract(address receiver, uint256 amount)

SynthDeposit

Source

Signature: SynthDeposit(address user, uint256 amount, uint256 depositIndex)

SynthDepositNotAccepted

Source

Signature: SynthDepositNotAccepted(address user, uint256 amount, uint256 minimum)

SynthDepositRemoved

Source

Signature: SynthDepositRemoved(address user, uint256 amount, uint256 depositIndex)

SynthWithdrawal

Source

Signature: SynthWithdrawal(address user, uint256 amount)