raydium-launchlab-sdk 0.1.1

Rust SDK for Raydium LaunchLab program
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
use anyhow::Result;
use raydium_launchlab::{
    accounts::PoolState,
    instructions,
    pda,
    TOKEN_PROGRAM_ID, SYSTEM_PROGRAM_ID, PROGRAM_ID,
};
use solana_client::rpc_client::RpcClient;
use solana_sdk::{
    commitment_config::CommitmentConfig,
    pubkey::Pubkey,
    signature::{Keypair, Signer},
    transaction::Transaction,
    instruction::{Instruction, AccountMeta},
    system_instruction,
    system_program,
};
use raydium_launchlab::accounts::GlobalConfig;
use spl_associated_token_account::{
    get_associated_token_address,
    instruction::create_associated_token_account_idempotent,
};
use spl_token::instruction as token_instruction;
use std::str::FromStr;
use borsh::BorshSerialize;

const WSOL_MINT: &str = "So11111111111111111111111111111111111111112";
const USD1_MINT: &str = "USD1ttGY1N17NEEHLmELoaybftRBUSErhqYiQzvEmuB";

// Fee rates in basis points (100 = 1%)
const PROTOCOL_FEE_RATE: u128 = 100; // 1%
const PLATFORM_FEE_RATE: u128 = 0;   // Platform-specific, varies
const SHARE_FEE_RATE: u128 = 0;      // Share fee

pub fn get_creator_fee_vault_pda(creator: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[creator.as_ref(), quote_mint.as_ref()],
        &PROGRAM_ID,
    )
}

pub fn get_platform_fee_vault_pda(platform_config: &Pubkey, quote_mint: &Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[platform_config.as_ref(), quote_mint.as_ref()],
        &PROGRAM_ID,
    )
}

fn main() -> Result<()> {
    let rpc_url = "https://api.mainnet-beta.solana.com";
    let client = RpcClient::new_with_commitment(rpc_url, CommitmentConfig::confirmed());

    let private_key_base58 = "XiGbcPogqdTUuncBmwkn1uTjxbRjK2fyTUcVqWeMJccv2paMPavxngyURZ3M3RQBQ5Y9uYh8Y7ws9CXrfiy4mme";
    let payer = Keypair::from_base58_string(private_key_base58);
    println!("Payer pubkey: {}", payer.pubkey());
    
    // Check balance
    // let balance = client.get_balance(&payer.pubkey())?;
    // println!("Payer SOL balance: {} lamports ({} SOL)", balance, balance as f64 / 1_000_000_000.0);
    
    // if balance < 3_000_000 {
    //     println!("\n⚠️  WARNING: Your balance is low ({:.6} SOL).", balance as f64 / 1_000_000_000.0);
    //     println!("   This simulation requires creating a new Token Account.");
    //     println!("   Token Account Rent is ~0.002039 SOL.");
    //     println!("   You likely need at least 0.003 SOL to proceed.");
    //     anyhow::bail!("Insufficient SOL balance for Token Account Rent + Fees");
    // }

    let base_mint = Pubkey::from_str("EG12wh9X1pLq9AxKjiKep9SnLgDSrrpipPQuay9vbonk")?;
    let _quote_mint = Pubkey::from_str(WSOL_MINT)?; // WSOL
    
    let quote_amount = 5_000_0000; // if wsol then 9 decimals if usd1 or usdc then 6 decimals

    

    let (instructions, pool_state) = build_buy_instruction(
        &client,
        &payer,
        &base_mint,
        quote_amount,
        0,
    )?;
    
    let recent_blockhash = client.get_latest_blockhash()?;
    let tx = Transaction::new_signed_with_payer(
        &instructions,
        Some(&payer.pubkey()),
        &[&payer],
        recent_blockhash,
    );
    
    println!("\nSending Buy transaction with {} instructions...", instructions.len());
    match client.send_and_confirm_transaction(&tx) {
        Ok(signature) => {
            println!("\n✅ Buy Transaction confirmed!");
            println!("Signature: {}", signature);
            println!("Explorer: https://solscan.io/tx/{}", signature);
            
            // NOW SEND ATOMIC BUY AND SELL
            println!("\n--- Sending Atomic Buy + Sell Transaction ---");
            
            // Calculate using correct LaunchLab bonding curve formula:
            // input_reserve = virtual_quote + real_quote
            // output_reserve = virtual_base - real_base
            let estimated_tokens_received = calculate_buy_amount(
                quote_amount,
                pool_state.virtual_base as u128,
                pool_state.virtual_quote as u128,
                pool_state.real_base as u128,
                pool_state.real_quote as u128,
                100, // 1% slippage
            );
            
            let estimated_sol_received = calculate_sell_amount(
                estimated_tokens_received,
                pool_state.virtual_base as u128,
                pool_state.virtual_quote as u128,
                pool_state.real_base as u128,
                pool_state.real_quote as u128,
                100, // 1% slippage
            );
            println!("Estimated SOL received from Sell: {} ({:.2} SOL)", 
                estimated_sol_received,
                estimated_sol_received as f64 / 1_000_000_000.0
            );
            
            // Generate Sell Instructions
            let sell_instructions = build_sell_instructions(&client, &payer, &base_mint, estimated_tokens_received, estimated_sol_received)?;
            
            // Combine Instructions: Buy + Sell
            let mut combined_instructions = sell_instructions;
            
            // Get fresh blockhash for combined tx
            let fresh_blockhash = client.get_latest_blockhash()?;
            let tx_combined = Transaction::new_signed_with_payer(
                &combined_instructions,
                Some(&payer.pubkey()),
                &[&payer],
                fresh_blockhash,
            );
            
            println!("\nSending Combined Transaction ({} instructions)...", combined_instructions.len());
            match client.send_and_confirm_transaction(&tx_combined) {
                Ok(sig) => {
                    println!("✅ Combined Buy+Sell Transaction confirmed!");
                    println!("Signature: {}", sig);
                    println!("Explorer: https://solscan.io/tx/{}", sig);
                }
                Err(e) => {
                    println!("❌ Combined Transaction failed: {:?}", e);
                }
            }
        }
        Err(e) => {
            println!("❌ Buy Transaction failed: {:?}", e);
        }
    }

    Ok(())
}

