Skip to content

Commit

Permalink
Merge pull request #4 from Bananapus/refactor/npm
Browse files Browse the repository at this point in the history
refactor: npm
  • Loading branch information
mejango authored Feb 14, 2024
2 parents 683b218 + a63a08e commit 2d6bccc
Show file tree
Hide file tree
Showing 32 changed files with 4,878 additions and 279 deletions.
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Description

*What does this PR: do, how, why?*

## Limitations & risks

*Are there any trade-off or new vulnarbility surface based on theses changes?*

# Check-list
- [ ] Tests are covering the new feature
- [ ] Code is [natspec'd](https://docs.soliditylang.org/en/v0.8.17/natspec-format.html)
- [ ] Code is [linted and formatted](https://docs.soliditylang.org/en/v0.8.17/style-guide.html)
- [ ] I have run the test locally (and they pass)
- [ ] I have rebased to the latest main commit (and tests still pass)

# Interactions
These changes will impact the following contracts:
- Directly:

- Indirectly:
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: contracts-template-lint
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
forge-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: bahmutov/npm-install@v1
- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly
- name: Check linting
run: forge fmt --check
34 changes: 3 additions & 31 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: juice-contracts-publish
name: contracts-publish
on:
push:
branches:
Expand All @@ -8,38 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 16
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore cached yarn cache
uses: actions/cache@v2
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Restore cached node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: |
./node_modules
./packages/hardhat/node_modules
key: ${{ runner.os }}-${{ steps.nvm.outputs.NVMRC }}-nodemodules-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ steps.nvm.outputs.NVMRC }}-nodemodules-
- name: Install JS dependencies
if: |
steps.cache-yarn-cache.outputs.cache-hit != 'true' ||
steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --prefer-offline
- uses: bahmutov/npm-install@v1
# Publish deploy artifacts NPM packages. This will only run if there are new deploys.
- name: Publish NPM package
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
access: "public"
access: "public"
26 changes: 26 additions & 0 deletions .github/workflows/system-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: contracts-template-tests
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
forge-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: bahmutov/npm-install@v1
- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly
- name: install libraries
run: git submodule update --init
- name: Run tests
run: FOUNDRY_PROFILE=default forge snapshot # TODO: Change to fork once fork tests can be run
- name: Check contract sizes
run: FOUNDRY_PROFILE=ci_sizes forge build --sizes
52 changes: 0 additions & 52 deletions .github/workflows/tests.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
[submodule "lib/juice-contracts-v4"]
path = lib/juice-contracts-v4
url = https://github.com/Bananapus/juice-contracts-v4
[submodule "lib/v3-core"]
path = lib/v3-core
url = https://github.com/uniswap/v3-core
branch = 0.8
[submodule "lib/v3-periphery"]
path = lib/v3-periphery
url = https://github.com/uniswap/v3-periphery
branch = 0.8
[submodule "lib/uniswap-v3-foundry-quote"]
path = lib/uniswap-v3-foundry-quote
url = https://github.com/exhausted-pigeon-srl/uniswap-v3-foundry-quote
[submodule "lib/uniswap-v3-foundry-pool"]
path = lib/uniswap-v3-foundry-pool
url = https://github.com/exhausted-pigeon-srl/uniswap-v3-foundry-pool
39 changes: 39 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
node_modules
.env
*.txt
!remappings.txt

# Git
.git/
.github/
.gitmodules

# Misc
.example.env
utils/

# Output
out

# Foundry
lib/

