@omegax/protocol-sdk 0.4.2 → 0.4.4

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/dist/protocol.js CHANGED
@@ -1,6 +1,7 @@
1
- import { PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
1
+ import { ComputeBudgetProgram, Ed25519Program, PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, Transaction, TransactionMessage, TransactionInstruction, VersionedTransaction, } from '@solana/web3.js';
2
+ import { blake3 } from '@noble/hashes/blake3.js';
2
3
  import { anchorDiscriminator, encodeI64Le, encodeString, encodeU16Le, encodeU64Le, fromHex, hashStringTo32, readI64Le, readString, readU16Le, readU64Le, toHex, } from './utils.js';
3
- import { asPubkey, deriveClaimPda, deriveClaimDelegatePda, deriveClaimV2Pda, deriveConfigPda, deriveConfigV2Pda, deriveCoverageClaimPda, deriveCoverageProductPda, deriveCoverageNftPda, deriveCoveragePolicyPda, deriveCycleOutcomePda, deriveCycleWindowPda, deriveEnrollmentReplayPda, deriveAttestationVotePda, deriveInviteIssuerPda, deriveMembershipPda, deriveOracleStakePda, deriveOracleProfilePda, deriveOutcomeAggregatePda, deriveOraclePda, derivePoolAssetVaultPda, derivePoolTermsPda, derivePoolOraclePolicyPda, derivePoolOraclePda, derivePoolPda, derivePoolRulePda, derivePremiumLedgerPda, derivePremiumReplayPda, deriveReplayPda, deriveSchemaPda, ZERO_PUBKEY, } from './protocol_seeds.js';
4
+ import { asPubkey, deriveClaimPda, deriveClaimDelegatePda, deriveClaimV2Pda, deriveConfigPda, deriveConfigV2Pda, deriveCoverageClaimPda, deriveCoverageProductPda, deriveCoverageProductPaymentOptionPda, deriveCoverageNftPda, deriveCoveragePolicyPda, deriveCycleOutcomePda, deriveCycleWindowPda, deriveEnrollmentReplayPda, deriveAttestationVotePda, deriveCycleQuoteReplayPda, deriveInviteIssuerPda, deriveMemberCyclePda, deriveMembershipPda, deriveOracleStakePda, deriveOracleProfilePda, deriveOutcomeAggregatePda, deriveOraclePda, derivePoolAssetVaultPda, derivePoolOraclePermissionSetPda, derivePoolOracleFeeVaultPda, derivePoolTermsPda, derivePoolOraclePolicyPda, derivePoolOraclePda, derivePoolPda, derivePoolRulePda, deriveProtocolFeeVaultPda, derivePremiumLedgerPda, derivePremiumReplayPda, derivePoolTreasuryReservePda, deriveReplayPda, deriveSchemaPda, ZERO_PUBKEY, } from './protocol_seeds.js';
4
5
  const MAX_POOL_ID_SEED_BYTES = 32;
5
6
  const MAX_ORACLE_SUPPORTED_SCHEMAS = 16;
6
7
  export const PROTOCOL_PROGRAM_ID = 'Bn6eixac1QEEVErGBvBjxAd6pgB9e2q4XHvAkinQ5y1B';
@@ -31,6 +32,8 @@ const IX_FINALIZE_UNSTAKE = anchorDiscriminator('global', 'finalize_unstake');
31
32
  const IX_SLASH_ORACLE = anchorDiscriminator('global', 'slash_oracle');
32
33
  const IX_CREATE_POOL_V2 = anchorDiscriminator('global', 'create_pool_v2');
33
34
  const IX_SET_POOL_ORACLE_POLICY = anchorDiscriminator('global', 'set_pool_oracle_policy');
35
+ const IX_SET_POOL_ORACLE_PERMISSIONS = anchorDiscriminator('global', 'set_pool_oracle_permissions');
36
+ const IX_SET_POOL_COVERAGE_RESERVE_FLOOR = anchorDiscriminator('global', 'set_pool_coverage_reserve_floor');
34
37
  const IX_SET_POOL_TERMS_HASH = anchorDiscriminator('global', 'set_pool_terms_hash');
35
38
  const IX_REGISTER_OUTCOME_SCHEMA = anchorDiscriminator('global', 'register_outcome_schema');
36
39
  const IX_VERIFY_OUTCOME_SCHEMA = anchorDiscriminator('global', 'verify_outcome_schema');
@@ -44,6 +47,7 @@ const IX_FUND_POOL_SOL = anchorDiscriminator('global', 'fund_pool_sol');
44
47
  const IX_FUND_POOL_SPL = anchorDiscriminator('global', 'fund_pool_spl');
45
48
  const IX_SUBMIT_REWARD_CLAIM = anchorDiscriminator('global', 'submit_reward_claim');
46
49
  const IX_REGISTER_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'register_coverage_product_v2');
50
+ const IX_UPSERT_COVERAGE_PRODUCT_PAYMENT_OPTION = anchorDiscriminator('global', 'upsert_coverage_product_payment_option');
47
51
  const IX_UPDATE_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'update_coverage_product_v2');
48
52
  const IX_SUBSCRIBE_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'subscribe_coverage_product_v2');
49
53
  const IX_ISSUE_COVERAGE_POLICY_FROM_PRODUCT_V2 = anchorDiscriminator('global', 'issue_coverage_policy_from_product_v2');
