• Stars
    star
    1,177
  • Rank 39,735 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Synthetix Solidity smart contracts

Synthetix

CircleCI codecov npm version Discord Twitter Follow

Synthetix is a crypto-backed synthetic asset platform.

It 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 Staking dApp The network currently supports an ever-growing list of synthetic assets. Please see the list of the deployed contracts on MAIN and TESTNETS Synths can be traded using Kwenta

Synthetix 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) system similar to the EIPs

Prices are committed on-chain by a trusted oracle provided by Chainlink.

Please note that this repository is under development.

For the latest system documentation see docs.synthetix.io

DApps

Community

Discord Twitter Follow

For a guide from the community, see synthetix.community


Repo Guide

Branching

A note on the branches used in this repo.

  • master represents the contracts live on mainnet and all testnets.

When a new version of the contracts makes its way through all testnets, it eventually becomes promoted in master, with semver 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.

Testing

CircleCI codecov

Please see docs.synthetix.io/contracts/testing for an overview of the automated testing methodologies.

Module Usage

npm version

This repo may be installed via npm install to support both node.js scripting applications and Solidity contract development.

Examples

💯 Please see our walkthroughs for code examples in both JavaScript and Solidity: docs.synthetix.io/integrations

Solidity API

All interfaces are available via the path synthetix/contracts/interfaces.

âš¡ In your code, the key is to use IAddressResolver which can be tied to the immutable proxy: ReadProxyAddressResolver (introduced in 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).

E.g.

npm install synthetix

then you can write Solidity as below (using a compiler that links named imports via node_modules):

pragma solidity 0.5.16;

import 'synthetix/contracts/interfaces/IAddressResolver.sol';
import 'synthetix/contracts/interfaces/ISynthetix.sol';

contract MyContract {
  // This should be instantiated with our ReadProxyAddressResolver
  // it's a ReadProxy that won't change, so safe to code it here without a setter
  // see https://docs.synthetix.io/addresses for addresses in mainnet and testnets
  IAddressResolver public synthetixResolver;

  constructor(IAddressResolver _snxResolver) public {
    synthetixResolver = _snxResolver;
  }

  function synthetixIssue() external {
    ISynthetix synthetix = synthetixResolver.getAddress('Synthetix');
    require(synthetix != address(0), 'Synthetix is missing from Synthetix resolver');

    // Issue for msg.sender = address(MyContract)
    synthetix.issueMaxSynths();
  }

  function synthetixIssueOnBehalf(address user) external {
    ISynthetix synthetix = synthetixResolver.getAddress('Synthetix');
    require(synthetix != address(0), 'Synthetix is missing from Synthetix resolver');

    // Note: this will fail if `DelegateApprovals.approveIssueOnBehalf(address(MyContract))` has
    // not yet been invoked by the `user`
    synthetix.issueMaxSynthsOnBehalf(user);
  }
}

Node.js API

  • 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
  • getPathToNetwork({ network, file = '' }) Returns the path to the folder (or file within the folder) for the given network
  • getSource({ network }) Return abi and bytecode for a contract source
  • getSuspensionReasons({ code }) Return mapping of SystemStatus suspension codes to string reasons
  • getStakingRewards({ network }) Return the list of staking reward contracts available.
  • getSynths({ network }) Return the list of synths for a network
  • getTarget({ network }) Return the information about a contract's address and source file. The contract names are those specified in docs.synthetix.io/addresses
  • getTokens({ network }) Return the list of tokens (synths and SNX) used in the system, along with their addresses.
  • getUsers({ network }) Return the list of user accounts within the Synthetix protocol (e.g. owner, fee, etc)
  • 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.
  • networks Return the list of supported networks
  • toBytes32 Convert any string to a bytes32 value

Via code

const snx = require('synthetix');

snx.getAST();
/*
{ 'contracts/AddressResolver.sol':
   { imports:
      [ 'contracts/Owned.sol',
        'contracts/interfaces/IAddressResolver.sol',
        'contracts/interfaces/ISynthetix.sol' ],
     contracts: { AddressResolver: [Object] },
     interfaces: {},
     libraries: {} },
  'contracts/Owned.sol':
   { imports: [],
     contracts: { Owned: [Object] },
     interfaces: {},
     libraries: {} },
*/

