Giter Site home page Giter Site logo

sdk's Introduction

Bancor SDK v0.2 (beta)

Javascript API that provides utilities and access to the Bancor Network mainnet contracts across the different blockchains using a unified & simplified interface.

Initialization

const BancorSDK = require('@bancor/sdk').SDK;

const settings = {
    // optional, mandatory when interacting with the ethereum mainnet
    ethereumNodeEndpoint: '<ethereum node endpoint>',
    // optional, mandatory when interacting with the EOS mainnet
    eosNodeEndpoint: '<eos node endpoint>'
};

let bancorSDK = await BancorSDK.create(settings);

Usage

getPathAndRate - returns the best conversion path and rate between any two tokens in the Bancor Network. Note that the source token and the target token can reside on two different blockchains. In addition, input/output amounts format is a decimal string (as opposed to wei) since the function is blockchain agnostic.

// get the path/rate between DAI and ENJ
const sourceToken = {
    blockchainType: 'ethereum',
    blockchainId: '0x6B175474E89094C44Da98b954EedeAC495271d0F'
};
const targetToken = {
    blockchainType: 'ethereum',
    blockchainId: '0xF629cBd94d3791C9250152BD8dfBDF380E2a3B9c'
};
const res = await bancorSDK.pricing.getPathAndRate(sourceToken, targetToken, "1.0");

// output:
{
    path: [
        { blockchainType: 'ethereum', blockchainId: '0x6B175474E89094C44Da98b954EedeAC495271d0F' },
        { blockchainType: 'ethereum', blockchainId: '0xE5Df055773Bf9710053923599504831c7DBdD697' },
        { blockchainType: 'ethereum', blockchainId: '0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C' },
        { blockchainType: 'ethereum', blockchainId: '0xf3aD2cBc4276eb4B0fb627Af0059CfcE094E20a1' },
        { blockchainType: 'ethereum', blockchainId: '0xF629cBd94d3791C9250152BD8dfBDF380E2a3B9c' }
    ],
    rate: '6.323790359609045609'
}

Cleanup

await BancorSDK.destroy(bancorSDK);

Features

  • Price discovery
  • Conversion path generation
  • Historical data
  • Utilities
  • Cross-chain support

Collaborators

sdk's People

Contributors

barakman avatar dependabot[bot] avatar devilla avatar xianny avatar yudilevi avatar yudilevi2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdk's Issues

web3 dependancy version

Defining web3 version like this (without ^), could possible make a project using this library include web3 twice in it's bundle.

Feature request: Getting the reverse exchange rate

Let's suppose I need to get X amount of SomeToken, and I have AnotherToken

It would be nice to have a function that calculates the following:
How many of AnotherToken should I spend to obtain X amount of SomeToken.

A simple example, explaining why it can be needed and getRate is not enough sometimes.
Let's try to use the current getRate function to calculate how many BNT tokens one should spend to get 10 ETH:

const ethToken = {
 blockchainType: 'ethereum',
 blockchainId: '0xc0829421C1d260BD3cB3E0F06cfE2D52db2cE315'
};
const bntToken = {
 blockchainType: 'ethereum',
 blockchainId: '0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C'
}

const initialAmount = "10";
console.log(initialAmount);

const bntTokenAmount = await bancor.getRate(ethToken, bntToken, initialAmount);
console.log(bntTokenAmount);

//now check the conversion result
const ethTokenAmount = await bancor.getRate(bntToken, ethToken, bntTokenAmount);
console.log(ethTokenAmount);

In this example, ethTokenAmount is quite close to initial (for now it is 9.944, ~0.56% deviation), but as initialAmount grows, the difference becomes greater too.

with initialAmount set to "1000" resulting ethTokenAmount is "859.966" which is 14% deviation, and that is a lot.

Though I understand that it might be hard to get an exact value, but I guess it's OK to specify a precision.

Looking for endpoints

Can you please provide more information about what I need to do to get these endpoints?

https://docs.bancor.network/sdk/sdk-api-reference#initialization

const settings = {
    // optional, mandatory when interacting with the ethereum mainnet
    ethereumNodeEndpoint: '<ethereum node endpoint>',
    // optional, mandatory when interacting with the EOS mainnet
    eosNodeEndpoint: '<eos node endpoint>'
};

On the EOS side, some of the block producers still provide /bp.json files. I did find one here: https://eosnation.io/bp.json and here https://eosauthority.com/bp.json .. In tried a few returned api_endpoint and ssl_endpoint URLs. That TIP would be good in your docs. I'm assuming your API will work with SSL, but a confirmation will help reduce confusion.

On the ETH side, I'm not sure what to use. I finally found one to try: https://main-light.eth.linkpool.io/ but I'm getting an error. What specifically am I looking for, it is any mainnet RPC URL? Do you have some suggestions?

> BancorSDK = require('bancor-sdk').SDK; settings = {ethereumNodeEndpoint: 'https://main-light.eth.linkpool.io/', eosNodeEndpoint: 'https://publicapi-mainnet.eosauthority.com'}; bancorSDK = await BancorSDK.create(settings)
Uncaught Error: Returned error: execution aborted (timeout = 5s)
    at Object.ErrorResponse (/bancor/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /bancor/node_modules/web3-core-requestmanager/src/index.js:140:36
    at XMLHttpRequest.request.onreadystatechange (/bancor/node_modules/web3-providers-http/src/index.js:96:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/bancor/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/bancor/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/bancor/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)

getRateByPath always return 0

var bancorSDK = await BancorSDK.create(settings);
tks=[sourceToken,targetToken]
const result = await bancorSDK.pricing.getRateByPath(tks, "1.0");
console.log(result )

result always 0

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.