-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
194 changed files
with
37,706 additions
and
0 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,4 @@ | ||
/contracts/.yarn/** linguist-vendored | ||
/contracts/.yarn/releases/* binary | ||
/contracts/.yarn/plugins/**/* binary | ||
/contracts/.pnp.* binary linguist-generated |
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,43 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
broadcast/ | ||
contracts/node_modules | ||
contracts/broadcast/* | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env | ||
|
||
# Node modules | ||
!/node_modules | ||
node_modules/* | ||
|
||
# Package lock files | ||
package-lock.json | ||
|
||
# Yarn | ||
.pnp.* | ||
*/.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
# System files | ||
.DS_Store | ||
contracts/.DS_Store | ||
|
||
# lib | ||
contracts/lib/* | ||
|
||
# Vscode | ||
.idea/ |
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,9 @@ | ||
[submodule "contracts/lib/openzeppelin-contracts"] | ||
path = contracts/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[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,6 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "explicit" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,104 @@ | ||
# Decentralized Exchange | ||
|
||
Annual project focused on creating a complete decentralized application (dApp) that simulates a digital asset exchange platform on the Ethereum blockchain. This project is designed to provide a comprehensive experience in the development of a modern, decentralized financial (DeFi) application. | ||
|
||
## Prerequisites | ||
|
||
- Node.js | ||
- npm | ||
- Wallet ( metamask / trust .. ) | ||
|
||
## Technologies | ||
|
||
To the global web architecture we're using foundry.Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts. | ||
|
||
1. **Smart Contracts**: | ||
|
||
We're using Solidity to write the smart contracts and Truffle to compile, test and deploy them. | ||
|
||
- Solidity, | ||
- Truffle, | ||
- TypeScript, | ||
|
||
2. **API**: | ||
|
||
We're using a Go API to get tokens Infos and to interact with the smart contracts. We're using Gin as a web framework, Gorm as an ORM and Go to interact with the Ethereum blockchain. | ||
|
||
- Go, | ||
- Gin, | ||
- Gorm, | ||
|
||
3. **Frontend**: | ||
|
||
We're using React to create the frontend of the dApp. We're using TypeScript to write the code and TailwindCSS to style the components. | ||
|
||
- React, | ||
- TypeScript, | ||
- TailwindCSS, | ||
- Shadcn/ui | ||
|
||
4. **Integration**: | ||
|
||
We're using Docker to run the API and the smart contracts on the same network. | ||
|
||
## Structure | ||
``` | ||
├── contracts | ||
│ ├── lib | ||
│ ├── script | ||
│ ├── src | ||
│ └── test | ||
│ | ||
├── api | ||
│ ├── controller | ||
│ ├── models | ||
│ ├── services | ||
│ ├── main.go | ||
│ └── .env | ||
│ | ||
└── frontend | ||
├── src | ||
│ ├── assets | ||
│ └── components | ||
│ └── lib | ||
│ └── styles | ||
├── .env | ||
├── tailwind.config.js | ||
├── lib | ||
└── styles | ||
``` | ||
|
||
## Installation | ||
|
||
### 1. Clone the repository | ||
|
||
```bash | ||
git clone [email protected]:MTthoas/Dex.git | ||
``` | ||
|
||
### 2. Install the dependencies | ||
|
||
```bash | ||
cd Dex | ||
npm install | ||
``` | ||
|
||
### 3. Compile the smart contracts | ||
|
||
```bash | ||
npm run compile | ||
``` | ||
|
||
### 4. Deploy the smart contracts | ||
|
||
```bash | ||
npm run deploy | ||
``` | ||
|
||
### 5. Run frontend | ||
|
||
```bash | ||
cd ./frontend | ||
npm i | ||
npm start | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
# Server settings: | ||
SERVER_URL="0.0.0.0:5000" | ||
SERVER_READ_TIMEOUT=60 | ||
|
||
# JWT settings: | ||
JWT_SECRET_KEY= | ||
JWT_SECRET_KEY_EXPIRE_MINUTES_COUNT=15 | ||
|
||
CG_API_KEY= | ||
|
||
# Database settings: | ||
DB_SERVER_URL="host= port=5432 user= password= dbname= sslmode=disable" | ||
DB_MAX_CONNECTIONS=100 | ||
DB_MAX_IDLE_CONNECTIONS=10 | ||
DB_MAX_LIFETIME_CONNECTIONS=2 |
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,5 @@ | ||
|
||
docs | ||
build | ||
*.out | ||
.env.local |
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,48 @@ | ||
# Utilisation d'une image de builder Go avec Alpine pour un environnement minimal. | ||
FROM golang:1.21-alpine AS builder | ||
|
||
# Installation de git, nécessaire pour récupérer les modules Go et Swaggo. | ||
RUN apk add --no-cache git | ||
|
||
# Installation des certificats CA, cruciaux pour les appels HTTPS. | ||
RUN apk add --no-cache ca-certificates | ||
|
||
# Installation de Swag CLI pour la documentation Swagger. | ||
RUN go install github.com/swaggo/swag/cmd/swag@latest | ||
|
||
# Définir le répertoire de travail où se trouve le code source. | ||
WORKDIR /api | ||
|
||
# Copie des fichiers de module Go et téléchargement des dépendances. | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
# Copie du reste de l'API dans l'image. | ||
COPY . . | ||
|
||
# Génération de la documentation Swagger. | ||
RUN swag init --generalInfo ./routes/swagger_routes.go --output ./docs | ||
|
||
# Configuration des variables d'environnement nécessaires pour la construction. | ||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 | ||
|
||
# Construction du serveur API. | ||
RUN go build -ldflags="-s -w" -o apiserver . | ||
|
||
# Utilisation d'une image scratch pour un environnement d'exécution minimal. | ||
FROM scratch | ||
|
||
# Copie du binaire, des fichiers de configuration, et de la documentation Swagger. | ||
COPY --from=builder /api/apiserver / | ||
COPY --from=builder /api/.env / | ||
COPY --from=builder /api/docs /docs | ||
|
||
# Copie des certificats CA. | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
# Exposition du port sur lequel le serveur API s'exécute. | ||
EXPOSE 5002 | ||
EXPOSE 5000 | ||
|
||
# Commande pour exécuter le serveur API lors du démarrage du conteneur. | ||
CMD ["/apiserver"] |
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,54 @@ | ||
.PHONY: clean test build run migrate.up migrate.down migrate.force docker.run docker.network docker.fiber.build docker.fiber docker.postgres docker.stop docker.stop.fiber docker.stop.postgres swag | ||
|
||
APP_NAME = apiserver | ||
BUILD_DIR = build | ||
MIGRATIONS_FOLDER = $(CURDIR)/platform/migrations | ||
DATABASE_URL = postgres://postgres:password@localhost/postgres?sslmode=disable | ||
|
||
# clean: | ||
# if exist $(BUILD_DIR) rmdir /s /q $(BUILD_DIR) | ||
# del /f /q cover.out 2>nul | ||
|
||
test: | ||
go test -v -timeout 30s -coverprofile=cover.out -cover ./... | ||
go tool cover -func=cover.out | ||
|
||
build: clean test | ||
go build -ldflags="-w -s" -o $(BUILD_DIR)/$(APP_NAME) main.go | ||
|
||
run: swag build | ||
$(BUILD_DIR)/$(APP_NAME) | ||
|
||
migrate.up: | ||
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" up | ||
|
||
migrate.down: | ||
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" down | ||
|
||
migrate.force: | ||
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" force $(version) | ||
|
||
docker.run: docker.network docker.postgres swag docker.fiber migrate.up | ||
|
||
docker.network: | ||
-docker network create -d bridge dev-network | ||
|
||
docker.fiber.build: | ||
docker build -t fiber . | ||
|
||
docker.fiber: docker.fiber.build | ||
docker run --rm -d --name dev-fiber --network dev-network -p 5000:5000 fiber | ||
|
||
docker.postgres: | ||
docker run --rm -d --name dev-postgres --network dev-network -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -v ${HOME}/dev-postgres/data/:/var/lib/postgresql/data -p 5432:5432 postgres | ||
|
||
docker.stop: docker.stop.fiber docker.stop.postgres | ||
|
||
docker.stop.fiber: | ||
docker stop dev-fiber | ||
|
||
docker.stop.postgres: | ||
docker stop dev-postgres | ||
|
||
swag: | ||
swag init -g main.go |
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,37 @@ | ||
# Create Network | ||
|
||
docker network create -d bridge dev-network | ||
|
||
# PostgreSQL and initial Migration | ||
|
||
docker run --rm -d --name dev-postgres --network dev-network -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=postgres -v \${HOME}/dev-postgres/data/:/var/lib/postgresql/data -p 5432:5432 postgres | ||
|
||
docker run --rm -d \ | ||
--name dev-postgres \ | ||
--network dev-network \ | ||
-e POSTGRES_USER=postgres \ | ||
-e POSTGRES_PASSWORD=password \ | ||
-e POSTGRES_DB=postgres \ | ||
-v \${HOME}/dev-postgres/data/:/var/lib/postgresql/data \ | ||
-p 5432:5432 \ | ||
postgres | ||
|
||
# Migrate | ||
|
||
migrate -path ./migrations -database "postgres://postgres:password@localhost/postgres?sslmode=disable" up | ||
|
||
# Build Fiber docker Image ( DockerFile ) | ||
|
||
docker build -t fiber . | ||
|
||
# Create and start container from image | ||
|
||
docker run --rm -d --name dev-fiber --network dev-network -p 5000:5000 fiber | ||
|
||
## IN LOCAL | ||
|
||
docker build -t api-build . | ||
|
||
go install github.com/swaggo/swag/cmd/swag@latest | ||
swag init --generalInfo ./routes/swagger_routes.go --output ./docs | ||
>> go run main.go |
Oops, something went wrong.