0.4.0-alpha10 • Published 9 months ago

@rholabs/rho-sdk v0.4.0-alpha10

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Rho Protocol SDK

Installation

npm install @rholabs/rho-sdk

Getting Started

Create Rho SDK with testnet configuration:

import RhoSDK from '@rholabs/rho-sdk';

const rhoSDK = new RhoSDK({ network: 'testnet' });

RhoSDKParams: Object (optional)

export type RhoSDKNetwork = 'mainnet' | 'testnet' | 'custom'

export interface RhoSDKParams {
  network?: RhoSDKNetwork
  routerAddress?: string
  viewAddress?: string
  quoterAddress?: string
  rpcUrl?: string
  oracleServiceUrl?: string
  privateKey?: string
  provider?: JsonRpcProvider | BrowserProvider
  signer?: JsonRpcSigner
}

API Reference

getActiveMarketIds(offset, limit)

Get active market ids

Parameters

  1. offset - Number (optional)
  2. limit - Number (optional)

Returns

String[]


getActiveMarkets({ oraclePackages, offset, limit })

Get active markets

Parameters

  1. oraclePackages - OraclePackages[] (optional)
  2. offset - Number (optional)
  3. limit - Number (optional)

Returns

MarketInfo[]


getPortfolio({ userAddress, oraclePackages, offset, limit })

Get user portfolio

Parameters

  1. userAddress - String
  2. oraclePackages - OraclePackages[] (optional)
  3. offset - Number (optional)
  4. limit - Number (optional)

Returns

MarketPortfolio[]


getTradeQuote({ marketId, futureId, notional, userAddress, oraclePackages? })

Get trade quote

Parameters

  1. marketId - String
  2. futureId - String
  3. notional - BigInt
  4. userAddress - String
  5. oraclePackages - OraclePackages[] (optional)

Returns

TradeQuote


getLiquidityProvisionQuote({ marketId, futureId, notional, operation, lowerBound, upperBound, userAddress, oraclePackages? })

Get liquidity provision quote

Parameters

  1. marketId - String
  2. futureId - String
  3. notional - BigInt
  4. operation - LiquidityOperation
  5. lowerBound - String
  6. upperBound - String
  7. userAddress - String
  8. oraclePackages - OraclePackages[] (optional)

Returns

LiquidityQuote


executeTrade({ marketId, futureId, notional, riskDirection, futureRateLimit, collateral, deadlineTimestamp, settleMaturedPositions?, oraclePackages? })

Execute trade

Parameters

  1. marketId - String
  2. futureId - String
  3. notional - BigInt
  4. riskDirection - RiskDirection
  5. futureRateLimit - BigInt
  6. collateral - BigInt
  7. deadline - Number (optional, Date.now() + 5 60 1000)
  8. settleMaturedPositions - Boolean (optional, true)
  9. oraclePackages - OraclePackages[] (optional)

Returns

TransactionReceipt


deposit({ marketId, recipientAddress, amount, settleMaturedPositions?, oraclePackages? })

Deposit

Parameters

  1. marketId - String
  2. recipientAddress - String
  3. amount - BigInt
  4. settleMaturedPositions - Boolean (optional)
  5. oraclePackages - OraclePackages[] (optional)

Returns

TransactionReceipt


withdraw({ marketId, amount, settleMaturedPositions?, oraclePackages? })

Withdraw

Parameters

  1. marketId - String
  2. amount - BigInt
  3. settleMaturedPositions - Boolean (optional, true)
  4. oraclePackages - OraclePackages[] (optional)

Returns

TransactionReceipt


provideLiquidity({ marketId, futureId, notional, collateral, lowerBound, upperBound, deadlineTimestamp?, settleMaturedPositions?, oraclePackages? })

Provide liquidity

Parameters

  1. marketId - String
  2. futureId - String
  3. notional - BigInt
  4. collateral - BigInt
  5. lowerBound - String
  6. upperBound - String
  7. deadline - Number (optional, Date.now() + 5 60 1000)
  8. settleMaturedPositions - Boolean (optional, true)
  9. oraclePackages - OraclePackages[] (optional)

Returns

TransactionReceipt


removeLiquidity({ marketId, futureId, notional, collateral, lowerBound, upperBound, deadlineTimestamp?, settleMaturedPositions?, oraclePackages? })

Remove liquidity

Parameters

  1. marketId - String
  2. futureId - String
  3. notional - BigInt
  4. collateral - BigInt
  5. lowerBound - String
  6. upperBound - String
  7. deadline - Number
  8. settleMaturedPositions - Boolean (optional, Date.now() + 5 60 1000)
  9. oraclePackages - OraclePackages[] (optional)

Returns

TransactionReceipt


Using in browser / Node.Js

Basic configuration (read only)

import RhoSDK from '@rholabs/rho-sdk';

const rhoSDK = new RhoSDK({ network: 'testnet' })

Node.JS

import RhoSDK from '@rholabs/rho-sdk';

const rhoSDK = new RhoSDK({
  network: 'testnet',
  privateKey: '<PRIVATE_KEY>'
})

Using with Metamask

if (window.ethereum) {
      const provider = new ethers.BrowserProvider(window.ethereum)
      await provider.send("eth_requestAccounts", [])
      const signer = await provider.getSigner()

      const sdk = new RhoSDK({ network: 'testnet', signer })
      const markets = await sdk.getActiveMarkets()
}

Testing

Create .env file:

TEST_PRIVATE_KEY=12345

and run the tests:

yarn test

Publishing

npm login
  1. Bump version in package.json
  2. Build package
yarn build
  1. Publish
npm publish --access public
0.4.0-alpha10

9 months ago

0.4.0-alpha9

9 months ago

0.4.0-alpha8

9 months ago

0.4.0-alpha5

9 months ago

0.4.0-alpha7

9 months ago

0.4.0-alpha1

10 months ago

0.4.0-alpha2

9 months ago

0.4.0-alpha3

9 months ago

0.4.0-alpha4

9 months ago

0.3.6

1 year ago

0.3.8

11 months ago

0.3.7

1 year ago

0.3.5

1 year ago

0.3.2

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.0

1 year ago

0.3.1

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.8

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.1.0-rc4

2 years ago

0.1.0-rc3

2 years ago

0.1.0-rc2

2 years ago

0.1.0-rc1

2 years ago