-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from thirdweb-dev/yash/clean-up
Setup forge, clean-up, etc
- Loading branch information
Showing
31 changed files
with
1,036 additions
and
11,936 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "Install" | ||
description: "Sets up Node.js and runs install" | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
registry-url: "https://registry.npmjs.org" | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: yarn | ||
|
||
- name: Setup lcov | ||
shell: bash | ||
run: | | ||
sudo apt update | ||
sudo apt install -y lcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Prettier Formatting | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
# cancel previous runs if new commits are pushed to the branch | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# This workflow contains a single job called "build" | ||
lint: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
fetch-depth: 25 | ||
|
||
- name: Setup Project | ||
uses: ./.github/composite-actions/setup | ||
|
||
- name: Run Prettier | ||
run: yarn prettier:contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Tests | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
# cancel previous runs if new commits are pushed to the branch | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
test: | ||
# The type of runner that the job will run on | ||
# 16 core paid runner | ||
runs-on: ubuntu-latest-16 | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
fetch-depth: 25 | ||
node-version: 18 | ||
|
||
- name: Setup Project | ||
uses: ./.github/composite-actions/setup | ||
|
||
- name: Install Foundry | ||
uses: onbjerg/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
- name: Run coverage and tests | ||
run: | | ||
forge coverage --report lcov | ||
lcov --remove lcov.info -o lcov.info 'src/test/**' | ||
lcov --remove lcov.info -o lcov.info 'contracts/external-deps/**' | ||
lcov --remove lcov.info -o lcov.info 'contracts/eip/**' | ||
forge test | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
files: ./lcov.info, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"endOfLine":"auto", | ||
"printWidth": 120, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"tabWidth": 4 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
# Sample Hardhat Project | ||
## **Thirdweb Gateway Contract** | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
Thirdweb Gateway Contract is used as the entrypoint to thirdweb Pay for swaps and bridges. | ||
|
||
Try running some of the following tasks: | ||
This is a forwarder contract that forwards the swap providers transaction (LiFi, Decent, etc) to their contract. Thirdweb Gateway Contract has the following responsibilities: | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.js | ||
``` | ||
- Data Logging - this is essential for attribution and linking on-chain and off-chain data | ||
- Fee Splitting - this allows us to split the fees in-flight and flexibility to change fees on a per client basis | ||
- Data validation - this provides high-security as only thirdweb originated swaps with untampered data can use this contract | ||
- exit point for contract calls - for LiFi, they can only guarantee toAmount for contract calls. This allows use to add a contract call to transferEnd that forwards the end funds to the user | ||
- Stateless - this will be deployed on many different chains. We don’t want to have to call addClient, changeFee, addSwapProvider, etc on every single chain for every change. Therefore, this should not rely on data held in the state of the contract, but rather data passed in | ||
|
||
# swaps-gateway-proto | ||
[Gateway Reference](img/gateway.png) | ||
|
||
Polygon Deploy | ||
USAGE: | ||
[Gateway With Transfer End](img/gateway-transfer-end.png) | ||
|
||
Successfully deployed on polygon: 0xB246b022df8cFd4a752dC058236Cc0A6abd02E3c | ||
## Features | ||
|
||
- Event Logging | ||
- TransferStart logs the necessary events attribution and link off-chain and on-chain through clientId and transactionId. We use bytes32 instead of string for clientId and transactionId (uuid in database) because this allows recovering indexed pre-image | ||
- TransferEnd logs the transfer end in case of a contract call and can be used for indexing bridge transactions by just listening to our Thirdweb Gateway deployments | ||
- FeePayout logs the fees distributed among the payees | ||
- Fee Splitting | ||
- supports many parties for fee payouts (we only expect us and client). It also allows for flexible fees on a per client basis | ||
- Withdrawals | ||
- some bridges refund the sender if it fails. If this contract ends up with a balance, we need a way to return it to user, so need to support withdrawals preventing lost funds | ||
- Data verification | ||
|
||
## Usage | ||
- Since we want this to be stateless and secure, we use an operator that signs all transactions created in our backend. This will use engine to sign the transactions. | ||
- We should be able to switch out this operator. Also, the operator (engine) should be able to programmatically withdraw funds so we can build automated customer support tools | ||
|
||
### Deploy | ||
npx hardhat run --network <network> scripts/deploy.js | ||
example: npx hardhat run --network polygon scripts/deploy.js | ||
### Build | ||
|
||
### Test | ||
npx hardhat test | ||
npx hardhat test --grep <testcase> | ||
```shell | ||
$ forge build | ||
``` | ||
|
||
### Encode Transfer End | ||
prints the data for the transfer end call. Use this for testing wrapping the data. | ||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.