@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.
@@ -14,6 +14,12 @@ export declare const SEED_ORACLE_STAKE = "oracle_stake";
14
14
  export declare const SEED_POOL_ORACLE_POLICY = "pool_oracle_policy";
15
15
  export declare const SEED_POOL_TERMS = "pool_terms";
16
16
  export declare const SEED_POOL_ASSET_VAULT = "pool_asset_vault";
17
+ export declare const SEED_POOL_ORACLE_PERMISSIONS = "pool_oracle_permissions";
18
+ export declare const SEED_MEMBER_CYCLE = "member_cycle";
19
+ export declare const SEED_CYCLE_QUOTE_REPLAY = "cycle_quote_replay";
20
+ export declare const SEED_POOL_TREASURY_RESERVE = "pool_treasury_reserve";
21
+ export declare const SEED_PROTOCOL_FEE_VAULT = "protocol_fee_vault";
22
+ export declare const SEED_POOL_ORACLE_FEE_VAULT = "pool_oracle_fee_vault";
17
23
  export declare const SEED_SCHEMA = "schema";
18
24
  export declare const SEED_POOL_RULE = "pool_rule";
19
25
  export declare const SEED_INVITE_ISSUER = "invite_issuer";
@@ -25,6 +31,7 @@ export declare const SEED_CLAIM_V2 = "claim_v2";
25
31
  export declare const SEED_COVERAGE_POLICY = "coverage_policy";
26
32
  export declare const SEED_COVERAGE_NFT = "coverage_nft";
27
33
  export declare const SEED_COVERAGE_PRODUCT = "coverage_product";
34
+ export declare const SEED_COVERAGE_PRODUCT_PAYMENT_OPTION = "coverage_product_payment_option";
28
35
  export declare const SEED_PREMIUM_LEDGER = "premium_ledger";
29
36
  export declare const SEED_PREMIUM_REPLAY = "premium_replay";
30
37
  export declare const SEED_COVERAGE_CLAIM = "coverage_claim";
@@ -95,6 +102,44 @@ export declare function derivePoolAssetVaultPda(params: {
95
102
  poolAddress: string | PublicKey;
96
103
  payoutMint: string | PublicKey;
97
104
  }): [PublicKey, number];
