Deploy Liquidity Provision Contract that integrates with Solana Swap

Liquidity Provision Contract integrates with X-Talk Swap Contract to provide liquidity for Solana swaps. Liquidity provision contracts are one of the examples of the use case of Solana-EVM Swaps.

Step 1: Pre-Requisites

Ensure Pre-Requisites for Solana and L1X are installed.

Step 2: Set up Solana Project

Open a new terminal to create Solana project

Step 1: Initialize a New Project

  1. Create a New Directory

mkdir solana-stake-project
cd solana-stake-project
  1. Initialize a New Anchor Project

anchor init stake

Step 2: Write your Solana smart contract

In this, below listed smart contracts are to be created at /programs/stake/src/

  1. lib.rs

  2. account_structs.rs

  3. error.rs

  4. events.rs

  5. instructions.rs

  6. state.rs

  7. utils.rs

Paste your contract code at /programs/stake/src/lib.rs

Update declare_id! with YOUR_SOLANA_PROGRAM_ID

  1. Paste your contract code at /programs/stake/src/account_structs.rs

  1. Paste your contract code at /programs/stake/src/error.rs

  1. Paste your contract code at /programs/stake/src/events.rs

  1. Paste your contract code at /programs/stake/src/instructions.rs

  1. Paste your contract code at /programs/stake/src/state.rs

  1. Paste your contract code at /programs/stake/src/utils.rs

Step 3: Update Cargo.toml

Ensure that you update at programs/stake/Cargo.toml

Step 4: Install Dependencies

Step 5: Compile the Smart Contract

Step 6: Display the list of Key Pairs

Output is YOUR_SOLANA_PROGRAM_ID. Save it as it is used later at various instances.

Step 7: Declare PROGRAM_ID

Goto program/stake/src/lib.rs and update declare_id! with YOUR_SOLANA_PROGRAM_ID.

Below is the snapshot for your reference

Step 8: Configure Scripts

Create scripts folder and add below scripts to it.

  1. Script to Initiate Contract

  • Ensure that the connection is set to devnet

  • Add YOUR_SOLANA_PROGRAM_ID as programId

  • Add YOUR_TREASURY_CONTRACT_ADDRESS

  • Load the wallet keypair path (for the file id.json) as YOUR_KEYPAIR_PATH

  • Load idlString with the relative path to stake.json as ./target/idl/stake.json as YOUR_IDL_PATH

  1. Configure Anchor.toml

  • Update stake with YOUR_SOLANA_PROGRAM_ID

  • Update wallet with YOUR_KEYPAIR_PATH

  • Set path for initialize.ts script

Step 9: Compile, Deploy and Run Solana Program

  1. Compile the Solana Program

  1. Deploy the Solana Program

  1. Run the Solana Program

Output contains YOUR_SOLANA_DERIVED_STATE_ACCOUNT and YOUR_SOLANA_TRANSACTION_HASH.

Last updated