Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Fixing vercel build bug #37

Merged
merged 4 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
insert_final_newline = true
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
with:
node-version: 16

- uses: pre-commit/action@v2.0.3
name: "Check python vercel functions"
with:
extra_args: --all-files --show-diff-on-failure

- name: Install dependencies (with cache)
uses: bahmutov/npm-install@v1

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ yarn-error.log*
.vercel

/api/storage/node_modules

#python
.venv
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
. "$(dirname "$0")/common.sh"

yarn lint-staged

pre-commit run --all-files
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- --in-place
- --remove-unused-variables
- --remove-all-unused-imports
- --expand-star-imports
- --ignore-init-module-imports
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The following repository hosts the source codes for `AlgoWorld Swapper`. Free an
- `Node` >= 14.x
- `yarn` >= 1.12.15
- `vercel cli` >= 24.2.4
- [`pre-commit`](https://pre-commit.com/) >= 2.19.0

## 🚀 Overview

Expand Down Expand Up @@ -57,7 +58,7 @@ Open `http://localhost:3000` with your browser to see the result.
- [`src`](./src) — Application source code, including pages, components, styles.
- [`api`](./api) — Serverless vercel functions, contract compilation is using `python` and `pyteal` and ipfs storage is done with `node`.
- [`.husky`](.husky) — Husky configuration and hooks.<br>

- [`.pre-commit-config.yaml`](.pre-commit-config.yaml) — pre commit coniguration for formatting python serverless functions.<br></br>
### Scripts

The section describes different modes of running the swapper for local dev purposes.
Expand Down
1 change: 1 addition & 0 deletions api/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "algoworld-swapper-storage",
"version": "0.0.1",
"description": "Serverless vercel functions to store ipfs files",
"license": "GPL-3.0",
"dependencies": {
"web3.storage": "4.2.0",
"@vercel/node": "2.1.0"
Expand Down
14 changes: 14 additions & 0 deletions api/swappers/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from algosdk.v2client.algod import AlgodClient

INCENTIVE_WALLET = "RJVRGSPGSPOG7W3V7IMZZ2BAYCABW3YC5MWGKEOPAEEI5ZK5J2GSF6Y26A"
INCENTIVE_FEE = 500_000

ALGOD_URL = "https://node.algoexplorerapi.io"
TESTNET_ALGOD_URL = "https://node.testnet.algoexplorerapi.io"

algod = AlgodClient("", ALGOD_URL, headers={"User-Agent": "algosdk"})
testnet_algod = AlgodClient("", TESTNET_ALGOD_URL, headers={"User-Agent": "algosdk"})


def get_algod(chain_type: str):
return testnet_algod if chain_type.lower() == "testnet" else algod
37 changes: 10 additions & 27 deletions api/swappers/compileSwap.py → api/swappers/compile-asa-to-asa.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
import json
import os
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler
from urllib import parse

from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from algoworld_contracts import contracts

CHAIN_TYPE = os.environ.get("CHAIN_TYPE", "TestNet")
INDEXER_URL = (
"https://algoindexer.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://algoindexer.algoexplorerapi.io"
)
ALGOD_URL = (
"https://node.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://node.algoexplorerapi.io"
)
INCENTIVE_WALLET = "RJVRGSPGSPOG7W3V7IMZZ2BAYCABW3YC5MWGKEOPAEEI5ZK5J2GSF6Y26A"
INCENTIVE_FEE = 500_000

algod = AlgodClient("", ALGOD_URL, headers={"User-Agent": "algosdk"})
indexer = IndexerClient("", INDEXER_URL, headers={"User-Agent": "algosdk"})
from .common import INCENTIVE_FEE, INCENTIVE_WALLET, get_algod


@dataclass
Expand All @@ -33,21 +15,22 @@ class SwapQueryParams:
offered_asa_amount: int
requested_asa_id: int
requested_asa_amount: int
chain_type: str


def compileSwap(inputParams: SwapQueryParams):
def compileSwap(input_params: SwapQueryParams):

swapper = contracts.get_swapper_teal(
inputParams.creator_address,
inputParams.offered_asa_id,
inputParams.offered_asa_amount,
inputParams.requested_asa_id,
inputParams.requested_asa_amount,
input_params.creator_address,
input_params.offered_asa_id,
input_params.offered_asa_amount,
input_params.requested_asa_id,
input_params.requested_asa_amount,
INCENTIVE_WALLET,
INCENTIVE_FEE,
)

response = algod.compile(swapper)
response = get_algod(input_params.chain_type).compile(swapper)
return response


Expand All @@ -64,6 +47,7 @@ def do_GET(self):
"offered_asa_amount": int(raw_params["offered_asa_amount"]),
"requested_asa_id": int(raw_params["requested_asa_id"]),
"requested_asa_amount": int(raw_params["requested_asa_amount"]),
"chain_type": raw_params["chain_type"],
}
)

Expand All @@ -72,6 +56,5 @@ def do_GET(self):
self.end_headers()

response = json.dumps(compileSwap(params))
print(response)
self.wfile.write(response.encode())
return
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
from cgi import parse_header, parse_multipart
import json
import os
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler
from urllib import parse

from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from algoworld_contracts import contracts