105
+ export declare function deriveCoverageProductPaymentOptionPda(params: {
106
+ programId: string | PublicKey;
107
+ poolAddress: string | PublicKey;
108
+ productIdHash: Uint8Array;
109
+ paymentMint: string | PublicKey;
110
+ }): [PublicKey, number];
111
+ export declare function derivePoolOraclePermissionSetPda(params: {
112
+ programId: string | PublicKey;
113
+ poolAddress: string | PublicKey;
114
+ oracle: string | PublicKey;
115
+ }): [PublicKey, number];
116
+ export declare function deriveMemberCyclePda(params: {
117
+ programId: string | PublicKey;
118
+ poolAddress: string | PublicKey;
119
+ member: string | PublicKey;
120
+ periodIndex: bigint | number;
121
+ }): [PublicKey, number];
122
+ export declare function deriveCycleQuoteReplayPda(params: {
123
+ programId: string | PublicKey;
124
+ poolAddress: string | PublicKey;
125
+ member: string | PublicKey;
126
+ nonceHash: Uint8Array;
127
+ }): [PublicKey, number];
128
+ export declare function derivePoolTreasuryReservePda(params: {
129
+ programId: string | PublicKey;
130
+ poolAddress: string | PublicKey;
131
+ paymentMint: string | PublicKey;
132
+ }): [PublicKey, number];
133
+ export declare function deriveProtocolFeeVaultPda(params: {
134
+ programId: string | PublicKey;
135
+ paymentMint: string | PublicKey;
136
+ }): [PublicKey, number];
137
+ export declare function derivePoolOracleFeeVaultPda(params: {
138
+ programId: string | PublicKey;
139
+ poolAddress: string | PublicKey;
140
+ oracle: string | PublicKey;
141
+ paymentMint: string | PublicKey;
142
+ }): [PublicKey, number];
98
143
  export declare function deriveSchemaPda(params: {
99
144
  programId: string | PublicKey;
100
145
  schemaKeyHash: Uint8Array;
@@ -14,6 +14,12 @@ export const SEED_ORACLE_STAKE = 'oracle_stake';
14
14
  export const SEED_POOL_ORACLE_POLICY = 'pool_oracle_policy';
15
15
  export const SEED_POOL_TERMS = 'pool_terms';
16
16
  export const SEED_POOL_ASSET_VAULT = 'pool_asset_vault';
17
+ export const SEED_POOL_ORACLE_PERMISSIONS = 'pool_oracle_permissions';
18
+ export const SEED_MEMBER_CYCLE = 'member_cycle';
19
+ export const SEED_CYCLE_QUOTE_REPLAY = 'cycle_quote_replay';
20
+ export const SEED_POOL_TREASURY_RESERVE = 'pool_treasury_reserve';
21
+ export const SEED_PROTOCOL_FEE_VAULT = 'protocol_fee_vault';
22
+ export const SEED_POOL_ORACLE_FEE_VAULT = 'pool_oracle_fee_vault';
17
23
  export const SEED_SCHEMA = 'schema';
18
24
  export const SEED_POOL_RULE = 'pool_rule';
19
25
  export const SEED_INVITE_ISSUER = 'invite_issuer';
@@ -25,6 +31,7 @@ export const SEED_CLAIM_V2 = 'claim_v2';
25
31
  export const SEED_COVERAGE_POLICY = 'coverage_policy';
26
32
  export const SEED_COVERAGE_NFT = 'coverage_nft';
27
33
  export const SEED_COVERAGE_PRODUCT = 'coverage_product';
34
+ export const SEED_COVERAGE_PRODUCT_PAYMENT_OPTION = 'coverage_product_payment_option';
28
35
  export const SEED_PREMIUM_LEDGER = 'premium_ledger';
29
36
  export const SEED_PREMIUM_REPLAY = 'premium_replay';
30
37
  export const SEED_COVERAGE_CLAIM = 'coverage_claim';
@@ -130,6 +137,77 @@ export function derivePoolAssetVaultPda(params) {
130
137
  const mint = asPubkey(params.payoutMint);
131
138
  return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_ASSET_VAULT), pool.toBuffer(), mint.toBuffer()], program);
132
139
  }
