@picon-finance/dlmm-sdk 1.2.0 → 1.3.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.
Files changed (221) hide show
  1. package/README.md +107 -16
  2. package/dist/entities/admin_config.d.ts +23 -0
  3. package/dist/entities/admin_config.d.ts.map +1 -0
  4. package/dist/entities/admin_config.js +54 -0
  5. package/dist/entities/bin_array.d.ts +36 -0
  6. package/dist/entities/bin_array.d.ts.map +1 -0
  7. package/dist/entities/bin_array.js +62 -0
  8. package/dist/entities/dlmm_program.d.ts +50 -0
  9. package/dist/entities/dlmm_program.d.ts.map +1 -0
  10. package/dist/entities/dlmm_program.js +73 -0
  11. package/dist/entities/index.d.ts +7 -0
  12. package/dist/entities/index.d.ts.map +1 -0
  13. package/dist/entities/index.js +6 -0
  14. package/dist/entities/pool.d.ts +71 -0
  15. package/dist/entities/pool.d.ts.map +1 -0
  16. package/dist/entities/pool.js +189 -0
  17. package/dist/entities/position.d.ts +51 -0
  18. package/dist/entities/position.d.ts.map +1 -0
  19. package/dist/entities/position.js +248 -0
  20. package/dist/entities/position_pool.d.ts +7 -0
  21. package/dist/entities/position_pool.d.ts.map +1 -0
  22. package/dist/entities/position_pool.js +30 -0
  23. package/dist/entities/types.d.ts +5 -0
  24. package/dist/entities/types.d.ts.map +1 -0
  25. package/dist/entities/types.js +0 -0
  26. package/dist/events.d.ts +9 -1
  27. package/dist/events.d.ts.map +1 -1
  28. package/dist/events.js +48 -0
  29. package/dist/index.d.ts +2 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/program_addresses.d.ts.map +1 -1
  33. package/dist/program_addresses.js +0 -5
  34. package/dist/utils/assert.d.ts +9 -0
  35. package/dist/utils/assert.d.ts.map +1 -0
  36. package/dist/utils/assert.js +10 -0
  37. package/dist/utils/bin_location.d.ts +4 -0
  38. package/dist/utils/bin_location.d.ts.map +1 -1
  39. package/dist/utils/bin_location.js +0 -12
  40. package/dist/utils/chunk.d.ts +1 -0
  41. package/dist/utils/chunk.d.ts.map +1 -1
  42. package/dist/utils/chunk.js +4 -0
  43. package/dist/utils/type_guards.d.ts +2 -0
  44. package/dist/utils/type_guards.d.ts.map +1 -1
  45. package/dist/utils/type_guards.js +7 -0
  46. package/package.json +1 -2
  47. package/src/entities/admin_config.ts +122 -0
  48. package/src/entities/bin_array.ts +156 -0
  49. package/src/entities/dlmm_program.ts +210 -0
  50. package/src/entities/index.ts +6 -0
  51. package/src/entities/pool.ts +392 -0
  52. package/src/entities/position.ts +444 -0
  53. package/src/entities/position_pool.ts +68 -0
  54. package/src/entities/types.ts +3 -0
  55. package/src/events.ts +77 -0
  56. package/src/index.ts +2 -1
  57. package/src/program_addresses.ts +0 -6
  58. package/src/utils/assert.ts +25 -0
  59. package/src/utils/bin_location.ts +5 -12
  60. package/src/utils/chunk.ts +9 -0
  61. package/src/utils/type_guards.ts +12 -0
  62. package/dist/actions/accept_admin_authority.d.ts +0 -13
  63. package/dist/actions/accept_admin_authority.d.ts.map +0 -1
  64. package/dist/actions/accept_admin_authority.js +0 -7
  65. package/dist/actions/claim_fee.d.ts +0 -21
  66. package/dist/actions/claim_fee.d.ts.map +0 -1
  67. package/dist/actions/claim_fee.js +0 -40
  68. package/dist/actions/claim_multiple_fees.d.ts +0 -19
  69. package/dist/actions/claim_multiple_fees.d.ts.map +0 -1
  70. package/dist/actions/claim_multiple_fees.js +0 -81
  71. package/dist/actions/claim_protocol_fee.d.ts +0 -18
  72. package/dist/actions/claim_protocol_fee.d.ts.map +0 -1
  73. package/dist/actions/claim_protocol_fee.js +0 -33
  74. package/dist/actions/close_position.d.ts +0 -14
  75. package/dist/actions/close_position.d.ts.map +0 -1
  76. package/dist/actions/close_position.js +0 -14
  77. package/dist/actions/create_admin_config.d.ts +0 -15
  78. package/dist/actions/create_admin_config.d.ts.map +0 -1
  79. package/dist/actions/create_admin_config.js +0 -30
  80. package/dist/actions/create_bin_array.d.ts +0 -16
  81. package/dist/actions/create_bin_array.d.ts.map +0 -1
  82. package/dist/actions/create_bin_array.js +0 -10
  83. package/dist/actions/create_pool.d.ts +0 -21
  84. package/dist/actions/create_pool.d.ts.map +0 -1
  85. package/dist/actions/create_pool.js +0 -22
  86. package/dist/actions/delete_bin_array.d.ts +0 -16
  87. package/dist/actions/delete_bin_array.d.ts.map +0 -1
  88. package/dist/actions/delete_bin_array.js +0 -13
  89. package/dist/actions/deposit_by_weight.d.ts +0 -27
  90. package/dist/actions/deposit_by_weight.d.ts.map +0 -1
  91. package/dist/actions/deposit_by_weight.js +0 -52
  92. package/dist/actions/get_admin_config.d.ts +0 -4
  93. package/dist/actions/get_admin_config.d.ts.map +0 -1
  94. package/dist/actions/get_admin_config.js +0 -7
  95. package/dist/actions/get_bin_arrays_by_indices.d.ts +0 -5
  96. package/dist/actions/get_bin_arrays_by_indices.d.ts.map +0 -1
  97. package/dist/actions/get_bin_arrays_by_indices.js +0 -6
  98. package/dist/actions/get_pool.d.ts +0 -4
  99. package/dist/actions/get_pool.d.ts.map +0 -1
  100. package/dist/actions/get_pool.js +0 -5
  101. package/dist/actions/get_position.d.ts +0 -4
  102. package/dist/actions/get_position.d.ts.map +0 -1
  103. package/dist/actions/get_position.js +0 -5
  104. package/dist/actions/get_position_by_position_mint.d.ts +0 -4
  105. package/dist/actions/get_position_by_position_mint.d.ts.map +0 -1
  106. package/dist/actions/get_position_by_position_mint.js +0 -6
  107. package/dist/actions/get_positions_by_owner.d.ts +0 -5
  108. package/dist/actions/get_positions_by_owner.d.ts.map +0 -1
  109. package/dist/actions/get_positions_by_owner.js +0 -33
  110. package/dist/actions/get_positions_by_position_mints.d.ts +0 -5
  111. package/dist/actions/get_positions_by_position_mints.d.ts.map +0 -1
  112. package/dist/actions/get_positions_by_position_mints.js +0 -9
  113. package/dist/actions/helpers/build_swap_transaction_message.d.ts +0 -22
  114. package/dist/actions/helpers/build_swap_transaction_message.d.ts.map +0 -1
  115. package/dist/actions/helpers/build_swap_transaction_message.js +0 -50
  116. package/dist/actions/helpers/build_transaction_message.d.ts +0 -20
  117. package/dist/actions/helpers/build_transaction_message.d.ts.map +0 -1
  118. package/dist/actions/helpers/build_transaction_message.js +0 -5
  119. package/dist/actions/helpers/index.d.ts +0 -8
  120. package/dist/actions/helpers/index.d.ts.map +0 -1
  121. package/dist/actions/helpers/index.js +0 -7
  122. package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts +0 -12
  123. package/dist/actions/helpers/resolve_active_bin_and_mints.d.ts.map +0 -1
  124. package/dist/actions/helpers/resolve_active_bin_and_mints.js +0 -13
  125. package/dist/actions/helpers/resolve_admin_config_address.d.ts +0 -3
  126. package/dist/actions/helpers/resolve_admin_config_address.d.ts.map +0 -1
  127. package/dist/actions/helpers/resolve_admin_config_address.js +0 -9
  128. package/dist/actions/helpers/resolve_mint_info.d.ts +0 -10
  129. package/dist/actions/helpers/resolve_mint_info.d.ts.map +0 -1
  130. package/dist/actions/helpers/resolve_mint_info.js +0 -20
  131. package/dist/actions/helpers/resolve_position_range.d.ts +0 -12
  132. package/dist/actions/helpers/resolve_position_range.d.ts.map +0 -1
  133. package/dist/actions/helpers/resolve_position_range.js +0 -12
  134. package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts +0 -15
  135. package/dist/actions/helpers/resolve_token_mints_and_programs.d.ts.map +0 -1
  136. package/dist/actions/helpers/resolve_token_mints_and_programs.js +0 -29
  137. package/dist/actions/index.d.ts +0 -31
  138. package/dist/actions/index.d.ts.map +0 -1
  139. package/dist/actions/index.js +0 -28
  140. package/dist/actions/is_admin_config_active.d.ts +0 -4
  141. package/dist/actions/is_admin_config_active.d.ts.map +0 -1
  142. package/dist/actions/is_admin_config_active.js +0 -7
  143. package/dist/actions/on_event.d.ts +0 -11
  144. package/dist/actions/on_event.d.ts.map +0 -1
  145. package/dist/actions/on_event.js +0 -50
  146. package/dist/actions/open_position.d.ts +0 -17
  147. package/dist/actions/open_position.d.ts.map +0 -1
  148. package/dist/actions/open_position.js +0 -31
  149. package/dist/actions/quote.d.ts +0 -13
  150. package/dist/actions/quote.d.ts.map +0 -1
  151. package/dist/actions/quote.js +0 -43
  152. package/dist/actions/set_metadata_update_authority.d.ts +0 -14
  153. package/dist/actions/set_metadata_update_authority.d.ts.map +0 -1
  154. package/dist/actions/set_metadata_update_authority.js +0 -7
  155. package/dist/actions/set_pool_dynamic_fee_config.d.ts +0 -16
  156. package/dist/actions/set_pool_dynamic_fee_config.d.ts.map +0 -1
  157. package/dist/actions/set_pool_dynamic_fee_config.js +0 -7
  158. package/dist/actions/set_pool_protocol_share.d.ts +0 -15
  159. package/dist/actions/set_pool_protocol_share.d.ts.map +0 -1
  160. package/dist/actions/set_pool_protocol_share.js +0 -7
  161. package/dist/actions/swap.d.ts +0 -22
  162. package/dist/actions/swap.d.ts.map +0 -1
  163. package/dist/actions/swap.js +0 -19
  164. package/dist/actions/sync_pool.d.ts +0 -15
  165. package/dist/actions/sync_pool.d.ts.map +0 -1
  166. package/dist/actions/sync_pool.js +0 -26
  167. package/dist/actions/transfer_admin_authority.d.ts +0 -14
  168. package/dist/actions/transfer_admin_authority.d.ts.map +0 -1
  169. package/dist/actions/transfer_admin_authority.js +0 -7
  170. package/dist/actions/withdraw.d.ts +0 -22
  171. package/dist/actions/withdraw.d.ts.map +0 -1
  172. package/dist/actions/withdraw.js +0 -41
  173. package/dist/utils/admin_config.d.ts +0 -3
  174. package/dist/utils/admin_config.d.ts.map +0 -1
  175. package/dist/utils/admin_config.js +0 -4
  176. package/dist/utils/bin_array.d.ts +0 -8
  177. package/dist/utils/bin_array.d.ts.map +0 -1
  178. package/dist/utils/bin_array.js +0 -29
  179. package/dist/utils/compute_budget.d.ts +0 -11
  180. package/dist/utils/compute_budget.d.ts.map +0 -1
  181. package/dist/utils/compute_budget.js +0 -22
  182. package/src/actions/accept_admin_authority.ts +0 -17
  183. package/src/actions/claim_fee.ts +0 -84
  184. package/src/actions/claim_multiple_fees.ts +0 -123
  185. package/src/actions/claim_protocol_fee.ts +0 -68
  186. package/src/actions/close_position.ts +0 -21
  187. package/src/actions/create_admin_config.ts +0 -51
  188. package/src/actions/create_bin_array.ts +0 -30
  189. package/src/actions/create_pool.ts +0 -49
  190. package/src/actions/delete_bin_array.ts +0 -33
  191. package/src/actions/deposit_by_weight.ts +0 -107
  192. package/src/actions/get_admin_config.ts +0 -13
  193. package/src/actions/get_bin_arrays_by_indices.ts +0 -15
  194. package/src/actions/get_pool.ts +0 -8
  195. package/src/actions/get_position.ts +0 -8
  196. package/src/actions/get_position_by_position_mint.ts +0 -14
  197. package/src/actions/get_positions_by_owner.ts +0 -48
  198. package/src/actions/get_positions_by_position_mints.ts +0 -21
  199. package/src/actions/helpers/build_swap_transaction_message.ts +0 -86
  200. package/src/actions/helpers/build_transaction_message.ts +0 -45
  201. package/src/actions/helpers/index.ts +0 -7
  202. package/src/actions/helpers/resolve_active_bin_and_mints.ts +0 -21
  203. package/src/actions/helpers/resolve_admin_config_address.ts +0 -11
  204. package/src/actions/helpers/resolve_mint_info.ts +0 -36
  205. package/src/actions/helpers/resolve_position_range.ts +0 -21
  206. package/src/actions/helpers/resolve_token_mints_and_programs.ts +0 -56
  207. package/src/actions/index.ts +0 -34
  208. package/src/actions/is_admin_config_active.ts +0 -14
  209. package/src/actions/on_event.ts +0 -78
  210. package/src/actions/open_position.ts +0 -66
  211. package/src/actions/quote.ts +0 -70
  212. package/src/actions/set_metadata_update_authority.ts +0 -17
  213. package/src/actions/set_pool_dynamic_fee_config.ts +0 -17
  214. package/src/actions/set_pool_protocol_share.ts +0 -17
  215. package/src/actions/swap.ts +0 -56
  216. package/src/actions/sync_pool.ts +0 -35
  217. package/src/actions/transfer_admin_authority.ts +0 -17
  218. package/src/actions/withdraw.ts +0 -87
  219. package/src/utils/admin_config.ts +0 -6
  220. package/src/utils/bin_array.ts +0 -45
  221. package/src/utils/compute_budget.ts +0 -58
