npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ragetrade/sdk

v2.0.4

Published

## Install

Downloads

262

Readme

Rage Trade SDK

Install

Ethers.js is a peer dependency so that needs to be installed in the project as well.

npm install @ragetrade/sdk ethers

Quick debugging

npx ragetrade

Opens a repl with the rage trade sdk loaded. Also the contracts are exposed as global variables.

ragetrade> sdk.fromQ128('0x0140000000000000000000000000000000')
1.25
ragetrade> await sdk.sqrtPriceX96ToPrice('0x03e08db11fa9d95156495b', 6, 18)
3500

Reading data

import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { core, tricryptoVault } from '@ragetrade/sdk';

const provider = new StaticJsonRpcProvider('arbitrum testnet node url');

// in your code

const { clearingHouse } = await core.getContracts(provider);
const num = await clearingHouse.numAccounts();
console.log(num); // BigNumber { _hex: '0x05', _isBigNumber: true }
console.log(num.toNumber()); // 5

const { curveYieldStrategy } = await tricryptoVault.getContracts(provider);
const tvl = await curveYieldStrategy.vaultMarketValue();
console.log(tvl); // BigNumber

Getting user data

import { core, tricryptoVault } from '@ragetrade/sdk';

// number[]
const accountIds = await getAccountIdsByAddress('0xAddress', 'arbmain');

// prints out all collaterals, token positions, liquidity positions for the account
const accountInfo = await getAccountInfo(2, 'arbmain');

Using Fallback Data Sources

import { getDefaultDataSourceSync, pools, VaultName } from '@ragetrade/sdk';
const ds = getDefaultDataSourceSync(
  'arbmain' /* optionally pass in ethers provider or array of ethers providers or data sources */
);

const prices = await ds.getPrices(pools.arbmain[0].poolId);
// { realPrice: number; virtualPrice: number; realTwapPrice: number; virtualTwapPrice: number; }
const vaultInfo = await ds.getVaultInfo('tricrypto' /* as VaultName */);
// { totalSupply: number; totalAssets: number; assetPrice: number; sharePrice: number; depositCap: number; vaultMarketValue: number; }

Making transaction: create account

import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { core, parseUsdc } from '@ragetrade/sdk';

const provider = new StaticJsonRpcProvider('arbitrum testnet node url');
const signer = new Wallet('private key', provider);

// creating account

const { clearingHouse } = await core.getContracts(signer);
const myAccountNum = await clearingHouse.callStatic.createAccount();
const tx = await clearingHouse.createAccount();
await tx.wait();

Making transaction: add money to account

import { core, formatUsdc, parseUsdc } from '@ragetrade/sdk';

const { clearingHouse, rBase } = await core.getContracts(signer);

const balance = await rBase.balanceOf(signer.address);
console.log(balance); // BigNumber { _hex: '0x05f5e100', _isBigNumber: true }
console.log(formatUsdc(balance)); // 100.0

const accountNo = 3;
const amount = parseUsdc('10'); // BigNumber { _hex: '0x989680', _isBigNumber: true }
const tx1 = await rBase.approve(clearingHouse.address, amount);
await tx1.wait();
const tx2 = await clearingHouse.addMargin(accountNo, amount);
const collateralTokenId = '0x' + c.rBase.address.slice(34, 42);
await c.clearingHouse.addMargin(3, collateralTokenId, amount);
await tx2.wait();

Initializing new pool

await rageTradeFactory.connect(w).initializePool({
  deployVTokenParams: {
    vTokenName: 'vWETH2',
    vTokenSymbol: 'vWETH2',
    rTokenDecimals: 18,
  },
  rageTradePoolInitialSettings: {
    initialMarginRatio: 20000,
    maintainanceMarginRatio: 10000,
    twapDuration: 60,
    whitelisted: false,
    oracle: '0x7DC0A2fE40a77DD435B0AE260320E5C58c12557a',
  },
  liquidityFeePips: 500,
  protocolFeePips: 500,
});

Timelock

import { core, generateTimelockSchedule } from '@ragetrade/sdk';

const { clearingHouse, timelock } = await core.getContracts(signer);

// single
const schedule = await generateTimelockSchedule(timelock, [
  clearingHouse.populateTransaction.withdrawProtocolFee(),
]);

// batch
const schedule = await generateTimelockSchedule(timelock, [
  clearingHouse.populateTransaction.withdrawProtocolFee(),
  clearingHouse.populateTransaction.updateProtocolSettings(...args),
]);