CHAIN_TYPE = os.environ.get("CHAIN_TYPE", "TestNet")
INDEXER_URL = (
"https://algoindexer.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://algoindexer.algoexplorerapi.io"
)
ALGOD_URL = (
"https://node.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://node.algoexplorerapi.io"
)
INCENTIVE_WALLET = "RJVRGSPGSPOG7W3V7IMZZ2BAYCABW3YC5MWGKEOPAEEI5ZK5J2GSF6Y26A"
INCENTIVE_FEE = 500_000

algod = AlgodClient("", ALGOD_URL, headers={"User-Agent": "algosdk"})
indexer = IndexerClient("", INDEXER_URL, headers={"User-Agent": "algosdk"})
from .common import INCENTIVE_FEE, INCENTIVE_WALLET, get_algod


@dataclass
Expand All @@ -34,6 +14,7 @@ class SwapConfig:
requested_algo_amount: int
max_fee: int
optin_funding_amount: int
chain_type: str


def compileMultiSwap(inputParams: SwapConfig):
Expand All @@ -48,7 +29,7 @@ def compileMultiSwap(inputParams: SwapConfig):
INCENTIVE_FEE,
)

response = algod.compile(swapper)
response = get_algod(inputParams.chain_type).compile(swapper)
return response


Expand All @@ -64,14 +45,14 @@ def do_POST(self):
"requested_algo_amount": post_body["requested_algo_amount"],
"max_fee": post_body["max_fee"],
"optin_funding_amount": post_body["optin_funding_amount"],
"chain_type": post_body["chain_type"],
}
)

self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()

print(params)
response = json.dumps(compileMultiSwap(params))

self.wfile.write(response.encode())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import json
import os
from dataclasses import dataclass
from http.server import BaseHTTPRequestHandler
from urllib import parse

from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from algoworld_contracts import contracts

CHAIN_TYPE = os.environ.get("CHAIN_TYPE", "TestNet")
INDEXER_URL = (
"https://algoindexer.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://algoindexer.algoexplorerapi.io"
)


ALGOD_URL = (
"https://node.testnet.algoexplorerapi.io"
if CHAIN_TYPE.lower() == "testnet"
else "https://node.algoexplorerapi.io"
)

algod = AlgodClient("", ALGOD_URL, headers={"User-Agent": "algosdk"})
indexer = IndexerClient("", INDEXER_URL, headers={"User-Agent": "algosdk"})
from .common import get_algod


@dataclass
class SwapProxyConfig:
swap_creator: str
version: str
chain_type: str


def compileSwapProxy(cfg: SwapProxyConfig):
swapper = contracts.get_swapper_proxy_teal(
swap_creator=cfg.swap_creator, version=cfg.version
)
response = algod.compile(swapper)
response = get_algod(cfg.chain_type).compile(swapper)
return response


Expand All @@ -48,6 +31,7 @@ def do_GET(self):
**{
"swap_creator": raw_params["swap_creator"],
"version": raw_params["version"],
"chain_type": raw_params["chain_type"],
}
)
self.send_response(200)
Expand Down
10 changes: 1 addition & 9 deletions api/swappers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
algoworld-contracts==1.3.0; python_version >= "3.9" and python_version < "4.0"
cffi==1.15.0; python_version >= "3.9" and python_version < "4.0"
msgpack==1.0.4; python_version >= "3.9" and python_version < "4.0"
py-algorand-sdk==1.13.1; python_version >= "3.9" and python_version < "4.0"
pycparser==2.21; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.4.0"
pycryptodomex==3.14.1; python_version >= "3.9" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.9" and python_version < "4.0" and python_full_version >= "3.5.0"
pynacl==1.5.0; python_version >= "3.9" and python_version < "4.0"
pyteal==0.10.0; python_version >= "3.9" and python_version < "4.0"
pyyaml==6.0; python_version >= "3.9" and python_version < "4.0"
algoworld-contracts @ git+https://github.com/algoworldnft/algoworld-contracts@1.3.0
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"@emotion/server": "11.4.0",
"@emotion/styled": "11.8.1",
"@fontsource/roboto": "4.5.7",
"@hookform/resolvers": "2.9.0",
"@hookform/resolvers": "2.9.1",
"@json-rpc-tools/utils": "1.7.6",
"@mui/icons-material": "5.8.3",
"@mui/lab": "5.0.0-alpha.85",
"@mui/material": "5.8.3",
"@mui/x-data-grid": "5.12.0",
"@mui/x-data-grid": "5.12.1",
"@reduxjs/toolkit": "1.8.2",
"@walletconnect/client": "1.7.8",
"algorand-walletconnect-qrcode-modal": "1.7.4",
Expand All @@ -59,12 +59,11 @@
"devDependencies": {
"@commitlint/cli": "17.0.2",
"@commitlint/config-conventional": "17.0.2",
"@types/node": "16.11.39",
"@types/node": "17.0.41",
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"@typescript-eslint/eslint-plugin": "5.27.1",
"@typescript-eslint/parser": "5.27.1",
"@vercel/node": "2.1.0",
"autoprefixer": "10.4.7",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
Expand All @@ -78,7 +77,8 @@
"postcss": "8.4.14",
"prettier": "2.6.2",
"typescript": "4.7.3",
"web3.storage": "4.2.0"
"web3.storage": "4.2.0",
"@vercel/node": "2.1.0"
},
"config": {
"commitizen": {
Expand Down
Loading