Sol.College

Structure lesson (licence does not allow quoting code)

cross-chain-cp-swap

Cross Chain CP Swap: A cross-chain DEX allows users to easily swap tokens between blockchains like Ethereum and Solana.

Original
SushantChandla/cross-chain-cp-swap
SuperStack fork
Blockchains/cross-chain-cp-swap @ 51c9448
Stars
1
Last push (original)
2024-10-08
Languages
TypeScript, Rust, Shell, CSS, Solidity, JavaScript
Detected stack
AnchorNext.jsweb3.js
Categories
DeFi
Licence
none detected: code not quoted on Sol.College

Architecture

67 source files. By extension: .rs ×31, .ts ×20, .tsx ×15, .sol ×1.

Top-level directorySource files
program44
frontend23

On-chain programs: program/programs/cp-swap

How it works: instructions and accounts

Each instruction handler and the accounts struct it validates, found by reading the Rust source. Links go to the exact line at the pinned commit.

InstructionAccountsSource
Initializenative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:221
AttestTokennative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:222
CompleteNativenative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:223
CompleteWrappednative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:224
TransferWrappednative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:225
TransferNativenative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:226
RegisterChainnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:227
CreateWrappednative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:228
UpgradeContractnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:229
CompleteNativeWithPayloadnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:230
CompleteWrappedWithPayloadnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:231
TransferWrappedWithPayloadnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:232
TransferNativeWithPayloadnative instruction variantprogram/programs/cp-swap/src/token_bridge_program_utils.rs:233
update_amm_configUpdateAmmConfigprogram/programs/cp-swap/src/lib.rs:91
update_pool_statusUpdatePoolStatusprogram/programs/cp-swap/src/lib.rs:102
update_pool_statusUpdatePoolStatusprogram/programs/cp-swap/src/instructions/admin/update_pool_status.rs:15
update_amm_configUpdateAmmConfigprogram/programs/cp-swap/src/instructions/admin/update_config.rs:17

Where the Solana code lives

Source files that import a Solana SDK, ranked by how many Solana APIs they use, with the APIs each one calls. Read them in this order to see how the app talks to the chain.

FileSolana APIs used
program/programs/cp-swap/src/token_bridge_program_utils.rsseeds, AccountInfo, Pubkey, Program, invoke_signed
program/tests/utils/instruction.tsPublicKey, getAssociatedTokenAddressSync, Program, SystemProgram, findProgramAddressSync, ComputeBudgetProgram
frontend/src/client/program.tsPublicKey, getAssociatedTokenAddressSync, Program, ComputeBudgetProgram, SystemProgram, findProgramAddressSync
program/tests/utils/util.tsPublicKey, Keypair, Connection, SystemProgram, mintTo, getAssociatedTokenAddressSync
program/programs/cp-swap/src/utils/token.rsAccountInfo, CpiContext
program/programs/cp-swap/src/instructions/initialize.rsseeds, AccountInfo, Program, init_if_needed, transfer, Pubkey
frontend/src/client/pda.tsPublicKey
program/tests/utils/pda.tsPublicKey
program/tests/utils/wormhole.utils.tsConnection, PublicKey, Keypair, TransactionMessage, VersionedTransaction, signTransaction
frontend/src/context/WalletsContext.tsxProgram, AnchorProvider, Connection, PublicKey, signTransaction
program/programs/cp-swap/src/utils/account_load.rsAccountInfo, Pubkey
program/programs/cp-swap/src/states/pool.rsPubkey

Dapp: devnet deploy pending

⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/cross-chain-cp-swap/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.

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
frontendnpm run dev
frontendnpm run start
frontendnpm run build
frontendnpm run lint
programnpm run test
programnpm run lint
programanchor build
programanchor test
programanchor run test

What you could build from it