How to use synthetix - 8 common examples

To help you get started, we’ve selected a few synthetix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Synthetixio / synthetix-js / tools / abitojs.js View on Github external
Object.keys(allContracts).forEach(contractName => {
      let target = contractName;
      let source = contractName;
      if (typeof allContracts[contractName] === 'object') {
        target = allContracts[contractName].target || target;
        source = allContracts[contractName].source || source;
      }

      // get the abis from the network's deploy from synthetix
      const { abi } = snx.getSource({ network, contract: source }) || {};
      // some environments might not have an ABI for this contract yet
      if (abi) {
        // track which contracts exist in this netork
        contractsInNetwork.push(contractName);

        // now create import header for index files
        const importStringForIndexFile = `import ${contractName} from './${contractName}';`;
        srcNetworkIndexFileHeader.push(importStringForIndexFile);

        // now only for source contracts in the original contract object
        if (contractName in contracts) {
          // write out ABI files (using ABIs from mainnet deploy)
          writeABIFileAsJS(network, contractName, abi);
          abiNetworkIndexFileHeader.push(importStringForIndexFile);

          // and track it
github Synthetixio / synthetix-js / tools / abitojs.js View on Github external
Object.values(SUPPORTED_NETWORKS).map(network => {
    // add the synth contract as well (target addresses are their proxies, and source is the synth contract)
    const synthContracts = snx.getSynths({ network }).reduce((memo, { name, subclass }) => {
      memo[name] = { target: `Proxy${name}`, source: subclass || 'Synth' };
      return memo;
    }, {});

    const allContracts = Object.assign({}, contracts, synthContracts);

    const importStringForHeaders = `import ${network} from './${network}';`;
    indexFileHeader.push(importStringForHeaders);

    const srcNetworkIndexFileHeader = [];
    const abiNetworkIndexFileHeader = [];
    const contractsInNetwork = [];
    const sourcesInNetwork = [];
    Object.keys(allContracts).forEach(contractName => {
      let target = contractName;
      let source = contractName;
github Synthetixio / synthetix-js / __tests__ / src / contracts / EscrowChecker.js View on Github external
test(`${network} must return escrow contract address`, async () => {
      const escrowAddress = await snxjs[contract].synthetix_escrow();
      const expectedAddress = snx.getTarget({ network, contract: 'SynthetixEscrow' }).address;
      expect(escrowAddress).toEqual(expectedAddress);
    });
  });
github Synthetixio / synthetix-js / __tests__ / src / contracts / Synth.js View on Github external
() => {
            expect(snxjs[synth].contract.interface.abi).toEqual(
              snx.getSource({ network, contract }).abi
            );
          };
        });
github Synthetixio / synthetix-js / __tests__ / src / contracts / Synth.js View on Github external
async () => {
            const synthetixProxy = await snxjs[synth].synthetixProxy();
            const expectedAddress = snx.getTarget({ network, contract: 'ProxySynthetix' }).address;
            expect(synthetixProxy).toEqual(expectedAddress);
          },
          15000
github Synthetixio / synthetix-js / tools / abitojs.js View on Github external
const writeAllABIFiles = network => {
  const folder = path.join(__dirname, '..', 'lib', 'abis', network);
  if (!fs.existsSync(folder)) {
    fs.mkdirSync(folder);
  }
  const sources = snx.getSource({ network });

  for (const [source, { abi }] of Object.entries(sources)) {
    const abiPath = path.join(folder, `${source}.json`);
    fs.writeFile(abiPath, JSON.stringify(abi, null, '\t') + '\n', err => {
      if (err) {
        console.log(err);
      } else {
        console.log(`ABI ${source}.son on ${network} successfully generated locally.`);
      }
    });
  }
};
github Synthetixio / synthetix-js / tools / abitojs.js View on Github external
.map(network => {
      const targets = snx.getTarget({ network });

      return `
        const ${network.toUpperCase()}_ADDRESSES = {
          ${Object.keys(targets)
            .map(name => `${name}: '${targets[name].address}'`)
            .join(',\n')}
        };`;
    })
    .join('\n\n');
github Synthetixio / synthetix-js / tools / abitojs.js View on Github external
.map(network => {
      const synths = snx.getSynths({ network });

      return `
        const ${network.toUpperCase()}_SYNTHS = ${util.inspect(synths, {
        showHidden: false,
        depth: null,
      })}
        `;
    })
    .join('\n\n');

synthetix

The smart contracts which make up the Synthetix system. (synthetix.io)

MIT
Latest version published 4 months ago

Package Health Score

69 / 100
Full package analysis