@omegax/protocol-sdk 0.4.4 → 0.6.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 (57) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +88 -20
  3. package/dist/claims.d.ts +1 -2
  4. package/dist/claims.js +101 -166
  5. package/dist/internal/protocol/all.d.ts +283 -0
  6. package/dist/internal/protocol/all.js +7195 -0
  7. package/dist/internal/protocol/builders.d.ts +1 -0
  8. package/dist/internal/protocol/builders.js +1 -0
  9. package/dist/internal/protocol/client.d.ts +1 -0
  10. package/dist/internal/protocol/client.js +1 -0
  11. package/dist/internal/protocol/constants.d.ts +1 -0
  12. package/dist/internal/protocol/constants.js +1 -0
  13. package/dist/internal/protocol/decoders.d.ts +1 -0
  14. package/dist/internal/protocol/decoders.js +1 -0
  15. package/dist/internal/protocol/fetchers.d.ts +1 -0
  16. package/dist/internal/protocol/fetchers.js +1 -0
  17. package/dist/internal/protocol/shared.d.ts +1 -0
  18. package/dist/internal/protocol/shared.js +1 -0
  19. package/dist/internal/protocol-seeds/all.d.ts +265 -0
  20. package/dist/internal/protocol-seeds/all.js +455 -0
  21. package/dist/internal/protocol-seeds/claims.d.ts +1 -0
  22. package/dist/internal/protocol-seeds/claims.js +1 -0
  23. package/dist/internal/protocol-seeds/core.d.ts +1 -0
  24. package/dist/internal/protocol-seeds/core.js +1 -0
  25. package/dist/internal/protocol-seeds/liquidity.d.ts +1 -0
  26. package/dist/internal/protocol-seeds/liquidity.js +1 -0
  27. package/dist/internal/protocol-seeds/oracle.d.ts +1 -0
  28. package/dist/internal/protocol-seeds/oracle.js +1 -0
  29. package/dist/internal/protocol-seeds/policy.d.ts +1 -0
  30. package/dist/internal/protocol-seeds/policy.js +1 -0
  31. package/dist/internal/reward-claim.d.ts +17 -0
  32. package/dist/internal/reward-claim.js +27 -0
  33. package/dist/internal/rpc.d.ts +15 -0
  34. package/dist/internal/rpc.js +26 -0
  35. package/dist/internal/types/all.d.ts +1952 -0
  36. package/dist/internal/types/all.js +1 -0
  37. package/dist/internal/types/builders.d.ts +1 -0
  38. package/dist/internal/types/builders.js +1 -0
  39. package/dist/internal/types/claims.d.ts +1 -0
  40. package/dist/internal/types/claims.js +1 -0
  41. package/dist/internal/types/oracle.d.ts +1 -0
  42. package/dist/internal/types/oracle.js +1 -0
  43. package/dist/internal/types/protocol.d.ts +1 -0
  44. package/dist/internal/types/protocol.js +1 -0
  45. package/dist/internal/types/rpc.d.ts +1 -0
  46. package/dist/internal/types/rpc.js +1 -0
  47. package/dist/oracle.js +3 -2
  48. package/dist/protocol.d.ts +3 -13
  49. package/dist/protocol.js +3 -4534
  50. package/dist/protocol_seeds.d.ts +1 -220
  51. package/dist/protocol_seeds.js +1 -324
  52. package/dist/rpc.js +51 -6
  53. package/dist/transactions.d.ts +1 -0
  54. package/dist/transactions.js +28 -6
  55. package/dist/types.d.ts +1 -1424
  56. package/dist/types.js +1 -1
  57. package/package.json +22 -5
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ OmegaX Health Protocol SDK
2
+ Copyright (c) 2026 OMEGAX HEALTH FZCO and contributors
3
+
4
+ Licensed under the Apache License, Version 2.0.
5
+ This product includes software developed by OMEGAX HEALTH FZCO.
package/README.md CHANGED
@@ -5,9 +5,9 @@ TypeScript SDK for OmegaX protocol integrations on Solana.
5
5
  ## Network status
6
6
 
7
7
  - Current live network: **devnet beta**
8
- - Mainnet support: **coming soon**
8
+ - Public integration target: **devnet beta**
9
9
  - Protocol UI: https://protocol.omegax.health