@@ -1,123 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, getClaimFeeInstruction } from "../generated";
3
- import { findPositionTokenAccount, processAssociatedTokenAccountPair, findPoolTokenVaults } from "../utils/ata";
4
- import { findPositionBinArrayAddresses } from "../utils/bin_array";
5
- import { isUndefined } from "../utils/type_guards";
6
- import { MAX_POSITIONS_PER_CLAIM } from "../utils/constants";
7
- import { getPositionsByPositionMints } from "./get_positions_by_position_mints";
8
- import {
9
- resolveTokenMintsAndPrograms,
10
- buildTransactionMessage,
11
- type TransactionMessageOptions,
12
- type Rpc,
13
- } from "./helpers";
14
-
15
- // No on-chain batch claim_fee — this chunks positions into multiple transactions bounded
16
- // by MAX_POSITIONS_PER_CLAIM, deduplicating the owner's ATAs and any shared bin arrays
17
- // within each chunk. All positions must belong to the same pool, since a single transaction
18
- // can only touch one pool's vaults.
19
- //
20
- // Returns one builder per chunk (not pre-built messages): only the first tx creates the
21
- // owner's ATAs (and only the last unwraps WSOL), so the chunks aren't independent — the
22
- // caller must call each builder and submit+confirm its transaction in order before calling
23
- // the next, since a later chunk's claim_fee assumes the first chunk's ATA already landed.
24
- export async function claimMultipleFees(
25
- rpc: Rpc,
26
- {
27
- owner,
28
- positionMints,
29
- pool,
30
- tokenMintX,
31
- tokenMintY,
32
- tokenProgramX,
33
- tokenProgramY,
34
- }: {
35
- owner: TransactionSigner,
36
- positionMints: Address[],
37
- pool?: Address,
38
- tokenMintX?: Address,
39
- tokenMintY?: Address,
40
- tokenProgramX?: Address,
41
- tokenProgramY?: Address,
42
- },
43
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
44
- options: TransactionMessageOptions = {},
45
- ) {
46
- if (positionMints.length === 0) {
47
- return [];
48
- }
49
-
50
- const positions = await getPositionsByPositionMints(rpc, positionMints, programAddress, options);
51
-
52
- const actualPool = positions[0].data.pool;
53
- if (positions.some(({ data }) => data.pool !== actualPool)) {
54
- throw new Error("claimMultipleFees: all positions must belong to the same pool");
55
- }
56
- if (!isUndefined(pool) && pool !== actualPool) {
57
- throw new Error("claimMultipleFees: provided pool does not match the positions' pool");
58
- }
59
- pool = actualPool;
60
-
61
- const tokenMintsAndPrograms = await resolveTokenMintsAndPrograms(rpc, {
62
- pool,
63
- tokenMintX,
64
- tokenMintY,
65
- tokenProgramX,
66
- tokenProgramY,
67
- }, options);
68
-
69
- // ATAs are persistent accounts: only the first tx needs to create them (and wrap WSOL,
70
- // though claim's ATAs are receive-only so there's nothing to transfer in), and only the
71
- // last needs to unwrap WSOL back to native SOL, once every chunk has landed in it.
72
- const {
73
- ataX: tokenOwnerAccountX,
74
- ataY: tokenOwnerAccountY,
75
- preInstructions: preInstructionsAta,
76
- postInstructions: postInstructionsAta,
77
- } = await processAssociatedTokenAccountPair({ owner, ...tokenMintsAndPrograms });
78
-
79
- const { tokenVaultX, tokenVaultY } = await findPoolTokenVaults({ pool, ...tokenMintsAndPrograms });
80
-
81
- const chunks = [];
82
- for (let i = 0; i < positions.length; i += MAX_POSITIONS_PER_CLAIM) {
83
- chunks.push(positions.slice(i, i + MAX_POSITIONS_PER_CLAIM));
84
- }
85
-
86
- // Returns one builder per chunk instead of pre-built messages: the caller submits and
87
- // confirms chunks strictly in order (see the contract above), and confirmation takes real
88
- // wall-clock time, so a blockhash fetched once up front for every chunk can outlive its
89
- // ~60-90s validity window before later chunks are ever submitted. Each builder fetches its
90
- // own blockhash (via buildTransactionMessage's default) at the moment it's actually called,
91
- // right before that chunk is submitted.
92
- return chunks.map((chunkPositions, i) => async () => {
93
- // One claim_fee per position in this chunk — deliberately excludes the owner's ATA
94
- // setup/teardown, which is account-level, not chunk-level (handled above/below instead).
95
- const coreInstructions = await Promise.all(chunkPositions.map(async ({ address: position, data }) => {
96
- const positionTokenAccount = await findPositionTokenAccount({ owner: owner.address, positionMint: data.positionMint });
97
- const { lowerBinArray, upperBinArray } = await findPositionBinArrayAddresses(pool, data.lowerBinId, data.upperBinId, programAddress);
98
-
99
- return getClaimFeeInstruction({
100
- owner,
101
- pool,
102
- position,
103
- positionTokenAccount,
104
- ...tokenMintsAndPrograms,
105
- tokenOwnerAccountX,
106
- tokenOwnerAccountY,
107
- tokenVaultX,
108
- tokenVaultY,
109
- lowerBinArray,
110
- upperBinArray,
111
- lowerBinId: data.lowerBinId,
112
- upperBinId: data.upperBinId,
113
- }, { programAddress });
114
- }));
115
-
116
- const instructions = [
117
- ...(i === 0 ? preInstructionsAta : []),
118
- ...coreInstructions,
119
- ...(i === chunks.length - 1 ? postInstructionsAta : []),
120
- ];
121
- return await buildTransactionMessage(rpc, { feePayer: owner, instructions }, options);
122
- });
123
- }
@@ -1,68 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, getClaimProtocolFeeInstructionAsync } from "../generated";
3
- import { findPoolTokenVaults, processAssociatedTokenAccountPair } from "../utils/ata";
4
- import {
5
- resolveTokenMintsAndPrograms,
6
- resolveAdminConfigAddress,
7
- buildTransactionMessage,
8
- type TransactionMessageOptions,
9
- type Rpc,
10
- } from "./helpers";
11
-
12
- export async function claimProtocolFee(
13
- rpc: Rpc,
14
- {
15
- authority,
16
- pool,
17
- tokenMintX,
18
- tokenMintY,
19
- tokenProgramX,
20
- tokenProgramY,
21
- }: {
22
- authority: TransactionSigner,
23
- pool: Address,
24
- tokenMintX?: Address,
25
- tokenMintY?: Address,
26
- tokenProgramX?: Address,
27
- tokenProgramY?: Address,
28
- },
29
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
30
- options: TransactionMessageOptions = {},
31
- ) {
32
- const [tokenMintsAndPrograms, adminConfig] = await Promise.all([
33
- resolveTokenMintsAndPrograms(rpc, {
34
- pool,
35
- tokenMintX,
36
- tokenMintY,
37
- tokenProgramX,
38
- tokenProgramY,
39
- }, options),
40
- resolveAdminConfigAddress(programAddress),
41
- ]);
42
- const { tokenVaultX, tokenVaultY } = await findPoolTokenVaults({ pool, ...tokenMintsAndPrograms });
43
-
44
- const {
45
- ataX: tokenAdminAccountX,
46
- ataY: tokenAdminAccountY,
47
- preInstructions: preInstructionsAta,
48
- postInstructions: postInstructionsAta,
49
- } = await processAssociatedTokenAccountPair({ owner: authority, ...tokenMintsAndPrograms });
50
-
51
- const claimProtocolFeeIx = await getClaimProtocolFeeInstructionAsync({
52
- authority,
53
- pool,
54
- adminConfig,
55
- ...tokenMintsAndPrograms,
56
- tokenVaultX,
57
- tokenVaultY,
58
- tokenAdminAccountX,
59
- tokenAdminAccountY,
60
- }, { programAddress });
61
-
62
- const instructions = [
63
- ...preInstructionsAta,
64
- claimProtocolFeeIx,
65
- ...postInstructionsAta,
66
- ];
67
- return await buildTransactionMessage(rpc, { feePayer: authority, instructions }, options);
68
- }
@@ -1,21 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, findPositionPda, getClosePositionInstructionAsync } from "../generated";
3
- import { findPositionTokenAccount } from "../utils/ata";
4
- import { buildTransactionMessage, type TransactionMessageOptions, type Rpc } from "./helpers";
5
-
6
- export async function closePosition(
7
- rpc: Rpc,
8
- { owner, positionMint }: { owner: TransactionSigner, positionMint: Address },
9
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
10
- options: TransactionMessageOptions = {},
11
- ) {
12
- const [position] = await findPositionPda({ positionMint }, { programAddress });
13
- const positionTokenAccount = await findPositionTokenAccount({ owner: owner.address, positionMint });
14
- const closePositionIx = await getClosePositionInstructionAsync({
15
- owner,
16
- positionMint,
17
- position,
18
- positionTokenAccount,
19
- }, { programAddress });
20
- return await buildTransactionMessage(rpc, { feePayer: owner, instructions: [closePositionIx] }, options);
21
- }
@@ -1,51 +0,0 @@
1
- import {
2
- type Address,
3
- type TransactionSigner,
4
- getAddressEncoder,
5
- getProgramDerivedAddress,
6
- } from "@solana/kit";
7
- import { PICON_DLMM_PROGRAM_ADDRESS, getCreateAdminConfigInstructionAsync } from "../generated";
8
- import { buildTransactionMessage, resolveAdminConfigAddress, type TransactionMessageOptions, type Rpc } from "./helpers";
9
-
10
- const LOADER_V3_PROGRAM_ADDRESS = "BPFLoaderUpgradeab1e11111111111111111111111" as Address;
11
-
12
- async function findProgramDataAddress(programAddress: Address): Promise<Address> {
13
- const [programData] = await getProgramDerivedAddress({
14
- programAddress: LOADER_V3_PROGRAM_ADDRESS,
15
- seeds: [getAddressEncoder().encode(programAddress)],
16
- });
17
- return programData;
18
- }
19
-
20
- export async function createAdminConfig(
21
- rpc: Rpc,
22
- {
23
- deployer,
24
- authority,
25
- metadataUpdateAuthority,
26
- }: {
27
- deployer: TransactionSigner,
28
- authority: Address,
29
- metadataUpdateAuthority?: Address,
30
- },
31
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
32
- options: TransactionMessageOptions = {},
33
- ) {
34
- // The generated builder's default account resolution for `adminConfig`/`program` doesn't
35
- // honor this call's `programAddress` argument (always resolves against the mainnet
36
- // PICON_DLMM_PROGRAM_ADDRESS baked in at codegen time) — both are derived and passed
37
- // explicitly here instead.
38
- const [adminConfig, programData] = await Promise.all([
39
- resolveAdminConfigAddress(programAddress),
40
- findProgramDataAddress(programAddress),
41
- ]);
42
- const createAdminConfigIx = await getCreateAdminConfigInstructionAsync({
43
- deployer,
44
- authority,
45
- metadataUpdateAuthority: metadataUpdateAuthority ?? null,
46
- adminConfig,
47
- program: programAddress,
48
- programData,
49
- }, { programAddress });
50
- return await buildTransactionMessage(rpc, { feePayer: deployer, instructions: [createAdminConfigIx] }, options);
51
- }
@@ -1,30 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, findBinArrayPda, getCreateBinArrayInstructionAsync } from "../generated";
3
- import { buildTransactionMessage, type TransactionMessageOptions, type Rpc } from "./helpers";
4
-
5
- // Standalone escape hatch for manually recreating a bin array — e.g. restoring one an
6
- // admin deleted while a position still had unclaimed fee or an untouched share in it.
7
- // Idempotent by default: harmless no-op if the array is already alive.
8
- export async function createBinArray(
9
- rpc: Rpc,
10
- {
11
- payer,
12
- pool,
13
- index,
14
- idempotent = true,
15
- }: {
16
- payer: TransactionSigner,
17
- pool: Address,
18
- index: number,
19
- idempotent?: boolean,
20
- },
21
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
22
- options: TransactionMessageOptions = {},
23
- ) {
24
- const [binArray] = await findBinArrayPda({ pool, index }, { programAddress });
25
- const instruction = await getCreateBinArrayInstructionAsync(
26
- { payer, pool, index, idempotent, binArray },
27
- { programAddress },
28
- );
29
- return await buildTransactionMessage(rpc, { feePayer: payer, instructions: [instruction] }, options);
30
- }
@@ -1,49 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, findPoolPda, getCreatePoolInstructionAsync } from "../generated";
3
- import { buildTransactionMessage, resolveAdminConfigAddress, type TransactionMessageOptions, type Rpc } from "./helpers";
4
-
5
- export async function createPool(
6
- rpc: Rpc,
7
- {
8
- authority,
9
- binStep,
10
- feeRate,
11
- protocolShare,
12
- activeBinId,
13
- tokenMintX,
14
- tokenMintY,
15
- tokenProgramX,
16
- tokenProgramY,
17
- }: {
18
- authority: TransactionSigner,
19
- binStep: number,
20
- feeRate: number,
21
- protocolShare: number,
22
- activeBinId: number,
23
- tokenMintX: Address,
24
- tokenMintY: Address,
25
- tokenProgramX: Address,
26
- tokenProgramY: Address,
27
- },
28
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
29
- options: TransactionMessageOptions = {},
30
- ) {
31
- const [[pool], adminConfig] = await Promise.all([
32
- findPoolPda({ tokenMintX, tokenMintY, binStep, feeRate }, { programAddress }),
33
- resolveAdminConfigAddress(programAddress),
34
- ]);
35
- const instruction = await getCreatePoolInstructionAsync({
36
- authority,
37
- pool,
38
- adminConfig,
39
- binStep,
40
- feeRate,
41
- protocolShare,
42
- activeBinId,
43
- tokenMintX,
44
- tokenMintY,
45
- tokenProgramX,
46
- tokenProgramY,
47
- }, { programAddress });
48
- return await buildTransactionMessage(rpc, { feePayer: authority, instructions: [instruction] }, options);
49
- }
@@ -1,33 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, fetchBinArray, findBinArrayPda, getDeleteBinArrayInstructionAsync } from "../generated";
3
- import { isUndefined } from "../utils/type_guards";
4
- import { buildTransactionMessage, resolveAdminConfigAddress, type TransactionMessageOptions, type Rpc } from "./helpers";
5
-
6
- export async function deleteBinArray(
7
- rpc: Rpc,
8
- {
9
- authority,
10
- pool,
11
- index,
12
- receiver,
13
- }: {
14
- authority: TransactionSigner,
15
- pool: Address,
16
- index: number,
17
- receiver?: Address,
18
- },
19
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
20
- options: TransactionMessageOptions = {},
21
- ) {
22
- const [binArray] = await findBinArrayPda({ pool, index }, { programAddress });
23
- if (isUndefined(receiver)) {
24
- const { data } = await fetchBinArray(rpc, binArray, options);
25
- receiver = data.payer;
26
- }
27
- const adminConfig = await resolveAdminConfigAddress(programAddress);
28
- const instruction = await getDeleteBinArrayInstructionAsync(
29
- { authority, pool, index, receiver, binArray, adminConfig },
30
- { programAddress },
31
- );
32
- return await buildTransactionMessage(rpc, { feePayer: authority, instructions: [instruction] }, options);
33
- }
@@ -1,107 +0,0 @@
1
- import type { Address, TransactionSigner } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, type DistributionMode, findPositionPda, getDepositByWeightInstruction } from "../generated";
3
- import { findPositionBinArrayAddresses } from "../utils/bin_array";
4
- import { processAssociatedTokenAccountPair, findPositionTokenAccount, findPoolTokenVaults } from "../utils/ata";
5
- import { isUndefined } from "../utils/type_guards";
6
- import { getPositionByPositionMint } from "./get_position_by_position_mint";
7
- import {
8
- resolveActiveBinAndMints,
9
- resolveTokenMintsAndPrograms,
10
- buildTransactionMessage,
11
- type TransactionMessageOptions,
12
- type Rpc,
13
- } from "./helpers";
14
-
15
- export async function depositByWeight(
16
- rpc: Rpc,
17
- {
18
- owner,
19
- positionMint,
20
- activeBinId,
21
- amountX,
22
- amountY,
23
- lowerBinId,
24
- binWeights,
25
- maxActiveBinSlippage,
26
- distributionMode,
27
- pool,
28
- tokenMintX,
29
- tokenMintY,
30
- tokenProgramX,
31
- tokenProgramY,
32
- }: {
33
- owner: TransactionSigner,
34
- positionMint: Address,
35
- activeBinId?: number,
36
- amountX: bigint,
37
- amountY: bigint,
38
- lowerBinId: number,
39
- binWeights: number[],
40
- maxActiveBinSlippage: number,
41
- distributionMode: DistributionMode,
42
- pool?: Address,
43
- tokenMintX?: Address,
44
- tokenMintY?: Address,
45
- tokenProgramX?: Address,
46
- tokenProgramY?: Address,
47
- },
48
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
49
- options: TransactionMessageOptions = {},
50
- ) {
51
- if (isUndefined(pool)) {
52
- const positionData = await getPositionByPositionMint(rpc, positionMint, programAddress, options);
53
- pool = positionData.pool;
54
- }
55
- ({ activeBinId, tokenMintX, tokenMintY } = await resolveActiveBinAndMints(rpc, pool, { activeBinId, tokenMintX, tokenMintY }, options));
56
-
57
- const tokenMintsAndPrograms = await resolveTokenMintsAndPrograms(rpc, {
58
- pool,
59
- tokenMintX,
60
- tokenMintY,
61
- tokenProgramX,
62
- tokenProgramY,
63
- }, options);
64
-
65
- const upperBinId = lowerBinId + binWeights.length - 1;
66
-
67
- const [position] = await findPositionPda({ positionMint }, { programAddress });
68
- const positionTokenAccount = await findPositionTokenAccount({ owner: owner.address, positionMint });
69
- const { tokenVaultX, tokenVaultY } = await findPoolTokenVaults({ pool, ...tokenMintsAndPrograms });
70
-
71
- const {
72
- ataX: tokenOwnerAccountX,
73
- ataY: tokenOwnerAccountY,
74
- preInstructions: preInstructionsAta,
75
- postInstructions: postInstructionsAta,
76
- } = await processAssociatedTokenAccountPair({ owner, ...tokenMintsAndPrograms, amountX, amountY });
77
-
78
- const { lowerBinArray, upperBinArray } = await findPositionBinArrayAddresses(pool, lowerBinId, upperBinId, programAddress);
79
-
80
- const depositByWeightIx = getDepositByWeightInstruction({
81
- owner,
82
- pool,
83
- position,
84
- positionTokenAccount,
85
- ...tokenMintsAndPrograms,
86
- tokenOwnerAccountX,
87
- tokenOwnerAccountY,
88
- tokenVaultX,
89
- tokenVaultY,
90
- lowerBinArray,
91
- upperBinArray,
92
- amountX,
93
- amountY,
94
- activeBinId,
95
- maxActiveBinSlippage,
96
- distributionMode,
97
- lowerBinId,
98
- binWeights,
99
- }, { programAddress });
100
-
101
- const instructions = [
102
- ...preInstructionsAta,
103
- depositByWeightIx,
104
- ...postInstructionsAta,
105
- ];
106
- return await buildTransactionMessage(rpc, { feePayer: owner, instructions }, options);
107
- }
@@ -1,13 +0,0 @@
1
- import type { Address } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, fetchAdminConfig } from "../generated";
3
- import { resolveAdminConfigAddress, type Rpc, type TransactionMessageOptions } from "./helpers";
4
-
5
- export async function getAdminConfig(
6
- rpc: Rpc,
7
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
8
- options: TransactionMessageOptions = {},
9
- ) {
10
- const adminConfig = await resolveAdminConfigAddress(programAddress);
11
- const { data } = await fetchAdminConfig(rpc, adminConfig, options);
12
- return data;
13
- }
@@ -1,15 +0,0 @@
1
- import type { Address, Account } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, type BinArray, fetchAllBinArray } from "../generated";
3
- import { findBinArrayAddresses } from "../utils/bin_array";
4
- import type { Rpc, TransactionMessageOptions } from "./helpers";
5
-
6
- export async function getBinArraysByIndices(
7
- rpc: Rpc,
8
- pool: Address,
9
- indices: number[],
10
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
11
- options: TransactionMessageOptions = {},
12
- ): Promise<Account<BinArray>[]> {
13
- const binArrayAddresses = await findBinArrayAddresses(pool, indices, programAddress);
14
- return await fetchAllBinArray(rpc, binArrayAddresses, options);
15
- }
@@ -1,8 +0,0 @@
1
- import type { Address } from "@solana/kit";
2
- import { fetchPool } from "../generated";
3
- import type { Rpc, TransactionMessageOptions } from "./helpers";
4
-
5
- export async function getPool(rpc: Rpc, pool: Address, options: TransactionMessageOptions = {}) {
6
- const { data } = await fetchPool(rpc, pool, options);
7
- return data;
8
- }
@@ -1,8 +0,0 @@
1
- import type { Address } from "@solana/kit";
2
- import { fetchPosition } from "../generated";
3
- import type { Rpc, TransactionMessageOptions } from "./helpers";
4
-
5
- export async function getPosition(rpc: Rpc, position: Address, options: TransactionMessageOptions = {}) {
6
- const { data } = await fetchPosition(rpc, position, options);
7
- return data;
8
- }
@@ -1,14 +0,0 @@
1
- import type { Address } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, findPositionPda } from "../generated";
3
- import { getPosition } from "./get_position";
4
- import type { Rpc, TransactionMessageOptions } from "./helpers";
5
-
6
- export async function getPositionByPositionMint(
7
- rpc: Rpc,
8
- positionMint: Address,
9
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
10
- options: TransactionMessageOptions = {},
11
- ) {
12
- const [position] = await findPositionPda({ positionMint }, { programAddress });
13
- return await getPosition(rpc, position, options);
14
- }
@@ -1,48 +0,0 @@
1
- import { type Address, parseBase64RpcAccount } from "@solana/kit";
2
- import { getTokenDecoder, TOKEN_2022_PROGRAM_ADDRESS } from "@solana-program/token-2022";
3
- import { PICON_DLMM_PROGRAM_ADDRESS, type Position, findPositionPda, fetchAllMaybePosition } from "../generated";
4
- import { chunk } from "../utils/chunk";
5
- import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
6
- import type { Rpc, TransactionMessageOptions } from "./helpers";
7
-
8
- export async function getPositionsByOwner(
9
- rpc: Rpc,
10
- owner: Address,
11
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
12
- { commitment, minContextSlot, abortSignal }: TransactionMessageOptions = {},
13
- ): Promise<Map<Address, Position[]>> {
14
- const { value: tokenAccounts } = await rpc
15
- .getTokenAccountsByOwner(owner, { programId: TOKEN_2022_PROGRAM_ADDRESS }, { commitment, minContextSlot, encoding: "base64" })
16
- .send({ abortSignal });
17
-
18
- const tokenDecoder = getTokenDecoder();
19
- const candidateMints = tokenAccounts
20
- .map(({ pubkey, account }) => tokenDecoder.decode(parseBase64RpcAccount(pubkey, account).data))
21
- .filter(token => token.amount === 1n)
22
- .map(token => token.mint);
23
-
24
- const positionsByPool = new Map<Address, Position[]>();
25
- if (candidateMints.length === 0) {
26
- return positionsByPool;
27
- }
28
-
29
- const positionAddresses = await Promise.all(
30
- candidateMints.map(async positionMint => (await findPositionPda({ positionMint }, { programAddress }))[0]),
31
- );
32
- // getMultipleAccounts caps out at MAX_ACCOUNTS_PER_RPC_BATCH addresses per request.
33
- const maybePositionChunks = await Promise.all(
34
- chunk(positionAddresses, MAX_ACCOUNTS_PER_RPC_BATCH).map(addresses => fetchAllMaybePosition(rpc, addresses, { commitment, minContextSlot, abortSignal })),
35
- );
36
- const maybePositions = maybePositionChunks.flat();
37
-
38
- for (const maybePosition of maybePositions) {
39
- if (!maybePosition.exists) {
40
- continue;
41
- }
42
- const position = maybePosition.data;
43
- const positions = positionsByPool.get(position.pool) ?? [];
44
- positions.push(position);
45
- positionsByPool.set(position.pool, positions);
46
- }
47
- return positionsByPool;
48
- }
@@ -1,21 +0,0 @@
1
- import type { Address, Account } from "@solana/kit";
2
- import { PICON_DLMM_PROGRAM_ADDRESS, type Position, findPositionPda, fetchAllPosition } from "../generated";
3
- import { chunk } from "../utils/chunk";
4
- import { MAX_ACCOUNTS_PER_RPC_BATCH } from "../utils/constants";
5
- import type { Rpc, TransactionMessageOptions } from "./helpers";
6
-
7
- export async function getPositionsByPositionMints(
8
- rpc: Rpc,
9
- positionMints: Address[],
10
- programAddress: Address = PICON_DLMM_PROGRAM_ADDRESS,
11
- options: TransactionMessageOptions = {},
12
- ): Promise<Account<Position>[]> {
13
- const positionAddresses = await Promise.all(
14
- positionMints.map(async positionMint => (await findPositionPda({ positionMint }, { programAddress }))[0]),
15
- );
16
- // getMultipleAccounts caps out at MAX_ACCOUNTS_PER_RPC_BATCH addresses per request.
17
- const positionChunks = await Promise.all(
18
- chunk(positionAddresses, MAX_ACCOUNTS_PER_RPC_BATCH).map(addresses => fetchAllPosition(rpc, addresses, options)),
19
- );
20
- return positionChunks.flat();
21
- }