140
+ export function deriveCoverageProductPaymentOptionPda(params) {
141
+ const program = asPubkey(params.programId);
142
+ const pool = asPubkey(params.poolAddress);
143
+ const mint = asPubkey(params.paymentMint);
144
+ return PublicKey.findProgramAddressSync([
145
+ Buffer.from(SEED_COVERAGE_PRODUCT_PAYMENT_OPTION),
146
+ pool.toBuffer(),
147
+ Buffer.from(params.productIdHash),
148
+ mint.toBuffer(),
149
+ ], program);
150
+ }
151
+ function encodeU64Seed(value) {
152
+ const out = Buffer.alloc(8);
153
+ out.writeBigUInt64LE(typeof value === 'bigint' ? value : BigInt(value));
154
+ return out;
155
+ }
156
+ export function derivePoolOraclePermissionSetPda(params) {
157
+ const program = asPubkey(params.programId);
158
+ const pool = asPubkey(params.poolAddress);
159
+ const oracle = asPubkey(params.oracle);
160
+ return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_ORACLE_PERMISSIONS), pool.toBuffer(), oracle.toBuffer()], program);
161
+ }
162
+ export function deriveMemberCyclePda(params) {
163
+ const program = asPubkey(params.programId);
164
+ const pool = asPubkey(params.poolAddress);
165
+ const member = asPubkey(params.member);
166
+ return PublicKey.findProgramAddressSync([
167
+ Buffer.from(SEED_MEMBER_CYCLE),
168
+ pool.toBuffer(),
169
+ member.toBuffer(),
170
+ encodeU64Seed(params.periodIndex),
171
+ ], program);
172
+ }
173
+ export function deriveCycleQuoteReplayPda(params) {
174
+ const program = asPubkey(params.programId);
175
+ const pool = asPubkey(params.poolAddress);
176
+ const member = asPubkey(params.member);
177
+ return PublicKey.findProgramAddressSync([
178
+ Buffer.from(SEED_CYCLE_QUOTE_REPLAY),
179
+ pool.toBuffer(),
180
+ member.toBuffer(),
181
+ Buffer.from(params.nonceHash),
182
+ ], program);
183
+ }
184
+ export function derivePoolTreasuryReservePda(params) {
185
+ const program = asPubkey(params.programId);
186
+ const pool = asPubkey(params.poolAddress);
187
+ const paymentMint = asPubkey(params.paymentMint);
188
+ return PublicKey.findProgramAddressSync([
189
+ Buffer.from(SEED_POOL_TREASURY_RESERVE),
190
+ pool.toBuffer(),
191
+ paymentMint.toBuffer(),
192
+ ], program);
193
+ }
194
+ export function deriveProtocolFeeVaultPda(params) {
195
+ const program = asPubkey(params.programId);
196
+ const paymentMint = asPubkey(params.paymentMint);
197
+ return PublicKey.findProgramAddressSync([Buffer.from(SEED_PROTOCOL_FEE_VAULT), paymentMint.toBuffer()], program);
198
+ }
199
+ export function derivePoolOracleFeeVaultPda(params) {
200
+ const program = asPubkey(params.programId);
201
+ const pool = asPubkey(params.poolAddress);
202
+ const oracle = asPubkey(params.oracle);
203
+ const paymentMint = asPubkey(params.paymentMint);
204
+ return PublicKey.findProgramAddressSync([
205
+ Buffer.from(SEED_POOL_ORACLE_FEE_VAULT),
206
+ pool.toBuffer(),
207
+ oracle.toBuffer(),
208
+ paymentMint.toBuffer(),
209
+ ], program);
210
+ }
133
211
  export function deriveSchemaPda(params) {
134
212
  const program = asPubkey(params.programId);
135
213
  return PublicKey.findProgramAddressSync([Buffer.from(SEED_SCHEMA), Buffer.from(params.schemaKeyHash)], program);
package/dist/rpc.js CHANGED
@@ -1,5 +1,6 @@
1
- import { Connection, Transaction, } from '@solana/web3.js';
1
+ import { Connection, } from '@solana/web3.js';
2
2
  import { normalizeClaimSimulationFailure } from './claims.js';
3
+ import { decodeSolanaTransaction, } from './transactions.js';
3
4
  export const OMEGAX_NETWORKS = {
4
5
  devnet: {
5
6
  network: 'devnet',
@@ -73,7 +74,7 @@ export function createRpcClient(connection) {
73
74
  async simulateSignedTx(params) {
74
75
  let tx;
75
76
  try {
76
- tx = Transaction.from(Buffer.from(params.signedTxBase64, 'base64'));
77
+ tx = decodeSolanaTransaction(params.signedTxBase64);
77
78
  }
78
79
  catch (error) {
79
80
  return {
@@ -0,0 +1,10 @@
1
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
2
+ export type SolanaTransaction = Transaction | VersionedTransaction;
3
+ export declare function decodeSolanaTransaction(input: string | Uint8Array | Buffer): SolanaTransaction;
4
+ export declare function serializeSolanaTransaction(transaction: SolanaTransaction): Buffer;
5
+ export declare function serializeSolanaTransactionBase64(transaction: SolanaTransaction): string;
6
+ export declare function solanaTransactionMessageBytes(transaction: SolanaTransaction): Uint8Array;
7
+ export declare function solanaTransactionMessageBase64(input: SolanaTransaction | string | Uint8Array | Buffer): string;
8
+ export declare function solanaTransactionRequiredSigner(transaction: SolanaTransaction): string | null;
9
+ export declare function solanaTransactionFirstSignature(transaction: SolanaTransaction): string | null;
10
+ export declare function solanaTransactionSignerSignature(transaction: SolanaTransaction, signer: string): Uint8Array | null;
@@ -0,0 +1,104 @@
1
+ import bs58 from 'bs58';
2
+ import { Transaction, VersionedTransaction, } from '@solana/web3.js';
3
+ function decodeShortVecLength(bytes, offset = 0) {
4
+ let length = 0;
5
+ let size = 0;
6
+ let cursor = offset;
7
+ while (cursor < bytes.length) {
8
+ const value = bytes[cursor] ?? 0;
9
+ length |= (value & 0x7f) << (size * 7);
10
+ size += 1;
11
+ cursor += 1;
12
+ if ((value & 0x80) === 0) {
13
+ return { length, bytesRead: size };
14
+ }
15
+ }
16
+ throw new Error('invalid shortvec length');
17
+ }
18
+ function versionedStaticAccountKeys(transaction) {
19
+ const message = transaction.message;
20
+ return (message?.staticAccountKeys ??
21
+ message?.getAccountKeys?.().staticAccountKeys ??
22
+ []);
23
+ }
24
+ function signatureIsPresent(signature) {
25
+ if (!signature || signature.length === 0)
26
+ return false;
27
+ return signature.some((value) => value !== 0);
28
+ }
29
+ export function decodeSolanaTransaction(input) {
30
+ const bytes = typeof input === 'string' ? Buffer.from(input, 'base64') : Buffer.from(input);
31
+ const { length: signatureCount, bytesRead } = decodeShortVecLength(bytes);
32
+ const messageOffset = bytesRead + signatureCount * 64;
33
+ if (messageOffset >= bytes.length) {
34
+ throw new Error('invalid serialized transaction');
35
+ }
36
+ const messagePrefix = bytes[messageOffset] ?? 0;
37
+ if ((messagePrefix & 0x80) !== 0) {
38
+ return VersionedTransaction.deserialize(bytes);
39
+ }
40
+ return Transaction.from(bytes);
41
+ }
42
+ export function serializeSolanaTransaction(transaction) {
43
+ if (transaction instanceof Transaction) {
44
+ return transaction.serialize({
45
+ requireAllSignatures: false,
46
+ verifySignatures: false,
47
+ });
48
+ }
49
+ return Buffer.from(transaction.serialize());
50
+ }
51
+ export function serializeSolanaTransactionBase64(transaction) {
52
+ return serializeSolanaTransaction(transaction).toString('base64');
53
+ }
54
+ export function solanaTransactionMessageBytes(transaction) {
55
+ if (transaction instanceof Transaction) {
56
+ return transaction.serializeMessage();
57
+ }
58
+ return transaction.message.serialize();
59
+ }
60
+ export function solanaTransactionMessageBase64(input) {
61
+ const transaction = typeof input === 'string' || input instanceof Uint8Array || Buffer.isBuffer(input)
62
+ ? decodeSolanaTransaction(input)
63
+ : input;
64
+ return Buffer.from(solanaTransactionMessageBytes(transaction)).toString('base64');
65
+ }
66
+ export function solanaTransactionRequiredSigner(transaction) {
67
+ if (transaction instanceof Transaction) {
68
+ return transaction.feePayer?.toBase58() ?? null;
69
+ }
70
+ const accountKeys = versionedStaticAccountKeys(transaction);
71
+ return accountKeys[0]?.toBase58() ?? null;
72
+ }
73
+ export function solanaTransactionFirstSignature(transaction) {
74
+ if (transaction instanceof Transaction) {
75
+ if (transaction.signatures.length === 0)
76
+ return null;
77
+ const first = transaction.signatures[0];
78
+ if (!signatureIsPresent(first?.signature))
79
+ return null;
80
+ return bs58.encode(first.signature);
81
+ }
82
+ const first = transaction.signatures[0];
83
+ if (!signatureIsPresent(first))
84
+ return null;
85
+ return bs58.encode(first);
86
+ }
87
+ export function solanaTransactionSignerSignature(transaction, signer) {
88
+ if (transaction instanceof Transaction) {
89
+ const entry = transaction.signatures.find((candidate) => candidate.publicKey.toBase58() === signer);
90
+ return signatureIsPresent(entry?.signature) ? entry?.signature : null;
91
+ }
92
+ const accountKeys = versionedStaticAccountKeys(transaction);
93
+ const signerIndex = accountKeys.findIndex((candidate) => candidate.toBase58() === signer);
94
+ if (signerIndex < 0)
95
+ return null;
96
+ const header = transaction.message
97
+ .header;
98
+ const requiredSignerCount = header?.numRequiredSignatures ?? 0;
99
+ if (signerIndex >= requiredSignerCount) {
100
+ return null;
101
+ }
102
+ const signature = transaction.signatures[signerIndex];
103
+ return signatureIsPresent(signature) ? signature : null;
104
+ }