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/loot-box

v1.1.0

Published

Loot Boxes are Ethereum smart contracts that can be traded like NFTs and plundered by the owner.

Downloads

38

Readme

Loot Boxes

CircleCI Coverage Status

Loot Boxes are Ethereum smart contracts that can be traded like NFTs and plundered for tokens.

Supported tokens:

  • ERC20
  • ERC721
  • ERC777 (only if it implements ERC20)
  • ERC1155

Setup

You can use NPM to install the package:

$ npm install @pooltogether/loot-box

Or you can find the address and ABIs on the Networks page of the PoolTogether documentation.

Usage

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.

The user flow is like so:

  1. The Loot Box Controller computes the Loot Box address for any ERC721.
  2. Anyone can transfer tokens to the Loot Box address
  3. Anyone may call the Loot Box Controller to transfer tokens from the Loot Box address to the current owner of the ERC721.

When 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.

API

LootBoxController

computeAddress(address erc721, uint256 tokenId)

Computes the address of the Loot Box for the given ERC721. Returns the address of the Loot Box.

Note that no contract will exist there. The Loot Box contract is created and destroyed in a single tx.

plunder(
  address erc721,
  uint256 tokenId,
  address[] calldata erc20s,
  WithdrawERC721[] calldata erc721s,
  WithdrawERC1155[] calldata erc1155s
)

Transfers all of the given tokens in the Loot Box to the owner of the ERC721.

erc20s is an array of ERC20 token addresses. The full balance of each will be transferred to the ERC721 owner.

erc721s is an array of WithdrawERC721 objects:

struct WithdrawERC721 {
  address token;
  uint256[] tokenIds;
}

erc1155s is an array of WithdrawERC1155 objects:

struct WithdrawERC1155 {
  address token;
  uint256[] ids;
  uint256[] amounts;
  bytes data;
}

The 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.

Development

First clone the repository then run:

$ yarn

Now run the tests:

$ yarn test

Run code coverage:

$ yarn coverage

Run gas checks:

# start a node
$ yarn start-gas
# run the tests with gas reporter
$ yarn gas