This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Metaplex } from "@metaplex-foundation/js"; | |
import { | |
getMint, | |
getTokenMetadata as getToken2022Metadata, | |
Mint, | |
} from "@solana/spl-token"; | |
import { PublicKey } from "@solana/web3.js"; | |
import { config } from "./config"; | |
// Generalized Token metadata interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { struct, u8 as u8Func } from "@solana/buffer-layout"; | |
import { | |
publicKey as publicKeyUtil, | |
u64 as u64Func, | |
} from "@solana/buffer-layout-utils"; | |
import { getAccount, getMint } from "@solana/spl-token"; | |
import { PublicKey } from "@solana/web3.js"; | |
import { config } from "./config"; | |
import { fetchToken } from "./fetch-token"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.1.0", | |
"name": "raydium_cp_swap", | |
"instructions": [ | |
{ | |
"name": "createAmmConfig", | |
"docs": [ | |
"# Arguments", | |
"", | |
"* `ctx`- The accounts needed by instruction.", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AsObservableFactory<T> = T extends (...a: infer U) => Promise<infer V> | |
? (...a: U) => Observable<V> | |
: never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Clone)] | |
pub struct Metadata; | |
impl anchor_lang::Id for Metadata { | |
fn id() -> Pubkey { | |
Pubkey::from_str("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s").unwrap() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Union method to create a mapped typed from a discriminated union | |
export type UnionBy< | |
Key extends string, | |
Value extends string, | |
Base, | |
Map extends Record<Value, object | null> | |
> = { | |
[TValue in keyof Map]: { | |
[key in Key]: TValue; | |
} & (Map[TValue] extends null ? Base : Base & Map[TValue]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn is_discriminator_already_set<'info>(account: &UncheckedAccount<'info>) -> Result<bool> { | |
let data = account.try_borrow_data()?; | |
let mut disc_bytes = [0u8; 8]; | |
disc_bytes.copy_from_slice(&data[..8]); | |
let discriminator = u64::from_le_bytes(disc_bytes); | |
Ok(discriminator != 0) | |
} | |
pub fn try_deserialize_unchecked<'info, T: AccountDeserialize>( | |
account: &UncheckedAccount<'info>, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn get_remaining_account<'info, T: AccountSerialize + AccountDeserialize + Owner + Clone>( | |
remaining_accounts: &[AccountInfo<'info>], | |
index: usize, | |
) -> std::result::Result<Option<Account<'info, T>>, Error> { | |
let maybe_account: Option<&AccountInfo> = remaining_accounts.get(index); | |
let maybe_decoded_account: Option<std::result::Result<Account<'info, T>, Error>> = | |
maybe_account.map(Account::try_from); | |
match maybe_decoded_account { | |
Some(Ok(account)) => Ok(Some(account)), | |
Some(Err(_)) => return Err(error!(ErrorCode::InvalidAccount)), |