UNPKG

@glamsystems/glam-sdk

Version:

TypeScript SDK for the GLAM Protocol

1,786 lines (1,784 loc) 720 kB
import * as anchor from '@coral-xyz/anchor'; import { Program, BN } from '@coral-xyz/anchor'; import { PublicKey, StakeProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL, AddressLookupTableAccount, SystemProgram, Connection, Transaction, sendAndConfirmTransaction, TransactionInstruction, SYSVAR_CLOCK_PUBKEY, Keypair, STAKE_CONFIG_ID, SYSVAR_RENT_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js'; import { getExtensionData, ExtensionType, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, unpackMint, AccountLayout, getAssociatedTokenAddressSync, getAccount, TokenAccountNotFoundError, createAssociatedTokenAccountIdempotentInstruction, createSyncNativeInstruction, createTransferCheckedInstruction, unpackAccount, createCloseAccountInstruction } from '@solana/spl-token'; import { unpack } from '@solana/spl-token-metadata'; import DLMM, { binIdToBinArrayIndex, deriveBinArray, Strategy } from '@meteora-ag/dlmm'; import { LstList } from '@glamsystems/sanctum-lst-list'; import { bs58 } from '@coral-xyz/anchor/dist/cjs/utils/bytes'; import * as borsh from '@coral-xyz/borsh'; import { struct, array, publicKey, u128, i64, u64, u32, u16, u8, bool } from '@coral-xyz/borsh'; import { Marinade, MarinadeConfig } from '@marinade.finance/marinade-ts-sdk'; import { getStakePoolAccount } from '@solana/spl-stake-pool'; var address = "GLAMbTqav9N9witRjswJ8enwp9vv5G8bsSJ2kPJ4rcyc"; var metadata = { name: "glam_protocol", version: "0.4.36", spec: "0.1.0", description: "Glam Protocol" }; var instructions = [ { name: "add_mint", discriminator: [ 171, 222, 111, 37, 60, 166, 208, 108 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_signer", writable: true, signer: true }, { name: "new_mint", writable: true }, { name: "extra_metas_account", writable: true, optional: true }, { name: "openfunds_metadata", writable: true, optional: true, pda: { seeds: [ { kind: "const", value: [ 109, 101, 116, 97, 100, 97, 116, 97 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "system_program", address: "11111111111111111111111111111111" }, { name: "token_2022_program", address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" }, { name: "policies_program", address: "po1iCYakK3gHCLbuju4wGzFowTMpAJxkqK1iwUqMonY" } ], args: [ { name: "mint_model", type: { defined: { name: "MintModel" } } } ] }, { name: "burn_tokens", discriminator: [ 76, 15, 51, 254, 229, 215, 121, 66 ], accounts: [ { name: "glam_state" }, { name: "glam_signer", writable: true, signer: true }, { name: "glam_mint", writable: true }, { name: "from_ata", writable: true, pda: { seeds: [ { kind: "account", path: "from" }, { kind: "account", path: "token_2022_program" }, { kind: "account", path: "glam_mint" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "from" }, { name: "token_2022_program", address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" } ], args: [ { name: "mint_id", type: "u8" }, { name: "amount", type: "u64" } ] }, { name: "claim", discriminator: [ 62, 198, 214, 193, 213, 159, 108, 210 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_escrow", pda: { seeds: [ { kind: "const", value: [ 101, 115, 99, 114, 111, 119 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "signer", writable: true, signer: true }, { name: "token_mint" }, { name: "signer_ata", writable: true, pda: { seeds: [ { kind: "account", path: "signer" }, { kind: "account", path: "claim_token_program" }, { kind: "account", path: "token_mint" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "escrow_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_escrow" }, { kind: "account", path: "claim_token_program" }, { kind: "account", path: "token_mint" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "system_program", address: "11111111111111111111111111111111" }, { name: "claim_token_program" }, { name: "associated_token_program", address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" } ], args: [ { name: "mint_id", type: "u8" } ] }, { name: "close_mint", discriminator: [ 149, 251, 157, 212, 65, 181, 235, 129 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "glam_mint", writable: true }, { name: "extra_metas_account", writable: true, optional: true }, { name: "metadata", writable: true, pda: { seeds: [ { kind: "const", value: [ 109, 101, 116, 97, 100, 97, 116, 97 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "policies_program", address: "po1iCYakK3gHCLbuju4wGzFowTMpAJxkqK1iwUqMonY" }, { name: "token_2022_program", address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" }, { name: "system_program", address: "11111111111111111111111111111111" } ], args: [ { name: "mint_id", type: "u8" } ] }, { name: "close_state", discriminator: [ 25, 1, 184, 101, 200, 245, 210, 246 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "metadata", writable: true, pda: { seeds: [ { kind: "const", value: [ 109, 101, 116, 97, 100, 97, 116, 97 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "system_program", address: "11111111111111111111111111111111" } ], args: [] }, { name: "crystallize_fees", discriminator: [ 78, 0, 111, 26, 7, 12, 41, 249 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_escrow", pda: { seeds: [ { kind: "const", value: [ 101, 115, 99, 114, 111, 119 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_mint", writable: true }, { name: "escrow_mint_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_escrow" }, { kind: "account", path: "token_2022_program" }, { kind: "account", path: "glam_mint" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "signer", writable: true, signer: true }, { name: "token_2022_program", address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" } ], args: [ { name: "mint_id", type: "u8" } ] }, { name: "disburse_fees", discriminator: [ 205, 56, 198, 40, 225, 103, 141, 219 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_escrow", pda: { seeds: [ { kind: "const", value: [ 101, 115, 99, 114, 111, 119 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_mint", writable: true }, { name: "escrow_mint_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_escrow" }, { kind: "account", path: "token_2022_program" }, { kind: "account", path: "glam_mint" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "signer", writable: true, signer: true }, { name: "deposit_asset" }, { name: "vault_deposit_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_vault" }, { kind: "account", path: "deposit_token_program" }, { kind: "account", path: "deposit_asset" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "protocol_fee_authority_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_config.fee_authority", account: "GlobalConfig" }, { kind: "account", path: "deposit_token_program" }, { kind: "account", path: "deposit_asset" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "manager_fee_authority_ata", writable: true, pda: { seeds: [ { kind: "account", path: "glam_state.owner", account: "StateAccount" }, { kind: "account", path: "deposit_token_program" }, { kind: "account", path: "deposit_asset" } ], program: { kind: "const", value: [ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 ] } } }, { name: "glam_config", pda: { seeds: [ { kind: "const", value: [ 103, 108, 111, 98, 97, 108, 45, 99, 111, 110, 102, 105, 103 ] } ], program: { kind: "const", value: [ 10, 11, 0, 83, 72, 16, 46, 144, 46, 42, 79, 22, 157, 123, 21, 242, 192, 146, 1, 78, 88, 59, 102, 9, 190, 226, 92, 189, 187, 232, 83, 220 ] } } }, { name: "system_program", address: "11111111111111111111111111111111" }, { name: "associated_token_program", address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" }, { name: "deposit_token_program" }, { name: "token_2022_program", address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" } ], args: [ { name: "mint_id", type: "u8" } ] }, { name: "drift_cancel_orders", discriminator: [ 98, 107, 48, 79, 97, 60, 99, 58 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "state" }, { name: "user", writable: true } ], args: [ { name: "market_type", type: { option: { defined: { name: "MarketType" } } } }, { name: "market_index", type: { option: "u16" } }, { name: "direction", type: { option: { defined: { name: "PositionDirection" } } } } ] }, { name: "drift_cancel_orders_by_ids", discriminator: [ 172, 99, 108, 14, 81, 89, 228, 183 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "state" }, { name: "user", writable: true } ], args: [ { name: "order_ids", type: { vec: "u32" } } ] }, { name: "drift_delete_user", discriminator: [ 179, 118, 20, 212, 145, 146, 49, 130 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "user", writable: true }, { name: "user_stats", writable: true }, { name: "state", writable: true } ], args: [] }, { name: "drift_deposit", discriminator: [ 252, 63, 250, 201, 98, 55, 130, 12 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "state" }, { name: "user", writable: true }, { name: "user_stats", writable: true }, { name: "spot_market_vault", writable: true }, { name: "user_token_account", writable: true }, { name: "token_program" } ], args: [ { name: "market_index", type: "u16" }, { name: "amount", type: "u64" }, { name: "reduce_only", type: "bool" } ] }, { name: "drift_distributor_new_claim", discriminator: [ 204, 159, 250, 46, 124, 193, 250, 10 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "E7HtfkEMhmn9uwL7EFNydcXBWy5WCYN1vFmKKjipEH1x" }, { name: "distributor", writable: true }, { name: "claim_status", writable: true }, { name: "from", writable: true }, { name: "to", writable: true }, { name: "token_program" }, { name: "system_program", address: "11111111111111111111111111111111" } ], args: [ { name: "amount_unlocked", type: "u64" }, { name: "amount_locked", type: "u64" }, { name: "proof", type: { vec: { array: [ "u8", 32 ] } } } ] }, { name: "drift_initialize_user", discriminator: [ 107, 244, 158, 15, 225, 239, 98, 245 ], accounts: [ { name: "glam_state", writable: true }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "user", writable: true }, { name: "user_stats", writable: true }, { name: "state", writable: true }, { name: "payer", writable: true, signer: true }, { name: "rent", address: "SysvarRent111111111111111111111111111111111" }, { name: "system_program", address: "11111111111111111111111111111111" } ], args: [ { name: "sub_account_id", type: "u16" }, { name: "name", type: { array: [ "u8", 32 ] } } ] }, { name: "drift_initialize_user_stats", discriminator: [ 133, 185, 103, 162, 90, 161, 78, 143 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "user_stats", writable: true }, { name: "state", writable: true }, { name: "payer", writable: true, signer: true }, { name: "rent", address: "SysvarRent111111111111111111111111111111111" }, { name: "system_program", address: "11111111111111111111111111111111" } ], args: [] }, { name: "drift_modify_order", discriminator: [ 235, 245, 222, 58, 245, 128, 19, 202 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "state" }, { name: "user", writable: true } ], args: [ { name: "order_id", type: { option: "u32" } }, { name: "modify_order_params", type: { defined: { name: "ModifyOrderParams" } } } ] }, { name: "drift_place_orders", discriminator: [ 117, 18, 210, 6, 238, 174, 135, 167 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", writable: true, pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer", writable: true, signer: true }, { name: "cpi_program", address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" }, { name: "state" }, { name: "user", writable: true } ], args: [ { name: "params", type: { vec: { defined: { name: "OrderParams" } } } } ] }, { name: "drift_settle_multiple_pnls", discriminator: [ 100, 72, 3, 45, 69, 37, 10, 144 ], accounts: [ { name: "glam_state" }, { name: "glam_vault", pda: { seeds: [ { kind: "const", value: [ 118, 97, 117, 108, 116 ] }, { kind: "account", path: "glam_state" } ] } }, { name: "glam_signer",