@rholabs/rho-sdk
v0.4.0-alpha10
Published
Rho Protocol SDK
Downloads
233
Readme
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
offset
-Number
(optional)limit
-Number
(optional)
Returns
String[]
getActiveMarkets({ oraclePackages, offset, limit })
Get active markets
Parameters
oraclePackages
-OraclePackages[]
(optional)offset
-Number
(optional)limit
-Number
(optional)
Returns
MarketInfo[]
getPortfolio({ userAddress, oraclePackages, offset, limit })
Get user portfolio
Parameters
userAddress
-String
oraclePackages
-OraclePackages[]
(optional)offset
-Number
(optional)limit
-Number
(optional)
Returns
MarketPortfolio[]
getTradeQuote({ marketId, futureId, notional, userAddress, oraclePackages? })
Get trade quote
Parameters
marketId
-String
futureId
-String
notional
-BigInt
userAddress
-String
oraclePackages
-OraclePackages[]
(optional)
Returns
TradeQuote
getLiquidityProvisionQuote({ marketId, futureId, notional, operation, lowerBound, upperBound, userAddress, oraclePackages? })
Get liquidity provision quote
Parameters
marketId
-String
futureId
-String
notional
-BigInt
operation
-LiquidityOperation
lowerBound
-String
upperBound
-String
userAddress
-String
oraclePackages
-OraclePackages[]
(optional)
Returns
LiquidityQuote
executeTrade({ marketId, futureId, notional, riskDirection, futureRateLimit, collateral, deadlineTimestamp, settleMaturedPositions?, oraclePackages? })
Execute trade
Parameters
marketId
-String
futureId
-String
notional
-BigInt
riskDirection
-RiskDirection
futureRateLimit
-BigInt
collateral
-BigInt
deadline
-Number
(optional, Date.now() + 5 _ 60 _ 1000)settleMaturedPositions
-Boolean
(optional, true)oraclePackages
-OraclePackages[]
(optional)
Returns
TransactionReceipt
deposit({ marketId, recipientAddress, amount, settleMaturedPositions?, oraclePackages? })
Deposit
Parameters
marketId
-String
recipientAddress
-String
amount
-BigInt
settleMaturedPositions
-Boolean
(optional)oraclePackages
-OraclePackages[]
(optional)
Returns
TransactionReceipt
withdraw({ marketId, amount, settleMaturedPositions?, oraclePackages? })
Withdraw
Parameters
marketId
-String
amount
-BigInt
settleMaturedPositions
-Boolean
(optional, true)oraclePackages
-OraclePackages[]
(optional)
Returns
TransactionReceipt
provideLiquidity({ marketId, futureId, notional, collateral, lowerBound, upperBound, deadlineTimestamp?, settleMaturedPositions?, oraclePackages? })
Provide liquidity
Parameters
marketId
-String
futureId
-String
notional
-BigInt
collateral
-BigInt
lowerBound
-String
upperBound
-String
deadline
-Number
(optional, Date.now() + 5 _ 60 _ 1000)settleMaturedPositions
-Boolean
(optional, true)oraclePackages
-OraclePackages[]
(optional)
Returns
TransactionReceipt
removeLiquidity({ marketId, futureId, notional, collateral, lowerBound, upperBound, deadlineTimestamp?, settleMaturedPositions?, oraclePackages? })
Remove liquidity
Parameters
marketId
-String
futureId
-String
notional
-BigInt
collateral
-BigInt
lowerBound
-String
upperBound
-String
deadline
-Number
settleMaturedPositions
-Boolean
(optional, Date.now() + 5 _ 60 _ 1000)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
- Bump version in package.json
- Build package
yarn build
- Publish
npm publish --access public