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

@pooltogether/hyperstructure-client-js

v1.0.0

Published

<p align="center"> <a href="https://github.com/pooltogether/pooltogether--brand-assets"> <img src="https://github.com/pooltogether/pooltogether--brand-assets/blob/977e03604c49c63314450b5d432fe57d34747c66/logo/pooltogether-logo--purple-gradient.png?r

Downloads

49

Readme

💻   PoolTogether Hyperstucture Client Library

ts viem npm license

Client Monorepo | Documentation | Prize Pool Contract | Vault Contract

🏆   Overview

A JS client library for wrapping Viem contracts and providing simple, unopinionated interfaces for interacting with the protocol.

The library exports the following classes to interact with different aspects of the protocol, including reading and writing onchain data:

  • PrizePool
  • Vault
  • Vaults

Useful utilities and types are also exported from internal packages. See the utilities or types packages for more info.

💾   Installation

This library is available as an NPM package:

npm install @pooltogether/hyperstructure-client-js

or

pnpm install @pooltogether/hyperstructure-client-js

or

yarn add @pooltogether/hyperstructure-client-js

🏎️   Quickstart

PrizePool

A PrizePool is an interface to interact with a prize pool contract, which is responsible for aggregating contributions from all vaults and awarding prizes.

To create an instance of a PrizePool, you will need:

  • The chain ID of the network the prize pool contract is deployed to.
  • The prize pool's address.
  • A Viem public client.

If you'd like to use any write methods, you must also provide a Viem wallet client.

import { PrizePool } from '@pooltogether/hyperstructure-client-js'
import { createPublicClient, createWalletClient } from 'viem'

// Viem clients
const publicClient = createPublicClient({ ... })
const walletClient = createWalletClient({ ... })

// Optional parameters
const options = {
  walletClient: walletClient,
  prizeTokenAddress: '0x456...',
  drawPeriodInSeconds: 86_400,
  tierShares: 100
}

// Initializing PrizePool
const prizePool = new PrizePool(1, '0x123...', publicClient, options)

Vault

A Vault is an interface to interact with a vault contract, which is an ERC 4626 wrapper around any yield source, responsible for deposits and withdrawals.

To create an instance of a Vault, you will need:

  • The chain ID of the network the vault contract is deployed to.
  • The vault's address.
  • A Viem public client.

If you'd like to use any write methods, you must also provide a Viem wallet client.

import { Vault } from '@pooltogether/hyperstructure-client-js'
import { createPublicClient, createWalletClient } from 'viem'

// Viem clients
const publicClient = createPublicClient({ ... })
const walletClient = createWalletClient({ ... })

// Optional parameters
const options = {
  walletClient: walletClient,
  decimals: 18,
  tokenAddress: '0x456...',
  name: 'Really Cool Vault',
  logoURI: 'https://...',
  tokenLogoURI: 'https://...'
}

// Initializing Vault
const vault = new Vault(1, '0x123...', publicClient, options)

Vaults

A Vaults is an read-only interface for multiple vault contracts. It is meant to take in all vaults in a VaultList and create Vault objects for each of them, allowing for more efficient aggregate queries.

To create an instance of Vaults, you will need:

  • An array of VaultInfo data for each of the vaults in the VaultList.
  • Viem public clients for each network vaults are deployed in.

See the typing of a VaultList here.

import { Vaults } from '@pooltogether/hyperstructure-client-js'

// VaultList
const vaultList = {
  name: 'Amazing Vault List',
  version: { ... },
  timestamp: '...',
  tokens: [{ ... }]
}

// Viem public clients
const publicClients = {
  1: createPublicClient({ ... }),
  10: createPublicClient({ ... }),
  42161: createPublicClient({ ... })
}

// Initializing Vaults
const vaults = new Vaults(vaultList.tokens, publicClients)

🧮   Examples

Getting prize token data for a prize pool

const tokenData = await prizePool.getPrizeTokenData()

Getting a prize pool's last awarded draw ID

const lastDrawId = await prizePool.getLastDrawId()

Getting current and estimated prize amounts and frequency for all tiers of a prize pool

const allPrizeInfo = await prizePool.getAllPrizeInfo()

Claiming a prize from a prize pool

NOTE: Since this is a write function, a wallet client is required when initializing PrizePool.

const userAddress = '0x123...'
const prizeTier = 0
const txHash = await prizePool.claimPrize(userAddress, prizeTier)

Getting token & share data for a vault

const tokenData = await vault.getTokenData() // Deposited asset
const shareData = await vault.getShareData() // Receipt token

Getting a user's deposited balance for a vault

const userAddress = '0x123...'
const tokenBalance = await vault.getUserTokenBalance(userAddress)
const shareBalance = await vault.getUserShareBalance(userAddress)

Getting total tokens deposited in a vault

const totalTokenBalance = await vault.getTotalTokenBalance()

Depositing into a vault

NOTE: Since this is a write function, a wallet client is required when initializing Vault.

const amount = 123456789n // Bigint value w/ decimals
const txHash = await vault.deposit(amount)

Withdrawing from a vault

NOTE: Since this is a write function, a wallet client is required when initializing Vault.

NOTE: You can withdraw a token amount, but it is generally better to redeem a share amount.

const amount = 123456789n // Bigint value w/ decimals
const txHash = await vault.redeem(amount)

Getting token & share data for multiple vaults

const allTokenData = await vaults.getTokenData()
const allShareData = await vaults.getShareData()

Getting a user's deposited balances for multiple vaults

const userAddress = '0x123...'
const allTokenBalances = await vaults.getUserTokenBalances(userAddress)
const allShareBalances = await vaults.getUserShareBalances(userAddress)