Add initial project structure and documentation files

- Created .gitignore to exclude sensitive files and directories.
- Added API documentation in API_DOCUMENTATION.md.
- Included deployment instructions in DEPLOYMENT.md.
- Established project structure documentation in PROJECT_STRUCTURE.md.
- Updated README.md with project status and team information.
- Added recommendations and status tracking documents.
- Introduced testing guidelines in TESTING.md.
- Set up CI workflow in .github/workflows/ci.yml.
- Created Dockerfile for backend and frontend setups.
- Added various service and utility files for backend functionality.
- Implemented frontend components and pages for user interface.
- Included mobile app structure and services.
- Established scripts for deployment across multiple chains.
This commit is contained in:
defiQUG
2025-12-03 21:22:31 -08:00
commit 507d9a35b1
261 changed files with 47004 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
import { ethers } from "hardhat";
import * as fs from "fs";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying to Avalanche with account:", deployer.address);
const chainId = 43114;
const rpcUrl = process.env.AVALANCHE_RPC_URL || "https://api.avax.network/ext/bc/C/rpc";
const ccipRouter = process.env.AVALANCHE_CCIP_ROUTER || "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D";
const chainSelector = BigInt('6433500567565415381');
console.log(`\n=== Deploying to Avalanche (Chain ID: ${chainId}) ===`);
try {
// Deploy Diamond
const Diamond = await ethers.getContractFactory("Diamond");
const diamond = await Diamond.deploy();
await diamond.waitForDeployment();
const diamondAddress = await diamond.getAddress();
console.log(`Diamond deployed to: ${diamondAddress}`);
// Deploy Facets
const facets = {
DiamondCutFacet: await (await ethers.getContractFactory("DiamondCutFacet")).deploy(),
LiquidityFacet: await (await ethers.getContractFactory("LiquidityFacet")).deploy(),
VaultFacet: await (await ethers.getContractFactory("VaultFacet")).deploy(),
ComplianceFacet: await (await ethers.getContractFactory("ComplianceFacet")).deploy(),
CCIPFacet: await (await ethers.getContractFactory("CCIPFacet")).deploy(),
GovernanceFacet: await (await ethers.getContractFactory("GovernanceFacet")).deploy(),
SecurityFacet: await (await ethers.getContractFactory("SecurityFacet")).deploy(),
ChainConfigFacet: await (await ethers.getContractFactory("ChainConfigFacet")).deploy(),
};
console.log("Facets deployed");
// Configure CCIP
const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress);
await ccipFacet.setCCIPRouter(ccipRouter);
await ccipFacet.setChainSelector(chainId, chainSelector);
console.log(`CCIP Router configured: ${ccipRouter}`);
// Configure ChainConfig
const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress);
await chainConfigFacet.setChainConfig(
chainId,
"Avalanche",
ethers.ZeroAddress,
"https://snowtrace.io",
BigInt(3000000),
BigInt(300)
);
await chainConfigFacet.setChainActive(chainId, true);
const deployment = {
diamond: diamondAddress,
facets: Object.fromEntries(
Object.entries(facets).map(([name, contract]) => [name, await contract.getAddress()])
),
chainId: chainId,
chainName: "Avalanche",
ccipRouter,
chainSelector: chainSelector.toString(),
};
console.log(`✓ Avalanche deployment complete`);
console.log(JSON.stringify(deployment, null, 2));
// Write to file
fs.writeFileSync(
`deployments-avalanche-${chainId}.json`,
JSON.stringify(deployment, null, 2)
);
} catch (error) {
console.error(`✗ Failed to deploy to Avalanche:`, error);
throw error;
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

86
scripts/deploy-base.ts Normal file
View File

@@ -0,0 +1,86 @@
import { ethers } from "hardhat";
import * as fs from "fs";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying to Base with account:", deployer.address);
const chainId = 8453;
const rpcUrl = process.env.BASE_RPC_URL || "https://mainnet.base.org";
const ccipRouter = process.env.BASE_CCIP_ROUTER || "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D";
const chainSelector = BigInt('15971525489660198786');
console.log(`\n=== Deploying to Base (Chain ID: ${chainId}) ===`);
try {
// Deploy Diamond
const Diamond = await ethers.getContractFactory("Diamond");
const diamond = await Diamond.deploy();
await diamond.waitForDeployment();
const diamondAddress = await diamond.getAddress();
console.log(`Diamond deployed to: ${diamondAddress}`);
// Deploy Facets
const facets = {
DiamondCutFacet: await (await ethers.getContractFactory("DiamondCutFacet")).deploy(),
LiquidityFacet: await (await ethers.getContractFactory("LiquidityFacet")).deploy(),
VaultFacet: await (await ethers.getContractFactory("VaultFacet")).deploy(),
ComplianceFacet: await (await ethers.getContractFactory("ComplianceFacet")).deploy(),
CCIPFacet: await (await ethers.getContractFactory("CCIPFacet")).deploy(),
GovernanceFacet: await (await ethers.getContractFactory("GovernanceFacet")).deploy(),
SecurityFacet: await (await ethers.getContractFactory("SecurityFacet")).deploy(),
ChainConfigFacet: await (await ethers.getContractFactory("ChainConfigFacet")).deploy(),
};
console.log("Facets deployed");
// Configure CCIP
const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress);
await ccipFacet.setCCIPRouter(ccipRouter);
await ccipFacet.setChainSelector(chainId, chainSelector);
console.log(`CCIP Router configured: ${ccipRouter}`);
// Configure ChainConfig
const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress);
await chainConfigFacet.setChainConfig(
chainId,
"Base",
ethers.ZeroAddress,
"https://basescan.org",
BigInt(3000000),
BigInt(300)
);
await chainConfigFacet.setChainActive(chainId, true);
const deployment = {
diamond: diamondAddress,
facets: Object.fromEntries(
Object.entries(facets).map(([name, contract]) => [name, await contract.getAddress()])
),
chainId: chainId,
chainName: "Base",
ccipRouter,
chainSelector: chainSelector.toString(),
};
console.log(`✓ Base deployment complete`);
console.log(JSON.stringify(deployment, null, 2));
// Write to file
fs.writeFileSync(
`deployments-base-${chainId}.json`,
JSON.stringify(deployment, null, 2)
);
} catch (error) {
console.error(`✗ Failed to deploy to Base:`, error);
throw error;
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

86
scripts/deploy-bsc.ts Normal file
View File

@@ -0,0 +1,86 @@
import { ethers } from "hardhat";
import * as fs from "fs";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying to BSC with account:", deployer.address);
const chainId = 56;
const rpcUrl = process.env.BSC_RPC_URL || "https://bsc-dataseed1.binance.org";
const ccipRouter = process.env.BSC_CCIP_ROUTER || "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D";
const chainSelector = BigInt('11344663589394136015');
console.log(`\n=== Deploying to BSC (Chain ID: ${chainId}) ===`);
try {
// Deploy Diamond
const Diamond = await ethers.getContractFactory("Diamond");
const diamond = await Diamond.deploy();
await diamond.waitForDeployment();
const diamondAddress = await diamond.getAddress();
console.log(`Diamond deployed to: ${diamondAddress}`);
// Deploy Facets
const facets = {
DiamondCutFacet: await (await ethers.getContractFactory("DiamondCutFacet")).deploy(),
LiquidityFacet: await (await ethers.getContractFactory("LiquidityFacet")).deploy(),
VaultFacet: await (await ethers.getContractFactory("VaultFacet")).deploy(),
ComplianceFacet: await (await ethers.getContractFactory("ComplianceFacet")).deploy(),
CCIPFacet: await (await ethers.getContractFactory("CCIPFacet")).deploy(),
GovernanceFacet: await (await ethers.getContractFactory("GovernanceFacet")).deploy(),
SecurityFacet: await (await ethers.getContractFactory("SecurityFacet")).deploy(),
ChainConfigFacet: await (await ethers.getContractFactory("ChainConfigFacet")).deploy(),
};
console.log("Facets deployed");
// Configure CCIP
const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress);
await ccipFacet.setCCIPRouter(ccipRouter);
await ccipFacet.setChainSelector(chainId, chainSelector);
console.log(`CCIP Router configured: ${ccipRouter}`);
// Configure ChainConfig
const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress);
await chainConfigFacet.setChainConfig(
chainId,
"BSC",
ethers.ZeroAddress,
"https://bscscan.com",
BigInt(3000000),
BigInt(300)
);
await chainConfigFacet.setChainActive(chainId, true);
const deployment = {
diamond: diamondAddress,
facets: Object.fromEntries(
Object.entries(facets).map(([name, contract]) => [name, await contract.getAddress()])
),
chainId: chainId,
chainName: "BSC",
ccipRouter,
chainSelector: chainSelector.toString(),
};
console.log(`✓ BSC deployment complete`);
console.log(JSON.stringify(deployment, null, 2));
// Write to file
fs.writeFileSync(
`deployments-bsc-${chainId}.json`,
JSON.stringify(deployment, null, 2)
);
} catch (error) {
console.error(`✗ Failed to deploy to BSC:`, error);
throw error;
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

View File

@@ -0,0 +1,145 @@
import { ethers } from "hardhat";
import { Contract } from "ethers";
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying with account:", deployer.address);
// Chain configurations
const chains = [
{ name: "Ethereum", chainId: 1, rpcUrl: process.env.ETHEREUM_RPC_URL },
{ name: "Polygon", chainId: 137, rpcUrl: process.env.POLYGON_RPC_URL },
{ name: "Arbitrum", chainId: 42161, rpcUrl: process.env.ARBITRUM_RPC_URL },
{ name: "Optimism", chainId: 10, rpcUrl: process.env.OPTIMISM_RPC_URL },
{ name: "BSC", chainId: 56, rpcUrl: process.env.BSC_RPC_URL },
{ name: "Avalanche", chainId: 43114, rpcUrl: process.env.AVALANCHE_RPC_URL },
{ name: "Base", chainId: 8453, rpcUrl: process.env.BASE_RPC_URL },
];
// CCIP Router addresses (mainnet)
const ccipRouters: { [key: number]: string } = {
1: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Ethereum
137: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Polygon
42161: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Arbitrum
10: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Optimism
56: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // BSC
43114: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Avalanche
8453: "0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D", // Base
};
// Chain selectors for CCIP
const chainSelectors: { [key: number]: bigint } = {
1: BigInt('5009297550715157269'), // Ethereum Mainnet
137: BigInt('4051577828743386545'), // Polygon
42161: BigInt('4949039107694359620'), // Arbitrum
10: BigInt('3734403246176062136'), // Optimism
56: BigInt('11344663589394136015'), // BSC
43114: BigInt('6433500567565415381'), // Avalanche
8453: BigInt('15971525489660198786'), // Base
};
const deployments: { [key: number]: any } = {};
for (const chain of chains) {
if (!chain.rpcUrl) {
console.log(`Skipping ${chain.name} - no RPC URL configured`);
continue;
}
console.log(`\n=== Deploying to ${chain.name} (Chain ID: ${chain.chainId}) ===`);
try {
// Deploy Diamond
const Diamond = await ethers.getContractFactory("Diamond");
const diamond = await Diamond.deploy();
await diamond.waitForDeployment();
const diamondAddress = await diamond.getAddress();
console.log(`Diamond deployed to: ${diamondAddress}`);
// Deploy Facets
const facets = {
DiamondCutFacet: await (await ethers.getContractFactory("DiamondCutFacet")).deploy(),
LiquidityFacet: await (await ethers.getContractFactory("LiquidityFacet")).deploy(),
VaultFacet: await (await ethers.getContractFactory("VaultFacet")).deploy(),
ComplianceFacet: await (await ethers.getContractFactory("ComplianceFacet")).deploy(),
CCIPFacet: await (await ethers.getContractFactory("CCIPFacet")).deploy(),
GovernanceFacet: await (await ethers.getContractFactory("GovernanceFacet")).deploy(),
SecurityFacet: await (await ethers.getContractFactory("SecurityFacet")).deploy(),
};
console.log("Facets deployed");
// Configure CCIP
const ccipRouter = ccipRouters[chain.chainId];
if (ccipRouter) {
const ccipFacet = await ethers.getContractAt("CCIPFacet", diamondAddress);
await ccipFacet.setCCIPRouter(ccipRouter);
console.log(`CCIP Router configured: ${ccipRouter}`);
// Set chain selector
const selector = chainSelectors[chain.chainId];
if (selector) {
await ccipFacet.setChainSelector(chain.chainId, selector);
console.log(`Chain selector set: ${selector}`);
}
// Set supported chains
const supportedChains = chains.map(c => c.chainId);
for (const supportedChainId of supportedChains) {
if (supportedChainId !== chain.chainId) {
await ccipFacet.setSupportedChain(supportedChainId, true);
}
}
}
// Configure ChainConfigFacet if deployed
try {
const chainConfigFacet = await ethers.getContractAt("ChainConfigFacet", diamondAddress);
await chainConfigFacet.setChainConfig(
chain.chainId,
chain.name,
ethers.ZeroAddress, // Native token
`https://${chain.name.toLowerCase()}.explorer.com`, // Explorer URL
BigInt(3000000), // Gas limit
BigInt(300) // Message timeout
);
await chainConfigFacet.setChainActive(chain.chainId, true);
console.log(`Chain config set for ${chain.name}`);
} catch (error) {
console.log(`ChainConfigFacet not available, skipping...`);
}
deployments[chain.chainId] = {
diamond: diamondAddress,
facets: Object.fromEntries(
Object.entries(facets).map(([name, contract]) => [name, contract.target])
),
chainId: chain.chainId,
chainName: chain.name,
};
console.log(`${chain.name} deployment complete`);
} catch (error) {
console.error(`✗ Failed to deploy to ${chain.name}:`, error);
}
}
// Save deployment addresses
console.log("\n=== Deployment Summary ===");
console.log(JSON.stringify(deployments, null, 2));
// Write to file
const fs = require("fs");
fs.writeFileSync(
"deployments.json",
JSON.stringify(deployments, null, 2)
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

151
scripts/setup-submodules.sh Executable file
View File

@@ -0,0 +1,151 @@
#!/bin/bash
# Script to create GitHub repositories and convert contracts/frontend to submodules
# Usage: GITHUB_TOKEN=<token> ./scripts/setup-submodules.sh [org-name]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check for GitHub token
if [ -z "$GITHUB_TOKEN" ]; then
echo -e "${YELLOW}GITHUB_TOKEN not found in environment.${NC}"
echo "Please provide it:"
echo " export GITHUB_TOKEN=your_token_here"
echo " ./scripts/setup-submodules.sh [org-name]"
exit 1
fi
# Get organization/user name
if [ -z "$1" ]; then
# Try to get from current git remote
ORG=$(git remote get-url origin 2>/dev/null | sed -E 's|.*github.com[:/]([^/]+)/.*|\1|' || echo "")
if [ -z "$ORG" ]; then
echo -e "${RED}Error: Please provide GitHub organization/username${NC}"
echo "Usage: GITHUB_TOKEN=<token> ./scripts/setup-submodules.sh <org-name>"
exit 1
fi
else
ORG="$1"
fi
echo -e "${GREEN}Setting up submodules for organization: ${ORG}${NC}"
# Get repository name from current directory or git remote
REPO_NAME=$(basename $(git rev-parse --show-toplevel))
MAIN_REPO="${ORG}/${REPO_NAME}"
echo -e "${GREEN}Main repository: ${MAIN_REPO}${NC}"
# Function to create GitHub repository
create_repo() {
local repo_name=$1
local description=$2
local is_private=${3:-false}
echo -e "${YELLOW}Creating repository: ${ORG}/${repo_name}${NC}"
response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos \
-d "{
\"name\": \"${repo_name}\",
\"description\": \"${description}\",
\"private\": ${is_private},
\"auto_init\": false
}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 201 ]; then
echo -e "${GREEN}✓ Repository ${repo_name} created successfully${NC}"
return 0
elif [ "$http_code" -eq 422 ]; then
echo -e "${YELLOW}⚠ Repository ${repo_name} may already exist, continuing...${NC}"
return 0
else
echo -e "${RED}✗ Failed to create repository ${repo_name}${NC}"
echo "Response: $body"
return 1
fi
}
# Function to push directory to repository
push_to_repo() {
local dir=$1
local repo_name=$2
echo -e "${YELLOW}Pushing ${dir} to ${ORG}/${repo_name}${NC}"
cd "$dir"
# Initialize git if not already
if [ ! -d ".git" ]; then
git init
git add .
git commit -m "Initial commit"
fi
# Add remote and push
git remote remove origin 2>/dev/null || true
git remote add origin "https://${GITHUB_TOKEN}@github.com/${ORG}/${repo_name}.git"
git branch -M main
git push -u origin main --force
cd ..
echo -e "${GREEN}${dir} pushed to ${ORG}/${repo_name}${NC}"
}
# Step 1: Create repositories
echo -e "\n${GREEN}=== Step 1: Creating GitHub repositories ===${NC}"
create_repo "${REPO_NAME}-contracts" "ASLE Smart Contracts (Foundry)" false
create_repo "${REPO_NAME}-frontend" "ASLE Frontend (Next.js)" false
# Step 2: Push contracts and frontend to their repositories
echo -e "\n${GREEN}=== Step 2: Pushing code to repositories ===${NC}"
# Remove from main repo temporarily
echo -e "${YELLOW}Removing contracts and frontend from main repo...${NC}"
git rm -r --cached contracts frontend 2>/dev/null || true
# Push contracts
if [ -d "contracts" ]; then
push_to_repo "contracts" "${REPO_NAME}-contracts"
fi
# Push frontend
if [ -d "frontend" ]; then
push_to_repo "frontend" "${REPO_NAME}-frontend"
fi
# Step 3: Add as submodules
echo -e "\n${GREEN}=== Step 3: Adding as submodules ===${NC}"
# Remove directories
rm -rf contracts frontend
# Add as submodules
echo -e "${YELLOW}Adding contracts as submodule...${NC}"
git submodule add "https://github.com/${ORG}/${REPO_NAME}-contracts.git" contracts
echo -e "${YELLOW}Adding frontend as submodule...${NC}"
git submodule add "https://github.com/${ORG}/${REPO_NAME}-frontend.git" frontend
# Step 4: Commit changes
echo -e "\n${GREEN}=== Step 4: Committing submodule configuration ===${NC}"
git add .gitmodules contracts frontend
git commit -m "Convert contracts and frontend to git submodules" || echo "No changes to commit"
echo -e "\n${GREEN}✓ Submodules setup complete!${NC}"
echo -e "\nRepository URLs:"
echo -e " Contracts: https://github.com/${ORG}/${REPO_NAME}-contracts"
echo -e " Frontend: https://github.com/${ORG}/${REPO_NAME}-frontend"
echo -e "\nTo clone with submodules:"
echo -e " git clone --recurse-submodules <main-repo-url>"