@@ -55,6 +59,16 @@ const IX_SUBMIT_COVERAGE_CLAIM = anchorDiscriminator('global', 'submit_coverage_
55
59
  const IX_SETTLE_COVERAGE_CLAIM = anchorDiscriminator('global', 'settle_coverage_claim');
56
60
  const IX_MIGRATE_POOL_V1_TO_V2 = anchorDiscriminator('global', 'migrate_pool_v1_to_v2');
57
61
  const IX_MIGRATE_MEMBERSHIP_V1_TO_V2 = anchorDiscriminator('global', 'migrate_membership_v1_to_v2');
62
+ const IX_ACTIVATE_CYCLE_WITH_QUOTE_SOL = anchorDiscriminator('global', 'activate_cycle_with_quote_sol');
63
+ const IX_ACTIVATE_CYCLE_WITH_QUOTE_SPL = anchorDiscriminator('global', 'activate_cycle_with_quote_spl');
64
+ const IX_SETTLE_CYCLE_COMMITMENT = anchorDiscriminator('global', 'settle_cycle_commitment');
65
+ const IX_SETTLE_CYCLE_COMMITMENT_SOL = anchorDiscriminator('global', 'settle_cycle_commitment_sol');
66
+ const IX_WITHDRAW_POOL_TREASURY_SPL = anchorDiscriminator('global', 'withdraw_pool_treasury_spl');
67
+ const IX_WITHDRAW_POOL_TREASURY_SOL = anchorDiscriminator('global', 'withdraw_pool_treasury_sol');
68
+ const IX_WITHDRAW_PROTOCOL_FEE_SPL = anchorDiscriminator('global', 'withdraw_protocol_fee_spl');
69
+ const IX_WITHDRAW_PROTOCOL_FEE_SOL = anchorDiscriminator('global', 'withdraw_protocol_fee_sol');
70
+ const IX_WITHDRAW_POOL_ORACLE_FEE_SPL = anchorDiscriminator('global', 'withdraw_pool_oracle_fee_spl');
71
+ const IX_WITHDRAW_POOL_ORACLE_FEE_SOL = anchorDiscriminator('global', 'withdraw_pool_oracle_fee_sol');
58
72
  const ACCOUNT_PROTOCOL_CONFIG = anchorDiscriminator('account', 'ProtocolConfig');
59
73
  const ACCOUNT_POOL = anchorDiscriminator('account', 'Pool');
60
74
  const ACCOUNT_ORACLE_REGISTRY = anchorDiscriminator('account', 'OracleRegistryEntry');
@@ -70,6 +84,8 @@ const ACCOUNT_ORACLE_STAKE_POSITION = anchorDiscriminator('account', 'OracleStak
70
84
  const ACCOUNT_POOL_ORACLE_POLICY = anchorDiscriminator('account', 'PoolOraclePolicy');
71
85
  const ACCOUNT_POOL_TERMS = anchorDiscriminator('account', 'PoolTerms');
72
86
  const ACCOUNT_POOL_ASSET_VAULT = anchorDiscriminator('account', 'PoolAssetVault');
87
+ const ACCOUNT_PROTOCOL_FEE_VAULT = anchorDiscriminator('account', 'ProtocolFeeVault');
88
+ const ACCOUNT_POOL_ORACLE_FEE_VAULT = anchorDiscriminator('account', 'PoolOracleFeeVault');
73
89
  const ACCOUNT_OUTCOME_SCHEMA = anchorDiscriminator('account', 'OutcomeSchemaRegistryEntry');
74
90
  const ACCOUNT_POOL_OUTCOME_RULE = anchorDiscriminator('account', 'PoolOutcomeRule');
75
91
  const ACCOUNT_INVITE_ISSUER = anchorDiscriminator('account', 'InviteIssuerRegistryEntry');
@@ -78,11 +94,18 @@ const ACCOUNT_CLAIM_RECORD_V2 = anchorDiscriminator('account', 'ClaimRecordV2');
78
94
  const ACCOUNT_COVERAGE_CLAIM_RECORD = anchorDiscriminator('account', 'CoverageClaimRecord');
79
95
  const ACCOUNT_COVERAGE_POLICY_POSITION_NFT = anchorDiscriminator('account', 'CoveragePolicyPositionNft');
80
96
  const ACCOUNT_COVERAGE_PRODUCT = anchorDiscriminator('account', 'CoverageProduct');
97
+ const ACCOUNT_COVERAGE_PRODUCT_PAYMENT_OPTION = anchorDiscriminator('account', 'CoverageProductPaymentOption');
81
98
  const ACCOUNT_ENROLLMENT_PERMIT_REPLAY = anchorDiscriminator('account', 'EnrollmentPermitReplay');
82
99
  const ACCOUNT_ATTESTATION_VOTE = anchorDiscriminator('account', 'AttestationVote');
83
100
  const ACCOUNT_COVERAGE_POLICY = anchorDiscriminator('account', 'CoveragePolicy');
84
101
  const ACCOUNT_PREMIUM_LEDGER = anchorDiscriminator('account', 'PremiumLedger');
85
102
  const ACCOUNT_PREMIUM_ATTESTATION_REPLAY = anchorDiscriminator('account', 'PremiumAttestationReplay');
103
+ const ACCOUNT_POOL_ORACLE_PERMISSION_SET = anchorDiscriminator('account', 'PoolOraclePermissionSet');
104
+ const ACCOUNT_MEMBER_CYCLE = anchorDiscriminator('account', 'MemberCycleState');
105
+ const ACCOUNT_CYCLE_QUOTE_REPLAY = anchorDiscriminator('account', 'CycleQuoteReplay');
106
+ const ACCOUNT_POOL_TREASURY_RESERVE = anchorDiscriminator('account', 'PoolTreasuryReserve');
107
+ const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
108
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
86
109
  function pubkeyFromData(buffer, offset) {
87
110
  return new PublicKey(buffer.subarray(offset, offset + 32)).toBase58();
88
111
  }
@@ -120,6 +143,75 @@ function parsePoolType(code) {
120
143
  return 'unknown';
121
144
  }
122
145
  }
146
+ function parseMemberCycleStatus(code) {
147
+ switch (code) {
148
+ case 1:
149
+ return 'active';
150
+ case 2:
151
+ return 'settled';
152
+ default:
153
+ return 'unknown';
154
+ }
155
+ }
156
+ function deriveAssociatedTokenAddress(params) {
157
+ const owner = asPubkey(params.owner);
158
+ const mint = asPubkey(params.mint);
159
+ const [address] = PublicKey.findProgramAddressSync([owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID);
160
+ return address;
161
+ }
162
+ export function buildCycleQuoteMessage(fields) {
163
+ return Buffer.concat([
164
+ Buffer.from('omegax:cycle_quote:v1', 'utf8'),
165
+ asPubkey(fields.poolAddress).toBuffer(),
166
+ asPubkey(fields.member).toBuffer(),
167
+ Buffer.from(fromHex(fields.productIdHashHex, 32)),
168
+ asPubkey(fields.paymentMint).toBuffer(),
169
+ encodeU64Le(fields.premiumAmountRaw),
170
+ encodeU64Le(fields.canonicalPremiumAmount),
171
+ encodeU64Le(fields.periodIndex),
172
+ Buffer.from([fields.commitmentEnabled ? 1 : 0]),
173
+ encodeU64Le(fields.bondAmountRaw),
174
+ encodeU64Le(fields.shieldFeeRaw),
175
+ encodeU64Le(fields.protocolFeeRaw),
176
+ encodeU64Le(fields.oracleFeeRaw),
177
+ encodeU64Le(fields.netPoolPremiumRaw),
178
+ encodeU64Le(fields.totalAmountRaw),
179
+ Buffer.from([fields.includedShieldCount]),
180
+ encodeU16Le(fields.thresholdBps),
181
+ encodeI64Le(fields.expiresAtTs),
182
+ Buffer.from(fromHex(fields.nonceHashHex, 32)),
183
+ Buffer.from(fromHex(fields.quoteMetaHashHex, 32)),
184
+ ]);
185
+ }
186
+ function asCycleQuoteMessage(input) {
187
+ if (input instanceof Uint8Array) {
188
+ return Buffer.from(input);
189
+ }
190
+ return buildCycleQuoteMessage(input);
191
+ }
192
+ export function buildCycleQuoteHash(input) {
193
+ return Buffer.from(blake3(asCycleQuoteMessage(input)));
194
+ }
195
+ export function buildCycleQuoteSignatureMessage(input) {
196
+ return Buffer.concat([
197
+ Buffer.from('omegax:cycle_quote_sig:v1', 'utf8'),
198
+ buildCycleQuoteHash(input),
199
+ ]);
200
+ }
201
+ export function compileTransactionToV0(transaction, lookupTableAccounts) {
202
+ if (!transaction.feePayer) {
203
+ throw new Error('transaction fee payer is required to compile a v0 transaction');
204
+ }
205
+ if (!transaction.recentBlockhash) {
206
+ throw new Error('transaction recentBlockhash is required to compile a v0 transaction');
207
+ }
208
+ const message = new TransactionMessage({
209
+ payerKey: transaction.feePayer,
210
+ recentBlockhash: transaction.recentBlockhash,
211
+ instructions: transaction.instructions,
212
+ }).compileToV0Message(lookupTableAccounts);
213
+ return new VersionedTransaction(message);
214
+ }
123
215
  function hasDiscriminator(data, discriminator) {
124
216
  if (data.length < 8)
125
217
  return false;
@@ -430,6 +522,8 @@ function decodeCycleOutcomeAggregateAccount(address, data) {
430
522
  offset += 1;
431
523
  const claimed = data.readUInt8(offset) === 1;
432
524
  offset += 1;
525
+ const rewardLiabilityReserved = data.readUInt8(offset) === 1;
526
+ offset += 1;
433
527
  const latestAsOfTs = Number(readI64Le(data, offset));
434
528
  offset += 8;
435
529
  const bump = data.readUInt8(offset);
@@ -446,6 +540,7 @@ function decodeCycleOutcomeAggregateAccount(address, data) {
446
540
  finalized,
447
541
  passed,
448
542
  claimed,
543
+ rewardLiabilityReserved,
449
544
  latestAsOfTs,
450
545
  bump,
451
546
  };
@@ -536,6 +631,8 @@ function decodePoolOraclePolicyAccount(address, data) {
536
631
  offset += 1;
537
632
  const requireVerifiedSchema = data.readUInt8(offset) === 1;
538
633
  offset += 1;
634
+ const oracleFeeBps = readU16Le(data, offset);
635
+ offset += 2;
539
636
  const allowDelegateClaim = data.readUInt8(offset) === 1;
540
637
  offset += 1;
541
638
  const bump = data.readUInt8(offset);
@@ -545,6 +642,7 @@ function decodePoolOraclePolicyAccount(address, data) {
545
642
  quorumM,
546
643
  quorumN,
547
644
  requireVerifiedSchema,
645
+ oracleFeeBps,
548
646
  allowDelegateClaim,
549
647
  bump,
550
648
  };
@@ -605,6 +703,190 @@ function decodePoolAssetVaultAccount(address, data) {
605
703
  bump,
606
704
  };
607
705
  }
706
+ function decodeProtocolFeeVaultAccount(address, data) {
707
+ if (!hasDiscriminator(data, ACCOUNT_PROTOCOL_FEE_VAULT)) {
708
+ throw new Error('account discriminator mismatch for ProtocolFeeVault');
709
+ }
710
+ let offset = 8;
711
+ const paymentMint = pubkeyFromData(data, offset);
712
+ offset += 32;
713
+ const bump = data.readUInt8(offset);
714
+ return {
715
+ address,
716
+ paymentMint,
717
+ bump,
718
+ };
719
+ }
720
+ function decodePoolOracleFeeVaultAccount(address, data) {
721
+ if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_FEE_VAULT)) {
722
+ throw new Error('account discriminator mismatch for PoolOracleFeeVault');
723
+ }
724
+ let offset = 8;
725
+ const pool = pubkeyFromData(data, offset);
726
+ offset += 32;
727
+ const oracle = pubkeyFromData(data, offset);
728
+ offset += 32;
729
+ const paymentMint = pubkeyFromData(data, offset);
730
+ offset += 32;
731
+ const bump = data.readUInt8(offset);
732
+ return {
733
+ address,
734
+ pool,
735
+ oracle,
736
+ paymentMint,
737
+ bump,
738
+ };
739
+ }
740
+ function decodePoolOraclePermissionSetAccount(address, data) {
741
+ if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_PERMISSION_SET)) {
742
+ throw new Error('account discriminator mismatch for PoolOraclePermissionSet');
743
+ }
744
+ let offset = 8;
745
+ const pool = pubkeyFromData(data, offset);
746
+ offset += 32;
747
+ const oracle = pubkeyFromData(data, offset);
748
+ offset += 32;
749
+ const permissions = data.readUInt32LE(offset);
750
+ offset += 4;
751
+ const bump = data.readUInt8(offset);
752
+ return {
753
+ address,
754
+ pool,
755
+ oracle,
756
+ permissions,
757
+ bump,
758
+ };
759
+ }
760
+ function decodeMemberCycleAccount(address, data) {
761
+ if (!hasDiscriminator(data, ACCOUNT_MEMBER_CYCLE)) {
762
+ throw new Error('account discriminator mismatch for MemberCycleState');
763
+ }
764
+ let offset = 8;
765
+ const pool = pubkeyFromData(data, offset);
766
+ offset += 32;
767
+ const member = pubkeyFromData(data, offset);
768
+ offset += 32;
769
+ const productIdHashHex = toHex(data.subarray(offset, offset + 32));
770
+ offset += 32;
771
+ const periodIndex = readU64Le(data, offset);
772
+ offset += 8;
773
+ const paymentMint = pubkeyFromData(data, offset);
774
+ offset += 32;
775
+ const premiumAmountRaw = readU64Le(data, offset);
776
+ offset += 8;
777
+ const bondAmountRaw = readU64Le(data, offset);
778
+ offset += 8;
779
+ const shieldFeeRaw = readU64Le(data, offset);
780
+ offset += 8;
781
+ const protocolFeeRaw = readU64Le(data, offset);
782
+ offset += 8;
783
+ const oracleFeeRaw = readU64Le(data, offset);
784
+ offset += 8;
785
+ const netPoolPremiumRaw = readU64Le(data, offset);
786
+ offset += 8;
787
+ const totalAmountRaw = readU64Le(data, offset);
788
+ offset += 8;
789
+ const canonicalPremiumAmount = readU64Le(data, offset);
790
+ offset += 8;
791
+ const commitmentEnabled = data.readUInt8(offset) === 1;
792
+ offset += 1;
793
+ const thresholdBps = readU16Le(data, offset);
794
+ offset += 2;
795
+ const includedShieldCount = data.readUInt8(offset);
796
+ offset += 1;
797
+ const shieldConsumed = data.readUInt8(offset) === 1;
798
+ offset += 1;
799
+ const statusCode = data.readUInt8(offset);
800
+ offset += 1;
801
+ const passed = data.readUInt8(offset) === 1;
802
+ offset += 1;
803
+ const activatedAt = Number(readI64Le(data, offset));
804
+ offset += 8;
805
+ const settledAt = Number(readI64Le(data, offset));
806
+ offset += 8;
807
+ const quoteHashHex = toHex(data.subarray(offset, offset + 32));
808
+ offset += 32;
809
+ const bump = data.readUInt8(offset);
810
+ return {
811
+ address,
812
+ pool,
813
+ member,
814
+ productIdHashHex,
815
+ periodIndex,
816
+ paymentMint,
817
+ premiumAmountRaw,
818
+ bondAmountRaw,
819
+ shieldFeeRaw,
820
+ protocolFeeRaw,
821
+ oracleFeeRaw,
822
+ netPoolPremiumRaw,
823
+ totalAmountRaw,
824
+ canonicalPremiumAmount,
825
+ commitmentEnabled,
826
+ thresholdBps,
827
+ includedShieldCount,
828
+ shieldConsumed,
829
+ statusCode,
830
+ status: parseMemberCycleStatus(statusCode),
831
+ passed,
832
+ activatedAt,
833
+ settledAt,
834
+ quoteHashHex,
835
+ bump,
836
+ };
837
+ }
838
+ function decodeCycleQuoteReplayAccount(address, data) {
839
+ if (!hasDiscriminator(data, ACCOUNT_CYCLE_QUOTE_REPLAY)) {
840
+ throw new Error('account discriminator mismatch for CycleQuoteReplay');
841
+ }
842
+ let offset = 8;
843
+ const pool = pubkeyFromData(data, offset);
844
+ offset += 32;
845
+ const member = pubkeyFromData(data, offset);
846
+ offset += 32;
847
+ const nonceHashHex = toHex(data.subarray(offset, offset + 32));
848
+ offset += 32;
849
+ const quoteHashHex = toHex(data.subarray(offset, offset + 32));
850
+ offset += 32;
851
+ const createdAt = Number(readI64Le(data, offset));
852
+ offset += 8;
853
+ const bump = data.readUInt8(offset);
854
+ return {
855
+ address,
856
+ pool,
857
+ member,
858
+ nonceHashHex,
859
+ quoteHashHex,
860
+ createdAt,
861
+ bump,
862
+ };
863
+ }
864
+ function decodePoolTreasuryReserveAccount(address, data) {
865
+ if (!hasDiscriminator(data, ACCOUNT_POOL_TREASURY_RESERVE)) {
866
+ throw new Error('account discriminator mismatch for PoolTreasuryReserve');
867
+ }
868
+ let offset = 8;
869
+ const pool = pubkeyFromData(data, offset);
870
+ offset += 32;
871
+ const paymentMint = pubkeyFromData(data, offset);
872
+ offset += 32;
873
+ const reservedRefundAmount = readU64Le(data, offset);
874
+ offset += 8;
875
+ const reservedRewardAmount = readU64Le(data, offset);
876
+ offset += 8;
877
+ const manualCoverageReserveAmount = readU64Le(data, offset);
878
+ offset += 8;
879
+ const bump = data.readUInt8(offset);
880
+ return {
881
+ address,
882
+ pool,
883
+ paymentMint,
884
+ reservedRefundAmount,
885
+ reservedRewardAmount,
886
+ manualCoverageReserveAmount,
887
+ bump,
888
+ };
889
+ }
608
890
  function decodeOutcomeSchemaAccount(address, data) {
609
891
  if (!hasDiscriminator(data, ACCOUNT_OUTCOME_SCHEMA)) {
610
892
  throw new Error('account discriminator mismatch for OutcomeSchemaRegistryEntry');
@@ -949,6 +1231,32 @@ function decodeCoverageProductAccount(address, data) {
949
1231
  bump,
950
1232
  };
951
1233
  }
1234
+ function decodeCoverageProductPaymentOptionAccount(address, data) {
1235
+ if (!hasDiscriminator(data, ACCOUNT_COVERAGE_PRODUCT_PAYMENT_OPTION)) {
1236
+ throw new Error('account discriminator mismatch for CoverageProductPaymentOption');
1237
+ }
1238
+ let offset = 8;
1239
+ const pool = pubkeyFromData(data, offset);
1240
+ offset += 32;
1241
+ const productIdHash = data.subarray(offset, offset + 32);
1242
+ offset += 32;
1243
+ const paymentMint = pubkeyFromData(data, offset);
1244
+ offset += 32;
1245
+ const paymentAmount = readU64Le(data, offset);
1246
+ offset += 8;
1247
+ const active = data.readUInt8(offset) === 1;
1248
+ offset += 1;
1249
+ const bump = data.readUInt8(offset);
1250
+ return {
1251
+ address,
1252
+ pool,
1253
+ productIdHashHex: toHex(productIdHash),
1254
+ paymentMint,
1255
+ paymentAmount,
1256
+ active,
1257
+ bump,
1258
+ };
1259
+ }
952
1260
  function decodeCoveragePolicyPositionNftAccount(address, data) {
953
1261
  if (!hasDiscriminator(data, ACCOUNT_COVERAGE_POLICY_POSITION_NFT)) {
954
1262
  throw new Error('account discriminator mismatch for CoveragePolicyPositionNft');
@@ -1288,9 +1596,35 @@ function encodeSetPoolOraclePolicyData(params) {
1288
1596
  Buffer.from([params.quorumM & 0xff]),
1289
1597
  Buffer.from([params.quorumN & 0xff]),
1290
1598
  Buffer.from([params.requireVerifiedSchema ? 1 : 0]),
1599
+ encodeU16Le(params.oracleFeeBps),
1291
1600
  Buffer.from([params.allowDelegateClaim ? 1 : 0]),
1292
1601
  ]);
1293
1602
  }
1603
+ function encodeSetPoolOraclePermissionsData(params) {
1604
+ const permissions = params.permissions >>> 0;
1605
+ const out = Buffer.alloc(4);
1606
+ out.writeUInt32LE(permissions, 0);
1607
+ return Buffer.concat([IX_SET_POOL_ORACLE_PERMISSIONS, out]);
1608
+ }
1609
+ function encodeSetPoolCoverageReserveFloorData(params) {
1610
+ return Buffer.concat([
1611
+ IX_SET_POOL_COVERAGE_RESERVE_FLOOR,
1612
+ asPubkey(params.paymentMint).toBuffer(),
1613
+ encodeU64Le(params.amount),
1614
+ ]);
1615
+ }
1616
+ function encodeWithdrawProtocolFeeSplData(params) {
1617
+ return Buffer.concat([IX_WITHDRAW_PROTOCOL_FEE_SPL, encodeU64Le(params.amount)]);
1618
+ }
1619
+ function encodeWithdrawProtocolFeeSolData(params) {
1620
+ return Buffer.concat([IX_WITHDRAW_PROTOCOL_FEE_SOL, encodeU64Le(params.amount)]);
1621
+ }
1622
+ function encodeWithdrawPoolOracleFeeSplData(params) {
1623
+ return Buffer.concat([IX_WITHDRAW_POOL_ORACLE_FEE_SPL, encodeU64Le(params.amount)]);
1624
+ }
1625
+ function encodeWithdrawPoolOracleFeeSolData(params) {
1626
+ return Buffer.concat([IX_WITHDRAW_POOL_ORACLE_FEE_SOL, encodeU64Le(params.amount)]);
1627
+ }
1294
1628
  function encodeSetPoolTermsHashData(params) {
1295
1629
  return Buffer.concat([
1296
1630
  IX_SET_POOL_TERMS_HASH,
@@ -1392,6 +1726,14 @@ function encodeRegisterCoverageProductV2Data(params) {
1392
1726
  Buffer.from([params.active ? 1 : 0]),
1393
1727
  ]);
1394
1728
  }
1729
+ function encodeUpsertCoverageProductPaymentOptionData(params) {
1730
+ return Buffer.concat([
1731
+ IX_UPSERT_COVERAGE_PRODUCT_PAYMENT_OPTION,
1732
+ asPubkey(params.paymentMint).toBuffer(),
1733
+ encodeU64Le(params.paymentAmount),
1734
+ Buffer.from([params.active ? 1 : 0]),
1735
+ ]);
1736
+ }
1395
1737
  function encodeUpdateCoverageProductV2Data(params) {
1396
1738
  return Buffer.concat([
1397
1739
  IX_UPDATE_COVERAGE_PRODUCT_V2,
@@ -1480,6 +1822,631 @@ function encodeMigratePoolV1ToV2Data(params) {
1480
1822
  encodeString(params.metadataUri),
1481
1823
  ]);
1482
1824
  }
1825
+ function buildActivateCycleWithQuoteSolTransaction(params) {
1826
+ const programId = asPubkey(params.programId);
1827
+ const payer = asPubkey(params.payer);
1828
+ const member = asPubkey(params.member);
1829
+ const poolAddress = asPubkey(params.poolAddress);
1830
+ const oracle = asPubkey(params.oracle);
1831
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
1832
+ const [configV2] = deriveConfigV2Pda(programId);
1833
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
1834
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
1835
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
1836
+ programId,
1837
+ poolAddress,
1838
+ oracle,
1839
+ });
1840
+ const [oraclePolicy] = derivePoolOraclePolicyPda({
1841
+ programId,
1842
+ poolAddress,
1843
+ });
1844
+ const [membership] = deriveMembershipPda({ programId, poolAddress, member });
1845
+ const [coverageProduct] = deriveCoverageProductPda({
1846
+ programId,
1847
+ poolAddress,
1848
+ productIdHash: fromHex(params.productIdHashHex, 32),
1849
+ });
1850
+ const [coverageProductPaymentOption] = deriveCoverageProductPaymentOptionPda({
1851
+ programId,
1852
+ poolAddress,
1853
+ productIdHash: fromHex(params.productIdHashHex, 32),
1854
+ paymentMint: zeroPubkey,
1855
+ });
1856
+ const [coveragePolicy] = deriveCoveragePolicyPda({ programId, poolAddress, member });
1857
+ const [coveragePolicyNft] = deriveCoverageNftPda({ programId, poolAddress, member });
1858
+ const [premiumLedger] = derivePremiumLedgerPda({ programId, poolAddress, member });
1859
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
1860
+ programId,
1861
+ paymentMint: zeroPubkey,
1862
+ });
1863
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
1864
+ programId,
1865
+ poolAddress,
1866
+ oracle,
1867
+ paymentMint: zeroPubkey,
1868
+ });
1869
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
1870
+ programId,
1871
+ poolAddress,
1872
+ paymentMint: zeroPubkey,
1873
+ });
1874
+ const [memberCycle] = deriveMemberCyclePda({
1875
+ programId,
1876
+ poolAddress,
1877
+ member,
1878
+ periodIndex: params.periodIndex,
1879
+ });
1880
+ const [cycleQuoteReplay] = deriveCycleQuoteReplayPda({
1881
+ programId,
1882
+ poolAddress,
1883
+ member,
1884
+ nonceHash: fromHex(params.nonceHashHex, 32),
1885
+ });
1886
+ const ed25519Instruction = Ed25519Program.createInstructionWithPrivateKey({
1887
+ privateKey: params.oracleSecretKey,
1888
+ message: buildCycleQuoteSignatureMessage(params.quoteMessage),
1889
+ });
1890
+ const instruction = new TransactionInstruction({
1891
+ programId,
1892
+ keys: [
1893
+ { pubkey: payer, isSigner: true, isWritable: true },
1894
+ { pubkey: configV2, isSigner: false, isWritable: false },
1895
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
1896
+ { pubkey: member, isSigner: false, isWritable: false },
1897
+ { pubkey: oracle, isSigner: false, isWritable: false },
1898
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
1899
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
1900
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
1901
+ { pubkey: oraclePolicy, isSigner: false, isWritable: false },
1902
+ { pubkey: membership, isSigner: false, isWritable: true },
1903
+ { pubkey: coverageProduct, isSigner: false, isWritable: false },
1904
+ { pubkey: coverageProductPaymentOption, isSigner: false, isWritable: false },
1905
+ { pubkey: coveragePolicy, isSigner: false, isWritable: true },
1906
+ { pubkey: coveragePolicyNft, isSigner: false, isWritable: true },
1907
+ { pubkey: premiumLedger, isSigner: false, isWritable: true },
1908
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
1909
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
1910
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
1911
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
1912
+ { pubkey: cycleQuoteReplay, isSigner: false, isWritable: true },
1913
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
1914
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
1915
+ ],
1916
+ data: Buffer.concat([
1917
+ IX_ACTIVATE_CYCLE_WITH_QUOTE_SOL,
1918
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
1919
+ encodeU64Le(params.periodIndex),
1920
+ Buffer.from(fromHex(params.nonceHashHex, 32)),
1921
+ encodeU64Le(params.premiumAmountRaw),
1922
+ encodeU64Le(params.canonicalPremiumAmount),
1923
+ Buffer.from([params.commitmentEnabled ? 1 : 0]),
1924
+ encodeU64Le(params.bondAmountRaw),
1925
+ encodeU64Le(params.shieldFeeRaw),
1926
+ encodeU64Le(params.protocolFeeRaw),
1927
+ encodeU64Le(params.oracleFeeRaw),
1928
+ encodeU64Le(params.netPoolPremiumRaw),
1929
+ encodeU64Le(params.totalAmountRaw),
1930
+ Buffer.from([params.includedShieldCount]),
1931
+ encodeU16Le(params.thresholdBps),
1932
+ encodeI64Le(params.expiresAtTs),
1933
+ Buffer.from(fromHex(params.quoteMetaHashHex, 32)),
1934
+ ]),
1935
+ });
1936
+ const transaction = new Transaction({
1937
+ feePayer: payer,
1938
+ recentBlockhash: params.recentBlockhash,
1939
+ });
1940
+ if (typeof params.computeUnitLimit === 'number') {
1941
+ transaction.add(ComputeBudgetProgram.setComputeUnitLimit({
1942
+ units: params.computeUnitLimit,
1943
+ }));
1944
+ }
1945
+ return transaction.add(ed25519Instruction, instruction);
1946
+ }
1947
+ function buildActivateCycleWithQuoteSplTransaction(params) {
1948
+ const programId = asPubkey(params.programId);
1949
+ const payer = asPubkey(params.payer);
1950
+ const member = asPubkey(params.member);
1951
+ const poolAddress = asPubkey(params.poolAddress);
1952
+ const oracle = asPubkey(params.oracle);
1953
+ const paymentMint = asPubkey(params.paymentMint);
1954
+ const [configV2] = deriveConfigV2Pda(programId);
1955
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
1956
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
1957
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
1958
+ programId,
1959
+ poolAddress,
1960
+ oracle,
1961
+ });
1962
+ const [oraclePolicy] = derivePoolOraclePolicyPda({
1963
+ programId,
1964
+ poolAddress,
1965
+ });
1966
+ const [membership] = deriveMembershipPda({ programId, poolAddress, member });
1967
+ const [coverageProduct] = deriveCoverageProductPda({
1968
+ programId,
1969
+ poolAddress,
1970
+ productIdHash: fromHex(params.productIdHashHex, 32),
1971
+ });
1972
+ const [coverageProductPaymentOption] = deriveCoverageProductPaymentOptionPda({
1973
+ programId,
1974
+ poolAddress,
1975
+ productIdHash: fromHex(params.productIdHashHex, 32),
1976
+ paymentMint,
1977
+ });
1978
+ const [coveragePolicy] = deriveCoveragePolicyPda({ programId, poolAddress, member });
1979
+ const [coveragePolicyNft] = deriveCoverageNftPda({ programId, poolAddress, member });
1980
+ const [premiumLedger] = derivePremiumLedgerPda({ programId, poolAddress, member });
1981
+ const [poolAssetVault] = derivePoolAssetVaultPda({
1982
+ programId,
1983
+ poolAddress,
1984
+ payoutMint: paymentMint,
1985
+ });
1986
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
1987
+ owner: poolAssetVault,
1988
+ mint: paymentMint,
1989
+ });
1990
+ const payerTokenAccount = deriveAssociatedTokenAddress({
1991
+ owner: payer,
1992
+ mint: paymentMint,
1993
+ });
1994
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
1995
+ programId,
1996
+ paymentMint,
1997
+ });
1998
+ const protocolFeeVaultTokenAccount = deriveAssociatedTokenAddress({
1999
+ owner: protocolFeeVault,
2000
+ mint: paymentMint,
2001
+ allowOwnerOffCurve: true,
2002
+ });
2003
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
2004
+ programId,
2005
+ poolAddress,
2006
+ oracle,
2007
+ paymentMint,
2008
+ });
2009
+ const poolOracleFeeVaultTokenAccount = deriveAssociatedTokenAddress({
2010
+ owner: poolOracleFeeVault,
2011
+ mint: paymentMint,
2012
+ allowOwnerOffCurve: true,
2013
+ });
2014
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2015
+ programId,
2016
+ poolAddress,
2017
+ paymentMint,
2018
+ });
2019
+ const [memberCycle] = deriveMemberCyclePda({
2020
+ programId,
2021
+ poolAddress,
2022
+ member,
2023
+ periodIndex: params.periodIndex,
2024
+ });
2025
+ const [cycleQuoteReplay] = deriveCycleQuoteReplayPda({
2026
+ programId,
2027
+ poolAddress,
2028
+ member,
2029
+ nonceHash: fromHex(params.nonceHashHex, 32),
2030
+ });
2031
+ const ed25519Instruction = Ed25519Program.createInstructionWithPrivateKey({
2032
+ privateKey: params.oracleSecretKey,
2033
+ message: buildCycleQuoteSignatureMessage(params.quoteMessage),
2034
+ });
2035
+ const instruction = new TransactionInstruction({
2036
+ programId,
2037
+ keys: [
2038
+ { pubkey: payer, isSigner: true, isWritable: true },
2039
+ { pubkey: configV2, isSigner: false, isWritable: false },
2040
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2041
+ { pubkey: member, isSigner: false, isWritable: false },
2042
+ { pubkey: oracle, isSigner: false, isWritable: false },
2043
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2044
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2045
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2046
+ { pubkey: oraclePolicy, isSigner: false, isWritable: false },
2047
+ { pubkey: membership, isSigner: false, isWritable: true },
2048
+ { pubkey: coverageProduct, isSigner: false, isWritable: false },
2049
+ { pubkey: coverageProductPaymentOption, isSigner: false, isWritable: false },
2050
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2051
+ { pubkey: coveragePolicy, isSigner: false, isWritable: true },
2052
+ { pubkey: coveragePolicyNft, isSigner: false, isWritable: true },
2053
+ { pubkey: premiumLedger, isSigner: false, isWritable: true },
2054
+ { pubkey: poolAssetVault, isSigner: false, isWritable: true },
2055
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
2056
+ { pubkey: payerTokenAccount, isSigner: false, isWritable: true },
2057
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
2058
+ { pubkey: protocolFeeVaultTokenAccount, isSigner: false, isWritable: true },
2059
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
2060
+ { pubkey: poolOracleFeeVaultTokenAccount, isSigner: false, isWritable: true },
2061
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2062
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
2063
+ { pubkey: cycleQuoteReplay, isSigner: false, isWritable: true },
2064
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2065
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2066
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
2067
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
2068
+ ],
2069
+ data: Buffer.concat([
2070
+ IX_ACTIVATE_CYCLE_WITH_QUOTE_SPL,
2071
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2072
+ encodeU64Le(params.periodIndex),
2073
+ Buffer.from(fromHex(params.nonceHashHex, 32)),
2074
+ encodeU64Le(params.premiumAmountRaw),
2075
+ encodeU64Le(params.canonicalPremiumAmount),
2076
+ Buffer.from([params.commitmentEnabled ? 1 : 0]),
2077
+ encodeU64Le(params.bondAmountRaw),
2078
+ encodeU64Le(params.shieldFeeRaw),
2079
+ encodeU64Le(params.protocolFeeRaw),
2080
+ encodeU64Le(params.oracleFeeRaw),
2081
+ encodeU64Le(params.netPoolPremiumRaw),
2082
+ encodeU64Le(params.totalAmountRaw),
2083
+ Buffer.from([params.includedShieldCount]),
2084
+ encodeU16Le(params.thresholdBps),
2085
+ encodeI64Le(params.expiresAtTs),
2086
+ Buffer.from(fromHex(params.quoteMetaHashHex, 32)),
2087
+ ]),
2088
+ });
2089
+ return new Transaction({
2090
+ feePayer: payer,
2091
+ recentBlockhash: params.recentBlockhash,
2092
+ }).add(ComputeBudgetProgram.setComputeUnitLimit({
2093
+ units: params.computeUnitLimit ?? 400_000,
2094
+ }), ed25519Instruction, instruction);
2095
+ }
2096
+ function buildSettleCycleCommitmentTransaction(params) {
2097
+ const programId = asPubkey(params.programId);
2098
+ const payer = asPubkey(params.payer);
2099
+ const oracle = asPubkey(params.oracle);
2100
+ const member = asPubkey(params.member);
2101
+ const poolAddress = asPubkey(params.poolAddress);
2102
+ const paymentMint = asPubkey(params.paymentMint);
2103
+ const [configV2] = deriveConfigV2Pda(programId);
2104
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2105
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2106
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2107
+ programId,
2108
+ poolAddress,
2109
+ oracle,
2110
+ });
2111
+ const [poolAssetVault] = derivePoolAssetVaultPda({
2112
+ programId,
2113
+ poolAddress,
2114
+ payoutMint: paymentMint,
2115
+ });
2116
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
2117
+ owner: poolAssetVault,
2118
+ mint: paymentMint,
2119
+ });
2120
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2121
+ programId,
2122
+ poolAddress,
2123
+ paymentMint,
2124
+ });
2125
+ const [memberCycle] = deriveMemberCyclePda({
2126
+ programId,
2127
+ poolAddress,
2128
+ member,
2129
+ periodIndex: params.periodIndex,
2130
+ });
2131
+ const recipientTokenAccount = deriveAssociatedTokenAddress({
2132
+ owner: member,
2133
+ mint: paymentMint,
2134
+ });
2135
+ const instruction = new TransactionInstruction({
2136
+ programId,
2137
+ keys: [
2138
+ { pubkey: oracle, isSigner: true, isWritable: true },
2139
+ { pubkey: configV2, isSigner: false, isWritable: false },
2140
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2141
+ { pubkey: member, isSigner: false, isWritable: false },
2142
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2143
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2144
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2145
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2146
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2147
+ { pubkey: poolAssetVault, isSigner: false, isWritable: false },
2148
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
2149
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2150
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
2151
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2152
+ ],
2153
+ data: Buffer.concat([
2154
+ IX_SETTLE_CYCLE_COMMITMENT,
2155
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2156
+ encodeU64Le(params.periodIndex),
2157
+ Buffer.from([params.passed ? 1 : 0]),
2158
+ Buffer.from([params.shieldConsumed ? 1 : 0]),
2159
+ ]),
2160
+ });
2161
+ return new Transaction({
2162
+ feePayer: payer,
2163
+ recentBlockhash: params.recentBlockhash,
2164
+ }).add(instruction);
2165
+ }
2166
+ function buildSettleCycleCommitmentSolTransaction(params) {
2167
+ const programId = asPubkey(params.programId);
2168
+ const payer = asPubkey(params.payer);
2169
+ const oracle = asPubkey(params.oracle);
2170
+ const member = asPubkey(params.member);
2171
+ const poolAddress = asPubkey(params.poolAddress);
2172
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2173
+ const [configV2] = deriveConfigV2Pda(programId);
2174
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2175
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2176
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2177
+ programId,
2178
+ poolAddress,
2179
+ oracle,
2180
+ });
2181
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2182
+ programId,
2183
+ poolAddress,
2184
+ paymentMint: zeroPubkey,
2185
+ });
2186
+ const [memberCycle] = deriveMemberCyclePda({
2187
+ programId,
2188
+ poolAddress,
2189
+ member,
2190
+ periodIndex: params.periodIndex,
2191
+ });
2192
+ const instruction = new TransactionInstruction({
2193
+ programId,
2194
+ keys: [
2195
+ { pubkey: oracle, isSigner: true, isWritable: true },
2196
+ { pubkey: configV2, isSigner: false, isWritable: false },
2197
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
2198
+ { pubkey: member, isSigner: false, isWritable: false },
2199
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2200
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2201
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2202
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2203
+ { pubkey: member, isSigner: false, isWritable: true },
2204
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
2205
+ ],
2206
+ data: Buffer.concat([
2207
+ IX_SETTLE_CYCLE_COMMITMENT_SOL,
2208
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2209
+ encodeU64Le(params.periodIndex),
2210
+ Buffer.from([params.passed ? 1 : 0]),
2211
+ Buffer.from([params.shieldConsumed ? 1 : 0]),
2212
+ ]),
2213
+ });
2214
+ return new Transaction({
2215
+ feePayer: payer,
2216
+ recentBlockhash: params.recentBlockhash,
2217
+ }).add(instruction);
2218
+ }
2219
+ function buildWithdrawPoolTreasurySplTransaction(params) {
2220
+ const programId = asPubkey(params.programId);
2221
+ const payer = asPubkey(params.payer);
2222
+ const oracle = asPubkey(params.oracle);
2223
+ const poolAddress = asPubkey(params.poolAddress);
2224
+ const paymentMint = asPubkey(params.paymentMint);
2225
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2226
+ const [configV2] = deriveConfigV2Pda(programId);
2227
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2228
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2229
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2230
+ programId,
2231
+ poolAddress,
2232
+ oracle,
2233
+ });
2234
+ const [poolAssetVault] = derivePoolAssetVaultPda({
2235
+ programId,
2236
+ poolAddress,
2237
+ payoutMint: paymentMint,
2238
+ });
2239
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
2240
+ owner: poolAssetVault,
2241
+ mint: paymentMint,
2242
+ });
2243
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2244
+ programId,
2245
+ poolAddress,
2246
+ paymentMint,
2247
+ });
2248
+ const instruction = new TransactionInstruction({
2249
+ programId,
2250
+ keys: [
2251
+ { pubkey: oracle, isSigner: true, isWritable: true },
2252
+ { pubkey: configV2, isSigner: false, isWritable: false },
2253
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2254
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2255
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2256
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2257
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2258
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2259
+ { pubkey: poolAssetVault, isSigner: false, isWritable: false },
2260
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
2261
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2262
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2263
+ ],
2264
+ data: Buffer.concat([IX_WITHDRAW_POOL_TREASURY_SPL, encodeU64Le(params.amount)]),
2265
+ });
2266
+ return new Transaction({
2267
+ feePayer: payer,
2268
+ recentBlockhash: params.recentBlockhash,
2269
+ }).add(instruction);
2270
+ }
2271
+ function buildWithdrawPoolTreasurySolTransaction(params) {
2272
+ const programId = asPubkey(params.programId);
2273
+ const payer = asPubkey(params.payer);
2274
+ const oracle = asPubkey(params.oracle);
2275
+ const poolAddress = asPubkey(params.poolAddress);
2276
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2277
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2278
+ const [configV2] = deriveConfigV2Pda(programId);
2279
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2280
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2281
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2282
+ programId,
2283
+ poolAddress,
2284
+ oracle,
2285
+ });
2286
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2287
+ programId,
2288
+ poolAddress,
2289
+ paymentMint: zeroPubkey,
2290
+ });
2291
+ const instruction = new TransactionInstruction({
2292
+ programId,
2293
+ keys: [
2294
+ { pubkey: oracle, isSigner: true, isWritable: true },
2295
+ { pubkey: configV2, isSigner: false, isWritable: false },
2296
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
2297
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2298
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2299
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2300
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2301
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2302
+ ],
2303
+ data: Buffer.concat([IX_WITHDRAW_POOL_TREASURY_SOL, encodeU64Le(params.amount)]),
2304
+ });
2305
+ return new Transaction({
2306
+ feePayer: payer,
2307
+ recentBlockhash: params.recentBlockhash,
2308
+ }).add(instruction);
2309
+ }
2310
+ function buildWithdrawProtocolFeeSplTransaction(params) {
2311
+ const programId = asPubkey(params.programId);
2312
+ const governanceAuthority = asPubkey(params.governanceAuthority);
2313
+ const paymentMint = asPubkey(params.paymentMint);
2314
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2315
+ const [configV2] = deriveConfigV2Pda(programId);
2316
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
2317
+ programId,
2318
+ paymentMint,
2319
+ });
2320
+ const protocolFeeVaultTokenAccount = deriveAssociatedTokenAddress({
2321
+ owner: protocolFeeVault,
2322
+ mint: paymentMint,
2323
+ allowOwnerOffCurve: true,
2324
+ });
2325
+ const instruction = new TransactionInstruction({
2326
+ programId,
2327
+ keys: [
2328
+ { pubkey: governanceAuthority, isSigner: true, isWritable: true },
2329
+ { pubkey: configV2, isSigner: false, isWritable: false },
2330
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2331
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
2332
+ { pubkey: protocolFeeVaultTokenAccount, isSigner: false, isWritable: true },
2333
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2334
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2335
+ ],
2336
+ data: encodeWithdrawProtocolFeeSplData(params),
2337
+ });
2338
+ return new Transaction({
2339
+ feePayer: governanceAuthority,
2340
+ recentBlockhash: params.recentBlockhash,
2341
+ }).add(instruction);
2342
+ }
2343
+ function buildWithdrawProtocolFeeSolTransaction(params) {
2344
+ const programId = asPubkey(params.programId);
2345
+ const governanceAuthority = asPubkey(params.governanceAuthority);
2346
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2347
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2348
+ const [configV2] = deriveConfigV2Pda(programId);
2349
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
2350
+ programId,
2351
+ paymentMint: zeroPubkey,
2352
+ });
2353
+ const instruction = new TransactionInstruction({
2354
+ programId,
2355
+ keys: [
2356
+ { pubkey: governanceAuthority, isSigner: true, isWritable: true },
2357
+ { pubkey: configV2, isSigner: false, isWritable: false },
2358
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
2359
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2360
+ ],
2361
+ data: encodeWithdrawProtocolFeeSolData(params),
2362
+ });
2363
+ return new Transaction({
2364
+ feePayer: governanceAuthority,
2365
+ recentBlockhash: params.recentBlockhash,
2366
+ }).add(instruction);
2367
+ }
2368
+ function buildWithdrawPoolOracleFeeSplTransaction(params) {
2369
+ const programId = asPubkey(params.programId);
2370
+ const oracle = asPubkey(params.oracle);
2371
+ const poolAddress = asPubkey(params.poolAddress);
2372
+ const paymentMint = asPubkey(params.paymentMint);
2373
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2374
+ const [configV2] = deriveConfigV2Pda(programId);
2375
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2376
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2377
+ programId,
2378
+ poolAddress,
2379
+ oracle,
2380
+ });
2381
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
2382
+ programId,
2383
+ poolAddress,
2384
+ oracle,
2385
+ paymentMint,
2386
+ });
2387
+ const poolOracleFeeVaultTokenAccount = deriveAssociatedTokenAddress({
2388
+ owner: poolOracleFeeVault,
2389
+ mint: paymentMint,
2390
+ allowOwnerOffCurve: true,
2391
+ });
2392
+ const instruction = new TransactionInstruction({
2393
+ programId,
2394
+ keys: [
2395
+ { pubkey: oracle, isSigner: true, isWritable: true },
2396
+ { pubkey: configV2, isSigner: false, isWritable: false },
2397
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2398
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2399
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2400
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2401
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
2402
+ { pubkey: poolOracleFeeVaultTokenAccount, isSigner: false, isWritable: true },
2403
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2404
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2405
+ ],
2406
+ data: encodeWithdrawPoolOracleFeeSplData(params),
2407
+ });
2408
+ return new Transaction({
2409
+ feePayer: oracle,
2410
+ recentBlockhash: params.recentBlockhash,
2411
+ }).add(instruction);
2412
+ }
2413
+ function buildWithdrawPoolOracleFeeSolTransaction(params) {
2414
+ const programId = asPubkey(params.programId);
2415
+ const oracle = asPubkey(params.oracle);
2416
+ const poolAddress = asPubkey(params.poolAddress);
2417
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2418
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2419
+ const [configV2] = deriveConfigV2Pda(programId);
2420
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2421
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2422
+ programId,
2423
+ poolAddress,
2424
+ oracle,
2425
+ });
2426
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
2427
+ programId,
2428
+ poolAddress,
2429
+ oracle,
2430
+ paymentMint: zeroPubkey,
2431
+ });
2432
+ const instruction = new TransactionInstruction({
2433
+ programId,
2434
+ keys: [
2435
+ { pubkey: oracle, isSigner: true, isWritable: true },
2436
+ { pubkey: configV2, isSigner: false, isWritable: false },
2437
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2438
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2439
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2440
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
2441
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2442
+ ],
2443
+ data: encodeWithdrawPoolOracleFeeSolData(params),
2444
+ });
2445
+ return new Transaction({
2446
+ feePayer: oracle,
2447
+ recentBlockhash: params.recentBlockhash,
2448
+ }).add(instruction);
2449
+ }
1483
2450
  export function createProtocolClient(connection, programIdInput) {
1484
2451
  const programId = new PublicKey(programIdInput);
1485
2452
  return {
@@ -1806,6 +2773,7 @@ export function createProtocolClient(connection, programIdInput) {
1806
2773
  const oracle = new PublicKey(params.oracle);
1807
2774
  const poolAddress = new PublicKey(params.poolAddress);
1808
2775
  const member = new PublicKey(params.member);
2776
+ const payoutMint = new PublicKey(params.payoutMint);
1809
2777
  const cycleHash = hashStringTo32(params.cycleId);
1810
2778
  const ruleHash = fromHex(params.ruleHashHex, 32);
1811
2779
  const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
@@ -1823,6 +2791,15 @@ export function createProtocolClient(connection, programIdInput) {
1823
2791
  programId,
1824
2792
  poolAddress,
1825
2793
  });
2794
+ const [poolTermsPda] = derivePoolTermsPda({
2795
+ programId,
2796
+ poolAddress,
2797
+ });
2798
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
2799
+ programId,
2800
+ poolAddress,
2801
+ paymentMint: payoutMint,
2802
+ });
1826
2803
  const [poolOraclePda] = derivePoolOraclePda({
1827
2804
  programId,
1828
2805
  poolAddress,
@@ -1865,7 +2842,9 @@ export function createProtocolClient(connection, programIdInput) {
1865
2842
  { pubkey: configV2Pda, isSigner: false, isWritable: false },
1866
2843
  { pubkey: stakePositionPda, isSigner: false, isWritable: false },
1867
2844
  { pubkey: poolAddress, isSigner: false, isWritable: false },
2845
+ { pubkey: poolTermsPda, isSigner: false, isWritable: false },
1868
2846
  { pubkey: poolOraclePolicyPda, isSigner: false, isWritable: false },
2847
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
1869
2848
  { pubkey: poolOraclePda, isSigner: false, isWritable: false },
1870
2849
  { pubkey: membershipPda, isSigner: false, isWritable: false },
1871
2850
  { pubkey: poolRulePda, isSigner: false, isWritable: false },
@@ -1885,8 +2864,18 @@ export function createProtocolClient(connection, programIdInput) {
1885
2864
  const payer = new PublicKey(params.payer);
1886
2865
  const poolAddress = new PublicKey(params.poolAddress);
1887
2866
  const member = new PublicKey(params.member);
2867
+ const payoutMint = new PublicKey(params.payoutMint);
1888
2868
  const cycleHash = hashStringTo32(params.cycleId);
1889
2869
  const ruleHash = fromHex(params.ruleHashHex, 32);
2870
+ const [poolTermsPda] = derivePoolTermsPda({
2871
+ programId,
2872
+ poolAddress,
2873
+ });
2874
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
2875
+ programId,
2876
+ poolAddress,
2877
+ paymentMint: payoutMint,
2878
+ });
1890
2879
  const [aggregatePda] = deriveOutcomeAggregatePda({
1891
2880
  programId,
1892
2881
  poolAddress,
@@ -1896,7 +2885,14 @@ export function createProtocolClient(connection, programIdInput) {
1896
2885
  });
1897
2886
  const instruction = new TransactionInstruction({
1898
2887
  programId,
1899
- keys: [{ pubkey: aggregatePda, isSigner: false, isWritable: true }],
2888
+ keys: [
2889
+ { pubkey: payer, isSigner: true, isWritable: true },
2890
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2891
+ { pubkey: poolTermsPda, isSigner: false, isWritable: false },
2892
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
2893
+ { pubkey: aggregatePda, isSigner: false, isWritable: true },
2894
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
2895
+ ],
1900
2896
  data: IX_FINALIZE_CYCLE_OUTCOME,
1901
2897
  });
1902
2898
  return new Transaction({
@@ -2182,6 +3178,7 @@ export function createProtocolClient(connection, programIdInput) {
2182
3178
  buildSetPoolOraclePolicyTx(params) {
2183
3179
  const authority = new PublicKey(params.authority);
2184
3180
  const poolAddress = new PublicKey(params.poolAddress);
3181
+ const [configV2Pda] = deriveConfigV2Pda(programId);
2185
3182
  const [oraclePolicyPda] = derivePoolOraclePolicyPda({
2186
3183
  programId,
2187
3184
  poolAddress,
@@ -2190,6 +3187,7 @@ export function createProtocolClient(connection, programIdInput) {
2190
3187
  programId,
2191
3188
  keys: [
2192
3189
  { pubkey: authority, isSigner: true, isWritable: false },
3190
+ { pubkey: configV2Pda, isSigner: false, isWritable: false },
2193
3191
  { pubkey: poolAddress, isSigner: false, isWritable: false },
2194
3192
  { pubkey: oraclePolicyPda, isSigner: false, isWritable: true },
2195
3193
  ],
@@ -2200,6 +3198,68 @@ export function createProtocolClient(connection, programIdInput) {
2200
3198
  recentBlockhash: params.recentBlockhash,
2201
3199
  }).add(instruction);
2202
3200
  },
3201
+ buildSetPoolOraclePermissionsTx(params) {
3202
+ const authority = new PublicKey(params.authority);
3203
+ const poolAddress = new PublicKey(params.poolAddress);
3204
+ const oracle = new PublicKey(params.oracle);
3205
+ const [oracleEntryPda] = deriveOraclePda({
3206
+ programId,
3207
+ oracle,
3208
+ });
3209
+ const [poolOraclePda] = derivePoolOraclePda({
3210
+ programId,
3211
+ poolAddress,
3212
+ oracle,
3213
+ });
3214
+ const [poolOraclePermissionsPda] = derivePoolOraclePermissionSetPda({
3215
+ programId,
3216
+ poolAddress,
3217
+ oracle,
3218
+ });
3219
+ const instruction = new TransactionInstruction({
3220
+ programId,
3221
+ keys: [
3222
+ { pubkey: authority, isSigner: true, isWritable: true },
3223
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
3224
+ { pubkey: oracle, isSigner: false, isWritable: false },
3225
+ { pubkey: oracleEntryPda, isSigner: false, isWritable: false },
3226
+ { pubkey: poolOraclePda, isSigner: false, isWritable: false },
3227
+ { pubkey: poolOraclePermissionsPda, isSigner: false, isWritable: true },
3228
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3229
+ ],
3230
+ data: encodeSetPoolOraclePermissionsData(params),
3231
+ });
3232
+ return new Transaction({
3233
+ feePayer: authority,
3234
+ recentBlockhash: params.recentBlockhash,
3235
+ }).add(instruction);
3236
+ },
3237
+ buildSetPoolCoverageReserveFloorTx(params) {
3238
+ const authority = new PublicKey(params.authority);
3239
+ const poolAddress = new PublicKey(params.poolAddress);
3240
+ const paymentMint = new PublicKey(params.paymentMint);
3241
+ const [configV2Pda] = deriveConfigV2Pda(programId);
3242
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
3243
+ programId,
3244
+ poolAddress,
3245
+ paymentMint,
3246
+ });
3247
+ const instruction = new TransactionInstruction({
3248
+ programId,
3249
+ keys: [
3250
+ { pubkey: authority, isSigner: true, isWritable: true },
3251
+ { pubkey: configV2Pda, isSigner: false, isWritable: false },
3252
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
3253
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
3254
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3255
+ ],
3256
+ data: encodeSetPoolCoverageReserveFloorData(params),
3257
+ });
3258
+ return new Transaction({
3259
+ feePayer: authority,
3260
+ recentBlockhash: params.recentBlockhash,
3261
+ }).add(instruction);
3262
+ },
2203
3263
  buildSetPoolTermsHashTx(params) {
2204
3264
  const authority = new PublicKey(params.authority);
2205
3265
  const poolAddress = new PublicKey(params.poolAddress);
@@ -2483,6 +3543,7 @@ export function createProtocolClient(connection, programIdInput) {
2483
3543
  const claimant = new PublicKey(params.claimant);
2484
3544
  const poolAddress = new PublicKey(params.poolAddress);
2485
3545
  const member = new PublicKey(params.member);
3546
+ const payoutMint = new PublicKey(params.payoutMint);
2486
3547
  const cycleHash = hashStringTo32(params.cycleId);
2487
3548
  const ruleHash = fromHex(params.ruleHashHex, 32);
2488
3549
  const [configV2Pda] = deriveConfigV2Pda(programId);
@@ -2494,6 +3555,11 @@ export function createProtocolClient(connection, programIdInput) {
2494
3555
  programId,
2495
3556
  poolAddress,
2496
3557
  });
3558
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
3559
+ programId,
3560
+ poolAddress,
3561
+ paymentMint: payoutMint,
3562
+ });
2497
3563
  const [membershipPda] = deriveMembershipPda({
2498
3564
  programId,
2499
3565
  poolAddress,
@@ -2537,6 +3603,7 @@ export function createProtocolClient(connection, programIdInput) {
2537
3603
  { pubkey: poolAddress, isSigner: false, isWritable: true },
2538
3604
  { pubkey: poolTermsPda, isSigner: false, isWritable: false },
2539
3605
  { pubkey: oraclePolicyPda, isSigner: false, isWritable: false },
3606
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
2540
3607
  { pubkey: membershipPda, isSigner: false, isWritable: false },
2541
3608
  { pubkey: aggregatePda, isSigner: false, isWritable: true },
2542
3609
  { pubkey: new PublicKey(params.recipientSystemAccount), isSigner: false, isWritable: true },
@@ -2581,6 +3648,41 @@ export function createProtocolClient(connection, programIdInput) {
2581
3648
  recentBlockhash: params.recentBlockhash,
2582
3649
  }).add(instruction);
2583
3650
  },
3651
+ buildUpsertCoverageProductPaymentOptionTx(params) {
3652
+ const authority = new PublicKey(params.authority);
3653
+ const poolAddress = new PublicKey(params.poolAddress);
3654
+ const paymentMint = new PublicKey(params.paymentMint);
3655
+ const productIdHash = fromHex(params.productIdHashHex, 32);
3656
+ const [configV2Pda] = deriveConfigV2Pda(programId);
3657
+ const [coverageProductPda] = deriveCoverageProductPda({
3658
+ programId,
3659
+ poolAddress,
3660
+ productIdHash,
3661
+ });
3662
+ const [coverageProductPaymentOptionPda] = deriveCoverageProductPaymentOptionPda({
3663
+ programId,
3664
+ poolAddress,
3665
+ productIdHash,
3666
+ paymentMint,
3667
+ });
3668
+ const instruction = new TransactionInstruction({
3669
+ programId,
3670
+ keys: [
3671
+ { pubkey: authority, isSigner: true, isWritable: true },
3672
+ { pubkey: configV2Pda, isSigner: false, isWritable: false },
3673
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
3674
+ { pubkey: coverageProductPda, isSigner: false, isWritable: true },
3675
+ { pubkey: paymentMint, isSigner: false, isWritable: false },
3676
+ { pubkey: coverageProductPaymentOptionPda, isSigner: false, isWritable: true },
3677
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3678
+ ],
3679
+ data: encodeUpsertCoverageProductPaymentOptionData(params),
3680
+ });
3681
+ return new Transaction({
3682
+ feePayer: authority,
3683
+ recentBlockhash: params.recentBlockhash,
3684
+ }).add(instruction);
3685
+ },
2584
3686
  buildUpdateCoverageProductV2Tx(params) {
2585
3687
  const authority = new PublicKey(params.authority);
2586
3688
  const poolAddress = new PublicKey(params.poolAddress);
@@ -3000,6 +4102,36 @@ export function createProtocolClient(connection, programIdInput) {
3000
4102
  recentBlockhash: params.recentBlockhash,
3001
4103
  }).add(instruction);
3002
4104
  },
4105
+ buildActivateCycleWithQuoteSolTx(params) {
4106
+ return buildActivateCycleWithQuoteSolTransaction(params);
4107
+ },
4108
+ buildActivateCycleWithQuoteSplTx(params) {
4109
+ return buildActivateCycleWithQuoteSplTransaction(params);
4110
+ },
4111
+ buildSettleCycleCommitmentTx(params) {
4112
+ return buildSettleCycleCommitmentTransaction(params);
4113
+ },
4114
+ buildSettleCycleCommitmentSolTx(params) {
4115
+ return buildSettleCycleCommitmentSolTransaction(params);
4116
+ },
4117
+ buildWithdrawPoolTreasurySplTx(params) {
4118
+ return buildWithdrawPoolTreasurySplTransaction(params);
4119
+ },
4120
+ buildWithdrawPoolTreasurySolTx(params) {
4121
+ return buildWithdrawPoolTreasurySolTransaction(params);
4122
+ },
4123
+ buildWithdrawProtocolFeeSplTx(params) {
4124
+ return buildWithdrawProtocolFeeSplTransaction(params);
4125
+ },
4126
+ buildWithdrawProtocolFeeSolTx(params) {
4127
+ return buildWithdrawProtocolFeeSolTransaction(params);
4128
+ },
4129
+ buildWithdrawPoolOracleFeeSplTx(params) {
4130
+ return buildWithdrawPoolOracleFeeSplTransaction(params);
4131
+ },
4132
+ buildWithdrawPoolOracleFeeSolTx(params) {
4133
+ return buildWithdrawPoolOracleFeeSolTransaction(params);
4134
+ },
3003
4135
  async fetchProtocolConfig() {
3004
4136
  const [configPda] = deriveConfigPda(programId);
3005
4137
  const account = await connection.getAccountInfo(configPda, 'confirmed');
@@ -3158,6 +4290,39 @@ export function createProtocolClient(connection, programIdInput) {
3158
4290
  return null;
3159
4291
  return decodePoolAssetVaultAccount(pda.toBase58(), account.data);
3160
4292
  },
4293
+ async fetchProtocolFeeVault(paymentMint) {
4294
+ const [pda] = deriveProtocolFeeVaultPda({
4295
+ programId,
4296
+ paymentMint,
4297
+ });
4298
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4299
+ if (!account)
4300
+ return null;
4301
+ return decodeProtocolFeeVaultAccount(pda.toBase58(), account.data);
4302
+ },
4303
+ async fetchPoolOracleFeeVault(params) {
4304
+ const [pda] = derivePoolOracleFeeVaultPda({
4305
+ programId,
4306
+ poolAddress: params.poolAddress,
4307
+ oracle: params.oracle,
4308
+ paymentMint: params.paymentMint,
4309
+ });
4310
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4311
+ if (!account)
4312
+ return null;
4313
+ return decodePoolOracleFeeVaultAccount(pda.toBase58(), account.data);
4314
+ },
4315
+ async fetchPoolOraclePermissionSet(params) {
4316
+ const [pda] = derivePoolOraclePermissionSetPda({
4317
+ programId,
4318
+ poolAddress: params.poolAddress,
4319
+ oracle: params.oracle,
4320
+ });
4321
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4322
+ if (!account)
4323
+ return null;
4324
+ return decodePoolOraclePermissionSetAccount(pda.toBase58(), account.data);
4325
+ },
3161
4326
  async fetchOutcomeSchema(schemaKeyHashHex) {
3162
4327
  const [pda] = deriveSchemaPda({
3163
4328
  programId,
@@ -3251,6 +4416,18 @@ export function createProtocolClient(connection, programIdInput) {
3251
4416
  return null;
3252
4417
  return decodeCoverageProductAccount(pda.toBase58(), account.data);
3253
4418
  },
4419
+ async fetchCoverageProductPaymentOption(params) {
4420
+ const [pda] = deriveCoverageProductPaymentOptionPda({
4421
+ programId,
4422
+ poolAddress: params.poolAddress,
4423
+ productIdHash: fromHex(params.productIdHashHex, 32),
4424
+ paymentMint: params.paymentMint,
4425
+ });
4426
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4427
+ if (!account)
4428
+ return null;
4429
+ return decodeCoverageProductPaymentOptionAccount(pda.toBase58(), account.data);
4430
+ },
3254
4431
  async fetchCoveragePolicy(params) {
3255
4432
  const [pda] = deriveCoveragePolicyPda({
3256
4433
  programId,
@@ -3296,6 +4473,43 @@ export function createProtocolClient(connection, programIdInput) {
3296
4473
  return null;
3297
4474
  return decodePremiumAttestationReplayAccount(pda.toBase58(), account.data);
3298
4475
  },
4476
+ async fetchMemberCycle(params) {
4477
+ const [pda] = deriveMemberCyclePda({
4478
+ programId,
4479
+ poolAddress: params.poolAddress,
4480
+ member: params.member,
4481
+ periodIndex: typeof params.periodIndex === 'bigint'
4482
+ ? params.periodIndex
4483
+ : BigInt(params.periodIndex),
4484
+ });
4485
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4486
+ if (!account)
4487
+ return null;
4488
+ return decodeMemberCycleAccount(pda.toBase58(), account.data);
4489
+ },
4490
+ async fetchCycleQuoteReplay(params) {
4491
+ const [pda] = deriveCycleQuoteReplayPda({
4492
+ programId,
4493
+ poolAddress: params.poolAddress,
4494
+ member: params.member,
4495
+ nonceHash: fromHex(params.nonceHashHex, 32),
4496
+ });
4497
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4498
+ if (!account)
4499
+ return null;
4500
+ return decodeCycleQuoteReplayAccount(pda.toBase58(), account.data);
4501
+ },
4502
+ async fetchPoolTreasuryReserve(params) {
4503
+ const [pda] = derivePoolTreasuryReservePda({
4504
+ programId,
4505
+ poolAddress: params.poolAddress,
4506
+ paymentMint: params.paymentMint,
4507
+ });
4508
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4509
+ if (!account)
4510
+ return null;
4511
+ return decodePoolTreasuryReserveAccount(pda.toBase58(), account.data);
4512
+ },
3299
4513
  async fetchCoverageClaimRecord(params) {
3300
4514
  const [pda] = deriveCoverageClaimPda({
3301
4515
  programId,