Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
feat: update contracts (#285)
Browse files Browse the repository at this point in the history
* wip: update contracts

* feat: update contracts and add tests

* chore: ignore act-actions locally to run ACT

* chore: revert types atm to master

* feat: update mint page and contract types

* chore: remove workflow dispache on gh-pages deploy

* feat: add action to deploy and initiate pool

* fix: fix method mint

* feat: update scripts and split init token and init pool

* chore: update docs

* chore: fix typo

* chore: prettify

* check lint before run tests

* chore: update contracts id
  • Loading branch information
luizstacio authored Jun 13, 2022
1 parent 8791704 commit 3f1404e
Show file tree
Hide file tree
Showing 33 changed files with 914 additions and 368 deletions.
137 changes: 137 additions & 0 deletions .github/workflows/deploy-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: "Deploy Contracts"

on:
workflow_dispatch:
inputs:
provider_url:
description: 'Provider url'
required: true
default: 'https://node.swayswap.io/graphql'
type: string
wallet_secret:
description: 'Wallet secret used to deploy and provide initial liquidity'
type: string
byte_price:
description: 'Min byte price required from the provider'
type: number
gas_price:
description: 'Min gas price required from the provider'
type: number
initiate_supply:
description: 'Should initialize the pool?'
required: true
default: true
type: boolean
commit_changes:
description: 'Commit .env.production on the current branch'
required: true
default: true
type: boolean

env:
RUST_VERSION: 1.61.0
FORC_VERSION: 0.15.2
NODE_VERSION: 16
PNPM_VERSION: 7.0.0
COMPOSE_VERSION: 2.6.0
WALLET_SECRET: ${{ github.event.inputs.wallet_secret || secrets.WALLET_SECRET }}
PROVIDER_URL: ${{ github.event.inputs.provider_url || 'https://node.swayswap.io/graphql' }}
BYTE_PRICE: ${{ github.event.inputs.byte_price || 1 }}
GAS_PRICE: ${{ github.event.inputs.gas_price || 1 }}
TOKEN_AMOUNT: ${{ github.event.inputs.token_amount }}
ETH_AMOUNT: ${{ github.event.inputs.eth_amount }}
OUTPUT_ENV: .env.production

jobs:
cancel-previous-run:
name: Cancel previous actions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

test_inputs:
runs-on: ubuntu-latest
steps:
- name: Check provider_url format
run: |
if ! [[ "${{ github.event.inputs.provider_url }}" =~ ^https?:\/\/([a-z0-9\.-]){1,}(:[0-9]{1,4})?\/graphql$ ]]; then
echo "Provider url is not valid";
process 1;
fi
shell: bash

build-and-deploy:
needs: test_inputs
name: Build and deploy
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_VERSION }}
override: true
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the cache plugin, as it uses the current rustc version as its cache key
- uses: Swatinem/rust-cache@v1

- name: Set git config
run: |
git config --global core.bigfilethreshold 100m
- name: Install Forc
run: |
curl -sSLf https://github.com/FuelLabs/sway/releases/download/v${{ env.FORC_VERSION }}/forc-binaries-linux_amd64.tar.gz -L -o forc.tar.gz
tar -xvf forc.tar.gz
chmod +x forc-binaries/forc
mv forc-binaries/forc /usr/local/bin/forc
shell: bash

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"

- name: Cache PNPM modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Setup PNPM
uses: pnpm/[email protected]
with:
version: ${{ env.PNPM_VERSION }}
run_install: true

- name: Setup scripts
run: |
pnpm scripts:setup
- name: Deploy contracts
run: |
pnpm exec swayswap-scripts run
- name: Initiate token contract and liquidity pool
if: ${{ github.event.inputs.initiate_supply }}
run: |
pnpm contracts:init-pool
env:
NODE_ENV: production

- name: Commit .env.production
if: ${{ github.event.inputs.commit_changes }}
uses: EndBug/add-and-commit@v9
with:
message: 'chore: update contract ids'
add: './packages/app/.env.production'
5 changes: 2 additions & 3 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: GitHub Pages
on:
release:
types: [published]
workflow_dispatch:

env:
NODE_VERSION: "16"
Expand Down Expand Up @@ -41,8 +40,8 @@ jobs:
CI: false
PUBLIC_URL: "/${{ github.event.repository.name }}"
VITE_FUEL_PROVIDER_URL: "https://node.swayswap.io/graphql"
VITE_CONTRACT_ID: "0x67ae68ddea9f9212d96c7b0f1ece1db522b0cfd688d96ed0bdd7d171b789e593"
VITE_TOKEN_ID: "0xf7a2eb8a271a3ea73d6fb8756e272f4a1687d9522acf2ded4454f5d0d5f6a660"
VITE_CONTRACT_ID: "0x4d7e56f79ad160ecd8f0da0833edd62044026bdab65275fa3a34e6a855b96ccc"
VITE_TOKEN_ID: "0xe3ee9322336a734296dd53afe9b90b1bfc7c716762844669b7895ca9ad438b88"
run: |
pnpm build
Expand Down
56 changes: 28 additions & 28 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: "CI"