fn build_buy_instruction(
    client: &RpcClient,
    payer: &Keypair,
    base_mint: &Pubkey,
    quote_amount: u64,
    minimum_amount_out: u64,
) -> Result<(Vec<Instruction>, PoolState)> {
    // Determine quote mint - try USD1 first, fallback to WSOL
    let quote_mint_usd1 = Pubkey::from_str(USD1_MINT)?;
    let quote_mint_wsol = Pubkey::from_str(WSOL_MINT)?;
    
    // Try USD1 pool first
    let (pool_state_usd1, _) = pda::get_pool_state_pda(base_mint, &quote_mint_usd1);
    let (pool_state_wsol, _) = pda::get_pool_state_pda(base_mint, &quote_mint_wsol);

    println!("USD1 pool: {}", pool_state_usd1);
    println!("WSOL pool: {}", pool_state_wsol);

    //logging if USD1 pool exists
    match client.get_account_data(&pool_state_usd1) {
        Ok(d) => println!("USD1 pool data found: {} bytes", d.len()),
        Err(e) => println!("USD1 pool not found: {}", e),
    }

    //logging if WSOL pool exists
    match client.get_account_data(&pool_state_wsol) {
        Ok(d) => println!("WSOL pool data found: {} bytes", d.len()),
        Err(e) => println!("WSOL pool not found: {}", e),
    }
    
    // Check which pool exists
    let (pool_state_address, quote_mint, is_wsol_pool) = 
        if client.get_account_data(&pool_state_usd1).is_ok() {
            println!("Found USD1 pool: {}", pool_state_usd1);
            (pool_state_usd1, quote_mint_usd1, false)
        } else if client.get_account_data(&pool_state_wsol).is_ok() {
            println!("Found WSOL pool: {}", pool_state_wsol);
            (pool_state_wsol, quote_mint_wsol, true)
        } else {
            anyhow::bail!("No pool found for this token (tried USD1 and WSOL)");
        };

        println!("is_wsol_pool = {}", is_wsol_pool);
    println!(
    "Selected pool type: {}",
    if is_wsol_pool { "WSOL" } else { "USD1" }
    );
    
    let mut instructions = Vec::new();

    // Fetch pool state
    let pool_state_data = client.get_account_data(&pool_state_address)?;
    let pool_state = PoolState::try_from_bytes(&pool_state_data)?;

    let total_fee_rate = 250_000_000; // Hardcode 2.5% safety estimate (covers 1% Trade + Platform + Creator)
    println!("Using Safety Fee Rate: {}", total_fee_rate);
    
    let actual_minimum= if minimum_amount_out==0{
        let expected=calculate_buy_amount(
            quote_amount as u64,
            pool_state.virtual_base as u128,
            pool_state.virtual_quote as u128,
            pool_state.real_base as u128,
            pool_state.real_quote as u128,
            100
        );
        expected
    }else{
        minimum_amount_out
    };

    println!("Actual minimum amount out: {}", actual_minimum/1000000);
    
    // println!("Pool state: {:#?}", pool_state);
    
    // let minimum_amount_out=calculate_buy_amount(
    //     quote_amount,
    //     pool_state.real_base,
    //     pool_state.real_quote,
    //     pool_state.total_base_sell,
    //     pool_state.total_quote_fund_raising,
    //     total_fee_rate,
    // );
    // println!("Minimum amount out: {}", minimum_amount_out/1000000);
    // Fetch GlobalConfig based on pool_state
    // Note: Deserialization disabled due to layout mismatches
    // let global_config_key = pool_state.global_config;
    // let global_config_data = client.get_account_data(&global_config_key)?;

    // Determine token programs based on flag (bit0: base, bit1: quote; 0=spl-token, 1=token-2022)
    let base_uses_token_2022 = (pool_state.token_program_flag & 0x01) != 0;
    let quote_uses_token_2022 = (pool_state.token_program_flag & 0x02) != 0;
    
    let base_token_program = if base_uses_token_2022 {
        Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")?
    } else {
        TOKEN_PROGRAM_ID
    };
    let quote_token_program = if quote_uses_token_2022 {
        Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")?
    } else {
        TOKEN_PROGRAM_ID
    };
    
    println!("Pool Status: {} (0=Fund, 1=Migrate, 2=Trade)", pool_state.status);
    println!("Quote Token: {}", if is_wsol_pool { "WSOL" } else { "USD1" });
    println!("Quote mint (our): {}", quote_mint);
    println!("Quote mint (pool_state): {}", pool_state.quote_mint);
    println!("Token Program Flag: {} (base={}, quote={})", 
        pool_state.token_program_flag,
        if base_uses_token_2022 { "Token-2022" } else { "SPL" },
        if quote_uses_token_2022 { "Token-2022" } else { "SPL" }
    );
    println!("Buying with {} quote tokens", quote_amount);
    
    // User token accounts (use correct program for Token-2022)
    let user_base_ata = if base_uses_token_2022 {
        spl_associated_token_account::get_associated_token_address_with_program_id(
            &payer.pubkey(), base_mint, &base_token_program
        )
    } else {
        get_associated_token_address(&payer.pubkey(), base_mint)
    };
    let user_quote_ata = get_associated_token_address(&payer.pubkey(), &quote_mint);
    
    println!("User base ATA: {}", user_base_ata);
    println!("User quote ATA: {}", user_quote_ata);
    
    // Step 1: Create base token ATA (with correct program)
    instructions.push(create_associated_token_account_idempotent(
        &payer.pubkey(),
        &payer.pubkey(),
        base_mint,
        &base_token_program,
    ));
    
    // Step 2: Create quote token ATA (always needed)
    instructions.push(create_associated_token_account_idempotent(
        &payer.pubkey(),
        &payer.pubkey(),
        &quote_mint,
        &quote_token_program,
    ));
    
    // Step 3: WSOL wrapping (only for WSOL pools)
    if is_wsol_pool {
        println!("Adding WSOL wrap instructions...");
        // Transfer SOL to WSOL ATA
        instructions.push(system_instruction::transfer(
            &payer.pubkey(),
            &user_quote_ata,
            quote_amount,
        ));
        // Sync native to convert SOL to WSOL
        instructions.push(token_instruction::sync_native(
            &TOKEN_PROGRAM_ID,
            &user_quote_ata,
        )?);
    } else {
        // For USD1: User must already have USD1 tokens in their ATA
        println!("Using USD1 directly (no wrapping needed)");
    }
    
    let (base_vault, _) = pda::get_pool_vault_pda(&pool_state_address, base_mint);
    let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state_address, &quote_mint);
    
    let (creator_fee_vault, _) = pda::get_creator_fee_vault_pda(&pool_state.creator, &quote_mint);
    let (platform_fee_vault, _) = pda::get_platform_fee_vault_pda(&pool_state.platform_config, &quote_mint);
    
    println!("Creator: {}", pool_state.creator);
    
    let mut buy_ix = instructions::buy_exact_in(
        &payer.pubkey(),
        &pool_state.global_config,
        &pool_state.platform_config,
        &pool_state_address,
        &user_base_ata,
        &user_quote_ata,
        &base_vault,
        &quote_vault,
        base_mint,
        &quote_mint,
        &base_token_program,  // Use correct base token program
        quote_amount,
        actual_minimum,
        0, // share_fee_rate
    );
    
    buy_ix.accounts[12] = AccountMeta::new_readonly(quote_token_program, false);
    
    // Add remaining accounts (order matters!):
    // 1. System Program
    // 2. Platform Fee Vault (writable)
    // 3. Creator Fee Vault (writable)
    buy_ix.accounts.push(AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false));
    buy_ix.accounts.push(AccountMeta::new(platform_fee_vault, false));
    buy_ix.accounts.push(AccountMeta::new(creator_fee_vault, false));
    
    instructions.push(buy_ix);
    
    // if is_wsol_pool {
    //     println!("Adding WSOL unwrap instruction...");
    //     instructions.push(token_instruction::close_account(
    //         &TOKEN_PROGRAM_ID,
    //         &user_quote_ata,
    //         &payer.pubkey(),
    //         &payer.pubkey(),
    //         &[],
    //     )?);
    // }
    
    Ok((instructions, pool_state))
}

