@omegax/protocol-sdk 0.4.2 → 0.4.3

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,6 @@
1
- import { PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
1
+ import { Ed25519Program, PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
2
2
  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';
3
+ import { asPubkey, deriveClaimPda, deriveClaimDelegatePda, deriveClaimV2Pda, deriveConfigPda, deriveConfigV2Pda, deriveCoverageClaimPda, deriveCoverageProductPda, 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
4
  const MAX_POOL_ID_SEED_BYTES = 32;
5
5
  const MAX_ORACLE_SUPPORTED_SCHEMAS = 16;
6
6
  export const PROTOCOL_PROGRAM_ID = 'Bn6eixac1QEEVErGBvBjxAd6pgB9e2q4XHvAkinQ5y1B';
@@ -31,6 +31,7 @@ const IX_FINALIZE_UNSTAKE = anchorDiscriminator('global', 'finalize_unstake');
31
31
  const IX_SLASH_ORACLE = anchorDiscriminator('global', 'slash_oracle');
32
32
  const IX_CREATE_POOL_V2 = anchorDiscriminator('global', 'create_pool_v2');
33
33
  const IX_SET_POOL_ORACLE_POLICY = anchorDiscriminator('global', 'set_pool_oracle_policy');
34
+ const IX_SET_POOL_COVERAGE_RESERVE_FLOOR = anchorDiscriminator('global', 'set_pool_coverage_reserve_floor');
34
35
  const IX_SET_POOL_TERMS_HASH = anchorDiscriminator('global', 'set_pool_terms_hash');
35
36
  const IX_REGISTER_OUTCOME_SCHEMA = anchorDiscriminator('global', 'register_outcome_schema');
36
37
  const IX_VERIFY_OUTCOME_SCHEMA = anchorDiscriminator('global', 'verify_outcome_schema');
@@ -55,6 +56,16 @@ const IX_SUBMIT_COVERAGE_CLAIM = anchorDiscriminator('global', 'submit_coverage_
55
56
  const IX_SETTLE_COVERAGE_CLAIM = anchorDiscriminator('global', 'settle_coverage_claim');
56
57
  const IX_MIGRATE_POOL_V1_TO_V2 = anchorDiscriminator('global', 'migrate_pool_v1_to_v2');
57
58
  const IX_MIGRATE_MEMBERSHIP_V1_TO_V2 = anchorDiscriminator('global', 'migrate_membership_v1_to_v2');
59
+ const IX_ACTIVATE_CYCLE_WITH_QUOTE_SOL = anchorDiscriminator('global', 'activate_cycle_with_quote_sol');
60
+ const IX_ACTIVATE_CYCLE_WITH_QUOTE_SPL = anchorDiscriminator('global', 'activate_cycle_with_quote_spl');
61
+ const IX_SETTLE_CYCLE_COMMITMENT = anchorDiscriminator('global', 'settle_cycle_commitment');
62
+ const IX_SETTLE_CYCLE_COMMITMENT_SOL = anchorDiscriminator('global', 'settle_cycle_commitment_sol');
63
+ const IX_WITHDRAW_POOL_TREASURY_SPL = anchorDiscriminator('global', 'withdraw_pool_treasury_spl');
64
+ const IX_WITHDRAW_POOL_TREASURY_SOL = anchorDiscriminator('global', 'withdraw_pool_treasury_sol');
65
+ const IX_WITHDRAW_PROTOCOL_FEE_SPL = anchorDiscriminator('global', 'withdraw_protocol_fee_spl');
66
+ const IX_WITHDRAW_PROTOCOL_FEE_SOL = anchorDiscriminator('global', 'withdraw_protocol_fee_sol');
67
+ const IX_WITHDRAW_POOL_ORACLE_FEE_SPL = anchorDiscriminator('global', 'withdraw_pool_oracle_fee_spl');
68
+ const IX_WITHDRAW_POOL_ORACLE_FEE_SOL = anchorDiscriminator('global', 'withdraw_pool_oracle_fee_sol');
58
69
  const ACCOUNT_PROTOCOL_CONFIG = anchorDiscriminator('account', 'ProtocolConfig');
59
70
  const ACCOUNT_POOL = anchorDiscriminator('account', 'Pool');
60
71
  const ACCOUNT_ORACLE_REGISTRY = anchorDiscriminator('account', 'OracleRegistryEntry');
@@ -70,6 +81,8 @@ const ACCOUNT_ORACLE_STAKE_POSITION = anchorDiscriminator('account', 'OracleStak
70
81
  const ACCOUNT_POOL_ORACLE_POLICY = anchorDiscriminator('account', 'PoolOraclePolicy');
71
82
  const ACCOUNT_POOL_TERMS = anchorDiscriminator('account', 'PoolTerms');
72
83
  const ACCOUNT_POOL_ASSET_VAULT = anchorDiscriminator('account', 'PoolAssetVault');
84
+ const ACCOUNT_PROTOCOL_FEE_VAULT = anchorDiscriminator('account', 'ProtocolFeeVault');
85
+ const ACCOUNT_POOL_ORACLE_FEE_VAULT = anchorDiscriminator('account', 'PoolOracleFeeVault');
73
86
  const ACCOUNT_OUTCOME_SCHEMA = anchorDiscriminator('account', 'OutcomeSchemaRegistryEntry');
74
87
  const ACCOUNT_POOL_OUTCOME_RULE = anchorDiscriminator('account', 'PoolOutcomeRule');
75
88
  const ACCOUNT_INVITE_ISSUER = anchorDiscriminator('account', 'InviteIssuerRegistryEntry');
@@ -83,6 +96,12 @@ const ACCOUNT_ATTESTATION_VOTE = anchorDiscriminator('account', 'AttestationVote
83
96
  const ACCOUNT_COVERAGE_POLICY = anchorDiscriminator('account', 'CoveragePolicy');
84
97
  const ACCOUNT_PREMIUM_LEDGER = anchorDiscriminator('account', 'PremiumLedger');
85
98
  const ACCOUNT_PREMIUM_ATTESTATION_REPLAY = anchorDiscriminator('account', 'PremiumAttestationReplay');
99
+ const ACCOUNT_POOL_ORACLE_PERMISSION_SET = anchorDiscriminator('account', 'PoolOraclePermissionSet');
100
+ const ACCOUNT_MEMBER_CYCLE = anchorDiscriminator('account', 'MemberCycleState');
101
+ const ACCOUNT_CYCLE_QUOTE_REPLAY = anchorDiscriminator('account', 'CycleQuoteReplay');
102
+ const ACCOUNT_POOL_TREASURY_RESERVE = anchorDiscriminator('account', 'PoolTreasuryReserve');
103
+ const TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
104
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
86
105
  function pubkeyFromData(buffer, offset) {
87
106
  return new PublicKey(buffer.subarray(offset, offset + 32)).toBase58();
88
107
  }
@@ -120,6 +139,46 @@ function parsePoolType(code) {
120
139
  return 'unknown';
121
140
  }
122
141
  }
142
+ function parseMemberCycleStatus(code) {
143
+ switch (code) {
144
+ case 1:
145
+ return 'active';
146
+ case 2:
147
+ return 'settled';
148
+ default:
149
+ return 'unknown';
150
+ }
151
+ }
152
+ function deriveAssociatedTokenAddress(params) {
153
+ const owner = asPubkey(params.owner);
154
+ const mint = asPubkey(params.mint);
155
+ const [address] = PublicKey.findProgramAddressSync([owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID);
156
+ return address;
157
+ }
158
+ export function buildCycleQuoteMessage(fields) {
159
+ return Buffer.concat([
160
+ Buffer.from('omegax:cycle_quote:v1', 'utf8'),
161
+ asPubkey(fields.poolAddress).toBuffer(),
162
+ asPubkey(fields.member).toBuffer(),
163
+ Buffer.from(fromHex(fields.productIdHashHex, 32)),
164
+ asPubkey(fields.paymentMint).toBuffer(),
165
+ encodeU64Le(fields.premiumAmountRaw),
166
+ encodeU64Le(fields.canonicalPremiumAmount),
167
+ encodeU64Le(fields.periodIndex),
168
+ Buffer.from([fields.commitmentEnabled ? 1 : 0]),
169
+ encodeU64Le(fields.bondAmountRaw),
170
+ encodeU64Le(fields.shieldFeeRaw),
171
+ encodeU64Le(fields.protocolFeeRaw),
172
+ encodeU64Le(fields.oracleFeeRaw),
173
+ encodeU64Le(fields.netPoolPremiumRaw),
174
+ encodeU64Le(fields.totalAmountRaw),
175
+ Buffer.from([fields.includedShieldCount]),
176
+ encodeU16Le(fields.thresholdBps),
177
+ encodeI64Le(fields.expiresAtTs),
178
+ Buffer.from(fromHex(fields.nonceHashHex, 32)),
179
+ Buffer.from(fromHex(fields.quoteMetaHashHex, 32)),
180
+ ]);
181
+ }
123
182
  function hasDiscriminator(data, discriminator) {
124
183
  if (data.length < 8)
125
184
  return false;
@@ -430,6 +489,8 @@ function decodeCycleOutcomeAggregateAccount(address, data) {
430
489
  offset += 1;
431
490
  const claimed = data.readUInt8(offset) === 1;
432
491
  offset += 1;
492
+ const rewardLiabilityReserved = data.readUInt8(offset) === 1;
493
+ offset += 1;
433
494
  const latestAsOfTs = Number(readI64Le(data, offset));
434
495
  offset += 8;
435
496
  const bump = data.readUInt8(offset);
@@ -446,6 +507,7 @@ function decodeCycleOutcomeAggregateAccount(address, data) {
446
507
  finalized,
447
508
  passed,
448
509
  claimed,
510
+ rewardLiabilityReserved,
449
511
  latestAsOfTs,
450
512
  bump,
451
513
  };
@@ -536,6 +598,8 @@ function decodePoolOraclePolicyAccount(address, data) {
536
598
  offset += 1;
537
599
  const requireVerifiedSchema = data.readUInt8(offset) === 1;
538
600
  offset += 1;
601
+ const oracleFeeBps = readU16Le(data, offset);
602
+ offset += 2;
539
603
  const allowDelegateClaim = data.readUInt8(offset) === 1;
540
604
  offset += 1;
541
605
  const bump = data.readUInt8(offset);
@@ -545,6 +609,7 @@ function decodePoolOraclePolicyAccount(address, data) {
545
609
  quorumM,
546
610
  quorumN,
547
611
  requireVerifiedSchema,
612
+ oracleFeeBps,
548
613
  allowDelegateClaim,
549
614
  bump,
550
615
  };
@@ -605,6 +670,190 @@ function decodePoolAssetVaultAccount(address, data) {
605
670
  bump,
606
671
  };
607
672
  }
673
+ function decodeProtocolFeeVaultAccount(address, data) {
674
+ if (!hasDiscriminator(data, ACCOUNT_PROTOCOL_FEE_VAULT)) {
675
+ throw new Error('account discriminator mismatch for ProtocolFeeVault');
676
+ }
677
+ let offset = 8;
678
+ const paymentMint = pubkeyFromData(data, offset);
679
+ offset += 32;
680
+ const bump = data.readUInt8(offset);
681
+ return {
682
+ address,
683
+ paymentMint,
684
+ bump,
685
+ };
686
+ }
687
+ function decodePoolOracleFeeVaultAccount(address, data) {
688
+ if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_FEE_VAULT)) {
689
+ throw new Error('account discriminator mismatch for PoolOracleFeeVault');
690
+ }
691
+ let offset = 8;
692
+ const pool = pubkeyFromData(data, offset);
693
+ offset += 32;
694
+ const oracle = pubkeyFromData(data, offset);
695
+ offset += 32;
696
+ const paymentMint = pubkeyFromData(data, offset);
697
+ offset += 32;
698
+ const bump = data.readUInt8(offset);
699
+ return {
700
+ address,
701
+ pool,
702
+ oracle,
703
+ paymentMint,
704
+ bump,
705
+ };
706
+ }
707
+ function decodePoolOraclePermissionSetAccount(address, data) {
708
+ if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_PERMISSION_SET)) {
709
+ throw new Error('account discriminator mismatch for PoolOraclePermissionSet');
710
+ }
711
+ let offset = 8;
712
+ const pool = pubkeyFromData(data, offset);
713
+ offset += 32;
714
+ const oracle = pubkeyFromData(data, offset);
715
+ offset += 32;
716
+ const permissions = data.readUInt32LE(offset);
717
+ offset += 4;
718
+ const bump = data.readUInt8(offset);
719
+ return {
720
+ address,
721
+ pool,
722
+ oracle,
723
+ permissions,
724
+ bump,
725
+ };
726
+ }
727
+ function decodeMemberCycleAccount(address, data) {
728
+ if (!hasDiscriminator(data, ACCOUNT_MEMBER_CYCLE)) {
729
+ throw new Error('account discriminator mismatch for MemberCycleState');
730
+ }
731
+ let offset = 8;
732
+ const pool = pubkeyFromData(data, offset);
733
+ offset += 32;
734
+ const member = pubkeyFromData(data, offset);
735
+ offset += 32;
736
+ const productIdHashHex = toHex(data.subarray(offset, offset + 32));
737
+ offset += 32;
738
+ const periodIndex = readU64Le(data, offset);
739
+ offset += 8;
740
+ const paymentMint = pubkeyFromData(data, offset);
741
+ offset += 32;
742
+ const premiumAmountRaw = readU64Le(data, offset);
743
+ offset += 8;
744
+ const bondAmountRaw = readU64Le(data, offset);
745
+ offset += 8;
746
+ const shieldFeeRaw = readU64Le(data, offset);
747
+ offset += 8;
748
+ const protocolFeeRaw = readU64Le(data, offset);
749
+ offset += 8;
750
+ const oracleFeeRaw = readU64Le(data, offset);
751
+ offset += 8;
752
+ const netPoolPremiumRaw = readU64Le(data, offset);
753
+ offset += 8;
754
+ const totalAmountRaw = readU64Le(data, offset);
755
+ offset += 8;
756
+ const canonicalPremiumAmount = readU64Le(data, offset);
757
+ offset += 8;
758
+ const commitmentEnabled = data.readUInt8(offset) === 1;
759
+ offset += 1;
760
+ const thresholdBps = readU16Le(data, offset);
761
+ offset += 2;
762
+ const includedShieldCount = data.readUInt8(offset);
763
+ offset += 1;
764
+ const shieldConsumed = data.readUInt8(offset) === 1;
765
+ offset += 1;
766
+ const statusCode = data.readUInt8(offset);
767
+ offset += 1;
768
+ const passed = data.readUInt8(offset) === 1;
769
+ offset += 1;
770
+ const activatedAt = Number(readI64Le(data, offset));
771
+ offset += 8;
772
+ const settledAt = Number(readI64Le(data, offset));
773
+ offset += 8;
774
+ const quoteHashHex = toHex(data.subarray(offset, offset + 32));
775
+ offset += 32;
776
+ const bump = data.readUInt8(offset);
777
+ return {
778
+ address,
779
+ pool,
780
+ member,
781
+ productIdHashHex,
782
+ periodIndex,
783
+ paymentMint,
784
+ premiumAmountRaw,
785
+ bondAmountRaw,
786
+ shieldFeeRaw,
787
+ protocolFeeRaw,
788
+ oracleFeeRaw,
789
+ netPoolPremiumRaw,
790
+ totalAmountRaw,
791
+ canonicalPremiumAmount,
792
+ commitmentEnabled,
793
+ thresholdBps,
794
+ includedShieldCount,
795
+ shieldConsumed,
796
+ statusCode,
797
+ status: parseMemberCycleStatus(statusCode),
798
+ passed,
799
+ activatedAt,
800
+ settledAt,
801
+ quoteHashHex,
802
+ bump,
803
+ };
804
+ }
805
+ function decodeCycleQuoteReplayAccount(address, data) {
806
+ if (!hasDiscriminator(data, ACCOUNT_CYCLE_QUOTE_REPLAY)) {
807
+ throw new Error('account discriminator mismatch for CycleQuoteReplay');
808
+ }
809
+ let offset = 8;
810
+ const pool = pubkeyFromData(data, offset);
811
+ offset += 32;
812
+ const member = pubkeyFromData(data, offset);
813
+ offset += 32;
814
+ const nonceHashHex = toHex(data.subarray(offset, offset + 32));
815
+ offset += 32;
816
+ const quoteHashHex = toHex(data.subarray(offset, offset + 32));
817
+ offset += 32;
818
+ const createdAt = Number(readI64Le(data, offset));
819
+ offset += 8;
820
+ const bump = data.readUInt8(offset);
821
+ return {
822
+ address,
823
+ pool,
824
+ member,
825
+ nonceHashHex,
826
+ quoteHashHex,
827
+ createdAt,
828
+ bump,
829
+ };
830
+ }
831
+ function decodePoolTreasuryReserveAccount(address, data) {
832
+ if (!hasDiscriminator(data, ACCOUNT_POOL_TREASURY_RESERVE)) {
833
+ throw new Error('account discriminator mismatch for PoolTreasuryReserve');
834
+ }
835
+ let offset = 8;
836
+ const pool = pubkeyFromData(data, offset);
837
+ offset += 32;
838
+ const paymentMint = pubkeyFromData(data, offset);
839
+ offset += 32;
840
+ const reservedRefundAmount = readU64Le(data, offset);
841
+ offset += 8;
842
+ const reservedRewardAmount = readU64Le(data, offset);
843
+ offset += 8;
844
+ const manualCoverageReserveAmount = readU64Le(data, offset);
845
+ offset += 8;
846
+ const bump = data.readUInt8(offset);
847
+ return {
848
+ address,
849
+ pool,
850
+ paymentMint,
851
+ reservedRefundAmount,
852
+ reservedRewardAmount,
853
+ manualCoverageReserveAmount,
854
+ bump,
855
+ };
856
+ }
608
857
  function decodeOutcomeSchemaAccount(address, data) {
609
858
  if (!hasDiscriminator(data, ACCOUNT_OUTCOME_SCHEMA)) {
610
859
  throw new Error('account discriminator mismatch for OutcomeSchemaRegistryEntry');
@@ -1288,9 +1537,29 @@ function encodeSetPoolOraclePolicyData(params) {
1288
1537
  Buffer.from([params.quorumM & 0xff]),
1289
1538
  Buffer.from([params.quorumN & 0xff]),
1290
1539
  Buffer.from([params.requireVerifiedSchema ? 1 : 0]),
1540
+ encodeU16Le(params.oracleFeeBps),
1291
1541
  Buffer.from([params.allowDelegateClaim ? 1 : 0]),
1292
1542
  ]);
1293
1543
  }
1544
+ function encodeSetPoolCoverageReserveFloorData(params) {
1545
+ return Buffer.concat([
1546
+ IX_SET_POOL_COVERAGE_RESERVE_FLOOR,
1547
+ asPubkey(params.paymentMint).toBuffer(),
1548
+ encodeU64Le(params.amount),
1549
+ ]);
1550
+ }
1551
+ function encodeWithdrawProtocolFeeSplData(params) {
1552
+ return Buffer.concat([IX_WITHDRAW_PROTOCOL_FEE_SPL, encodeU64Le(params.amount)]);
1553
+ }
1554
+ function encodeWithdrawProtocolFeeSolData(params) {
1555
+ return Buffer.concat([IX_WITHDRAW_PROTOCOL_FEE_SOL, encodeU64Le(params.amount)]);
1556
+ }
1557
+ function encodeWithdrawPoolOracleFeeSplData(params) {
1558
+ return Buffer.concat([IX_WITHDRAW_POOL_ORACLE_FEE_SPL, encodeU64Le(params.amount)]);
1559
+ }
1560
+ function encodeWithdrawPoolOracleFeeSolData(params) {
1561
+ return Buffer.concat([IX_WITHDRAW_POOL_ORACLE_FEE_SOL, encodeU64Le(params.amount)]);
1562
+ }
1294
1563
  function encodeSetPoolTermsHashData(params) {
1295
1564
  return Buffer.concat([
1296
1565
  IX_SET_POOL_TERMS_HASH,
@@ -1480,6 +1749,634 @@ function encodeMigratePoolV1ToV2Data(params) {
1480
1749
  encodeString(params.metadataUri),
1481
1750
  ]);
1482
1751
  }
1752
+ function deriveCoverageProductPaymentOptionPda(params) {
1753
+ const program = asPubkey(params.programId);
1754
+ const pool = asPubkey(params.poolAddress);
1755
+ const paymentMint = asPubkey(params.paymentMint);
1756
+ return PublicKey.findProgramAddressSync([
1757
+ Buffer.from('coverage_product_payment_option'),
1758
+ pool.toBuffer(),
1759
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
1760
+ paymentMint.toBuffer(),
1761
+ ], program);
1762
+ }
1763
+ function buildActivateCycleWithQuoteSolTransaction(params) {
1764
+ const programId = asPubkey(params.programId);
1765
+ const payer = asPubkey(params.payer);
1766
+ const member = asPubkey(params.member);
1767
+ const poolAddress = asPubkey(params.poolAddress);
1768
+ const oracle = asPubkey(params.oracle);
1769
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
1770
+ const [configV2] = deriveConfigV2Pda(programId);
1771
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
1772
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
1773
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
1774
+ programId,
1775
+ poolAddress,
1776
+ oracle,
1777
+ });
1778
+ const [oraclePolicy] = derivePoolOraclePolicyPda({
1779
+ programId,
1780
+ poolAddress,
1781
+ });
1782
+ const [membership] = deriveMembershipPda({ programId, poolAddress, member });
1783
+ const [coverageProduct] = deriveCoverageProductPda({
1784
+ programId,
1785
+ poolAddress,
1786
+ productIdHash: fromHex(params.productIdHashHex, 32),
1787
+ });
1788
+ const [coverageProductPaymentOption] = deriveCoverageProductPaymentOptionPda({
1789
+ programId,
1790
+ poolAddress,
1791
+ productIdHashHex: params.productIdHashHex,
1792
+ paymentMint: zeroPubkey,
1793
+ });
1794
+ const [coveragePolicy] = deriveCoveragePolicyPda({ programId, poolAddress, member });
1795
+ const [coveragePolicyNft] = deriveCoverageNftPda({ programId, poolAddress, member });
1796
+ const [premiumLedger] = derivePremiumLedgerPda({ programId, poolAddress, member });
1797
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
1798
+ programId,
1799
+ paymentMint: zeroPubkey,
1800
+ });
1801
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
1802
+ programId,
1803
+ poolAddress,
1804
+ oracle,
1805
+ paymentMint: zeroPubkey,
1806
+ });
1807
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
1808
+ programId,
1809
+ poolAddress,
1810
+ paymentMint: zeroPubkey,
1811
+ });
1812
+ const [memberCycle] = deriveMemberCyclePda({
1813
+ programId,
1814
+ poolAddress,
1815
+ member,
1816
+ periodIndex: params.periodIndex,
1817
+ });
1818
+ const [cycleQuoteReplay] = deriveCycleQuoteReplayPda({
1819
+ programId,
1820
+ poolAddress,
1821
+ member,
1822
+ nonceHash: fromHex(params.nonceHashHex, 32),
1823
+ });
1824
+ const ed25519Instruction = Ed25519Program.createInstructionWithPrivateKey({
1825
+ privateKey: params.oracleSecretKey,
1826
+ message: params.quoteMessage,
1827
+ });
1828
+ const instruction = new TransactionInstruction({
1829
+ programId,
1830
+ keys: [
1831
+ { pubkey: payer, isSigner: true, isWritable: true },
1832
+ { pubkey: configV2, isSigner: false, isWritable: false },
1833
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
1834
+ { pubkey: member, isSigner: false, isWritable: false },
1835
+ { pubkey: oracle, isSigner: false, isWritable: false },
1836
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
1837
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
1838
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
1839
+ { pubkey: oraclePolicy, isSigner: false, isWritable: false },
1840
+ { pubkey: membership, isSigner: false, isWritable: true },
1841
+ { pubkey: coverageProduct, isSigner: false, isWritable: false },
1842
+ { pubkey: coverageProductPaymentOption, isSigner: false, isWritable: false },
1843
+ { pubkey: coveragePolicy, isSigner: false, isWritable: true },
1844
+ { pubkey: coveragePolicyNft, isSigner: false, isWritable: true },
1845
+ { pubkey: premiumLedger, isSigner: false, isWritable: true },
1846
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
1847
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
1848
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
1849
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
1850
+ { pubkey: cycleQuoteReplay, isSigner: false, isWritable: true },
1851
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
1852
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
1853
+ ],
1854
+ data: Buffer.concat([
1855
+ IX_ACTIVATE_CYCLE_WITH_QUOTE_SOL,
1856
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
1857
+ encodeU64Le(params.periodIndex),
1858
+ encodeU64Le(params.premiumAmountRaw),
1859
+ encodeU64Le(params.canonicalPremiumAmount),
1860
+ Buffer.from([params.commitmentEnabled ? 1 : 0]),
1861
+ encodeU64Le(params.bondAmountRaw),
1862
+ encodeU64Le(params.shieldFeeRaw),
1863
+ encodeU64Le(params.protocolFeeRaw),
1864
+ encodeU64Le(params.oracleFeeRaw),
1865
+ encodeU64Le(params.netPoolPremiumRaw),
1866
+ encodeU64Le(params.totalAmountRaw),
1867
+ Buffer.from([params.includedShieldCount]),
1868
+ encodeU16Le(params.thresholdBps),
1869
+ encodeI64Le(params.expiresAtTs),
1870
+ Buffer.from(fromHex(params.nonceHashHex, 32)),
1871
+ Buffer.from(fromHex(params.quoteMetaHashHex, 32)),
1872
+ ]),
1873
+ });
1874
+ return new Transaction({
1875
+ feePayer: payer,
1876
+ recentBlockhash: params.recentBlockhash,
1877
+ }).add(ed25519Instruction, instruction);
1878
+ }
1879
+ function buildActivateCycleWithQuoteSplTransaction(params) {
1880
+ const programId = asPubkey(params.programId);
1881
+ const payer = asPubkey(params.payer);
1882
+ const member = asPubkey(params.member);
1883
+ const poolAddress = asPubkey(params.poolAddress);
1884
+ const oracle = asPubkey(params.oracle);
1885
+ const paymentMint = asPubkey(params.paymentMint);
1886
+ const [configV2] = deriveConfigV2Pda(programId);
1887
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
1888
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
1889
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
1890
+ programId,
1891
+ poolAddress,
1892
+ oracle,
1893
+ });
1894
+ const [oraclePolicy] = derivePoolOraclePolicyPda({
1895
+ programId,
1896
+ poolAddress,
1897
+ });
1898
+ const [membership] = deriveMembershipPda({ programId, poolAddress, member });
1899
+ const [coverageProduct] = deriveCoverageProductPda({
1900
+ programId,
1901
+ poolAddress,
1902
+ productIdHash: fromHex(params.productIdHashHex, 32),
1903
+ });
1904
+ const [coverageProductPaymentOption] = deriveCoverageProductPaymentOptionPda({
1905
+ programId,
1906
+ poolAddress,
1907
+ productIdHashHex: params.productIdHashHex,
1908
+ paymentMint,
1909
+ });
1910
+ const [coveragePolicy] = deriveCoveragePolicyPda({ programId, poolAddress, member });
1911
+ const [coveragePolicyNft] = deriveCoverageNftPda({ programId, poolAddress, member });
1912
+ const [premiumLedger] = derivePremiumLedgerPda({ programId, poolAddress, member });
1913
+ const [poolAssetVault] = derivePoolAssetVaultPda({
1914
+ programId,
1915
+ poolAddress,
1916
+ payoutMint: paymentMint,
1917
+ });
1918
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
1919
+ owner: poolAssetVault,
1920
+ mint: paymentMint,
1921
+ });
1922
+ const payerTokenAccount = deriveAssociatedTokenAddress({
1923
+ owner: payer,
1924
+ mint: paymentMint,
1925
+ });
1926
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
1927
+ programId,
1928
+ paymentMint,
1929
+ });
1930
+ const protocolFeeVaultTokenAccount = deriveAssociatedTokenAddress({
1931
+ owner: protocolFeeVault,
1932
+ mint: paymentMint,
1933
+ allowOwnerOffCurve: true,
1934
+ });
1935
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
1936
+ programId,
1937
+ poolAddress,
1938
+ oracle,
1939
+ paymentMint,
1940
+ });
1941
+ const poolOracleFeeVaultTokenAccount = deriveAssociatedTokenAddress({
1942
+ owner: poolOracleFeeVault,
1943
+ mint: paymentMint,
1944
+ allowOwnerOffCurve: true,
1945
+ });
1946
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
1947
+ programId,
1948
+ poolAddress,
1949
+ paymentMint,
1950
+ });
1951
+ const [memberCycle] = deriveMemberCyclePda({
1952
+ programId,
1953
+ poolAddress,
1954
+ member,
1955
+ periodIndex: params.periodIndex,
1956
+ });
1957
+ const [cycleQuoteReplay] = deriveCycleQuoteReplayPda({
1958
+ programId,
1959
+ poolAddress,
1960
+ member,
1961
+ nonceHash: fromHex(params.nonceHashHex, 32),
1962
+ });
1963
+ const ed25519Instruction = Ed25519Program.createInstructionWithPrivateKey({
1964
+ privateKey: params.oracleSecretKey,
1965
+ message: params.quoteMessage,
1966
+ });
1967
+ const instruction = new TransactionInstruction({
1968
+ programId,
1969
+ keys: [
1970
+ { pubkey: payer, isSigner: true, isWritable: true },
1971
+ { pubkey: configV2, isSigner: false, isWritable: false },
1972
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
1973
+ { pubkey: member, isSigner: false, isWritable: false },
1974
+ { pubkey: oracle, isSigner: false, isWritable: false },
1975
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
1976
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
1977
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
1978
+ { pubkey: oraclePolicy, isSigner: false, isWritable: false },
1979
+ { pubkey: membership, isSigner: false, isWritable: true },
1980
+ { pubkey: coverageProduct, isSigner: false, isWritable: false },
1981
+ { pubkey: coverageProductPaymentOption, isSigner: false, isWritable: false },
1982
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
1983
+ { pubkey: coveragePolicy, isSigner: false, isWritable: true },
1984
+ { pubkey: coveragePolicyNft, isSigner: false, isWritable: true },
1985
+ { pubkey: premiumLedger, isSigner: false, isWritable: true },
1986
+ { pubkey: poolAssetVault, isSigner: false, isWritable: true },
1987
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
1988
+ { pubkey: payerTokenAccount, isSigner: false, isWritable: true },
1989
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
1990
+ { pubkey: protocolFeeVaultTokenAccount, isSigner: false, isWritable: true },
1991
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
1992
+ { pubkey: poolOracleFeeVaultTokenAccount, isSigner: false, isWritable: true },
1993
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
1994
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
1995
+ { pubkey: cycleQuoteReplay, isSigner: false, isWritable: true },
1996
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
1997
+ { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
1998
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
1999
+ { pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
2000
+ ],
2001
+ data: Buffer.concat([
2002
+ IX_ACTIVATE_CYCLE_WITH_QUOTE_SPL,
2003
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2004
+ encodeU64Le(params.periodIndex),
2005
+ encodeU64Le(params.premiumAmountRaw),
2006
+ encodeU64Le(params.canonicalPremiumAmount),
2007
+ Buffer.from([params.commitmentEnabled ? 1 : 0]),
2008
+ encodeU64Le(params.bondAmountRaw),
2009
+ encodeU64Le(params.shieldFeeRaw),
2010
+ encodeU64Le(params.protocolFeeRaw),
2011
+ encodeU64Le(params.oracleFeeRaw),
2012
+ encodeU64Le(params.netPoolPremiumRaw),
2013
+ encodeU64Le(params.totalAmountRaw),
2014
+ Buffer.from([params.includedShieldCount]),
2015
+ encodeU16Le(params.thresholdBps),
2016
+ encodeI64Le(params.expiresAtTs),
2017
+ Buffer.from(fromHex(params.nonceHashHex, 32)),
2018
+ Buffer.from(fromHex(params.quoteMetaHashHex, 32)),
2019
+ ]),
2020
+ });
2021
+ return new Transaction({
2022
+ feePayer: payer,
2023
+ recentBlockhash: params.recentBlockhash,
2024
+ }).add(ed25519Instruction, instruction);
2025
+ }
2026
+ function buildSettleCycleCommitmentTransaction(params) {
2027
+ const programId = asPubkey(params.programId);
2028
+ const payer = asPubkey(params.payer);
2029
+ const oracle = asPubkey(params.oracle);
2030
+ const member = asPubkey(params.member);
2031
+ const poolAddress = asPubkey(params.poolAddress);
2032
+ const paymentMint = asPubkey(params.paymentMint);
2033
+ const [configV2] = deriveConfigV2Pda(programId);
2034
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2035
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2036
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2037
+ programId,
2038
+ poolAddress,
2039
+ oracle,
2040
+ });
2041
+ const [poolAssetVault] = derivePoolAssetVaultPda({
2042
+ programId,
2043
+ poolAddress,
2044
+ payoutMint: paymentMint,
2045
+ });
2046
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
2047
+ owner: poolAssetVault,
2048
+ mint: paymentMint,
2049
+ });
2050
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2051
+ programId,
2052
+ poolAddress,
2053
+ paymentMint,
2054
+ });
2055
+ const [memberCycle] = deriveMemberCyclePda({
2056
+ programId,
2057
+ poolAddress,
2058
+ member,
2059
+ periodIndex: params.periodIndex,
2060
+ });
2061
+ const recipientTokenAccount = deriveAssociatedTokenAddress({
2062
+ owner: member,
2063
+ mint: paymentMint,
2064
+ });
2065
+ const instruction = new TransactionInstruction({
2066
+ programId,
2067
+ keys: [
2068
+ { pubkey: oracle, isSigner: true, isWritable: true },
2069
+ { pubkey: configV2, isSigner: false, isWritable: false },
2070
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2071
+ { pubkey: member, isSigner: false, isWritable: false },
2072
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2073
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2074
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2075
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2076
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2077
+ { pubkey: poolAssetVault, isSigner: false, isWritable: false },
2078
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
2079
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2080
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
2081
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2082
+ ],
2083
+ data: Buffer.concat([
2084
+ IX_SETTLE_CYCLE_COMMITMENT,
2085
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2086
+ encodeU64Le(params.periodIndex),
2087
+ Buffer.from([params.passed ? 1 : 0]),
2088
+ Buffer.from([params.shieldConsumed ? 1 : 0]),
2089
+ ]),
2090
+ });
2091
+ return new Transaction({
2092
+ feePayer: payer,
2093
+ recentBlockhash: params.recentBlockhash,
2094
+ }).add(instruction);
2095
+ }
2096
+ function buildSettleCycleCommitmentSolTransaction(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 zeroPubkey = asPubkey(ZERO_PUBKEY);
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 [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2112
+ programId,
2113
+ poolAddress,
2114
+ paymentMint: zeroPubkey,
2115
+ });
2116
+ const [memberCycle] = deriveMemberCyclePda({
2117
+ programId,
2118
+ poolAddress,
2119
+ member,
2120
+ periodIndex: params.periodIndex,
2121
+ });
2122
+ const instruction = new TransactionInstruction({
2123
+ programId,
2124
+ keys: [
2125
+ { pubkey: oracle, isSigner: true, isWritable: true },
2126
+ { pubkey: configV2, isSigner: false, isWritable: false },
2127
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
2128
+ { pubkey: member, isSigner: false, isWritable: false },
2129
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2130
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2131
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2132
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2133
+ { pubkey: member, isSigner: false, isWritable: true },
2134
+ { pubkey: memberCycle, isSigner: false, isWritable: true },
2135
+ ],
2136
+ data: Buffer.concat([
2137
+ IX_SETTLE_CYCLE_COMMITMENT_SOL,
2138
+ Buffer.from(fromHex(params.productIdHashHex, 32)),
2139
+ encodeU64Le(params.periodIndex),
2140
+ Buffer.from([params.passed ? 1 : 0]),
2141
+ Buffer.from([params.shieldConsumed ? 1 : 0]),
2142
+ ]),
2143
+ });
2144
+ return new Transaction({
2145
+ feePayer: payer,
2146
+ recentBlockhash: params.recentBlockhash,
2147
+ }).add(instruction);
2148
+ }
2149
+ function buildWithdrawPoolTreasurySplTransaction(params) {
2150
+ const programId = asPubkey(params.programId);
2151
+ const payer = asPubkey(params.payer);
2152
+ const oracle = asPubkey(params.oracle);
2153
+ const poolAddress = asPubkey(params.poolAddress);
2154
+ const paymentMint = asPubkey(params.paymentMint);
2155
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2156
+ const [configV2] = deriveConfigV2Pda(programId);
2157
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2158
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2159
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2160
+ programId,
2161
+ poolAddress,
2162
+ oracle,
2163
+ });
2164
+ const [poolAssetVault] = derivePoolAssetVaultPda({
2165
+ programId,
2166
+ poolAddress,
2167
+ payoutMint: paymentMint,
2168
+ });
2169
+ const poolVaultTokenAccount = deriveAssociatedTokenAddress({
2170
+ owner: poolAssetVault,
2171
+ mint: paymentMint,
2172
+ });
2173
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2174
+ programId,
2175
+ poolAddress,
2176
+ paymentMint,
2177
+ });
2178
+ const instruction = new TransactionInstruction({
2179
+ programId,
2180
+ keys: [
2181
+ { pubkey: oracle, isSigner: true, isWritable: true },
2182
+ { pubkey: configV2, isSigner: false, isWritable: false },
2183
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2184
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2185
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2186
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2187
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2188
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2189
+ { pubkey: poolAssetVault, isSigner: false, isWritable: false },
2190
+ { pubkey: poolVaultTokenAccount, isSigner: false, isWritable: true },
2191
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2192
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2193
+ ],
2194
+ data: Buffer.concat([IX_WITHDRAW_POOL_TREASURY_SPL, encodeU64Le(params.amount)]),
2195
+ });
2196
+ return new Transaction({
2197
+ feePayer: payer,
2198
+ recentBlockhash: params.recentBlockhash,
2199
+ }).add(instruction);
2200
+ }
2201
+ function buildWithdrawPoolTreasurySolTransaction(params) {
2202
+ const programId = asPubkey(params.programId);
2203
+ const payer = asPubkey(params.payer);
2204
+ const oracle = asPubkey(params.oracle);
2205
+ const poolAddress = asPubkey(params.poolAddress);
2206
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2207
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2208
+ const [configV2] = deriveConfigV2Pda(programId);
2209
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2210
+ const [poolOracle] = derivePoolOraclePda({ programId, poolAddress, oracle });
2211
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2212
+ programId,
2213
+ poolAddress,
2214
+ oracle,
2215
+ });
2216
+ const [poolTreasuryReserve] = derivePoolTreasuryReservePda({
2217
+ programId,
2218
+ poolAddress,
2219
+ paymentMint: zeroPubkey,
2220
+ });
2221
+ const instruction = new TransactionInstruction({
2222
+ programId,
2223
+ keys: [
2224
+ { pubkey: oracle, isSigner: true, isWritable: true },
2225
+ { pubkey: configV2, isSigner: false, isWritable: false },
2226
+ { pubkey: poolAddress, isSigner: false, isWritable: true },
2227
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2228
+ { pubkey: poolOracle, isSigner: false, isWritable: false },
2229
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2230
+ { pubkey: poolTreasuryReserve, isSigner: false, isWritable: true },
2231
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2232
+ ],
2233
+ data: Buffer.concat([IX_WITHDRAW_POOL_TREASURY_SOL, encodeU64Le(params.amount)]),
2234
+ });
2235
+ return new Transaction({
2236
+ feePayer: payer,
2237
+ recentBlockhash: params.recentBlockhash,
2238
+ }).add(instruction);
2239
+ }
2240
+ function buildWithdrawProtocolFeeSplTransaction(params) {
2241
+ const programId = asPubkey(params.programId);
2242
+ const governanceAuthority = asPubkey(params.governanceAuthority);
2243
+ const paymentMint = asPubkey(params.paymentMint);
2244
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2245
+ const [configV2] = deriveConfigV2Pda(programId);
2246
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
2247
+ programId,
2248
+ paymentMint,
2249
+ });
2250
+ const protocolFeeVaultTokenAccount = deriveAssociatedTokenAddress({
2251
+ owner: protocolFeeVault,
2252
+ mint: paymentMint,
2253
+ allowOwnerOffCurve: true,
2254
+ });
2255
+ const instruction = new TransactionInstruction({
2256
+ programId,
2257
+ keys: [
2258
+ { pubkey: governanceAuthority, isSigner: true, isWritable: true },
2259
+ { pubkey: configV2, isSigner: false, isWritable: false },
2260
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2261
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
2262
+ { pubkey: protocolFeeVaultTokenAccount, isSigner: false, isWritable: true },
2263
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2264
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2265
+ ],
2266
+ data: encodeWithdrawProtocolFeeSplData(params),
2267
+ });
2268
+ return new Transaction({
2269
+ feePayer: governanceAuthority,
2270
+ recentBlockhash: params.recentBlockhash,
2271
+ }).add(instruction);
2272
+ }
2273
+ function buildWithdrawProtocolFeeSolTransaction(params) {
2274
+ const programId = asPubkey(params.programId);
2275
+ const governanceAuthority = asPubkey(params.governanceAuthority);
2276
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2277
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2278
+ const [configV2] = deriveConfigV2Pda(programId);
2279
+ const [protocolFeeVault] = deriveProtocolFeeVaultPda({
2280
+ programId,
2281
+ paymentMint: zeroPubkey,
2282
+ });
2283
+ const instruction = new TransactionInstruction({
2284
+ programId,
2285
+ keys: [
2286
+ { pubkey: governanceAuthority, isSigner: true, isWritable: true },
2287
+ { pubkey: configV2, isSigner: false, isWritable: false },
2288
+ { pubkey: protocolFeeVault, isSigner: false, isWritable: true },
2289
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2290
+ ],
2291
+ data: encodeWithdrawProtocolFeeSolData(params),
2292
+ });
2293
+ return new Transaction({
2294
+ feePayer: governanceAuthority,
2295
+ recentBlockhash: params.recentBlockhash,
2296
+ }).add(instruction);
2297
+ }
2298
+ function buildWithdrawPoolOracleFeeSplTransaction(params) {
2299
+ const programId = asPubkey(params.programId);
2300
+ const oracle = asPubkey(params.oracle);
2301
+ const poolAddress = asPubkey(params.poolAddress);
2302
+ const paymentMint = asPubkey(params.paymentMint);
2303
+ const recipientTokenAccount = asPubkey(params.recipientTokenAccount);
2304
+ const [configV2] = deriveConfigV2Pda(programId);
2305
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2306
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2307
+ programId,
2308
+ poolAddress,
2309
+ oracle,
2310
+ });
2311
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
2312
+ programId,
2313
+ poolAddress,
2314
+ oracle,
2315
+ paymentMint,
2316
+ });
2317
+ const poolOracleFeeVaultTokenAccount = deriveAssociatedTokenAddress({
2318
+ owner: poolOracleFeeVault,
2319
+ mint: paymentMint,
2320
+ allowOwnerOffCurve: true,
2321
+ });
2322
+ const instruction = new TransactionInstruction({
2323
+ programId,
2324
+ keys: [
2325
+ { pubkey: oracle, isSigner: true, isWritable: true },
2326
+ { pubkey: configV2, isSigner: false, isWritable: false },
2327
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2328
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2329
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2330
+ { pubkey: paymentMint, isSigner: false, isWritable: true },
2331
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
2332
+ { pubkey: poolOracleFeeVaultTokenAccount, isSigner: false, isWritable: true },
2333
+ { pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
2334
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
2335
+ ],
2336
+ data: encodeWithdrawPoolOracleFeeSplData(params),
2337
+ });
2338
+ return new Transaction({
2339
+ feePayer: oracle,
2340
+ recentBlockhash: params.recentBlockhash,
2341
+ }).add(instruction);
2342
+ }
2343
+ function buildWithdrawPoolOracleFeeSolTransaction(params) {
2344
+ const programId = asPubkey(params.programId);
2345
+ const oracle = asPubkey(params.oracle);
2346
+ const poolAddress = asPubkey(params.poolAddress);
2347
+ const recipientSystemAccount = asPubkey(params.recipientSystemAccount);
2348
+ const zeroPubkey = asPubkey(ZERO_PUBKEY);
2349
+ const [configV2] = deriveConfigV2Pda(programId);
2350
+ const [oracleEntry] = deriveOraclePda({ programId, oracle });
2351
+ const [poolOraclePermissions] = derivePoolOraclePermissionSetPda({
2352
+ programId,
2353
+ poolAddress,
2354
+ oracle,
2355
+ });
2356
+ const [poolOracleFeeVault] = derivePoolOracleFeeVaultPda({
2357
+ programId,
2358
+ poolAddress,
2359
+ oracle,
2360
+ paymentMint: zeroPubkey,
2361
+ });
2362
+ const instruction = new TransactionInstruction({
2363
+ programId,
2364
+ keys: [
2365
+ { pubkey: oracle, isSigner: true, isWritable: true },
2366
+ { pubkey: configV2, isSigner: false, isWritable: false },
2367
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2368
+ { pubkey: oracleEntry, isSigner: false, isWritable: false },
2369
+ { pubkey: poolOraclePermissions, isSigner: false, isWritable: false },
2370
+ { pubkey: poolOracleFeeVault, isSigner: false, isWritable: true },
2371
+ { pubkey: recipientSystemAccount, isSigner: false, isWritable: true },
2372
+ ],
2373
+ data: encodeWithdrawPoolOracleFeeSolData(params),
2374
+ });
2375
+ return new Transaction({
2376
+ feePayer: oracle,
2377
+ recentBlockhash: params.recentBlockhash,
2378
+ }).add(instruction);
2379
+ }
1483
2380
  export function createProtocolClient(connection, programIdInput) {
1484
2381
  const programId = new PublicKey(programIdInput);
1485
2382
  return {
@@ -1806,6 +2703,7 @@ export function createProtocolClient(connection, programIdInput) {
1806
2703
  const oracle = new PublicKey(params.oracle);
1807
2704
  const poolAddress = new PublicKey(params.poolAddress);
1808
2705
  const member = new PublicKey(params.member);
2706
+ const payoutMint = new PublicKey(params.payoutMint);
1809
2707
  const cycleHash = hashStringTo32(params.cycleId);
1810
2708
  const ruleHash = fromHex(params.ruleHashHex, 32);
1811
2709
  const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
@@ -1823,6 +2721,15 @@ export function createProtocolClient(connection, programIdInput) {
1823
2721
  programId,
1824
2722
  poolAddress,
1825
2723
  });
2724
+ const [poolTermsPda] = derivePoolTermsPda({
2725
+ programId,
2726
+ poolAddress,
2727
+ });
2728
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
2729
+ programId,
2730
+ poolAddress,
2731
+ paymentMint: payoutMint,
2732
+ });
1826
2733
  const [poolOraclePda] = derivePoolOraclePda({
1827
2734
  programId,
1828
2735
  poolAddress,
@@ -1865,7 +2772,9 @@ export function createProtocolClient(connection, programIdInput) {
1865
2772
  { pubkey: configV2Pda, isSigner: false, isWritable: false },
1866
2773
  { pubkey: stakePositionPda, isSigner: false, isWritable: false },
1867
2774
  { pubkey: poolAddress, isSigner: false, isWritable: false },
2775
+ { pubkey: poolTermsPda, isSigner: false, isWritable: false },
1868
2776
  { pubkey: poolOraclePolicyPda, isSigner: false, isWritable: false },
2777
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
1869
2778
  { pubkey: poolOraclePda, isSigner: false, isWritable: false },
1870
2779
  { pubkey: membershipPda, isSigner: false, isWritable: false },
1871
2780
  { pubkey: poolRulePda, isSigner: false, isWritable: false },
@@ -1885,8 +2794,18 @@ export function createProtocolClient(connection, programIdInput) {
1885
2794
  const payer = new PublicKey(params.payer);
1886
2795
  const poolAddress = new PublicKey(params.poolAddress);
1887
2796
  const member = new PublicKey(params.member);
2797
+ const payoutMint = new PublicKey(params.payoutMint);
1888
2798
  const cycleHash = hashStringTo32(params.cycleId);
1889
2799
  const ruleHash = fromHex(params.ruleHashHex, 32);
2800
+ const [poolTermsPda] = derivePoolTermsPda({
2801
+ programId,
2802
+ poolAddress,
2803
+ });
2804
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
2805
+ programId,
2806
+ poolAddress,
2807
+ paymentMint: payoutMint,
2808
+ });
1890
2809
  const [aggregatePda] = deriveOutcomeAggregatePda({
1891
2810
  programId,
1892
2811
  poolAddress,
@@ -1896,7 +2815,14 @@ export function createProtocolClient(connection, programIdInput) {
1896
2815
  });
1897
2816
  const instruction = new TransactionInstruction({
1898
2817
  programId,
1899
- keys: [{ pubkey: aggregatePda, isSigner: false, isWritable: true }],
2818
+ keys: [
2819
+ { pubkey: payer, isSigner: true, isWritable: true },
2820
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
2821
+ { pubkey: poolTermsPda, isSigner: false, isWritable: false },
2822
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
2823
+ { pubkey: aggregatePda, isSigner: false, isWritable: true },
2824
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
2825
+ ],
1900
2826
  data: IX_FINALIZE_CYCLE_OUTCOME,
1901
2827
  });
1902
2828
  return new Transaction({
@@ -2182,6 +3108,7 @@ export function createProtocolClient(connection, programIdInput) {
2182
3108
  buildSetPoolOraclePolicyTx(params) {
2183
3109
  const authority = new PublicKey(params.authority);
2184
3110
  const poolAddress = new PublicKey(params.poolAddress);
3111
+ const [configV2Pda] = deriveConfigV2Pda(programId);
2185
3112
  const [oraclePolicyPda] = derivePoolOraclePolicyPda({
2186
3113
  programId,
2187
3114
  poolAddress,
@@ -2190,6 +3117,7 @@ export function createProtocolClient(connection, programIdInput) {
2190
3117
  programId,
2191
3118
  keys: [
2192
3119
  { pubkey: authority, isSigner: true, isWritable: false },
3120
+ { pubkey: configV2Pda, isSigner: false, isWritable: false },
2193
3121
  { pubkey: poolAddress, isSigner: false, isWritable: false },
2194
3122
  { pubkey: oraclePolicyPda, isSigner: false, isWritable: true },
2195
3123
  ],
@@ -2200,6 +3128,32 @@ export function createProtocolClient(connection, programIdInput) {
2200
3128
  recentBlockhash: params.recentBlockhash,
2201
3129
  }).add(instruction);
2202
3130
  },
3131
+ buildSetPoolCoverageReserveFloorTx(params) {
3132
+ const authority = new PublicKey(params.authority);
3133
+ const poolAddress = new PublicKey(params.poolAddress);
3134
+ const paymentMint = new PublicKey(params.paymentMint);
3135
+ const [configV2Pda] = deriveConfigV2Pda(programId);
3136
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
3137
+ programId,
3138
+ poolAddress,
3139
+ paymentMint,
3140
+ });
3141
+ const instruction = new TransactionInstruction({
3142
+ programId,
3143
+ keys: [
3144
+ { pubkey: authority, isSigner: true, isWritable: true },
3145
+ { pubkey: configV2Pda, isSigner: false, isWritable: false },
3146
+ { pubkey: poolAddress, isSigner: false, isWritable: false },
3147
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
3148
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
3149
+ ],
3150
+ data: encodeSetPoolCoverageReserveFloorData(params),
3151
+ });
3152
+ return new Transaction({
3153
+ feePayer: authority,
3154
+ recentBlockhash: params.recentBlockhash,
3155
+ }).add(instruction);
3156
+ },
2203
3157
  buildSetPoolTermsHashTx(params) {
2204
3158
  const authority = new PublicKey(params.authority);
2205
3159
  const poolAddress = new PublicKey(params.poolAddress);
@@ -2483,6 +3437,7 @@ export function createProtocolClient(connection, programIdInput) {
2483
3437
  const claimant = new PublicKey(params.claimant);
2484
3438
  const poolAddress = new PublicKey(params.poolAddress);
2485
3439
  const member = new PublicKey(params.member);
3440
+ const payoutMint = new PublicKey(params.payoutMint);
2486
3441
  const cycleHash = hashStringTo32(params.cycleId);
2487
3442
  const ruleHash = fromHex(params.ruleHashHex, 32);
2488
3443
  const [configV2Pda] = deriveConfigV2Pda(programId);
@@ -2494,6 +3449,11 @@ export function createProtocolClient(connection, programIdInput) {
2494
3449
  programId,
2495
3450
  poolAddress,
2496
3451
  });
3452
+ const [poolTreasuryReservePda] = derivePoolTreasuryReservePda({
3453
+ programId,
3454
+ poolAddress,
3455
+ paymentMint: payoutMint,
3456
+ });
2497
3457
  const [membershipPda] = deriveMembershipPda({
2498
3458
  programId,
2499
3459
  poolAddress,
@@ -2537,6 +3497,7 @@ export function createProtocolClient(connection, programIdInput) {
2537
3497
  { pubkey: poolAddress, isSigner: false, isWritable: true },
2538
3498
  { pubkey: poolTermsPda, isSigner: false, isWritable: false },
2539
3499
  { pubkey: oraclePolicyPda, isSigner: false, isWritable: false },
3500
+ { pubkey: poolTreasuryReservePda, isSigner: false, isWritable: true },
2540
3501
  { pubkey: membershipPda, isSigner: false, isWritable: false },
2541
3502
  { pubkey: aggregatePda, isSigner: false, isWritable: true },
2542
3503
  { pubkey: new PublicKey(params.recipientSystemAccount), isSigner: false, isWritable: true },
@@ -3000,6 +3961,36 @@ export function createProtocolClient(connection, programIdInput) {
3000
3961
  recentBlockhash: params.recentBlockhash,
3001
3962
  }).add(instruction);
3002
3963
  },
3964
+ buildActivateCycleWithQuoteSolTx(params) {
3965
+ return buildActivateCycleWithQuoteSolTransaction(params);
3966
+ },
3967
+ buildActivateCycleWithQuoteSplTx(params) {
3968
+ return buildActivateCycleWithQuoteSplTransaction(params);
3969
+ },
3970
+ buildSettleCycleCommitmentTx(params) {
3971
+ return buildSettleCycleCommitmentTransaction(params);
3972
+ },
3973
+ buildSettleCycleCommitmentSolTx(params) {
3974
+ return buildSettleCycleCommitmentSolTransaction(params);
3975
+ },
3976
+ buildWithdrawPoolTreasurySplTx(params) {
3977
+ return buildWithdrawPoolTreasurySplTransaction(params);
3978
+ },
3979
+ buildWithdrawPoolTreasurySolTx(params) {
3980
+ return buildWithdrawPoolTreasurySolTransaction(params);
3981
+ },
3982
+ buildWithdrawProtocolFeeSplTx(params) {
3983
+ return buildWithdrawProtocolFeeSplTransaction(params);
3984
+ },
3985
+ buildWithdrawProtocolFeeSolTx(params) {
3986
+ return buildWithdrawProtocolFeeSolTransaction(params);
3987
+ },
3988
+ buildWithdrawPoolOracleFeeSplTx(params) {
3989
+ return buildWithdrawPoolOracleFeeSplTransaction(params);
3990
+ },
3991
+ buildWithdrawPoolOracleFeeSolTx(params) {
3992
+ return buildWithdrawPoolOracleFeeSolTransaction(params);
3993
+ },
3003
3994
  async fetchProtocolConfig() {
3004
3995
  const [configPda] = deriveConfigPda(programId);
3005
3996
  const account = await connection.getAccountInfo(configPda, 'confirmed');
@@ -3158,6 +4149,39 @@ export function createProtocolClient(connection, programIdInput) {
3158
4149
  return null;
3159
4150
  return decodePoolAssetVaultAccount(pda.toBase58(), account.data);
3160
4151
  },
4152
+ async fetchProtocolFeeVault(paymentMint) {
4153
+ const [pda] = deriveProtocolFeeVaultPda({
4154
+ programId,
4155
+ paymentMint,
4156
+ });
4157
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4158
+ if (!account)
4159
+ return null;
4160
+ return decodeProtocolFeeVaultAccount(pda.toBase58(), account.data);
4161
+ },
4162
+ async fetchPoolOracleFeeVault(params) {
4163
+ const [pda] = derivePoolOracleFeeVaultPda({
4164
+ programId,
4165
+ poolAddress: params.poolAddress,
4166
+ oracle: params.oracle,
4167
+ paymentMint: params.paymentMint,
4168
+ });
4169
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4170
+ if (!account)
4171
+ return null;
4172
+ return decodePoolOracleFeeVaultAccount(pda.toBase58(), account.data);
4173
+ },
4174
+ async fetchPoolOraclePermissionSet(params) {
4175
+ const [pda] = derivePoolOraclePermissionSetPda({
4176
+ programId,
4177
+ poolAddress: params.poolAddress,
4178
+ oracle: params.oracle,
4179
+ });
4180
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4181
+ if (!account)
4182
+ return null;
4183
+ return decodePoolOraclePermissionSetAccount(pda.toBase58(), account.data);
4184
+ },
3161
4185
  async fetchOutcomeSchema(schemaKeyHashHex) {
3162
4186
  const [pda] = deriveSchemaPda({
3163
4187
  programId,
@@ -3296,6 +4320,43 @@ export function createProtocolClient(connection, programIdInput) {
3296
4320
  return null;
3297
4321
  return decodePremiumAttestationReplayAccount(pda.toBase58(), account.data);
3298
4322
  },
4323
+ async fetchMemberCycle(params) {
4324
+ const [pda] = deriveMemberCyclePda({
4325
+ programId,
4326
+ poolAddress: params.poolAddress,
4327
+ member: params.member,
4328
+ periodIndex: typeof params.periodIndex === 'bigint'
4329
+ ? params.periodIndex
4330
+ : BigInt(params.periodIndex),
4331
+ });
4332
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4333
+ if (!account)
4334
+ return null;
4335
+ return decodeMemberCycleAccount(pda.toBase58(), account.data);
4336
+ },
4337
+ async fetchCycleQuoteReplay(params) {
4338
+ const [pda] = deriveCycleQuoteReplayPda({
4339
+ programId,
4340
+ poolAddress: params.poolAddress,
4341
+ member: params.member,
4342
+ nonceHash: fromHex(params.nonceHashHex, 32),
4343
+ });
4344
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4345
+ if (!account)
4346
+ return null;
4347
+ return decodeCycleQuoteReplayAccount(pda.toBase58(), account.data);
4348
+ },
4349
+ async fetchPoolTreasuryReserve(params) {
4350
+ const [pda] = derivePoolTreasuryReservePda({
4351
+ programId,
4352
+ poolAddress: params.poolAddress,
4353
+ paymentMint: params.paymentMint,
4354
+ });
4355
+ const account = await connection.getAccountInfo(pda, 'confirmed');
4356
+ if (!account)
4357
+ return null;
4358
+ return decodePoolTreasuryReserveAccount(pda.toBase58(), account.data);
4359
+ },
3299
4360
  async fetchCoverageClaimRecord(params) {
3300
4361
  const [pda] = deriveCoverageClaimPda({
3301
4362
  programId,