Initial commit from template

This commit is contained in:
StackClass
2025-12-29 11:40:44 +00:00
commit fc3913834d
9 changed files with 146 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
node_modules
dist
build
target
.env
.DS_Store
*.log

9
Anchor.toml Normal file
View File

@@ -0,0 +1,9 @@
[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"
[programs.localnet]
swap = "11111111111111111111111111111111"
[scripts]
test = "cargo test -- --nocapture"

21
Cargo.toml Normal file
View File

@@ -0,0 +1,21 @@
[workspace]
members = [
"programs/*"
]
resolver = "2"
[package]
name = "stackclass-solana-swap-program"
version = "0.1.0"
authors = ["StackClass <hello@stackclass.dev>"]
edition = "2021"
[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1

5
migrations/deploy.ts Normal file
View File

@@ -0,0 +1,5 @@
use anchor_lang::prelude::*;
pub fn deploy() -> Result<()> {
Ok(())
}

19
package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "solana-swap",
"version": "0.1.0",
"description": "Solana swap program built with Anchor",
"main": "index.js",
"scripts": {
"test": "cargo test -- --nocapture",
"build": "anchor build",
"deploy": "anchor deploy"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.0",
"@solana/web3.js": "^1.91.0",
"@solana/spl-token": "^0.4.0"
},
"devDependencies": {
"@types/node": "^20.0.0"
}
}

12
programs/swap/Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "swap"
version = "0.1.0"
description = "Solana swap program"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
anchor-lang = "0.30.1"
anchor-spl = "0.30.1"

42
programs/swap/src/lib.rs Normal file
View File

@@ -0,0 +1,42 @@
use anchor_lang::prelude::*;
declare_id!("11111111111111111111111111111111");
#[program]
pub mod swap {
use super::*;
pub fn make_offer(
ctx: Context<MakeOffer>,
id: u64,
token_a_offered_amount: u64,
token_b_wanted_amount: u64,
) -> Result<()> {
// Students will implement this function
Ok(())
}
pub fn take_offer(ctx: Context<TakeOffer>) -> Result<()> {
// Students will implement this function
Ok(())
}
}
#[derive(Accounts)]
#[instruction(id: u64)]
pub struct MakeOffer<'info> {
pub maker: Signer<'info>,
}
#[derive(Accounts)]
pub struct TakeOffer<'info> {
pub taker: Signer<'info>,
}
#[cfg(test)]
mod tests {
#[test]
fn test_sample() {
assert_eq!(2 + 2, 4);
}
}

15
tests/swap.ts Normal file
View File

@@ -0,0 +1,15 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Swap } from "../target/types/swap";
describe("swap", async () => {
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.Swap as Program<Swap>;
it("Is initialized!", async () => {
const tx = await program.methods.initialize().rpc();
console.log("Transaction signature:", tx);
});
});

16
tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"types": ["mocha"],
"lib": ["es2020"],
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"rootDir": "."
},
"include": ["tests/**/*", "migrations/**/*"]
}