{"id":20002040,"url":"https://github.com/pooltogether/loot-box","last_synced_at":"2025-05-04T15:33:50.790Z","repository":{"id":49369080,"uuid":"307927106","full_name":"pooltogether/loot-box","owner":"pooltogether","description":"Loot Boxes are Ethereum smart contracts that can be traded like NFTs and plundered by the owner","archived":false,"fork":false,"pushed_at":"2023-11-10T17:42:21.000Z","size":1331,"stargazers_count":38,"open_issues_count":1,"forks_count":27,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T04:03:29.701Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-28T06:33:09.000Z","updated_at":"2025-01-06T04:35:34.000Z","dependencies_parsed_at":"2024-11-13T05:30:16.534Z","dependency_job_id":null,"html_url":"https://github.com/pooltogether/loot-box","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Floot-box","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Floot-box/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Floot-box/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pooltogether%2Floot-box/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pooltogether","download_url":"https://codeload.github.com/pooltogether/loot-box/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252356701,"owners_count":21734996,"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:35.021Z","updated_at":"2025-05-04T15:33:50.415Z","avatar_url":"https://github.com/pooltogether.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Loot Boxes\n\n[![CircleCI](https://circleci.com/gh/pooltogether/loot-box.svg?style=svg)](https://circleci.com/gh/pooltogether/loot-box)\n[![Coverage Status](https://coveralls.io/repos/github/pooltogether/loot-box/badge.svg?branch=main)](https://coveralls.io/github/pooltogether/loot-box?branch=main)\n\nLoot Boxes are special addresses that are associated to an ERC721.  Only the NFT owner can withdraw tokens from the Loot Box address.\n\nSupported tokens:\n\n- ERC20\n- ERC721\n- ERC777 (only if it implements ERC20)\n- ERC1155\n\n# Setup\n\nYou can use NPM to install the package:\n\n```bash\n$ npm install @pooltogether/loot-box\n```\n\nOr you can find the address and ABIs on the [Networks](https://docs.pooltogether.com/networks) page of the PoolTogether documentation.\n\n# Usage\n\n**LootBoxController**: A contract that associates an address with an ERC721 and allows anyone to \"plunder\" the address: withdrawing desired tokens to the ERC721 owner's address.\n\nThe user flow is like so:\n\n1. The Loot Box Controller computes the Loot Box address for *any ERC721*.\n2. Anyone can transfer tokens to the Loot Box address\n3. Anyone may call the Loot Box Controller to transfer tokens from the Loot Box address to the current owner of the ERC721.\n\nWhen the Loot Box controller withdraws tokens from a Loot Box, it's actually using CREATE2 to create a minimal proxy instance of a Loot Box.  After the tokens are transferred, the Loot Box contract is destroyed.  This cheap deployment and immediate destruction of the contract minimizes the gas overhead.\n\n# API\n\n## LootBoxController\n\n```solidity\ncomputeAddress(address erc721, uint256 tokenId)\n```\n\nComputes the address of the Loot Box for the given ERC721.  Returns the address of the Loot Box.\n\nNote that no contract will exist there.  The Loot Box contract is created and destroyed in a single tx.\n\n```solidity\nplunder(\n  address erc721,\n  uint256 tokenId,\n  address[] calldata erc20s,\n  WithdrawERC721[] calldata erc721s,\n  WithdrawERC1155[] calldata erc1155s\n)\n```\n\nTransfers all of the given tokens in the Loot Box to the owner of the ERC721.\n\n`erc20s` is an array of ERC20 token addresses. The full balance of each will be transferred to the ERC721 owner.\n\n`erc721s` is an array of `WithdrawERC721` objects:\n\n```solidity\nstruct WithdrawERC721 {\n  address token;\n  uint256[] tokenIds;\n}\n```\n\n`erc1155s` is an array of `WithdrawERC1155` objects:\n\n```solidity\nstruct WithdrawERC1155 {\n  address token;\n  uint256[] ids;\n  uint256[] amounts;\n  bytes data;\n}\n```\n\nThe gas usage of `plunder` is quite reasonable.  When withdrawing 2 ERC20s, 1 ERC721s and 1 ERC1155 the gas cost is ~211k.  This is based on the standard OpenZeppelin token implementations.\n\n## Development\n\nFirst clone the repository then run:\n\n```bash\n$ yarn\n```\n\nNow run the tests:\n\n```bash\n$ yarn test\n```\n\nRun code coverage:\n\n```bash\n$ yarn coverage\n```\n\nRun gas checks:\n\n```bash\n# start a node\n$ yarn start-gas\n# run the tests with gas reporter\n$ yarn gas\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Floot-box","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpooltogether%2Floot-box","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpooltogether%2Floot-box/lists"}