10
- - Protocol repository: `omegaxhealth_protocol`
10
+ - Protocol repository: `omegax-protocol`
11
11
  - Governance token:
12
12
  - Mainnet CA: `4Aar9R14YMbEie6yh8WcH1gWXrBtfucoFjw6SpjXpump`
13
13
  - Devnet: governance token distribution is via the protocol faucet
@@ -16,7 +16,7 @@ It supports:
16
16
 
17
17
  - Oracle lifecycle, staking, attestation voting, and reward claims
18
18
  - Pool creation, configuration, enrollment, funding, and reward claims
19
- - Coverage product and policy lifecycle (subscribe, premium, claim, settlement)
19
+ - Policy series and policy position lifecycle (subscribe, premium, claim, settlement)
20
20
  - Deterministic PDA/seed derivation and account readers
21
21
  - Unsigned claim-intent building + signed message validation
22
22
  - RPC helpers for send/simulate/status workflows
@@ -38,6 +38,11 @@ It supports:
38
38
  npm install @omegax/protocol-sdk
39
39
  ```
40
40
 
41
+ ## Breaking change in `0.5.0`
42
+
43
+ - Legacy and `V2` exported names were removed from the public SDK surface.
44
+ - Use the current canonical protocol builders, readers, and PDA helpers only.
45
+
41
46
  ## Support matrix
42
47
 
43
48
  - Node.js `>=20`
@@ -49,14 +54,18 @@ npm install @omegax/protocol-sdk
49
54
  - Builders create **unsigned** transactions. Your app signs and submits them.
50
55
  - `programId` is explicit in SDK flows and should be passed from your runtime config.
51
56
  - Use `createProtocolClient(connection, programId)` for protocol operations.
52
- - `createConnection({ network: 'mainnet' })` is available but warns that mainnet is coming soon.
57
+ - Keep integrations pointed at `devnet` until OmegaX announces public mainnet availability.
53
58
 
54
59
  ## Quickstart
55
60
 
56
61
  ### 1) Create clients
57
62
 
58
63
  ```ts
59
- import { createConnection, createProtocolClient, createRpcClient } from '@omegax/protocol-sdk';
64
+ import {
65
+ createConnection,
66
+ createProtocolClient,
67
+ createRpcClient,
68
+ } from '@omegax/protocol-sdk';
60
69
 
