Sol.College

Full lesson

cura-contract-sdk

What it does

From the project README:

This is the official client library for interacting with the Cura contract on Solana blockchain using the Anchor framework. The package is designed to help developers easily communicate with the Cura program, manage token rewards, distribute tokens, and burn tokens.
Original
CURA-Lab/cura-contract-sdk
SuperStack fork
Blockchains/cura-contract-sdk @ ff8a3fd
Stars
0
Last push (original)
2024-11-06
Languages
TypeScript, JavaScript
Detected stack
Metaplexweb3.js
Categories
Infrastructure & Tooling
Licence
MIT

Architecture

13 source files. By extension: .ts ×8, .js ×5.

Top-level directorySource files
src6
docs4
test2
(root)1

Dapp: deploying

This fork is queued for its own live dapp on Sol.College, with a Devnet/Mainnet switch. It appears here, at /dapps/cura-contract-sdk/, once it is deployed and checked on devnet. Until then, run it locally with the commands below.

Key code, explained

Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.

CURA-Lab/cura-contract-sdk · src/cura.ts L1–24 @ ff8a3fd · MIT · original
import * as anchor from "@coral-xyz/anchor";import { Keypair, PublicKey, sendAndConfirmTransaction, Transaction, TransactionInstruction, TransactionSignature} from "@solana/web3.js";import {    getAssociatedTokenAddressSync,    getOrCreateAssociatedTokenAccount,    approve,    createTransferCheckedWithTransferHookInstruction,    burnChecked,    ASSOCIATED_TOKEN_PROGRAM_ID,    TOKEN_2022_PROGRAM_ID,    TokenAccountNotFoundError,    TokenInvalidAccountOwnerError,    getAccount} from "@solana/spl-token";import { createMemoInstruction} from "@solana/spl-memo";import { checkTokenAccountAndBalance, getOrCreateAssociatedTokenAccountInstruction, optimizeComputeUnit} from "./utils"import idl from "./IDL/cura.json"; const SUPER_ADMIN = new PublicKey("6T9ajVYoL13jeNp9FCMoU9s4AEBaNFJpHvXptUz1MGag");const CURA_PROGRAME_ID = new PublicKey(idl.address); const metadata = {    name: "Cura Token",    symbol: "CT",
  1. Line 2 import { Keypair, PublicKey, sendAndConfirmTransaction, Transaction, TransactionInstructio: Submits the signed transaction to the cluster.
  2. Line 7 createTransferCheckedWithTransferHookInstruction,: A checked token transfer, which also verifies the mint and decimals.
  3. Line 10 TOKEN_2022_PROGRAM_ID,: Targets the Token-2022 program instead of the original Token Program.
CURA-Lab/cura-contract-sdk · src/utils.ts L1–24 @ ff8a3fd · MIT · original
import { Commitment, Connection, PublicKey,  TransactionInstruction, ComputeBudgetProgram } from '@solana/web3.js';import {  getAccount,  TokenAccountNotFoundError,  TokenInvalidAccountOwnerError,  TOKEN_2022_PROGRAM_ID,  ASSOCIATED_TOKEN_PROGRAM_ID,  getAssociatedTokenAddressSync,  createAssociatedTokenAccountInstruction} from "@solana/spl-token";import { getSimulationComputeUnits } from "@solana-developers/helpers"  /** * Check whether the Token account exists and the Token balance is sufficient * @param connection - Solana cluster connection * @param tokenAccountAddress - Associated Token Account * @param requiredAmount - Required Token amount * @returns - true if the Token account exists and the Token balance is sufficient, otherwise false * @throws - Error if the Token account does not exist or the Token balance is insufficient */export async function checkTokenAccountAndBalance(    connection: Connection,    tokenAccountAddress: PublicKey,
  1. Line 1 import { Commitment, Connection, PublicKey, TransactionInstruction, ComputeBudgetProgram : Sets the compute-unit limit or price (priority fee).
  2. Line 6 TOKEN_2022_PROGRAM_ID,: Targets the Token-2022 program instead of the original Token Program.

How to run, build and test

These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.

DirectoryCommandRuns
.npm run buildtsc

What you could build from it