@omnipair/dusk-sdk 2.0.2 → 2.18.0-next.20261106

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 (187) hide show
  1. package/README.md +863 -42
  2. package/dist/amounts.d.ts +9 -0
  3. package/dist/amounts.d.ts.map +1 -0
  4. package/dist/amounts.js +10 -0
  5. package/dist/amounts.js.map +1 -0
  6. package/dist/constants.d.ts +68 -27
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +153 -41
  9. package/dist/constants.js.map +1 -1
  10. package/dist/delegate.d.ts +97 -0
  11. package/dist/delegate.d.ts.map +1 -0
  12. package/dist/delegate.js +152 -0
  13. package/dist/delegate.js.map +1 -0
  14. package/dist/dusk.d.ts +14 -0
  15. package/dist/dusk.d.ts.map +1 -1
  16. package/dist/dusk.js +22 -0
  17. package/dist/dusk.js.map +1 -1
  18. package/dist/get.d.ts +3033 -385
  19. package/dist/get.d.ts.map +1 -1
  20. package/dist/get.js +109 -72
  21. package/dist/get.js.map +1 -1
  22. package/dist/hash.d.ts +9 -0
  23. package/dist/hash.d.ts.map +1 -0
  24. package/dist/hash.js +16 -0
  25. package/dist/hash.js.map +1 -0
  26. package/dist/hlp-liquidation-client.d.ts +104 -0
  27. package/dist/hlp-liquidation-client.d.ts.map +1 -0
  28. package/dist/hlp-liquidation-client.js +146 -0
  29. package/dist/hlp-liquidation-client.js.map +1 -0
  30. package/dist/idl_delegate.d.ts +3 -0
  31. package/dist/idl_delegate.d.ts.map +1 -0
  32. package/dist/idl_delegate.js +3 -0
  33. package/dist/idl_delegate.js.map +1 -0
  34. package/dist/idl_delegate.json +6268 -0
  35. package/dist/idl_v2.json +16746 -6676
  36. package/dist/index.d.ts +23 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +23 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/interest-accounting.d.ts +45 -0
  41. package/dist/interest-accounting.d.ts.map +1 -0
  42. package/dist/interest-accounting.js +59 -0
  43. package/dist/interest-accounting.js.map +1 -0
  44. package/dist/leverage-actions.d.ts +122 -0
  45. package/dist/leverage-actions.d.ts.map +1 -0
  46. package/dist/leverage-actions.js +228 -0
  47. package/dist/leverage-actions.js.map +1 -0
  48. package/dist/leverage-margins.d.ts +12 -0
  49. package/dist/leverage-margins.d.ts.map +1 -0
  50. package/dist/leverage-margins.js +45 -0
  51. package/dist/leverage-margins.js.map +1 -0
  52. package/dist/leverage-preview.d.ts +598 -0
  53. package/dist/leverage-preview.d.ts.map +1 -0
  54. package/dist/leverage-preview.js +89 -0
  55. package/dist/leverage-preview.js.map +1 -0
  56. package/dist/liquidation-client.d.ts +226 -0
  57. package/dist/liquidation-client.d.ts.map +1 -0
  58. package/dist/liquidation-client.js +237 -0
  59. package/dist/liquidation-client.js.map +1 -0
  60. package/dist/liquidation.d.ts +72 -0
  61. package/dist/liquidation.d.ts.map +1 -0
  62. package/dist/liquidation.js +104 -0
  63. package/dist/liquidation.js.map +1 -0
  64. package/dist/lp-naming.d.ts +43 -0
  65. package/dist/lp-naming.d.ts.map +1 -0
  66. package/dist/lp-naming.js +81 -0
  67. package/dist/lp-naming.js.map +1 -0
  68. package/dist/lp-vanity.d.ts +33 -0
  69. package/dist/lp-vanity.d.ts.map +1 -0
  70. package/dist/lp-vanity.js +94 -0
  71. package/dist/lp-vanity.js.map +1 -0
  72. package/dist/market-bootstrap.d.ts +109 -0
  73. package/dist/market-bootstrap.d.ts.map +1 -0
  74. package/dist/market-bootstrap.js +156 -0
  75. package/dist/market-bootstrap.js.map +1 -0
  76. package/dist/market-launch.d.ts +45 -0
  77. package/dist/market-launch.d.ts.map +1 -0
  78. package/dist/market-launch.js +76 -0
  79. package/dist/market-launch.js.map +1 -0
  80. package/dist/operator-client.d.ts +99 -0
  81. package/dist/operator-client.d.ts.map +1 -0
  82. package/dist/operator-client.js +153 -0
  83. package/dist/operator-client.js.map +1 -0
  84. package/dist/oracle.d.ts +46 -0
  85. package/dist/oracle.d.ts.map +1 -0
  86. package/dist/oracle.js +103 -0
  87. package/dist/oracle.js.map +1 -0
  88. package/dist/parameters.d.ts +231 -0
  89. package/dist/parameters.d.ts.map +1 -0
  90. package/dist/parameters.js +683 -0
  91. package/dist/parameters.js.map +1 -0
  92. package/dist/preview.d.ts +39 -1
  93. package/dist/preview.d.ts.map +1 -1
  94. package/dist/preview.js +12 -0
  95. package/dist/preview.js.map +1 -1
  96. package/dist/protection.d.ts +48 -0
  97. package/dist/protection.d.ts.map +1 -0
  98. package/dist/protection.js +88 -0
  99. package/dist/protection.js.map +1 -0
  100. package/dist/risk-pricing.d.ts +12 -0
  101. package/dist/risk-pricing.d.ts.map +1 -0
  102. package/dist/risk-pricing.js +23 -0
  103. package/dist/risk-pricing.js.map +1 -0
  104. package/dist/simulation.d.ts +45 -0
  105. package/dist/simulation.d.ts.map +1 -0
  106. package/dist/simulation.js +106 -0
  107. package/dist/simulation.js.map +1 -0
  108. package/dist/tranche-client.d.ts +121 -0
  109. package/dist/tranche-client.d.ts.map +1 -0
  110. package/dist/tranche-client.js +185 -0
  111. package/dist/tranche-client.js.map +1 -0
  112. package/dist/transfer-fees.d.ts +46 -0
  113. package/dist/transfer-fees.d.ts.map +1 -0
  114. package/dist/transfer-fees.js +76 -0
  115. package/dist/transfer-fees.js.map +1 -0
  116. package/dist/type-aliases.d.ts +265 -31
  117. package/dist/type-aliases.d.ts.map +1 -1
  118. package/dist/types_delegate.d.ts +6275 -0
  119. package/dist/types_delegate.d.ts.map +1 -0
  120. package/dist/types_delegate.js +2 -0
  121. package/dist/types_delegate.js.map +1 -0
  122. package/dist/types_v2.d.ts +16654 -6584
  123. package/dist/types_v2.d.ts.map +1 -1
  124. package/dist/virtual-book/index.d.ts +4 -0
  125. package/dist/virtual-book/index.d.ts.map +1 -0
  126. package/dist/virtual-book/index.js +4 -0
  127. package/dist/virtual-book/index.js.map +1 -0
  128. package/dist/virtual-book/market.d.ts +619 -0
  129. package/dist/virtual-book/market.d.ts.map +1 -0
  130. package/dist/virtual-book/market.js +59 -0
  131. package/dist/virtual-book/market.js.map +1 -0
  132. package/dist/virtual-book/projection.d.ts +44 -0
  133. package/dist/virtual-book/projection.d.ts.map +1 -0
  134. package/dist/virtual-book/projection.js +229 -0
  135. package/dist/virtual-book/projection.js.map +1 -0
  136. package/dist/virtual-book/quotes.d.ts +1263 -0
  137. package/dist/virtual-book/quotes.d.ts.map +1 -0
  138. package/dist/virtual-book/quotes.js +233 -0
  139. package/dist/virtual-book/quotes.js.map +1 -0
  140. package/dist/write.d.ts +427 -0
  141. package/dist/write.d.ts.map +1 -1
  142. package/dist/write.js +970 -26
  143. package/dist/write.js.map +1 -1
  144. package/dist/yield-client.d.ts +51 -0
  145. package/dist/yield-client.d.ts.map +1 -0
  146. package/dist/yield-client.js +98 -0
  147. package/dist/yield-client.js.map +1 -0
  148. package/package.json +11 -4
  149. package/src/amounts.ts +13 -0
  150. package/src/constants.ts +220 -46
  151. package/src/delegate.ts +259 -0
  152. package/src/dusk.ts +28 -0
  153. package/src/get.ts +201 -86
  154. package/src/hash.ts +15 -0
  155. package/src/hlp-liquidation-client.ts +189 -0
  156. package/src/idl_delegate.json +6268 -0
  157. package/src/idl_delegate.ts +3 -0
  158. package/src/idl_v2.json +16746 -6676
  159. package/src/index.ts +31 -0
  160. package/src/interest-accounting.ts +73 -0
  161. package/src/leverage-actions.ts +216 -0
  162. package/src/leverage-margins.ts +48 -0
  163. package/src/leverage-preview.ts +86 -0
  164. package/src/liquidation-client.ts +295 -0
  165. package/src/liquidation.ts +119 -0
  166. package/src/lp-naming.ts +127 -0
  167. package/src/lp-vanity.ts +135 -0
  168. package/src/market-bootstrap.ts +271 -0
  169. package/src/market-launch.ts +103 -0
  170. package/src/operator-client.ts +169 -0
  171. package/src/oracle.ts +120 -0
  172. package/src/parameters.ts +1019 -0
  173. package/src/preview.ts +53 -1
  174. package/src/protection.ts +112 -0
  175. package/src/risk-pricing.ts +26 -0
  176. package/src/simulation.ts +169 -0
  177. package/src/tranche-client.ts +187 -0
  178. package/src/transfer-fees.ts +99 -0
  179. package/src/type-aliases.ts +294 -32
  180. package/src/types_delegate.ts +6274 -0
  181. package/src/types_v2.ts +16745 -6675
  182. package/src/virtual-book/index.ts +3 -0
  183. package/src/virtual-book/market.ts +76 -0
  184. package/src/virtual-book/projection.ts +265 -0
  185. package/src/virtual-book/quotes.ts +308 -0
  186. package/src/write.ts +1650 -28
  187. package/src/yield-client.ts +117 -0
