mirror of
https://github.com/arkorty/B.Tech-Project-III.git
synced 2026-04-19 12:41:48 +00:00
init
This commit is contained in:
59
dmtp/server/scripts/deploy.js
Normal file
59
dmtp/server/scripts/deploy.js
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const hardhat_1 = require("hardhat");
|
||||
async function main() {
|
||||
console.log("🚀 Starting deployment to Celo Sepolia...\n");
|
||||
// Get deployer account
|
||||
const [deployer] = await hardhat_1.ethers.getSigners();
|
||||
console.log("📝 Deploying contracts with account:", deployer.address);
|
||||
// Get account balance
|
||||
const balance = await hardhat_1.ethers.provider.getBalance(deployer.address);
|
||||
console.log("💰 Account balance:", hardhat_1.ethers.formatEther(balance), "CELO\n");
|
||||
// cUSD token address on Sepolia testnet
|
||||
const CUSD_SEPOLIA = "0x874069fa1eb16d44d622f2e0ca25eea172369bc1";
|
||||
console.log("📄 cUSD Token Address:", CUSD_SEPOLIA);
|
||||
// Deploy TaskEscrow contract
|
||||
console.log("\n⏳ Deploying TaskEscrow contract...");
|
||||
const TaskEscrow = await hardhat_1.ethers.getContractFactory("TaskEscrow");
|
||||
const taskEscrow = await TaskEscrow.deploy(CUSD_SEPOLIA);
|
||||
await taskEscrow.waitForDeployment();
|
||||
const taskEscrowAddress = await taskEscrow.getAddress();
|
||||
console.log("✅ TaskEscrow deployed to:", taskEscrowAddress);
|
||||
// Verify contract details
|
||||
console.log("\n📋 Contract Details:");
|
||||
console.log("-----------------------------------");
|
||||
console.log("Network: Celo Sepolia");
|
||||
console.log("Contract: TaskEscrow");
|
||||
console.log("Address:", taskEscrowAddress);
|
||||
console.log("Owner:", deployer.address);
|
||||
console.log("cUSD Token:", CUSD_SEPOLIA);
|
||||
console.log("Platform Fee: 5%");
|
||||
console.log("-----------------------------------\n");
|
||||
// Save deployment info
|
||||
const deploymentInfo = {
|
||||
network: "sepolia",
|
||||
contractName: "TaskEscrow",
|
||||
contractAddress: taskEscrowAddress,
|
||||
deployer: deployer.address,
|
||||
cUSDAddress: CUSD_SEPOLIA,
|
||||
deployedAt: new Date().toISOString(),
|
||||
blockNumber: await hardhat_1.ethers.provider.getBlockNumber(),
|
||||
};
|
||||
console.log("💾 Deployment Info:");
|
||||
console.log(JSON.stringify(deploymentInfo, null, 2));
|
||||
console.log("\n🔍 Verify contract on Celoscan:");
|
||||
console.log(`npx hardhat verify --network sepolia ${taskEscrowAddress} ${CUSD_SEPOLIA}`);
|
||||
console.log("\n✨ Deployment completed successfully!\n");
|
||||
// Return addresses for use in scripts
|
||||
return {
|
||||
taskEscrowAddress,
|
||||
cUSDAddress: CUSD_SEPOLIA,
|
||||
};
|
||||
}
|
||||
// Execute deployment
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("❌ Deployment failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
72
dmtp/server/scripts/deploy.ts
Normal file
72
dmtp/server/scripts/deploy.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
console.log("🚀 Starting deployment to Celo Sepolia...\n");
|
||||
|
||||
// Get deployer account
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log("📝 Deploying contracts with account:", deployer.address);
|
||||
|
||||
// Get account balance
|
||||
const balance = await ethers.provider.getBalance(deployer.address);
|
||||
console.log("💰 Account balance:", ethers.formatEther(balance), "CELO\n");
|
||||
|
||||
// cUSD token address on Sepolia testnet
|
||||
const CUSD_SEPOLIA = "0x874069fa1eb16d44d622f2e0ca25eea172369bc1";
|
||||
|
||||
console.log("📄 cUSD Token Address:", CUSD_SEPOLIA);
|
||||
|
||||
// Deploy TaskEscrow contract
|
||||
console.log("\n⏳ Deploying TaskEscrow contract...");
|
||||
const TaskEscrow = await ethers.getContractFactory("TaskEscrow");
|
||||
const taskEscrow = await TaskEscrow.deploy(CUSD_SEPOLIA);
|
||||
|
||||
await taskEscrow.waitForDeployment();
|
||||
const taskEscrowAddress = await taskEscrow.getAddress();
|
||||
|
||||
console.log("✅ TaskEscrow deployed to:", taskEscrowAddress);
|
||||
|
||||
// Verify contract details
|
||||
console.log("\n📋 Contract Details:");
|
||||
console.log("-----------------------------------");
|
||||
console.log("Network: Celo Sepolia");
|
||||
console.log("Contract: TaskEscrow");
|
||||
console.log("Address:", taskEscrowAddress);
|
||||
console.log("Owner:", deployer.address);
|
||||
console.log("cUSD Token:", CUSD_SEPOLIA);
|
||||
console.log("Platform Fee: 5%");
|
||||
console.log("-----------------------------------\n");
|
||||
|
||||
// Save deployment info
|
||||
const deploymentInfo = {
|
||||
network: "sepolia",
|
||||
contractName: "TaskEscrow",
|
||||
contractAddress: taskEscrowAddress,
|
||||
deployer: deployer.address,
|
||||
cUSDAddress: CUSD_SEPOLIA,
|
||||
deployedAt: new Date().toISOString(),
|
||||
blockNumber: await ethers.provider.getBlockNumber(),
|
||||
};
|
||||
|
||||
console.log("💾 Deployment Info:");
|
||||
console.log(JSON.stringify(deploymentInfo, null, 2));
|
||||
|
||||
console.log("\n🔍 Verify contract on Celoscan:");
|
||||
console.log(`npx hardhat verify --network sepolia ${taskEscrowAddress} ${CUSD_SEPOLIA}`);
|
||||
|
||||
console.log("\n✨ Deployment completed successfully!\n");
|
||||
|
||||
// Return addresses for use in scripts
|
||||
return {
|
||||
taskEscrowAddress,
|
||||
cUSDAddress: CUSD_SEPOLIA,
|
||||
};
|
||||
}
|
||||
|
||||
// Execute deployment
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("❌ Deployment failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
72
dmtp/server/scripts/interact.js
Normal file
72
dmtp/server/scripts/interact.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const hardhat_1 = require("hardhat");
|
||||
async function main() {
|
||||
console.log("🔧 Interacting with TaskEscrow contract...\n");
|
||||
// Replace with your deployed contract address
|
||||
const TASK_ESCROW_ADDRESS = "YOUR_DEPLOYED_CONTRACT_ADDRESS";
|
||||
const CUSD_ADDRESS = "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1";
|
||||
const [deployer, worker] = await hardhat_1.ethers.getSigners();
|
||||
// Get contract instances
|
||||
const TaskEscrow = await hardhat_1.ethers.getContractAt("TaskEscrow", TASK_ESCROW_ADDRESS);
|
||||
const cUSD = await hardhat_1.ethers.getContractAt("IERC20", CUSD_ADDRESS);
|
||||
console.log("📝 Contract Address:", TASK_ESCROW_ADDRESS);
|
||||
console.log("👤 Deployer:", deployer.address);
|
||||
console.log("👷 Worker:", worker.address, "\n");
|
||||
// Check cUSD balance
|
||||
const balance = await cUSD.balanceOf(deployer.address);
|
||||
console.log("💰 Deployer cUSD Balance:", hardhat_1.ethers.formatEther(balance), "\n");
|
||||
// Example: Create a task
|
||||
console.log("📝 Creating a task...");
|
||||
const paymentAmount = hardhat_1.ethers.parseEther("5"); // 5 cUSD
|
||||
const durationInDays = 7;
|
||||
// Approve TaskEscrow to spend cUSD
|
||||
console.log("✅ Approving cUSD spending...");
|
||||
const approveTx = await cUSD.approve(TASK_ESCROW_ADDRESS, paymentAmount);
|
||||
await approveTx.wait();
|
||||
console.log("✅ Approved!\n");
|
||||
// Create task
|
||||
const createTx = await TaskEscrow.createTask(paymentAmount, durationInDays);
|
||||
const receipt = await createTx.wait();
|
||||
// Get taskId from event
|
||||
const event = receipt?.logs.find((log) => {
|
||||
try {
|
||||
return TaskEscrow.interface.parseLog(log)?.name === "TaskCreated";
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
const parsedEvent = TaskEscrow.interface.parseLog(event);
|
||||
const taskId = parsedEvent?.args[0];
|
||||
console.log("✅ Task created! Task ID:", taskId.toString(), "\n");
|
||||
// Get task details
|
||||
const task = await TaskEscrow.getTask(taskId);
|
||||
console.log("📋 Task Details:");
|
||||
console.log("-----------------------------------");
|
||||
console.log("Task ID:", task.taskId.toString());
|
||||
console.log("Requester:", task.requester);
|
||||
console.log("Payment Amount:", hardhat_1.ethers.formatEther(task.paymentAmount), "cUSD");
|
||||
console.log("Status:", task.status);
|
||||
console.log("-----------------------------------\n");
|
||||
// Assign worker
|
||||
console.log("👷 Assigning worker...");
|
||||
const assignTx = await TaskEscrow.assignWorker(taskId, worker.address);
|
||||
await assignTx.wait();
|
||||
console.log("✅ Worker assigned!\n");
|
||||
// Approve submission (as owner)
|
||||
console.log("✅ Approving submission...");
|
||||
const approveTx2 = await TaskEscrow.approveSubmission(taskId);
|
||||
await approveTx2.wait();
|
||||
console.log("✅ Submission approved! Payment released.\n");
|
||||
// Check worker balance
|
||||
const workerBalance = await cUSD.balanceOf(worker.address);
|
||||
console.log("💰 Worker cUSD Balance:", hardhat_1.ethers.formatEther(workerBalance), "\n");
|
||||
console.log("✨ Interaction completed!");
|
||||
}
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("❌ Error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
87
dmtp/server/scripts/interact.ts
Normal file
87
dmtp/server/scripts/interact.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
console.log("🔧 Interacting with TaskEscrow contract...\n");
|
||||
|
||||
// Replace with your deployed contract address
|
||||
const TASK_ESCROW_ADDRESS = "YOUR_DEPLOYED_CONTRACT_ADDRESS";
|
||||
const CUSD_ADDRESS = "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1";
|
||||
|
||||
const [deployer, worker] = await ethers.getSigners();
|
||||
|
||||
// Get contract instances
|
||||
const TaskEscrow = await ethers.getContractAt("TaskEscrow", TASK_ESCROW_ADDRESS);
|
||||
const cUSD = await ethers.getContractAt("IERC20", CUSD_ADDRESS);
|
||||
|
||||
console.log("📝 Contract Address:", TASK_ESCROW_ADDRESS);
|
||||
console.log("👤 Deployer:", deployer.address);
|
||||
console.log("👷 Worker:", worker.address, "\n");
|
||||
|
||||
// Check cUSD balance
|
||||
const balance = await cUSD.balanceOf(deployer.address);
|
||||
console.log("💰 Deployer cUSD Balance:", ethers.formatEther(balance), "\n");
|
||||
|
||||
// Example: Create a task
|
||||
console.log("📝 Creating a task...");
|
||||
const paymentAmount = ethers.parseEther("5"); // 5 cUSD
|
||||
const durationInDays = 7;
|
||||
|
||||
// Approve TaskEscrow to spend cUSD
|
||||
console.log("✅ Approving cUSD spending...");
|
||||
const approveTx = await cUSD.approve(TASK_ESCROW_ADDRESS, paymentAmount);
|
||||
await approveTx.wait();
|
||||
console.log("✅ Approved!\n");
|
||||
|
||||
// Create task
|
||||
const createTx = await TaskEscrow.createTask(paymentAmount, durationInDays);
|
||||
const receipt = await createTx.wait();
|
||||
|
||||
// Get taskId from event
|
||||
const event = receipt?.logs.find((log: any) => {
|
||||
try {
|
||||
return TaskEscrow.interface.parseLog(log)?.name === "TaskCreated";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
const parsedEvent = TaskEscrow.interface.parseLog(event as any);
|
||||
const taskId = parsedEvent?.args[0];
|
||||
|
||||
console.log("✅ Task created! Task ID:", taskId.toString(), "\n");
|
||||
|
||||
// Get task details
|
||||
const task = await TaskEscrow.getTask(taskId);
|
||||
console.log("📋 Task Details:");
|
||||
console.log("-----------------------------------");
|
||||
console.log("Task ID:", task.taskId.toString());
|
||||
console.log("Requester:", task.requester);
|
||||
console.log("Payment Amount:", ethers.formatEther(task.paymentAmount), "cUSD");
|
||||
console.log("Status:", task.status);
|
||||
console.log("-----------------------------------\n");
|
||||
|
||||
// Assign worker
|
||||
console.log("👷 Assigning worker...");
|
||||
const assignTx = await TaskEscrow.assignWorker(taskId, worker.address);
|
||||
await assignTx.wait();
|
||||
console.log("✅ Worker assigned!\n");
|
||||
|
||||
// Approve submission (as owner)
|
||||
console.log("✅ Approving submission...");
|
||||
const approveTx2 = await TaskEscrow.approveSubmission(taskId);
|
||||
await approveTx2.wait();
|
||||
console.log("✅ Submission approved! Payment released.\n");
|
||||
|
||||
// Check worker balance
|
||||
const workerBalance = await cUSD.balanceOf(worker.address);
|
||||
console.log("💰 Worker cUSD Balance:", ethers.formatEther(workerBalance), "\n");
|
||||
|
||||
console.log("✨ Interaction completed!");
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("❌ Error:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user