on:
pull_request:
types: [opened, synchronize, ready_for_review, edited, closed]
types: [opened, synchronize, edited, closed]

env:
RUST_VERSION: 1.61.0
FORC_VERSION: 0.14.5
FORC_VERSION: 0.15.2
NODE_VERSION: 16
PNPM_VERSION: 7.0.0
COMPOSE_VERSION: 2.6.0
Expand Down Expand Up @@ -37,6 +37,32 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"

- name: Cache PNPM modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Setup PNPM
uses: pnpm/[email protected]
with:
version: ${{ env.PNPM_VERSION }}
run_install: true

# Check lint as early as possible to avoid
# Long fail CI and fail on this step
- name: Lint
run: |
pnpm lint
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -76,32 +102,6 @@ jobs:
run: |
./scripts/test-contracts.sh
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"

- name: Cache PNPM modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Setup PNPM
uses: pnpm/[email protected]
with:
version: ${{ env.PNPM_VERSION }}
run_install: true

# Check lint as early as possible to avoid
# Long fail CI and fail on this step
- name: Lint
run: |
pnpm lint
- name: Setup Docker
uses: docker/login-action@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ storybook-static
# general
contracts/token_contract/.rustc_info.json
.vercel

# Local actions to test CI using ACT
act-actions
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Built with an entirely new language ([Sway](https://fuellabs.github.io/sway/late
- [📦 - Install dependencies](docs/GETTING_STARTED.md#---install-dependencies)
- [📒 - Run Local Node](docs/GETTING_STARTED.md#---run-local-node)
- [💻 - Run Web App](docs/GETTING_STARTED.md#---run-web-app)
- [✨ - First steps](docs/GETTING_STARTED.md#---first-steps)
- [📗 Project overview](docs/GETTING_STARTED.md#-project-overview)
- [🧰 Useful scripts](docs/GETTING_STARTED.md#-useful-scripts)
- [Running tests](docs/GETTING_STARTED.md#running-tests)
- [Run tests on development mode](docs/GETTING_STARTED.md#running-tests-1)
- [Run tests on a Local TEST Environment](docs/GETTING_STARTED.md#run-tests-on-a-local-test-environment)
- [Contribution Guide](docs/CONTRIBUTE_GUIDE.md)
- [Finding Something to Work On](docs/CONTRIBUTE_GUIDE.md#finding-something-to-work-on)
- [Contribution Flow](docs/CONTRIBUTE_GUIDE.md#contribution-flow)
Expand Down
19 changes: 6 additions & 13 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project includes Front-End and Contracts because of this we expect the curr
- [Node.js v16.15.0 or latest stable](https://nodejs.org/en/) we recommend use [nvm](https://github.com/nvm-sh/nvm) to install.
- [PNPM v7.1.7 or latest stable](https://pnpm.io/installation/)
- [Rust toolchain v0.16.0 or latest stable](https://www.rust-lang.org/tools/install)
- [Forc v0.14.5 or latest stable](https://fuellabs.github.io/sway/latest/introduction/installation.html)
- [Forc v0.15.2](https://fuellabs.github.io/sway/latest/introduction/installation.html)
- [Docker v0.8.2 or latest stable](https://docs.docker.com/get-docker/)
- [Docker Compose v2.6.0 or latest stable](https://docs.docker.com/get-docker/)

Expand Down Expand Up @@ -36,7 +36,9 @@ In this step, we are going to;
- launch a local `fuel-core` node;
- launch a local `faucet` API;
- Setup `swayswap-scripts`;
- Build and Deploy the `swayswap contracts`.
- Build and Deploy the `swayswap contracts`;
- Initialize `token contract`;
- Initialize pool with liquidity `ETH <> DAI`.

```sh
pnpm services:setup
Expand All @@ -51,16 +53,6 @@ you browser [http://localhost:3000](http://localhost:3000).
pnpm dev
```

### ✨ - First steps

This guided step-by-step tutorial will allow you to create your first liquidity pool and play around with the application

1. As you go trough the `Welcome page` you should have already mintrf some `ETH`, you can get more by clicking on the `faucet button`;
2. Go to [http://localhost:3000/mint](http://localhost:4000/mint) and mint some DAI by clicking `Mint tokens`;
3. Now you need to create a pool, you can navigate by clicking `pool` and `add liquidity` or access [http://localhost:3000/pool/add-liquidity](http://localhost:3000/pool/add-liquidity);
4. Set the inputs with some `ETH` and `DAI` and click `Create liquidity`.
5. 🎉🎉 You are all set! Now you can go back to the swap page or add more liquidity, have fun!

## 📗 Project overview

This section has a brief description of each directory, more details can be found inside each package, by clicking on the links.
Expand Down Expand Up @@ -101,7 +93,7 @@ Please make sure you have follow the steps;
- [📦 - Install dependencies](docs/GETTING_STARTED.md#---install-dependencies)
- [📒 - Run Local Node](docs/GETTING_STARTED.md#---run-local-node)

## Run tests
## Run tests on development mode

We are going to run all tests, against the node and contract configured on the `packages/app/.env` or `packages/app/.env.test` if the file exists.

Expand All @@ -117,6 +109,7 @@ With this command we are going to;
- launch a local `test` specific `faucet` API;
- Setup `swayswap-scripts`;
- Build and Deploy the `swayswap contracts` to the `test` node.
- Initialize `token contract` deployed on the `test` node.
- Create a `packages/app/.env.test`
- Run all tests against the configs `packages/app/.env.test`
- Delete the local `test` specific `fuel-core` node;
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"contracts": "pnpm exec swayswap-scripts run",
"contracts:build": "pnpm exec swayswap-scripts build",
"contracts:deploy": "pnpm exec swayswap-scripts deploy",
"contracts:init": "pnpm run --filter swayswap-app contracts:init",
"contracts:init-pool": "pnpm run --filter swayswap-app contracts:init --init-pool",
"cy:open": "cypress open",
"cy:run": "cypress run --headless",
"dev": "turbo run dev --parallel",
Expand All @@ -38,13 +40,13 @@
"prettier:format": "prettier --write .",
"scripts:setup": "turbo run build --filter=swayswap-scripts && pnpm install",
"services:clean": "make -C docker services-clean",
"services:setup": "run-s scripts:setup services:run contracts",
"services:setup": "run-s scripts:setup services:run contracts contracts:init-pool",
"services:run": "make -C docker services-run",
"services:reset": "run-s services:clean services:run contracts",
"services:reset": "run-s services:clean services:setup",
"services:clean-test": "make -C docker services-clean-test",
"services:setup-test": "NODE_ENV=test run-s scripts:setup create:test-env services:run-test contracts",
"services:setup-test": "NODE_ENV=test run-s scripts:setup create:test-env services:run-test contracts contracts:init",
"services:run-test": "make -C docker services-run-test",
"services:reset-test": "NODE_ENV=test run-s services:clean-test services:run-test contracts",
"services:reset-test": "NODE_ENV=test run-s services:clean-test services:setup-test",
"test": "turbo run test -- --passWithNoTests --runInBand",
"test:coverage": "turbo run test -- --collectCoverage --passWithNoTests --runInBand",
"test:clear": "jest --clearCache",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
VITE_FUEL_PROVIDER_URL=https://node.swayswap.io/graphql
VITE_FUEL_FAUCET_URL=https://faucet-fuel-core.swayswap.io/dispense
VITE_FAUCET_RECAPTCHA_KEY=6Ld3cEwfAAAAAMd4QTs7aO85LyKGdgj0bFsdBfre
VITE_CONTRACT_ID=0x67ae68ddea9f9212d96c7b0f1ece1db522b0cfd688d96ed0bdd7d171b789e593
VITE_TOKEN_ID=0xf7a2eb8a271a3ea73d6fb8756e272f4a1687d9522acf2ded4454f5d0d5f6a660
VITE_CONTRACT_ID=0x4d7e56f79ad160ecd8f0da0833edd62044026bdab65275fa3a34e6a855b96ccc
VITE_TOKEN_ID=0xe3ee9322336a734296dd53afe9b90b1bfc7c716762844669b7895ca9ad438b88
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/App.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('App flow', () => {
it('should execute whole app flow', () => {
cy.visit('/ ');
cy.visit('/');

cy.contains('button', /Launch app/i).click();

Expand Down
2 changes: 1 addition & 1 deletion packages/app/load.envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ function getEnvName() {
[getEnvName(), '.env'].forEach((envFile) => {
if (!envFile) return;
config({
path: resolve(process.cwd(), envFile),
path: resolve(__dirname, envFile),
});
});
4 changes: 3 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"create404": "cp ./dist/index.html ./dist/404.html",
"dev": "vite",
"gh-preview": "sh ./scripts/gh-pages-preview.sh",
"contracts:init": "pnpm exec ts-node ./scripts/contracts-init",
"postinstall": "sh ./scripts/postinstall.sh",
"preview": "vite preview",
"test": "jest --verbose",
Expand All @@ -17,8 +18,8 @@
"@ethersproject/bignumber": "^5.6.2",
"@ethersproject/random": "^5.6.1",
"@ethersproject/units": "^5.6.1",
"@fontsource/raleway": "^4.5.9",
"@fontsource/inter": "^4.5.11",
"@fontsource/raleway": "^4.5.9",
"@headlessui/react": "^1.6.4",
"@radix-ui/react-accordion": "^0.1.6",
"@radix-ui/react-alert-dialog": "^0.1.7",
Expand Down Expand Up @@ -87,6 +88,7 @@
"postcss": "^8.4.14",
"postcss-import": "^14.1.0",
"tailwindcss": "^3.0.24",
"ts-node": "^10.8.1",
"typescript": "^4.7.3",
"vite": "^2.9.10"
}
Expand Down
Loading

0 comments on commit 3f1404e

Please sign in to comment.