snx.getAST({ source: 'Synthetix.sol' });
/*
{ imports:
   [ 'contracts/ExternStateToken.sol',
     'contracts/MixinResolver.sol',
     'contracts/interfaces/ISynthetix.sol',
     'contracts/TokenState.sol',
     'contracts/interfaces/ISynth.sol',
     'contracts/interfaces/IERC20.sol',
     'contracts/interfaces/ISystemStatus.sol',
     'contracts/interfaces/IExchanger.sol',
     'contracts/interfaces/IIssuer.sol',
     'contracts/interfaces/ISynthetixState.sol',
     'contracts/interfaces/IExchangeRates.sol',
     'contracts/SupplySchedule.sol',
     'contracts/interfaces/IRewardEscrow.sol',
     'contracts/interfaces/IHasBalance.sol',
     'contracts/interfaces/IRewardsDistribution.sol' ],
  contracts:
   { Synthetix:
      { functions: [Array],
        events: [Array],
        variables: [Array],
        modifiers: [Array],
        structs: [],
        inherits: [Array] } },
  interfaces: {},
  libraries: {} }
*/

// Get the path to the network
snx.getPathToNetwork({ network: 'mainnet' });
//'.../Synthetixio/synthetix/publish/deployed/mainnet'

// retrieve an object detailing the contract ABI and bytecode
snx.getSource({ network: 'goerli', contract: 'Proxy' });
/*
{
  bytecode: '0..0',
  abi: [ ... ]
}
*/

snx.getSuspensionReasons();
/*
{
	1: 'System Upgrade',
	2: 'Market Closure',
	3: 'Circuit breaker',
	99: 'Emergency',
};
*/

// retrieve the array of synths used
snx.getSynths({ network: 'goerli' }).map(({ name }) => name);
// ['sUSD', 'sEUR', ...]

// retrieve an object detailing the contract deployed to the given network.
snx.getTarget({ network: 'goerli', contract: 'ProxySynthetix' });
/*
{
	name: 'ProxySynthetix',
  address: '0x322A3346bf24363f451164d96A5b5cd5A7F4c337',
  source: 'Proxy',
  link: 'https://goerli.etherscan.io/address/0x322A3346bf24363f451164d96A5b5cd5A7F4c337',
  timestamp: '2019-03-06T23:05:43.914Z',
  txn: '',
	network: 'goerli'
}
*/

// retrieve the list of system user addresses
snx.getUsers({ network: 'mainnet' });
/*
[ { name: 'owner',
    address: '0xEb3107117FEAd7de89Cd14D463D340A2E6917769' },
  { name: 'deployer',
    address: '0x302d2451d9f47620374B54c521423Bf0403916A2' },
  { name: 'marketClosure',
    address: '0xC105Ea57Eb434Fbe44690d7Dec2702e4a2FBFCf7' },
  { name: 'oracle',
    address: '0xaC1ED4Fabbd5204E02950D68b6FC8c446AC95362' },
  { name: 'fee',
    address: '0xfeEFEEfeefEeFeefEEFEEfEeFeefEEFeeFEEFEeF' },
  { name: 'zero',
    address: '0x0000000000000000000000000000000000000000' } ]
*/

snx.getVersions();
/*
{ 'v2.21.12-107':
   { tag: 'v2.21.12-107',
     fulltag: 'v2.21.12-107',
     release: 'Hadar',
     network: 'goerli',
     date: '2020-05-08T12:52:06-04:00',
     commit: '19997724bc7eaceb902c523a6742e0bd74fc75cb',
		 contracts: { ReadProxyAddressResolver: [Object] }
		}
}
*/

snx.networks;
// [ 'local', 'goerli', 'mainnet' ]

snx.toBytes32('sUSD');
// '0x7355534400000000000000000000000000000000000000000000000000000000'

As a CLI tool

Same as above but as a CLI tool that outputs JSON, using names without the get prefixes:

$ npx synthetix ast contracts/Synth.sol
{
  "imports": [
    "contracts/Owned.sol",
    "contracts/ExternStateToken.sol",
    "contracts/MixinResolver.sol",
    "contracts/interfaces/ISynth.sol",
    "contracts/interfaces/IERC20.sol",
    "contracts/interfaces/ISystemStatus.sol",
    "contracts/interfaces/IFeePool.sol",
    "contracts/interfaces/ISynthetix.sol",
    "contracts/interfaces/IExchanger.sol",
    "contracts/interfaces/IIssue"
    # ...
  ]
}

$ npx synthetix bytes32 sUSD
0x7355534400000000000000000000000000000000000000000000000000000000

$ npx synthetix networks
[ 'local', 'goerli', 'mainnet' ]

