GithubHelp home page GithubHelp logo

od-sdk's Introduction

@opendollar/sdk

npm package License: MIT Twitter: open_dollar

Library to interact with the Open Dollar smart contracts. Manage your vaults, mint OD, inspect the system state, and much more.

The library is written in Typescript with full typing support. It allows access to the low level API to directly interact with the contracts.

Usage ๐Ÿ“–

yarn add @opendollar/sdk
import { ethers, utils as ethersUtils } from 'ethers'
import { Geb, utils } from '@opendollar/sdk'
import { fetchUserSafes } from '@opendollar/sdk/lib/virtual/virtualUserSafes.js'

// Setup Ether.js
const provider = new ethers.providers.JsonRpcProvider(
    'http://kovan.infura.io/<API KEY>'
)
const wallet = new ethers.Wallet('0xdefiisawesome...', provider)

// Create the main GEB object
const geb = new Geb('arbitrum', provider)

// Get a Vault by ID
let safe = await geb.getSafe(4)

// Get a Vault by user address
safes = await fetchUserSafes(geb, wallet.address)

// Create a proxy 
const txData = await geb.deployProxy()
const tx = await wallet.sendTransaction(txData)
console.log(`Transaction ${tx.hash} waiting to be mined...`)
await tx.wait()

// Open a vault
// TODO

How Information is Fetched with Subgraphs ๐Ÿ“Š

Our SDK uses subgraphs to fetch indexed information about auctions (collateral, surplus, and debt) from the blockchain. The subgraphs are hosted on The Graph, and we also have our own Render-hosted subgraph. For more information about how to deploy your own subgraph check out our od-subgraph repo.

The main way we fetch auction information is through the querySubgraph function. This function take in a subgraph URL and a GraphQL query corresponding to the auction type (for example, fetchSurplusAuctionEvents will fetch the surplus auctions). The function will return a promise that resolves to an array of auction events. The auction events will be persisted in od-app through the Redux store in auctionModel.ts.

Subgraph Redundancy

When a request fails to our hosted subgraph in The Graph, we will automatically retry the request to our Render-hosted subgraph in the querySubgraph function. Make sure in od-app you've set REACT_APP_FALLBACK_SUBGRAPH_URL as a .env variable to ensure there's a fallback subgraph to query.

Resources ๐Ÿง‘โ€๐Ÿ’ป

Documentation

Contributing ๐Ÿ’ก

Running prebuild is required to generate the solidity artifacts files

yarn
yarn prebuild

od-sdk's People

Contributors

pi0neerpat avatar jahabeebs avatar wei3erhase avatar 0xshaito avatar 0xgorilla avatar 0xardy avatar seroxdesign avatar guifel avatar

Stargazers

web3genie avatar llihwerd avatar

Watchers

Axe avatar  avatar st4rgard3n avatar

Forkers

shabarkin

od-sdk's Issues

Troubleshoot repaying issue from SDK side

Troubleshooting for repaying issue:

  • Check changes related to interfaces for the tax collector
  • Check changes to how we call functions in the app
  • Check changes to how we are using the SDK in the app

Later

Publish a new SDK with the correct decimals

OP <-> Arbitrum Sepolia Integration Bugs

On branch optimism-hai : Liquidity missing from header (works on optimism, but not arb-sepolia)
On branch optimism-hai : Vault NFT number is wrong
Fix CORS errors when doing sanctions API fetching
Test REACT_APP_WALLET_CONNECT_PROJECT_ID on staging

Hide warnings for duplicate definition

Remove the warnings for

Duplicate definition of TransferCollateral (TransferCollateral(address,uint256,address,uint256), TransferCollateral(address,bytes32,uint256,address,uint256))

settleEvents parsing error

settleEvents are not being parsed correctly from the Subgraph

TypeError: Cannot read properties of undefined (reading 'toString')
at auctions.ts:106:44

Fix proxy-action.ts network routing logic

  • We are checking whether to route transactions by checking whether this.addressList.GEB_TAX_COLLECTOR !== NULL_ADDRESS however, this is preventing us from merging our optimism-hai branch into dev because this logic isn't valid since arbitrum sepolia now has a non null GEB_TAX_COLLECTOR in the latest SDK deployment
  1. expose network in the constructor in proxy-actions
  2. use network to route transactions

[blocked] Fetch pool data from camelot

Create a function to fetch liquidity details for ODG and OD. This will be used for the stats page

  • Fetch pool data from camelot https://docs.camelot.exchange/
  • Add addresses for existing pools. Later we will update the address to our own pools
    • a stablecoin pool for OD
    • any token pool for ODG
  • Fetch both price and liquidity data

Enable multiple pools

Depends on #45

Now that we can load data from a single pool, we need to add the ability to pull for multiple pools.

  • Rename fetchNitroPoolODGwstETH to fetchNitroPool which is more generic
  • The arguments should accept the token symbol (eg. WSTETH), instead of the address of the pool
  • Validate that we are fetching all data needed (see both app screenshots below)

image

image

Update mainnet collateral addresses

Make subgraph queries more resilient

If the subgraph API call fails with an error, a backup subgraph should be tried.

Eg. Our own hosted subgraph is the primary option. If the request fails, and there is a fallback URL, then we try that one

Subgraph documentation

  1. Add documentation explaining how auction events are fetched using the subgraph
  2. Add documentation for the fallback subgraph URL (#38 (review))
  3. Add documentation for fallback subgraph in the od-app repo as well

HAI Optimism tweaks

There are two remaining tasks to enable our SDK to work seamlessly with HAI on Optimism. Please address the following items, using branch add-optimism-hai

  1. src/virtual/virtualAnalyticsData.ts has a call vault721.totalSupply to fetch the total number of vaults. This is incompatible, since HAI does not have a vault721 contract. Will need to research how they are fetching total vaults and implement a switch statement to use the other method when on Optimism.
  2. src/geb.ts has a call to check if a user has a proxy. We updated our PROXY_REGISTRY and renamed the function from proxies to getProxy. Update the function getProxyAction to properly call proxyRegistry.proxies when on Optimism.

To test the results, run the app on Optimism from branch optimism-hai. Don't forget to yarn link the sdk and build.

Once this issue is completed, I can update the bot to support HAI, and also deploy a second interface for HAI using our od-app ๐ŸŽ‰

Resources:

https://solidity-by-example.org/

auctions undefined error

Related to #18

Still seeing this error, eg in RETH collateral auction

index.tsx:125 TypeError: Cannot read properties of undefined (reading 'toString')
    at auctions.ts:102:44

Use both queryFilter AND subgraph for aution data

Currently the app is delayed by the speed of the subgraph indexer to show the most current auction data.
if we use both on-chain data (last 5000 blocks) and the subgraph together, we could eliminate the data latency

Remove duplicate definition warning

How can we remove all these console logs from the sdk?

Duplicate definition of ModifyParameters (ModifyParameters(bytes32,uint256), ModifyParameters(bytes32,bytes32,uint256))
Duplicate definition of ModifyParameters (ModifyParameters(bytes32,uint256), ModifyParameters(bytes32,address))
Duplicate definition of ModifyParameters (ModifyParameters(bytes32,bytes32,uint256), ModifyParameters(bytes32,uint256), ModifyParameters(bytes32,address), ModifyParameters(bytes32,uint256,uint256), ModifyParameters(bytes32,uint256,uint256,address))
Duplicate definition of ModifyParameters (ModifyParameters(bytes32,uint256), ModifyParameters(bytes32,address), ModifyParameters(bytes32,bytes32,uint256), ModifyParameters(bytes32,bytes32,address))

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.