@picon-finance/dlmm-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/actions/accept_admin_authority.d.ts +13 -0
- package/dist/actions/accept_admin_authority.d.ts.map +1 -0
- package/dist/actions/accept_admin_authority.js +7 -0
- package/dist/actions/claim_fee.d.ts +21 -0
- package/dist/actions/claim_fee.d.ts.map +1 -0
- package/dist/actions/claim_fee.js +40 -0
- package/dist/actions/claim_multiple_fees.d.ts +19 -0
- package/dist/actions/claim_multiple_fees.d.ts.map +1 -0
- package/dist/actions/claim_multiple_fees.js +81 -0
- package/dist/actions/claim_protocol_fee.d.ts +18 -0
- package/dist/actions/claim_protocol_fee.d.ts.map +1 -0
- package/dist/actions/claim_protocol_fee.js +33 -0
- package/dist/actions/close_position.d.ts +14 -0
- package/dist/actions/close_position.d.ts.map +1 -0
- package/dist/actions/close_position.js +14 -0
- package/dist/actions/create_admin_config.d.ts +15 -0
- package/dist/actions/create_admin_config.d.ts.map +1 -0
- package/dist/actions/create_admin_config.js +30 -0
- package/dist/actions/create_bin_array.d.ts +16 -0
- package/dist/actions/create_bin_array.d.ts.map +1 -0
- package/dist/actions/create_bin_array.js +10 -0
- package/dist/actions/create_pool.d.ts +21 -0
- package/dist/actions/create_pool.d.ts.map +1 -0
- package/dist/actions/create_pool.js +22 -0
- package/dist/actions/delete_bin_array.d.ts +16 -0
- package/dist/actions/delete_bin_array.d.ts.map +1 -0
- package/dist/actions/delete_bin_array.js +13 -0
- package/dist/actions/deposit_by_weight.d.ts +27 -0
- package/dist/actions/deposit_by_weight.d.ts.map +1 -0
- package/dist/actions/deposit_by_weight.js +52 -0
- package/dist/actions/get_admin_config.d.ts +4 -0
- package/dist/actions/get_admin_config.d.ts.map +1 -0
- package/dist/actions/get_admin_config.js +7 -0
- package/dist/actions/get_bin_arrays_by_indices.d.ts +5 -0
- package/dist/actions/get_bin_arrays_by_indices.d.ts.map +1 -0
- package/dist/actions/get_bin_arrays_by_indices.js +6 -0
- package/dist/actions/get_pool.d.ts +4 -0
- package/dist/actions/get_pool.d.ts.map +1 -0
- package/dist/actions/get_pool.js +5 -0
- package/dist/actions/get_position.d.ts +4 -0
- package/dist/actions/get_position.d.ts.map +1 -0
- package/dist/actions/get_position.js +5 -0
- package/dist/actions/get_position_by_position_mint.d.ts +4 -0
- package/dist/actions/get_position_by_position_mint.d.ts.map +1 -0
- package/dist/actions/get_position_by_position_mint.js +6 -0
- package/dist/actions/get_positions_by_owner.d.ts +5 -0
- package/dist/actions/get_positions_by_owner.d.ts.map +1 -0
- package/dist/actions/get_positions_by_owner.js +33 -0
- package/dist/actions/get_positions_by_position_mints.d.ts +5 -0
- package/dist/actions/get_positions_by_position_mints.d.ts.map +1 -0
- package/dist/actions/get_positions_by_position_mints.js +9 -0
- package/dist/actions/helpers/build_swap_transaction_message.d.ts +22 -0
- package/dist/actions/helpers/build_swap_transaction_message.d.ts.map +1 -0
- package/dist/actions/helpers/build_swap_transaction_message.js +50 -0
- package/dist/actions/helpers/build_transaction_message.d.ts +20 -0
- package/dist/actions/helpers/build_transaction_message.d.ts.map +1 -0
- package/dist/actions/helpers/build_transaction_message.js +5 -0
- package/dist/actions/helpers/index.d.ts +8 -0
- package/dist/actions/helpers/index.d.ts.map +1 -0
- package/dist/actions/helpers/index.js +7 -0
- package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts +12 -0
- package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts.map +1 -0
- package/dist/actions/helpers/resolve_active_bin_and_mints.js +13 -0
- package/dist/actions/helpers/resolve_admin_config_address.d.ts +3 -0
- package/dist/actions/helpers/resolve_admin_config_address.d.ts.map +1 -0
- package/dist/actions/helpers/resolve_admin_config_address.js +9 -0
- package/dist/actions/helpers/resolve_mint_info.d.ts +10 -0
- package/dist/actions/helpers/resolve_mint_info.d.ts.map +1 -0
- package/dist/actions/helpers/resolve_mint_info.js +20 -0
- package/dist/actions/helpers/resolve_position_range.d.ts +12 -0
- package/dist/actions/helpers/resolve_position_range.d.ts.map +1 -0
- package/dist/actions/helpers/resolve_position_range.js +12 -0
- package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts +15 -0
- package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts.map +1 -0
- package/dist/actions/helpers/resolve_token_mints_and_programs.js +29 -0
- package/dist/actions/index.d.ts +31 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +28 -0
- package/dist/actions/is_admin_config_active.d.ts +4 -0
- package/dist/actions/is_admin_config_active.d.ts.map +1 -0
- package/dist/actions/is_admin_config_active.js +7 -0
- package/dist/actions/on_event.d.ts +11 -0
- package/dist/actions/on_event.d.ts.map +1 -0
- package/dist/actions/on_event.js +50 -0
- package/dist/actions/open_position.d.ts +17 -0
- package/dist/actions/open_position.d.ts.map +1 -0
- package/dist/actions/open_position.js +31 -0
- package/dist/actions/quote.d.ts +13 -0
- package/dist/actions/quote.d.ts.map +1 -0
- package/dist/actions/quote.js +43 -0
- package/dist/actions/set_metadata_update_authority.d.ts +14 -0
- package/dist/actions/set_metadata_update_authority.d.ts.map +1 -0
- package/dist/actions/set_metadata_update_authority.js +7 -0
- package/dist/actions/set_pool_dynamic_fee_config.d.ts +16 -0
- package/dist/actions/set_pool_dynamic_fee_config.d.ts.map +1 -0
- package/dist/actions/set_pool_dynamic_fee_config.js +7 -0
- package/dist/actions/set_pool_protocol_share.d.ts +15 -0
- package/dist/actions/set_pool_protocol_share.d.ts.map +1 -0
- package/dist/actions/set_pool_protocol_share.js +7 -0
- package/dist/actions/swap.d.ts +22 -0
- package/dist/actions/swap.d.ts.map +1 -0
- package/dist/actions/swap.js +19 -0
- package/dist/actions/sync_pool.d.ts +15 -0
- package/dist/actions/sync_pool.d.ts.map +1 -0
- package/dist/actions/sync_pool.js +26 -0
- package/dist/actions/transfer_admin_authority.d.ts +14 -0
- package/dist/actions/transfer_admin_authority.d.ts.map +1 -0
- package/dist/actions/transfer_admin_authority.js +7 -0
- package/dist/actions/withdraw.d.ts +22 -0
- package/dist/actions/withdraw.d.ts.map +1 -0
- package/dist/actions/withdraw.js +41 -0
- package/dist/events.d.ts +93 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +166 -0
- package/dist/generated/accounts/adminConfig.d.ts +35 -0
- package/dist/generated/accounts/adminConfig.d.ts.map +1 -0
- package/dist/generated/accounts/adminConfig.js +60 -0
- package/dist/generated/accounts/binArray.d.ts +40 -0
- package/dist/generated/accounts/binArray.d.ts.map +1 -0
- package/dist/generated/accounts/binArray.js +65 -0
- package/dist/generated/accounts/index.d.ts +12 -0
- package/dist/generated/accounts/index.d.ts.map +1 -0
- package/dist/generated/accounts/index.js +11 -0
- package/dist/generated/accounts/pool.d.ts +54 -0
- package/dist/generated/accounts/pool.d.ts.map +1 -0
- package/dist/generated/accounts/pool.js +79 -0
- package/dist/generated/accounts/position.d.ts +42 -0
- package/dist/generated/accounts/position.d.ts.map +1 -0
- package/dist/generated/accounts/position.js +67 -0
- package/dist/generated/errors/index.d.ts +9 -0
- package/dist/generated/errors/index.d.ts.map +1 -0
- package/dist/generated/errors/index.js +8 -0
- package/dist/generated/errors/piconDlmm.d.ts +58 -0
- package/dist/generated/errors/piconDlmm.d.ts.map +1 -0
- package/dist/generated/errors/piconDlmm.js +80 -0
- package/dist/generated/index.d.ts +14 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +13 -0
- package/dist/generated/instructions/acceptAdminAuthority.d.ts +47 -0
- package/dist/generated/instructions/acceptAdminAuthority.d.ts.map +1 -0
- package/dist/generated/instructions/acceptAdminAuthority.js +99 -0
- package/dist/generated/instructions/claimFee.d.ts +83 -0
- package/dist/generated/instructions/claimFee.d.ts.map +1 -0
- package/dist/generated/instructions/claimFee.js +127 -0
- package/dist/generated/instructions/claimProtocolFee.d.ts +83 -0
- package/dist/generated/instructions/claimProtocolFee.d.ts.map +1 -0
- package/dist/generated/instructions/claimProtocolFee.js +147 -0
- package/dist/generated/instructions/closePosition.d.ts +59 -0
- package/dist/generated/instructions/closePosition.d.ts.map +1 -0
- package/dist/generated/instructions/closePosition.js +124 -0
- package/dist/generated/instructions/createAdminConfig.d.ts +68 -0
- package/dist/generated/instructions/createAdminConfig.d.ts.map +1 -0
- package/dist/generated/instructions/createAdminConfig.js +132 -0
- package/dist/generated/instructions/createBinArray.d.ts +64 -0
- package/dist/generated/instructions/createBinArray.d.ts.map +1 -0
- package/dist/generated/instructions/createBinArray.js +122 -0
- package/dist/generated/instructions/createPool.d.ts +100 -0
- package/dist/generated/instructions/createPool.d.ts.map +1 -0
- package/dist/generated/instructions/createPool.js +202 -0
- package/dist/generated/instructions/deleteBinArray.d.ts +68 -0
- package/dist/generated/instructions/deleteBinArray.d.ts.map +1 -0
- package/dist/generated/instructions/deleteBinArray.js +130 -0
- package/dist/generated/instructions/depositByWeight.d.ts +99 -0
- package/dist/generated/instructions/depositByWeight.d.ts.map +1 -0
- package/dist/generated/instructions/depositByWeight.js +136 -0
- package/dist/generated/instructions/index.d.ts +25 -0
- package/dist/generated/instructions/index.d.ts.map +1 -0
- package/dist/generated/instructions/index.js +24 -0
- package/dist/generated/instructions/openPosition.d.ts +88 -0
- package/dist/generated/instructions/openPosition.d.ts.map +1 -0
- package/dist/generated/instructions/openPosition.js +200 -0
- package/dist/generated/instructions/setMetadataUpdateAuthority.d.ts +52 -0
- package/dist/generated/instructions/setMetadataUpdateAuthority.d.ts.map +1 -0
- package/dist/generated/instructions/setMetadataUpdateAuthority.js +98 -0
- package/dist/generated/instructions/setPoolDynamicFeeConfig.d.ts +57 -0
- package/dist/generated/instructions/setPoolDynamicFeeConfig.d.ts.map +1 -0
- package/dist/generated/instructions/setPoolDynamicFeeConfig.js +107 -0
- package/dist/generated/instructions/setPoolProtocolShare.d.ts +56 -0
- package/dist/generated/instructions/setPoolProtocolShare.d.ts.map +1 -0
- package/dist/generated/instructions/setPoolProtocolShare.js +106 -0
- package/dist/generated/instructions/swap.d.ts +74 -0
- package/dist/generated/instructions/swap.d.ts.map +1 -0
- package/dist/generated/instructions/swap.js +108 -0
- package/dist/generated/instructions/syncPool.d.ts +44 -0
- package/dist/generated/instructions/syncPool.d.ts.map +1 -0
- package/dist/generated/instructions/syncPool.js +71 -0
- package/dist/generated/instructions/transferAdminAuthority.d.ts +52 -0
- package/dist/generated/instructions/transferAdminAuthority.d.ts.map +1 -0
- package/dist/generated/instructions/transferAdminAuthority.js +98 -0
- package/dist/generated/instructions/withdraw.d.ts +86 -0
- package/dist/generated/instructions/withdraw.d.ts.map +1 -0
- package/dist/generated/instructions/withdraw.js +129 -0
- package/dist/generated/pdas/adminConfig.d.ts +12 -0
- package/dist/generated/pdas/adminConfig.d.ts.map +1 -0
- package/dist/generated/pdas/adminConfig.js +19 -0
- package/dist/generated/pdas/binArray.d.ts +16 -0
- package/dist/generated/pdas/binArray.d.ts.map +1 -0
- package/dist/generated/pdas/binArray.js +19 -0
- package/dist/generated/pdas/index.d.ts +12 -0
- package/dist/generated/pdas/index.d.ts.map +1 -0
- package/dist/generated/pdas/index.js +11 -0
- package/dist/generated/pdas/pool.d.ts +18 -0
- package/dist/generated/pdas/pool.d.ts.map +1 -0
- package/dist/generated/pdas/pool.js +21 -0
- package/dist/generated/pdas/position.d.ts +15 -0
- package/dist/generated/pdas/position.d.ts.map +1 -0
- package/dist/generated/pdas/position.js +18 -0
- package/dist/generated/programs/index.d.ts +9 -0
- package/dist/generated/programs/index.d.ts.map +1 -0
- package/dist/generated/programs/index.js +8 -0
- package/dist/generated/programs/piconDlmm.d.ts +126 -0
- package/dist/generated/programs/piconDlmm.d.ts.map +1 -0
- package/dist/generated/programs/piconDlmm.js +285 -0
- package/dist/generated/types/bin.d.ts +28 -0
- package/dist/generated/types/bin.d.ts.map +1 -0
- package/dist/generated/types/bin.js +31 -0
- package/dist/generated/types/distributionMode.d.ts +19 -0
- package/dist/generated/types/distributionMode.d.ts.map +1 -0
- package/dist/generated/types/distributionMode.js +24 -0
- package/dist/generated/types/dynamicFeeConfig.d.ts +29 -0
- package/dist/generated/types/dynamicFeeConfig.d.ts.map +1 -0
- package/dist/generated/types/dynamicFeeConfig.js +29 -0
- package/dist/generated/types/dynamicFeeState.d.ts +27 -0
- package/dist/generated/types/dynamicFeeState.d.ts.map +1 -0
- package/dist/generated/types/dynamicFeeState.js +30 -0
- package/dist/generated/types/feeState.d.ts +26 -0
- package/dist/generated/types/feeState.d.ts.map +1 -0
- package/dist/generated/types/feeState.js +29 -0
- package/dist/generated/types/index.d.ts +13 -0
- package/dist/generated/types/index.d.ts.map +1 -0
- package/dist/generated/types/index.js +12 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/picon_dlmm.json +2378 -0
- package/dist/program_addresses.d.ts +4 -0
- package/dist/program_addresses.d.ts.map +1 -0
- package/dist/program_addresses.js +8 -0
- package/dist/quote/index.d.ts +4 -0
- package/dist/quote/index.d.ts.map +1 -0
- package/dist/quote/index.js +5 -0
- package/dist/quote/wasm-node/picon_dlmm_quote.d.ts +6 -0
- package/dist/quote/wasm-node/picon_dlmm_quote.d.ts.map +1 -0
- package/dist/quote/wasm-node/picon_dlmm_quote.js +398 -0
- package/dist/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
- package/dist/quote/wasm-node-loader.d.ts +4 -0
- package/dist/quote/wasm-node-loader.d.ts.map +1 -0
- package/dist/quote/wasm-node-loader.js +7 -0
- package/dist/quote/wasm-web/picon_dlmm_quote.d.ts +9 -0
- package/dist/quote/wasm-web/picon_dlmm_quote.d.ts.map +1 -0
- package/dist/quote/wasm-web/picon_dlmm_quote.js +486 -0
- package/dist/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
- package/dist/quote/wasm-web-loader.d.ts +4 -0
- package/dist/quote/wasm-web-loader.d.ts.map +1 -0
- package/dist/quote/wasm-web-loader.js +12 -0
- package/dist/utils/admin_config.d.ts +3 -0
- package/dist/utils/admin_config.d.ts.map +1 -0
- package/dist/utils/admin_config.js +4 -0
- package/dist/utils/ata.d.ts +49 -0
- package/dist/utils/ata.d.ts.map +1 -0
- package/dist/utils/ata.js +113 -0
- package/dist/utils/bin_array.d.ts +8 -0
- package/dist/utils/bin_array.d.ts.map +1 -0
- package/dist/utils/bin_array.js +29 -0
- package/dist/utils/bin_location.d.ts +11 -0
- package/dist/utils/bin_location.d.ts.map +1 -0
- package/dist/utils/bin_location.js +55 -0
- package/dist/utils/chunk.d.ts +2 -0
- package/dist/utils/chunk.d.ts.map +1 -0
- package/dist/utils/chunk.js +7 -0
- package/dist/utils/compute_budget.d.ts +11 -0
- package/dist/utils/compute_budget.d.ts.map +1 -0
- package/dist/utils/compute_budget.js +22 -0
- package/dist/utils/constants.d.ts +12 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +20 -0
- package/dist/utils/transfer_fee.d.ts +4 -0
- package/dist/utils/transfer_fee.d.ts.map +1 -0
- package/dist/utils/transfer_fee.js +21 -0
- package/dist/utils/type_guards.d.ts +2 -0
- package/dist/utils/type_guards.d.ts.map +1 -0
- package/dist/utils/type_guards.js +3 -0
- package/package.json +59 -0
- package/src/actions/accept_admin_authority.ts +17 -0
- package/src/actions/claim_fee.ts +84 -0
- package/src/actions/claim_multiple_fees.ts +123 -0
- package/src/actions/claim_protocol_fee.ts +68 -0
- package/src/actions/close_position.ts +21 -0
- package/src/actions/create_admin_config.ts +50 -0
- package/src/actions/create_bin_array.ts +30 -0
- package/src/actions/create_pool.ts +49 -0
- package/src/actions/delete_bin_array.ts +33 -0
- package/src/actions/deposit_by_weight.ts +107 -0
- package/src/actions/get_admin_config.ts +13 -0
- package/src/actions/get_bin_arrays_by_indices.ts +15 -0
- package/src/actions/get_pool.ts +8 -0
- package/src/actions/get_position.ts +8 -0
- package/src/actions/get_position_by_position_mint.ts +14 -0
- package/src/actions/get_positions_by_owner.ts +48 -0
- package/src/actions/get_positions_by_position_mints.ts +21 -0
- package/src/actions/helpers/build_swap_transaction_message.ts +86 -0
- package/src/actions/helpers/build_transaction_message.ts +45 -0
- package/src/actions/helpers/index.ts +7 -0
- package/src/actions/helpers/resolve_active_bin_and_mints.ts +21 -0
- package/src/actions/helpers/resolve_admin_config_address.ts +11 -0
- package/src/actions/helpers/resolve_mint_info.ts +36 -0
- package/src/actions/helpers/resolve_position_range.ts +21 -0
- package/src/actions/helpers/resolve_token_mints_and_programs.ts +56 -0
- package/src/actions/index.ts +34 -0
- package/src/actions/is_admin_config_active.ts +14 -0
- package/src/actions/on_event.ts +78 -0
- package/src/actions/open_position.ts +66 -0
- package/src/actions/quote.ts +70 -0
- package/src/actions/set_metadata_update_authority.ts +17 -0
- package/src/actions/set_pool_dynamic_fee_config.ts +17 -0
- package/src/actions/set_pool_protocol_share.ts +17 -0
- package/src/actions/swap.ts +56 -0
- package/src/actions/sync_pool.ts +35 -0
- package/src/actions/transfer_admin_authority.ts +17 -0
- package/src/actions/withdraw.ts +87 -0
- package/src/events.ts +279 -0
- package/src/generated/accounts/adminConfig.ts +147 -0
- package/src/generated/accounts/binArray.ts +155 -0
- package/src/generated/accounts/index.ts +12 -0
- package/src/generated/accounts/pool.ts +192 -0
- package/src/generated/accounts/position.ts +164 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/piconDlmm.ts +124 -0
- package/src/generated/index.ts +14 -0
- package/src/generated/instructions/acceptAdminAuthority.ts +262 -0
- package/src/generated/instructions/claimFee.ts +395 -0
- package/src/generated/instructions/claimProtocolFee.ts +462 -0
- package/src/generated/instructions/closePosition.ts +342 -0
- package/src/generated/instructions/createAdminConfig.ts +369 -0
- package/src/generated/instructions/createBinArray.ts +344 -0
- package/src/generated/instructions/createPool.ts +582 -0
- package/src/generated/instructions/deleteBinArray.ts +365 -0
- package/src/generated/instructions/depositByWeight.ts +435 -0
- package/src/generated/instructions/index.ts +25 -0
- package/src/generated/instructions/openPosition.ts +547 -0
- package/src/generated/instructions/setMetadataUpdateAuthority.ts +274 -0
- package/src/generated/instructions/setPoolDynamicFeeConfig.ts +304 -0
- package/src/generated/instructions/setPoolProtocolShare.ts +298 -0
- package/src/generated/instructions/swap.ts +336 -0
- package/src/generated/instructions/syncPool.ts +189 -0
- package/src/generated/instructions/transferAdminAuthority.ts +271 -0
- package/src/generated/instructions/withdraw.ts +402 -0
- package/src/generated/pdas/adminConfig.ts +32 -0
- package/src/generated/pdas/binArray.ts +40 -0
- package/src/generated/pdas/index.ts +12 -0
- package/src/generated/pdas/pool.ts +43 -0
- package/src/generated/pdas/position.ts +37 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/piconDlmm.ts +803 -0
- package/src/generated/types/bin.ts +64 -0
- package/src/generated/types/distributionMode.ts +43 -0
- package/src/generated/types/dynamicFeeConfig.ts +69 -0
- package/src/generated/types/dynamicFeeState.ts +71 -0
- package/src/generated/types/feeState.ts +60 -0
- package/src/generated/types/index.ts +13 -0
- package/src/index.ts +4 -0
- package/src/picon_dlmm.json +2378 -0
- package/src/program_addresses.ts +10 -0
- package/src/quote/index.ts +14 -0
- package/src/quote/wasm-node/package.json +4 -0
- package/src/quote/wasm-node/picon_dlmm_quote.d.ts +64 -0
- package/src/quote/wasm-node/picon_dlmm_quote.js +407 -0
- package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm +0 -0
- package/src/quote/wasm-node/picon_dlmm_quote_bg.wasm.d.ts +11 -0
- package/src/quote/wasm-node-loader.ts +11 -0
- package/src/quote/wasm-web/picon_dlmm_quote.d.ts +100 -0
- package/src/quote/wasm-web/picon_dlmm_quote.js +500 -0
- package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm +0 -0
- package/src/quote/wasm-web/picon_dlmm_quote_bg.wasm.d.ts +11 -0
- package/src/quote/wasm-web-loader.ts +17 -0
- package/src/utils/admin_config.ts +6 -0
- package/src/utils/ata.ts +213 -0
- package/src/utils/bin_array.ts +45 -0
- package/src/utils/bin_location.ts +79 -0
- package/src/utils/chunk.ts +7 -0
- package/src/utils/compute_budget.ts +58 -0
- package/src/utils/constants.ts +24 -0
- package/src/utils/transfer_fee.ts +29 -0
- package/src/utils/type_guards.ts +3 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
fixDecoderSize,
|
|
12
|
+
fixEncoderSize,
|
|
13
|
+
getBytesDecoder,
|
|
14
|
+
getBytesEncoder,
|
|
15
|
+
getStructDecoder,
|
|
16
|
+
getStructEncoder,
|
|
17
|
+
getU16Decoder,
|
|
18
|
+
getU16Encoder,
|
|
19
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
20
|
+
SolanaError,
|
|
21
|
+
transformEncoder,
|
|
22
|
+
type AccountMeta,
|
|
23
|
+
type AccountSignerMeta,
|
|
24
|
+
type Address,
|
|
25
|
+
type FixedSizeCodec,
|
|
26
|
+
type FixedSizeDecoder,
|
|
27
|
+
type FixedSizeEncoder,
|
|
28
|
+
type Instruction,
|
|
29
|
+
type InstructionWithAccounts,
|
|
30
|
+
type InstructionWithData,
|
|
31
|
+
type ReadonlyAccount,
|
|
32
|
+
type ReadonlySignerAccount,
|
|
33
|
+
type ReadonlyUint8Array,
|
|
34
|
+
type TransactionSigner,
|
|
35
|
+
type WritableAccount,
|
|
36
|
+
} from "@solana/kit";
|
|
37
|
+
import {
|
|
38
|
+
getAccountMetaFactory,
|
|
39
|
+
type ResolvedInstructionAccount,
|
|
40
|
+
} from "@solana/program-client-core";
|
|
41
|
+
import { findAdminConfigPda } from "../pdas";
|
|
42
|
+
import { PICON_DLMM_PROGRAM_ADDRESS } from "../programs";
|
|
43
|
+
|
|
44
|
+
export const SET_POOL_PROTOCOL_SHARE_DISCRIMINATOR: ReadonlyUint8Array =
|
|
45
|
+
new Uint8Array([16, 138, 62, 186, 255, 137, 75, 193]);
|
|
46
|
+
|
|
47
|
+
export function getSetPoolProtocolShareDiscriminatorBytes(): ReadonlyUint8Array {
|
|
48
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
49
|
+
SET_POOL_PROTOCOL_SHARE_DISCRIMINATOR,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SetPoolProtocolShareInstruction<
|
|
54
|
+
TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
55
|
+
TAccountAuthority extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountAdminConfig extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountPool extends string | AccountMeta<string> = string,
|
|
58
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
59
|
+
> = Instruction<TProgram> &
|
|
60
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
61
|
+
InstructionWithAccounts<
|
|
62
|
+
[
|
|
63
|
+
TAccountAuthority extends string
|
|
64
|
+
? ReadonlySignerAccount<TAccountAuthority> &
|
|
65
|
+
AccountSignerMeta<TAccountAuthority>
|
|
66
|
+
: TAccountAuthority,
|
|
67
|
+
TAccountAdminConfig extends string
|
|
68
|
+
? ReadonlyAccount<TAccountAdminConfig>
|
|
69
|
+
: TAccountAdminConfig,
|
|
70
|
+
TAccountPool extends string
|
|
71
|
+
? WritableAccount<TAccountPool>
|
|
72
|
+
: TAccountPool,
|
|
73
|
+
...TRemainingAccounts,
|
|
74
|
+
]
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
export type SetPoolProtocolShareInstructionData = {
|
|
78
|
+
discriminator: ReadonlyUint8Array;
|
|
79
|
+
protocolShare: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type SetPoolProtocolShareInstructionDataArgs = { protocolShare: number };
|
|
83
|
+
|
|
84
|
+
export function getSetPoolProtocolShareInstructionDataEncoder(): FixedSizeEncoder<SetPoolProtocolShareInstructionDataArgs> {
|
|
85
|
+
return transformEncoder(
|
|
86
|
+
getStructEncoder([
|
|
87
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
88
|
+
["protocolShare", getU16Encoder()],
|
|
89
|
+
]),
|
|
90
|
+
(value) => ({
|
|
91
|
+
...value,
|
|
92
|
+
discriminator: SET_POOL_PROTOCOL_SHARE_DISCRIMINATOR,
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function getSetPoolProtocolShareInstructionDataDecoder(): FixedSizeDecoder<SetPoolProtocolShareInstructionData> {
|
|
98
|
+
return getStructDecoder([
|
|
99
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
100
|
+
["protocolShare", getU16Decoder()],
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getSetPoolProtocolShareInstructionDataCodec(): FixedSizeCodec<
|
|
105
|
+
SetPoolProtocolShareInstructionDataArgs,
|
|
106
|
+
SetPoolProtocolShareInstructionData
|
|
107
|
+
> {
|
|
108
|
+
return combineCodec(
|
|
109
|
+
getSetPoolProtocolShareInstructionDataEncoder(),
|
|
110
|
+
getSetPoolProtocolShareInstructionDataDecoder(),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type SetPoolProtocolShareAsyncInput<
|
|
115
|
+
TAccountAuthority extends string = string,
|
|
116
|
+
TAccountAdminConfig extends string = string,
|
|
117
|
+
TAccountPool extends string = string,
|
|
118
|
+
> = {
|
|
119
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
120
|
+
adminConfig?: Address<TAccountAdminConfig>;
|
|
121
|
+
pool: Address<TAccountPool>;
|
|
122
|
+
protocolShare: SetPoolProtocolShareInstructionDataArgs["protocolShare"];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export async function getSetPoolProtocolShareInstructionAsync<
|
|
126
|
+
TAccountAuthority extends string,
|
|
127
|
+
TAccountAdminConfig extends string,
|
|
128
|
+
TAccountPool extends string,
|
|
129
|
+
TProgramAddress extends Address = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
130
|
+
>(
|
|
131
|
+
input: SetPoolProtocolShareAsyncInput<
|
|
132
|
+
TAccountAuthority,
|
|
133
|
+
TAccountAdminConfig,
|
|
134
|
+
TAccountPool
|
|
135
|
+
>,
|
|
136
|
+
config?: { programAddress?: TProgramAddress },
|
|
137
|
+
): Promise<
|
|
138
|
+
SetPoolProtocolShareInstruction<
|
|
139
|
+
TProgramAddress,
|
|
140
|
+
TAccountAuthority,
|
|
141
|
+
TAccountAdminConfig,
|
|
142
|
+
TAccountPool
|
|
143
|
+
>
|
|
144
|
+
> {
|
|
145
|
+
// Program address.
|
|
146
|
+
const programAddress = config?.programAddress ?? PICON_DLMM_PROGRAM_ADDRESS;
|
|
147
|
+
|
|
148
|
+
// Original accounts.
|
|
149
|
+
const originalAccounts = {
|
|
150
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
151
|
+
adminConfig: { value: input.adminConfig ?? null, isWritable: false },
|
|
152
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
153
|
+
};
|
|
154
|
+
const accounts = originalAccounts as Record<
|
|
155
|
+
keyof typeof originalAccounts,
|
|
156
|
+
ResolvedInstructionAccount
|
|
157
|
+
>;
|
|
158
|
+
|
|
159
|
+
// Original args.
|
|
160
|
+
const args = { ...input };
|
|
161
|
+
|
|
162
|
+
// Resolve default values.
|
|
163
|
+
if (!accounts.adminConfig.value) {
|
|
164
|
+
accounts.adminConfig.value = await findAdminConfigPda();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
168
|
+
return Object.freeze({
|
|
169
|
+
accounts: [
|
|
170
|
+
getAccountMeta("authority", accounts.authority),
|
|
171
|
+
getAccountMeta("adminConfig", accounts.adminConfig),
|
|
172
|
+
getAccountMeta("pool", accounts.pool),
|
|
173
|
+
],
|
|
174
|
+
data: getSetPoolProtocolShareInstructionDataEncoder().encode(
|
|
175
|
+
args as SetPoolProtocolShareInstructionDataArgs,
|
|
176
|
+
),
|
|
177
|
+
programAddress,
|
|
178
|
+
} as SetPoolProtocolShareInstruction<
|
|
179
|
+
TProgramAddress,
|
|
180
|
+
TAccountAuthority,
|
|
181
|
+
TAccountAdminConfig,
|
|
182
|
+
TAccountPool
|
|
183
|
+
>);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type SetPoolProtocolShareInput<
|
|
187
|
+
TAccountAuthority extends string = string,
|
|
188
|
+
TAccountAdminConfig extends string = string,
|
|
189
|
+
TAccountPool extends string = string,
|
|
190
|
+
> = {
|
|
191
|
+
authority: TransactionSigner<TAccountAuthority>;
|
|
192
|
+
adminConfig: Address<TAccountAdminConfig>;
|
|
193
|
+
pool: Address<TAccountPool>;
|
|
194
|
+
protocolShare: SetPoolProtocolShareInstructionDataArgs["protocolShare"];
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export function getSetPoolProtocolShareInstruction<
|
|
198
|
+
TAccountAuthority extends string,
|
|
199
|
+
TAccountAdminConfig extends string,
|
|
200
|
+
TAccountPool extends string,
|
|
201
|
+
TProgramAddress extends Address = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
202
|
+
>(
|
|
203
|
+
input: SetPoolProtocolShareInput<
|
|
204
|
+
TAccountAuthority,
|
|
205
|
+
TAccountAdminConfig,
|
|
206
|
+
TAccountPool
|
|
207
|
+
>,
|
|
208
|
+
config?: { programAddress?: TProgramAddress },
|
|
209
|
+
): SetPoolProtocolShareInstruction<
|
|
210
|
+
TProgramAddress,
|
|
211
|
+
TAccountAuthority,
|
|
212
|
+
TAccountAdminConfig,
|
|
213
|
+
TAccountPool
|
|
214
|
+
> {
|
|
215
|
+
// Program address.
|
|
216
|
+
const programAddress = config?.programAddress ?? PICON_DLMM_PROGRAM_ADDRESS;
|
|
217
|
+
|
|
218
|
+
// Original accounts.
|
|
219
|
+
const originalAccounts = {
|
|
220
|
+
authority: { value: input.authority ?? null, isWritable: false },
|
|
221
|
+
adminConfig: { value: input.adminConfig ?? null, isWritable: false },
|
|
222
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
223
|
+
};
|
|
224
|
+
const accounts = originalAccounts as Record<
|
|
225
|
+
keyof typeof originalAccounts,
|
|
226
|
+
ResolvedInstructionAccount
|
|
227
|
+
>;
|
|
228
|
+
|
|
229
|
+
// Original args.
|
|
230
|
+
const args = { ...input };
|
|
231
|
+
|
|
232
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
233
|
+
return Object.freeze({
|
|
234
|
+
accounts: [
|
|
235
|
+
getAccountMeta("authority", accounts.authority),
|
|
236
|
+
getAccountMeta("adminConfig", accounts.adminConfig),
|
|
237
|
+
getAccountMeta("pool", accounts.pool),
|
|
238
|
+
],
|
|
239
|
+
data: getSetPoolProtocolShareInstructionDataEncoder().encode(
|
|
240
|
+
args as SetPoolProtocolShareInstructionDataArgs,
|
|
241
|
+
),
|
|
242
|
+
programAddress,
|
|
243
|
+
} as SetPoolProtocolShareInstruction<
|
|
244
|
+
TProgramAddress,
|
|
245
|
+
TAccountAuthority,
|
|
246
|
+
TAccountAdminConfig,
|
|
247
|
+
TAccountPool
|
|
248
|
+
>);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export type ParsedSetPoolProtocolShareInstruction<
|
|
252
|
+
TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
253
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
254
|
+
> = {
|
|
255
|
+
programAddress: Address<TProgram>;
|
|
256
|
+
accounts: {
|
|
257
|
+
authority: TAccountMetas[0];
|
|
258
|
+
adminConfig: TAccountMetas[1];
|
|
259
|
+
pool: TAccountMetas[2];
|
|
260
|
+
};
|
|
261
|
+
data: SetPoolProtocolShareInstructionData;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export function parseSetPoolProtocolShareInstruction<
|
|
265
|
+
TProgram extends string,
|
|
266
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
267
|
+
>(
|
|
268
|
+
instruction: Instruction<TProgram> &
|
|
269
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
270
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
271
|
+
): ParsedSetPoolProtocolShareInstruction<TProgram, TAccountMetas> {
|
|
272
|
+
if (instruction.accounts.length < 3) {
|
|
273
|
+
throw new SolanaError(
|
|
274
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
275
|
+
{
|
|
276
|
+
actualAccountMetas: instruction.accounts.length,
|
|
277
|
+
expectedAccountMetas: 3,
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
let accountIndex = 0;
|
|
282
|
+
const getNextAccount = () => {
|
|
283
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
284
|
+
accountIndex += 1;
|
|
285
|
+
return accountMeta;
|
|
286
|
+
};
|
|
287
|
+
return {
|
|
288
|
+
programAddress: instruction.programAddress,
|
|
289
|
+
accounts: {
|
|
290
|
+
authority: getNextAccount(),
|
|
291
|
+
adminConfig: getNextAccount(),
|
|
292
|
+
pool: getNextAccount(),
|
|
293
|
+
},
|
|
294
|
+
data: getSetPoolProtocolShareInstructionDataDecoder().decode(
|
|
295
|
+
instruction.data,
|
|
296
|
+
),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
fixDecoderSize,
|
|
12
|
+
fixEncoderSize,
|
|
13
|
+
getBooleanDecoder,
|
|
14
|
+
getBooleanEncoder,
|
|
15
|
+
getBytesDecoder,
|
|
16
|
+
getBytesEncoder,
|
|
17
|
+
getStructDecoder,
|
|
18
|
+
getStructEncoder,
|
|
19
|
+
getU64Decoder,
|
|
20
|
+
getU64Encoder,
|
|
21
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
22
|
+
SolanaError,
|
|
23
|
+
transformEncoder,
|
|
24
|
+
type AccountMeta,
|
|
25
|
+
type AccountSignerMeta,
|
|
26
|
+
type Address,
|
|
27
|
+
type FixedSizeCodec,
|
|
28
|
+
type FixedSizeDecoder,
|
|
29
|
+
type FixedSizeEncoder,
|
|
30
|
+
type Instruction,
|
|
31
|
+
type InstructionWithAccounts,
|
|
32
|
+
type InstructionWithData,
|
|
33
|
+
type ReadonlyAccount,
|
|
34
|
+
type ReadonlySignerAccount,
|
|
35
|
+
type ReadonlyUint8Array,
|
|
36
|
+
type TransactionSigner,
|
|
37
|
+
type WritableAccount,
|
|
38
|
+
} from "@solana/kit";
|
|
39
|
+
import {
|
|
40
|
+
getAccountMetaFactory,
|
|
41
|
+
type ResolvedInstructionAccount,
|
|
42
|
+
} from "@solana/program-client-core";
|
|
43
|
+
import { PICON_DLMM_PROGRAM_ADDRESS } from "../programs";
|
|
44
|
+
|
|
45
|
+
export const SWAP_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
|
46
|
+
248, 198, 158, 145, 225, 117, 135, 200,
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export function getSwapDiscriminatorBytes(): ReadonlyUint8Array {
|
|
50
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(SWAP_DISCRIMINATOR);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type SwapInstruction<
|
|
54
|
+
TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
55
|
+
TAccountUser extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountPool extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountTokenMintX extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountTokenMintY extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountTokenUserAccountX extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountTokenUserAccountY extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountTokenVaultX extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountTokenVaultY extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountTokenProgramX extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountTokenProgramY extends string | AccountMeta<string> = string,
|
|
65
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
66
|
+
> = Instruction<TProgram> &
|
|
67
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
68
|
+
InstructionWithAccounts<
|
|
69
|
+
[
|
|
70
|
+
TAccountUser extends string
|
|
71
|
+
? ReadonlySignerAccount<TAccountUser> & AccountSignerMeta<TAccountUser>
|
|
72
|
+
: TAccountUser,
|
|
73
|
+
TAccountPool extends string
|
|
74
|
+
? WritableAccount<TAccountPool>
|
|
75
|
+
: TAccountPool,
|
|
76
|
+
TAccountTokenMintX extends string
|
|
77
|
+
? ReadonlyAccount<TAccountTokenMintX>
|
|
78
|
+
: TAccountTokenMintX,
|
|
79
|
+
TAccountTokenMintY extends string
|
|
80
|
+
? ReadonlyAccount<TAccountTokenMintY>
|
|
81
|
+
: TAccountTokenMintY,
|
|
82
|
+
TAccountTokenUserAccountX extends string
|
|
83
|
+
? WritableAccount<TAccountTokenUserAccountX>
|
|
84
|
+
: TAccountTokenUserAccountX,
|
|
85
|
+
TAccountTokenUserAccountY extends string
|
|
86
|
+
? WritableAccount<TAccountTokenUserAccountY>
|
|
87
|
+
: TAccountTokenUserAccountY,
|
|
88
|
+
TAccountTokenVaultX extends string
|
|
89
|
+
? WritableAccount<TAccountTokenVaultX>
|
|
90
|
+
: TAccountTokenVaultX,
|
|
91
|
+
TAccountTokenVaultY extends string
|
|
92
|
+
? WritableAccount<TAccountTokenVaultY>
|
|
93
|
+
: TAccountTokenVaultY,
|
|
94
|
+
TAccountTokenProgramX extends string
|
|
95
|
+
? ReadonlyAccount<TAccountTokenProgramX>
|
|
96
|
+
: TAccountTokenProgramX,
|
|
97
|
+
TAccountTokenProgramY extends string
|
|
98
|
+
? ReadonlyAccount<TAccountTokenProgramY>
|
|
99
|
+
: TAccountTokenProgramY,
|
|
100
|
+
...TRemainingAccounts,
|
|
101
|
+
]
|
|
102
|
+
>;
|
|
103
|
+
|
|
104
|
+
export type SwapInstructionData = {
|
|
105
|
+
discriminator: ReadonlyUint8Array;
|
|
106
|
+
amountIn: bigint;
|
|
107
|
+
minAmountOut: bigint;
|
|
108
|
+
xToY: boolean;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type SwapInstructionDataArgs = {
|
|
112
|
+
amountIn: number | bigint;
|
|
113
|
+
minAmountOut: number | bigint;
|
|
114
|
+
xToY: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export function getSwapInstructionDataEncoder(): FixedSizeEncoder<SwapInstructionDataArgs> {
|
|
118
|
+
return transformEncoder(
|
|
119
|
+
getStructEncoder([
|
|
120
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
121
|
+
["amountIn", getU64Encoder()],
|
|
122
|
+
["minAmountOut", getU64Encoder()],
|
|
123
|
+
["xToY", getBooleanEncoder()],
|
|
124
|
+
]),
|
|
125
|
+
(value) => ({ ...value, discriminator: SWAP_DISCRIMINATOR }),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getSwapInstructionDataDecoder(): FixedSizeDecoder<SwapInstructionData> {
|
|
130
|
+
return getStructDecoder([
|
|
131
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
132
|
+
["amountIn", getU64Decoder()],
|
|
133
|
+
["minAmountOut", getU64Decoder()],
|
|
134
|
+
["xToY", getBooleanDecoder()],
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getSwapInstructionDataCodec(): FixedSizeCodec<
|
|
139
|
+
SwapInstructionDataArgs,
|
|
140
|
+
SwapInstructionData
|
|
141
|
+
> {
|
|
142
|
+
return combineCodec(
|
|
143
|
+
getSwapInstructionDataEncoder(),
|
|
144
|
+
getSwapInstructionDataDecoder(),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type SwapInput<
|
|
149
|
+
TAccountUser extends string = string,
|
|
150
|
+
TAccountPool extends string = string,
|
|
151
|
+
TAccountTokenMintX extends string = string,
|
|
152
|
+
TAccountTokenMintY extends string = string,
|
|
153
|
+
TAccountTokenUserAccountX extends string = string,
|
|
154
|
+
TAccountTokenUserAccountY extends string = string,
|
|
155
|
+
TAccountTokenVaultX extends string = string,
|
|
156
|
+
TAccountTokenVaultY extends string = string,
|
|
157
|
+
TAccountTokenProgramX extends string = string,
|
|
158
|
+
TAccountTokenProgramY extends string = string,
|
|
159
|
+
> = {
|
|
160
|
+
user: TransactionSigner<TAccountUser>;
|
|
161
|
+
pool: Address<TAccountPool>;
|
|
162
|
+
tokenMintX: Address<TAccountTokenMintX>;
|
|
163
|
+
tokenMintY: Address<TAccountTokenMintY>;
|
|
164
|
+
tokenUserAccountX: Address<TAccountTokenUserAccountX>;
|
|
165
|
+
tokenUserAccountY: Address<TAccountTokenUserAccountY>;
|
|
166
|
+
tokenVaultX: Address<TAccountTokenVaultX>;
|
|
167
|
+
tokenVaultY: Address<TAccountTokenVaultY>;
|
|
168
|
+
tokenProgramX: Address<TAccountTokenProgramX>;
|
|
169
|
+
tokenProgramY: Address<TAccountTokenProgramY>;
|
|
170
|
+
amountIn: SwapInstructionDataArgs["amountIn"];
|
|
171
|
+
minAmountOut: SwapInstructionDataArgs["minAmountOut"];
|
|
172
|
+
xToY: SwapInstructionDataArgs["xToY"];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export function getSwapInstruction<
|
|
176
|
+
TAccountUser extends string,
|
|
177
|
+
TAccountPool extends string,
|
|
178
|
+
TAccountTokenMintX extends string,
|
|
179
|
+
TAccountTokenMintY extends string,
|
|
180
|
+
TAccountTokenUserAccountX extends string,
|
|
181
|
+
TAccountTokenUserAccountY extends string,
|
|
182
|
+
TAccountTokenVaultX extends string,
|
|
183
|
+
TAccountTokenVaultY extends string,
|
|
184
|
+
TAccountTokenProgramX extends string,
|
|
185
|
+
TAccountTokenProgramY extends string,
|
|
186
|
+
TProgramAddress extends Address = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
187
|
+
>(
|
|
188
|
+
input: SwapInput<
|
|
189
|
+
TAccountUser,
|
|
190
|
+
TAccountPool,
|
|
191
|
+
TAccountTokenMintX,
|
|
192
|
+
TAccountTokenMintY,
|
|
193
|
+
TAccountTokenUserAccountX,
|
|
194
|
+
TAccountTokenUserAccountY,
|
|
195
|
+
TAccountTokenVaultX,
|
|
196
|
+
TAccountTokenVaultY,
|
|
197
|
+
TAccountTokenProgramX,
|
|
198
|
+
TAccountTokenProgramY
|
|
199
|
+
>,
|
|
200
|
+
config?: { programAddress?: TProgramAddress },
|
|
201
|
+
): SwapInstruction<
|
|
202
|
+
TProgramAddress,
|
|
203
|
+
TAccountUser,
|
|
204
|
+
TAccountPool,
|
|
205
|
+
TAccountTokenMintX,
|
|
206
|
+
TAccountTokenMintY,
|
|
207
|
+
TAccountTokenUserAccountX,
|
|
208
|
+
TAccountTokenUserAccountY,
|
|
209
|
+
TAccountTokenVaultX,
|
|
210
|
+
TAccountTokenVaultY,
|
|
211
|
+
TAccountTokenProgramX,
|
|
212
|
+
TAccountTokenProgramY
|
|
213
|
+
> {
|
|
214
|
+
// Program address.
|
|
215
|
+
const programAddress = config?.programAddress ?? PICON_DLMM_PROGRAM_ADDRESS;
|
|
216
|
+
|
|
217
|
+
// Original accounts.
|
|
218
|
+
const originalAccounts = {
|
|
219
|
+
user: { value: input.user ?? null, isWritable: false },
|
|
220
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
221
|
+
tokenMintX: { value: input.tokenMintX ?? null, isWritable: false },
|
|
222
|
+
tokenMintY: { value: input.tokenMintY ?? null, isWritable: false },
|
|
223
|
+
tokenUserAccountX: {
|
|
224
|
+
value: input.tokenUserAccountX ?? null,
|
|
225
|
+
isWritable: true,
|
|
226
|
+
},
|
|
227
|
+
tokenUserAccountY: {
|
|
228
|
+
value: input.tokenUserAccountY ?? null,
|
|
229
|
+
isWritable: true,
|
|
230
|
+
},
|
|
231
|
+
tokenVaultX: { value: input.tokenVaultX ?? null, isWritable: true },
|
|
232
|
+
tokenVaultY: { value: input.tokenVaultY ?? null, isWritable: true },
|
|
233
|
+
tokenProgramX: { value: input.tokenProgramX ?? null, isWritable: false },
|
|
234
|
+
tokenProgramY: { value: input.tokenProgramY ?? null, isWritable: false },
|
|
235
|
+
};
|
|
236
|
+
const accounts = originalAccounts as Record<
|
|
237
|
+
keyof typeof originalAccounts,
|
|
238
|
+
ResolvedInstructionAccount
|
|
239
|
+
>;
|
|
240
|
+
|
|
241
|
+
// Original args.
|
|
242
|
+
const args = { ...input };
|
|
243
|
+
|
|
244
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
245
|
+
return Object.freeze({
|
|
246
|
+
accounts: [
|
|
247
|
+
getAccountMeta("user", accounts.user),
|
|
248
|
+
getAccountMeta("pool", accounts.pool),
|
|
249
|
+
getAccountMeta("tokenMintX", accounts.tokenMintX),
|
|
250
|
+
getAccountMeta("tokenMintY", accounts.tokenMintY),
|
|
251
|
+
getAccountMeta("tokenUserAccountX", accounts.tokenUserAccountX),
|
|
252
|
+
getAccountMeta("tokenUserAccountY", accounts.tokenUserAccountY),
|
|
253
|
+
getAccountMeta("tokenVaultX", accounts.tokenVaultX),
|
|
254
|
+
getAccountMeta("tokenVaultY", accounts.tokenVaultY),
|
|
255
|
+
getAccountMeta("tokenProgramX", accounts.tokenProgramX),
|
|
256
|
+
getAccountMeta("tokenProgramY", accounts.tokenProgramY),
|
|
257
|
+
],
|
|
258
|
+
data: getSwapInstructionDataEncoder().encode(
|
|
259
|
+
args as SwapInstructionDataArgs,
|
|
260
|
+
),
|
|
261
|
+
programAddress,
|
|
262
|
+
} as SwapInstruction<
|
|
263
|
+
TProgramAddress,
|
|
264
|
+
TAccountUser,
|
|
265
|
+
TAccountPool,
|
|
266
|
+
TAccountTokenMintX,
|
|
267
|
+
TAccountTokenMintY,
|
|
268
|
+
TAccountTokenUserAccountX,
|
|
269
|
+
TAccountTokenUserAccountY,
|
|
270
|
+
TAccountTokenVaultX,
|
|
271
|
+
TAccountTokenVaultY,
|
|
272
|
+
TAccountTokenProgramX,
|
|
273
|
+
TAccountTokenProgramY
|
|
274
|
+
>);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type ParsedSwapInstruction<
|
|
278
|
+
TProgram extends string = typeof PICON_DLMM_PROGRAM_ADDRESS,
|
|
279
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
280
|
+
> = {
|
|
281
|
+
programAddress: Address<TProgram>;
|
|
282
|
+
accounts: {
|
|
283
|
+
user: TAccountMetas[0];
|
|
284
|
+
pool: TAccountMetas[1];
|
|
285
|
+
tokenMintX: TAccountMetas[2];
|
|
286
|
+
tokenMintY: TAccountMetas[3];
|
|
287
|
+
tokenUserAccountX: TAccountMetas[4];
|
|
288
|
+
tokenUserAccountY: TAccountMetas[5];
|
|
289
|
+
tokenVaultX: TAccountMetas[6];
|
|
290
|
+
tokenVaultY: TAccountMetas[7];
|
|
291
|
+
tokenProgramX: TAccountMetas[8];
|
|
292
|
+
tokenProgramY: TAccountMetas[9];
|
|
293
|
+
};
|
|
294
|
+
data: SwapInstructionData;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export function parseSwapInstruction<
|
|
298
|
+
TProgram extends string,
|
|
299
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
300
|
+
>(
|
|
301
|
+
instruction: Instruction<TProgram> &
|
|
302
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
303
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
304
|
+
): ParsedSwapInstruction<TProgram, TAccountMetas> {
|
|
305
|
+
if (instruction.accounts.length < 10) {
|
|
306
|
+
throw new SolanaError(
|
|
307
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
308
|
+
{
|
|
309
|
+
actualAccountMetas: instruction.accounts.length,
|
|
310
|
+
expectedAccountMetas: 10,
|
|
311
|
+
},
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
let accountIndex = 0;
|
|
315
|
+
const getNextAccount = () => {
|
|
316
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
317
|
+
accountIndex += 1;
|
|
318
|
+
return accountMeta;
|
|
319
|
+
};
|
|
320
|
+
return {
|
|
321
|
+
programAddress: instruction.programAddress,
|
|
322
|
+
accounts: {
|
|
323
|
+
user: getNextAccount(),
|
|
324
|
+
pool: getNextAccount(),
|
|
325
|
+
tokenMintX: getNextAccount(),
|
|
326
|
+
tokenMintY: getNextAccount(),
|
|
327
|
+
tokenUserAccountX: getNextAccount(),
|
|
328
|
+
tokenUserAccountY: getNextAccount(),
|
|
329
|
+
tokenVaultX: getNextAccount(),
|
|
330
|
+
tokenVaultY: getNextAccount(),
|
|
331
|
+
tokenProgramX: getNextAccount(),
|
|
332
|
+
tokenProgramY: getNextAccount(),
|
|
333
|
+
},
|
|
334
|
+
data: getSwapInstructionDataDecoder().decode(instruction.data),
|
|
335
|
+
};
|
|
336
|
+
}
|