From 3eddaec42d4c4308b92b13070a40753dda0e6667 Mon Sep 17 00:00:00 2001 From: StackClass Date: Sat, 6 Sep 2025 03:04:54 +0000 Subject: [PATCH] Initial commit from template --- .eslintrc.js | 16 ++++++++++++ .gitignore | 28 ++++++++++++++++++++ Anchor.toml | 9 +++++++ Cargo.toml | 9 +++++++ migrations/deploy.ts | 14 ++++++++++ package.json | 24 +++++++++++++++++ programs/voting-program/Cargo.toml | 12 +++++++++ programs/voting-program/src/lib.rs | 42 ++++++++++++++++++++++++++++++ tests/voting-program.ts | 15 +++++++++++ tsconfig.json | 15 +++++++++++ 10 files changed, 184 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 Anchor.toml create mode 100644 Cargo.toml create mode 100644 migrations/deploy.ts create mode 100644 package.json create mode 100644 programs/voting-program/Cargo.toml create mode 100644 programs/voting-program/src/lib.rs create mode 100644 tests/voting-program.ts create mode 100644 tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..434f862 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + env: { + es2021: true, + node: true, + }, + extends: ["eslint:recommended", "@typescript-eslint/recommended"], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: 12, + sourceType: "module", + }, + plugins: ["@typescript-eslint"], + rules: { + // Add custom rules here + }, +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9226831 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Dependencies +node_modules/ +target/ +dist/ + +# Environment variables +.env +.env.local + +# IDE files +.vscode/ +.idea/ + +# OS files +.DS_Store +Thumbs.db + +# Logs +logs +*.log + +# Coverage +coverage/ +.nyc_output/ + +# Anchor +.anchor/ +test-ledger/ diff --git a/Anchor.toml b/Anchor.toml new file mode 100644 index 0000000..f7f73e1 --- /dev/null +++ b/Anchor.toml @@ -0,0 +1,9 @@ +[provider] +cluster = "devnet" +wallet = "~/.config/solana/id.json" + +[programs.devnet] +voting_program = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS" + +[scripts] +test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..101e0d6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +members = [ + "programs/*", + "tests", +] + +[profile.release] +lto = true +opt-level = 3 diff --git a/migrations/deploy.ts b/migrations/deploy.ts new file mode 100644 index 0000000..541e3df --- /dev/null +++ b/migrations/deploy.ts @@ -0,0 +1,14 @@ +// Migrations are managed by Anchor +// This file can be used for custom deployment scripts + +import * as anchor from "@coral-xyz/anchor"; + +async function main() { + console.log("Running deployment script..."); + // Custom deployment logic can be added here +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..3cb3f07 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "solana-voting", + "version": "0.1.0", + "description": "Solana voting program built with Anchor", + "main": "index.js", + "scripts": { + "test": "anchor test", + "lint": "eslint --ext .ts tests/", + "build": "anchor build", + "deploy": "anchor deploy" + }, + "dependencies": { + "@coral-xyz/anchor": "^0.29.0", + "@solana/web3.js": "^1.87.0" + }, + "devDependencies": { + "@types/mocha": "^10.0.0", + "@types/node": "^20.0.0", + "eslint": "^8.0.0", + "mocha": "^10.0.0", + "ts-mocha": "^10.0.0", + "typescript": "^5.0.0" + } +} diff --git a/programs/voting-program/Cargo.toml b/programs/voting-program/Cargo.toml new file mode 100644 index 0000000..6bcaa88 --- /dev/null +++ b/programs/voting-program/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "voting-program" +version = "0.1.0" +description = "Solana voting program" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] + +[dependencies] +anchor-lang = { version = "0.29.0", features = ["init", "derive"] } +anchor-spl = "0.29.0" diff --git a/programs/voting-program/src/lib.rs b/programs/voting-program/src/lib.rs new file mode 100644 index 0000000..aca13bb --- /dev/null +++ b/programs/voting-program/src/lib.rs @@ -0,0 +1,42 @@ +use anchor_lang::prelude::*; + +declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); + +#[program] +pub mod voting_program { + use super::*; + + pub fn initialize_proposal( + ctx: Context, + title: String, + options: Vec, + ) -> Result<()> { + // Students will implement this function + Ok(()) + } + + pub fn vote(ctx: Context, option_index: u32) -> Result<()> { + // Students will implement this function + Ok(()) + } +} + +#[account] +pub struct Proposal { + // Students will complete this struct +} + +#[derive(Accounts)] +pub struct InitializeProposal<'info> { + // Students will complete this struct +} + +#[derive(Accounts)] +pub struct Vote<'info> { + // Students will complete this struct +} + +#[error_code] +pub enum VotingError { + // Students will define error codes +} diff --git a/tests/voting-program.ts b/tests/voting-program.ts new file mode 100644 index 0000000..a2853cf --- /dev/null +++ b/tests/voting-program.ts @@ -0,0 +1,15 @@ +import * as anchor from "@coral-xyz/anchor"; +import { Program } from "@coral-xyz/anchor"; +import { VotingProgram } from "../target/types/voting_program"; + +describe("voting-program", () => { + // Configure the client to use the local cluster. + const provider = anchor.AnchorProvider.env(); + anchor.setProvider(provider); + + const program = anchor.workspace.VotingProgram as Program; + + it("Is initialized!", async () => { + // Students will write test cases here + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c89cfe7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "types": ["mocha", "chai"], + "typeRoots": ["./node_modules/@types"], + "lib": ["es2020"], + "module": "commonjs", + "target": "es2020", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + } +}