Git Product home page Git Product logo

set.js's Introduction

License NPM

set.js

set.js is a library for wrapping and interacting with Set Protocol V2 smart contracts. This library enables you to create, issue, redeem, and trade for Sets.

For Set Protocol V2 smart contract function descriptions, visit our docs

Getting Started

  1. Add this package to your project: yarn install set.js
  2. Configure your Set.js instance to read from & write to Ethereum, Polygon, or Optimism contract addresses. Your configuration for Ethereum Mainnet (Production) might look like this:
const SetJsEthereumMainnetAddresses = {
  controllerAddress: "0xF1B12A7b1f0AF744ED21eEC7d3E891C48Fd3c329",
  setTokenCreatorAddress: "0x026d25C2B70Ddbb8D759f1f38d6fD6e23b60B6DF",
  basicIssuanceModuleAddress: "0x508910aA6fF3D029Dc358dD0f775877A355BA35B",
  debtIssuanceModuleAddress: "0x338BEf3f37794dd199d6910E6109125D3eCa6048",
  debtIssuanceModuleV2Address: "0x3C0CC7624B1c408cF2cF11b3961301949f2F7820",
  streamingFeeModuleAddress: "0x3D8d14b7eFb8e342189ee14c3d40dCe005EB901B",
  tradeModuleAddress: "0x45D67b9dbEA9bd51ED2B67832addEAF839628fAa",
  navIssuanceModuleAddress: "0x33f6184b1695a8Fe344Ea6b7De11aA35A74Ec300",
  protocolViewerAddress: "0x15D860670b7DC211714282f1583CF591Cc3A945E"
}
  1. Pass in an ethereum provider to your Set.js instance (either an ethers.js or web3.js will work). Your Set.js initialization might look like this:
const SetJsConfig = {
  ethersProvider: new ethers.providers.Web3Provider(myProvider),
  ...SetJsEthereumMainnetAddresses,
};

const SetJsInstance = new SetJs(SetJsConfig);
  1. Begin using the Set Protocol. Try this command to see if your instance has been set up correctly (for ethereum production mainnet):
mySetJsInstance
  .setToken
  .fetchSetDetailsAsync(
    "0x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b",   // DeFi Pulse Index Set Token
    ["0xd8EF3cACe8b4907117a45B0b125c68560532F94D"], // Basic Issuance Module
    myAccount
  )

Take a look at our developer portal for more information on Set Protocol.

set.js's People

Contributors

justinkchen avatar asoong avatar cgewecke avatar williamsfu99 avatar controtie avatar rootulp avatar inje avatar ayshptk avatar

Stargazers

Louis avatar Saberhabeel avatar  avatar  avatar o avatar  avatar Vedmaka avatar emre avatar TokenDAO avatar Dan Harcsztark avatar Nelson avatar Siphamandla Mjoli avatar cryptohaver.ΞTH avatar EtherPan avatar Samuel Safahi avatar Nikita Shekhov avatar  avatar  avatar Moaaz Sidat avatar Eli Citron avatar YU HUNG, CHIANG avatar Alex Fanat avatar ReferralCrypto.com avatar  avatar Dennis Zoma avatar Adam McMahon avatar Atul Bhardwaj avatar pblivin0x avatar Marwan Hilmi avatar  avatar  avatar lil reentrant avatar Amos ATSUVIA avatar

Watchers

James Cloos avatar  avatar  avatar Oliver Tang avatar Richard avatar  avatar Felix Feng avatar  avatar  avatar

set.js's Issues

Trade API: next steps

⚠️ Actively edited. ⚠️

Several things have been raised by the #60 review that should be addressed in subsequent PRs

  • Service is can easily fail if one of the (many) external resource calls fails
  • Gas price oracles
    • Use fallbacks? e.g gasNow and EthGasStation ?
  • CoinGecko token list: especially bad for polygon which makes 4 external calls to compose a list.
    • (from review) In a follow up, we should make this fault tolerant to CoinGecko API failures, return default values for things like estimated USD value, and return some kind of error that indicates CoinGecko failed.

    • Pricing seems pretty time sensitive... perhaps we can have redundancy via another service?
    • Could also maintain our own token list (for metadata) and generate in a CI chron job / publish to github?
    • fallback on the dynamic generation if that fails?

Resolved in #60

  • Currently formats prices as dollar strings.
  • Should this be configurable, e.g pick your national currency
  • Should formatting be delegated to quote consumer?

Enable read operations without providing a signer.

Pure read operations like NavIssuanceAPI.getExpectedSetTokenIssueQuantity() should be able to be called with a default provider.

Currently it's required to set a provider gathered from a signer due to the following logic (ContractWrapper.ts:201):

const signer = (this.provider as JsonRpcProvider).getSigner(callerAddress);
const cacheKey = `NavIssuanceModule_${navIssuanceModuleAddress}_${await signer.getAddress()}`;

signer.getAddress() is not supported for a default provider.

Resolve warnings encountered on yarn add set.js

A vanilla install of set.js encounters the following:

