Synth¶
Description¶
This contract is the basis of all Synth flavours.
It exposes sufficient functionality for the Synthetix
and FeePool
contracts to manage its supply. Otherwise Synths are fairly vanilla ERC20 tokens; the PurgeableSynth
contract extends this basic functionality to allow the owner to liquidate a Synth if its total value is low enough.
See the main synth notes for more information about how Synths function in practice.
A Historical Note on Conversion Fees
Since transfer conversion is not operating, the following is recorded only to be kept in mind in case it is ever reactivated. At present there is no way for users to set a preferred currency.
The Synthetix system has implements both exchange and transfer fees on Synths. Although they should be distinct, the preferred currency auto conversion on transfer only charges the transfer fee, and not the exchange fee. As a result, it is possible to convert Synths more cheaply whenever the transfer fee is less than the conversion fee.
Given that the transfer fee is currently nil, if a user was able to set a preferred currency for themselves, it would be possible by this means to perform free Synth conversions. This would undercut fee revenue for the system to incentivise participants with. If markets had priced in the conversion fee, but were unaware of the exploit, then there would be a profit cycle available for someone exploiting this.
In particular:
Let \phi_\kappa, \ \phi_\tau \in [0,1] be the conversion and transfer fee rates, respectively. Let \pi_A, \ \pi_B be the prices of synths A and B in terms of some implicit common currency. Q_A will be the starting quantity of synth A.
Then to convert from A to B, quantities
are received if the user performs a standard conversion or a transfer conversion, respectively. The profit of performing a transfer conversion relative to a standard one is then:
That is, the relative profit is simply (\phi_\kappa - \phi_\tau). With no transfer fee, this is \phi_\kappa, as expected.
Source: contracts/Synth.sol
Variables¶
CONTRACT_NAME
¶
Type: bytes32
DECIMALS
¶
The number of decimal places this token uses. Fixed at 18.
Value: 18
Type: uint8
FEE_ADDRESS
¶
Type: address
currencyKey
¶
The identifier of this Synth within the Synthetix ecosystem. The currency key could in principle be distinct from this token's ERC20 symbol.
Type: bytes32
Constructor¶
constructor
¶
Initialises the feePool
and synthetix
addresses, this Synth's currencyKey
, and the inherited ExternStateToken
instance.
The precision in every Synth's fixed point representation is fixed at 18 so they are all conveniently interconvertible. The total supply of all new Synths is initialised to 0 since they must be created by the Synthetix
contract when issuing or converting between Synths, or by the FeePool
when users claim fees.
Details
Signature
constructor(address payable _proxy, contract TokenState _tokenState, string _tokenName, string _tokenSymbol, address _owner, bytes32 _currencyKey, uint256 _totalSupply, address _resolver)
Visibility
public
State Mutability
``
Requires
Views¶
resolverAddressesRequired
¶
Details
Signature
resolverAddressesRequired() view returns (bytes32[] addresses)
Visibility
public
State Mutability
view
transferableSynths
¶
Details
Signature
transferableSynths(address account) view returns (uint256)
Visibility
public
State Mutability
view
Restricted Functions¶
burn
¶
Allows the Synthetix
contract to burn existing Synths of this flavour. This is used whenever Synths are exchanged or burnt directly. This is also used to burn Synths involved in oracle frontrunning as part of the protection circuit. This is also used by the FeePool
to burn sUSD when fees are paid out.
Details
Signature
burn(address account, uint256 amount)
Visibility
external
State Mutability
``
Modifiers
issue
¶
Allows the Synthetix
contract to issue new Synths of this flavour. This is used whenever Synths are exchanged or issued directly. This is also used by the FeePool
to pay fees out.
Details
Signature
issue(address account, uint256 amount)
Visibility
external
State Mutability
``
Modifiers
setTotalSupply
¶
This allows the owner to set the total supply directly for upgrades, where the tokenState
is retained, but the total supply figure must be migrated.
For example, just such a migration is performed by this script.
Details
Signature
setTotalSupply(uint256 amount)
Visibility
external
State Mutability
``
Modifiers
transfer
¶
This is a pair of ERC20 transfer function.
Implemented based on ExternStateToken._transfer_byProxy
.
Warning
Due to SIP-37 Fee Reclamation, this will always fail if there are any exchanges awaiting settlement for this synth. To prevent failues, please use transferAndSettle()
below or invoke Exchanger.settle()
prior to transfer()
.
Details
Signature
transfer(address to, uint256 value) returns (bool)
Visibility
public
State Mutability
``
Modifiers
transferAndSettle
¶
Settles any outstanding fee reclaims and rebates from SIP-37 and then performs the transfer
functionality. If there is insufficient balance to transfer value
after any reclaims, the amount
will be reduced to the remaining balance of the sender.
Implemented based on ExternStateToken._transfer_byProxy
.
Details
Signature
transferAndSettle(address to, uint256 value) returns (bool)
Visibility
public
State Mutability
``
Modifiers
transferFrom
¶
This is a ERC20 transferFrom function.
Implemented based on ExternStateToken._transferFrom_byProxy
.
Warning
Due to SIP-37 Fee Reclamation, this will always fail if there are any exchanges awaiting settlement for this synth. To prevent failues, please use transferFromAndSettle()
below or invoke Exchanger.settle()
prior to transferFrom()
.
Details
Signature
transferFrom(address from, address to, uint256 value) returns (bool)
Visibility
public
State Mutability
``
Modifiers
transferFromAndSettle
¶
Settles any outstanding fee reclaims and rebates from SIP-37 and then performs the transferFrom
functionality. If there is insufficient balance to transfer value
after any reclaims, the amount
will be reduced to the remaining balance of the from
address.
Implemented based on ExternStateToken._transferFrom_byProxy
.
Warning
Due to SIP-37 Fee Reclamation, this will always fail if there are any exchanges awaiting settlement for this synth. To prevent failues, please use transferFromAndSettle()
below or invoke Exchanger.settle()
prior to transferFrom()
.
Details
Signature
transferFromAndSettle(address from, address to, uint256 value) returns (bool)
Visibility
public
State Mutability
``
Modifiers
Internal Functions¶
_ensureCanTransfer
¶
Details
Signature
_ensureCanTransfer(address from, uint256 value) view
Visibility
internal
State Mutability
view
Requires
_internalBurn
¶
Details
Signature
_internalBurn(address account, uint256 amount) returns (bool)
Visibility
internal
State Mutability
``
_internalIssue
¶
Details
Signature
_internalIssue(address account, uint256 amount)
Visibility
internal
State Mutability
``
_internalTransferFrom
¶
Details
Signature
_internalTransferFrom(address from, address to, uint256 value) returns (bool)
Visibility
internal
State Mutability
``
_isInternalContract
¶
Details
Signature
_isInternalContract(address account) view returns (bool)
Visibility
internal
State Mutability
view
_isInternalTransferCaller
¶
Details
Signature
_isInternalTransferCaller(address caller) view returns (bool)
Visibility
internal
State Mutability
view
_onlyProxyOrInternal
¶
Details
Signature
_onlyProxyOrInternal()
Visibility
internal
State Mutability
``
_transferToFeeAddress
¶
Details
Signature
_transferToFeeAddress(address to, uint256 value) returns (bool)
Visibility
internal
State Mutability
``
emitBurned
¶
Details
Signature
emitBurned(address account, uint256 value)
Visibility
internal
State Mutability
``
emitIssued
¶
Details
Signature
emitIssued(address account, uint256 value)
Visibility
internal
State Mutability
``
exchanger
¶
Details
Signature
exchanger() view returns (contract IExchanger)
Visibility
internal
State Mutability
view
feePool
¶
The address of the FeePool
contract.
Type: FeePool public
Details
Signature
feePool() view returns (contract IFeePool)
Visibility
internal
State Mutability
view
futuresMarketManager
¶
Details
Signature
futuresMarketManager() view returns (contract IFuturesMarketManager)
Visibility
internal
State Mutability
view
issuer
¶
Details
Signature
issuer() view returns (contract IIssuer)
Visibility
internal
State Mutability
view
systemStatus
¶
Details
Signature
systemStatus() view returns (contract ISystemStatus)
Visibility
internal
State Mutability
view
Modifiers¶
onlyInternalContracts
¶
onlyProxyOrInternal
¶
Events¶
Burned
¶
Records that a quantity of this Synth was burned.
This event is emitted from the Synths's proxy with the emitBurned
function.
Signature: Burned(address account, uint256 value)
Issued
¶
Records that a quantity of this Synth was newly issued.
This event is emitted from the Synths's proxy with the emitIssued
function.
Signature: Issued(address account, uint256 value)