Integrations Overview¶
Who this guide is for
This is a series of guides for developers looking into integrate with Synthetix protocol. Please read the below thoroughly and ask for help in the #dev-portal
channel of our Discord.
If you're looking to integrate Synthetix into your dApps and scripts, please reference the libraries section in addition to the data guide.
Synthetix provides the following integration guides:
The additional contextual information below is also helpful as a companion reference to the guides provided.
Address Resolver¶
In our Achernar release, we introduced a new feature called the AddressResolver
contract.
In short, the AddressResolver
allows any referencing contract to have access to a number of key contract - in particular the underlying Synthetix
, FeePool
, SynthsUSD
and SynthsETH
contracts. There are plans in the near future to add our proxies as well.
The ReadProxyAddressResolver
is our readable AddressResolver
behind a proxy that won't change, so it's safe to use in your code (it only allows calls that do not mutate state). We have one for each testnet and mainnet up on the addresses page.
For guides on how to use the AddressResolver
in Solidity, see our trading section.
Proxies¶
Synthetix makes extensive use of the proxy pattern. This allows users and integrated systems to refer to immutable proxy addresses while the underlying functionality is passed through to the target or underlying contracts which can be updated by an owner
function. This allows for fast iteration of the Synthetix ecosystem at the cost of trust in the protocol.
The transaction's to
parameter can be to either the proxy or the underlying, however two things are worth noting:
the underlying is subject to change (and does most releases); and the events will always be emitted on the proxy, regardless of the to
parameter in the transaction.
For best results, always interact with the proxy using the ABI of the underlying.
Decentralize All the Things
In order for Synthetix to become a fully decentralized protocol, these upgradable proxy contracts need more oversight and constraint. Please read our blogpost for the path towards full decentralization and how the Proxy architecture is impacted: https://blog.synthetix.io/transition-to-decentralised-governance/ (see Protocol Changes)
As of this moment, the following contracts are behind proxies:
FeePool
is behindProxyFeePool
Synthetix
is behind bothProxyERC20
andProxySynthetix
(deprecated, see notice below).SynthsUSD
is behind bothProxyERC20sUSD
andProxysUSD
(deprecated)- All remaining synths are also behind a Proxy, all of which are the newer
ProxyERC20
pattern. e.g.ProxysETH
,ProxyiBTC
, etc.
Proxy Deprecation¶
Why are we deprecating proxies?
The current proxies have been marked deprecated:
- Synthetix (aka
ProxySynthetix
at0xC011A72400E58ecD99Ee497CF89E3775d4bd732F
) and - sUSD (aka
ProxysUSD
at0x57Ab1E02fEE23774580C119740129eAC7081e9D3
)
The Synthetix proxies use the CALL
pattern and set messageSender
on the target for any request (see here). This mutation inside functions that are marked view
- such as balanceOf
, break ERC20 interface conventions, and thus fail.
In their stead we have new integration proxies in place, used by both Uniswap and Kyber. The new integration proxies are fully ERC20 compliant and explictly call through to the target for all ERC20 functions (see ProxyERC20.sol).
If you are planning any integration with Synthetix, it is recommended that you use the newer proxies:
- Synthetix (aka
ProxyERC20
at0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F
) and - sUSD (aka
ProxyERC20sUSD
at0x57Ab1ec28D129707052df4dF418D58a2D46d5f51
)
That said however, both are functioning side by side while we transition over.
One note of caution: the events from the underlying contracts - Synthetix
and Synth
are still emitted on the currently deprecated proxy contracts. Indeed, SynthetixJs still use the deprecated proxies for this reason (see Synthetix.js). Once we migrate to the new proxies, the events will be emitted on the integration proxies and the deprecated ones will be removed entirely.
-
Phase 1
Prior to May 10, 2020, both proxies for
Synthetix
andSynthsUSD
will function. Our dApps and integrations will call and transact using the deprecated proxies, and all events emitted will be on the deprecated proxy. -
Phase 2
Time converter at worldtimebuddy.com
On
May 10, 2020 11pm UTC
, we will switch theproxy
andintegrationProxy
properties ofSynthetix
and ourSynthsUSD
contracts. We will then update our dApps and integrations (includingsynthetix-js
) to use the addresses of the new proxies for all calls and transactions. All events emitted will now be on the new ERC20 proxies. However, the deprecated proxies will continue to work until Phase 3. -
Phase 3 (Current)
Updated timeline to July 31
Due to some third party project requirements, we've decided to push back Phase 3 to the end of July, 2020. Please reach out to us in Discord channel
#dev-portal
if you need more time.Time converter at worldtimebuddy.com
On
July 31, 2020 11pm UTC
, we will set theintegrationProxy
property fromSynthetix
andSynthsUSD
to0x0
, meaning that no more incoming transactions on0xC011A72400E58ecD99Ee497CF89E3775d4bd732F
(ProxySynthetix
) or0x57Ab1E02fEE23774580C119740129eAC7081e9D3
(ProxysUSD
) will work. These will fail as the target contracts they use will no longer accept incoming requests from them. We will update ourProxySynthetix
andProxysUSD
labels to point to the new ERC20 proxies (in our docs and in our contract-linker utility). -
Phase 4: We will rename our proxy labels to all be
ProxyERC20<name>
where<name>
is eitherSynthetix
or the name of the synth (eg.sUSD
,iETH
, etc). We will also remove theintegrationProxy
property fromProxyable.sol
.
Example Scenarios:¶
Exchanging via Synthetix¶
Let's say you want to exchange 100
sUSD
for sETH
:
-
Phase 1 (prior to May 10, 2020):
- You can invoke
exchange(sUSD, 100e18, sETH)
on eitherProxySynthetix
(0xC011a72
) orProxyERC20
(0xC011a73
). - On success,
SynthExchange
will be emitted onProxySynthetix
(0xC011a72
) regardless of which proxy you used to transact.
- You can invoke
-
Phase 2 (between May 10 - May 30, 2020):
- You can still invoke
exchange(sUSD, 100e18, sETH)
on eitherProxySynthetix
(0xC011a72
) orProxyERC20
(0xC011a73
), however you are strongly recommended to migrate to usingProxyERC20
. - On success,
SynthExchange
will be emitted onProxyERC20
(0xC011a73
) regardless of which proxy you used to transact.
- You can still invoke
-
Phase 3 (From May 30, 2020):
- You can only invoke
exchange(sUSD, 100e18, sETH)
onProxyERC20
(0xC011a73
), the old proxy address will fail. - On success,
SynthExchange
will be emitted onProxyERC20
(0xC011a73
).
- You can only invoke
Transferring sUSD¶
Or say you want to transfer 5
sUSD
to user
-
Phase 1 (prior to May 10, 2020):
- You can invoke
transfer(user, 5e18)
on eitherProxysUSD
(0x57Ab1E0
) orProxyERC20sUSD
(0x57Ab1ec
). - On success,
Transfer
will be emitted onProxysUSD
(0x57Ab1E0
) regardless of which proxy you used to transact.
- You can invoke
-
Phase 2 (between May 10 - May 30, 2020):
- You can still invoke
transfer(user, 5e18)
on eitherProxysUSD
(0x57Ab1E0
) orProxyERC20sUSD
(0x57Ab1ec
), however you are strongly recommended to migrate to usingProxyERC20sUSD
. - On success,
Transfer
will be emitted onProxysUSD
(0x57Ab1E0
) regardless of which proxy you used to transact.
- You can still invoke
-
Phase 3 (From May 30, 2020):
- You can only invoke
transfer(user, 5e18)
onProxyERC20sUSD
(0x57Ab1ec
), the old proxy will fail. - On success,
Transfer
will be emitted onProxyERC20sUSD
(0x57Ab1ec
).
- You can only invoke
Fee Reclamation and Atomicity of Exchanges¶
In our Achernar release, we introduced Fee Reclamation (SIP-37). The major implication here is that if you invoke exchange(src, amount, dest)
in your smart contracts, you cannot atomically invoke dest.transfer()
or exchange(dest, ..., ...)
- both will fail until a waiting period expires.
You can use Exchanger.maxSecsLeftInWaitingPeriod()
to check how many seconds are left in the waiting period for that dest
synth. Once it's 0
, exchanges of the dest
synth will automatically settle any rebates or reclaims. However after the waiting period expires, dest.transfer()
will fail regardless if there are any exchanges awaiting settlement. To circumvent this, integrators are encouraged to use transferAndSettle
or transferFromAndSettle
. Alternatively, Exchanger.settle()
can be invoked directly prior to a transfer
or transferFrom
.