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¶
Related Contracts¶
Structs¶
SynthDepositEntry
¶
Stores an individual Synth deposit on sale.
Field | Type | Description |
---|---|---|
user |
address payable |
The depositor. |
amount |
uint256 |
The quantity of sUSD deposited. |
Variables¶
depositEndIndex
¶
The index one past the last deposit in the deposits
queue.
Type: uint256
depositStartIndex
¶
The index of the next deposit to be processed in the deposits
queue.
Type: uint256
deposits
¶
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
¶
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
¶
Type: uint256
minimumDepositAmount
¶
The minimum sUSD quantity required for a deposit to be added to the queue. Initialised to 50.0.
Type: uint256
smallDeposits
¶
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
¶
The total quantity of sUSD currently in the deposits
queue to be purchased.
Type: uint256
Constructor¶
constructor
¶
Initialises the various addresses this contract knows, along with the inherited SelfDestructible
and Pausable
instances.
Details
Signature
constructor(address _owner, address payable _fundsWallet, address _resolver)
Visibility
public
State Mutability
``
Views¶
resolverAddressesRequired
¶
Details
Signature
resolverAddressesRequired() view returns (bytes32[] addresses)
Visibility
public
State Mutability
view
synthetixReceivedForEther
¶
Computes the quantity of SNX received in exchange for a given quantity of Ether at current prices. This is equivalent to:
Details
Signature
synthetixReceivedForEther(uint256 amount) view returns (uint256)
Visibility
public
State Mutability
view
synthetixReceivedForSynths
¶
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:
Details
Signature
synthetixReceivedForSynths(uint256 amount) view returns (uint256)
Visibility
public
State Mutability
view
synthsReceivedForEther
¶
Computes the quantity of sUSD received in exchange for a given quantity of ETH at current prices. This is equivalent to:
Details
Signature
synthsReceivedForEther(uint256 amount) view returns (uint256)
Visibility
public
State Mutability
view
Restricted Functions¶
setFundsWallet
¶
Allows the owner to set the fundsWallet
address.
Details
Signature
setFundsWallet(address payable _fundsWallet)
Visibility
external
State Mutability
``
Modifiers
Emits
setMaxEthPurchase
¶
Details
Signature
setMaxEthPurchase(uint256 _maxEthPurchase)
Visibility
external
State Mutability
``
Modifiers
Emits
setMinimumDepositAmount
¶
Allows the owner to set the minimum deposit amount.
Details
Signature
setMinimumDepositAmount(uint256 _amount)
Visibility
external
State Mutability
``
Requires
Modifiers
Emits
withdrawSynthetix
¶
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
``
Modifiers
Internal Functions¶
_exchangeEtherForSNX
¶
Details
Signature
_exchangeEtherForSNX() returns (uint256)
Visibility
internal
State Mutability
``
Emits
_exchangeEtherForSynths
¶
Details
Signature
_exchangeEtherForSynths() returns (uint256)
Visibility
internal
State Mutability
``
Requires
_exchangeSynthsForSNX
¶
Details
Signature
_exchangeSynthsForSNX(uint256 synthAmount) returns (uint256)
Visibility
internal
State Mutability
``
Emits
exchangeRates
¶
Details
Signature
exchangeRates() view returns (contract IExchangeRates)
Visibility
internal
State Mutability
view
synthetix
¶
The address of the main Synthetix
contract; the depot contains SNX.
Type: Synthetix public
Details
Signature
synthetix() view returns (contract IERC20)
Visibility
internal
State Mutability
view
synthsUSD
¶
Details
Signature
synthsUSD() view returns (contract IERC20)
Visibility
internal
State Mutability
view
External Functions¶
depositSynths
¶
depositSynths(uint amount)
: Just an alias tosynth.transferFrom(msg.sender, this, amount)
. This requires the sender to have approved the deposit.
Details
Signature
depositSynths(uint256 amount)
Visibility
external
State Mutability
``
exchangeEtherForSNX
¶
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 withsynthetixReceivedForEther
. Sends the ether tofundsWallet
, 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() payable returns (uint256)
Visibility
external
State Mutability
payable
Modifiers
exchangeEtherForSNXAtRate
¶
exchangeEtherForSNXAtRate(uint guaranteedEtherRate, uint guaranteedSynthetixRate) returns (uint)
: AsexchangeEtherForSynthsAtRate
is toexchangeEtherForSynths
, this is toexchangeEtherForSNX
.
Details
Signature
exchangeEtherForSNXAtRate(uint256 guaranteedEtherRate, uint256 guaranteedSynthetixRate) payable returns (uint256)
Visibility
external
State Mutability
payable
Requires
Modifiers
exchangeEtherForSynths
¶
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() payable returns (uint256)
Visibility
external
State Mutability
payable
Modifiers
exchangeEtherForSynthsAtRate
¶
exchangeEtherForSynthsAtRate(uint guaranteedRate) returns (uint)
: Allows the caller to specify the current price, and then calls toexchangeEtherForSynths
. 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) payable returns (uint256)
Visibility
external
State Mutability
payable
Requires
Modifiers
exchangeSynthsForSNX
¶
exchangeSynthsForSNX(uint synthAmount) returns (uint)
: Identical toexchangeEtherForSNX
, but perform the price conversion withsynthetixReceivedForSynths
. The amount of synths to send is provided as a function argument, and then transferred tofundsWallet
withtransferFrom
, 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
``
Modifiers
exchangeSynthsForSNXAtRate
¶
exchangeSynthsForSNXAtRate(uint synthAmount, uint guaranteedRate) returns (uint)
: As perexchangeEtherForSNXAtRate
.
Details
Signature
exchangeSynthsForSNXAtRate(uint256 synthAmount, uint256 guaranteedRate) returns (uint256)
Visibility
external
State Mutability
``
Requires
Modifiers
withdrawMyDepositedSynths
¶
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 insmallDeposits
.
Details
Signature
withdrawMyDepositedSynths()
Visibility
external
State Mutability
``
Requires
Emits
Modifiers¶
rateNotInvalid
¶
Signature: rateNotInvalid(bytes32 currencyKey)
Events¶
ClearedDeposit
¶
Signature: ClearedDeposit(address fromAddress, address toAddress, uint256 fromETHAmount, uint256 toAmount, uint256 depositIndex)
Exchange
¶
Signature: Exchange(string fromCurrency, uint256 fromAmount, string toCurrency, uint256 toAmount)
FundsWalletUpdated
¶
Signature: FundsWalletUpdated(address newFundsWallet)
MaxEthPurchaseUpdated
¶
Signature: MaxEthPurchaseUpdated(uint256 amount)
MinimumDepositAmountUpdated
¶
Signature: MinimumDepositAmountUpdated(uint256 amount)
NonPayableContract
¶
Signature: NonPayableContract(address receiver, uint256 amount)
SynthDeposit
¶
Signature: SynthDeposit(address user, uint256 amount, uint256 depositIndex)
SynthDepositNotAccepted
¶
Signature: SynthDepositNotAccepted(address user, uint256 amount, uint256 minimum)
SynthDepositRemoved
¶
Signature: SynthDepositRemoved(address user, uint256 amount, uint256 depositIndex)
SynthWithdrawal
¶
Signature: SynthWithdrawal(address user, uint256 amount)