61
70
  const connection = createConnection({
62
71
  network: 'devnet',
@@ -72,11 +81,12 @@ const rpc = createRpcClient(connection);
72
81
  ### 2) Build an unsigned reward-claim transaction
73
82
 
74
83
  ```ts
75
- const tx = protocol.buildSubmitRewardClaimTx!({
84
+ const tx = protocol.buildSubmitRewardClaimTx({
76
85
  claimant: '<claimant-pubkey>',
77
86
  poolAddress: '<pool-pubkey>',
78
87
  member: '<member-pubkey>',
79
- cycleId: 'cycle-2026-01',
88
+ seriesRefHashHex: '<32-byte-hex>',
89
+ cycleHashHex: '<32-byte-hex>',
80
90
  ruleHashHex: '<32-byte-hex>',
81
91
  intentHashHex: '<32-byte-hex>',
82
92
  payoutAmount: 1n,
@@ -98,30 +108,31 @@ const result = await rpc.broadcastSignedTx({ signedTxBase64: signed });
98
108
 
99
109
  ### Pool creator / operator
100
110
 
101
- - Create and configure pools: `buildCreatePoolV2Tx`, `buildSetPoolStatusTx`, `buildSetPoolTermsHashTx`
102
- - Configure oracle policy/rules: `buildSetPoolOraclePolicyTx`, `buildSetPoolOutcomeRuleTx`, `buildSetPoolOracleTx`
111
+ - Create and configure pools: `buildCreatePoolTx`, `buildSetPoolStatusTx`, `buildSetPoolTermsHashTx`
112
+ - Configure oracle policy/rules: `buildSetPoolOraclePolicyTx`, `buildSetPolicySeriesOutcomeRuleTx`, `buildSetPoolOracleTx`
103
113
  - Fund payout liquidity: `buildFundPoolSolTx`, `buildFundPoolSplTx`
104
- - Manage coverage products: `buildRegisterCoverageProductV2Tx`, `buildUpdateCoverageProductV2Tx`
114
+ - Manage policy series: `buildCreatePolicySeriesTx`, `buildUpdatePolicySeriesTx`
105
115
 
106
116
  ### Pool participant / member
107
117
 
108
118
  - Enroll: `buildEnrollMemberOpenTx`, `buildEnrollMemberTokenGateTx`, `buildEnrollMemberInvitePermitTx`
109
119
  - Authorize claim delegation: `buildSetClaimDelegateTx`
110
- - Claim rewards: `buildSubmitRewardClaimTx` (and legacy `buildSubmitClaimTx`)
111
- - Participate in coverage: `buildSubscribeCoverageProductV2Tx`, `buildCreateCoveragePolicyTx`, `buildIssueCoveragePolicyFromProductV2Tx`
120
+ - Claim rewards: `buildSubmitRewardClaimTx`
121
+ - Participate in policy series: `buildSubscribePolicySeriesTx`, `buildIssuePolicyPositionTx`, `buildPayPremiumSolTx`, `buildPayPremiumSplTx`
112
122
 
113
123
  ### Oracle operator
114
124
 
115
- - Register/update oracle: `buildRegisterOracleV2Tx`, `buildUpdateOracleProfileV2Tx`, `buildUpdateOracleMetadataTx`
125
+ - Register/update oracle: `buildRegisterOracleTx`, `buildUpdateOracleProfileTx`, `buildUpdateOracleMetadataTx`
116
126
  - Stake lifecycle: `buildStakeOracleTx`, `buildRequestUnstakeTx`, `buildFinalizeUnstakeTx`, `buildSlashOracleTx`
117
127
  - Outcome + premium attestations: `buildSubmitOutcomeAttestationVoteTx`, `buildAttestPremiumPaidOffchainTx`
118
- - Claim oracle rewards: `buildClaimOracleV2Tx`
128
+ - Claim oracle rewards: `buildClaimOracleTx`
119
129
 
120
130
  ### Coverage claims
121
131
 
122
132
  - Submit claim: `buildSubmitCoverageClaimTx`
133
+ - Claim approved payout: `buildClaimApprovedCoveragePayoutTx`
123
134
  - Settle claim: `buildSettleCoverageClaimTx`
124
- - Premium payment: `buildPayPremiumOnchainTx`
135
+ - Premium payment: `buildPayPremiumSolTx`, `buildPayPremiumSplTx`
125
136
  - Optional policy NFT mint: `buildMintPolicyNftTx`
126
137
 
127
138
  ## Module imports
@@ -146,11 +157,15 @@ Available subpaths: `claims`, `protocol`, `protocol_seeds`, `rpc`, `oracle`, `ty
146
157
  - `/docs/RELEASE.md` — versioning, CI gates, tag/publish flow
147
158
  - `/docs/DOCS_SYNC_WORKFLOW.md` — exact cross-repo docs sync workflow (`omegax-docs`)
148
159
  - `/docs/CROSS_REPO_RELEASE_ORDER.md` — commit message templates and release ordering
149
- - `/PROTOCOL_V2_PARITY_CHECKLIST.md` — protocol parity checklist
160
+ - `/PROTOCOL_PARITY_CHECKLIST.md` — protocol parity checklist
150
161
 
151
162
  ## Protocol parity
152
163
 
153
- The SDK includes a strict instruction-account parity test against an Anchor IDL.
164
+ The SDK includes:
165
+
166
+ - a strict instruction-account parity test against an Anchor IDL
167
+ - a live protocol-contract parity check when a local `omegax-protocol` workspace is present
168
+ - a local protocol compatibility gate that runs an SDK smoke test plus the full protocol surface matrix through an SDK adapter
154
169
 
155
170
  - Default fixture path: `tests/fixtures/omegax_protocol.idl.json`
156
171
  - Optional local override:
@@ -165,26 +180,79 @@ Refresh the fixture:
165
180
  npm run sync:idl-fixture
166
181
  ```
167
182
 
183
+ For the normal local workspace layout, this reads from:
184
+
185
+ - `../omegax-protocol/idl/omegax_protocol.json`
186
+
187
+ Run the full local compatibility gate before pushing SDK changes that may affect protocol behavior:
188
+
189
+ ```bash
190
+ npm run typecheck
191
+ npm run lint
192
+ npm run format:check
193
+ npm run verify:protocol:local
194
+ ```
195
+
196
+ This verifies the current local `omegax-protocol` workspace state, including staged, unstaged, and untracked source changes, and records the exact workspace fingerprint it tested.
197
+
198
+ For targeted localnet-only verification:
199
+
200
+ ```bash
201
+ npm run test:protocol:localnet
202
+ ```
203
+
204
+ If you changed SDK builders that are consumed by the oracle service, refresh the local dependency there after rebuilding the SDK:
205
+
206
+ ```bash
207
+ cd ../omegaxhealth_services/services/protocol-oracle-service
208
+ npm run sdk:refresh
209
+ npm run sdk:check
210
+ ```
211
+
168
212
  Latest fixture sync metadata:
169
213
 
170
- - Source commit: `e32313b5c49fb06a609252f845845fcf2d49e98d`
171
- - Fixture SHA-256: `da54336ff190407d1dfa89ae8ca976c1f025cf3c53ffdabb853b661c157e4ee9`
214
+ - Source commit: `5b8ae12f572c66b4daa0f52cf0bf533e151f557a`
215
+ - Fixture SHA-256: `273ba886c5454572e3a88f60ae9101a719d7deefce7b549b5a93786cbf04c19b`
172
216
 
173
217
  ## Development commands
174
218
 
175
219
  ```bash
220
+ npm run typecheck
221
+ npm run lint
222
+ npm run format:check
176
223
  npm run build
177
224
  npm test
178
225
  npm pack --dry-run
179
226
  npm audit --omit=dev
180
227
  ```
181
228
 
229
+ ## Cross-repo sync
230
+
231
+ Keep the repos aligned in this order:
232
+
233
+ 1. `omegax-protocol`
234
+ 2. `omegax-sdk`
235
+ 3. `protocol-oracle-service`
236
+ 4. `omegaxhealth_flutter` if the service DTO changed
237
+
238
+ Practical rule:
239
+
240
+ - protocol interface changes start in `omegax-protocol`
241
+ - SDK mirrors the protocol interface and exposes the supported client surface
242
+ - the oracle service refreshes the local SDK package and owns the app-facing Seeker DTO
243
+ - Flutter only follows the service contract
244
+
182
245
  ## OSS docs
183
246
 
184
247
  - `CONTRIBUTING.md`
185
248
  - `SECURITY.md`
186
249
  - `CODE_OF_CONDUCT.md`
250
+ - `AUTHORS.md`
187
251
 
188
252
  ## License
189
253
 
190
- Apache-2.0
254
+ This SDK is licensed under Apache-2.0.
255
+
256
+ The on-chain OmegaX protocol program lives in the separate `omegax-protocol` repository and is licensed independently under AGPL-3.0-or-later.
257
+
258
+ Maintained by OMEGAX HEALTH FZCO with open-source contributors. Project initiated by Marino Sabijan, MD.
package/dist/claims.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { BuildUnsignedClaimTxParams, BuildUnsignedRewardClaimTxParams, ClaimFailureCode, ClaimFailureDetail, ClaimIntent, RewardClaimIntent, ValidateSignedClaimTxReason, ValidateSignedClaimTxParams, ValidateSignedClaimTxResult } from './types.js';
2
- export declare function buildUnsignedClaimTx(params: BuildUnsignedClaimTxParams): ClaimIntent;
1
+ import type { BuildUnsignedRewardClaimTxParams, ClaimFailureCode, ClaimFailureDetail, RewardClaimIntent, ValidateSignedClaimTxReason, ValidateSignedClaimTxParams, ValidateSignedClaimTxResult } from './types.js';
3
2
  export declare function buildUnsignedRewardClaimTx(params: BuildUnsignedRewardClaimTxParams): RewardClaimIntent;
4
3
  export declare function validateSignedClaimTx(params: ValidateSignedClaimTxParams): ValidateSignedClaimTxResult;
5
4
  export declare function mapValidationReasonToClaimFailure(reason: ValidateSignedClaimTxReason | null): ClaimFailureCode | null;
package/dist/claims.js CHANGED
@@ -1,125 +1,12 @@
1
1
  import nacl from 'tweetnacl';
2
2
  import { PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
3
- import { anchorDiscriminator, encodeU64Le, fromHex, hashStringTo32, } from './utils.js';
4
- import { decodeSolanaTransaction, solanaTransactionFirstSignature, solanaTransactionMessageBytes, solanaTransactionRequiredSigner, solanaTransactionSignerSignature, } from './transactions.js';
5
- import { deriveClaimDelegatePda, deriveClaimPda, deriveClaimV2Pda, deriveConfigV2Pda, deriveOutcomeAggregatePda, derivePoolOraclePolicyPda, derivePoolTermsPda, deriveCycleWindowPda, deriveCycleOutcomePda, deriveMembershipPda, } from './protocol_seeds.js';
6
- const SUBMIT_CLAIM_DISCRIMINATOR = anchorDiscriminator('global', 'submit_claim');
7
- const SUBMIT_REWARD_CLAIM_DISCRIMINATOR = anchorDiscriminator('global', 'submit_reward_claim');
8
- function validateRewardClaimOptionalAccounts(params) {
9
- const providedCount = [
10
- params.poolAssetVault,
11
- params.poolVaultTokenAccount,
12
- params.recipientTokenAccount,
13
- ].filter((value) => typeof value === 'string' && value.length > 0).length;
14
- if (providedCount !== 0 && providedCount !== 3) {
15
- throw new Error('poolAssetVault, poolVaultTokenAccount, and recipientTokenAccount must be provided together');
16
- }
17
- }
18
- function serializeSubmitClaimPayload(params) {
19
- const cycleHash = hashStringTo32(params.cycleId);
20
- const intentHash = hashStringTo32(params.intentId);
21
- return Buffer.concat([
22
- SUBMIT_CLAIM_DISCRIMINATOR,
23
- Buffer.from(cycleHash),
24
- Buffer.from(intentHash),
25
- ]);
26
- }
27
- function serializeSubmitRewardClaimPayload(params) {
28
- const cycleHash = hashStringTo32(params.cycleId);
29
- const ruleHash = fromHex(params.ruleHashHex, 32);
30
- const intentHash = fromHex(params.intentHashHex, 32);
31
- return Buffer.concat([
32
- SUBMIT_REWARD_CLAIM_DISCRIMINATOR,
33
- new PublicKey(params.member).toBuffer(),
34
- Buffer.from(cycleHash),
35
- Buffer.from(ruleHash),
36
- Buffer.from(intentHash),
37
- encodeU64Le(params.payoutAmount),
38
- new PublicKey(params.recipient).toBuffer(),
39
- ]);
40
- }
41
- export function buildUnsignedClaimTx(params) {
42
- const claimant = new PublicKey(params.claimantWallet);
43
- const programId = new PublicKey(params.programId);
44
- const poolAddress = new PublicKey(params.poolAddress);
45
- const cycleHash = hashStringTo32(params.cycleId);
46
- const [membershipPda] = deriveMembershipPda({
47
- programId,
48
- poolAddress,
49
- member: claimant,
50
- });
51
- const [cycleOutcomePda] = deriveCycleOutcomePda({
52
- programId,
53
- poolAddress,
54
- member: claimant,
55
- cycleHash,
56
- });
57
- const [claimPda] = deriveClaimPda({
58
- programId,
59
- poolAddress,
60
- member: claimant,
61
- cycleHash,
62
- });
63
- const [cycleWindowPda] = deriveCycleWindowPda({
64
- programId,
65
- poolAddress,
66
- cycleHash,
67
- });
68
- const instruction = new TransactionInstruction({
69
- keys: [
70
- {
71
- pubkey: claimant,
72
- isSigner: true,
73
- isWritable: true,
74
- },
75
- {
76
- pubkey: poolAddress,
77
- isSigner: false,
78
- isWritable: true,
79
- },
80
- {
81
- pubkey: membershipPda,
82
- isSigner: false,
83
- isWritable: false,
84
- },
85
- {
86
- pubkey: cycleOutcomePda,
87
- isSigner: false,
88
- isWritable: true,
89
- },
90
- {
91
- pubkey: cycleWindowPda,
92
- isSigner: false,
93
- isWritable: false,
94
- },
95
- {
96
- pubkey: claimPda,
97
- isSigner: false,
98
- isWritable: true,
99
- },
100
- {
101
- pubkey: SystemProgram.programId,
102
- isSigner: false,
103
- isWritable: false,
104
- },
105
- ],
106
- programId,
107
- data: serializeSubmitClaimPayload(params),
108
- });
109
- const tx = new Transaction({
110
- recentBlockhash: params.recentBlockhash,
111
- feePayer: claimant,
112
- }).add(instruction);
113
- const unsignedTxBase64 = tx
114
- .serialize({ requireAllSignatures: false, verifySignatures: false })
115
- .toString('base64');
116
- return {
117
- intentId: params.intentId,
118
- unsignedTxBase64,
119
- requiredSigner: claimant.toBase58(),
120
- expiresAtIso: params.expiresAtIso,
121
- attestationRefs: params.attestationRefs,
122
- };
3
+ import { fromHex } from './utils.js';
4
+ import { decodeSolanaTransaction, solanaTransactionFirstSignature, solanaTransactionIntentMessageBytes, solanaTransactionMessageBytes, solanaTransactionRequiredSigner, solanaTransactionSignerSignature, } from './transactions.js';
5
+ import { deriveClaimPda, deriveConfigPda, deriveOutcomeAggregatePda, derivePoolCompliancePolicyPda, derivePoolOraclePolicyPda, derivePoolTreasuryReservePda, derivePoolTermsPda, deriveMembershipPda, ZERO_PUBKEY, } from './protocol_seeds.js';
6
+ import { encodeSubmitRewardClaimPayload, validateRewardClaimOptionalAccounts, } from './internal/reward-claim.js';
7
+ function bytesEqual(left, right) {
8
+ return (left.length === right.length &&
9
+ left.every((value, index) => value === right[index]));
123
10
  }
124
11
  export function buildUnsignedRewardClaimTx(params) {
125
12
  validateRewardClaimOptionalAccounts(params);
@@ -127,9 +14,11 @@ export function buildUnsignedRewardClaimTx(params) {
127
14
  const member = new PublicKey(params.member);
128
15
  const programId = new PublicKey(params.programId);
129
16
  const poolAddress = new PublicKey(params.poolAddress);
130
- const cycleHash = hashStringTo32(params.cycleId);
17
+ const payoutMint = new PublicKey(params.payoutMint ?? ZERO_PUBKEY);
18
+ const cycleHash = fromHex(params.cycleHashHex, 32);
131
19
  const ruleHash = fromHex(params.ruleHashHex, 32);
132
- const [configV2Pda] = deriveConfigV2Pda(programId);
20
+ const seriesRefHash = fromHex(params.seriesRefHashHex, 32);
21
+ const [configPda] = deriveConfigPda(programId);
133
22
  const [poolTermsPda] = derivePoolTermsPda({
134
23
  programId,
135
24
  poolAddress,
@@ -138,6 +27,11 @@ export function buildUnsignedRewardClaimTx(params) {
138
27
  programId,
139
28
  poolAddress,
140
29
  });
30
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
31
+ programId,
32
+ poolAddress,
33
+ paymentMint: payoutMint,
34
+ });
141
35
  const [membershipPda] = deriveMembershipPda({
142
36
  programId,
143
37
  poolAddress,
@@ -146,24 +40,29 @@ export function buildUnsignedRewardClaimTx(params) {
146
40
  const [aggregatePda] = deriveOutcomeAggregatePda({
147
41
  programId,
148
42
  poolAddress,
43
+ seriesRefHash,
149
44
  member,
150
45
  cycleHash,
151
46
  ruleHash,
152
47
  });
153
- const [claimRecordV2Pda] = deriveClaimV2Pda({
48
+ const [claimRecordPda] = deriveClaimPda({
154
49
  programId,
155
50
  poolAddress,
51
+ seriesRefHash,
156
52
  member,
157
53
  cycleHash,
158
54
  ruleHash,
159
55
  });
160
- const [claimDelegatePda] = deriveClaimDelegatePda({
161
- programId,
162
- poolAddress,
163
- member,
164
- });
165
56
  const optionPlaceholder = programId;
166
- const claimDelegateAccount = params.claimDelegate ? claimDelegatePda : optionPlaceholder;
57
+ const memberCycleAccount = params.memberCycle
58
+ ? new PublicKey(params.memberCycle)
59
+ : optionPlaceholder;
60
+ const cohortSettlementRootAccount = params.cohortSettlementRoot
61
+ ? new PublicKey(params.cohortSettlementRoot)
62
+ : optionPlaceholder;
63
+ const claimDelegateAccount = params.claimDelegate
64
+ ? new PublicKey(params.claimDelegate)
65
+ : optionPlaceholder;
167
66
  const poolAssetVaultAccount = params.poolAssetVault
168
67
  ? new PublicKey(params.poolAssetVault)
169
68
  : optionPlaceholder;
@@ -173,26 +72,57 @@ export function buildUnsignedRewardClaimTx(params) {
173
72
  const recipientTokenAccount = params.recipientTokenAccount
174
73
  ? new PublicKey(params.recipientTokenAccount)
175
74
  : optionPlaceholder;
75
+ const keys = [
76
+ { pubkey: claimant, isSigner: true, isWritable: true },
77
+ { pubkey: configPda, isSigner: false, isWritable: false },
78
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
79
+ { pubkey: poolTermsPda, isSigner: false, isWritable: false },
80
+ { pubkey: poolOraclePolicyPda, isSigner: false, isWritable: false },
81
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
82
+ { pubkey: membershipPda, isSigner: false, isWritable: false },
83
+ { pubkey: aggregatePda, isSigner: false, isWritable: true },
84
+ { pubkey: memberCycleAccount, isSigner: false, isWritable: false },
85
+ {
86
+ pubkey: cohortSettlementRootAccount,
87
+ isSigner: false,
88
+ isWritable: params.cohortSettlementRoot != null,
89
+ },
90
+ {
91
+ pubkey: new PublicKey(params.recipientSystemAccount),
92
+ isSigner: false,
93
+ isWritable: true,
94
+ },
95
+ { pubkey: claimDelegateAccount, isSigner: false, isWritable: false },
96
+ { pubkey: poolAssetVaultAccount, isSigner: false, isWritable: false },
97
+ {
98
+ pubkey: poolVaultTokenAccount,
99
+ isSigner: false,
100
+ isWritable: params.poolVaultTokenAccount != null,
101
+ },
102
+ {
103
+ pubkey: recipientTokenAccount,
104
+ isSigner: false,
105
+ isWritable: params.recipientTokenAccount != null,
106
+ },
107
+ { pubkey: claimRecordPda, isSigner: false, isWritable: true },
108
+ {
109
+ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
110
+ isSigner: false,
111
+ isWritable: false,
112
+ },
113
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
114
+ {
115
+ pubkey: params.includePoolCompliancePolicy
116
+ ? derivePoolCompliancePolicyPda({ programId, poolAddress })[0]
117
+ : programId,
118
+ isSigner: false,
119
+ isWritable: false,
120
+ },
121
+ ];
176
122
  const instruction = new TransactionInstruction({
177
- keys: [
178
- { pubkey: claimant, isSigner: true, isWritable: true },
179
- { pubkey: configV2Pda, isSigner: false, isWritable: false },
180
- { pubkey: poolAddress, isSigner: false, isWritable: true },
181
- { pubkey: poolTermsPda, isSigner: false, isWritable: false },
182
- { pubkey: poolOraclePolicyPda, isSigner: false, isWritable: false },
183
- { pubkey: membershipPda, isSigner: false, isWritable: false },
184
- { pubkey: aggregatePda, isSigner: false, isWritable: true },
185
- { pubkey: new PublicKey(params.recipientSystemAccount), isSigner: false, isWritable: true },
186
- { pubkey: claimDelegateAccount, isSigner: false, isWritable: false },
187
- { pubkey: poolAssetVaultAccount, isSigner: false, isWritable: false },
188
- { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: params.poolVaultTokenAccount != null },
189
- { pubkey: recipientTokenAccount, isSigner: false, isWritable: params.recipientTokenAccount != null },
190
- { pubkey: claimRecordV2Pda, isSigner: false, isWritable: true },
191
- { pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
192
- { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
193
- ],
123
+ keys,
194
124
  programId,
195
- data: serializeSubmitRewardClaimPayload(params),
125
+ data: encodeSubmitRewardClaimPayload(params),
196
126
  });
197
127
  const tx = new Transaction({
198
128
  recentBlockhash: params.recentBlockhash,
@@ -220,19 +150,23 @@ export function validateSignedClaimTx(params) {
220
150
  signer: null,
221
151
  };
222
152
  }
223
- if (typeof params.expectedUnsignedTxBase64 === 'string' && params.expectedUnsignedTxBase64.length > 0) {
153
+ if (typeof params.expectedUnsignedTxBase64 === 'string' &&
154
+ params.expectedUnsignedTxBase64.length > 0) {
224
155
  try {
225
156
  const expectedUnsignedTx = decodeSolanaTransaction(params.expectedUnsignedTxBase64);
226
157
  const signedMessageBytes = solanaTransactionMessageBytes(tx);
227
158
  const expectedMessageBytes = solanaTransactionMessageBytes(expectedUnsignedTx);
228
- if (signedMessageBytes.length !== expectedMessageBytes.length
229
- || !signedMessageBytes.every((value, index) => value === expectedMessageBytes[index])) {
230
- return {
231
- valid: false,
232
- txSignature: solanaTransactionFirstSignature(tx),
233
- reason: 'intent_message_mismatch',
234
- signer: solanaTransactionRequiredSigner(tx),
235
- };
159
+ if (!bytesEqual(signedMessageBytes, expectedMessageBytes)) {
160
+ const signedIntentBytes = solanaTransactionIntentMessageBytes(tx);
161
+ const expectedIntentBytes = solanaTransactionIntentMessageBytes(expectedUnsignedTx);
162
+ if (!bytesEqual(signedIntentBytes, expectedIntentBytes)) {
163
+ return {
164
+ valid: false,
165
+ txSignature: solanaTransactionFirstSignature(tx),
166
+ reason: 'intent_message_mismatch',
167
+ signer: solanaTransactionRequiredSigner(tx),
168
+ };
169
+ }
236
170
  }
237
171
  }
238
172
  catch {
@@ -308,23 +242,24 @@ export function normalizeClaimSimulationFailure(params) {
308
242
  ? params.err
309
243
  : JSON.stringify(params.err));
310
244
  const haystack = `${logsText}\n${errText}`;
311
- if (haystack.includes('insufficientpoolliquidity')
312
- || haystack.includes('insufficient funds')
313
- || haystack.includes('insufficient lamports')) {
245
+ if (haystack.includes('insufficientpoolliquidity') ||
246
+ haystack.includes('insufficient funds') ||
247
+ haystack.includes('insufficient lamports')) {
314
248
  return {
315
249
  code: 'simulation_failed_insufficient_funds',
316
250
  message: 'Pool does not have sufficient liquidity for this claim.',
317
251
  };
318
252
  }
319
- if (haystack.includes('poolnotactive') || haystack.includes('pool is not active')) {
253
+ if (haystack.includes('poolnotactive') ||
254
+ haystack.includes('pool is not active')) {
320
255
  return {
321
256
  code: 'simulation_failed_pool_paused',
322
257
  message: 'Pool is paused or not active for claims.',
323
258
  };
324
259
  }
325
- if (haystack.includes('membershipnotactive')
326
- || haystack.includes('membership member mismatch')
327
- || haystack.includes('membership')) {
260
+ if (haystack.includes('membershipnotactive') ||
261
+ haystack.includes('membership member mismatch') ||
262
+ haystack.includes('membership')) {
328
263
  return {
329
264
  code: 'simulation_failed_membership_invalid',
330
265
  message: 'Membership is not active for this pool.',
@@ -338,9 +273,9 @@ export function normalizeClaimSimulationFailure(params) {
338
273
  export function normalizeClaimRpcFailure(error) {
339
274
  const message = error instanceof Error ? error.message : String(error);
340
275
  const normalized = lower(message);
341
- if (normalized.includes('timeout')
342
- || normalized.includes('timed out')
343
- || normalized.includes('blockhash not found')) {
276
+ if (normalized.includes('timeout') ||
277
+ normalized.includes('timed out') ||
278
+ normalized.includes('blockhash not found')) {
344
279
  return {
345
280
  code: 'rpc_timeout',
346
281
  message: message || 'RPC timeout while submitting claim transaction.',