|
| 1 | +################################################################ |
| 2 | +# Swap on Raydium CLMM (v3) - Concentrated Liquidity |
| 3 | +# |
| 4 | +# This runbook executes a swap on a Raydium CLMM pool. |
| 5 | +# CLMM uses concentrated liquidity similar to Uniswap v3. |
| 6 | +################################################################ |
| 7 | + |
| 8 | +addon "svm" { |
| 9 | + rpc_api_url = input.rpc_api_url |
| 10 | + network_id = input.network_id |
| 11 | +} |
| 12 | + |
| 13 | +signer "user" "svm::secret_key" { |
| 14 | + description = "The account executing the swap" |
| 15 | + keypair_json = "~/.config/solana/id.json" |
| 16 | +} |
| 17 | + |
| 18 | +variable "program" { |
| 19 | + description = "The raydium_arbitrage program" |
| 20 | + value = svm::get_program_from_anchor_project("raydium_arbitrage") |
| 21 | +} |
| 22 | + |
| 23 | +# Token configuration |
| 24 | +variable "input_mint" { |
| 25 | + description = "Input token mint address" |
| 26 | + editable = true |
| 27 | +} |
| 28 | + |
| 29 | +variable "output_mint" { |
| 30 | + description = "Output token mint address" |
| 31 | + editable = true |
| 32 | +} |
| 33 | + |
| 34 | +# CLMM Pool configuration |
| 35 | +variable "pool_state" { |
| 36 | + description = "CLMM pool state account" |
| 37 | + editable = true |
| 38 | +} |
| 39 | + |
| 40 | +variable "amm_config" { |
| 41 | + description = "CLMM AMM config account" |
| 42 | + editable = true |
| 43 | +} |
| 44 | + |
| 45 | +variable "input_vault" { |
| 46 | + description = "CLMM input token vault" |
| 47 | + editable = true |
| 48 | +} |
| 49 | + |
| 50 | +variable "output_vault" { |
| 51 | + description = "CLMM output token vault" |
| 52 | + editable = true |
| 53 | +} |
| 54 | + |
| 55 | +variable "observation_state" { |
| 56 | + description = "CLMM oracle observation state" |
| 57 | + editable = true |
| 58 | +} |
| 59 | + |
| 60 | +# Swap parameters |
| 61 | +variable "amount" { |
| 62 | + description = "Amount to swap (in smallest units)" |
| 63 | + value = 1000000000 |
| 64 | + editable = true |
| 65 | +} |
| 66 | + |
| 67 | +variable "other_amount_threshold" { |
| 68 | + description = "Minimum output or maximum input (depending on is_base_input)" |
| 69 | + value = 0 |
| 70 | + editable = true |
| 71 | +} |
| 72 | + |
| 73 | +variable "sqrt_price_limit_x64" { |
| 74 | + description = "Price limit for the swap (0 for no limit)" |
| 75 | + value = 0 |
| 76 | + editable = true |
| 77 | +} |
| 78 | + |
| 79 | +variable "is_base_input" { |
| 80 | + description = "True for exact input swap, false for exact output" |
| 81 | + value = true |
| 82 | + editable = true |
| 83 | +} |
| 84 | + |
| 85 | +# Programs |
| 86 | +variable "token_program" { |
| 87 | + value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" |
| 88 | +} |
| 89 | + |
| 90 | +variable "token_program_2022" { |
| 91 | + value = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" |
| 92 | +} |
| 93 | + |
| 94 | +variable "memo_program" { |
| 95 | + value = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" |
| 96 | +} |
| 97 | + |
| 98 | +variable "clmm_program" { |
| 99 | + value = "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK" |
| 100 | +} |
| 101 | + |
| 102 | +action "swap_clmm" "svm::process_instructions" { |
| 103 | + description = "Execute CLMM swap" |
| 104 | + signers = [signer.user] |
| 105 | + |
| 106 | + instruction { |
| 107 | + program_idl = variable.program.idl |
| 108 | + instruction_name = "swap_clmm" |
| 109 | + instruction_args = [ |
| 110 | + variable.amount, |
| 111 | + variable.other_amount_threshold, |
| 112 | + variable.sqrt_price_limit_x64, |
| 113 | + variable.is_base_input |
| 114 | + ] |
| 115 | + |
| 116 | + payer { |
| 117 | + public_key = signer.user.public_key |
| 118 | + } |
| 119 | + amm_config { |
| 120 | + public_key = variable.amm_config |
| 121 | + } |
| 122 | + pool_state { |
| 123 | + public_key = variable.pool_state |
| 124 | + } |
| 125 | + input_token_account { |
| 126 | + public_key = svm::get_associated_token_address(signer.user.public_key, variable.input_mint) |
| 127 | + } |
| 128 | + output_token_account { |
| 129 | + public_key = svm::get_associated_token_address(signer.user.public_key, variable.output_mint) |
| 130 | + } |
| 131 | + input_vault { |
| 132 | + public_key = variable.input_vault |
| 133 | + } |
| 134 | + output_vault { |
| 135 | + public_key = variable.output_vault |
| 136 | + } |
| 137 | + observation_state { |
| 138 | + public_key = variable.observation_state |
| 139 | + } |
| 140 | + token_program { |
| 141 | + public_key = variable.token_program |
| 142 | + } |
| 143 | + token_program_2022 { |
| 144 | + public_key = variable.token_program_2022 |
| 145 | + } |
| 146 | + memo_program { |
| 147 | + public_key = variable.memo_program |
| 148 | + } |
| 149 | + input_vault_mint { |
| 150 | + public_key = variable.input_mint |
| 151 | + } |
| 152 | + output_vault_mint { |
| 153 | + public_key = variable.output_mint |
| 154 | + } |
| 155 | + clmm_program { |
| 156 | + public_key = variable.clmm_program |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +output "signature" { |
| 162 | + value = action.swap_clmm.signature |
| 163 | +} |
0 commit comments