Skip to content

Commit

Permalink
Merge pull request #1 from thirdweb-dev/yash/clean-up
Browse files Browse the repository at this point in the history
Setup forge, clean-up, etc
  • Loading branch information
kumaryash90 authored Feb 26, 2024
2 parents 8f3a43c + 4382f6d commit ff2520d
Show file tree
Hide file tree
Showing 31 changed files with 1,036 additions and 11,936 deletions.
22 changes: 22 additions & 0 deletions .github/composite-actions/setup/action.yml
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
36 changes: 36 additions & 0 deletions .github/workflows/prettier.yml
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
52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
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,
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# folders
artifacts_forge
cache
node_modules
.env

# Hardhat files
/cache
/artifacts
# files
*.env

# TypeChain files
/typechain
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
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
18 changes: 18 additions & 0 deletions .prettierrc
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
}
}
]
}
53 changes: 30 additions & 23 deletions README.md
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
```
71 changes: 0 additions & 71 deletions contracts/MockTarget.sol

This file was deleted.

Loading

0 comments on commit ff2520d

Please sign in to comment.