{"id":20001894,"url":"https://github.com/pooltogether/v4-client-js","last_synced_at":"2025-05-04T15:33:30.970Z","repository":{"id":37231078,"uuid":"402857981","full_name":"pooltogether/v4-client-js","owner":"pooltogether","description":"JS library with a simplified interface for interacting with PoolTogether V4 deployments.","archived":false,"fork":false,"pushed_at":"2023-01-25T16:05:11.000Z","size":494,"stargazers_count":16,"open_issues_count":2,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-31T19:05:27.602Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pooltogether.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-03T18:02:05.000Z","updated_at":"2023-09-11T09:10:27.000Z","dependencies_parsed_at":"2023-02-10T17:15:19.195Z","dependency_job_id":null,"html_url":"https://github.com/pooltogether/v4-client-js","commit_stats":null,"previous_names":["pooltogether/v4-js-client"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-client-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-client-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-client-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-client-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pooltogether","download_url":"https://codeload.github.com/pooltogether/v4-client-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224067026,"owners_count":17250099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T05:19:02.677Z","updated_at":"2024-11-13T05:19:03.516Z","avatar_url":"https://github.com/pooltogether.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/pooltogether/pooltogether--brand-assets\"\u003e\n    \u003cimg src=\"https://github.com/pooltogether/pooltogether--brand-assets/blob/977e03604c49c63314450b5d432fe57d34747c66/logo/pooltogether-logo--purple-gradient.png?raw=true\" alt=\"PoolTogether Brand\" style=\"max-width:100%;\" width=\"200\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n# 💻 \u0026nbsp; PoolTogether Client Library || PoolTogether V4\n\n![Tests](https://github.com/pooltogether/v4-client-js/actions/workflows/main.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/pooltogether/v4-client-js/badge.svg?branch=main)](https://coveralls.io/github/pooltogether/v4-client-js?branch=main)\n![ts](https://badgen.net/badge/-/TypeScript?icon=typescript\u0026label\u0026labelColor=blue\u0026color=555555)\n[![MIT license](https://img.shields.io/npm/l/@pooltogether/v4-client-js)](https://img.shields.io/npm/l/@pooltogether/v4-client-js)\n![npm](https://img.shields.io/npm/v/@pooltogether/v4-client-js)\n\n[Application](https://app.pooltogether.com/) | [Contracts](https://github.com/pooltogether/v4-core) | [Documentation](https://dev.docs.pooltogether.com/) | [Draw Calculator](https://github.com/pooltogether/draw-calculator-cli) | [Utility Library](https://github.com/pooltogether/v4-utils-js) | [Static Cache](https://github.com/pooltogether/v4-draw-results)\n\n# 🏆 \u0026nbsp; Overview\n\nThis library includes a simplified interface for interacting with a v4 PoolTogether deployment. Create an instance of `PrizePoolNetwork` and use the initialized `PrizePool` and `PrizeDistributor` to begin reading and writing data to the protocol.\n\nThere are several classes that provide interfaces to the different aspects of the V4 PoolTogether protocol. `PrizePoolNetwork` is the main entry point.\n\n- [PrizePoolNetwork](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/PrizePoolNetwork)\n- [PrizePool](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/PrizePool)\n- [User](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/User)\n- [PrizeDistributor](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/PrizeDistributor)\n- [DrawCalculatorApi](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/DrawCalculatorApi)\n- [ContractFactory](https://dev.pooltogether.com/protocol/libraries/v4-client-js/Classes/ContractFactory)\n\n## 💾 \u0026nbsp; Installation\n\nThis project is available as an NPM package:\n\n```sh\nnpm install @pooltogether/v4-client-js\n```\n\nor\n\n```sh\nyarn add @pooltogether/v4-client-js\n```\n\nThe repo can be cloned from Github for contributions.\n\n```sh\ngit clone https://github.com/pooltogether/v4-client-js.git\n```\n\n## 🏎️ \u0026nbsp; Quickstart\n\n### PrizePoolNetwork\n\nA `PrizePoolNetwork` is a collection of `PrizePool` and `PrizeDistributor` across several chains that make up a v4 deployment.\n\nTo create an instance of `PrizePoolNetwork` you will need:\n\n- A [Contract List](https://github.com/pooltogether/contract-list-schema) containing all of the relevant contracts for a v4 prize pool. You can obtain this by generating your own after deploying a v4 Prize Pool ([start here](https://github.com/pooltogether/v4-core)). Or by importing a copy of our current deployments [v4-pool-data](https://www.npmjs.com/package/@pooltogether/v4-pool-data).\n- [Ethers providers](https://docs.ethers.io/v5/api/providers/) for every chain that a Prize Pool is deployed on.\n\n```js\nimport { PrizePoolNetwork } from '@pooltogether/v4-client-js'\nimport { mainnet } from '@pooltogether/v4-pool-data'\n\nconst PrizePoolNetwork = new PrizePoolNetwork(providers, mainnet)\n```\n\n### PrizePool\n\nA `PrizePool` is a representation of a Prize Pool deployment. The Prize Pool is responsible for managing deposits, withdrawals \u0026 delegation. `PrizePool` is a read only object, for write capabilities check out `User`\n\n```js\nconst prizePool = PrizePoolNetwork.getPrizePool(1, '0xabc123')\n```\n\n### User\n\nA `User` is wrapper around `PrizePool` with the ability to send transactions to manage deposits, withdrawals and delegation.\n\n```js\nconst user = new User(prizePool.prizePoolMetadata, signer, prizePool)\n```\n\n### PrizeDistributor\n\nA `PrizeDistributor` is what handles prizes. It is used to determine the current draw, check for prizes \u0026 claiming prizes. For write capabilities, pass a Signer when creating an instance.\n\n```js\nconst prizeDistributor = PrizePoolNetwork.getPrizeDistributor(1, '0xabc123')\n```\n\n```js\nconst prizeDistributor = PrizePoolNetwork.getPrizeDistributor(1, '0xabc123')\nconst signer = provider.getSigner()\nconst signerPrizeDistributor = new PrizeDistributor(\n  prizeDistributor.prizeDistributorMetadata,\n  signer,\n  prizeDistributor.contractMetadataList\n)\n```\n\n## 🧮 \u0026nbsp; Examples\n\n### Get token data for a Prize Pool\n\n```js\nconst tokenData = await prizePool.getTokenData() // Underlying token (ex. USDC)\nconst ticketData = await prizePool.getTicketData() // Ticket token\n```\n\n### Get a users deposit token \u0026 ticket balances\n\n```js\nconst usersBalances: {\n  chainId: number,\n  address: string,\n  balances: PrizePoolTokenBalances\n}[] = await PrizePoolNetwork.getUsersPrizePoolBalances(usersAddress)\n```\n\n### Get a users deposit token \u0026 ticket balance\n\n```js\nconst balance: PrizePoolTokenBalances = await prizePool.getUsersPrizePoolBalances(usersAddress)\n```\n\n### Approve deposits\n\nNOTE: Make sure you're shifting by the proper decimal amount\n\n```js\nconst txResponse: TransactionResponse = await user.approveDeposits(\n  ethers.utils.parseUnits(10, decimals)\n)\n```\n\n### Deposit and delegate tokens\n\nNOTE: Make sure you're shifting by the proper decimal amount\n\n```js\nconst txResponse: TransactionResponse = await user.depositAndDelegate(\n  ethers.utils.parseUnits(10, decimals)\n)\n```\n\n### Deposit tokens\n\nNOTE: Make sure you're shifting by the proper decimal amount\n\n```js\nconst txResponse: TransactionResponse = await user.deposit(ethers.utils.parseUnits(10, decimals))\n```\n\n### Withdraw tokens\n\nNOTE: Make sure you're shifting by the proper decimal amount\n\n```js\nconst txResponse: TransactionResponse = await user.withdraw(ethers.utils.parseUnits(10, decimals))\n```\n\n### Get valid draw ids\n\nValid draw ids are draw ids that have all of the relevant data pushed to their respective chain \u0026 are not expired.\n\n```js\nconst drawIds = await prizeDistributor.getValidDrawIds()\n```\n\n### Get a users prizes\n\n```js\nconst drawResults = await PrizeApi.getUsersDrawResultsByDraw(\n  chainId,\n  usersAddress,\n  prizeDistributorAddress,\n  drawId,\n  maxPicksPerUser\n)\n```\n\n### Claim a users prizes\n\nNOTE: Ensure the `PrizeDistributor` was initialized with a `Signer`\n\n```js\nconst txResponse: TransactionResponse = await prizeDistributor.claimPrizesByDraw(1)\n```\n\n## 💻 \u0026nbsp; Developer Experience\n\n### Contributing\n\n[Create an Issue](https://github.com/pooltogether/v4-utils-js/issues) to request new features.\n\n[Open Pull Request](#) adhering to Contribution guidelines.\n\nThe package is setup using the [TSDX zero-config CLI](https://tsdx.io/) which includes:\n\n- Typescript\n- Rollup\n- Jest\n- Prettier\n- ESLint\n\n**Minor changes have been made to extend the default configuration.**\n\n#### ESLint\n\nThe TSDX linting configuration is overwritten to include override(s)\\* for:\n\n- Import/Order (used to enforce consistent module import ordering)\n\n###### \\*The ESLint overrides may incorrectly be interpreted by VSCode since the nested config file is ignored in the IDE\n\n### Porting docs to PoolTogether V4 Docs\n\n1. `yarn docs`\n2. Copy \u0026 paste\n\n- `classes` to `Classes`\n- `interfaces` to `Interfaces`\n- `README.md` below header to `index.md`\n\n3. Replace all `.md` with `` (nothing) in links\n4. Replace all `README` links to `./` and `../README` to `../`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Fv4-client-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpooltogether%2Fv4-client-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Fv4-client-js/lists"}