@omegax/protocol-sdk 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +175 -0
- package/dist/claims.d.ts +10 -0
- package/dist/claims.js +361 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/oracle.d.ts +22 -0
- package/dist/oracle.js +82 -0
- package/dist/protocol.d.ts +9 -0
- package/dist/protocol.js +3320 -0
- package/dist/protocol_seeds.d.ts +175 -0
- package/dist/protocol_seeds.js +246 -0
- package/dist/rpc.d.ts +4 -0
- package/dist/rpc.js +109 -0
- package/dist/types.d.ts +1122 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +98 -0
- package/package.json +97 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export declare const SEED_CONFIG = "config";
|
|
3
|
+
export declare const SEED_POOL = "pool";
|
|
4
|
+
export declare const SEED_ORACLE = "oracle";
|
|
5
|
+
export declare const SEED_ORACLE_PROFILE = "oracle_profile";
|
|
6
|
+
export declare const SEED_POOL_ORACLE = "pool_oracle";
|
|
7
|
+
export declare const SEED_MEMBERSHIP = "membership";
|
|
8
|
+
export declare const SEED_CYCLE = "cycle";
|
|
9
|
+
export declare const SEED_CYCLE_WINDOW = "cycle_window";
|
|
10
|
+
export declare const SEED_REPLAY = "replay";
|
|
11
|
+
export declare const SEED_CLAIM = "claim";
|
|
12
|
+
export declare const SEED_CONFIG_V2 = "config_v2";
|
|
13
|
+
export declare const SEED_ORACLE_STAKE = "oracle_stake";
|
|
14
|
+
export declare const SEED_POOL_ORACLE_POLICY = "pool_oracle_policy";
|
|
15
|
+
export declare const SEED_POOL_TERMS = "pool_terms";
|
|
16
|
+
export declare const SEED_POOL_ASSET_VAULT = "pool_asset_vault";
|
|
17
|
+
export declare const SEED_SCHEMA = "schema";
|
|
18
|
+
export declare const SEED_POOL_RULE = "pool_rule";
|
|
19
|
+
export declare const SEED_INVITE_ISSUER = "invite_issuer";
|
|
20
|
+
export declare const SEED_ENROLLMENT_REPLAY = "enrollment_replay";
|
|
21
|
+
export declare const SEED_ATTESTATION_VOTE = "attestation_vote";
|
|
22
|
+
export declare const SEED_OUTCOME_AGGREGATE = "outcome_agg";
|
|
23
|
+
export declare const SEED_CLAIM_DELEGATE = "claim_delegate";
|
|
24
|
+
export declare const SEED_CLAIM_V2 = "claim_v2";
|
|
25
|
+
export declare const SEED_COVERAGE_POLICY = "coverage_policy";
|
|
26
|
+
export declare const SEED_COVERAGE_NFT = "coverage_nft";
|
|
27
|
+
export declare const SEED_COVERAGE_PRODUCT = "coverage_product";
|
|
28
|
+
export declare const SEED_PREMIUM_LEDGER = "premium_ledger";
|
|
29
|
+
export declare const SEED_PREMIUM_REPLAY = "premium_replay";
|
|
30
|
+
export declare const SEED_COVERAGE_CLAIM = "coverage_claim";
|
|
31
|
+
export declare const ZERO_PUBKEY = "11111111111111111111111111111111";
|
|
32
|
+
export declare function asPubkey(value: string | PublicKey): PublicKey;
|
|
33
|
+
export declare function deriveConfigPda(programId: PublicKey): [PublicKey, number];
|
|
34
|
+
export declare function derivePoolPda(params: {
|
|
35
|
+
programId: string | PublicKey;
|
|
36
|
+
authority: string | PublicKey;
|
|
37
|
+
poolId: string;
|
|
38
|
+
}): [PublicKey, number];
|
|
39
|
+
export declare function deriveOraclePda(params: {
|
|
40
|
+
programId: string | PublicKey;
|
|
41
|
+
oracle: string | PublicKey;
|
|
42
|
+
}): [PublicKey, number];
|
|
43
|
+
export declare function deriveOracleProfilePda(params: {
|
|
44
|
+
programId: string | PublicKey;
|
|
45
|
+
oracle: string | PublicKey;
|
|
46
|
+
}): [PublicKey, number];
|
|
47
|
+
export declare function derivePoolOraclePda(params: {
|
|
48
|
+
programId: string | PublicKey;
|
|
49
|
+
poolAddress: string | PublicKey;
|
|
50
|
+
oracle: string | PublicKey;
|
|
51
|
+
}): [PublicKey, number];
|
|
52
|
+
export declare function deriveMembershipPda(params: {
|
|
53
|
+
programId: string | PublicKey;
|
|
54
|
+
poolAddress: string | PublicKey;
|
|
55
|
+
member: string | PublicKey;
|
|
56
|
+
}): [PublicKey, number];
|
|
57
|
+
export declare function deriveCycleOutcomePda(params: {
|
|
58
|
+
programId: string | PublicKey;
|
|
59
|
+
poolAddress: string | PublicKey;
|
|
60
|
+
member: string | PublicKey;
|
|
61
|
+
cycleHash: Uint8Array;
|
|
62
|
+
}): [PublicKey, number];
|
|
63
|
+
export declare function deriveCycleWindowPda(params: {
|
|
64
|
+
programId: string | PublicKey;
|
|
65
|
+
poolAddress: string | PublicKey;
|
|
66
|
+
cycleHash: Uint8Array;
|
|
67
|
+
}): [PublicKey, number];
|
|
68
|
+
export declare function deriveReplayPda(params: {
|
|
69
|
+
programId: string | PublicKey;
|
|
70
|
+
poolAddress: string | PublicKey;
|
|
71
|
+
replayHash: Uint8Array;
|
|
72
|
+
}): [PublicKey, number];
|
|
73
|
+
export declare function deriveClaimPda(params: {
|
|
74
|
+
programId: string | PublicKey;
|
|
75
|
+
poolAddress: string | PublicKey;
|
|
76
|
+
member: string | PublicKey;
|
|
77
|
+
cycleHash: Uint8Array;
|
|
78
|
+
}): [PublicKey, number];
|
|
79
|
+
export declare function deriveConfigV2Pda(programId: string | PublicKey): [PublicKey, number];
|
|
80
|
+
export declare function deriveOracleStakePda(params: {
|
|
81
|
+
programId: string | PublicKey;
|
|
82
|
+
oracle: string | PublicKey;
|
|
83
|
+
staker: string | PublicKey;
|
|
84
|
+
}): [PublicKey, number];
|
|
85
|
+
export declare function derivePoolOraclePolicyPda(params: {
|
|
86
|
+
programId: string | PublicKey;
|
|
87
|
+
poolAddress: string | PublicKey;
|
|
88
|
+
}): [PublicKey, number];
|
|
89
|
+
export declare function derivePoolTermsPda(params: {
|
|
90
|
+
programId: string | PublicKey;
|
|
91
|
+
poolAddress: string | PublicKey;
|
|
92
|
+
}): [PublicKey, number];
|
|
93
|
+
export declare function derivePoolAssetVaultPda(params: {
|
|
94
|
+
programId: string | PublicKey;
|
|
95
|
+
poolAddress: string | PublicKey;
|
|
96
|
+
payoutMint: string | PublicKey;
|
|
97
|
+
}): [PublicKey, number];
|
|
98
|
+
export declare function deriveSchemaPda(params: {
|
|
99
|
+
programId: string | PublicKey;
|
|
100
|
+
schemaKeyHash: Uint8Array;
|
|
101
|
+
}): [PublicKey, number];
|
|
102
|
+
export declare function derivePoolRulePda(params: {
|
|
103
|
+
programId: string | PublicKey;
|
|
104
|
+
poolAddress: string | PublicKey;
|
|
105
|
+
ruleHash: Uint8Array;
|
|
106
|
+
}): [PublicKey, number];
|
|
107
|
+
export declare function deriveInviteIssuerPda(params: {
|
|
108
|
+
programId: string | PublicKey;
|
|
109
|
+
issuer: string | PublicKey;
|
|
110
|
+
}): [PublicKey, number];
|
|
111
|
+
export declare function deriveEnrollmentReplayPda(params: {
|
|
112
|
+
programId: string | PublicKey;
|
|
113
|
+
poolAddress: string | PublicKey;
|
|
114
|
+
member: string | PublicKey;
|
|
115
|
+
nonceHash: Uint8Array;
|
|
116
|
+
}): [PublicKey, number];
|
|
117
|
+
export declare function deriveAttestationVotePda(params: {
|
|
118
|
+
programId: string | PublicKey;
|
|
119
|
+
poolAddress: string | PublicKey;
|
|
120
|
+
member: string | PublicKey;
|
|
121
|
+
cycleHash: Uint8Array;
|
|
122
|
+
ruleHash: Uint8Array;
|
|
123
|
+
oracle: string | PublicKey;
|
|
124
|
+
}): [PublicKey, number];
|
|
125
|
+
export declare function deriveClaimDelegatePda(params: {
|
|
126
|
+
programId: string | PublicKey;
|
|
127
|
+
poolAddress: string | PublicKey;
|
|
128
|
+
member: string | PublicKey;
|
|
129
|
+
}): [PublicKey, number];
|
|
130
|
+
export declare function deriveClaimV2Pda(params: {
|
|
131
|
+
programId: string | PublicKey;
|
|
132
|
+
poolAddress: string | PublicKey;
|
|
133
|
+
member: string | PublicKey;
|
|
134
|
+
cycleHash: Uint8Array;
|
|
135
|
+
ruleHash: Uint8Array;
|
|
136
|
+
}): [PublicKey, number];
|
|
137
|
+
export declare function deriveOutcomeAggregatePda(params: {
|
|
138
|
+
programId: string | PublicKey;
|
|
139
|
+
poolAddress: string | PublicKey;
|
|
140
|
+
member: string | PublicKey;
|
|
141
|
+
cycleHash: Uint8Array;
|
|
142
|
+
ruleHash: Uint8Array;
|
|
143
|
+
}): [PublicKey, number];
|
|
144
|
+
export declare function deriveCoveragePolicyPda(params: {
|
|
145
|
+
programId: string | PublicKey;
|
|
146
|
+
poolAddress: string | PublicKey;
|
|
147
|
+
member: string | PublicKey;
|
|
148
|
+
}): [PublicKey, number];
|
|
149
|
+
export declare function deriveCoverageProductPda(params: {
|
|
150
|
+
programId: string | PublicKey;
|
|
151
|
+
poolAddress: string | PublicKey;
|
|
152
|
+
productIdHash: Uint8Array;
|
|
153
|
+
}): [PublicKey, number];
|
|
154
|
+
export declare function deriveCoverageNftPda(params: {
|
|
155
|
+
programId: string | PublicKey;
|
|
156
|
+
poolAddress: string | PublicKey;
|
|
157
|
+
member: string | PublicKey;
|
|
158
|
+
}): [PublicKey, number];
|
|
159
|
+
export declare function derivePremiumLedgerPda(params: {
|
|
160
|
+
programId: string | PublicKey;
|
|
161
|
+
poolAddress: string | PublicKey;
|
|
162
|
+
member: string | PublicKey;
|
|
163
|
+
}): [PublicKey, number];
|
|
164
|
+
export declare function derivePremiumReplayPda(params: {
|
|
165
|
+
programId: string | PublicKey;
|
|
166
|
+
poolAddress: string | PublicKey;
|
|
167
|
+
member: string | PublicKey;
|
|
168
|
+
replayHash: Uint8Array;
|
|
169
|
+
}): [PublicKey, number];
|
|
170
|
+
export declare function deriveCoverageClaimPda(params: {
|
|
171
|
+
programId: string | PublicKey;
|
|
172
|
+
poolAddress: string | PublicKey;
|
|
173
|
+
member: string | PublicKey;
|
|
174
|
+
intentHash: Uint8Array;
|
|
175
|
+
}): [PublicKey, number];
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { PublicKey, } from '@solana/web3.js';
|
|
2
|
+
export const SEED_CONFIG = 'config';
|
|
3
|
+
export const SEED_POOL = 'pool';
|
|
4
|
+
export const SEED_ORACLE = 'oracle';
|
|
5
|
+
export const SEED_ORACLE_PROFILE = 'oracle_profile';
|
|
6
|
+
export const SEED_POOL_ORACLE = 'pool_oracle';
|
|
7
|
+
export const SEED_MEMBERSHIP = 'membership';
|
|
8
|
+
export const SEED_CYCLE = 'cycle';
|
|
9
|
+
export const SEED_CYCLE_WINDOW = 'cycle_window';
|
|
10
|
+
export const SEED_REPLAY = 'replay';
|
|
11
|
+
export const SEED_CLAIM = 'claim';
|
|
12
|
+
export const SEED_CONFIG_V2 = 'config_v2';
|
|
13
|
+
export const SEED_ORACLE_STAKE = 'oracle_stake';
|
|
14
|
+
export const SEED_POOL_ORACLE_POLICY = 'pool_oracle_policy';
|
|
15
|
+
export const SEED_POOL_TERMS = 'pool_terms';
|
|
16
|
+
export const SEED_POOL_ASSET_VAULT = 'pool_asset_vault';
|
|
17
|
+
export const SEED_SCHEMA = 'schema';
|
|
18
|
+
export const SEED_POOL_RULE = 'pool_rule';
|
|
19
|
+
export const SEED_INVITE_ISSUER = 'invite_issuer';
|
|
20
|
+
export const SEED_ENROLLMENT_REPLAY = 'enrollment_replay';
|
|
21
|
+
export const SEED_ATTESTATION_VOTE = 'attestation_vote';
|
|
22
|
+
export const SEED_OUTCOME_AGGREGATE = 'outcome_agg';
|
|
23
|
+
export const SEED_CLAIM_DELEGATE = 'claim_delegate';
|
|
24
|
+
export const SEED_CLAIM_V2 = 'claim_v2';
|
|
25
|
+
export const SEED_COVERAGE_POLICY = 'coverage_policy';
|
|
26
|
+
export const SEED_COVERAGE_NFT = 'coverage_nft';
|
|
27
|
+
export const SEED_COVERAGE_PRODUCT = 'coverage_product';
|
|
28
|
+
export const SEED_PREMIUM_LEDGER = 'premium_ledger';
|
|
29
|
+
export const SEED_PREMIUM_REPLAY = 'premium_replay';
|
|
30
|
+
export const SEED_COVERAGE_CLAIM = 'coverage_claim';
|
|
31
|
+
export const ZERO_PUBKEY = '11111111111111111111111111111111';
|
|
32
|
+
export function asPubkey(value) {
|
|
33
|
+
if (value instanceof PublicKey)
|
|
34
|
+
return value;
|
|
35
|
+
return new PublicKey(value);
|
|
36
|
+
}
|
|
37
|
+
export function deriveConfigPda(programId) {
|
|
38
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_CONFIG)], programId);
|
|
39
|
+
}
|
|
40
|
+
export function derivePoolPda(params) {
|
|
41
|
+
const program = asPubkey(params.programId);
|
|
42
|
+
const authority = asPubkey(params.authority);
|
|
43
|
+
return PublicKey.findProgramAddressSync([
|
|
44
|
+
Buffer.from(SEED_POOL),
|
|
45
|
+
authority.toBuffer(),
|
|
46
|
+
Buffer.from(params.poolId, 'utf8'),
|
|
47
|
+
], program);
|
|
48
|
+
}
|
|
49
|
+
export function deriveOraclePda(params) {
|
|
50
|
+
const program = asPubkey(params.programId);
|
|
51
|
+
const oracle = asPubkey(params.oracle);
|
|
52
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_ORACLE), oracle.toBuffer()], program);
|
|
53
|
+
}
|
|
54
|
+
export function deriveOracleProfilePda(params) {
|
|
55
|
+
const program = asPubkey(params.programId);
|
|
56
|
+
const oracle = asPubkey(params.oracle);
|
|
57
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_ORACLE_PROFILE), oracle.toBuffer()], program);
|
|
58
|
+
}
|
|
59
|
+
export function derivePoolOraclePda(params) {
|
|
60
|
+
const program = asPubkey(params.programId);
|
|
61
|
+
const pool = asPubkey(params.poolAddress);
|
|
62
|
+
const oracle = asPubkey(params.oracle);
|
|
63
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_ORACLE), pool.toBuffer(), oracle.toBuffer()], program);
|
|
64
|
+
}
|
|
65
|
+
export function deriveMembershipPda(params) {
|
|
66
|
+
const program = asPubkey(params.programId);
|
|
67
|
+
const pool = asPubkey(params.poolAddress);
|
|
68
|
+
const member = asPubkey(params.member);
|
|
69
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_MEMBERSHIP), pool.toBuffer(), member.toBuffer()], program);
|
|
70
|
+
}
|
|
71
|
+
export function deriveCycleOutcomePda(params) {
|
|
72
|
+
const program = asPubkey(params.programId);
|
|
73
|
+
const pool = asPubkey(params.poolAddress);
|
|
74
|
+
const member = asPubkey(params.member);
|
|
75
|
+
return PublicKey.findProgramAddressSync([
|
|
76
|
+
Buffer.from(SEED_CYCLE),
|
|
77
|
+
pool.toBuffer(),
|
|
78
|
+
member.toBuffer(),
|
|
79
|
+
Buffer.from(params.cycleHash),
|
|
80
|
+
], program);
|
|
81
|
+
}
|
|
82
|
+
export function deriveCycleWindowPda(params) {
|
|
83
|
+
const program = asPubkey(params.programId);
|
|
84
|
+
const pool = asPubkey(params.poolAddress);
|
|
85
|
+
return PublicKey.findProgramAddressSync([
|
|
86
|
+
Buffer.from(SEED_CYCLE_WINDOW),
|
|
87
|
+
pool.toBuffer(),
|
|
88
|
+
Buffer.from(params.cycleHash),
|
|
89
|
+
], program);
|
|
90
|
+
}
|
|
91
|
+
export function deriveReplayPda(params) {
|
|
92
|
+
const program = asPubkey(params.programId);
|
|
93
|
+
const pool = asPubkey(params.poolAddress);
|
|
94
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_REPLAY), pool.toBuffer(), Buffer.from(params.replayHash)], program);
|
|
95
|
+
}
|
|
96
|
+
export function deriveClaimPda(params) {
|
|
97
|
+
const program = asPubkey(params.programId);
|
|
98
|
+
const pool = asPubkey(params.poolAddress);
|
|
99
|
+
const member = asPubkey(params.member);
|
|
100
|
+
return PublicKey.findProgramAddressSync([
|
|
101
|
+
Buffer.from(SEED_CLAIM),
|
|
102
|
+
pool.toBuffer(),
|
|
103
|
+
member.toBuffer(),
|
|
104
|
+
Buffer.from(params.cycleHash),
|
|
105
|
+
], program);
|
|
106
|
+
}
|
|
107
|
+
export function deriveConfigV2Pda(programId) {
|
|
108
|
+
const program = asPubkey(programId);
|
|
109
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_CONFIG_V2)], program);
|
|
110
|
+
}
|
|
111
|
+
export function deriveOracleStakePda(params) {
|
|
112
|
+
const program = asPubkey(params.programId);
|
|
113
|
+
const oracle = asPubkey(params.oracle);
|
|
114
|
+
const staker = asPubkey(params.staker);
|
|
115
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_ORACLE_STAKE), oracle.toBuffer(), staker.toBuffer()], program);
|
|
116
|
+
}
|
|
117
|
+
export function derivePoolOraclePolicyPda(params) {
|
|
118
|
+
const program = asPubkey(params.programId);
|
|
119
|
+
const pool = asPubkey(params.poolAddress);
|
|
120
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_ORACLE_POLICY), pool.toBuffer()], program);
|
|
121
|
+
}
|
|
122
|
+
export function derivePoolTermsPda(params) {
|
|
123
|
+
const program = asPubkey(params.programId);
|
|
124
|
+
const pool = asPubkey(params.poolAddress);
|
|
125
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_TERMS), pool.toBuffer()], program);
|
|
126
|
+
}
|
|
127
|
+
export function derivePoolAssetVaultPda(params) {
|
|
128
|
+
const program = asPubkey(params.programId);
|
|
129
|
+
const pool = asPubkey(params.poolAddress);
|
|
130
|
+
const mint = asPubkey(params.payoutMint);
|
|
131
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_ASSET_VAULT), pool.toBuffer(), mint.toBuffer()], program);
|
|
132
|
+
}
|
|
133
|
+
export function deriveSchemaPda(params) {
|
|
134
|
+
const program = asPubkey(params.programId);
|
|
135
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_SCHEMA), Buffer.from(params.schemaKeyHash)], program);
|
|
136
|
+
}
|
|
137
|
+
export function derivePoolRulePda(params) {
|
|
138
|
+
const program = asPubkey(params.programId);
|
|
139
|
+
const pool = asPubkey(params.poolAddress);
|
|
140
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_POOL_RULE), pool.toBuffer(), Buffer.from(params.ruleHash)], program);
|
|
141
|
+
}
|
|
142
|
+
export function deriveInviteIssuerPda(params) {
|
|
143
|
+
const program = asPubkey(params.programId);
|
|
144
|
+
const issuer = asPubkey(params.issuer);
|
|
145
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_INVITE_ISSUER), issuer.toBuffer()], program);
|
|
146
|
+
}
|
|
147
|
+
export function deriveEnrollmentReplayPda(params) {
|
|
148
|
+
const program = asPubkey(params.programId);
|
|
149
|
+
const pool = asPubkey(params.poolAddress);
|
|
150
|
+
const member = asPubkey(params.member);
|
|
151
|
+
return PublicKey.findProgramAddressSync([
|
|
152
|
+
Buffer.from(SEED_ENROLLMENT_REPLAY),
|
|
153
|
+
pool.toBuffer(),
|
|
154
|
+
member.toBuffer(),
|
|
155
|
+
Buffer.from(params.nonceHash),
|
|
156
|
+
], program);
|
|
157
|
+
}
|
|
158
|
+
export function deriveAttestationVotePda(params) {
|
|
159
|
+
const program = asPubkey(params.programId);
|
|
160
|
+
const pool = asPubkey(params.poolAddress);
|
|
161
|
+
const member = asPubkey(params.member);
|
|
162
|
+
const oracle = asPubkey(params.oracle);
|
|
163
|
+
return PublicKey.findProgramAddressSync([
|
|
164
|
+
Buffer.from(SEED_ATTESTATION_VOTE),
|
|
165
|
+
pool.toBuffer(),
|
|
166
|
+
member.toBuffer(),
|
|
167
|
+
Buffer.from(params.cycleHash),
|
|
168
|
+
Buffer.from(params.ruleHash),
|
|
169
|
+
oracle.toBuffer(),
|
|
170
|
+
], program);
|
|
171
|
+
}
|
|
172
|
+
export function deriveClaimDelegatePda(params) {
|
|
173
|
+
const program = asPubkey(params.programId);
|
|
174
|
+
const pool = asPubkey(params.poolAddress);
|
|
175
|
+
const member = asPubkey(params.member);
|
|
176
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_CLAIM_DELEGATE), pool.toBuffer(), member.toBuffer()], program);
|
|
177
|
+
}
|
|
178
|
+
export function deriveClaimV2Pda(params) {
|
|
179
|
+
const program = asPubkey(params.programId);
|
|
180
|
+
const pool = asPubkey(params.poolAddress);
|
|
181
|
+
const member = asPubkey(params.member);
|
|
182
|
+
return PublicKey.findProgramAddressSync([
|
|
183
|
+
Buffer.from(SEED_CLAIM_V2),
|
|
184
|
+
pool.toBuffer(),
|
|
185
|
+
member.toBuffer(),
|
|
186
|
+
Buffer.from(params.cycleHash),
|
|
187
|
+
Buffer.from(params.ruleHash),
|
|
188
|
+
], program);
|
|
189
|
+
}
|
|
190
|
+
export function deriveOutcomeAggregatePda(params) {
|
|
191
|
+
const program = asPubkey(params.programId);
|
|
192
|
+
const pool = asPubkey(params.poolAddress);
|
|
193
|
+
const member = asPubkey(params.member);
|
|
194
|
+
return PublicKey.findProgramAddressSync([
|
|
195
|
+
Buffer.from(SEED_OUTCOME_AGGREGATE),
|
|
196
|
+
pool.toBuffer(),
|
|
197
|
+
member.toBuffer(),
|
|
198
|
+
Buffer.from(params.cycleHash),
|
|
199
|
+
Buffer.from(params.ruleHash),
|
|
200
|
+
], program);
|
|
201
|
+
}
|
|
202
|
+
export function deriveCoveragePolicyPda(params) {
|
|
203
|
+
const program = asPubkey(params.programId);
|
|
204
|
+
const pool = asPubkey(params.poolAddress);
|
|
205
|
+
const member = asPubkey(params.member);
|
|
206
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_COVERAGE_POLICY), pool.toBuffer(), member.toBuffer()], program);
|
|
207
|
+
}
|
|
208
|
+
export function deriveCoverageProductPda(params) {
|
|
209
|
+
const program = asPubkey(params.programId);
|
|
210
|
+
const pool = asPubkey(params.poolAddress);
|
|
211
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_COVERAGE_PRODUCT), pool.toBuffer(), Buffer.from(params.productIdHash)], program);
|
|
212
|
+
}
|
|
213
|
+
export function deriveCoverageNftPda(params) {
|
|
214
|
+
const program = asPubkey(params.programId);
|
|
215
|
+
const pool = asPubkey(params.poolAddress);
|
|
216
|
+
const member = asPubkey(params.member);
|
|
217
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_COVERAGE_NFT), pool.toBuffer(), member.toBuffer()], program);
|
|
218
|
+
}
|
|
219
|
+
export function derivePremiumLedgerPda(params) {
|
|
220
|
+
const program = asPubkey(params.programId);
|
|
221
|
+
const pool = asPubkey(params.poolAddress);
|
|
222
|
+
const member = asPubkey(params.member);
|
|
223
|
+
return PublicKey.findProgramAddressSync([Buffer.from(SEED_PREMIUM_LEDGER), pool.toBuffer(), member.toBuffer()], program);
|
|
224
|
+
}
|
|
225
|
+
export function derivePremiumReplayPda(params) {
|
|
226
|
+
const program = asPubkey(params.programId);
|
|
227
|
+
const pool = asPubkey(params.poolAddress);
|
|
228
|
+
const member = asPubkey(params.member);
|
|
229
|
+
return PublicKey.findProgramAddressSync([
|
|
230
|
+
Buffer.from(SEED_PREMIUM_REPLAY),
|
|
231
|
+
pool.toBuffer(),
|
|
232
|
+
member.toBuffer(),
|
|
233
|
+
Buffer.from(params.replayHash),
|
|
234
|
+
], program);
|
|
235
|
+
}
|
|
236
|
+
export function deriveCoverageClaimPda(params) {
|
|
237
|
+
const program = asPubkey(params.programId);
|
|
238
|
+
const pool = asPubkey(params.poolAddress);
|
|
239
|
+
const member = asPubkey(params.member);
|
|
240
|
+
return PublicKey.findProgramAddressSync([
|
|
241
|
+
Buffer.from(SEED_COVERAGE_CLAIM),
|
|
242
|
+
pool.toBuffer(),
|
|
243
|
+
member.toBuffer(),
|
|
244
|
+
Buffer.from(params.intentHash),
|
|
245
|
+
], program);
|
|
246
|
+
}
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Connection, type Commitment } from '@solana/web3.js';
|
|
2
|
+
import type { RpcClient } from './types.js';
|
|
3
|
+
export declare function createConnection(rpcUrl: string, commitment?: Commitment): Connection;
|
|
4
|
+
export declare function createRpcClient(connection: Connection): RpcClient;
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Connection, Transaction, } from '@solana/web3.js';
|
|
2
|
+
import { normalizeClaimSimulationFailure } from './claims.js';
|
|
3
|
+
export function createConnection(rpcUrl, commitment = 'confirmed') {
|
|
4
|
+
return new Connection(rpcUrl, commitment);
|
|
5
|
+
}
|
|
6
|
+
export function createRpcClient(connection) {
|
|
7
|
+
return {
|
|
8
|
+
async getRecentBlockhash() {
|
|
9
|
+
const latest = await connection.getLatestBlockhash('confirmed');
|
|
10
|
+
return latest.blockhash;
|
|
11
|
+
},
|
|
12
|
+
async broadcastSignedTx(params) {
|
|
13
|
+
const raw = Buffer.from(params.signedTxBase64, 'base64');
|
|
14
|
+
const signature = await connection.sendRawTransaction(raw, {
|
|
15
|
+
skipPreflight: params.skipPreflight ?? false,
|
|
16
|
+
maxRetries: params.maxRetries,
|
|
17
|
+
});
|
|
18
|
+
const commitment = params.commitment ?? 'confirmed';
|
|
19
|
+
const confirmation = await connection.confirmTransaction(signature, commitment);
|
|
20
|
+
if (confirmation.value.err) {
|
|
21
|
+
return {
|
|
22
|
+
signature,
|
|
23
|
+
status: 'failed',
|
|
24
|
+
slot: confirmation.context.slot,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
signature,
|
|
29
|
+
status: commitment === 'processed' ? 'submitted' : 'confirmed',
|
|
30
|
+
slot: confirmation.context.slot,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
async simulateSignedTx(params) {
|
|
34
|
+
let tx;
|
|
35
|
+
try {
|
|
36
|
+
tx = Transaction.from(Buffer.from(params.signedTxBase64, 'base64'));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
logs: [],
|
|
42
|
+
unitsConsumed: null,
|
|
43
|
+
err: error,
|
|
44
|
+
failure: normalizeClaimSimulationFailure({ err: error, logs: [] }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const result = await connection.simulateTransaction(tx, {
|
|
48
|
+
commitment: params.commitment ?? 'confirmed',
|
|
49
|
+
replaceRecentBlockhash: params.replaceRecentBlockhash ?? true,
|
|
50
|
+
sigVerify: params.sigVerify ?? true,
|
|
51
|
+
});
|
|
52
|
+
const logs = result.value.logs ?? [];
|
|
53
|
+
const unitsConsumed = typeof result.value.unitsConsumed === 'number'
|
|
54
|
+
? result.value.unitsConsumed
|
|
55
|
+
: null;
|
|
56
|
+
if (result.value.err) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
logs,
|
|
60
|
+
unitsConsumed,
|
|
61
|
+
err: result.value.err,
|
|
62
|
+
failure: normalizeClaimSimulationFailure({
|
|
63
|
+
err: result.value.err,
|
|
64
|
+
logs,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
logs,
|
|
71
|
+
unitsConsumed,
|
|
72
|
+
err: null,
|
|
73
|
+
failure: null,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
async getSignatureStatus(params) {
|
|
77
|
+
const response = await connection.getSignatureStatuses([params.signature], {
|
|
78
|
+
searchTransactionHistory: params.searchTransactionHistory ?? true,
|
|
79
|
+
});
|
|
80
|
+
const info = response.value[0];
|
|
81
|
+
if (!info) {
|
|
82
|
+
return {
|
|
83
|
+
signature: params.signature,
|
|
84
|
+
status: 'unknown',
|
|
85
|
+
confirmations: null,
|
|
86
|
+
slot: null,
|
|
87
|
+
err: null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (info.err) {
|
|
91
|
+
return {
|
|
92
|
+
signature: params.signature,
|
|
93
|
+
status: 'failed',
|
|
94
|
+
confirmations: info.confirmations ?? null,
|
|
95
|
+
slot: info.slot ?? null,
|
|
96
|
+
err: info.err,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const confirmationStatus = info.confirmationStatus ?? 'processed';
|
|
100
|
+
return {
|
|
101
|
+
signature: params.signature,
|
|
102
|
+
status: confirmationStatus,
|
|
103
|
+
confirmations: info.confirmations ?? null,
|
|
104
|
+
slot: info.slot ?? null,
|
|
105
|
+
err: null,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|