package/src/constants.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { AccountMeta, PublicKey } from "@solana/web3.js";
2
+ import IDL from "./idl_v2.js";
2
3
 
3
- const DEFAULT_PROGRAM_ID = "358bjJKXWxeAXAzteX1xTgyd9JNnjtzW8fnwCS8Da1mv";
4
+ /** Shared on-chain default; regenerated from the program instead of duplicated here. */
5
+ export const DEFAULT_PROTOCOL_REVENUE_SHARE_BPS = Number(
6
+ IDL.constants.find(({ name }) => name === "DEFAULT_PROTOCOL_REVENUE_SHARE_BPS")!.value
7
+ );
8
+
9
+ const DEFAULT_PROGRAM_ID = "B3vxDQmtKFxfh6hmfLRWKaHZR2w4UPw18XJCTbfrrBa2";
4
10
  const MPL_TOKEN_METADATA_PROGRAM_ID = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
5
11
 
6
12
  function getProgramIdFromEnv(fallback: string): string {
@@ -9,14 +15,29 @@ function getProgramIdFromEnv(fallback: string): string {
9
15
  }
10
16
 
11
17
  /**
12
- * Omnipair Dusk (v2) program ID.
18
+ * Omnipair Dusk program ID.
13
19
  * Reads from env DUSK_PROGRAM_ID.
14
20
  */
15
21
  export const DUSK_PROGRAM_ID = new PublicKey(getProgramIdFromEnv(DEFAULT_PROGRAM_ID));
16
22
 
17
23
  export const PROGRAM_ID = DUSK_PROGRAM_ID;
24
+ /** Current development Market account layout. */
25
+ export const MARKET_LAYOUT_VERSION = Number(
26
+ IDL.constants.find(({ name }) => name === "MARKET_LAYOUT_VERSION")!.value
27
+ );
18
28
  export const TOKEN_METADATA_PROGRAM_ID = new PublicKey(MPL_TOKEN_METADATA_PROGRAM_ID);
19
29
 
30
+ /** Immutable Dusk operator and metadata limits. */
31
+ export const PARAMETER_EXECUTION_MAX_UTILIZATION_BPS = 8_000;
32
+ export const PROPOSAL_METADATA_VERSION = 1;
33
+ export const MAX_PROPOSAL_TITLE_BYTES = 96;
34
+ export const MAX_PROPOSAL_DESCRIPTION_URI_BYTES = 200;
35
+ export const MAX_PROPOSAL_DESCRIPTION_BYTES = 32_768;
36
+ // Nominal 1-7 day ramp at Solana's current 200 ms scheduled slot cadence.
37
+ // Update with the on-chain timing constant if the network cadence changes.
38
+ export const DEFAULT_CONCENTRATION_RAMP_DURATION_SLOTS = 432_000;
39
+ export const MIN_CONCENTRATION_RAMP_DURATION_SLOTS = 432_000;
40
+
20
41
  /**
21
42
  * PDA seeds used by the program
22
43
  */
@@ -27,15 +48,26 @@ export const SEEDS = {
27
48
  MARKET_INTEREST_VAULT: Buffer.from("market_interest"),
28
49
  BORROW_POSITION: Buffer.from("borrow_position_v2"),
29
50
  LEVERAGE_POSITION: Buffer.from("leverage_position_v2"),
51
+ LEVERAGE_COLLATERAL_VAULT: Buffer.from("leverage_collateral"),
52
+ LEVERAGE_DELEGATION: Buffer.from("leverage_delegation_v2"),
30
53
  YIELD_ACCOUNT: Buffer.from("yield"),
31
- HLP_YLP_VAULT: Buffer.from("hlp_ylp_vault"),
32
- INSURANCE: Buffer.from("insurance"),
54
+ // Stable PDA namespace, shared with the program.
55
+ HLP_SRLP_VAULT: Buffer.from("hlp_ylp_vault"),
56
+ HLP_COHORT: Buffer.from("hlp_cohort"),
57
+ EVENT_AUTHORITY: Buffer.from("__event_authority"),
33
58
  FUTARCHY_AUTHORITY: Buffer.from("futarchy_authority"),
34
59
  REFERRAL_PARTNER: Buffer.from("referral_partner"),
35
60
  REFERRAL_ACCRUAL: Buffer.from("referral_accrual"),
36
61
  METADATA: Buffer.from("metadata"),
37
62
  } as const;
38
63
 
64
+ /** Derive the canonical Anchor event-CPI authority for a Dusk program. */
65
+ export function deriveEventAuthorityAddress(
66
+ programId: PublicKey = DUSK_PROGRAM_ID
67
+ ): [PublicKey, number] {
68
+ return PublicKey.findProgramAddressSync([SEEDS.EVENT_AUTHORITY], programId);
69
+ }
70
+
39
71
  function normalizeParamsHash(paramsHash: Uint8Array | Buffer | number[]): Buffer {
40
72
  const hash = Buffer.from(paramsHash);
41
73
  if (hash.length !== 32) {
@@ -47,8 +79,8 @@ function normalizeParamsHash(paramsHash: Uint8Array | Buffer | number[]): Buffer
47
79
  /**
48
80
  * Derive Futarchy Authority PDA address
49
81
  */
50
- export function deriveFutarchyAuthorityAddress(): [PublicKey, number] {
51
- return PublicKey.findProgramAddressSync([SEEDS.FUTARCHY_AUTHORITY], DUSK_PROGRAM_ID);
82
+ export function deriveFutarchyAuthorityAddress(programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
83
+ return PublicKey.findProgramAddressSync([SEEDS.FUTARCHY_AUTHORITY], programId);
52
84
  }
53
85
 
54
86
  /** Derive the protocol-wide referral partner for a referrer authority. */
@@ -63,7 +95,8 @@ export function deriveReferralPartnerAddress(authority: PublicKey): [PublicKey,
63
95
  export function deriveReferralAccrualAddress(
64
96
  referralPartner: PublicKey,
65
97
  market: PublicKey,
66
- assetMint: PublicKey
98
+ assetMint: PublicKey,
99
+ programId: PublicKey = DUSK_PROGRAM_ID
67
100
  ): [PublicKey, number] {
68
101
  return PublicKey.findProgramAddressSync(
69
102
  [
@@ -72,17 +105,44 @@ export function deriveReferralAccrualAddress(
72
105
  market.toBuffer(),
73
106
  assetMint.toBuffer(),
74
107
  ],
75
- DUSK_PROGRAM_ID
108
+ programId
76
109
  );
77
110
  }
78
111
 
112
+ export type U64SeedLike = bigint | number | string | { toString(): string };
113
+
114
+ function u64Seed(value: U64SeedLike, label: string): Buffer {
115
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
116
+ throw new Error(`${label} must be a safe integer when supplied as a number`);
117
+ }
118
+ let normalized: bigint;
119
+ try {
120
+ normalized = BigInt(value.toString());
121
+ } catch {
122
+ throw new Error(`${label} must be an unsigned 64-bit integer`);
123
+ }
124
+ if (normalized < 0n || normalized > 0xffff_ffff_ffff_ffffn) {
125
+ throw new Error(`${label} must be an unsigned 64-bit integer`);
126
+ }
127
+ const encoded = Buffer.alloc(8);
128
+ encoded.writeBigUInt64LE(normalized);
129
+ return encoded;
130
+ }
131
+
132
+ /** Derive one immutable typed parameter proposal. The nonce is Borsh u64 LE. */
133
+
134
+
135
+ /** Derive one support position. Locked srLP cannot be shared across proposals. */
136
+
137
+
79
138
  /**
80
139
  * Derive Dusk market PDA address
81
140
  */
82
141
  export function deriveMarketAddress(
83
142
  baseMint: PublicKey,
84
143
  quoteMint: PublicKey,
85
- paramsHash: Uint8Array | Buffer | number[]
144
+ paramsHash: Uint8Array | Buffer | number[],
145
+ programId: PublicKey = DUSK_PROGRAM_ID
86
146
  ): [PublicKey, number] {
87
147
  return PublicKey.findProgramAddressSync(
88
148
  [
@@ -91,7 +151,7 @@ export function deriveMarketAddress(
91
151
  quoteMint.toBuffer(),
92
152
  normalizeParamsHash(paramsHash),
93
153
  ],
94
- DUSK_PROGRAM_ID
154
+ programId
95
155
  );
96
156
  }
97
157
 
@@ -121,6 +181,18 @@ export function deriveMarketReserveVaultAddress(
121
181
  /**
122
182
  * Derive market collateral vault PDA address
123
183
  */
184
+ /** Per-market collateral custody for leverage positions. */
185
+ export function deriveLeverageCollateralVaultAddress(
186
+ market: PublicKey,
187
+ collateralMint: PublicKey,
188
+ programId: PublicKey = DUSK_PROGRAM_ID
189
+ ): [PublicKey, number] {
190
+ return PublicKey.findProgramAddressSync(
191
+ [SEEDS.LEVERAGE_COLLATERAL_VAULT, market.toBuffer(), collateralMint.toBuffer()],
192
+ programId
193
+ );
194
+ }
195
+
124
196
  export function deriveMarketCollateralVaultAddress(
125
197
  market: PublicKey,
126
198
  collateralMint: PublicKey
@@ -149,10 +221,11 @@ export function deriveMarketInterestVaultAddress(
149
221
  */
150
222
  export function deriveBorrowPositionAddress(
151
223
  market: PublicKey,
224
+ owner: PublicKey,
152
225
  positionId: PublicKey
153
226
  ): [PublicKey, number] {
154
227
  return PublicKey.findProgramAddressSync(
155
- [SEEDS.BORROW_POSITION, market.toBuffer(), positionId.toBuffer()],
228
+ [SEEDS.BORROW_POSITION, market.toBuffer(), owner.toBuffer(), positionId.toBuffer()],
156
229
  DUSK_PROGRAM_ID
157
230
  );
158
231
  }
@@ -160,33 +233,53 @@ export function deriveBorrowPositionAddress(
160
233
  /**
161
234
  * Derive leverage position PDA address
162
235
  */
236
+ /** Delegation is keyed by the position it delegates, not by the owner. */
237
+ export function deriveLeverageDelegationAddress(
238
+ leveragePosition: PublicKey
239
+ ): [PublicKey, number] {
240
+ return PublicKey.findProgramAddressSync(
241
+ [SEEDS.LEVERAGE_DELEGATION, leveragePosition.toBuffer()],
242
+ DUSK_PROGRAM_ID
243
+ );
244
+ }
245
+
163
246
  export function deriveLeveragePositionAddress(
164
247
  market: PublicKey,
165
- positionId: PublicKey
248
+ positionOwner: PublicKey,
249
+ positionId: PublicKey,
250
+ namespaceAuthority: PublicKey = positionOwner
166
251
  ): [PublicKey, number] {
167
252
  return PublicKey.findProgramAddressSync(
168
- [SEEDS.LEVERAGE_POSITION, market.toBuffer(), positionId.toBuffer()],
253
+ [
254
+ SEEDS.LEVERAGE_POSITION,
255
+ market.toBuffer(),
256
+ positionOwner.toBuffer(),
257
+ namespaceAuthority.toBuffer(),
258
+ positionId.toBuffer(),
259
+ ],
169
260
  DUSK_PROGRAM_ID
170
261
  );
171
262
  }
172
263
 
173
- export type YieldTokenKind = "ylp" | "hlp" | 0 | 1;
264
+ export type YieldTokenKind = "srlp" | "hlp" | "junior" | 0 | 1 | 2;
174
265
 
175
266
  function yieldTokenKindCode(tokenKind: YieldTokenKind): number {
176
- if (tokenKind === "ylp" || tokenKind === 0) return 0;
267
+ if (tokenKind === "srlp" || tokenKind === 0) return 0;
177
268
  if (tokenKind === "hlp" || tokenKind === 1) return 1;
269
+ if (tokenKind === "junior" || tokenKind === 2) return 2;
178
270
  throw new Error(`Unsupported yield token kind: ${tokenKind}`);
179
271
  }
180
272
 
181
273
  /**
182
- * Derive yield-account PDA address for yLP/hLP revenue checkpoints.
274
+ * Derive yield-account PDA address for srLP/hLP revenue checkpoints.
183
275
  */
184
276
  export function deriveYieldAccountAddress(
185
277
  market: PublicKey,
186
278
  owner: PublicKey,
187
279
  lpMint: PublicKey,
188
280
  assetMint: PublicKey,
189
- tokenKind: YieldTokenKind
281
+ tokenKind: YieldTokenKind,
282
+ programId: PublicKey = DUSK_PROGRAM_ID
190
283
  ): [PublicKey, number] {
191
284
  return PublicKey.findProgramAddressSync(
192
285
  [
@@ -197,7 +290,7 @@ export function deriveYieldAccountAddress(
197
290
  assetMint.toBuffer(),
198
291
  Buffer.from([yieldTokenKindCode(tokenKind)]),
199
292
  ],
200
- DUSK_PROGRAM_ID
293
+ programId
201
294
  );
202
295
  }
203
296
 
@@ -209,6 +302,7 @@ export interface YieldTransferHookAccountsArgs {
209
302
  baseMint: PublicKey;
210
303
  quoteMint: PublicKey;
211
304
  tokenKind: YieldTokenKind;
305
+ programId?: PublicKey;
212
306
  }
213
307
 
214
308
  export const TRANSFER_HOOK_EXECUTE_DISCRIMINATOR = Buffer.from([
@@ -241,15 +335,31 @@ export interface LpTransferHookValidationArgs {
241
335
  baseMint: PublicKey;
242
336
  quoteMint: PublicKey;
243
337
  tokenKind: YieldTokenKind;
338
+ programId?: PublicKey;
244
339
  }
245
340
 
246
341
  /**
247
342
  * Derive the standard Token-2022 transfer-hook validation PDA for a Dusk LP mint.
248
343
  */
249
- export function deriveYieldTransferHookValidationAddress(lpMint: PublicKey): [PublicKey, number] {
344
+ export function deriveYieldTransferHookValidationAddress(
345
+ lpMint: PublicKey,
346
+ programId: PublicKey = DUSK_PROGRAM_ID
347
+ ): [PublicKey, number] {
250
348
  return PublicKey.findProgramAddressSync(
251
349
  [Buffer.from("extra-account-metas"), lpMint.toBuffer()],
252
- DUSK_PROGRAM_ID
350
+ programId
351
+ );
352
+ }
353
+
354
+ /** Mint-specific hLP cohort; retired mints retain their frozen yield state. */
355
+ export function deriveHlpCohortAddress(
356
+ market: PublicKey,
357
+ hlpMint: PublicKey,
358
+ programId: PublicKey = DUSK_PROGRAM_ID
359
+ ): [PublicKey, number] {
360
+ return PublicKey.findProgramAddressSync(
361
+ [SEEDS.HLP_COHORT, market.toBuffer(), hlpMint.toBuffer()],
362
+ programId
253
363
  );
254
364
  }
255
365
 
@@ -380,7 +490,7 @@ export function buildYieldTransferHookValidationAccountData(extraMetas: AccountM
380
490
 
381
491
  /**
382
492
  * Encode the production Token-2022 transfer-hook validation account for Dusk
383
- * yLP/hLP mints.
493
+ * srLP/hLP mints.
384
494
  *
385
495
  * The validation state resolves static market/asset-mint accounts and derives
386
496
  * source/destination YieldAccount PDAs from the source and destination token
@@ -391,7 +501,17 @@ export function buildLpTransferHookValidationAccountData({
391
501
  baseMint,
392
502
  quoteMint,
393
503
  tokenKind,
504
+ programId = DUSK_PROGRAM_ID,
394
505
  }: LpTransferHookValidationArgs): Buffer {
506
+ const eventMetas = [
507
+ staticTransferHookMeta({
508
+ pubkey: deriveEventAuthorityAddress(programId)[0],
509
+ isSigner: false,
510
+ isWritable: false,
511
+ }),
512
+ staticTransferHookMeta({ pubkey: programId, isSigner: false, isWritable: false }),
513
+ staticTransferHookMeta({ pubkey: deriveFutarchyAuthorityAddress(programId)[0], isSigner: false, isWritable: false }),
514
+ ];
395
515
  return encodeTransferHookValidationAccountData([
396
516
  staticTransferHookMeta({ pubkey: market, isSigner: false, isWritable: true }),
397
517
  staticTransferHookMeta({ pubkey: baseMint, isSigner: false, isWritable: false }),
@@ -420,17 +540,33 @@ export function buildLpTransferHookValidationAccountData({
420
540
  ),
421
541
  true
422
542
  ),
543
+ ...eventMetas,
544
+ ...(yieldTokenKindCode(tokenKind) !== 0
545
+ ? [
546
+ pdaTransferHookMeta(
547
+ [
548
+ { kind: "literal", bytes: yieldTokenKindCode(tokenKind) === 2 ? Buffer.from("junior_cohort") : SEEDS.HLP_COHORT },
549
+ { kind: "accountKey", index: TRANSFER_HOOK_MARKET_ACCOUNT_INDEX },
550
+ { kind: "accountKey", index: 1 },
551
+ ],
552
+ false
553
+ ),
554
+ ]
555
+ : []),
423
556
  ]);
424
557
  }
425
558
 
426
559
  /**
427
- * Build Dusk yLP/hLP transfer-hook extra account metas.
560
+ * Build Dusk srLP/hLP transfer-hook extra account metas.
428
561
  *
429
562
  * Token-2022 passes the source token account, LP mint, destination token
430
- * account, and transfer authority as the base hook accounts. Omnipair Dusk (v2) needs
563
+ * account, and transfer authority as the base hook accounts. Omnipair Dusk needs
431
564
  * the market, underlying asset mint, canonical source/destination yield
432
565
  * accounts, hook program, and standard validation PDA as extra metas so the
433
- * hook can checkpoint revenue before the balance move is finalized.
566
+ * hook can checkpoint revenue before the balance move is finalized. The event
567
+ * authority lets the hook publish `LpTransferred`; Token-2022 ignores it for
568
+ * mints that still use the legacy seven-account layout, so the list works for
569
+ * both layouts.
434
570
  */
435
571
  export function buildLpTransferHookAccountMetas({
436
572
  lpMint,
@@ -440,36 +576,41 @@ export function buildLpTransferHookAccountMetas({
440
576
  baseMint,
441
577
  quoteMint,
442
578
  tokenKind,
579
+ programId = DUSK_PROGRAM_ID,
443
580
  }: YieldTransferHookAccountsArgs): AccountMeta[] {
444
581
  const sourceBaseYieldAccount = deriveYieldAccountAddress(
445
582
  market,
446
583
  sourceOwner,
447
584
  lpMint,
448
585
  baseMint,
449
- tokenKind
586
+ tokenKind,
587
+ programId
450
588
  )[0];
451
589
  const destinationBaseYieldAccount = deriveYieldAccountAddress(
452
590
  market,
453
591
  destinationOwner,
454
592
  lpMint,
455
593
  baseMint,
456
- tokenKind
594
+ tokenKind,
595
+ programId
457
596
  )[0];
458
597
  const sourceQuoteYieldAccount = deriveYieldAccountAddress(
459
598
  market,
460
599
  sourceOwner,
461
600
  lpMint,
462
601
  quoteMint,
463
- tokenKind
602
+ tokenKind,
603
+ programId
464
604
  )[0];
465
605
  const destinationQuoteYieldAccount = deriveYieldAccountAddress(
466
606
  market,
467
607
  destinationOwner,
468
608
  lpMint,
469
609
  quoteMint,
470
- tokenKind
610
+ tokenKind,
611
+ programId
471
612
  )[0];
472
- const validationAccount = deriveYieldTransferHookValidationAddress(lpMint)[0];
613
+ const validationAccount = deriveYieldTransferHookValidationAddress(lpMint, programId)[0];
473
614
 
474
615
  return [
475
616
  { pubkey: market, isSigner: false, isWritable: true },
@@ -479,39 +620,72 @@ export function buildLpTransferHookAccountMetas({
479
620
  { pubkey: destinationBaseYieldAccount, isSigner: false, isWritable: true },
480
621
  { pubkey: sourceQuoteYieldAccount, isSigner: false, isWritable: true },
481
622
  { pubkey: destinationQuoteYieldAccount, isSigner: false, isWritable: true },
482
- { pubkey: DUSK_PROGRAM_ID, isSigner: false, isWritable: false },
623
+ { pubkey: deriveEventAuthorityAddress(programId)[0], isSigner: false, isWritable: false },
624
+ { pubkey: programId, isSigner: false, isWritable: false },
625
+ { pubkey: deriveFutarchyAuthorityAddress(programId)[0], isSigner: false, isWritable: false },
626
+ ...(yieldTokenKindCode(tokenKind) === 1
627
+ ? [{ pubkey: deriveHlpCohortAddress(market, lpMint, programId)[0], isSigner: false, isWritable: false }]
628
+ : yieldTokenKindCode(tokenKind) === 2
629
+ ? [{ pubkey: deriveJuniorCohortAddress(market, lpMint, programId)[0], isSigner: false, isWritable: false }]
630
+ : []),
483
631
  { pubkey: validationAccount, isSigner: false, isWritable: false },
484
632
  ];
485
633
  }
486
634
 
487
635
  /**
488
- * Derive canonical aggregate hLP vault yLP token-account PDA.
636
+ * Derive canonical aggregate hLP vault srLP token-account PDA.
489
637
  */
490
- export function deriveHlpYlpVaultAddress(
638
+ export function deriveHlpSrlpVaultAddress(
491
639
  market: PublicKey,
492
640
  targetHlpMint: PublicKey,
493
- ylpMint: PublicKey
641
+ srlpMint: PublicKey
494
642
  ): [PublicKey, number] {
495
643
  return PublicKey.findProgramAddressSync(
496
644
  [
497
- SEEDS.HLP_YLP_VAULT,
645
+ SEEDS.HLP_SRLP_VAULT,
498
646
  market.toBuffer(),
499
647
  targetHlpMint.toBuffer(),
500
- ylpMint.toBuffer(),
648
+ srlpMint.toBuffer(),
501
649
  ],
502
650
  DUSK_PROGRAM_ID
503
651
  );
504
652
  }
505
653
 
506
- /**
507
- * Derive insurance PDA address
508
- */
509
- export function deriveInsuranceAddress(
510
- market: PublicKey,
511
- assetMint: PublicKey
512
- ): [PublicKey, number] {
513
- return PublicKey.findProgramAddressSync(
514
- [SEEDS.INSURANCE, market.toBuffer(), assetMint.toBuffer()],
515
- DUSK_PROGRAM_ID
516
- );
654
+
655
+
656
+
657
+
658
+
659
+ export function deriveJuniorMintAddress(market: PublicKey, generation: U64SeedLike, programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
660
+ return PublicKey.findProgramAddressSync([Buffer.from("junior_mint"), market.toBuffer(), u64Seed(generation, "generation")], programId);
661
+ }
662
+ export function deriveJuniorCohortAddress(market: PublicKey, mint: PublicKey, programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
663
+ return PublicKey.findProgramAddressSync([Buffer.from("junior_cohort"), market.toBuffer(), mint.toBuffer()], programId);
664
+ }
665
+ export function deriveJuniorExitAddress(market: PublicKey, owner: PublicKey, mint: PublicKey, programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
666
+ return PublicKey.findProgramAddressSync([Buffer.from("junior_exit"), market.toBuffer(), owner.toBuffer(), mint.toBuffer()], programId);
667
+ }
668
+
669
+ export function deriveIncomeEpochAddress(market: PublicKey, bookIndex: number, epoch: U64SeedLike, programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
670
+ if (!Number.isInteger(bookIndex) || bookIndex < 0 || bookIndex > 3) throw new Error("bookIndex must be 0–3");
671
+ return PublicKey.findProgramAddressSync([Buffer.from("income_epoch"), market.toBuffer(), Buffer.from([bookIndex]), u64Seed(epoch, "epoch")], programId);
672
+ }
673
+
674
+
675
+
676
+
677
+
678
+
679
+ export const OPERATOR_POLICY_VERSION = 2;
680
+ export const OPERATOR_PENDING_LIMIT = 1;
681
+ export const JUNIOR_MAX_NOTICE_SLOTS = 4_320_000;
682
+ export const OPERATOR_NOTICE_SLOTS = 4_752_000;
683
+ export const OPERATOR_EXECUTION_WINDOW_SLOTS = 3_024_000;
684
+ export const MAX_OPERATOR_INTEREST_SHARE_BPS = 5_000;
685
+ export function deriveOperatorProposalAddress(market: PublicKey, nonce: U64SeedLike, programId: PublicKey = DUSK_PROGRAM_ID): [PublicKey, number] {
686
+ return PublicKey.findProgramAddressSync([Buffer.from("operator_change"), market.toBuffer(), u64Seed(nonce, "nonce")], programId);
687
+ }
688
+
689
+ export function deriveOperatorRevenueAddress(market: PublicKey,revenueEpoch:U64SeedLike,programId:PublicKey=DUSK_PROGRAM_ID):[PublicKey,number] {
690
+ return PublicKey.findProgramAddressSync([Buffer.from("operator_revenue"),market.toBuffer(),u64Seed(revenueEpoch,"revenueEpoch")],programId);
517
691
  }