$ npx synthetix source --network goerli --contract Proxy
{
  "bytecode": "0..0",
  "abi": [ ... ]
}

$ npx synthetix suspension-reason --code 2
Market Closure

$ npx synthetix synths --network goerli --key name
["sUSD", "sEUR", ... ]

$ npx synthetix target --network goerli --contract ProxySynthetix
{
  "name": "ProxySynthetix",
  "address": "0x322A3346bf24363f451164d96A5b5cd5A7F4c337",
  "source": "Proxy",
  "link": "https://goerli.etherscan.io/address/0x322A3346bf24363f451164d96A5b5cd5A7F4c337",
  "timestamp": "2019-03-06T23:05:43.914Z",
  "network": "goerli"
}

$ npx synthetix users --network mainnet --user oracle
{
  "name": "oracle",
  "address": "0xaC1ED4Fabbd5204E02950D68b6FC8c446AC95362"
}

$ npx synthetix versions
{
  "v2.0-19": {
    "tag": "v2.0-19",
    "fulltag": "v2.0-19",
    "release": "",
    "network": "mainnet",
    "date": "2019-03-11T18:17:52-04:00",
    "commit": "eeb271f4fdd2e615f9dba90503f42b2cb9f9716e",
    "contracts": {
      "Depot": {
        "address": "0x172E09691DfBbC035E37c73B62095caa16Ee2388",
        "status": "replaced",
        "replaced_in": "v2.18.1"
      },
      "ExchangeRates": {
        "address": "0x73b172756BD5DDf0110Ba8D7b88816Eb639Eb21c",
        "status": "replaced",
        "replaced_in": "v2.1.11"
      },

      # ...

    }
  }
}

$ npx synthetix versions --by-contract
{
  "Depot": [
    {
      "address": "0x172E09691DfBbC035E37c73B62095caa16Ee2388",
      "status": "replaced",
      "replaced_in": "v2.18.1"
    },
    {
      "address": "0xE1f64079aDa6Ef07b03982Ca34f1dD7152AA3b86",
      "status": "current"
    }
  ],
  "ExchangeRates": [
    {
      "address": "0x73b172756BD5DDf0110Ba8D7b88816Eb639Eb21c",
      "status": "replaced",
      "replaced_in": "v2.1.11"
    },

    # ...
  ],

  # ...
}

More Repositories

1

synpress

Synpress is e2e testing framework based on Cypress.io and playwright with support for metamask.
JavaScript
570
star
2

synthetix-exchange

The Synthetix Exchange dApp code
TypeScript
121
star
3

synthetix-v3

TypeScript
117
star
4

SIPs

The Synthetix Improvement Proposal repository
Jupyter Notebook
104
star
5

staking

A dAPP for minting, burning, and earning on the Synthetix Protocol.
TypeScript
81
star
6

synthetix-mintr

Synthetix's Mintr v2.0: Lock up SNX to mint sUSD, claim weekly SNX and sUSD rewards for staking in the system..
JavaScript
75
star
7

synthetix-js

[deprecated] Please use https://github.com/Synthetixio/js-monorepo/tree/master/packages/contracts-interface
JavaScript
63
star
8

synthetix-subgraph

All sources for the handful of Synthetix subgraphs indexed by The Graph
TypeScript
61
star
9

js-monorepo

Standard JS conventions and utilities for working with Synthetix
TypeScript
31
star
10

cannon

Develop and test your smart contracts with existing protocols and tools inspired by Docker and Terraform
TypeScript
28
star
11

synthetix-data

A utility to query for data on Synthetix usage
JavaScript
24
star
12

simulation

Agent-based model of the proposed stablecoin.
Python
23
star
13

codegen-graph-ts

Create generated code based on a subgraph from The Graph
TypeScript
21
star
14

synthetix-website

Synthetix website powered by next.js + typescript
TypeScript
17
star
15

synthetix-docs

System and developer documentation for Synthetix
JavaScript
17
star
16

snx-grants-dao

TypeScript
16
star
17

perps-keepers

Keepers incentivised to maintain health on Synthetix Perps
TypeScript
16
star
18

synthetix-node

JavaScript
12
star
19

synthetix-v3-labs

Free experimentation on v3 components
Solidity
11
star
20

number-guessing-game

Example market for Synthetix v3
Solidity
11
star
21

hardhat-interact

Execute commands on deployed contracts using a helpful TUI. Inspired by `hardhat inteteract` command on https://github.com/Synthetixio/synthetix
TypeScript
10
star
22

