{"id":20001936,"url":"https://github.com/pooltogether/v4-twab-delegator","last_synced_at":"2025-05-04T15:33:39.942Z","repository":{"id":43124695,"uuid":"457958128","full_name":"pooltogether/v4-twab-delegator","owner":"pooltogether","description":"Contract to delegate chances of winning to multiple delegatees","archived":false,"fork":false,"pushed_at":"2022-03-17T20:42:08.000Z","size":355,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-25T04:03:31.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"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":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-10T21:47:36.000Z","updated_at":"2022-07-08T04:35:50.000Z","dependencies_parsed_at":"2022-09-22T06:11:58.132Z","dependency_job_id":null,"html_url":"https://github.com/pooltogether/v4-twab-delegator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"pooltogether/pooltogether-contracts-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-twab-delegator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-twab-delegator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-twab-delegator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Fv4-twab-delegator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pooltogether","download_url":"https://codeload.github.com/pooltogether/v4-twab-delegator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252356615,"owners_count":21734985,"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:10.185Z","updated_at":"2025-05-04T15:33:39.565Z","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# PoolTogether TWAB Delegator\n\n![Tests](https://github.com/pooltogether/v4-twab-delegator/actions/workflows/main.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/pooltogether/v4-twab-delegator/badge.svg?branch=master)](https://coveralls.io/github/pooltogether/v4-twab-delegator?branch=master)\n\nThe PoolTogether V4 TWAB Delegator contract allows accounts to easily delegate their chance of winning to other accounts. See the [PoolTogether V4 Docs](https://dev.pooltogether.com) for more details on chance and the TWAB.\n\nThere are three roles that relate to this contract:\n\n- Delegators\n- Delegatees\n- Representatives\n\n**Delegators**\n\nDelegators are accounts that want to delegate their chance to win to another account. They do so using delegation \"slots\". Each delegation slot corresponds to a smart contract deployed as a minimal proxy. This contract holds the tickets and delegates the chance of the held tickets to the delegatee.\n\n**Delegatees**\n\nDelegatees are those who have tickets delegated to them.  The delegatee gets a higher chance to win thanks to the delegation, but they don't have access to the underlying funds.\n\n**Representatives**\n\nRepresentatives are accounts that can manage delegations for a delegator.  They can create and update the delegations, but cannot withdraw any funds. This enables smart contracts to manage delegations, or even a human representative.\n\n# User Flow\n\nThe main user flow is that a delegator delegates tickets to a delegatee. The flow proceeds like so:\n\n1. Delegator creates a delegation for the given slot:\n```solidity\ncreateDelegation(address delegatorAddress, uint256 slotIndex, address delegatee, uint256 lockDuration)\n```\n2. Delegator funds the delegation (transfers tickets into the delegation)\n```solidity\nfundDelegation(address delegator, uint256 slotIndex, uint256 amount)\n```\n\nIf a delegator wishes a representative to manage their delegations for them, then the delegator can stake on the contract instead. The representative can use the stake to create delegations, but cannot withdraw the stake.\n\nThe staking and rep flow looks like so:\n\n1. Delegator stakes tickets into the contract:\n```solidity\nstake(address to, uint256 amount)\n```\n2. Delegator adds a rep:\n```solidity\nsetRepresentative(address rep, bool isRep)\n```\n\nThe representative would follow a similar flow to create a delegation, but would instead fund from the stake:\n\n1. Delegator creates a delegation for the given slot:\n```solidity\ncreateDelegation(address delegatorAddress, uint256 slotIndex, address delegatee, uint256 lockDuration)\n```\n2. Delegator funds the delegation (transfers tickets into the delegation)\n```solidity\nfundDelegationFromStake(address delegator, uint256 slotIndex, uint256 amount)\n```\n\n# Permit \u0026 Multicall\n\nThis contract implements the Multicall interface which allows EOAs to batch transactions together. It also implements a special `permitAndMulticall` function so that users can also approve the ticket contract before running transactions, allowing them to create a delegation in a single tx.\n\n# Development\n\n1. Clone this repo: `git clone git@github.com:pooltogether/pooltogether-contracts-template.git \u003cDESTINATION REPO\u003e`\n1. Create repo using Github GUI\n1. Set remote repo (`git remote add origin git@github.com:pooltogether/\u003cNAME_OF_NEW_REPO\u003e.git`),\n1. Checkout a new branch (`git checkout -b name_of_new_branch`)\n1. Begin implementing as appropriate.\n1. Update this README\n\nThis repo is setup to compile (`nvm use \u0026\u0026 yarn compile`) and successfully pass tests (`yarn test`)\n\n# Preset Packages\n\n## Generic Proxy Factory\n\nThe minimal proxy factory is a powerful pattern used throughout PoolTogethers smart contracts. A [typescript package](https://www.npmjs.com/package/@pooltogether/pooltogether-proxy-factory-package) is available to use a generic deployed instance. This is typically used in the deployment script.\n\n## Generic Registry\n\nThe [generic registry](https://www.npmjs.com/package/@pooltogether/pooltogether-generic-registry) is a iterable singly linked list data structure that is commonly used throughout PoolTogethers contracts. Consider using this where appropriate or deploying in a seperate repo such as the (Prize Pool Registry)[https://github.com/pooltogether/pooltogether-prizepool-registry.\n\n# Installation\n\nInstall the repo and dependencies by running:\n`yarn`\n\n## Deployment\n\nThese contracts can be deployed to a network by running:\n`yarn deploy \u003cnetworkName\u003e`\n\n## Verification\n\nThese contracts can be verified on Etherscan, or an Etherscan clone, for example (Polygonscan) by running:\n`yarn etherscan-verify \u003cethereum network name\u003e` or `yarn etherscan-verify-polygon matic`\n\n# Testing\n\nRun the unit tests locally with:\n`yarn test`\n\n## Coverage\n\nGenerate the test coverage report with:\n`yarn coverage`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Fv4-twab-delegator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpooltogether%2Fv4-twab-delegator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Fv4-twab-delegator/lists"}