1.2.0 • Published 1 year ago

@generationsoftware/pt-v5-utils-js v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

🧰 Javascript Utility Library - PoolTogether V5

📖 Documentation

Compute

The @generationsoftware/v5-utils-js node module package provides computations for the PoolTogether v5 protocol.

High-order operations like processing subgraphs and chain state (draws, winners, etc..) is included in the compute namespaced functions.

🖥️ Computations:

Consume subgraph and protocol chain state to return computed outcomes:

Create Issue to request new features.Open Pull Request adhering to Contribution guidelines.

💾 Installation

This project is available as an NPM package:

npm install @generationsoftware/v5-utils-js
yarn add @generationsoftware/v5-utils-js

The repo can be cloned from Github for contributions.

git clone https://github.com/generationsoftware/v5-utils-js

📄 Contracts Blob

downloadContractsBlob(contractJsonUrl)

Gets the list of contracts for a specific network. Typically this would be the URL of the raw JSON file on committed on GitHub.

import { downloadContractsBlob } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  const contracts = await downloadContractsBlob(contractJsonUrl);
}
runAsync();

🏆 Draw Results

computeDrawWinners(provider, contracts, subgraphUrl)

A helper function that runs five intensive utility functions to compute and return a JSON blob of all previous draw winner's Claim objects for each tier of a prize pool, grouped by vault.

import { computeDrawWinners } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  const subgraphUrl = "https://api.studio.thegraph.com/query/63100/pt-v5-optimism/version/latest";

  // Compute Winners for the last Draw
  const winners = await computeDrawWinners(provider, contracts, subgraphUrl);
}
runAsync();

// Returns Claim[] array:
//
// interface Claim {
//   vault: string;
//   winner: string;
//   tier: number;
//   prizeIndex: number;
//   claimed?: boolean;
// }
//

🏊 Prize Pool Info

getPrizePoolInfo(readProvider, contracts)

Gathers info about the prize pool contained in provided the contracts JSON blob.

import { getPrizePoolInfo, PrizePoolInfo } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);
}
runAsync();

// Returns PrizePoolInfo object:
//
// interface PrizePoolInfo {
//   drawId: number;
//   numTiers: number;
//   numPrizeIndices: number;
//   reserve: string;
//   tiersRangeArray: number[]; // an easily iterable range of numbers for each tier available (ie. [0, 1, 2])
//   tierPrizeData: {
//     [tierNum: string]: TierPrizeData;
//   };
// }
//
// interface TierPrizeData {
//   prizeIndicesCount: number;
//   prizeIndicesRangeArray: number[]; // an easily iterable range of numbers for each tier's prize indices
//   amount: BigNumber;
//   liquidity: BigNumber;
// }
//

🏦 Get Subgraph Prize Vaults

getSubgraphPrizeVaults(subgraphUrl)

Collects all vaults from the PT v5 subgraph for a specific chain into an array.

import { getSubgraphPrizeVaults } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  const subgraphUrl = "https://api.studio.thegraph.com/query/63100/pt-v5-optimism/version/latest";

  const prizeVaults = await getSubgraphPrizeVaults(subgraphUrl);
}
runAsync();

// Returns PrizeVault[] array:
//
// interface PrizeVault {
//  id: string;
//  accounts: PrizeVaultAccount[]; // empty
// }

👥 Populate Subgraph Prize Vault Accounts

populateSubgraphPrizeVaultAccounts(subgraphUrl, vaults)

Takes the prize vaults from getSubgraphPrizeVaults and adds user deposit account arrays for each. populateSubgraphPrizeVaultAccounts is split up into a separate call from getSubgraphPrizeVaults as it's very network heavy, needing to page through potentially hundreds of thousands of accounts from the subgraph.

import { populateSubgraphPrizeVaultAccounts } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  const subgraphUrl = "https://api.studio.thegraph.com/query/63100/pt-v5-optimism/version/latest";

  let prizeVaults = await getSubgraphPrizeVaults(subgraphUrl);

  prizeVaults = await populateSubgraphPrizeVaultAccounts(subgraphUrl, prizeVaults);
}
runAsync();

// Returns PrizeVault[] array:
//
// interface PrizeVault {
//  ...
//  accounts: PrizeVaultAccount[]; // populated!
// }

🏁 Get Winner's Claims

getWinnersClaims(readaProvider, prizePoolInfo, contracts, vaults)

Collects Claim objects into an array for all prizes in the past draw.

import { getWinnersClaims } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  let claims: Claim[] = await getWinnersClaims(readProvider, prizePoolInfo, contracts, vaults);
}
runAsync();

// Returns Claim[] array:
//
// interface Vault {
//  vault: string;
//  winner: string;
//  tier: number;
//  prizeIndex: number;
//  claimed?: boolean; // null
// }

🏁 Flag Claimed (RPC)

flagClaimedRpc(readProvider, contracts, claims)

Adds the claimed boolean to the claims using RPC lookups.

import { flagClaimedRpc } from "@generationsoftware/v5-utils-js";

async function runAsync() {
  claims = await flagClaimedRpc(readProvider, contracts, claims);
}
runAsync();

// Returns Claim[] array:
//
// interface Vault {
//  ...
//  claimed?: boolean; // now set true or false
// }
1.2.0

1 year ago

1.2.0-beta.1

1 year ago

1.1.11

1 year ago

1.1.9

1 year ago

1.1.10

1 year ago

1.2.0-beta.0

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.3-beta.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0-beta.18

1 year ago

1.1.0

1 year ago

1.1.0-beta.17

1 year ago

1.1.0-beta.16

1 year ago

1.1.0-beta.14

1 year ago

1.1.0-beta.15

1 year ago

1.1.0-beta.11

1 year ago

1.1.0-beta.12

1 year ago

1.1.0-beta.13

1 year ago

1.1.0-beta.10

1 year ago

1.1.0-beta.9

1 year ago

1.1.0-beta.8

1 year ago

1.1.0-beta.7

1 year ago

1.1.0-beta.6

1 year ago

1.1.0-beta.5

1 year ago

1.1.0-beta.4

1 year ago

1.1.0-beta.3

1 year ago

1.10.0-beta.1

1 year ago

1.1.0-beta.2

1 year ago

1.1.0-beta.1

1 year ago

1.1.0-beta.0

1 year ago

1.0.10

1 year ago

1.10.0-beta.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1-beta.52

2 years ago

0.0.1-beta.51

2 years ago

0.0.1-beta.50

2 years ago

0.0.1-beta.49

2 years ago

0.0.1-beta.48

2 years ago

0.0.1-beta.47

2 years ago

0.0.1-beta.46

2 years ago

0.0.1-beta.45

2 years ago

0.0.1-beta.44

2 years ago

0.0.1-beta.43

2 years ago

0.0.1-beta.42

2 years ago

0.0.1-beta.41

2 years ago

0.0.1-beta.40

2 years ago

0.0.1-beta.39

2 years ago

0.0.1-beta.38

2 years ago

0.0.1-beta.37

2 years ago

0.0.1-beta.36

2 years ago

0.0.1-beta.35

2 years ago

0.0.1-beta.34

2 years ago

0.0.1-beta.33

2 years ago

0.0.1-beta.32

2 years ago

0.0.1-beta.30

2 years ago

0.0.1-beta.29

2 years ago

0.0.1-beta.28

2 years ago

0.0.1-beta.27

2 years ago