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

@jbx-protocol/juice-buyback-delegate

v1.0.2

Published

## Summary

Downloads

4

Readme

Juice Buyback Delegate - ETH-Project token

Summary

Provides a datasource and delegate which maximise the project token received by the contributor when they call pay on the terminal. In order to do so, the delegate will either mint new tokens ("vanilla" path, bypassing the delegate) or swap existing token in an Uniswap V3 pool ("buyback" path), depending on the best quote available at the time of the call.

This first iteration is only compatible with 18-decimals token terminals.

Design

Flow

  • The frontend passes a quote (as an amount received for a given amount send) from the correct Uniswap V3 pool, as well as a maximum slippage allowed (in 1/10000th) while calling pay(..). These should be encoded as uint256 and passed as third and fourth words of the pay(..) metadata parameter (the first 2 32bytes being reserved for the protocol). If no quote is provided, a twap is then used.
  • Pay(..) will use the buyback delegate as datasource and, based on the quote (taking slippage into account) and the funding cycle weight, will either mint (bypassing the delegate and using the regular terminal logic) or swap (signaling this by returning the delegate address and a 0 weight to the terminal).
  • If swap is privilegied, the terminal will call the delegate's didPay method, which will wrap and swap the eth, and transfer the correct amount of project tokens to the contributor (ie the non-reserved ones). NB: The whole amount contributed will be swapped, including what should be considered as reserved. The delegate will then burn/mint/burn again the non-transfered to account for the reserved tokens (ie burn them all, then mint an amount which will return the correct amount of reserved token, then burn the non-reserved token just minted)
  • In case of failure of the swap (eg max slippage, low liquidity), the delegate will mint the tokens instead (using the original funding cycle weight and reserved rate).

Contracts/Interfaces

  • BuyBackDelegate: the datasource, pay delegate and uniswap pool callback contract
  • BuyBackDelegate3.1.1: the buyback delegate leveraging the new terminal v3.1.1

Usage

Anyone can deploy this delegate using the provided forge script. To run this repo, you'll need Foundry and NodeJS installed. Install the dependencies with npm install && git submodule update --init --force --recursive, you should then be able to run the tests using forge test or deploy a new delegate using forge script Deploy (and the correct arguments, based on the chain and key you want to use - see the Foundry docs).

Use-case

Maximizing the project token received by the contributor while leveling the funding cycle/secondary market price.

Risk & trade-offs

  • This delegate is, for now, only compatible with ETH as terminal token.
  • This delegate relies on the liquidity available in an Uniswap V3. If LP migrate to a new pool or another DEX, this delegate would need to be redeployed.
  • A low liquidity might, if the max slippage isn't set properly, lead to an actual amount of token received lower than expected.

Future work

  • Non-18 decimals token should use a non fixed decimals (ln167, ln199, ln284 - _data.amount.decimals) and the tests should then use this same decimals (or the terminal decimal for forked tests, IJBSingleTokenPaymentTerminal(address(jbEthPaymentTerminal)).decimals())
  • Invariant are only partially tested (total supply hold in mint case, pool needfs additional tooling as we rely on hardcoded pool hash for create2)
  • A first version was designed to be used as a BBD for an unique project (project token, pool, etc being immutables), in order to keep the gas cost as low as possible. This might be resumed and further tested if a need arises.