@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.
- package/NOTICE +5 -0
- package/README.md +88 -20
- package/dist/claims.d.ts +1 -2
- package/dist/claims.js +101 -166
- package/dist/internal/protocol/all.d.ts +283 -0
- package/dist/internal/protocol/all.js +7195 -0
- package/dist/internal/protocol/builders.d.ts +1 -0
- package/dist/internal/protocol/builders.js +1 -0
- package/dist/internal/protocol/client.d.ts +1 -0
- package/dist/internal/protocol/client.js +1 -0
- package/dist/internal/protocol/constants.d.ts +1 -0
- package/dist/internal/protocol/constants.js +1 -0
- package/dist/internal/protocol/decoders.d.ts +1 -0
- package/dist/internal/protocol/decoders.js +1 -0
- package/dist/internal/protocol/fetchers.d.ts +1 -0
- package/dist/internal/protocol/fetchers.js +1 -0
- package/dist/internal/protocol/shared.d.ts +1 -0
- package/dist/internal/protocol/shared.js +1 -0
- package/dist/internal/protocol-seeds/all.d.ts +265 -0
- package/dist/internal/protocol-seeds/all.js +455 -0
- package/dist/internal/protocol-seeds/claims.d.ts +1 -0
- package/dist/internal/protocol-seeds/claims.js +1 -0
- package/dist/internal/protocol-seeds/core.d.ts +1 -0
- package/dist/internal/protocol-seeds/core.js +1 -0
- package/dist/internal/protocol-seeds/liquidity.d.ts +1 -0
- package/dist/internal/protocol-seeds/liquidity.js +1 -0
- package/dist/internal/protocol-seeds/oracle.d.ts +1 -0
- package/dist/internal/protocol-seeds/oracle.js +1 -0
- package/dist/internal/protocol-seeds/policy.d.ts +1 -0
- package/dist/internal/protocol-seeds/policy.js +1 -0
- package/dist/internal/reward-claim.d.ts +17 -0
- package/dist/internal/reward-claim.js +27 -0
- package/dist/internal/rpc.d.ts +15 -0
- package/dist/internal/rpc.js +26 -0
- package/dist/internal/types/all.d.ts +1952 -0
- package/dist/internal/types/all.js +1 -0
- package/dist/internal/types/builders.d.ts +1 -0
- package/dist/internal/types/builders.js +1 -0
- package/dist/internal/types/claims.d.ts +1 -0
- package/dist/internal/types/claims.js +1 -0
- package/dist/internal/types/oracle.d.ts +1 -0
- package/dist/internal/types/oracle.js +1 -0
- package/dist/internal/types/protocol.d.ts +1 -0
- package/dist/internal/types/protocol.js +1 -0
- package/dist/internal/types/rpc.d.ts +1 -0
- package/dist/internal/types/rpc.js +1 -0
- package/dist/oracle.js +3 -2
- package/dist/protocol.d.ts +3 -13
- package/dist/protocol.js +3 -4534
- package/dist/protocol_seeds.d.ts +1 -220
- package/dist/protocol_seeds.js +1 -324
- package/dist/rpc.js +51 -6
- package/dist/transactions.d.ts +1 -0
- package/dist/transactions.js +28 -6
- package/dist/types.d.ts +1 -1424
- package/dist/types.js +1 -1
- package/package.json +22 -5
package/NOTICE
ADDED
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
|
-
-
|
|
8
|
+
- Public integration target: **devnet beta**
|
|
9
9
|
- Protocol UI: https://protocol.omegax.health
|
|
10
|
-
- Protocol repository: `
|
|
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
|
-
-
|
|
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
|
-
-
|
|
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 {
|
|
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
|
-
|
|
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: `
|
|
102
|
-
- Configure oracle policy/rules: `buildSetPoolOraclePolicyTx`, `
|
|
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
|
|
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`
|
|
111
|
-
- Participate in
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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
|
-
- `/
|
|
160
|
+
- `/PROTOCOL_PARITY_CHECKLIST.md` — protocol parity checklist
|
|
150
161
|
|
|
151
162
|
## Protocol parity
|
|
152
163
|
|
|
153
|
-
The SDK includes
|
|
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: `
|
|
171
|
-
- Fixture SHA-256: `
|
|
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 {
|
|
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 {
|
|
4
|
-
import { decodeSolanaTransaction, solanaTransactionFirstSignature, solanaTransactionMessageBytes, solanaTransactionRequiredSigner, solanaTransactionSignerSignature, } from './transactions.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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
|
|
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 [
|
|
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
|
|
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:
|
|
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' &&
|
|
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
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
313
|
-
|
|
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') ||
|
|
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
|
-
|
|
327
|
-
|
|
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
|
-
|
|
343
|
-
|
|
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.',
|