Sol.College

Structure lesson (licence does not allow quoting code)

bestlend

always get the best rates on your debt and collateral

Original
SC4RECOIN/bestlend
SuperStack fork
Blockchains/bestlend @ 2b16332
Stars
1
Last push (original)
2024-06-02
Languages
Rust, TypeScript, JavaScript, Dockerfile
Detected stack
AnchorMetaplexNext.jsweb3.js
Categories
DeFi
Licence
none detected: code not quoted on Sol.College
Homepage
https://bestlend.vercel.app/

Architecture

327 source files. By extension: .ts ×184, .rs ×127, .tsx ×11, .js ×5.

Top-level directorySource files
clients165
programs127
app21
api8
tests4
migrations1
cli1

On-chain programs: programs/bestlend, programs/dummy-swap, programs/klend, programs/marginfi, programs/mock-pyth

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
update_lending_market_ownerUpdateLendingMarketOwnerprograms/klend/src/lib.rs:38
init_reserveInitReserveprograms/klend/src/lib.rs:42
init_farms_for_reserveInitFarmsForReserveprograms/klend/src/lib.rs:46
refresh_reserveRefreshReserveprograms/klend/src/lib.rs:66
init_obligationInitObligationprograms/klend/src/lib.rs:86
refresh_obligationRefreshObligationprograms/klend/src/lib.rs:106
redeem_feesRedeemFeesprograms/klend/src/lib.rs:176
socialize_lossSocializeLossprograms/klend/src/lib.rs:201
withdraw_referrer_feesWithdrawReferrerFeesprograms/klend/src/lib.rs:228
withdraw_protocol_feeWithdrawProtocolFeesprograms/klend/src/lib.rs:232
processInitReferrerStateAndShortUrlprograms/klend/src/handlers/handler_init_referrer_state_and_short_url.rs:11
processWithdrawObligationCollateralprograms/klend/src/handlers/handler_withdraw_obligation_collateral.rs:16
processDepositObligationCollateralprograms/klend/src/handlers/handler_deposit_obligation_collateral.rs:16
processSocializeLossprograms/klend/src/handlers/handler_socialize_loss.rs:14
processInitUserMetadataprograms/klend/src/handlers/handler_init_user_metadata.rs:8
processFlashBorrowReserveLiquidityprograms/klend/src/handlers/handler_flash_borrow_reserve_liquidity.rs:12
processUpdateLendingMarketOwnerprograms/klend/src/handlers/handler_update_lending_market_owner.rs:5
processRedeemFeesprograms/klend/src/handlers/handler_redeem_fees.rs:11
processRepayObligationLiquidityprograms/klend/src/handlers/handler_repay_obligation_liquidity.rs:16
processWithdrawProtocolFeesprograms/klend/src/handlers/handler_withdraw_protocol_fees.rs:10
processInitLendingMarketprograms/klend/src/handlers/handler_init_lending_market.rs:8
processInitObligationprograms/klend/src/handlers/handler_init_obligation.rs:13
processInitObligationFarmsForReserveprograms/klend/src/handlers/handler_init_obligation_farms_for_reserve.rs:12
processUpdateUserMetadataOwnerprograms/klend/src/handlers/handler_update_user_metadata_owner.rs:6
processUpdateReserveConfigprograms/klend/src/handlers/handler_update_reserve_config.rs:8
processRedeemReserveCollateralprograms/klend/src/handlers/handler_redeem_reserve_collateral.rs:11
processInitReserveprograms/klend/src/handlers/handler_init_reserve.rs:16
processWithdrawReferrerFeesprograms/klend/src/handlers/handler_withdraw_referrer_fees.rs:15
processInitReferrerTokenStateprograms/klend/src/handlers/handler_init_referrer_token_state.rs:8
processRequestElevationGroupprograms/klend/src/handlers/handler_request_elevation_group.rs:8

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
tests/bestlend.tsPublicKey, findProgramAddressSync, Transaction, sendAndConfirmTransaction, Keypair, Program
api/src/tx.tsPublicKey, findProgramAddressSync, TransactionMessage, VersionedTransaction, getAssociatedTokenAddressSync, getLatestBlockhash
cli/actions.tsPublicKey, findProgramAddressSync, Transaction, sendTransaction, SystemProgram, mintTo
programs/klend/src/utils/token_transfer.rsAccountInfo, CpiContext, transfer
api/src/swap.tsPublicKey, findProgramAddressSync, ComputeBudgetProgram, Keypair, Connection, TransactionMessage
tests/accounts.tsPublicKey, findProgramAddressSync, Program, Keypair, Connection
programs/marginfi/src/state/marginfi_group.rsPubkey, AccountInfo, transfer, CpiContext
programs/marginfi/src/events.rsPubkey
programs/klend/src/state/obligation.rsPubkey
programs/bestlend/src/instructions/handle_init_account.rsProgram, AccountInfo, seeds, invoke_signed, CpiContext, Pubkey
app/src/requests/backend.tsPublicKey, VersionedTransaction
programs/klend/src/utils/seeds.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/bestlend/. 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
.npm run lint
appnpm run dev
appnpm run start
appnpm run build
appnpm run lint
apinpm run dev
apinpm run start
apinpm run build
apinpm run deploy
.anchor build
.anchor test
.anchor run test
.cargo build
.cargo test

What you could build from it