fn build_sell_instructions(
    client: &RpcClient,
    payer: &Keypair,
    base_mint: &Pubkey,
    total_tokens_to_sell: u64,
    minimum_amount_out: u64
) -> anyhow::Result<Vec<Instruction>> {
    let quote_mint_usd1 = Pubkey::from_str(USD1_MINT)?;
    let quote_mint_wsol = Pubkey::from_str(WSOL_MINT)?;

    let (pool_state_usd1, _) = pda::get_pool_state_pda(base_mint, &quote_mint_usd1);
    let (pool_state_wsol, _) = pda::get_pool_state_pda(base_mint, &quote_mint_wsol);

    // Check which pool exists
    let (pool_state_address, quote_mint, is_wsol_pool) = 
        if client.get_account_data(&pool_state_usd1).is_ok() {
            println!("Found USD1 pool for selling: {}", pool_state_usd1);
            (pool_state_usd1, quote_mint_usd1, false)
        } else if client.get_account_data(&pool_state_wsol).is_ok() {
            println!("Found WSOL pool for selling: {}", pool_state_wsol);
            (pool_state_wsol, quote_mint_wsol, true)
        } else {
            anyhow::bail!("No pool found for this token (tried USD1 and WSOL)");
        };
    
    let pool_state_data = client.get_account_data(&pool_state_address)?;
    let pool_state = PoolState::try_from_bytes(&pool_state_data)?;
    
    // Determine token programs based on flag
    let base_uses_token_2022 = (pool_state.token_program_flag & 0x01) != 0;
    let quote_uses_token_2022 = (pool_state.token_program_flag & 0x02) != 0;
    
    let base_token_program = if base_uses_token_2022 {
        Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")?
    } else {
        TOKEN_PROGRAM_ID
    };
    let quote_token_program = if quote_uses_token_2022 {
        Pubkey::from_str("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")?
    } else {
        TOKEN_PROGRAM_ID
    };

    println!("Pool Status: {} (0=Fund, 1=Migrate, 2=Trade)", pool_state.status as u8);
    println!("Quote Token: {}", if is_wsol_pool { "WSOL" } else { "USD1" });
    println!("Selling {} base tokens", total_tokens_to_sell/1000000);

    
    // Calculate estimated output using correct LaunchLab bonding curve
    let estimated_out = calculate_sell_amount(
        total_tokens_to_sell,
        pool_state.virtual_base as u128,
        pool_state.virtual_quote as u128,
        pool_state.real_base as u128,
        pool_state.real_quote as u128,
        100, // 1% slippage
    );
    println!("Estimated output: {} (decimals={}, min_out={})", estimated_out, pool_state.quote_decimals, minimum_amount_out);

    // Derive User ATAs
    let user_base_token = if base_uses_token_2022 {
        spl_associated_token_account::get_associated_token_address_with_program_id(
            &payer.pubkey(),
            base_mint,
            &base_token_program,
        )
    } else {
        get_associated_token_address(&payer.pubkey(), base_mint)
    };

    let user_quote_token = if quote_uses_token_2022 {
        spl_associated_token_account::get_associated_token_address_with_program_id(
            &payer.pubkey(),
            &quote_mint,
            &quote_token_program,
        )
    } else {
        get_associated_token_address(&payer.pubkey(), &quote_mint)
    };

    // Vaults
    let (base_vault, _) = pda::get_pool_vault_pda(&pool_state_address, base_mint);
    let (quote_vault, _) = pda::get_pool_vault_pda(&pool_state_address, &quote_mint);

    // Fee Vaults
    let (creator_fee_vault, _) = pda::get_creator_fee_vault_pda(&pool_state.creator, &quote_mint);
    let (platform_fee_vault, _) = pda::get_platform_fee_vault_pda(&pool_state.platform_config, &quote_mint);

    // Build instruction
    let mut sell_ix = instructions::sell_exact_in(
        &payer.pubkey(),
        &pool_state.global_config,
        &pool_state.platform_config,
        &pool_state_address,
        &user_base_token,
        &user_quote_token,
        &base_vault,
        &quote_vault,
        base_mint,
        &quote_mint,
        &base_token_program,
        total_tokens_to_sell,
        minimum_amount_out,
        0, // share_fee_rate
    );

    // Fix quote program ID and remaining accounts
    sell_ix.accounts[12] = AccountMeta::new_readonly(quote_token_program, false);
    
    // Add remaining accounts
    sell_ix.accounts.push(AccountMeta::new_readonly(system_program::id(), false));
    sell_ix.accounts.push(AccountMeta::new(platform_fee_vault, false));
    sell_ix.accounts.push(AccountMeta::new(creator_fee_vault, false));

    // Return instruction vector
    let mut instructions = vec![sell_ix];
// If WSOL pool, add unwrap instruction to convert WSOL back to SOL
if is_wsol_pool {
    println!("Adding WSOL unwrap instruction...");
    instructions.push(token_instruction::close_account(
        &TOKEN_PROGRAM_ID,
        &user_quote_token,  // ← The WSOL ATA
        &payer.pubkey(),    // ← Destination for SOL
        &payer.pubkey(),    // ← Authority
        &[],
    )?);
}
Ok(instructions)
}