❯ yarn add set.js
yarn add v1.22.10
[1/4] 🔍  Resolving packages...
warning set.js > [email protected]: WARNING: This package has been renamed to @truffle/hdwallet-provider.
warning set.js > truffle > mocha > [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
warning set.js > @truffle/contract > @ensdomains/ensjs > @ensdomains/[email protected]: Please use @ensdomains/ens-contracts
warning set.js > truffle > mocha > chokidar > [email protected]: "Please update to latest v2.3 or v2.2"
warning set.js > @truffle/contract > @ensdomains/ensjs > @ensdomains/[email protected]: Please use @ensdomains/ens-contracts
warning set.js > truffle > @truffle/db > [email protected]: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning set.js > truffle > @truffle/db > apollo-server > [email protected]: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning set.js > truffle > @truffle/preserve-to-filecoin > cids > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-filecoin > cids > multihashes > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > multihashes > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > uint8arrays > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/db > jsondown > [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
warning set.js > truffle > @truffle/preserve-to-filecoin > filecoin.js > @nodefactory/[email protected]: Package is deprecated in favour of @chainsafe/filsnap-adapter
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > [email protected]: This module has been superseded by @ipld/dag-cbor and multiformats
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > [email protected]: This module has been superseded by @ipld/dag-pb and multiformats
warning set.js > truffle > @truffle/debugger > remote-redux-devtools > [email protected]: Package moved to @redux-devtools/app.
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > multiaddr > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/debugger > remote-redux-devtools > [email protected]: Package moved to @redux-devtools/instrument.
warning set.js > truffle > @truffle/db > pouchdb > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning set.js > truffle > @truffle/db > apollo-server > graphql-tools > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning set.js > truffle > @truffle/db > pouchdb-adapter-node-websql > pouchdb-utils > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning set.js > truffle > @truffle/debugger > remote-redux-devtools > socketcluster-client > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning set.js > truffle > @truffle/db > apollo-server > apollo-server-express > [email protected]: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning set.js > truffle > @truffle/preserve-to-buckets > @textile/hub > @textile/crypto > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/db > apollo-server > apollo-server-core > [email protected]: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
warning set.js > truffle > @truffle/preserve-to-buckets > @textile/hub > @textile/threads-id > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-buckets > @textile/hub > @textile/security > [email protected]: This module has been superseded by the multiformats module
warning set.js > @truffle/contract > @ensdomains/ensjs > @ensdomains/ens > [email protected]: testrpc has been renamed to ganache-cli, please use this package from now on.
warning set.js > @truffle/contract > @ensdomains/ensjs > @ensdomains/ens > [email protected]: ethereumjs-testrpc has been renamed to ganache-cli, please use this package from now on.
warning set.js > truffle > @truffle/preserve-to-filecoin > filecoin.js > rpc-websockets > [email protected]: CircularJSON is in maintenance only, flatted is its successor.
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > ipld-raw > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > ipld-dag-cbor > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > ipld-dag-pb > [email protected]: This module has been superseded by the multiformats module
warning set.js > truffle > @truffle/preserve-to-ipfs > ipfs-http-client > ipld-dag-pb > [email protected]: This module is no longer maintained
warning set.js > truffle > @truffle/debugger > remote-redux-devtools > redux-devtools-core > [email protected]: Package moved to @redux-devtools/serialize.
warning set.js > truffle > @truffle/db > apollo-server > apollo-server-core > [email protected]: The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.
warning set.js > truffle > @truffle/db > apollo-server > apollo-server-core > [email protected]: The `graphql-extensions` API has been removed from Apollo Server 3. Use the plugin API instead: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
warning set.js > truffle > @truffle/db > apollo-server > apollo-server-core > [email protected]: The `apollo-tracing` package is no longer part of Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#tracing for details
warning set.js > truffle > @truffle/db > pouchdb-adapter-node-websql > websql > sqlite3 > [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
warning set.js > truffle > @truffle/preserve-to-filecoin > filecoin.js > @zondax/filecoin-signing-tools > [email protected]: This module has been superseded by @ipld/dag-cbor and multiformats
warning set.js > truffle > @truffle/preserve-to-filecoin > filecoin.js > @zondax/filecoin-signing-tools > [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
warning set.js > truffle > @truffle/debugger > reselect-tree > esdoc > ice-cap > cheerio > jsdom > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
[2/4] 🚚  Fetching packages...

We likely want to upgrade our dependency on truffle, rename a dep to @truffle/hdwallet-provider, and resolve the remaining warnings.

Make gas price oracle fault tolerant

From #60 review

This is a terrible dependency that can disrupt the flow. Want to abstract, add defaults, and make fault tolerant in a follow up!

Options are:

  • returning 0 defaults
  • using a fallback service

Internationalize trade quote currency values

At the moment prices are returned in USD and there are no other currency options. From #60 review

It's interesting seeing this kind of code here, I know it's a direct mapping of what's happening in the service right now, but it feels like we'd want a separation of generating the data and formatting the data.

We previously followed a "dumb" client type of approach where the client only needed to display strings and not worry about formatting but its weird seeing that now in a library.

Also note, in #60 there's an open question whether the vs_currencies parameter of the CoinGecko coin prices req needs to be paired one-for-one with the addresses lists:

const coinPrices = await coinGecko.fetchCoinPrices({
contractAddresses: [this.chainCurrencyAddress(chainId), fromTokenAddress, toTokenAddress],
vsCurrencies: [ USD_CURRENCY_CODE, USD_CURRENCY_CODE, USD_CURRENCY_CODE ],
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.