kwenta

DEPRECATED. Please use: https://github.com/Kwenta/kwenta
TypeScript
10
star
23

synthetix-assets

Synthetix Assets
10
star
24

v3ui

Synthetix V3 UI Monorepo
TypeScript
10
star
25

js

BETA: Javascript library for interacting with the Synthetix protocol
TypeScript
9
star
26

optimistic-trader

Demo app to script your L2 bot
JavaScript
9
star
27

synthetix-dashboard

Synthetix Dashboard website
CSS
9
star
28

futures-keepers

TypeScript
8
star
29

vanity-contract

Tool to mine vanity ETH contract address
JavaScript
8
star
30

synthetix-deployments

Infrastructure-as-code definition for Synthetix contracts on all of its deployed networks
JavaScript
7
star
31

python-sdk

A python SDK for interactions with the Synthetix protocol
Python
7
star
32

contract-linker

Auto-linking to Synthetix contracts
JavaScript
5
star
33

tokenvest

JavaScript
5
star
34

synthetix-sandbox

Solidity
5
star
35

docker-sec-tools

Docker container based on docker-node with security-oriented tools included.
Dockerfile
4
star
36

Synthetix-Gitbook-v3

4
star
37

bfp-market

swsteth <> 1x short eth. l1 perp
TypeScript
4
star
38

deprecated-whitepaper

DEPRECATED - The old Havven White Paper
TeX
4
star
39

snx-v3-prototype

TypeScript
4
star
40

data

Create and host a database replica of activity on the Synthetix protocol
HTML
4
star
41

synthetix-scripts

A set of cli utilities for the Synthetix protocol
JavaScript
4
star
42

docker-e2e

Docker container based on docker-node with e2e-related tools included.
Dockerfile
3
star
43

synthetix-shaula-frontend

UI to interact with the new Synthetix Shaula release containing Multi-Collateral Loans and Shorting features.
JavaScript
2
star
44

synthetix-utility

Utility smart contracts to be used with the Synthetix dApps
2
star
45

synthetix-translations

Synthetix Translations module! Internationalization inside the Synthetix dApp ecosystem
JavaScript
2
star
46

synthetix-delegate

Synthetix Delegate
TypeScript
2
star
47

example-rewards-distributor

Example repository for deploying a rewards distributor
Solidity
2
star
48

perps-event-decoder

Decode perps transaction events
JavaScript
2
star
49

docker-node

Docker containers based on official node images used across Synthetix repositories for CI purposes.
Dockerfile
2
star
50

utility-contracts

A collection of useful smart contract components. (internal)
Python
2
star
51

synthetix-router

TypeScript
2
star
52

spartan-council

Custom Contract for issuing NFT tokens for SIP 93: Supersede SIP-90 to Delegated Council Governance.
JavaScript
2
star
53

fork

Simple utility to fork the Synthetix protocol for testing and benchmarking
JavaScript
1
star
54

ui

react ui components
TypeScript
1
star
55

docker-shared

Shared resources used across Synthetix docker images.
JavaScript
1
star
56

js-template

A starter project for JS-based projects (predominantly nodejs)
JavaScript
1
star
57

safe-synthetix-module

Customization for Gnosis Safes used to govern Synthetix protocol
Solidity
1
star
58

snx-ambassadors-dapp

The dApp for the delegation of voting powers to the SNX Ambassadors
TypeScript
1
star
59

stats

TypeScript
1
star
60

roadmap

Roadmap
1
star
61

ipfs-follower

Scripts for automatic ipfs-cluster-follower node installation
Shell
1
star
62

v3-markets-prototype

TypeScript
1
star
63

litepapers

All the Synthetix Litepaper versions that have been published in the past.
1
star
64

cannon-plugin-router

Cannon Plugin for generating Router
JavaScript
1
star
65

Synthetix-Gitbook-Docs

1
star
66

perps-ecosystem

TypeScript
1
star
67

trusted-multicall-forwarder

ERC-2771 compliant trusted forwarder including Multicall3 functionality with error bubbling
Solidity
1
star
68

sample-v3-keeper

Prototype V3 keeper using the Synthetix Python SDK
Python
1
star
69

sdk-playground

Tools and scripts using the Synthetix python sdk
Python
1
star
70

erc7412

Reference implementation for ERC-7412
Solidity
1
star
71

providers

Javascript library for handling providers on Layer 1 & Optimism Layer 2
TypeScript
1
star
72

snax-core

1
star