UNPKG

14 kBMarkdownView Raw
1# Synthetix
2
3[![CircleCI](https://circleci.com/gh/Synthetixio/synthetix.svg?style=svg)](https://circleci.com/gh/Synthetixio/synthetix)
4[![codecov](https://codecov.io/gh/Synthetixio/synthetix/branch/develop/graph/badge.svg)](https://codecov.io/gh/Synthetixio/synthetix)
5[![npm version](https://badge.fury.io/js/synthetix.svg)](https://badge.fury.io/js/synthetix)
6[![Discord](https://img.shields.io/discord/413890591840272394.svg?color=768AD4&label=discord&logo=https%3A%2F%2Fdiscordapp.com%2Fassets%2F8c9701b98ad4372b58f13fd9f65f966e.svg)](https://discordapp.com/channels/413890591840272394/)
7[![Twitter Follow](https://img.shields.io/twitter/follow/synthetix_io.svg?label=synthetix_io&style=social)](https://twitter.com/synthetix_io)
8
9Synthetix is a crypto-backed synthetic asset platform.
10
11It is a multi-token system, powered by SNX, the Synthetix Network Token. SNX holders can stake SNX to issue Synths, on-chain synthetic assets via the [Mintr dApp](https://mintr.synthetix.io) The network currently supports an ever growing [list of synthetic assets](https://www.synthetix.io/tokens/). Please see the [list of the deployed contracts on MAIN and TESTNETS](https://developer.synthetix.io/api/docs/deployed-contracts.html)
12Synths can be traded using [synthetix.exchange](https://synthetix.exchange)
13
14Synthetix uses a proxy system so that upgrades will not be disruptive to the functionality of the contract. This smooths user interaction, since new functionality will become available without any interruption in their experience. It is also transparent to the community at large, since each upgrade is accompanied by events announcing those upgrades. New releases are managed via the [Synthetix Improvement Proposal (SIP)](https://sips.synthetix.io/all-sip) system similar to the [EF's EIPs](https://eips.ethereum.org/all)
15
16Prices are committed on chain by a trusted oracle. Moving to a decentralised oracle is phased in with the first phase completed for all forex prices using [Chainlink](https://feeds.chain.link/)
17
18Please note that this repository is under development.
19
20For the latest system documentation see [docs.synthetix.io](https://docs.synthetix.io)
21
22## DApps
23
24- [mintr.synthetix.io](https://mintr.synthetix.io)
25- [synthetix.exchange](https://synthetix.exchange)
26- [dashboard.synthetix.io](https://dashboard.synthetix.io)
27
28### Community
29
30[![Discord](https://img.shields.io/discord/413890591840272394.svg?color=768AD4&label=discord&logo=https%3A%2F%2Fdiscordapp.com%2Fassets%2F8c9701b98ad4372b58f13fd9f65f966e.svg)](https://discordapp.com/channels/413890591840272394/) [![Twitter Follow](https://img.shields.io/twitter/follow/synthetix_io.svg?label=synthetix_io&style=social)](https://twitter.com/synthetix_io)
31
32For a guide from the community, see [synthetix.community](https://synthetix.community)
33
34---
35
36## Repo Guide
37
38### Branching
39
40A note on the branches used in this repo.
41
42- `master` represents the contracts live on `mainnet` and all testnets.
43- `alpha` is for the newest version of contracts, and is reserved for deploys to `kovan`
44- `beta` is for promoted alpha contracts, and is reserved for deploys to `rinkeby`
45- `release-candidate` is for promoted beta contracts, and is reserved for deploys to `ropsten`
46
47When a new version of the contracts makes its way through all testnets, it eventually becomes promoted in `master`, with [semver](https://semver.org/) reflecting contract changes in the `major` or `minor` portion of the version (depending on backwards compatibility). `patch` changes are simply for changes to the JavaScript interface.
48
49### Testing
50
51[![CircleCI](https://circleci.com/gh/Synthetixio/synthetix.svg?style=svg)](https://circleci.com/gh/Synthetixio/synthetix)
52[![codecov](https://codecov.io/gh/Synthetixio/synthetix/branch/develop/graph/badge.svg)](https://codecov.io/gh/Synthetixio/synthetix)
53
54Please see [docs.synthetix.io/contracts/testing](https://docs.synthetix.io/contracts/testing) for an overview of the automated testing methodologies.
55
56## Module Usage
57
58[![npm version](https://badge.fury.io/js/synthetix.svg)](https://badge.fury.io/js/synthetix)
59
60This repo may be installed via `npm install` to support both node.js scripting applications and Solidity contract development.
61
62### Examples
63
64:100: Please see our walkthrus for code examples in both JavaScript and Solidity: [docs.synthetix.io/contracts/walkthrus](https://docs.synthetix.io/contracts/walkthrus)
65
66### Solidity API
67
68All interfaces are available via the path [`synthetix/contracts/interfaces`](./contracts/interfaces/).
69
70:zap: In your code, the key is to use `IAddressResolver` which can be tied to the immutable proxy: [`ReadProxyAddressResolver`](https://contracts.synthetix.io/ReadProxyAddressResolver) ([introduced in SIP-57](https://sips.synthetix.io/sips/sip-57)). You can then fetch `Synthetix`, `FeePool`, `Depot`, et al via `IAddressResolver.getAddress(bytes32 name)` where `name` is the `bytes32` version of the contract name (case-sensitive). Or you can fetch any synth using `IAddressResolver.getSynth(bytes32 synth)` where `synth` is the `bytes32` name of the synth (e.g. `iETH`, `sUSD`, `sDEFI`).
71
72E.g.
73
74`npm install synthetix`
75
76then you can write Solidity as below (using a compiler that links named imports via `node_modules`):
77
78```solidity
79pragma solidity 0.5.16;
80
81import 'synthetix/contracts/interfaces/IAddressResolver.sol';
82import 'synthetix/contracts/interfaces/ISynthetix.sol';
83
84
85contract MyContract {
86 // This should be instantiated with our ReadProxyAddressResolver
87 // it's a ReadProxy that won't change, so safe to code it here without a setter
88 // see https://docs.synthetix.io/addresses for addresses in mainnet and testnets
89 IAddressResolver public synthetixResolver;
90
91 constructor(IAddressResolver _snxResolver) public {
92 synthetixResolver = _snxResolver;
93 }
94
95 function synthetixIssue() external {
96 ISynthetix synthetix = synthetixResolver.getAddress('Synthetix');
97 require(synthetix != address(0), 'Synthetix is missing from Synthetix resolver');
98
99 // Issue for msg.sender = address(MyContract)
100 synthetix.issueMaxSynths();
101 }
102
103 function synthetixIssueOnBehalf(address user) external {
104 ISynthetix synthetix = synthetixResolver.getAddress('Synthetix');
105 require(synthetix != address(0), 'Synthetix is missing from Synthetix resolver');
106
107 // Note: this will fail if `DelegateApprovals.approveIssueOnBehalf(address(MyContract))` has
108 // not yet been invoked by the `user`
109 synthetix.issueMaxSynthsOnBehalf(user);
110 }
111}
112```
113
114### Node.js API
115
116- `getAST({ source, match = /^contracts\// })` Returns the Abstract Syntax Tree (AST) for all compiled sources. Optionally add `source` to restrict to a single contract source, and set `match` to an empty regex if you'd like all source ASTs including third party contracts
117- `getPathToNetwork({ network, file = '' })` Returns the path to the folder (or file within the folder) for the given network
118- `getSource({ network })` Return `abi` and `bytecode` for a contract `source`
119- `getSuspensionReasons({ code })` Return mapping of `SystemStatus` suspension codes to string reasons
120- `getStakingRewards({ network })` Return the list of staking reward contracts available.
121- `getSynths({ network })` Return the list of synths for a network
122- `getTarget({ network })` Return the information about a contract's `address` and `source` file. The contract names are those specified in [docs.synthetix.io/addresses](https://docs.synthetix.io/addresses)
123- `getTokens({ network })` Return the list of tokens (synths and `SNX`) used in the system, along with their addresses.
124- `getUsers({ network })` Return the list of user accounts within the Synthetix protocol (e.g. `owner`, `fee`, etc)
125- `getVersions({ network, byContract = false })` Return the list of deployed versions to the network keyed by tagged version. If `byContract` is `true`, it keys by `contract` name.
126- `networks` Return the list of supported networks
127- `toBytes32` Convert any string to a `bytes32` value
128
129#### Via code
130
131```javascript
132const snx = require('synthetix');
133
134snx.getAST();
135/*
136{ 'contracts/AddressResolver.sol':
137 { imports:
138 [ 'contracts/Owned.sol',
139 'contracts/interfaces/IAddressResolver.sol',
140 'contracts/interfaces/ISynthetix.sol' ],
141 contracts: { AddressResolver: [Object] },
142 interfaces: {},
143 libraries: {} },
144 'contracts/Owned.sol':
145 { imports: [],
146 contracts: { Owned: [Object] },
147 interfaces: {},
148 libraries: {} },
149*/
150
151snx.getAST({ source: 'Synthetix.sol' });
152/*
153{ imports:
154 [ 'contracts/ExternStateToken.sol',
155 'contracts/MixinResolver.sol',
156 'contracts/interfaces/ISynthetix.sol',
157 'contracts/TokenState.sol',
158 'contracts/interfaces/ISynth.sol',
159 'contracts/interfaces/IERC20.sol',
160 'contracts/interfaces/ISystemStatus.sol',
161 'contracts/interfaces/IExchanger.sol',
162 'contracts/interfaces/IEtherCollateral.sol',
163 'contracts/interfaces/IIssuer.sol',
164 'contracts/interfaces/ISynthetixState.sol',
165 'contracts/interfaces/IExchangeRates.sol',
166 'contracts/SupplySchedule.sol',
167 'contracts/interfaces/IRewardEscrow.sol',
168 'contracts/interfaces/IHasBalance.sol',
169 'contracts/interfaces/IRewardsDistribution.sol' ],
170 contracts:
171 { Synthetix:
172 { functions: [Array],
173 events: [Array],
174 variables: [Array],
175 modifiers: [Array],
176 structs: [],
177 inherits: [Array] } },
178 interfaces: {},
179 libraries: {} }
180*/
181
182// Get the path to the network
183snx.getPathToNetwork({ network: 'mainnet' });
184//'.../Synthetixio/synthetix/publish/deployed/mainnet'
185
186// retrieve an object detailing the contract ABI and bytecode
187snx.getSource({ network: 'rinkeby', contract: 'Proxy' });
188/*
189{
190 bytecode: '0..0',
191 abi: [ ... ]
192}
193*/
194
195snx.getSuspensionReasons();
196/*
197{
198 1: 'System Upgrade',
199 2: 'Market Closure',
200 3: 'Circuit breaker',
201 99: 'Emergency',
202};
203*/
204
205// retrieve the array of synths used
206snx.getSynths({ network: 'rinkeby' }).map(({ name }) => name);
207// ['sUSD', 'sEUR', ...]
208
209// retrieve an object detailing the contract deployed to the given network.
210snx.getTarget({ network: 'rinkeby', contract: 'ProxySynthetix' });
211/*
212{
213 name: 'ProxySynthetix',
214 address: '0x322A3346bf24363f451164d96A5b5cd5A7F4c337',
215 source: 'Proxy',
216 link: 'https://rinkeby.etherscan.io/address/0x322A3346bf24363f451164d96A5b5cd5A7F4c337',
217 timestamp: '2019-03-06T23:05:43.914Z',
218 txn: '',
219 network: 'rinkeby'
220}
221*/
222
223// retrieve the list of system user addresses
224snx.getUsers({ network: 'mainnet' });
225/*
226[ { name: 'owner',
227 address: '0xEb3107117FEAd7de89Cd14D463D340A2E6917769' },
228 { name: 'deployer',
229 address: '0xDe910777C787903F78C89e7a0bf7F4C435cBB1Fe' },
230 { name: 'marketClosure',
231 address: '0xC105Ea57Eb434Fbe44690d7Dec2702e4a2FBFCf7' },
232 { name: 'oracle',
233 address: '0xaC1ED4Fabbd5204E02950D68b6FC8c446AC95362' },
234 { name: 'fee',
235 address: '0xfeEFEEfeefEeFeefEEFEEfEeFeefEEFeeFEEFEeF' },
236 { name: 'zero',
237 address: '0x0000000000000000000000000000000000000000' } ]
238*/
239
240snx.getVersions();
241/*
242{ 'v2.21.12-107':
243 { tag: 'v2.21.12-107',
244 fulltag: 'v2.21.12-107',
245 release: 'Hadar',
246 network: 'kovan',
247 date: '2020-05-08T12:52:06-04:00',
248 commit: '19997724bc7eaceb902c523a6742e0bd74fc75cb',
249 contracts: { ReadProxyAddressResolver: [Object] }
250 }
251}
252*/
253
254snx.networks;
255// [ 'local', 'kovan', 'rinkeby', 'ropsten', 'mainnet' ]
256
257snx.toBytes32('sUSD');
258// '0x7355534400000000000000000000000000000000000000000000000000000000'
259```
260
261#### As a CLI tool
262
263Same as above but as a CLI tool that outputs JSON, using names without the `get` prefixes:
264
265```bash
266$ npx synthetix ast contracts/Synth.sol
267{
268 "imports": [
269 "contracts/Owned.sol",
270 "contracts/ExternStateToken.sol",
271 "contracts/MixinResolver.sol",
272 "contracts/interfaces/ISynth.sol",
273 "contracts/interfaces/IERC20.sol",
274 "contracts/interfaces/ISystemStatus.sol",
275 "contracts/interfaces/IFeePool.sol",
276 "contracts/interfaces/ISynthetix.sol",
277 "contracts/interfaces/IExchanger.sol",
278 "contracts/interfaces/IIssue"
279 # ...
280 ]
281}
282
283$ npx synthetix bytes32 sUSD
2840x7355534400000000000000000000000000000000000000000000000000000000
285
286$ npx synthetix networks
287[ 'local', 'kovan', 'rinkeby', 'ropsten', 'mainnet' ]
288
289$ npx synthetix source --network rinkeby --contract Proxy
290{
291 "bytecode": "0..0",
292 "abi": [ ... ]
293}
294
295$ npx synthetix suspension-reason --code 2
296Market Closure
297
298$ npx synthetix synths --network rinkeby --key name
299["sUSD", "sEUR", ... ]
300
301$ npx synthetix target --network rinkeby --contract ProxySynthetix
302{
303 "name": "ProxySynthetix",
304 "address": "0x322A3346bf24363f451164d96A5b5cd5A7F4c337",
305 "source": "Proxy",
306 "link": "https://rinkeby.etherscan.io/address/0x322A3346bf24363f451164d96A5b5cd5A7F4c337",
307 "timestamp": "2019-03-06T23:05:43.914Z",
308 "network": "rinkeby"
309}
310
311$ npx synthetix users --network mainnet --user oracle
312{
313 "name": "oracle",
314 "address": "0xaC1ED4Fabbd5204E02950D68b6FC8c446AC95362"
315}
316
317$ npx synthetix versions
318{
319 "v2.0-19": {
320 "tag": "v2.0-19",
321 "fulltag": "v2.0-19",
322 "release": "",
323 "network": "mainnet",
324 "date": "2019-03-11T18:17:52-04:00",
325 "commit": "eeb271f4fdd2e615f9dba90503f42b2cb9f9716e",
326 "contracts": {
327 "Depot": {
328 "address": "0x172E09691DfBbC035E37c73B62095caa16Ee2388",
329 "status": "replaced",
330 "replaced_in": "v2.18.1"
331 },
332 "ExchangeRates": {
333 "address": "0x73b172756BD5DDf0110Ba8D7b88816Eb639Eb21c",
334 "status": "replaced",
335 "replaced_in": "v2.1.11"
336 },
337
338 # ...
339
340 }
341 }
342}
343
344$ npx synthetix versions --by-contract
345{
346 "Depot": [
347 {
348 "address": "0x172E09691DfBbC035E37c73B62095caa16Ee2388",
349 "status": "replaced",
350 "replaced_in": "v2.18.1"
351 },
352 {
353 "address": "0xE1f64079aDa6Ef07b03982Ca34f1dD7152AA3b86",
354 "status": "current"
355 }
356 ],
357 "ExchangeRates": [
358 {
359 "address": "0x73b172756BD5DDf0110Ba8D7b88816Eb639Eb21c",
360 "status": "replaced",
361 "replaced_in": "v2.1.11"
362 },
363
364 # ...
365 ],
366
367 # ...
368}
369```