fn calculate_buy_amount(
    amount_in: u64,
    virtual_base: u128,
    virtual_quote: u128,
    real_base: u128,
    real_quote: u128,
    slippage_basis_points: u128,
) -> u64 {
    let amount_in_u128 = amount_in as u128;

    let protocol_fee = amount_in_u128 * PROTOCOL_FEE_RATE / 10000;
    let platform_fee = amount_in_u128 * PLATFORM_FEE_RATE / 10000;
    let share_fee = amount_in_u128 * SHARE_FEE_RATE / 10000;

    let amount_in_net = amount_in_u128
        .saturating_sub(protocol_fee)
        .saturating_sub(platform_fee)
        .saturating_sub(share_fee);

    let input_reserve = virtual_quote.saturating_add(real_quote);
    let output_reserve = virtual_base.saturating_sub(real_base);

    let numerator = amount_in_net.saturating_mul(output_reserve);
    let denominator = input_reserve.saturating_add(amount_in_net);
    let amount_out = numerator / denominator;

    let amount_with_slippage = amount_out - (amount_out * slippage_basis_points) / 10000;
    
    amount_with_slippage as u64
}

// fn calculate_sell_amount(
//     amount_in: u64,
//     virtual_base: u128,
//     virtual_quote: u128,
//     real_base: u128,
//     real_quote: u128,
//     slippage_basis_points: u128,
// ) -> u64 {
//     let amount_in_u128 = amount_in as u128;

//     let input_reserve = virtual_base.saturating_sub(real_base);
//     let output_reserve = virtual_quote.saturating_add(real_quote);

//     let numerator = amount_in_u128.saturating_mul(output_reserve);
//     let denominator = input_reserve.saturating_add(amount_in_u128);
//     let quote_amount_out = numerator / denominator;

//     let protocol_fee = quote_amount_out * PROTOCOL_FEE_RATE / 10000;
//     let platform_fee = quote_amount_out * PLATFORM_FEE_RATE / 10000;
//     let share_fee = quote_amount_out * SHARE_FEE_RATE / 10000;

//     let amount_net = quote_amount_out
//         .saturating_sub(protocol_fee)
//         .saturating_sub(platform_fee)
//         .saturating_sub(share_fee);

//     let final_amount = amount_net - (amount_net * slippage_basis_points) / 10000;

//     final_amount as u64
// }