# Hardhat files
cache
artifacts
deployments/localhost/**

# Mac OSX
.DS_Store

# Code coverage reports
coverage/
coverage.json
lcov.info

# VSCode
workspace.code-workspace
.vscode/

backup/
.secret
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Bananapus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
# Juicebox Buyback Hook
# Bananapus Buyback Hook

When a Juicebox project that uses the buyback hook is paid, it checks whether buying tokens in a Uniswap pool or paying the project as usual would yield more tokens for the payer. If buying tokens in the pool would yield more tokens, the payment is routed there. Otherwise, the payment is sent to the project as usual. Either way, the project's reserved rate applies.

The buyback hook works with any Juicebox terminal and checks the Uniswap pool specified by the project's owner.

_If you're having trouble understanding this contract, take a look at the [core Juicebox contracts](https://github.com/bananapus/juice-contracts-v4) and the [documentation](https://docs.juicebox.money/) first. If you have questions, reach out on [Discord](https://discord.com/invite/ErQYmth4dS)._
_If you're having trouble understanding this contract, take a look at the [core protocol contracts](https://github.com/Bananapus/nana-core) and the [documentation](https://docs.juicebox.money/) first. If you have questions, reach out on [Discord](https://discord.com/invite/ErQYmth4dS)._

## Install

For `npm` projects (recommended):

```bash
npm install @bananapus/buyback-hook
```

For `forge` projects (not recommended):

```bash
forge install Bananapus/nana-buyback-hook
```

Add `@bananapus/buyback-hook/=lib/nana-buyback-hook/` to `remappings.txt`. You'll also need to install `nana-buyback-hook`'s dependencies and add similar remappings for them.

## Develop

`juice-buyback` uses the [Foundry](https://github.com/foundry-rs/foundry) development toolchain for builds, tests, and deployments. To get set up, install [Foundry](https://github.com/foundry-rs/foundry):
`nana-buyback-hook` uses the [Foundry](https://github.com/foundry-rs/foundry) development toolchain for builds, tests, and deployments. To get set up, install [Foundry](https://github.com/foundry-rs/foundry):

```bash
curl -L https://foundry.paradigm.xyz | sh
Expand All @@ -26,7 +42,6 @@ Some useful commands:

| Command | Description |
| --------------------- | --------------------------------------------------- |
| `forge install` | Install the dependencies. |
| `forge build` | Compile the contracts and write artifacts to `out`. |
| `forge fmt` | Lint. |
| `forge test` | Run the tests. |
Expand All @@ -37,21 +52,19 @@ Some useful commands:

To learn more, visit the [Foundry Book](https://book.getfoundry.sh/) docs.

We recommend using [Juan Blanco's solidity extension](https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity) for VSCode.

## Utilities

For convenience, several utility commands are available in `util.sh`. To see a list, run:

```bash
`bash util.sh --help`.
```
## Scripts

Or make the script executable and run:
For convenience, several utility commands are available in `package.json`.

```bash
./util.sh --help
```
| Command | Description |
| --------------------------------- | -------------------------------------- |
| `npm test` | Run local tests. |
| `npm run test:fork` | Run fork tests (for use in CI). |
| `npm run coverage:lcov` | Generate an LCOV test coverage report. |
| `npm run deploy:ethereum-mainnet` | Deploy to Ethereum mainnet |
| `npm run deploy:ethereum-sepolia` | Deploy to Ethereum Sepolia testnet |
| `npm run deploy:optimism-mainnet` | Deploy to Optimism mainnet |
| `npm run deploy:optimism-testnet` | Deploy to Optimism testnet |

## Hooks

Expand Down
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ block_number = 14126430
block_timestamp = 1643802347
runs = 4096
fs_permissions = [{ access = "read", path = "lib/juice-contracts-v4/broadcast/Deploy.s.sol" }] # Get the deployment addresses to base the hook on.
libs = ["node_modules", "lib"]

[profile.fork] # run via FOUNDRY_PROFILE=fork foundry test

[profile.ci_sizes]
optimizer_runs = 200

[invariant]
fail_on_revert = false

Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 1 files
+1 −1 scripts/vm.py
1 change: 0 additions & 1 deletion lib/juice-contracts-v4
Submodule juice-contracts-v4 deleted from 292a8d
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from 192e87
1 change: 0 additions & 1 deletion lib/prb-math
Submodule prb-math deleted from 5b6279
1 change: 0 additions & 1 deletion lib/uniswap-v3-foundry-pool
Submodule uniswap-v3-foundry-pool deleted from 9ca359
1 change: 0 additions & 1 deletion lib/uniswap-v3-foundry-quote
Submodule uniswap-v3-foundry-quote deleted from cb6b07
1 change: 0 additions & 1 deletion lib/v3-core
Submodule v3-core deleted from 6562c5
1 change: 0 additions & 1 deletion lib/v3-periphery
Submodule v3-periphery deleted from b325bb
Loading

0 comments on commit 2d6bccc

Please sign in to comment.