@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
package/src/utils/ata.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
address,
|
|
3
|
+
type Address,
|
|
4
|
+
type Instruction,
|
|
5
|
+
type TransactionSigner,
|
|
6
|
+
} from "@solana/kit";
|
|
7
|
+
import {
|
|
8
|
+
findAssociatedTokenPda,
|
|
9
|
+
getCloseAccountInstruction,
|
|
10
|
+
getCreateAssociatedTokenIdempotentInstruction,
|
|
11
|
+
getSyncNativeInstruction,
|
|
12
|
+
TOKEN_PROGRAM_ADDRESS,
|
|
13
|
+
} from "@solana-program/token";
|
|
14
|
+
import {
|
|
15
|
+
findAssociatedTokenPda as findAssociatedToken2022Pda,
|
|
16
|
+
getCreateAssociatedTokenIdempotentInstruction as getCreateAssociatedToken2022IdempotentInstruction,
|
|
17
|
+
TOKEN_2022_PROGRAM_ADDRESS
|
|
18
|
+
} from "@solana-program/token-2022";
|
|
19
|
+
import { getTransferSolInstruction } from "@solana-program/system";
|
|
20
|
+
|
|
21
|
+
export const NATIVE_MINT_ADDRESS = address("So11111111111111111111111111111111111111112");
|
|
22
|
+
|
|
23
|
+
export async function findAssociatedTokenPdaByTokenProgram(params: {
|
|
24
|
+
owner: Address,
|
|
25
|
+
mint: Address,
|
|
26
|
+
tokenProgram: Address,
|
|
27
|
+
}) {
|
|
28
|
+
const findAssociatedTokenPda = chooseFindAssociatedTokenPda(params.tokenProgram);
|
|
29
|
+
const [ata] = await findAssociatedTokenPda(params);
|
|
30
|
+
return ata;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Position NFTs are always Token2022 — shared by every position-scoped instruction
|
|
34
|
+
// (open_position, close_position, withdraw, claim_fee, claim_multiple_fees, deposit_by_weight).
|
|
35
|
+
export function findPositionTokenAccount({
|
|
36
|
+
owner,
|
|
37
|
+
positionMint,
|
|
38
|
+
}: {
|
|
39
|
+
owner: Address,
|
|
40
|
+
positionMint: Address,
|
|
41
|
+
}): Promise<Address> {
|
|
42
|
+
return findAssociatedTokenPdaByTokenProgram({ owner, mint: positionMint, tokenProgram: TOKEN_2022_PROGRAM_ADDRESS });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A pool's X/Y vaults — shared by every instruction that moves tokens through a pool
|
|
46
|
+
// (withdraw, claim_fee, claim_multiple_fees, claim_protocol_fee, deposit_by_weight, swap).
|
|
47
|
+
export async function findPoolTokenVaults({
|
|
48
|
+
pool,
|
|
49
|
+
tokenMintX,
|
|
50
|
+
tokenMintY,
|
|
51
|
+
tokenProgramX,
|
|
52
|
+
tokenProgramY,
|
|
53
|
+
}: {
|
|
54
|
+
pool: Address,
|
|
55
|
+
tokenMintX: Address,
|
|
56
|
+
tokenMintY: Address,
|
|
57
|
+
tokenProgramX: Address,
|
|
58
|
+
tokenProgramY: Address,
|
|
59
|
+
}): Promise<{ tokenVaultX: Address; tokenVaultY: Address }> {
|
|
60
|
+
const [tokenVaultX, tokenVaultY] = await Promise.all([
|
|
61
|
+
findAssociatedTokenPdaByTokenProgram({ owner: pool, mint: tokenMintX, tokenProgram: tokenProgramX }),
|
|
62
|
+
findAssociatedTokenPdaByTokenProgram({ owner: pool, mint: tokenMintY, tokenProgram: tokenProgramY }),
|
|
63
|
+
]);
|
|
64
|
+
return { tokenVaultX, tokenVaultY };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface ProcessAssociatedTokenAccountParams {
|
|
68
|
+
owner: TransactionSigner,
|
|
69
|
+
mint: Address,
|
|
70
|
+
amount?: bigint,
|
|
71
|
+
tokenProgram: Address,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface ProcessAssociatedTokenAccountResult {
|
|
75
|
+
ata: Address,
|
|
76
|
+
preInstructions: Instruction[],
|
|
77
|
+
postInstructions: Instruction[],
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function processAssociatedTokenAccount(params: ProcessAssociatedTokenAccountParams): Promise<ProcessAssociatedTokenAccountResult> {
|
|
81
|
+
if (params.mint === NATIVE_MINT_ADDRESS) {
|
|
82
|
+
return processWsolAssociatedTokenAccount(params);
|
|
83
|
+
} else {
|
|
84
|
+
return processRegularAssociatedTokenAccount(params);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Shared by every instruction that moves both X and Y through a single owner's ATAs
|
|
89
|
+
// (swap, withdraw, claim_fee, claim_protocol_fee, deposit_by_weight, claim_multiple_fees) —
|
|
90
|
+
// processes both sides and flattens their pre/post instructions in X-then-Y order.
|
|
91
|
+
export async function processAssociatedTokenAccountPair({
|
|
92
|
+
owner,
|
|
93
|
+
tokenMintX,
|
|
94
|
+
tokenMintY,
|
|
95
|
+
tokenProgramX,
|
|
96
|
+
tokenProgramY,
|
|
97
|
+
amountX,
|
|
98
|
+
amountY,
|
|
99
|
+
}: {
|
|
100
|
+
owner: TransactionSigner,
|
|
101
|
+
tokenMintX: Address,
|
|
102
|
+
tokenMintY: Address,
|
|
103
|
+
tokenProgramX: Address,
|
|
104
|
+
tokenProgramY: Address,
|
|
105
|
+
amountX?: bigint,
|
|
106
|
+
amountY?: bigint,
|
|
107
|
+
}): Promise<{
|
|
108
|
+
ataX: Address,
|
|
109
|
+
ataY: Address,
|
|
110
|
+
preInstructions: Instruction[],
|
|
111
|
+
postInstructions: Instruction[],
|
|
112
|
+
}> {
|
|
113
|
+
const [x, y] = await Promise.all([
|
|
114
|
+
processAssociatedTokenAccount({ owner, mint: tokenMintX, amount: amountX, tokenProgram: tokenProgramX }),
|
|
115
|
+
processAssociatedTokenAccount({ owner, mint: tokenMintY, amount: amountY, tokenProgram: tokenProgramY }),
|
|
116
|
+
]);
|
|
117
|
+
return {
|
|
118
|
+
ataX: x.ata,
|
|
119
|
+
ataY: y.ata,
|
|
120
|
+
preInstructions: [...x.preInstructions, ...y.preInstructions],
|
|
121
|
+
postInstructions: [...x.postInstructions, ...y.postInstructions],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function processWsolAssociatedTokenAccount({
|
|
126
|
+
owner,
|
|
127
|
+
amount,
|
|
128
|
+
tokenProgram,
|
|
129
|
+
}: ProcessAssociatedTokenAccountParams): Promise<ProcessAssociatedTokenAccountResult> {
|
|
130
|
+
if (tokenProgram !== TOKEN_PROGRAM_ADDRESS) {
|
|
131
|
+
throw new Error("Invalid program for wSOL");
|
|
132
|
+
}
|
|
133
|
+
const { ata, instructions: wrapIxs } = await getWrapWsolInstructions(owner, amount);
|
|
134
|
+
const unwrapIx = getUnwrapWsolInstruction(owner, ata);
|
|
135
|
+
return {
|
|
136
|
+
ata,
|
|
137
|
+
preInstructions: wrapIxs,
|
|
138
|
+
postInstructions: [unwrapIx],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function processRegularAssociatedTokenAccount({
|
|
143
|
+
owner,
|
|
144
|
+
mint,
|
|
145
|
+
tokenProgram,
|
|
146
|
+
}: ProcessAssociatedTokenAccountParams): Promise<ProcessAssociatedTokenAccountResult> {
|
|
147
|
+
const [findAssociatedTokenPda, getCreateAssociatedTokenIdempotentInstruction] = choosePdaFunctions(tokenProgram);
|
|
148
|
+
const [ata] = await findAssociatedTokenPda({ mint, owner: owner.address, tokenProgram });
|
|
149
|
+
const createAtaIx = getCreateAssociatedTokenIdempotentInstruction({ ata, mint, owner: owner.address, payer: owner, tokenProgram });
|
|
150
|
+
return {
|
|
151
|
+
ata,
|
|
152
|
+
preInstructions: [createAtaIx],
|
|
153
|
+
postInstructions: [],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function choosePdaFunctions(tokenProgram: Address):
|
|
158
|
+
[typeof findAssociatedTokenPda, typeof getCreateAssociatedTokenIdempotentInstruction] |
|
|
159
|
+
[typeof findAssociatedToken2022Pda, typeof getCreateAssociatedToken2022IdempotentInstruction] {
|
|
160
|
+
switch (tokenProgram) {
|
|
161
|
+
case TOKEN_PROGRAM_ADDRESS: return [findAssociatedTokenPda, getCreateAssociatedTokenIdempotentInstruction];
|
|
162
|
+
case TOKEN_2022_PROGRAM_ADDRESS: return [findAssociatedToken2022Pda, getCreateAssociatedToken2022IdempotentInstruction];
|
|
163
|
+
default: throw new Error(`Unsupported token program: ${tokenProgram}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function chooseFindAssociatedTokenPda(tokenProgram: Address) {
|
|
168
|
+
return choosePdaFunctions(tokenProgram)[0];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function getWrapWsolInstructions(
|
|
172
|
+
owner: TransactionSigner,
|
|
173
|
+
amount?: bigint,
|
|
174
|
+
): Promise<{ ata: Address; instructions: Instruction[] }> {
|
|
175
|
+
const [ata] = await findAssociatedTokenPda({
|
|
176
|
+
mint: NATIVE_MINT_ADDRESS,
|
|
177
|
+
owner: owner.address,
|
|
178
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const instructions = [
|
|
182
|
+
getCreateAssociatedTokenIdempotentInstruction({
|
|
183
|
+
ata,
|
|
184
|
+
mint: NATIVE_MINT_ADDRESS,
|
|
185
|
+
owner: owner.address,
|
|
186
|
+
payer: owner,
|
|
187
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
188
|
+
}),
|
|
189
|
+
...(amount
|
|
190
|
+
? [
|
|
191
|
+
getTransferSolInstruction({
|
|
192
|
+
source: owner,
|
|
193
|
+
destination: ata,
|
|
194
|
+
amount,
|
|
195
|
+
}),
|
|
196
|
+
getSyncNativeInstruction({ account: ata }),
|
|
197
|
+
]
|
|
198
|
+
: []),
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
return { ata, instructions };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getUnwrapWsolInstruction(
|
|
205
|
+
owner: TransactionSigner,
|
|
206
|
+
ata: Address,
|
|
207
|
+
) {
|
|
208
|
+
return getCloseAccountInstruction({
|
|
209
|
+
account: ata,
|
|
210
|
+
destination: owner.address,
|
|
211
|
+
owner,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Address } from "@solana/kit";
|
|
2
|
+
import { findBinArrayPda } from "../generated";
|
|
3
|
+
import { generateBinArrayIndicesForSwap, getPositionBinArrayIndices } from "./bin_location";
|
|
4
|
+
import { MAX_BIN_ARRAYS_PER_SWAP } from "./constants";
|
|
5
|
+
import { isUndefined } from "./type_guards";
|
|
6
|
+
|
|
7
|
+
// Shared by every instruction that enumerates an arbitrary span of bin arrays as Anchor
|
|
8
|
+
// `remaining_accounts` (swap, sync_pool), as opposed to the fixed lower/upper pair a
|
|
9
|
+
// position-scoped instruction uses.
|
|
10
|
+
export async function findBinArrayAddresses(pool: Address, indices: number[], programAddress: Address): Promise<Address[]> {
|
|
11
|
+
return Promise.all(indices.map(async index => (await findBinArrayPda({ pool, index }, { programAddress }))[0]));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Pure local PDA derivation — no RPC. Shared by `swap` (which only needs the addresses for
|
|
15
|
+
// remaining accounts) and `quote` (which additionally fetches each account's data).
|
|
16
|
+
export function findSwapBinArrayAddresses(
|
|
17
|
+
pool: Address,
|
|
18
|
+
activeBinId: number,
|
|
19
|
+
xToY: boolean,
|
|
20
|
+
programAddress: Address,
|
|
21
|
+
): Promise<Address[]> {
|
|
22
|
+
const binArrayIndices = generateBinArrayIndicesForSwap(activeBinId, xToY, MAX_BIN_ARRAYS_PER_SWAP);
|
|
23
|
+
return findBinArrayAddresses(pool, binArrayIndices, programAddress);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Shared by every position-scoped instruction (open_position, deposit_by_weight, withdraw,
|
|
27
|
+
// claim_fee) — derives the lower and (optionally) upper bin array covering the position's
|
|
28
|
+
// range, matching the program's own `lowerBinArray` + `upperBinArray: Option<UncheckedAccount>`
|
|
29
|
+
// account pair. `upperBinArray` is omitted when both ends fall in the same bin array.
|
|
30
|
+
export async function findPositionBinArrayAddresses(
|
|
31
|
+
pool: Address,
|
|
32
|
+
lowerBinId: number,
|
|
33
|
+
upperBinId: number,
|
|
34
|
+
programAddress: Address,
|
|
35
|
+
): Promise<{ lowerBinArray: Address; upperBinArray?: Address }> {
|
|
36
|
+
const { lowerBinArrayIndex, upperBinArrayIndex } = getPositionBinArrayIndices(lowerBinId, upperBinId);
|
|
37
|
+
|
|
38
|
+
const [lowerBinArray] = await findBinArrayPda({ pool, index: lowerBinArrayIndex }, { programAddress });
|
|
39
|
+
if (isUndefined(upperBinArrayIndex)) {
|
|
40
|
+
return { lowerBinArray };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const [upperBinArray] = await findBinArrayPda({ pool, index: upperBinArrayIndex }, { programAddress });
|
|
44
|
+
return { lowerBinArray, upperBinArray };
|
|
45
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BINS_PER_BIN_ARRAY } from "./constants";
|
|
2
|
+
|
|
3
|
+
export function getBinArrayIndex(binId: number): number {
|
|
4
|
+
return Math.floor(binId / BINS_PER_BIN_ARRAY);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getBinIndex(binId: number): number {
|
|
8
|
+
return ((binId % BINS_PER_BIN_ARRAY) + BINS_PER_BIN_ARRAY) % BINS_PER_BIN_ARRAY;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getBinId(binArrayIndex: number, binIndex: number): number {
|
|
12
|
+
return binArrayIndex * BINS_PER_BIN_ARRAY + binIndex;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getBinArrayIndexSequence(
|
|
16
|
+
lowerBinArrayIndex: number,
|
|
17
|
+
upperBinArrayIndex: number,
|
|
18
|
+
): number[] {
|
|
19
|
+
return Array.from(
|
|
20
|
+
{ length: upperBinArrayIndex - lowerBinArrayIndex + 1 },
|
|
21
|
+
(_, i) => lowerBinArrayIndex + i
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A position spans at most MAX_BIN_ARRAYS_PER_POSITION (2) bin arrays — the lower and
|
|
26
|
+
// (only if distinct) upper one covering its range. Shared by every position-scoped
|
|
27
|
+
// instruction that needs to enumerate exactly those arrays (open_position's bin-array
|
|
28
|
+
// bootstrap, withdraw/claim_fee's account derivation).
|
|
29
|
+
export function getPositionBinArrayIndices(
|
|
30
|
+
lowerBinId: number,
|
|
31
|
+
upperBinId: number,
|
|
32
|
+
): { lowerBinArrayIndex: number, upperBinArrayIndex?: number } {
|
|
33
|
+
const lowerBinArrayIndex = getBinArrayIndex(lowerBinId);
|
|
34
|
+
const upperBinArrayIndex = getBinArrayIndex(upperBinId);
|
|
35
|
+
return lowerBinArrayIndex === upperBinArrayIndex
|
|
36
|
+
? { lowerBinArrayIndex }
|
|
37
|
+
: { lowerBinArrayIndex, upperBinArrayIndex };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// One bin array of margin is kept on the opposite side of travel: if the live active bin
|
|
41
|
+
// drifts one array against the expected direction between quote time and execution (e.g. a
|
|
42
|
+
// competing swap lands first), it's still covered by this range instead of reverting.
|
|
43
|
+
export function generateBinArrayIndicesForSwap(
|
|
44
|
+
activeBinId: number,
|
|
45
|
+
xToY: boolean,
|
|
46
|
+
maxBinArrays: number,
|
|
47
|
+
): number[] {
|
|
48
|
+
const activeBinArrayIndex = getBinArrayIndex(activeBinId);
|
|
49
|
+
const [lowerBinArrayIndex, upperBinArrayIndex] = xToY
|
|
50
|
+
? [activeBinArrayIndex - (maxBinArrays - 2), activeBinArrayIndex + 1]
|
|
51
|
+
: [activeBinArrayIndex - 1, activeBinArrayIndex + (maxBinArrays - 2)];
|
|
52
|
+
return getBinArrayIndexSequence(lowerBinArrayIndex, upperBinArrayIndex);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Spans from the live `activeBinId` to the caller's exact `desiredBinId` target, plus one
|
|
56
|
+
// bin array of margin beyond the active end (the side subject to drift — `desiredBinId` is
|
|
57
|
+
// a fixed target, but the live active bin could move further away from it before this tx
|
|
58
|
+
// lands). Capped at `maxBinArrays`, trimming from the `desiredBinId` end so the active+margin
|
|
59
|
+
// anchor stays intact — a sync toward a distant target simply converges partially in that case.
|
|
60
|
+
export function generateBinArrayIndicesForSync(
|
|
61
|
+
activeBinId: number,
|
|
62
|
+
desiredBinId: number,
|
|
63
|
+
maxBinArrays: number,
|
|
64
|
+
): number[] {
|
|
65
|
+
const activeBinArrayIndex = getBinArrayIndex(activeBinId);
|
|
66
|
+
const desiredBinArrayIndex = getBinArrayIndex(desiredBinId);
|
|
67
|
+
const xToY = desiredBinId <= activeBinId;
|
|
68
|
+
|
|
69
|
+
let lowerBinArrayIndex: number;
|
|
70
|
+
let upperBinArrayIndex: number;
|
|
71
|
+
if (xToY) {
|
|
72
|
+
upperBinArrayIndex = activeBinArrayIndex + 1;
|
|
73
|
+
lowerBinArrayIndex = Math.max(desiredBinArrayIndex, upperBinArrayIndex - maxBinArrays + 1);
|
|
74
|
+
} else {
|
|
75
|
+
lowerBinArrayIndex = activeBinArrayIndex - 1;
|
|
76
|
+
upperBinArrayIndex = Math.min(desiredBinArrayIndex, lowerBinArrayIndex + maxBinArrays - 1);
|
|
77
|
+
}
|
|
78
|
+
return getBinArrayIndexSequence(lowerBinArrayIndex, upperBinArrayIndex);
|
|
79
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSetComputeUnitLimitInstruction,
|
|
3
|
+
getSetComputeUnitPriceInstruction,
|
|
4
|
+
} from "@solana-program/compute-budget";
|
|
5
|
+
import {
|
|
6
|
+
createSolanaRpc,
|
|
7
|
+
estimateComputeUnitLimitFactory,
|
|
8
|
+
prependTransactionMessageInstructions,
|
|
9
|
+
type TransactionMessage,
|
|
10
|
+
type TransactionMessageWithFeePayer,
|
|
11
|
+
} from "@solana/kit";
|
|
12
|
+
import { isUndefined } from "./type_guards";
|
|
13
|
+
|
|
14
|
+
export function withComputeBudget<TTransactionMessage extends TransactionMessage>(
|
|
15
|
+
message: TTransactionMessage,
|
|
16
|
+
{
|
|
17
|
+
computeUnitLimit,
|
|
18
|
+
computeUnitPrice,
|
|
19
|
+
}: {
|
|
20
|
+
computeUnitLimit?: number,
|
|
21
|
+
computeUnitPrice?: bigint,
|
|
22
|
+
} = {},
|
|
23
|
+
): TTransactionMessage {
|
|
24
|
+
const ixs = [
|
|
25
|
+
...(isUndefined(computeUnitLimit) ? [] : [getSetComputeUnitLimitInstruction({ units: computeUnitLimit })]),
|
|
26
|
+
...(isUndefined(computeUnitPrice) ? [] : [getSetComputeUnitPriceInstruction({ microLamports: computeUnitPrice })]),
|
|
27
|
+
];
|
|
28
|
+
return prependTransactionMessageInstructions(ixs, message) as TTransactionMessage;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function withEstimatedComputeBudget<
|
|
32
|
+
TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer
|
|
33
|
+
>(
|
|
34
|
+
rpc: ReturnType<typeof createSolanaRpc>,
|
|
35
|
+
message: TTransactionMessage,
|
|
36
|
+
{
|
|
37
|
+
estimateComputeUnitPrice,
|
|
38
|
+
estimateComputeUnitLimit,
|
|
39
|
+
bufferFactor = 1.1,
|
|
40
|
+
}: {
|
|
41
|
+
estimateComputeUnitPrice?: bigint | ((computeUnitLimit: number) => bigint),
|
|
42
|
+
estimateComputeUnitLimit?: ReturnType<typeof estimateComputeUnitLimitFactory>,
|
|
43
|
+
bufferFactor?: number,
|
|
44
|
+
} = {},
|
|
45
|
+
): Promise<TTransactionMessage> {
|
|
46
|
+
estimateComputeUnitLimit = estimateComputeUnitLimit ?? estimateComputeUnitLimitFactory({ rpc });
|
|
47
|
+
|
|
48
|
+
const computeUnitBase = await estimateComputeUnitLimit(message);
|
|
49
|
+
const computeUnitLimit = Math.ceil(computeUnitBase * bufferFactor);
|
|
50
|
+
const computeUnitPrice = estimateComputeUnitPrice instanceof Function
|
|
51
|
+
? estimateComputeUnitPrice(computeUnitLimit)
|
|
52
|
+
: estimateComputeUnitPrice;
|
|
53
|
+
|
|
54
|
+
return withComputeBudget(message, {
|
|
55
|
+
computeUnitLimit: computeUnitLimit,
|
|
56
|
+
computeUnitPrice,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import IDL from "./../picon_dlmm.json";
|
|
2
|
+
import { isUndefined } from "./type_guards";
|
|
3
|
+
|
|
4
|
+
function getIdlConstant(name: string): number {
|
|
5
|
+
const constant = IDL.constants.find(c => c.name === name);
|
|
6
|
+
if (isUndefined(constant)) throw new Error(`${name} constant not found in IDL`);
|
|
7
|
+
return Number.parseInt(constant.value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const BINS_PER_BIN_ARRAY = getIdlConstant("BINS_PER_BIN_ARRAY");
|
|
11
|
+
export const MAX_BIN_ARRAYS_PER_POSITION = getIdlConstant("MAX_BIN_ARRAYS_PER_POSITION");
|
|
12
|
+
export const MAX_BIN_ARRAYS_PER_SWAP = getIdlConstant("MAX_BIN_ARRAYS_PER_SWAP");
|
|
13
|
+
export const MAX_BIN_ARRAYS_PER_SYNC = getIdlConstant("MAX_BIN_ARRAYS_PER_SYNC");
|
|
14
|
+
|
|
15
|
+
export const FEE_PRECISION = getIdlConstant("FEE_PRECISION");
|
|
16
|
+
export const ONE_BPS_FEE_RATE = getIdlConstant("ONE_BPS_FEE_RATE");
|
|
17
|
+
export const MAX_FEE_RATE = getIdlConstant("MAX_FEE_RATE");
|
|
18
|
+
export const MAX_PROTOCOL_SHARE = getIdlConstant("MAX_PROTOCOL_SHARE");
|
|
19
|
+
export const MAX_BASIS_POINTS = getIdlConstant("MAX_BASIS_POINTS");
|
|
20
|
+
|
|
21
|
+
export const MAX_POSITIONS_PER_CLAIM = 3;
|
|
22
|
+
|
|
23
|
+
// Solana RPC's own hard cap on addresses per getMultipleAccounts request.
|
|
24
|
+
export const MAX_ACCOUNTS_PER_RPC_BATCH = 100;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { unwrapOption } from "@solana/kit";
|
|
2
|
+
import { type Mint, type Extension } from "@solana-program/token-2022";
|
|
3
|
+
import type { TransferFee } from "../quote";
|
|
4
|
+
|
|
5
|
+
function isTransferFeeConfig(
|
|
6
|
+
extension: Extension,
|
|
7
|
+
): extension is Extract<Extension, { __kind: "TransferFeeConfig" }> {
|
|
8
|
+
return extension.__kind === "TransferFeeConfig";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// TransferFeeConfig carries two rates — olderTransferFee/newerTransferFee — so the
|
|
12
|
+
// program can phase in a fee change without retroactively affecting in-flight swaps.
|
|
13
|
+
// newerTransferFee takes effect once the current epoch reaches its `epoch` field.
|
|
14
|
+
export function resolveTransferFee(mint: Mint, epoch: bigint): TransferFee | undefined {
|
|
15
|
+
const extensions = unwrapOption(mint.extensions) ?? [];
|
|
16
|
+
const transferFeeConfig = extensions.find(isTransferFeeConfig);
|
|
17
|
+
if (!transferFeeConfig) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const activeTransferFee = epoch >= transferFeeConfig.newerTransferFee.epoch
|
|
22
|
+
? transferFeeConfig.newerTransferFee
|
|
23
|
+
: transferFeeConfig.olderTransferFee;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
feeBps: activeTransferFee.transferFeeBasisPoints,
|
|
27
|
+
maxFee: activeTransferFee.maximumFee,
|
|
28
|
+
};
|
|
29
|
+
}
|