@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
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,3320 @@
|
|
|
1
|
+
import { PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
|
|
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';
|
|
4
|
+
const MAX_POOL_ID_SEED_BYTES = 32;
|
|
5
|
+
const MAX_ORACLE_SUPPORTED_SCHEMAS = 16;
|
|
6
|
+
export const PROTOCOL_PROGRAM_ID = 'Bn6eixac1QEEVErGBvBjxAd6pgB9e2q4XHvAkinQ5y1B';
|
|
7
|
+
const IX_INITIALIZE_PROTOCOL = anchorDiscriminator('global', 'initialize_protocol');
|
|
8
|
+
const IX_SET_PROTOCOL_PAUSE = anchorDiscriminator('global', 'set_protocol_pause');
|
|
9
|
+
const IX_CREATE_POOL = anchorDiscriminator('global', 'create_pool');
|
|
10
|
+
const IX_SET_POOL_STATUS = anchorDiscriminator('global', 'set_pool_status');
|
|
11
|
+
const IX_SET_CYCLE_WINDOW = anchorDiscriminator('global', 'set_cycle_window');
|
|
12
|
+
const IX_FUND_POOL = anchorDiscriminator('global', 'fund_pool');
|
|
13
|
+
const IX_REGISTER_ORACLE = anchorDiscriminator('global', 'register_oracle');
|
|
14
|
+
const IX_REGISTER_ORACLE_V2 = anchorDiscriminator('global', 'register_oracle_v2');
|
|
15
|
+
const IX_CLAIM_ORACLE_V2 = anchorDiscriminator('global', 'claim_oracle_v2');
|
|
16
|
+
const IX_UPDATE_ORACLE_PROFILE_V2 = anchorDiscriminator('global', 'update_oracle_profile_v2');
|
|
17
|
+
const IX_SET_POOL_ORACLE = anchorDiscriminator('global', 'set_pool_oracle');
|
|
18
|
+
const IX_ENROLL_MEMBER = anchorDiscriminator('global', 'enroll_member');
|
|
19
|
+
const IX_REVOKE_MEMBER = anchorDiscriminator('global', 'revoke_member');
|
|
20
|
+
const IX_SUBMIT_OUTCOME_ATTESTATION = anchorDiscriminator('global', 'submit_outcome_attestation');
|
|
21
|
+
const IX_SUBMIT_CLAIM = anchorDiscriminator('global', 'submit_claim');
|
|
22
|
+
const IX_SUBMIT_OUTCOME_ATTESTATION_VOTE = anchorDiscriminator('global', 'submit_outcome_attestation_vote');
|
|
23
|
+
const IX_FINALIZE_CYCLE_OUTCOME = anchorDiscriminator('global', 'finalize_cycle_outcome');
|
|
24
|
+
const IX_INITIALIZE_PROTOCOL_V2 = anchorDiscriminator('global', 'initialize_protocol_v2');
|
|
25
|
+
const IX_SET_PROTOCOL_PARAMS = anchorDiscriminator('global', 'set_protocol_params');
|
|
26
|
+
const IX_ROTATE_GOVERNANCE_AUTHORITY = anchorDiscriminator('global', 'rotate_governance_authority');
|
|
27
|
+
const IX_UPDATE_ORACLE_METADATA = anchorDiscriminator('global', 'update_oracle_metadata');
|
|
28
|
+
const IX_STAKE_ORACLE = anchorDiscriminator('global', 'stake_oracle');
|
|
29
|
+
const IX_REQUEST_UNSTAKE = anchorDiscriminator('global', 'request_unstake');
|
|
30
|
+
const IX_FINALIZE_UNSTAKE = anchorDiscriminator('global', 'finalize_unstake');
|
|
31
|
+
const IX_SLASH_ORACLE = anchorDiscriminator('global', 'slash_oracle');
|
|
32
|
+
const IX_CREATE_POOL_V2 = anchorDiscriminator('global', 'create_pool_v2');
|
|
33
|
+
const IX_SET_POOL_ORACLE_POLICY = anchorDiscriminator('global', 'set_pool_oracle_policy');
|
|
34
|
+
const IX_SET_POOL_TERMS_HASH = anchorDiscriminator('global', 'set_pool_terms_hash');
|
|
35
|
+
const IX_REGISTER_OUTCOME_SCHEMA = anchorDiscriminator('global', 'register_outcome_schema');
|
|
36
|
+
const IX_VERIFY_OUTCOME_SCHEMA = anchorDiscriminator('global', 'verify_outcome_schema');
|
|
37
|
+
const IX_SET_POOL_OUTCOME_RULE = anchorDiscriminator('global', 'set_pool_outcome_rule');
|
|
38
|
+
const IX_REGISTER_INVITE_ISSUER = anchorDiscriminator('global', 'register_invite_issuer');
|
|
39
|
+
const IX_ENROLL_MEMBER_OPEN = anchorDiscriminator('global', 'enroll_member_open');
|
|
40
|
+
const IX_ENROLL_MEMBER_TOKEN_GATE = anchorDiscriminator('global', 'enroll_member_token_gate');
|
|
41
|
+
const IX_ENROLL_MEMBER_INVITE_PERMIT = anchorDiscriminator('global', 'enroll_member_invite_permit');
|
|
42
|
+
const IX_SET_CLAIM_DELEGATE = anchorDiscriminator('global', 'set_claim_delegate');
|
|
43
|
+
const IX_FUND_POOL_SOL = anchorDiscriminator('global', 'fund_pool_sol');
|
|
44
|
+
const IX_FUND_POOL_SPL = anchorDiscriminator('global', 'fund_pool_spl');
|
|
45
|
+
const IX_SUBMIT_REWARD_CLAIM = anchorDiscriminator('global', 'submit_reward_claim');
|
|
46
|
+
const IX_REGISTER_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'register_coverage_product_v2');
|
|
47
|
+
const IX_UPDATE_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'update_coverage_product_v2');
|
|
48
|
+
const IX_SUBSCRIBE_COVERAGE_PRODUCT_V2 = anchorDiscriminator('global', 'subscribe_coverage_product_v2');
|
|
49
|
+
const IX_ISSUE_COVERAGE_POLICY_FROM_PRODUCT_V2 = anchorDiscriminator('global', 'issue_coverage_policy_from_product_v2');
|
|
50
|
+
const IX_CREATE_COVERAGE_POLICY = anchorDiscriminator('global', 'create_coverage_policy');
|
|
51
|
+
const IX_MINT_POLICY_NFT = anchorDiscriminator('global', 'mint_policy_nft');
|
|
52
|
+
const IX_PAY_PREMIUM_ONCHAIN = anchorDiscriminator('global', 'pay_premium_onchain');
|
|
53
|
+
const IX_ATTEST_PREMIUM_PAID_OFFCHAIN = anchorDiscriminator('global', 'attest_premium_paid_offchain');
|
|
54
|
+
const IX_SUBMIT_COVERAGE_CLAIM = anchorDiscriminator('global', 'submit_coverage_claim');
|
|
55
|
+
const IX_SETTLE_COVERAGE_CLAIM = anchorDiscriminator('global', 'settle_coverage_claim');
|
|
56
|
+
const IX_MIGRATE_POOL_V1_TO_V2 = anchorDiscriminator('global', 'migrate_pool_v1_to_v2');
|
|
57
|
+
const IX_MIGRATE_MEMBERSHIP_V1_TO_V2 = anchorDiscriminator('global', 'migrate_membership_v1_to_v2');
|
|
58
|
+
const ACCOUNT_PROTOCOL_CONFIG = anchorDiscriminator('account', 'ProtocolConfig');
|
|
59
|
+
const ACCOUNT_POOL = anchorDiscriminator('account', 'Pool');
|
|
60
|
+
const ACCOUNT_ORACLE_REGISTRY = anchorDiscriminator('account', 'OracleRegistryEntry');
|
|
61
|
+
const ACCOUNT_ORACLE_PROFILE = anchorDiscriminator('account', 'OracleProfile');
|
|
62
|
+
const ACCOUNT_POOL_ORACLE_APPROVAL = anchorDiscriminator('account', 'PoolOracleApproval');
|
|
63
|
+
const ACCOUNT_MEMBERSHIP_RECORD = anchorDiscriminator('account', 'MembershipRecord');
|
|
64
|
+
const ACCOUNT_CYCLE_OUTCOME = anchorDiscriminator('account', 'CycleOutcomeState');
|
|
65
|
+
const ACCOUNT_CYCLE_WINDOW = anchorDiscriminator('account', 'CycleWindow');
|
|
66
|
+
const ACCOUNT_CLAIM_RECORD = anchorDiscriminator('account', 'ClaimRecord');
|
|
67
|
+
const ACCOUNT_CYCLE_OUTCOME_AGGREGATE = anchorDiscriminator('account', 'CycleOutcomeAggregate');
|
|
68
|
+
const ACCOUNT_PROTOCOL_CONFIG_V2 = anchorDiscriminator('account', 'ProtocolConfigV2');
|
|
69
|
+
const ACCOUNT_ORACLE_STAKE_POSITION = anchorDiscriminator('account', 'OracleStakePosition');
|
|
70
|
+
const ACCOUNT_POOL_ORACLE_POLICY = anchorDiscriminator('account', 'PoolOraclePolicy');
|
|
71
|
+
const ACCOUNT_POOL_TERMS = anchorDiscriminator('account', 'PoolTerms');
|
|
72
|
+
const ACCOUNT_POOL_ASSET_VAULT = anchorDiscriminator('account', 'PoolAssetVault');
|
|
73
|
+
const ACCOUNT_OUTCOME_SCHEMA = anchorDiscriminator('account', 'OutcomeSchemaRegistryEntry');
|
|
74
|
+
const ACCOUNT_POOL_OUTCOME_RULE = anchorDiscriminator('account', 'PoolOutcomeRule');
|
|
75
|
+
const ACCOUNT_INVITE_ISSUER = anchorDiscriminator('account', 'InviteIssuerRegistryEntry');
|
|
76
|
+
const ACCOUNT_CLAIM_DELEGATE_AUTH = anchorDiscriminator('account', 'ClaimDelegateAuthorization');
|
|
77
|
+
const ACCOUNT_CLAIM_RECORD_V2 = anchorDiscriminator('account', 'ClaimRecordV2');
|
|
78
|
+
const ACCOUNT_COVERAGE_CLAIM_RECORD = anchorDiscriminator('account', 'CoverageClaimRecord');
|
|
79
|
+
const ACCOUNT_COVERAGE_POLICY_POSITION_NFT = anchorDiscriminator('account', 'CoveragePolicyPositionNft');
|
|
80
|
+
const ACCOUNT_COVERAGE_PRODUCT = anchorDiscriminator('account', 'CoverageProduct');
|
|
81
|
+
const ACCOUNT_ENROLLMENT_PERMIT_REPLAY = anchorDiscriminator('account', 'EnrollmentPermitReplay');
|
|
82
|
+
const ACCOUNT_ATTESTATION_VOTE = anchorDiscriminator('account', 'AttestationVote');
|
|
83
|
+
const ACCOUNT_COVERAGE_POLICY = anchorDiscriminator('account', 'CoveragePolicy');
|
|
84
|
+
const ACCOUNT_PREMIUM_LEDGER = anchorDiscriminator('account', 'PremiumLedger');
|
|
85
|
+
const ACCOUNT_PREMIUM_ATTESTATION_REPLAY = anchorDiscriminator('account', 'PremiumAttestationReplay');
|
|
86
|
+
function pubkeyFromData(buffer, offset) {
|
|
87
|
+
return new PublicKey(buffer.subarray(offset, offset + 32)).toBase58();
|
|
88
|
+
}
|
|
89
|
+
function parsePoolStatus(code) {
|
|
90
|
+
switch (code) {
|
|
91
|
+
case 0:
|
|
92
|
+
return 'draft';
|
|
93
|
+
case 1:
|
|
94
|
+
return 'active';
|
|
95
|
+
case 2:
|
|
96
|
+
return 'paused';
|
|
97
|
+
case 3:
|
|
98
|
+
return 'closed';
|
|
99
|
+
default:
|
|
100
|
+
return 'unknown';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function parseMembershipStatus(code) {
|
|
104
|
+
switch (code) {
|
|
105
|
+
case 1:
|
|
106
|
+
return 'active';
|
|
107
|
+
case 2:
|
|
108
|
+
return 'revoked';
|
|
109
|
+
default:
|
|
110
|
+
return 'unknown';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function parsePoolType(code) {
|
|
114
|
+
switch (code) {
|
|
115
|
+
case 0:
|
|
116
|
+
return 'reward';
|
|
117
|
+
case 1:
|
|
118
|
+
return 'coverage';
|
|
119
|
+
default:
|
|
120
|
+
return 'unknown';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function hasDiscriminator(data, discriminator) {
|
|
124
|
+
if (data.length < 8)
|
|
125
|
+
return false;
|
|
126
|
+
return discriminator.equals(data.subarray(0, 8));
|
|
127
|
+
}
|
|
128
|
+
function decodeProtocolConfigAccount(address, data) {
|
|
129
|
+
if (!hasDiscriminator(data, ACCOUNT_PROTOCOL_CONFIG)) {
|
|
130
|
+
throw new Error('account discriminator mismatch for ProtocolConfig');
|
|
131
|
+
}
|
|
132
|
+
let offset = 8;
|
|
133
|
+
const admin = pubkeyFromData(data, offset);
|
|
134
|
+
offset += 32;
|
|
135
|
+
const protocolFeeBps = readU16Le(data, offset);
|
|
136
|
+
offset += 2;
|
|
137
|
+
const emergencyPaused = data.readUInt8(offset) === 1;
|
|
138
|
+
offset += 1;
|
|
139
|
+
const bump = data.readUInt8(offset);
|
|
140
|
+
return {
|
|
141
|
+
address,
|
|
142
|
+
admin,
|
|
143
|
+
protocolFeeBps,
|
|
144
|
+
emergencyPaused,
|
|
145
|
+
bump,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function decodePoolAccount(address, data) {
|
|
149
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL)) {
|
|
150
|
+
throw new Error('account discriminator mismatch for Pool');
|
|
151
|
+
}
|
|
152
|
+
let offset = 8;
|
|
153
|
+
const authority = pubkeyFromData(data, offset);
|
|
154
|
+
offset += 32;
|
|
155
|
+
const poolId = readString(data, offset);
|
|
156
|
+
offset = poolId.offset;
|
|
157
|
+
const organizationRef = readString(data, offset);
|
|
158
|
+
offset = organizationRef.offset;
|
|
159
|
+
const payoutLamportsPerPass = readU64Le(data, offset);
|
|
160
|
+
offset += 8;
|
|
161
|
+
const membershipMode = data.readUInt8(offset);
|
|
162
|
+
offset += 1;
|
|
163
|
+
const tokenGateMint = pubkeyFromData(data, offset);
|
|
164
|
+
offset += 32;
|
|
165
|
+
const tokenGateMinBalance = readU64Le(data, offset);
|
|
166
|
+
offset += 8;
|
|
167
|
+
const inviteIssuer = pubkeyFromData(data, offset);
|
|
168
|
+
offset += 32;
|
|
169
|
+
const statusCode = data.readUInt8(offset);
|
|
170
|
+
offset += 1;
|
|
171
|
+
const bump = data.readUInt8(offset);
|
|
172
|
+
return {
|
|
173
|
+
address,
|
|
174
|
+
authority,
|
|
175
|
+
poolId: poolId.value,
|
|
176
|
+
organizationRef: organizationRef.value,
|
|
177
|
+
payoutLamportsPerPass,
|
|
178
|
+
membershipMode,
|
|
179
|
+
tokenGateMint,
|
|
180
|
+
tokenGateMinBalance,
|
|
181
|
+
inviteIssuer,
|
|
182
|
+
statusCode,
|
|
183
|
+
status: parsePoolStatus(statusCode),
|
|
184
|
+
bump,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function decodeOracleRegistryEntryAccount(address, data) {
|
|
188
|
+
if (!hasDiscriminator(data, ACCOUNT_ORACLE_REGISTRY)) {
|
|
189
|
+
throw new Error('account discriminator mismatch for OracleRegistryEntry');
|
|
190
|
+
}
|
|
191
|
+
let offset = 8;
|
|
192
|
+
const oracle = pubkeyFromData(data, offset);
|
|
193
|
+
offset += 32;
|
|
194
|
+
const active = data.readUInt8(offset) === 1;
|
|
195
|
+
offset += 1;
|
|
196
|
+
const bump = data.readUInt8(offset);
|
|
197
|
+
offset += 1;
|
|
198
|
+
const metadataUri = readString(data, offset).value;
|
|
199
|
+
return {
|
|
200
|
+
address,
|
|
201
|
+
oracle,
|
|
202
|
+
active,
|
|
203
|
+
bump,
|
|
204
|
+
metadataUri,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function decodeOracleProfileAccount(address, data) {
|
|
208
|
+
if (!hasDiscriminator(data, ACCOUNT_ORACLE_PROFILE)) {
|
|
209
|
+
throw new Error('account discriminator mismatch for OracleProfile');
|
|
210
|
+
}
|
|
211
|
+
let offset = 8;
|
|
212
|
+
const oracle = pubkeyFromData(data, offset);
|
|
213
|
+
offset += 32;
|
|
214
|
+
const admin = pubkeyFromData(data, offset);
|
|
215
|
+
offset += 32;
|
|
216
|
+
const oracleType = data.readUInt8(offset);
|
|
217
|
+
offset += 1;
|
|
218
|
+
const displayName = readString(data, offset);
|
|
219
|
+
offset = displayName.offset;
|
|
220
|
+
const legalName = readString(data, offset);
|
|
221
|
+
offset = legalName.offset;
|
|
222
|
+
const websiteUrl = readString(data, offset);
|
|
223
|
+
offset = websiteUrl.offset;
|
|
224
|
+
const appUrl = readString(data, offset);
|
|
225
|
+
offset = appUrl.offset;
|
|
226
|
+
const logoUri = readString(data, offset);
|
|
227
|
+
offset = logoUri.offset;
|
|
228
|
+
const webhookUrl = readString(data, offset);
|
|
229
|
+
offset = webhookUrl.offset;
|
|
230
|
+
const supportedSchemaCount = data.readUInt8(offset);
|
|
231
|
+
offset += 1;
|
|
232
|
+
const supportedSchemaKeyHashesHex = [];
|
|
233
|
+
for (let index = 0; index < 16; index += 1) {
|
|
234
|
+
const schemaHash = data.subarray(offset, offset + 32);
|
|
235
|
+
offset += 32;
|
|
236
|
+
if (index < supportedSchemaCount) {
|
|
237
|
+
supportedSchemaKeyHashesHex.push(toHex(schemaHash));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const claimed = data.readUInt8(offset) === 1;
|
|
241
|
+
offset += 1;
|
|
242
|
+
const createdAtTs = Number(readI64Le(data, offset));
|
|
243
|
+
offset += 8;
|
|
244
|
+
const updatedAtTs = Number(readI64Le(data, offset));
|
|
245
|
+
offset += 8;
|
|
246
|
+
const bump = data.readUInt8(offset);
|
|
247
|
+
return {
|
|
248
|
+
address,
|
|
249
|
+
oracle,
|
|
250
|
+
admin,
|
|
251
|
+
oracleType,
|
|
252
|
+
displayName: displayName.value,
|
|
253
|
+
legalName: legalName.value,
|
|
254
|
+
websiteUrl: websiteUrl.value,
|
|
255
|
+
appUrl: appUrl.value,
|
|
256
|
+
logoUri: logoUri.value,
|
|
257
|
+
webhookUrl: webhookUrl.value,
|
|
258
|
+
supportedSchemaCount,
|
|
259
|
+
supportedSchemaKeyHashesHex,
|
|
260
|
+
claimed,
|
|
261
|
+
createdAtTs,
|
|
262
|
+
updatedAtTs,
|
|
263
|
+
bump,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function decodePoolOracleApprovalAccount(address, data) {
|
|
267
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_APPROVAL)) {
|
|
268
|
+
throw new Error('account discriminator mismatch for PoolOracleApproval');
|
|
269
|
+
}
|
|
270
|
+
let offset = 8;
|
|
271
|
+
const pool = pubkeyFromData(data, offset);
|
|
272
|
+
offset += 32;
|
|
273
|
+
const oracle = pubkeyFromData(data, offset);
|
|
274
|
+
offset += 32;
|
|
275
|
+
const active = data.readUInt8(offset) === 1;
|
|
276
|
+
offset += 1;
|
|
277
|
+
const bump = data.readUInt8(offset);
|
|
278
|
+
return {
|
|
279
|
+
address,
|
|
280
|
+
pool,
|
|
281
|
+
oracle,
|
|
282
|
+
active,
|
|
283
|
+
bump,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function decodeMembershipRecordAccount(address, data) {
|
|
287
|
+
if (!hasDiscriminator(data, ACCOUNT_MEMBERSHIP_RECORD)) {
|
|
288
|
+
throw new Error('account discriminator mismatch for MembershipRecord');
|
|
289
|
+
}
|
|
290
|
+
let offset = 8;
|
|
291
|
+
const pool = pubkeyFromData(data, offset);
|
|
292
|
+
offset += 32;
|
|
293
|
+
const member = pubkeyFromData(data, offset);
|
|
294
|
+
offset += 32;
|
|
295
|
+
const subjectCommitment = data.subarray(offset, offset + 32);
|
|
296
|
+
offset += 32;
|
|
297
|
+
const statusCode = data.readUInt8(offset);
|
|
298
|
+
offset += 1;
|
|
299
|
+
const enrolledAt = Number(readI64Le(data, offset));
|
|
300
|
+
offset += 8;
|
|
301
|
+
const updatedAt = Number(readI64Le(data, offset));
|
|
302
|
+
offset += 8;
|
|
303
|
+
const bump = data.readUInt8(offset);
|
|
304
|
+
return {
|
|
305
|
+
address,
|
|
306
|
+
pool,
|
|
307
|
+
member,
|
|
308
|
+
subjectCommitmentHex: toHex(subjectCommitment),
|
|
309
|
+
statusCode,
|
|
310
|
+
status: parseMembershipStatus(statusCode),
|
|
311
|
+
enrolledAt,
|
|
312
|
+
updatedAt,
|
|
313
|
+
bump,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function decodeCycleOutcomeAccount(address, data) {
|
|
317
|
+
if (!hasDiscriminator(data, ACCOUNT_CYCLE_OUTCOME)) {
|
|
318
|
+
throw new Error('account discriminator mismatch for CycleOutcomeState');
|
|
319
|
+
}
|
|
320
|
+
let offset = 8;
|
|
321
|
+
const pool = pubkeyFromData(data, offset);
|
|
322
|
+
offset += 32;
|
|
323
|
+
const member = pubkeyFromData(data, offset);
|
|
324
|
+
offset += 32;
|
|
325
|
+
const cycleHash = data.subarray(offset, offset + 32);
|
|
326
|
+
offset += 32;
|
|
327
|
+
const passCount = data.readUInt32LE(offset);
|
|
328
|
+
offset += 4;
|
|
329
|
+
const attestationCount = data.readUInt32LE(offset);
|
|
330
|
+
offset += 4;
|
|
331
|
+
const latestAsOfTs = Number(readI64Le(data, offset));
|
|
332
|
+
offset += 8;
|
|
333
|
+
const claimed = data.readUInt8(offset) === 1;
|
|
334
|
+
offset += 1;
|
|
335
|
+
const bump = data.readUInt8(offset);
|
|
336
|
+
return {
|
|
337
|
+
address,
|
|
338
|
+
pool,
|
|
339
|
+
member,
|
|
340
|
+
cycleHashHex: toHex(cycleHash),
|
|
341
|
+
passCount,
|
|
342
|
+
attestationCount,
|
|
343
|
+
latestAsOfTs,
|
|
344
|
+
claimed,
|
|
345
|
+
bump,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function decodeCycleWindowAccount(address, data) {
|
|
349
|
+
if (!hasDiscriminator(data, ACCOUNT_CYCLE_WINDOW)) {
|
|
350
|
+
throw new Error('account discriminator mismatch for CycleWindow');
|
|
351
|
+
}
|
|
352
|
+
let offset = 8;
|
|
353
|
+
const pool = pubkeyFromData(data, offset);
|
|
354
|
+
offset += 32;
|
|
355
|
+
const cycleHash = data.subarray(offset, offset + 32);
|
|
356
|
+
offset += 32;
|
|
357
|
+
const authority = pubkeyFromData(data, offset);
|
|
358
|
+
offset += 32;
|
|
359
|
+
const claimOpenTs = Number(readI64Le(data, offset));
|
|
360
|
+
offset += 8;
|
|
361
|
+
const claimCloseTs = Number(readI64Le(data, offset));
|
|
362
|
+
offset += 8;
|
|
363
|
+
const bump = data.readUInt8(offset);
|
|
364
|
+
return {
|
|
365
|
+
address,
|
|
366
|
+
pool,
|
|
367
|
+
cycleHashHex: toHex(cycleHash),
|
|
368
|
+
authority,
|
|
369
|
+
claimOpenTs,
|
|
370
|
+
claimCloseTs,
|
|
371
|
+
bump,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function decodeClaimRecordAccount(address, data) {
|
|
375
|
+
if (!hasDiscriminator(data, ACCOUNT_CLAIM_RECORD)) {
|
|
376
|
+
throw new Error('account discriminator mismatch for ClaimRecord');
|
|
377
|
+
}
|
|
378
|
+
let offset = 8;
|
|
379
|
+
const pool = pubkeyFromData(data, offset);
|
|
380
|
+
offset += 32;
|
|
381
|
+
const member = pubkeyFromData(data, offset);
|
|
382
|
+
offset += 32;
|
|
383
|
+
const cycleHash = data.subarray(offset, offset + 32);
|
|
384
|
+
offset += 32;
|
|
385
|
+
const claimIntent = data.subarray(offset, offset + 32);
|
|
386
|
+
offset += 32;
|
|
387
|
+
const payoutLamports = readU64Le(data, offset);
|
|
388
|
+
offset += 8;
|
|
389
|
+
const passCount = data.readUInt32LE(offset);
|
|
390
|
+
offset += 4;
|
|
391
|
+
const submittedAt = Number(readI64Le(data, offset));
|
|
392
|
+
offset += 8;
|
|
393
|
+
const bump = data.readUInt8(offset);
|
|
394
|
+
return {
|
|
395
|
+
address,
|
|
396
|
+
pool,
|
|
397
|
+
member,
|
|
398
|
+
cycleHashHex: toHex(cycleHash),
|
|
399
|
+
claimIntentHex: toHex(claimIntent),
|
|
400
|
+
payoutLamports,
|
|
401
|
+
passCount,
|
|
402
|
+
submittedAt,
|
|
403
|
+
bump,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function decodeCycleOutcomeAggregateAccount(address, data) {
|
|
407
|
+
if (!hasDiscriminator(data, ACCOUNT_CYCLE_OUTCOME_AGGREGATE)) {
|
|
408
|
+
throw new Error('account discriminator mismatch for CycleOutcomeAggregate');
|
|
409
|
+
}
|
|
410
|
+
let offset = 8;
|
|
411
|
+
const pool = pubkeyFromData(data, offset);
|
|
412
|
+
offset += 32;
|
|
413
|
+
const member = pubkeyFromData(data, offset);
|
|
414
|
+
offset += 32;
|
|
415
|
+
const cycleHash = data.subarray(offset, offset + 32);
|
|
416
|
+
offset += 32;
|
|
417
|
+
const ruleHash = data.subarray(offset, offset + 32);
|
|
418
|
+
offset += 32;
|
|
419
|
+
const passVotes = data.readUInt16LE(offset);
|
|
420
|
+
offset += 2;
|
|
421
|
+
const failVotes = data.readUInt16LE(offset);
|
|
422
|
+
offset += 2;
|
|
423
|
+
const quorumM = data.readUInt8(offset);
|
|
424
|
+
offset += 1;
|
|
425
|
+
const quorumN = data.readUInt8(offset);
|
|
426
|
+
offset += 1;
|
|
427
|
+
const finalized = data.readUInt8(offset) === 1;
|
|
428
|
+
offset += 1;
|
|
429
|
+
const passed = data.readUInt8(offset) === 1;
|
|
430
|
+
offset += 1;
|
|
431
|
+
const claimed = data.readUInt8(offset) === 1;
|
|
432
|
+
offset += 1;
|
|
433
|
+
const latestAsOfTs = Number(readI64Le(data, offset));
|
|
434
|
+
offset += 8;
|
|
435
|
+
const bump = data.readUInt8(offset);
|
|
436
|
+
return {
|
|
437
|
+
address,
|
|
438
|
+
pool,
|
|
439
|
+
member,
|
|
440
|
+
cycleHashHex: toHex(cycleHash),
|
|
441
|
+
ruleHashHex: toHex(ruleHash),
|
|
442
|
+
passVotes,
|
|
443
|
+
failVotes,
|
|
444
|
+
quorumM,
|
|
445
|
+
quorumN,
|
|
446
|
+
finalized,
|
|
447
|
+
passed,
|
|
448
|
+
claimed,
|
|
449
|
+
latestAsOfTs,
|
|
450
|
+
bump,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function decodeProtocolConfigV2Account(address, data) {
|
|
454
|
+
if (!hasDiscriminator(data, ACCOUNT_PROTOCOL_CONFIG_V2)) {
|
|
455
|
+
throw new Error('account discriminator mismatch for ProtocolConfigV2');
|
|
456
|
+
}
|
|
457
|
+
let offset = 8;
|
|
458
|
+
const admin = pubkeyFromData(data, offset);
|
|
459
|
+
offset += 32;
|
|
460
|
+
const governanceAuthority = pubkeyFromData(data, offset);
|
|
461
|
+
offset += 32;
|
|
462
|
+
const governanceRealm = pubkeyFromData(data, offset);
|
|
463
|
+
offset += 32;
|
|
464
|
+
const governanceConfig = pubkeyFromData(data, offset);
|
|
465
|
+
offset += 32;
|
|
466
|
+
const defaultStakeMint = pubkeyFromData(data, offset);
|
|
467
|
+
offset += 32;
|
|
468
|
+
const protocolFeeBps = readU16Le(data, offset);
|
|
469
|
+
offset += 2;
|
|
470
|
+
const minOracleStake = readU64Le(data, offset);
|
|
471
|
+
offset += 8;
|
|
472
|
+
const emergencyPaused = data.readUInt8(offset) === 1;
|
|
473
|
+
offset += 1;
|
|
474
|
+
const allowedPayoutMintsHash = data.subarray(offset, offset + 32);
|
|
475
|
+
offset += 32;
|
|
476
|
+
const bump = data.readUInt8(offset);
|
|
477
|
+
return {
|
|
478
|
+
address,
|
|
479
|
+
admin,
|
|
480
|
+
governanceAuthority,
|
|
481
|
+
governanceRealm,
|
|
482
|
+
governanceConfig,
|
|
483
|
+
defaultStakeMint,
|
|
484
|
+
protocolFeeBps,
|
|
485
|
+
minOracleStake,
|
|
486
|
+
emergencyPaused,
|
|
487
|
+
allowedPayoutMintsHashHex: toHex(allowedPayoutMintsHash),
|
|
488
|
+
bump,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function decodeOracleStakePositionAccount(address, data) {
|
|
492
|
+
if (!hasDiscriminator(data, ACCOUNT_ORACLE_STAKE_POSITION)) {
|
|
493
|
+
throw new Error('account discriminator mismatch for OracleStakePosition');
|
|
494
|
+
}
|
|
495
|
+
let offset = 8;
|
|
496
|
+
const oracle = pubkeyFromData(data, offset);
|
|
497
|
+
offset += 32;
|
|
498
|
+
const staker = pubkeyFromData(data, offset);
|
|
499
|
+
offset += 32;
|
|
500
|
+
const stakeMint = pubkeyFromData(data, offset);
|
|
501
|
+
offset += 32;
|
|
502
|
+
const stakeVault = pubkeyFromData(data, offset);
|
|
503
|
+
offset += 32;
|
|
504
|
+
const stakedAmount = readU64Le(data, offset);
|
|
505
|
+
offset += 8;
|
|
506
|
+
const pendingUnstakeAmount = readU64Le(data, offset);
|
|
507
|
+
offset += 8;
|
|
508
|
+
const canFinalizeUnstakeAt = Number(readI64Le(data, offset));
|
|
509
|
+
offset += 8;
|
|
510
|
+
const slashPending = data.readUInt8(offset) === 1;
|
|
511
|
+
offset += 1;
|
|
512
|
+
const bump = data.readUInt8(offset);
|
|
513
|
+
return {
|
|
514
|
+
address,
|
|
515
|
+
oracle,
|
|
516
|
+
staker,
|
|
517
|
+
stakeMint,
|
|
518
|
+
stakeVault,
|
|
519
|
+
stakedAmount,
|
|
520
|
+
pendingUnstakeAmount,
|
|
521
|
+
canFinalizeUnstakeAt,
|
|
522
|
+
slashPending,
|
|
523
|
+
bump,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function decodePoolOraclePolicyAccount(address, data) {
|
|
527
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL_ORACLE_POLICY)) {
|
|
528
|
+
throw new Error('account discriminator mismatch for PoolOraclePolicy');
|
|
529
|
+
}
|
|
530
|
+
let offset = 8;
|
|
531
|
+
const pool = pubkeyFromData(data, offset);
|
|
532
|
+
offset += 32;
|
|
533
|
+
const quorumM = data.readUInt8(offset);
|
|
534
|
+
offset += 1;
|
|
535
|
+
const quorumN = data.readUInt8(offset);
|
|
536
|
+
offset += 1;
|
|
537
|
+
const requireVerifiedSchema = data.readUInt8(offset) === 1;
|
|
538
|
+
offset += 1;
|
|
539
|
+
const allowDelegateClaim = data.readUInt8(offset) === 1;
|
|
540
|
+
offset += 1;
|
|
541
|
+
const bump = data.readUInt8(offset);
|
|
542
|
+
return {
|
|
543
|
+
address,
|
|
544
|
+
pool,
|
|
545
|
+
quorumM,
|
|
546
|
+
quorumN,
|
|
547
|
+
requireVerifiedSchema,
|
|
548
|
+
allowDelegateClaim,
|
|
549
|
+
bump,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function decodePoolTermsAccount(address, data) {
|
|
553
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL_TERMS)) {
|
|
554
|
+
throw new Error('account discriminator mismatch for PoolTerms');
|
|
555
|
+
}
|
|
556
|
+
let offset = 8;
|
|
557
|
+
const pool = pubkeyFromData(data, offset);
|
|
558
|
+
offset += 32;
|
|
559
|
+
const poolTypeCode = data.readUInt8(offset);
|
|
560
|
+
offset += 1;
|
|
561
|
+
const payoutAssetMint = pubkeyFromData(data, offset);
|
|
562
|
+
offset += 32;
|
|
563
|
+
const termsHash = data.subarray(offset, offset + 32);
|
|
564
|
+
offset += 32;
|
|
565
|
+
const payoutPolicyHash = data.subarray(offset, offset + 32);
|
|
566
|
+
offset += 32;
|
|
567
|
+
const cycleMode = data.readUInt8(offset);
|
|
568
|
+
offset += 1;
|
|
569
|
+
const metadataUri = readString(data, offset);
|
|
570
|
+
offset = metadataUri.offset;
|
|
571
|
+
const bump = data.readUInt8(offset);
|
|
572
|
+
return {
|
|
573
|
+
address,
|
|
574
|
+
pool,
|
|
575
|
+
poolTypeCode,
|
|
576
|
+
poolType: parsePoolType(poolTypeCode),
|
|
577
|
+
payoutAssetMint,
|
|
578
|
+
termsHashHex: toHex(termsHash),
|
|
579
|
+
payoutPolicyHashHex: toHex(payoutPolicyHash),
|
|
580
|
+
cycleMode,
|
|
581
|
+
metadataUri: metadataUri.value,
|
|
582
|
+
bump,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function decodePoolAssetVaultAccount(address, data) {
|
|
586
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL_ASSET_VAULT)) {
|
|
587
|
+
throw new Error('account discriminator mismatch for PoolAssetVault');
|
|
588
|
+
}
|
|
589
|
+
let offset = 8;
|
|
590
|
+
const pool = pubkeyFromData(data, offset);
|
|
591
|
+
offset += 32;
|
|
592
|
+
const payoutMint = pubkeyFromData(data, offset);
|
|
593
|
+
offset += 32;
|
|
594
|
+
const vaultTokenAccount = pubkeyFromData(data, offset);
|
|
595
|
+
offset += 32;
|
|
596
|
+
const active = data.readUInt8(offset) === 1;
|
|
597
|
+
offset += 1;
|
|
598
|
+
const bump = data.readUInt8(offset);
|
|
599
|
+
return {
|
|
600
|
+
address,
|
|
601
|
+
pool,
|
|
602
|
+
payoutMint,
|
|
603
|
+
vaultTokenAccount,
|
|
604
|
+
active,
|
|
605
|
+
bump,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function decodeOutcomeSchemaAccount(address, data) {
|
|
609
|
+
if (!hasDiscriminator(data, ACCOUNT_OUTCOME_SCHEMA)) {
|
|
610
|
+
throw new Error('account discriminator mismatch for OutcomeSchemaRegistryEntry');
|
|
611
|
+
}
|
|
612
|
+
let offset = 8;
|
|
613
|
+
const schemaKeyHash = data.subarray(offset, offset + 32);
|
|
614
|
+
offset += 32;
|
|
615
|
+
const schemaKey = readString(data, offset);
|
|
616
|
+
offset = schemaKey.offset;
|
|
617
|
+
const version = readU16Le(data, offset);
|
|
618
|
+
offset += 2;
|
|
619
|
+
const schemaHash = data.subarray(offset, offset + 32);
|
|
620
|
+
offset += 32;
|
|
621
|
+
const publisher = pubkeyFromData(data, offset);
|
|
622
|
+
offset += 32;
|
|
623
|
+
const verified = data.readUInt8(offset) === 1;
|
|
624
|
+
offset += 1;
|
|
625
|
+
const metadataUri = readString(data, offset);
|
|
626
|
+
offset = metadataUri.offset;
|
|
627
|
+
const bump = data.readUInt8(offset);
|
|
628
|
+
return {
|
|
629
|
+
address,
|
|
630
|
+
schemaKeyHashHex: toHex(schemaKeyHash),
|
|
631
|
+
schemaKey: schemaKey.value,
|
|
632
|
+
version,
|
|
633
|
+
schemaHashHex: toHex(schemaHash),
|
|
634
|
+
publisher,
|
|
635
|
+
verified,
|
|
636
|
+
metadataUri: metadataUri.value,
|
|
637
|
+
bump,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
function decodePoolOutcomeRuleAccount(address, data) {
|
|
641
|
+
if (!hasDiscriminator(data, ACCOUNT_POOL_OUTCOME_RULE)) {
|
|
642
|
+
throw new Error('account discriminator mismatch for PoolOutcomeRule');
|
|
643
|
+
}
|
|
644
|
+
let offset = 8;
|
|
645
|
+
const pool = pubkeyFromData(data, offset);
|
|
646
|
+
offset += 32;
|
|
647
|
+
const ruleHash = data.subarray(offset, offset + 32);
|
|
648
|
+
offset += 32;
|
|
649
|
+
const schemaKeyHash = data.subarray(offset, offset + 32);
|
|
650
|
+
offset += 32;
|
|
651
|
+
const ruleId = readString(data, offset);
|
|
652
|
+
offset = ruleId.offset;
|
|
653
|
+
const schemaKey = readString(data, offset);
|
|
654
|
+
offset = schemaKey.offset;
|
|
655
|
+
const schemaVersion = readU16Le(data, offset);
|
|
656
|
+
offset += 2;
|
|
657
|
+
const payoutHash = data.subarray(offset, offset + 32);
|
|
658
|
+
offset += 32;
|
|
659
|
+
const enabled = data.readUInt8(offset) === 1;
|
|
660
|
+
offset += 1;
|
|
661
|
+
const bump = data.readUInt8(offset);
|
|
662
|
+
return {
|
|
663
|
+
address,
|
|
664
|
+
pool,
|
|
665
|
+
ruleHashHex: toHex(ruleHash),
|
|
666
|
+
schemaKeyHashHex: toHex(schemaKeyHash),
|
|
667
|
+
ruleId: ruleId.value,
|
|
668
|
+
schemaKey: schemaKey.value,
|
|
669
|
+
schemaVersion,
|
|
670
|
+
payoutHashHex: toHex(payoutHash),
|
|
671
|
+
enabled,
|
|
672
|
+
bump,
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
function decodeInviteIssuerAccount(address, data) {
|
|
676
|
+
if (!hasDiscriminator(data, ACCOUNT_INVITE_ISSUER)) {
|
|
677
|
+
throw new Error('account discriminator mismatch for InviteIssuerRegistryEntry');
|
|
678
|
+
}
|
|
679
|
+
let offset = 8;
|
|
680
|
+
const issuer = pubkeyFromData(data, offset);
|
|
681
|
+
offset += 32;
|
|
682
|
+
const organizationRef = readString(data, offset);
|
|
683
|
+
offset = organizationRef.offset;
|
|
684
|
+
const metadataUri = readString(data, offset);
|
|
685
|
+
offset = metadataUri.offset;
|
|
686
|
+
const active = data.readUInt8(offset) === 1;
|
|
687
|
+
offset += 1;
|
|
688
|
+
const bump = data.readUInt8(offset);
|
|
689
|
+
return {
|
|
690
|
+
address,
|
|
691
|
+
issuer,
|
|
692
|
+
organizationRef: organizationRef.value,
|
|
693
|
+
metadataUri: metadataUri.value,
|
|
694
|
+
active,
|
|
695
|
+
bump,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
function decodeEnrollmentPermitReplayAccount(address, data) {
|
|
699
|
+
if (!hasDiscriminator(data, ACCOUNT_ENROLLMENT_PERMIT_REPLAY)) {
|
|
700
|
+
throw new Error('account discriminator mismatch for EnrollmentPermitReplay');
|
|
701
|
+
}
|
|
702
|
+
let offset = 8;
|
|
703
|
+
const pool = pubkeyFromData(data, offset);
|
|
704
|
+
offset += 32;
|
|
705
|
+
const issuer = pubkeyFromData(data, offset);
|
|
706
|
+
offset += 32;
|
|
707
|
+
const member = pubkeyFromData(data, offset);
|
|
708
|
+
offset += 32;
|
|
709
|
+
const nonceHash = data.subarray(offset, offset + 32);
|
|
710
|
+
offset += 32;
|
|
711
|
+
const inviteIdHash = data.subarray(offset, offset + 32);
|
|
712
|
+
offset += 32;
|
|
713
|
+
const createdAt = Number(readI64Le(data, offset));
|
|
714
|
+
offset += 8;
|
|
715
|
+
const bump = data.readUInt8(offset);
|
|
716
|
+
return {
|
|
717
|
+
address,
|
|
718
|
+
pool,
|
|
719
|
+
issuer,
|
|
720
|
+
member,
|
|
721
|
+
nonceHashHex: toHex(nonceHash),
|
|
722
|
+
inviteIdHashHex: toHex(inviteIdHash),
|
|
723
|
+
createdAt,
|
|
724
|
+
bump,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
function decodeAttestationVoteAccount(address, data) {
|
|
728
|
+
if (!hasDiscriminator(data, ACCOUNT_ATTESTATION_VOTE)) {
|
|
729
|
+
throw new Error('account discriminator mismatch for AttestationVote');
|
|
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 cycleHash = data.subarray(offset, offset + 32);
|
|
737
|
+
offset += 32;
|
|
738
|
+
const ruleHash = data.subarray(offset, offset + 32);
|
|
739
|
+
offset += 32;
|
|
740
|
+
const oracle = pubkeyFromData(data, offset);
|
|
741
|
+
offset += 32;
|
|
742
|
+
const passed = data.readUInt8(offset) === 1;
|
|
743
|
+
offset += 1;
|
|
744
|
+
const attestationDigest = data.subarray(offset, offset + 32);
|
|
745
|
+
offset += 32;
|
|
746
|
+
const observedValueHash = data.subarray(offset, offset + 32);
|
|
747
|
+
offset += 32;
|
|
748
|
+
const asOfTs = Number(readI64Le(data, offset));
|
|
749
|
+
offset += 8;
|
|
750
|
+
const bump = data.readUInt8(offset);
|
|
751
|
+
return {
|
|
752
|
+
address,
|
|
753
|
+
pool,
|
|
754
|
+
member,
|
|
755
|
+
cycleHashHex: toHex(cycleHash),
|
|
756
|
+
ruleHashHex: toHex(ruleHash),
|
|
757
|
+
oracle,
|
|
758
|
+
passed,
|
|
759
|
+
attestationDigestHex: toHex(attestationDigest),
|
|
760
|
+
observedValueHashHex: toHex(observedValueHash),
|
|
761
|
+
asOfTs,
|
|
762
|
+
bump,
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
function decodeClaimDelegateAccount(address, data) {
|
|
766
|
+
if (!hasDiscriminator(data, ACCOUNT_CLAIM_DELEGATE_AUTH)) {
|
|
767
|
+
throw new Error('account discriminator mismatch for ClaimDelegateAuthorization');
|
|
768
|
+
}
|
|
769
|
+
let offset = 8;
|
|
770
|
+
const pool = pubkeyFromData(data, offset);
|
|
771
|
+
offset += 32;
|
|
772
|
+
const member = pubkeyFromData(data, offset);
|
|
773
|
+
offset += 32;
|
|
774
|
+
const delegate = pubkeyFromData(data, offset);
|
|
775
|
+
offset += 32;
|
|
776
|
+
const active = data.readUInt8(offset) === 1;
|
|
777
|
+
offset += 1;
|
|
778
|
+
const updatedAt = Number(readI64Le(data, offset));
|
|
779
|
+
offset += 8;
|
|
780
|
+
const bump = data.readUInt8(offset);
|
|
781
|
+
return {
|
|
782
|
+
address,
|
|
783
|
+
pool,
|
|
784
|
+
member,
|
|
785
|
+
delegate,
|
|
786
|
+
active,
|
|
787
|
+
updatedAt,
|
|
788
|
+
bump,
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
function decodeCoveragePolicyAccount(address, data) {
|
|
792
|
+
if (!hasDiscriminator(data, ACCOUNT_COVERAGE_POLICY)) {
|
|
793
|
+
throw new Error('account discriminator mismatch for CoveragePolicy');
|
|
794
|
+
}
|
|
795
|
+
let offset = 8;
|
|
796
|
+
const pool = pubkeyFromData(data, offset);
|
|
797
|
+
offset += 32;
|
|
798
|
+
const member = pubkeyFromData(data, offset);
|
|
799
|
+
offset += 32;
|
|
800
|
+
const termsHash = data.subarray(offset, offset + 32);
|
|
801
|
+
offset += 32;
|
|
802
|
+
const status = data.readUInt8(offset);
|
|
803
|
+
offset += 1;
|
|
804
|
+
const startsAt = Number(readI64Le(data, offset));
|
|
805
|
+
offset += 8;
|
|
806
|
+
const endsAt = Number(readI64Le(data, offset));
|
|
807
|
+
offset += 8;
|
|
808
|
+
const premiumDueEverySecs = Number(readI64Le(data, offset));
|
|
809
|
+
offset += 8;
|
|
810
|
+
const premiumGraceSecs = Number(readI64Le(data, offset));
|
|
811
|
+
offset += 8;
|
|
812
|
+
const nextDueAt = Number(readI64Le(data, offset));
|
|
813
|
+
offset += 8;
|
|
814
|
+
const nftMint = pubkeyFromData(data, offset);
|
|
815
|
+
offset += 32;
|
|
816
|
+
const bump = data.readUInt8(offset);
|
|
817
|
+
return {
|
|
818
|
+
address,
|
|
819
|
+
pool,
|
|
820
|
+
member,
|
|
821
|
+
termsHashHex: toHex(termsHash),
|
|
822
|
+
status,
|
|
823
|
+
startsAt,
|
|
824
|
+
endsAt,
|
|
825
|
+
premiumDueEverySecs,
|
|
826
|
+
premiumGraceSecs,
|
|
827
|
+
nextDueAt,
|
|
828
|
+
nftMint,
|
|
829
|
+
bump,
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function decodePremiumLedgerAccount(address, data) {
|
|
833
|
+
if (!hasDiscriminator(data, ACCOUNT_PREMIUM_LEDGER)) {
|
|
834
|
+
throw new Error('account discriminator mismatch for PremiumLedger');
|
|
835
|
+
}
|
|
836
|
+
let offset = 8;
|
|
837
|
+
const pool = pubkeyFromData(data, offset);
|
|
838
|
+
offset += 32;
|
|
839
|
+
const member = pubkeyFromData(data, offset);
|
|
840
|
+
offset += 32;
|
|
841
|
+
const periodIndex = readU64Le(data, offset);
|
|
842
|
+
offset += 8;
|
|
843
|
+
const amount = readU64Le(data, offset);
|
|
844
|
+
offset += 8;
|
|
845
|
+
const source = data.readUInt8(offset);
|
|
846
|
+
offset += 1;
|
|
847
|
+
const paidAt = Number(readI64Le(data, offset));
|
|
848
|
+
offset += 8;
|
|
849
|
+
const bump = data.readUInt8(offset);
|
|
850
|
+
return {
|
|
851
|
+
address,
|
|
852
|
+
pool,
|
|
853
|
+
member,
|
|
854
|
+
periodIndex,
|
|
855
|
+
amount,
|
|
856
|
+
source,
|
|
857
|
+
paidAt,
|
|
858
|
+
bump,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
function decodeClaimRecordV2Account(address, data) {
|
|
862
|
+
if (!hasDiscriminator(data, ACCOUNT_CLAIM_RECORD_V2)) {
|
|
863
|
+
throw new Error('account discriminator mismatch for ClaimRecordV2');
|
|
864
|
+
}
|
|
865
|
+
let offset = 8;
|
|
866
|
+
const pool = pubkeyFromData(data, offset);
|
|
867
|
+
offset += 32;
|
|
868
|
+
const member = pubkeyFromData(data, offset);
|
|
869
|
+
offset += 32;
|
|
870
|
+
const claimant = pubkeyFromData(data, offset);
|
|
871
|
+
offset += 32;
|
|
872
|
+
const cycleHash = data.subarray(offset, offset + 32);
|
|
873
|
+
offset += 32;
|
|
874
|
+
const ruleHash = data.subarray(offset, offset + 32);
|
|
875
|
+
offset += 32;
|
|
876
|
+
const intentHash = data.subarray(offset, offset + 32);
|
|
877
|
+
offset += 32;
|
|
878
|
+
const payoutMint = pubkeyFromData(data, offset);
|
|
879
|
+
offset += 32;
|
|
880
|
+
const payoutAmount = readU64Le(data, offset);
|
|
881
|
+
offset += 8;
|
|
882
|
+
const recipient = pubkeyFromData(data, offset);
|
|
883
|
+
offset += 32;
|
|
884
|
+
const submittedAt = Number(readI64Le(data, offset));
|
|
885
|
+
offset += 8;
|
|
886
|
+
const bump = data.readUInt8(offset);
|
|
887
|
+
return {
|
|
888
|
+
address,
|
|
889
|
+
pool,
|
|
890
|
+
member,
|
|
891
|
+
claimant,
|
|
892
|
+
cycleHashHex: toHex(cycleHash),
|
|
893
|
+
ruleHashHex: toHex(ruleHash),
|
|
894
|
+
intentHashHex: toHex(intentHash),
|
|
895
|
+
payoutMint,
|
|
896
|
+
payoutAmount,
|
|
897
|
+
recipient,
|
|
898
|
+
submittedAt,
|
|
899
|
+
bump,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
function decodeCoverageProductAccount(address, data) {
|
|
903
|
+
if (!hasDiscriminator(data, ACCOUNT_COVERAGE_PRODUCT)) {
|
|
904
|
+
throw new Error('account discriminator mismatch for CoverageProduct');
|
|
905
|
+
}
|
|
906
|
+
let offset = 8;
|
|
907
|
+
const pool = pubkeyFromData(data, offset);
|
|
908
|
+
offset += 32;
|
|
909
|
+
const admin = pubkeyFromData(data, offset);
|
|
910
|
+
offset += 32;
|
|
911
|
+
const productIdHash = data.subarray(offset, offset + 32);
|
|
912
|
+
offset += 32;
|
|
913
|
+
const active = data.readUInt8(offset) === 1;
|
|
914
|
+
offset += 1;
|
|
915
|
+
const displayName = readString(data, offset);
|
|
916
|
+
offset = displayName.offset;
|
|
917
|
+
const metadataUri = readString(data, offset);
|
|
918
|
+
offset = metadataUri.offset;
|
|
919
|
+
const termsHash = data.subarray(offset, offset + 32);
|
|
920
|
+
offset += 32;
|
|
921
|
+
const durationSecs = Number(readI64Le(data, offset));
|
|
922
|
+
offset += 8;
|
|
923
|
+
const premiumDueEverySecs = Number(readI64Le(data, offset));
|
|
924
|
+
offset += 8;
|
|
925
|
+
const premiumGraceSecs = Number(readI64Le(data, offset));
|
|
926
|
+
offset += 8;
|
|
927
|
+
const premiumAmount = readU64Le(data, offset);
|
|
928
|
+
offset += 8;
|
|
929
|
+
const createdAtTs = Number(readI64Le(data, offset));
|
|
930
|
+
offset += 8;
|
|
931
|
+
const updatedAtTs = Number(readI64Le(data, offset));
|
|
932
|
+
offset += 8;
|
|
933
|
+
const bump = data.readUInt8(offset);
|
|
934
|
+
return {
|
|
935
|
+
address,
|
|
936
|
+
pool,
|
|
937
|
+
admin,
|
|
938
|
+
productIdHashHex: toHex(productIdHash),
|
|
939
|
+
active,
|
|
940
|
+
displayName: displayName.value,
|
|
941
|
+
metadataUri: metadataUri.value,
|
|
942
|
+
termsHashHex: toHex(termsHash),
|
|
943
|
+
durationSecs,
|
|
944
|
+
premiumDueEverySecs,
|
|
945
|
+
premiumGraceSecs,
|
|
946
|
+
premiumAmount,
|
|
947
|
+
createdAtTs,
|
|
948
|
+
updatedAtTs,
|
|
949
|
+
bump,
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function decodeCoveragePolicyPositionNftAccount(address, data) {
|
|
953
|
+
if (!hasDiscriminator(data, ACCOUNT_COVERAGE_POLICY_POSITION_NFT)) {
|
|
954
|
+
throw new Error('account discriminator mismatch for CoveragePolicyPositionNft');
|
|
955
|
+
}
|
|
956
|
+
let offset = 8;
|
|
957
|
+
const pool = pubkeyFromData(data, offset);
|
|
958
|
+
offset += 32;
|
|
959
|
+
const member = pubkeyFromData(data, offset);
|
|
960
|
+
offset += 32;
|
|
961
|
+
const nftMint = pubkeyFromData(data, offset);
|
|
962
|
+
offset += 32;
|
|
963
|
+
const metadataUri = readString(data, offset);
|
|
964
|
+
offset = metadataUri.offset;
|
|
965
|
+
const bump = data.readUInt8(offset);
|
|
966
|
+
return {
|
|
967
|
+
address,
|
|
968
|
+
pool,
|
|
969
|
+
member,
|
|
970
|
+
nftMint,
|
|
971
|
+
metadataUri: metadataUri.value,
|
|
972
|
+
bump,
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
function decodePremiumAttestationReplayAccount(address, data) {
|
|
976
|
+
if (!hasDiscriminator(data, ACCOUNT_PREMIUM_ATTESTATION_REPLAY)) {
|
|
977
|
+
throw new Error('account discriminator mismatch for PremiumAttestationReplay');
|
|
978
|
+
}
|
|
979
|
+
let offset = 8;
|
|
980
|
+
const pool = pubkeyFromData(data, offset);
|
|
981
|
+
offset += 32;
|
|
982
|
+
const member = pubkeyFromData(data, offset);
|
|
983
|
+
offset += 32;
|
|
984
|
+
const periodIndex = readU64Le(data, offset);
|
|
985
|
+
offset += 8;
|
|
986
|
+
const replayHash = data.subarray(offset, offset + 32);
|
|
987
|
+
offset += 32;
|
|
988
|
+
const oracle = pubkeyFromData(data, offset);
|
|
989
|
+
offset += 32;
|
|
990
|
+
const createdAt = Number(readI64Le(data, offset));
|
|
991
|
+
offset += 8;
|
|
992
|
+
const bump = data.readUInt8(offset);
|
|
993
|
+
return {
|
|
994
|
+
address,
|
|
995
|
+
pool,
|
|
996
|
+
member,
|
|
997
|
+
periodIndex,
|
|
998
|
+
replayHashHex: toHex(replayHash),
|
|
999
|
+
oracle,
|
|
1000
|
+
createdAt,
|
|
1001
|
+
bump,
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
function decodeCoverageClaimRecordAccount(address, data) {
|
|
1005
|
+
if (!hasDiscriminator(data, ACCOUNT_COVERAGE_CLAIM_RECORD)) {
|
|
1006
|
+
throw new Error('account discriminator mismatch for CoverageClaimRecord');
|
|
1007
|
+
}
|
|
1008
|
+
let offset = 8;
|
|
1009
|
+
const pool = pubkeyFromData(data, offset);
|
|
1010
|
+
offset += 32;
|
|
1011
|
+
const member = pubkeyFromData(data, offset);
|
|
1012
|
+
offset += 32;
|
|
1013
|
+
const claimant = pubkeyFromData(data, offset);
|
|
1014
|
+
offset += 32;
|
|
1015
|
+
const intentHash = data.subarray(offset, offset + 32);
|
|
1016
|
+
offset += 32;
|
|
1017
|
+
const eventHash = data.subarray(offset, offset + 32);
|
|
1018
|
+
offset += 32;
|
|
1019
|
+
const status = data.readUInt8(offset);
|
|
1020
|
+
offset += 1;
|
|
1021
|
+
const submittedAt = Number(readI64Le(data, offset));
|
|
1022
|
+
offset += 8;
|
|
1023
|
+
const settledAt = Number(readI64Le(data, offset));
|
|
1024
|
+
offset += 8;
|
|
1025
|
+
const bump = data.readUInt8(offset);
|
|
1026
|
+
return {
|
|
1027
|
+
address,
|
|
1028
|
+
pool,
|
|
1029
|
+
member,
|
|
1030
|
+
claimant,
|
|
1031
|
+
intentHashHex: toHex(intentHash),
|
|
1032
|
+
eventHashHex: toHex(eventHash),
|
|
1033
|
+
status,
|
|
1034
|
+
submittedAt,
|
|
1035
|
+
settledAt,
|
|
1036
|
+
bump,
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
function toUnixTimestamp(value) {
|
|
1040
|
+
const millis = new Date(value).getTime();
|
|
1041
|
+
if (!Number.isFinite(millis) || Number.isNaN(millis)) {
|
|
1042
|
+
throw new Error('invalid ISO timestamp');
|
|
1043
|
+
}
|
|
1044
|
+
return BigInt(Math.floor(millis / 1000));
|
|
1045
|
+
}
|
|
1046
|
+
function assertPoolIdSeedLength(poolId) {
|
|
1047
|
+
const length = Buffer.byteLength(poolId, 'utf8');
|
|
1048
|
+
if (length > MAX_POOL_ID_SEED_BYTES) {
|
|
1049
|
+
throw new Error(`poolId exceeds ${MAX_POOL_ID_SEED_BYTES} UTF-8 bytes`);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function normalize32ByteHexOrHash(value, fallbackInput) {
|
|
1053
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
1054
|
+
return fromHex(value, 32);
|
|
1055
|
+
}
|
|
1056
|
+
return hashStringTo32(fallbackInput);
|
|
1057
|
+
}
|
|
1058
|
+
function encodeInitializeProtocolData(params) {
|
|
1059
|
+
if (!Number.isInteger(params.protocolFeeBps) || params.protocolFeeBps < 0 || params.protocolFeeBps > 10_000) {
|
|
1060
|
+
throw new Error('protocolFeeBps must be an integer between 0 and 10000');
|
|
1061
|
+
}
|
|
1062
|
+
return Buffer.concat([IX_INITIALIZE_PROTOCOL, encodeU16Le(params.protocolFeeBps)]);
|
|
1063
|
+
}
|
|
1064
|
+
function encodeSetProtocolPauseData(params) {
|
|
1065
|
+
return Buffer.concat([IX_SET_PROTOCOL_PAUSE, Buffer.from([params.paused ? 1 : 0])]);
|
|
1066
|
+
}
|
|
1067
|
+
function encodeCreatePoolData(params) {
|
|
1068
|
+
assertPoolIdSeedLength(params.poolId);
|
|
1069
|
+
const tokenGateMint = params.tokenGateMint ? asPubkey(params.tokenGateMint) : new PublicKey(ZERO_PUBKEY);
|
|
1070
|
+
const inviteIssuer = params.inviteIssuer ? asPubkey(params.inviteIssuer) : new PublicKey(ZERO_PUBKEY);
|
|
1071
|
+
return Buffer.concat([
|
|
1072
|
+
IX_CREATE_POOL,
|
|
1073
|
+
encodeString(params.poolId),
|
|
1074
|
+
encodeString(params.organizationRef),
|
|
1075
|
+
encodeU64Le(params.payoutLamportsPerPass),
|
|
1076
|
+
Buffer.from([params.membershipMode & 0xff]),
|
|
1077
|
+
tokenGateMint.toBuffer(),
|
|
1078
|
+
encodeU64Le(params.tokenGateMinBalance ?? 0n),
|
|
1079
|
+
inviteIssuer.toBuffer(),
|
|
1080
|
+
]);
|
|
1081
|
+
}
|
|
1082
|
+
function encodeSetPoolStatusData(params) {
|
|
1083
|
+
return Buffer.concat([IX_SET_POOL_STATUS, Buffer.from([params.status & 0xff])]);
|
|
1084
|
+
}
|
|
1085
|
+
function encodeSetCycleWindowData(params) {
|
|
1086
|
+
if (!Number.isFinite(params.claimOpenTs) || !Number.isFinite(params.claimCloseTs)) {
|
|
1087
|
+
throw new Error('claim window timestamps must be finite numbers');
|
|
1088
|
+
}
|
|
1089
|
+
const claimOpenTs = BigInt(Math.trunc(params.claimOpenTs));
|
|
1090
|
+
const claimCloseTs = BigInt(Math.trunc(params.claimCloseTs));
|
|
1091
|
+
if (claimCloseTs <= claimOpenTs) {
|
|
1092
|
+
throw new Error('claimCloseTs must be greater than claimOpenTs');
|
|
1093
|
+
}
|
|
1094
|
+
return Buffer.concat([
|
|
1095
|
+
IX_SET_CYCLE_WINDOW,
|
|
1096
|
+
Buffer.from(hashStringTo32(params.cycleId)),
|
|
1097
|
+
encodeI64Le(claimOpenTs),
|
|
1098
|
+
encodeI64Le(claimCloseTs),
|
|
1099
|
+
]);
|
|
1100
|
+
}
|
|
1101
|
+
function encodeFundPoolData(params) {
|
|
1102
|
+
return Buffer.concat([IX_FUND_POOL, encodeU64Le(params.lamports)]);
|
|
1103
|
+
}
|
|
1104
|
+
function encodeRegisterOracleData(params) {
|
|
1105
|
+
return Buffer.concat([IX_REGISTER_ORACLE, encodeString(params.metadataUri)]);
|
|
1106
|
+
}
|
|
1107
|
+
function encodeFixed32Vec(valuesHex) {
|
|
1108
|
+
const count = valuesHex.length >>> 0;
|
|
1109
|
+
if (count > MAX_ORACLE_SUPPORTED_SCHEMAS) {
|
|
1110
|
+
throw new Error(`supported schema key hashes cannot exceed ${MAX_ORACLE_SUPPORTED_SCHEMAS}`);
|
|
1111
|
+
}
|
|
1112
|
+
const encoded = [Buffer.alloc(4)];
|
|
1113
|
+
encoded[0].writeUInt32LE(count, 0);
|
|
1114
|
+
for (const value of valuesHex) {
|
|
1115
|
+
encoded.push(Buffer.from(fromHex(value, 32)));
|
|
1116
|
+
}
|
|
1117
|
+
return Buffer.concat(encoded);
|
|
1118
|
+
}
|
|
1119
|
+
function validateRewardClaimOptionalAccounts(params) {
|
|
1120
|
+
const providedCount = [
|
|
1121
|
+
params.poolAssetVault,
|
|
1122
|
+
params.poolVaultTokenAccount,
|
|
1123
|
+
params.recipientTokenAccount,
|
|
1124
|
+
].filter((value) => typeof value === 'string' && value.length > 0).length;
|
|
1125
|
+
if (providedCount !== 0 && providedCount !== 3) {
|
|
1126
|
+
throw new Error('poolAssetVault, poolVaultTokenAccount, and recipientTokenAccount must be provided together');
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
function encodeRegisterOracleV2Data(params) {
|
|
1130
|
+
return Buffer.concat([
|
|
1131
|
+
IX_REGISTER_ORACLE_V2,
|
|
1132
|
+
asPubkey(params.oraclePubkey).toBuffer(),
|
|
1133
|
+
Buffer.from([params.oracleType & 0xff]),
|
|
1134
|
+
encodeString(params.displayName),
|
|
1135
|
+
encodeString(params.legalName),
|
|
1136
|
+
encodeString(params.websiteUrl),
|
|
1137
|
+
encodeString(params.appUrl),
|
|
1138
|
+
encodeString(params.logoUri),
|
|
1139
|
+
encodeString(params.webhookUrl),
|
|
1140
|
+
encodeFixed32Vec(params.supportedSchemaKeyHashesHex),
|
|
1141
|
+
]);
|
|
1142
|
+
}
|
|
1143
|
+
function encodeUpdateOracleProfileV2Data(params) {
|
|
1144
|
+
return Buffer.concat([
|
|
1145
|
+
IX_UPDATE_ORACLE_PROFILE_V2,
|
|
1146
|
+
Buffer.from([params.oracleType & 0xff]),
|
|
1147
|
+
encodeString(params.displayName),
|
|
1148
|
+
encodeString(params.legalName),
|
|
1149
|
+
encodeString(params.websiteUrl),
|
|
1150
|
+
encodeString(params.appUrl),
|
|
1151
|
+
encodeString(params.logoUri),
|
|
1152
|
+
encodeString(params.webhookUrl),
|
|
1153
|
+
encodeFixed32Vec(params.supportedSchemaKeyHashesHex),
|
|
1154
|
+
]);
|
|
1155
|
+
}
|
|
1156
|
+
function encodeSetPoolOracleData(params) {
|
|
1157
|
+
return Buffer.concat([IX_SET_POOL_ORACLE, Buffer.from([params.active ? 1 : 0])]);
|
|
1158
|
+
}
|
|
1159
|
+
function encodeEnrollMemberData(params) {
|
|
1160
|
+
const subjectCommitment = normalize32ByteHexOrHash(params.subjectCommitmentHex, `subject:${params.member}`);
|
|
1161
|
+
const inviteCodeHash = params.inviteCodeHashHex
|
|
1162
|
+
? fromHex(params.inviteCodeHashHex, 32)
|
|
1163
|
+
: new Uint8Array(32);
|
|
1164
|
+
return Buffer.concat([
|
|
1165
|
+
IX_ENROLL_MEMBER,
|
|
1166
|
+
Buffer.from(subjectCommitment),
|
|
1167
|
+
Buffer.from(inviteCodeHash),
|
|
1168
|
+
]);
|
|
1169
|
+
}
|
|
1170
|
+
function encodeSubmitOutcomeAttestationData(params) {
|
|
1171
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1172
|
+
const outcomeHash = hashStringTo32(params.outcomeId);
|
|
1173
|
+
const replayHash = hashStringTo32(params.replayKey);
|
|
1174
|
+
const digest = params.attestationDigestHex
|
|
1175
|
+
? Buffer.from(params.attestationDigestHex.replace(/^0x/, ''), 'hex')
|
|
1176
|
+
: Buffer.from(hashStringTo32(`${params.cycleId}:${params.outcomeId}:${params.replayKey}`));
|
|
1177
|
+
if (digest.length !== 32) {
|
|
1178
|
+
throw new Error('attestation digest must be 32 bytes');
|
|
1179
|
+
}
|
|
1180
|
+
return Buffer.concat([
|
|
1181
|
+
IX_SUBMIT_OUTCOME_ATTESTATION,
|
|
1182
|
+
asPubkey(params.member).toBuffer(),
|
|
1183
|
+
Buffer.from(cycleHash),
|
|
1184
|
+
Buffer.from(outcomeHash),
|
|
1185
|
+
Buffer.from(replayHash),
|
|
1186
|
+
encodeI64Le(toUnixTimestamp(params.asOfIso)),
|
|
1187
|
+
Buffer.from([params.passed ? 1 : 0]),
|
|
1188
|
+
digest,
|
|
1189
|
+
]);
|
|
1190
|
+
}
|
|
1191
|
+
function encodeSubmitClaimData(params) {
|
|
1192
|
+
return Buffer.concat([
|
|
1193
|
+
IX_SUBMIT_CLAIM,
|
|
1194
|
+
Buffer.from(hashStringTo32(params.cycleId)),
|
|
1195
|
+
Buffer.from(hashStringTo32(params.intentId)),
|
|
1196
|
+
]);
|
|
1197
|
+
}
|
|
1198
|
+
function encodeSubmitOutcomeAttestationVoteData(params) {
|
|
1199
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1200
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
1201
|
+
const digest = fromHex(params.attestationDigestHex, 32);
|
|
1202
|
+
const observedValueHash = fromHex(params.observedValueHashHex, 32);
|
|
1203
|
+
const asOfTs = BigInt(Math.trunc(params.asOfTs));
|
|
1204
|
+
return Buffer.concat([
|
|
1205
|
+
IX_SUBMIT_OUTCOME_ATTESTATION_VOTE,
|
|
1206
|
+
asPubkey(params.member).toBuffer(),
|
|
1207
|
+
Buffer.from(cycleHash),
|
|
1208
|
+
Buffer.from(ruleHash),
|
|
1209
|
+
Buffer.from(digest),
|
|
1210
|
+
Buffer.from(observedValueHash),
|
|
1211
|
+
encodeI64Le(asOfTs),
|
|
1212
|
+
Buffer.from([params.passed ? 1 : 0]),
|
|
1213
|
+
]);
|
|
1214
|
+
}
|
|
1215
|
+
function encodeInitializeProtocolV2Data(params) {
|
|
1216
|
+
if (!Number.isInteger(params.protocolFeeBps) || params.protocolFeeBps < 0 || params.protocolFeeBps > 10_000) {
|
|
1217
|
+
throw new Error('protocolFeeBps must be an integer between 0 and 10000');
|
|
1218
|
+
}
|
|
1219
|
+
return Buffer.concat([
|
|
1220
|
+
IX_INITIALIZE_PROTOCOL_V2,
|
|
1221
|
+
encodeU16Le(params.protocolFeeBps),
|
|
1222
|
+
asPubkey(params.governanceRealm).toBuffer(),
|
|
1223
|
+
asPubkey(params.governanceConfig).toBuffer(),
|
|
1224
|
+
asPubkey(params.defaultStakeMint).toBuffer(),
|
|
1225
|
+
encodeU64Le(params.minOracleStake),
|
|
1226
|
+
]);
|
|
1227
|
+
}
|
|
1228
|
+
function encodeSetProtocolParamsData(params) {
|
|
1229
|
+
if (!Number.isInteger(params.protocolFeeBps) || params.protocolFeeBps < 0 || params.protocolFeeBps > 10_000) {
|
|
1230
|
+
throw new Error('protocolFeeBps must be an integer between 0 and 10000');
|
|
1231
|
+
}
|
|
1232
|
+
return Buffer.concat([
|
|
1233
|
+
IX_SET_PROTOCOL_PARAMS,
|
|
1234
|
+
encodeU16Le(params.protocolFeeBps),
|
|
1235
|
+
Buffer.from(fromHex(params.allowedPayoutMintsHashHex, 32)),
|
|
1236
|
+
encodeU64Le(params.minOracleStake),
|
|
1237
|
+
Buffer.from([params.emergencyPaused ? 1 : 0]),
|
|
1238
|
+
]);
|
|
1239
|
+
}
|
|
1240
|
+
function encodeRotateGovernanceAuthorityData(params) {
|
|
1241
|
+
return Buffer.concat([
|
|
1242
|
+
IX_ROTATE_GOVERNANCE_AUTHORITY,
|
|
1243
|
+
asPubkey(params.newAuthority).toBuffer(),
|
|
1244
|
+
]);
|
|
1245
|
+
}
|
|
1246
|
+
function encodeUpdateOracleMetadataData(params) {
|
|
1247
|
+
return Buffer.concat([
|
|
1248
|
+
IX_UPDATE_ORACLE_METADATA,
|
|
1249
|
+
encodeString(params.metadataUri),
|
|
1250
|
+
Buffer.from([params.active ? 1 : 0]),
|
|
1251
|
+
]);
|
|
1252
|
+
}
|
|
1253
|
+
function encodeStakeOracleData(params) {
|
|
1254
|
+
return Buffer.concat([IX_STAKE_ORACLE, encodeU64Le(params.amount)]);
|
|
1255
|
+
}
|
|
1256
|
+
function encodeRequestUnstakeData(params) {
|
|
1257
|
+
return Buffer.concat([
|
|
1258
|
+
IX_REQUEST_UNSTAKE,
|
|
1259
|
+
encodeU64Le(params.amount),
|
|
1260
|
+
encodeI64Le(BigInt(Math.trunc(params.cooldownSeconds))),
|
|
1261
|
+
]);
|
|
1262
|
+
}
|
|
1263
|
+
function encodeSlashOracleData(params) {
|
|
1264
|
+
return Buffer.concat([IX_SLASH_ORACLE, encodeU64Le(params.amount)]);
|
|
1265
|
+
}
|
|
1266
|
+
function encodeCreatePoolV2Data(params) {
|
|
1267
|
+
assertPoolIdSeedLength(params.poolId);
|
|
1268
|
+
return Buffer.concat([
|
|
1269
|
+
IX_CREATE_POOL_V2,
|
|
1270
|
+
encodeString(params.poolId),
|
|
1271
|
+
encodeString(params.organizationRef),
|
|
1272
|
+
encodeU64Le(params.payoutLamportsPerPass),
|
|
1273
|
+
Buffer.from([params.membershipMode & 0xff]),
|
|
1274
|
+
asPubkey(params.tokenGateMint).toBuffer(),
|
|
1275
|
+
encodeU64Le(params.tokenGateMinBalance),
|
|
1276
|
+
asPubkey(params.inviteIssuer).toBuffer(),
|
|
1277
|
+
Buffer.from([params.poolType & 0xff]),
|
|
1278
|
+
asPubkey(params.payoutAssetMint).toBuffer(),
|
|
1279
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1280
|
+
Buffer.from(fromHex(params.payoutPolicyHashHex, 32)),
|
|
1281
|
+
Buffer.from([params.cycleMode & 0xff]),
|
|
1282
|
+
encodeString(params.metadataUri),
|
|
1283
|
+
]);
|
|
1284
|
+
}
|
|
1285
|
+
function encodeSetPoolOraclePolicyData(params) {
|
|
1286
|
+
return Buffer.concat([
|
|
1287
|
+
IX_SET_POOL_ORACLE_POLICY,
|
|
1288
|
+
Buffer.from([params.quorumM & 0xff]),
|
|
1289
|
+
Buffer.from([params.quorumN & 0xff]),
|
|
1290
|
+
Buffer.from([params.requireVerifiedSchema ? 1 : 0]),
|
|
1291
|
+
Buffer.from([params.allowDelegateClaim ? 1 : 0]),
|
|
1292
|
+
]);
|
|
1293
|
+
}
|
|
1294
|
+
function encodeSetPoolTermsHashData(params) {
|
|
1295
|
+
return Buffer.concat([
|
|
1296
|
+
IX_SET_POOL_TERMS_HASH,
|
|
1297
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1298
|
+
Buffer.from(fromHex(params.payoutPolicyHashHex, 32)),
|
|
1299
|
+
Buffer.from([params.cycleMode & 0xff]),
|
|
1300
|
+
encodeString(params.metadataUri),
|
|
1301
|
+
]);
|
|
1302
|
+
}
|
|
1303
|
+
function encodeRegisterOutcomeSchemaData(params) {
|
|
1304
|
+
return Buffer.concat([
|
|
1305
|
+
IX_REGISTER_OUTCOME_SCHEMA,
|
|
1306
|
+
Buffer.from(fromHex(params.schemaKeyHashHex, 32)),
|
|
1307
|
+
encodeString(params.schemaKey),
|
|
1308
|
+
encodeU16Le(params.version),
|
|
1309
|
+
Buffer.from(fromHex(params.schemaHashHex, 32)),
|
|
1310
|
+
encodeString(params.metadataUri),
|
|
1311
|
+
]);
|
|
1312
|
+
}
|
|
1313
|
+
function encodeVerifyOutcomeSchemaData(params) {
|
|
1314
|
+
return Buffer.concat([
|
|
1315
|
+
IX_VERIFY_OUTCOME_SCHEMA,
|
|
1316
|
+
Buffer.from([params.verified ? 1 : 0]),
|
|
1317
|
+
]);
|
|
1318
|
+
}
|
|
1319
|
+
function encodeSetPoolOutcomeRuleData(params) {
|
|
1320
|
+
return Buffer.concat([
|
|
1321
|
+
IX_SET_POOL_OUTCOME_RULE,
|
|
1322
|
+
Buffer.from(fromHex(params.ruleHashHex, 32)),
|
|
1323
|
+
Buffer.from(fromHex(params.schemaKeyHashHex, 32)),
|
|
1324
|
+
encodeString(params.ruleId),
|
|
1325
|
+
encodeString(params.schemaKey),
|
|
1326
|
+
encodeU16Le(params.schemaVersion),
|
|
1327
|
+
Buffer.from(fromHex(params.payoutHashHex, 32)),
|
|
1328
|
+
Buffer.from([params.enabled ? 1 : 0]),
|
|
1329
|
+
]);
|
|
1330
|
+
}
|
|
1331
|
+
function encodeRegisterInviteIssuerData(params) {
|
|
1332
|
+
return Buffer.concat([
|
|
1333
|
+
IX_REGISTER_INVITE_ISSUER,
|
|
1334
|
+
encodeString(params.organizationRef),
|
|
1335
|
+
encodeString(params.metadataUri),
|
|
1336
|
+
Buffer.from([params.active ? 1 : 0]),
|
|
1337
|
+
]);
|
|
1338
|
+
}
|
|
1339
|
+
function encodeEnrollMemberOpenData(params) {
|
|
1340
|
+
const subjectCommitment = normalize32ByteHexOrHash(params.subjectCommitmentHex, `subject:${params.member}`);
|
|
1341
|
+
return Buffer.concat([IX_ENROLL_MEMBER_OPEN, Buffer.from(subjectCommitment)]);
|
|
1342
|
+
}
|
|
1343
|
+
function encodeEnrollMemberTokenGateData(params) {
|
|
1344
|
+
const subjectCommitment = normalize32ByteHexOrHash(params.subjectCommitmentHex, `subject:${params.member}`);
|
|
1345
|
+
return Buffer.concat([IX_ENROLL_MEMBER_TOKEN_GATE, Buffer.from(subjectCommitment)]);
|
|
1346
|
+
}
|
|
1347
|
+
function encodeEnrollMemberInvitePermitData(params) {
|
|
1348
|
+
const subjectCommitment = normalize32ByteHexOrHash(params.subjectCommitmentHex, `subject:${params.member}`);
|
|
1349
|
+
return Buffer.concat([
|
|
1350
|
+
IX_ENROLL_MEMBER_INVITE_PERMIT,
|
|
1351
|
+
Buffer.from(subjectCommitment),
|
|
1352
|
+
Buffer.from(fromHex(params.nonceHashHex, 32)),
|
|
1353
|
+
Buffer.from(fromHex(params.inviteIdHashHex, 32)),
|
|
1354
|
+
encodeI64Le(BigInt(Math.trunc(params.expiresAtTs))),
|
|
1355
|
+
]);
|
|
1356
|
+
}
|
|
1357
|
+
function encodeSetClaimDelegateData(params) {
|
|
1358
|
+
return Buffer.concat([
|
|
1359
|
+
IX_SET_CLAIM_DELEGATE,
|
|
1360
|
+
asPubkey(params.delegate).toBuffer(),
|
|
1361
|
+
Buffer.from([params.active ? 1 : 0]),
|
|
1362
|
+
]);
|
|
1363
|
+
}
|
|
1364
|
+
function encodeFundPoolSolData(params) {
|
|
1365
|
+
return Buffer.concat([IX_FUND_POOL_SOL, encodeU64Le(params.lamports)]);
|
|
1366
|
+
}
|
|
1367
|
+
function encodeFundPoolSplData(params) {
|
|
1368
|
+
return Buffer.concat([IX_FUND_POOL_SPL, encodeU64Le(params.amount)]);
|
|
1369
|
+
}
|
|
1370
|
+
function encodeSubmitRewardClaimData(params) {
|
|
1371
|
+
return Buffer.concat([
|
|
1372
|
+
IX_SUBMIT_REWARD_CLAIM,
|
|
1373
|
+
asPubkey(params.member).toBuffer(),
|
|
1374
|
+
Buffer.from(hashStringTo32(params.cycleId)),
|
|
1375
|
+
Buffer.from(fromHex(params.ruleHashHex, 32)),
|
|
1376
|
+
Buffer.from(fromHex(params.intentHashHex, 32)),
|
|
1377
|
+
encodeU64Le(params.payoutAmount),
|
|
1378
|
+
asPubkey(params.recipient).toBuffer(),
|
|
1379
|
+
]);
|
|
1380
|
+
}
|
|
1381
|
+
function encodeRegisterCoverageProductV2Data(params) {
|
|
1382
|
+
return Buffer.concat([
|
|
1383
|
+
IX_REGISTER_COVERAGE_PRODUCT_V2,
|
|
1384
|
+
Buffer.from(fromHex(params.productIdHashHex, 32)),
|
|
1385
|
+
encodeString(params.displayName),
|
|
1386
|
+
encodeString(params.metadataUri),
|
|
1387
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1388
|
+
encodeI64Le(BigInt(Math.trunc(params.durationSecs))),
|
|
1389
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumDueEverySecs))),
|
|
1390
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumGraceSecs))),
|
|
1391
|
+
encodeU64Le(params.premiumAmount),
|
|
1392
|
+
Buffer.from([params.active ? 1 : 0]),
|
|
1393
|
+
]);
|
|
1394
|
+
}
|
|
1395
|
+
function encodeUpdateCoverageProductV2Data(params) {
|
|
1396
|
+
return Buffer.concat([
|
|
1397
|
+
IX_UPDATE_COVERAGE_PRODUCT_V2,
|
|
1398
|
+
encodeString(params.displayName),
|
|
1399
|
+
encodeString(params.metadataUri),
|
|
1400
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1401
|
+
encodeI64Le(BigInt(Math.trunc(params.durationSecs))),
|
|
1402
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumDueEverySecs))),
|
|
1403
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumGraceSecs))),
|
|
1404
|
+
encodeU64Le(params.premiumAmount),
|
|
1405
|
+
Buffer.from([params.active ? 1 : 0]),
|
|
1406
|
+
]);
|
|
1407
|
+
}
|
|
1408
|
+
function encodeSubscribeCoverageProductV2Data(params) {
|
|
1409
|
+
return Buffer.concat([
|
|
1410
|
+
IX_SUBSCRIBE_COVERAGE_PRODUCT_V2,
|
|
1411
|
+
Buffer.from(fromHex(params.productIdHashHex, 32)),
|
|
1412
|
+
encodeI64Le(BigInt(Math.trunc(params.startsAt))),
|
|
1413
|
+
]);
|
|
1414
|
+
}
|
|
1415
|
+
function encodeIssueCoveragePolicyFromProductV2Data(params) {
|
|
1416
|
+
return Buffer.concat([
|
|
1417
|
+
IX_ISSUE_COVERAGE_POLICY_FROM_PRODUCT_V2,
|
|
1418
|
+
asPubkey(params.member).toBuffer(),
|
|
1419
|
+
Buffer.from(fromHex(params.productIdHashHex, 32)),
|
|
1420
|
+
encodeI64Le(BigInt(Math.trunc(params.startsAt))),
|
|
1421
|
+
]);
|
|
1422
|
+
}
|
|
1423
|
+
function encodeCreateCoveragePolicyData(params) {
|
|
1424
|
+
return Buffer.concat([
|
|
1425
|
+
IX_CREATE_COVERAGE_POLICY,
|
|
1426
|
+
asPubkey(params.member).toBuffer(),
|
|
1427
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1428
|
+
encodeI64Le(BigInt(Math.trunc(params.startsAt))),
|
|
1429
|
+
encodeI64Le(BigInt(Math.trunc(params.endsAt))),
|
|
1430
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumDueEverySecs))),
|
|
1431
|
+
encodeI64Le(BigInt(Math.trunc(params.premiumGraceSecs))),
|
|
1432
|
+
]);
|
|
1433
|
+
}
|
|
1434
|
+
function encodeMintPolicyNftData(params) {
|
|
1435
|
+
return Buffer.concat([
|
|
1436
|
+
IX_MINT_POLICY_NFT,
|
|
1437
|
+
asPubkey(params.nftMint).toBuffer(),
|
|
1438
|
+
encodeString(params.metadataUri),
|
|
1439
|
+
]);
|
|
1440
|
+
}
|
|
1441
|
+
function encodePayPremiumOnchainData(params) {
|
|
1442
|
+
return Buffer.concat([
|
|
1443
|
+
IX_PAY_PREMIUM_ONCHAIN,
|
|
1444
|
+
encodeU64Le(params.periodIndex),
|
|
1445
|
+
encodeU64Le(params.amount),
|
|
1446
|
+
]);
|
|
1447
|
+
}
|
|
1448
|
+
function encodeAttestPremiumPaidOffchainData(params) {
|
|
1449
|
+
return Buffer.concat([
|
|
1450
|
+
IX_ATTEST_PREMIUM_PAID_OFFCHAIN,
|
|
1451
|
+
asPubkey(params.member).toBuffer(),
|
|
1452
|
+
encodeU64Le(params.periodIndex),
|
|
1453
|
+
Buffer.from(fromHex(params.replayHashHex, 32)),
|
|
1454
|
+
encodeU64Le(params.amount),
|
|
1455
|
+
encodeI64Le(BigInt(Math.trunc(params.paidAtTs))),
|
|
1456
|
+
]);
|
|
1457
|
+
}
|
|
1458
|
+
function encodeSubmitCoverageClaimData(params) {
|
|
1459
|
+
return Buffer.concat([
|
|
1460
|
+
IX_SUBMIT_COVERAGE_CLAIM,
|
|
1461
|
+
asPubkey(params.member).toBuffer(),
|
|
1462
|
+
Buffer.from(fromHex(params.intentHashHex, 32)),
|
|
1463
|
+
Buffer.from(fromHex(params.eventHashHex, 32)),
|
|
1464
|
+
]);
|
|
1465
|
+
}
|
|
1466
|
+
function encodeSettleCoverageClaimData(params) {
|
|
1467
|
+
return Buffer.concat([
|
|
1468
|
+
IX_SETTLE_COVERAGE_CLAIM,
|
|
1469
|
+
encodeU64Le(params.payoutAmount),
|
|
1470
|
+
]);
|
|
1471
|
+
}
|
|
1472
|
+
function encodeMigratePoolV1ToV2Data(params) {
|
|
1473
|
+
return Buffer.concat([
|
|
1474
|
+
IX_MIGRATE_POOL_V1_TO_V2,
|
|
1475
|
+
Buffer.from([params.poolType & 0xff]),
|
|
1476
|
+
asPubkey(params.payoutAssetMint).toBuffer(),
|
|
1477
|
+
Buffer.from(fromHex(params.termsHashHex, 32)),
|
|
1478
|
+
Buffer.from(fromHex(params.payoutPolicyHashHex, 32)),
|
|
1479
|
+
Buffer.from([params.cycleMode & 0xff]),
|
|
1480
|
+
encodeString(params.metadataUri),
|
|
1481
|
+
]);
|
|
1482
|
+
}
|
|
1483
|
+
export function createProtocolClient(connection, programIdInput) {
|
|
1484
|
+
const programId = new PublicKey(programIdInput);
|
|
1485
|
+
return {
|
|
1486
|
+
connection,
|
|
1487
|
+
programId,
|
|
1488
|
+
buildInitializeProtocolTx(params) {
|
|
1489
|
+
const admin = new PublicKey(params.admin);
|
|
1490
|
+
const [configPda] = deriveConfigPda(programId);
|
|
1491
|
+
const instruction = new TransactionInstruction({
|
|
1492
|
+
programId,
|
|
1493
|
+
keys: [
|
|
1494
|
+
{ pubkey: admin, isSigner: true, isWritable: true },
|
|
1495
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1496
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1497
|
+
],
|
|
1498
|
+
data: encodeInitializeProtocolData(params),
|
|
1499
|
+
});
|
|
1500
|
+
return new Transaction({
|
|
1501
|
+
feePayer: admin,
|
|
1502
|
+
recentBlockhash: params.recentBlockhash,
|
|
1503
|
+
}).add(instruction);
|
|
1504
|
+
},
|
|
1505
|
+
buildSetProtocolPauseTx(params) {
|
|
1506
|
+
const admin = new PublicKey(params.admin);
|
|
1507
|
+
const [configPda] = deriveConfigPda(programId);
|
|
1508
|
+
const instruction = new TransactionInstruction({
|
|
1509
|
+
programId,
|
|
1510
|
+
keys: [
|
|
1511
|
+
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
1512
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1513
|
+
],
|
|
1514
|
+
data: encodeSetProtocolPauseData(params),
|
|
1515
|
+
});
|
|
1516
|
+
return new Transaction({
|
|
1517
|
+
feePayer: admin,
|
|
1518
|
+
recentBlockhash: params.recentBlockhash,
|
|
1519
|
+
}).add(instruction);
|
|
1520
|
+
},
|
|
1521
|
+
buildCreatePoolTx(params) {
|
|
1522
|
+
assertPoolIdSeedLength(params.poolId);
|
|
1523
|
+
const authority = new PublicKey(params.authority);
|
|
1524
|
+
const [configPda] = deriveConfigPda(programId);
|
|
1525
|
+
const [poolPda] = derivePoolPda({
|
|
1526
|
+
programId,
|
|
1527
|
+
authority,
|
|
1528
|
+
poolId: params.poolId,
|
|
1529
|
+
});
|
|
1530
|
+
const instruction = new TransactionInstruction({
|
|
1531
|
+
programId,
|
|
1532
|
+
keys: [
|
|
1533
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
1534
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
1535
|
+
{ pubkey: poolPda, isSigner: false, isWritable: true },
|
|
1536
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1537
|
+
],
|
|
1538
|
+
data: encodeCreatePoolData(params),
|
|
1539
|
+
});
|
|
1540
|
+
return new Transaction({
|
|
1541
|
+
feePayer: authority,
|
|
1542
|
+
recentBlockhash: params.recentBlockhash,
|
|
1543
|
+
}).add(instruction);
|
|
1544
|
+
},
|
|
1545
|
+
buildSetPoolStatusTx(params) {
|
|
1546
|
+
const authority = new PublicKey(params.authority);
|
|
1547
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1548
|
+
const instruction = new TransactionInstruction({
|
|
1549
|
+
programId,
|
|
1550
|
+
keys: [
|
|
1551
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1552
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
1553
|
+
],
|
|
1554
|
+
data: encodeSetPoolStatusData(params),
|
|
1555
|
+
});
|
|
1556
|
+
return new Transaction({
|
|
1557
|
+
feePayer: authority,
|
|
1558
|
+
recentBlockhash: params.recentBlockhash,
|
|
1559
|
+
}).add(instruction);
|
|
1560
|
+
},
|
|
1561
|
+
buildSetCycleWindowTx(params) {
|
|
1562
|
+
const authority = new PublicKey(params.authority);
|
|
1563
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1564
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1565
|
+
const [cycleWindowPda] = deriveCycleWindowPda({
|
|
1566
|
+
programId,
|
|
1567
|
+
poolAddress,
|
|
1568
|
+
cycleHash,
|
|
1569
|
+
});
|
|
1570
|
+
const instruction = new TransactionInstruction({
|
|
1571
|
+
programId,
|
|
1572
|
+
keys: [
|
|
1573
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
1574
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
1575
|
+
{ pubkey: cycleWindowPda, isSigner: false, isWritable: true },
|
|
1576
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1577
|
+
],
|
|
1578
|
+
data: encodeSetCycleWindowData(params),
|
|
1579
|
+
});
|
|
1580
|
+
return new Transaction({
|
|
1581
|
+
feePayer: authority,
|
|
1582
|
+
recentBlockhash: params.recentBlockhash,
|
|
1583
|
+
}).add(instruction);
|
|
1584
|
+
},
|
|
1585
|
+
buildFundPoolTx(params) {
|
|
1586
|
+
const funder = new PublicKey(params.funder);
|
|
1587
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1588
|
+
const instruction = new TransactionInstruction({
|
|
1589
|
+
programId,
|
|
1590
|
+
keys: [
|
|
1591
|
+
{ pubkey: funder, isSigner: true, isWritable: true },
|
|
1592
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
1593
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1594
|
+
],
|
|
1595
|
+
data: encodeFundPoolData(params),
|
|
1596
|
+
});
|
|
1597
|
+
return new Transaction({
|
|
1598
|
+
feePayer: funder,
|
|
1599
|
+
recentBlockhash: params.recentBlockhash,
|
|
1600
|
+
}).add(instruction);
|
|
1601
|
+
},
|
|
1602
|
+
buildRegisterOracleTx(params) {
|
|
1603
|
+
const oracle = new PublicKey(params.oracle);
|
|
1604
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
1605
|
+
programId,
|
|
1606
|
+
oracle,
|
|
1607
|
+
});
|
|
1608
|
+
const instruction = new TransactionInstruction({
|
|
1609
|
+
programId,
|
|
1610
|
+
keys: [
|
|
1611
|
+
{ pubkey: oracle, isSigner: true, isWritable: true },
|
|
1612
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: true },
|
|
1613
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1614
|
+
],
|
|
1615
|
+
data: encodeRegisterOracleData(params),
|
|
1616
|
+
});
|
|
1617
|
+
return new Transaction({
|
|
1618
|
+
feePayer: oracle,
|
|
1619
|
+
recentBlockhash: params.recentBlockhash,
|
|
1620
|
+
}).add(instruction);
|
|
1621
|
+
},
|
|
1622
|
+
buildSetPoolOracleTx(params) {
|
|
1623
|
+
const authority = new PublicKey(params.authority);
|
|
1624
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1625
|
+
const oracle = new PublicKey(params.oracle);
|
|
1626
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
1627
|
+
programId,
|
|
1628
|
+
oracle,
|
|
1629
|
+
});
|
|
1630
|
+
const [poolOraclePda] = derivePoolOraclePda({
|
|
1631
|
+
programId,
|
|
1632
|
+
poolAddress,
|
|
1633
|
+
oracle,
|
|
1634
|
+
});
|
|
1635
|
+
const instruction = new TransactionInstruction({
|
|
1636
|
+
programId,
|
|
1637
|
+
keys: [
|
|
1638
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
1639
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
1640
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: false },
|
|
1641
|
+
{ pubkey: poolOraclePda, isSigner: false, isWritable: true },
|
|
1642
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1643
|
+
],
|
|
1644
|
+
data: encodeSetPoolOracleData(params),
|
|
1645
|
+
});
|
|
1646
|
+
return new Transaction({
|
|
1647
|
+
feePayer: authority,
|
|
1648
|
+
recentBlockhash: params.recentBlockhash,
|
|
1649
|
+
}).add(instruction);
|
|
1650
|
+
},
|
|
1651
|
+
buildEnrollMemberTx(params) {
|
|
1652
|
+
const member = new PublicKey(params.member);
|
|
1653
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1654
|
+
const [membershipPda] = deriveMembershipPda({
|
|
1655
|
+
programId,
|
|
1656
|
+
poolAddress,
|
|
1657
|
+
member,
|
|
1658
|
+
});
|
|
1659
|
+
const keys = [
|
|
1660
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
1661
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
1662
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: true },
|
|
1663
|
+
];
|
|
1664
|
+
if (params.tokenGateAccount) {
|
|
1665
|
+
keys.push({
|
|
1666
|
+
pubkey: new PublicKey(params.tokenGateAccount),
|
|
1667
|
+
isSigner: false,
|
|
1668
|
+
isWritable: false,
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
if (params.inviteIssuer) {
|
|
1672
|
+
keys.push({
|
|
1673
|
+
pubkey: new PublicKey(params.inviteIssuer),
|
|
1674
|
+
isSigner: true,
|
|
1675
|
+
isWritable: false,
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
keys.push({
|
|
1679
|
+
pubkey: SystemProgram.programId,
|
|
1680
|
+
isSigner: false,
|
|
1681
|
+
isWritable: false,
|
|
1682
|
+
});
|
|
1683
|
+
const instruction = new TransactionInstruction({
|
|
1684
|
+
programId,
|
|
1685
|
+
keys,
|
|
1686
|
+
data: encodeEnrollMemberData(params),
|
|
1687
|
+
});
|
|
1688
|
+
return new Transaction({
|
|
1689
|
+
feePayer: member,
|
|
1690
|
+
recentBlockhash: params.recentBlockhash,
|
|
1691
|
+
}).add(instruction);
|
|
1692
|
+
},
|
|
1693
|
+
buildRevokeMemberTx(params) {
|
|
1694
|
+
const authority = new PublicKey(params.authority);
|
|
1695
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1696
|
+
const member = new PublicKey(params.member);
|
|
1697
|
+
const [membershipPda] = deriveMembershipPda({
|
|
1698
|
+
programId,
|
|
1699
|
+
poolAddress,
|
|
1700
|
+
member,
|
|
1701
|
+
});
|
|
1702
|
+
const instruction = new TransactionInstruction({
|
|
1703
|
+
programId,
|
|
1704
|
+
keys: [
|
|
1705
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1706
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
1707
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: true },
|
|
1708
|
+
],
|
|
1709
|
+
data: IX_REVOKE_MEMBER,
|
|
1710
|
+
});
|
|
1711
|
+
return new Transaction({
|
|
1712
|
+
feePayer: authority,
|
|
1713
|
+
recentBlockhash: params.recentBlockhash,
|
|
1714
|
+
}).add(instruction);
|
|
1715
|
+
},
|
|
1716
|
+
buildSubmitOutcomeAttestationTx(params) {
|
|
1717
|
+
const oracle = new PublicKey(params.oracle);
|
|
1718
|
+
const member = new PublicKey(params.member);
|
|
1719
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1720
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1721
|
+
const replayHash = hashStringTo32(params.replayKey);
|
|
1722
|
+
const [poolOraclePda] = derivePoolOraclePda({
|
|
1723
|
+
programId,
|
|
1724
|
+
poolAddress,
|
|
1725
|
+
oracle,
|
|
1726
|
+
});
|
|
1727
|
+
const [membershipPda] = deriveMembershipPda({
|
|
1728
|
+
programId,
|
|
1729
|
+
poolAddress,
|
|
1730
|
+
member,
|
|
1731
|
+
});
|
|
1732
|
+
const [cycleOutcomePda] = deriveCycleOutcomePda({
|
|
1733
|
+
programId,
|
|
1734
|
+
poolAddress,
|
|
1735
|
+
member,
|
|
1736
|
+
cycleHash,
|
|
1737
|
+
});
|
|
1738
|
+
const [replayPda] = deriveReplayPda({
|
|
1739
|
+
programId,
|
|
1740
|
+
poolAddress,
|
|
1741
|
+
replayHash,
|
|
1742
|
+
});
|
|
1743
|
+
const instruction = new TransactionInstruction({
|
|
1744
|
+
programId,
|
|
1745
|
+
keys: [
|
|
1746
|
+
{ pubkey: oracle, isSigner: true, isWritable: true },
|
|
1747
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
1748
|
+
{ pubkey: poolOraclePda, isSigner: false, isWritable: false },
|
|
1749
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
1750
|
+
{ pubkey: cycleOutcomePda, isSigner: false, isWritable: true },
|
|
1751
|
+
{ pubkey: replayPda, isSigner: false, isWritable: true },
|
|
1752
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1753
|
+
],
|
|
1754
|
+
data: encodeSubmitOutcomeAttestationData(params),
|
|
1755
|
+
});
|
|
1756
|
+
return new Transaction({
|
|
1757
|
+
feePayer: oracle,
|
|
1758
|
+
recentBlockhash: params.recentBlockhash,
|
|
1759
|
+
}).add(instruction);
|
|
1760
|
+
},
|
|
1761
|
+
buildSubmitClaimTx(params) {
|
|
1762
|
+
const claimant = new PublicKey(params.claimant);
|
|
1763
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1764
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1765
|
+
const [membershipPda] = deriveMembershipPda({
|
|
1766
|
+
programId,
|
|
1767
|
+
poolAddress,
|
|
1768
|
+
member: claimant,
|
|
1769
|
+
});
|
|
1770
|
+
const [cycleOutcomePda] = deriveCycleOutcomePda({
|
|
1771
|
+
programId,
|
|
1772
|
+
poolAddress,
|
|
1773
|
+
member: claimant,
|
|
1774
|
+
cycleHash,
|
|
1775
|
+
});
|
|
1776
|
+
const [claimPda] = deriveClaimPda({
|
|
1777
|
+
programId,
|
|
1778
|
+
poolAddress,
|
|
1779
|
+
member: claimant,
|
|
1780
|
+
cycleHash,
|
|
1781
|
+
});
|
|
1782
|
+
const [cycleWindowPda] = deriveCycleWindowPda({
|
|
1783
|
+
programId,
|
|
1784
|
+
poolAddress,
|
|
1785
|
+
cycleHash,
|
|
1786
|
+
});
|
|
1787
|
+
const instruction = new TransactionInstruction({
|
|
1788
|
+
programId,
|
|
1789
|
+
keys: [
|
|
1790
|
+
{ pubkey: claimant, isSigner: true, isWritable: true },
|
|
1791
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
1792
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
1793
|
+
{ pubkey: cycleOutcomePda, isSigner: false, isWritable: true },
|
|
1794
|
+
{ pubkey: cycleWindowPda, isSigner: false, isWritable: false },
|
|
1795
|
+
{ pubkey: claimPda, isSigner: false, isWritable: true },
|
|
1796
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1797
|
+
],
|
|
1798
|
+
data: encodeSubmitClaimData(params),
|
|
1799
|
+
});
|
|
1800
|
+
return new Transaction({
|
|
1801
|
+
feePayer: claimant,
|
|
1802
|
+
recentBlockhash: params.recentBlockhash,
|
|
1803
|
+
}).add(instruction);
|
|
1804
|
+
},
|
|
1805
|
+
buildSubmitOutcomeAttestationVoteTx(params) {
|
|
1806
|
+
const oracle = new PublicKey(params.oracle);
|
|
1807
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1808
|
+
const member = new PublicKey(params.member);
|
|
1809
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1810
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
1811
|
+
const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
|
|
1812
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
1813
|
+
programId,
|
|
1814
|
+
oracle,
|
|
1815
|
+
});
|
|
1816
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
1817
|
+
const [stakePositionPda] = deriveOracleStakePda({
|
|
1818
|
+
programId,
|
|
1819
|
+
oracle,
|
|
1820
|
+
staker: oracle,
|
|
1821
|
+
});
|
|
1822
|
+
const [poolOraclePolicyPda] = derivePoolOraclePolicyPda({
|
|
1823
|
+
programId,
|
|
1824
|
+
poolAddress,
|
|
1825
|
+
});
|
|
1826
|
+
const [poolOraclePda] = derivePoolOraclePda({
|
|
1827
|
+
programId,
|
|
1828
|
+
poolAddress,
|
|
1829
|
+
oracle,
|
|
1830
|
+
});
|
|
1831
|
+
const [membershipPda] = deriveMembershipPda({
|
|
1832
|
+
programId,
|
|
1833
|
+
poolAddress,
|
|
1834
|
+
member,
|
|
1835
|
+
});
|
|
1836
|
+
const [poolRulePda] = derivePoolRulePda({
|
|
1837
|
+
programId,
|
|
1838
|
+
poolAddress,
|
|
1839
|
+
ruleHash,
|
|
1840
|
+
});
|
|
1841
|
+
const [schemaPda] = deriveSchemaPda({
|
|
1842
|
+
programId,
|
|
1843
|
+
schemaKeyHash,
|
|
1844
|
+
});
|
|
1845
|
+
const [votePda] = deriveAttestationVotePda({
|
|
1846
|
+
programId,
|
|
1847
|
+
poolAddress,
|
|
1848
|
+
member,
|
|
1849
|
+
cycleHash,
|
|
1850
|
+
ruleHash,
|
|
1851
|
+
oracle,
|
|
1852
|
+
});
|
|
1853
|
+
const [aggregatePda] = deriveOutcomeAggregatePda({
|
|
1854
|
+
programId,
|
|
1855
|
+
poolAddress,
|
|
1856
|
+
member,
|
|
1857
|
+
cycleHash,
|
|
1858
|
+
ruleHash,
|
|
1859
|
+
});
|
|
1860
|
+
const instruction = new TransactionInstruction({
|
|
1861
|
+
programId,
|
|
1862
|
+
keys: [
|
|
1863
|
+
{ pubkey: oracle, isSigner: true, isWritable: true },
|
|
1864
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: false },
|
|
1865
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
1866
|
+
{ pubkey: stakePositionPda, isSigner: false, isWritable: false },
|
|
1867
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
1868
|
+
{ pubkey: poolOraclePolicyPda, isSigner: false, isWritable: false },
|
|
1869
|
+
{ pubkey: poolOraclePda, isSigner: false, isWritable: false },
|
|
1870
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
1871
|
+
{ pubkey: poolRulePda, isSigner: false, isWritable: false },
|
|
1872
|
+
{ pubkey: schemaPda, isSigner: false, isWritable: false },
|
|
1873
|
+
{ pubkey: votePda, isSigner: false, isWritable: true },
|
|
1874
|
+
{ pubkey: aggregatePda, isSigner: false, isWritable: true },
|
|
1875
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1876
|
+
],
|
|
1877
|
+
data: encodeSubmitOutcomeAttestationVoteData(params),
|
|
1878
|
+
});
|
|
1879
|
+
return new Transaction({
|
|
1880
|
+
feePayer: oracle,
|
|
1881
|
+
recentBlockhash: params.recentBlockhash,
|
|
1882
|
+
}).add(instruction);
|
|
1883
|
+
},
|
|
1884
|
+
buildFinalizeCycleOutcomeTx(params) {
|
|
1885
|
+
const payer = new PublicKey(params.payer);
|
|
1886
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
1887
|
+
const member = new PublicKey(params.member);
|
|
1888
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
1889
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
1890
|
+
const [aggregatePda] = deriveOutcomeAggregatePda({
|
|
1891
|
+
programId,
|
|
1892
|
+
poolAddress,
|
|
1893
|
+
member,
|
|
1894
|
+
cycleHash,
|
|
1895
|
+
ruleHash,
|
|
1896
|
+
});
|
|
1897
|
+
const instruction = new TransactionInstruction({
|
|
1898
|
+
programId,
|
|
1899
|
+
keys: [{ pubkey: aggregatePda, isSigner: false, isWritable: true }],
|
|
1900
|
+
data: IX_FINALIZE_CYCLE_OUTCOME,
|
|
1901
|
+
});
|
|
1902
|
+
return new Transaction({
|
|
1903
|
+
feePayer: payer,
|
|
1904
|
+
recentBlockhash: params.recentBlockhash,
|
|
1905
|
+
}).add(instruction);
|
|
1906
|
+
},
|
|
1907
|
+
buildInitializeProtocolV2Tx(params) {
|
|
1908
|
+
const admin = new PublicKey(params.admin);
|
|
1909
|
+
const [configPda] = deriveConfigV2Pda(programId);
|
|
1910
|
+
const instruction = new TransactionInstruction({
|
|
1911
|
+
programId,
|
|
1912
|
+
keys: [
|
|
1913
|
+
{ pubkey: admin, isSigner: true, isWritable: true },
|
|
1914
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1915
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1916
|
+
],
|
|
1917
|
+
data: encodeInitializeProtocolV2Data(params),
|
|
1918
|
+
});
|
|
1919
|
+
return new Transaction({
|
|
1920
|
+
feePayer: admin,
|
|
1921
|
+
recentBlockhash: params.recentBlockhash,
|
|
1922
|
+
}).add(instruction);
|
|
1923
|
+
},
|
|
1924
|
+
buildSetProtocolParamsTx(params) {
|
|
1925
|
+
const governanceAuthority = new PublicKey(params.governanceAuthority);
|
|
1926
|
+
const [configPda] = deriveConfigV2Pda(programId);
|
|
1927
|
+
const instruction = new TransactionInstruction({
|
|
1928
|
+
programId,
|
|
1929
|
+
keys: [
|
|
1930
|
+
{ pubkey: governanceAuthority, isSigner: true, isWritable: false },
|
|
1931
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1932
|
+
],
|
|
1933
|
+
data: encodeSetProtocolParamsData(params),
|
|
1934
|
+
});
|
|
1935
|
+
return new Transaction({
|
|
1936
|
+
feePayer: governanceAuthority,
|
|
1937
|
+
recentBlockhash: params.recentBlockhash,
|
|
1938
|
+
}).add(instruction);
|
|
1939
|
+
},
|
|
1940
|
+
buildRotateGovernanceAuthorityTx(params) {
|
|
1941
|
+
const governanceAuthority = new PublicKey(params.governanceAuthority);
|
|
1942
|
+
const [configPda] = deriveConfigV2Pda(programId);
|
|
1943
|
+
const instruction = new TransactionInstruction({
|
|
1944
|
+
programId,
|
|
1945
|
+
keys: [
|
|
1946
|
+
{ pubkey: governanceAuthority, isSigner: true, isWritable: false },
|
|
1947
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1948
|
+
],
|
|
1949
|
+
data: encodeRotateGovernanceAuthorityData(params),
|
|
1950
|
+
});
|
|
1951
|
+
return new Transaction({
|
|
1952
|
+
feePayer: governanceAuthority,
|
|
1953
|
+
recentBlockhash: params.recentBlockhash,
|
|
1954
|
+
}).add(instruction);
|
|
1955
|
+
},
|
|
1956
|
+
buildRegisterOracleV2Tx(params) {
|
|
1957
|
+
const admin = new PublicKey(params.admin);
|
|
1958
|
+
const oraclePubkey = new PublicKey(params.oraclePubkey);
|
|
1959
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
1960
|
+
programId,
|
|
1961
|
+
oracle: oraclePubkey,
|
|
1962
|
+
});
|
|
1963
|
+
const [oracleProfilePda] = deriveOracleProfilePda({
|
|
1964
|
+
programId,
|
|
1965
|
+
oracle: oraclePubkey,
|
|
1966
|
+
});
|
|
1967
|
+
const instruction = new TransactionInstruction({
|
|
1968
|
+
programId,
|
|
1969
|
+
keys: [
|
|
1970
|
+
{ pubkey: admin, isSigner: true, isWritable: true },
|
|
1971
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: true },
|
|
1972
|
+
{ pubkey: oracleProfilePda, isSigner: false, isWritable: true },
|
|
1973
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1974
|
+
],
|
|
1975
|
+
data: encodeRegisterOracleV2Data(params),
|
|
1976
|
+
});
|
|
1977
|
+
return new Transaction({
|
|
1978
|
+
feePayer: admin,
|
|
1979
|
+
recentBlockhash: params.recentBlockhash,
|
|
1980
|
+
}).add(instruction);
|
|
1981
|
+
},
|
|
1982
|
+
buildClaimOracleV2Tx(params) {
|
|
1983
|
+
const oracle = new PublicKey(params.oracle);
|
|
1984
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
1985
|
+
programId,
|
|
1986
|
+
oracle,
|
|
1987
|
+
});
|
|
1988
|
+
const [oracleProfilePda] = deriveOracleProfilePda({
|
|
1989
|
+
programId,
|
|
1990
|
+
oracle,
|
|
1991
|
+
});
|
|
1992
|
+
const instruction = new TransactionInstruction({
|
|
1993
|
+
programId,
|
|
1994
|
+
keys: [
|
|
1995
|
+
{ pubkey: oracle, isSigner: true, isWritable: false },
|
|
1996
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: true },
|
|
1997
|
+
{ pubkey: oracleProfilePda, isSigner: false, isWritable: true },
|
|
1998
|
+
],
|
|
1999
|
+
data: IX_CLAIM_ORACLE_V2,
|
|
2000
|
+
});
|
|
2001
|
+
return new Transaction({
|
|
2002
|
+
feePayer: oracle,
|
|
2003
|
+
recentBlockhash: params.recentBlockhash,
|
|
2004
|
+
}).add(instruction);
|
|
2005
|
+
},
|
|
2006
|
+
buildUpdateOracleProfileV2Tx(params) {
|
|
2007
|
+
const authority = new PublicKey(params.authority);
|
|
2008
|
+
const [oracleProfilePda] = deriveOracleProfilePda({
|
|
2009
|
+
programId,
|
|
2010
|
+
oracle: params.oracle,
|
|
2011
|
+
});
|
|
2012
|
+
const instruction = new TransactionInstruction({
|
|
2013
|
+
programId,
|
|
2014
|
+
keys: [
|
|
2015
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2016
|
+
{ pubkey: oracleProfilePda, isSigner: false, isWritable: true },
|
|
2017
|
+
],
|
|
2018
|
+
data: encodeUpdateOracleProfileV2Data(params),
|
|
2019
|
+
});
|
|
2020
|
+
return new Transaction({
|
|
2021
|
+
feePayer: authority,
|
|
2022
|
+
recentBlockhash: params.recentBlockhash,
|
|
2023
|
+
}).add(instruction);
|
|
2024
|
+
},
|
|
2025
|
+
buildUpdateOracleMetadataTx(params) {
|
|
2026
|
+
const oracle = new PublicKey(params.oracle);
|
|
2027
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
2028
|
+
programId,
|
|
2029
|
+
oracle,
|
|
2030
|
+
});
|
|
2031
|
+
const instruction = new TransactionInstruction({
|
|
2032
|
+
programId,
|
|
2033
|
+
keys: [
|
|
2034
|
+
{ pubkey: oracle, isSigner: true, isWritable: false },
|
|
2035
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: true },
|
|
2036
|
+
],
|
|
2037
|
+
data: encodeUpdateOracleMetadataData(params),
|
|
2038
|
+
});
|
|
2039
|
+
return new Transaction({
|
|
2040
|
+
feePayer: oracle,
|
|
2041
|
+
recentBlockhash: params.recentBlockhash,
|
|
2042
|
+
}).add(instruction);
|
|
2043
|
+
},
|
|
2044
|
+
buildStakeOracleTx(params) {
|
|
2045
|
+
const staker = new PublicKey(params.staker);
|
|
2046
|
+
const oracle = new PublicKey(params.oracle);
|
|
2047
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2048
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
2049
|
+
programId,
|
|
2050
|
+
oracle,
|
|
2051
|
+
});
|
|
2052
|
+
const [stakePositionPda] = deriveOracleStakePda({
|
|
2053
|
+
programId,
|
|
2054
|
+
oracle,
|
|
2055
|
+
staker,
|
|
2056
|
+
});
|
|
2057
|
+
const instruction = new TransactionInstruction({
|
|
2058
|
+
programId,
|
|
2059
|
+
keys: [
|
|
2060
|
+
{ pubkey: staker, isSigner: true, isWritable: true },
|
|
2061
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2062
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: false },
|
|
2063
|
+
{ pubkey: stakePositionPda, isSigner: false, isWritable: true },
|
|
2064
|
+
{ pubkey: new PublicKey(params.stakeMint), isSigner: false, isWritable: true },
|
|
2065
|
+
{ pubkey: new PublicKey(params.stakeVault), isSigner: true, isWritable: true },
|
|
2066
|
+
{ pubkey: new PublicKey(params.stakerTokenAccount), isSigner: false, isWritable: true },
|
|
2067
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2068
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2069
|
+
],
|
|
2070
|
+
data: encodeStakeOracleData(params),
|
|
2071
|
+
});
|
|
2072
|
+
return new Transaction({
|
|
2073
|
+
feePayer: staker,
|
|
2074
|
+
recentBlockhash: params.recentBlockhash,
|
|
2075
|
+
}).add(instruction);
|
|
2076
|
+
},
|
|
2077
|
+
buildRequestUnstakeTx(params) {
|
|
2078
|
+
const staker = new PublicKey(params.staker);
|
|
2079
|
+
const oracle = new PublicKey(params.oracle);
|
|
2080
|
+
const [stakePositionPda] = deriveOracleStakePda({
|
|
2081
|
+
programId,
|
|
2082
|
+
oracle,
|
|
2083
|
+
staker,
|
|
2084
|
+
});
|
|
2085
|
+
const instruction = new TransactionInstruction({
|
|
2086
|
+
programId,
|
|
2087
|
+
keys: [
|
|
2088
|
+
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
2089
|
+
{ pubkey: stakePositionPda, isSigner: false, isWritable: true },
|
|
2090
|
+
],
|
|
2091
|
+
data: encodeRequestUnstakeData(params),
|
|
2092
|
+
});
|
|
2093
|
+
return new Transaction({
|
|
2094
|
+
feePayer: staker,
|
|
2095
|
+
recentBlockhash: params.recentBlockhash,
|
|
2096
|
+
}).add(instruction);
|
|
2097
|
+
},
|
|
2098
|
+
buildFinalizeUnstakeTx(params) {
|
|
2099
|
+
const staker = new PublicKey(params.staker);
|
|
2100
|
+
const oracle = new PublicKey(params.oracle);
|
|
2101
|
+
const [stakePositionPda] = deriveOracleStakePda({
|
|
2102
|
+
programId,
|
|
2103
|
+
oracle,
|
|
2104
|
+
staker,
|
|
2105
|
+
});
|
|
2106
|
+
const instruction = new TransactionInstruction({
|
|
2107
|
+
programId,
|
|
2108
|
+
keys: [
|
|
2109
|
+
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
2110
|
+
{ pubkey: stakePositionPda, isSigner: false, isWritable: true },
|
|
2111
|
+
{ pubkey: new PublicKey(params.stakeVault), isSigner: false, isWritable: true },
|
|
2112
|
+
{ pubkey: new PublicKey(params.destinationTokenAccount), isSigner: false, isWritable: true },
|
|
2113
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2114
|
+
],
|
|
2115
|
+
data: IX_FINALIZE_UNSTAKE,
|
|
2116
|
+
});
|
|
2117
|
+
return new Transaction({
|
|
2118
|
+
feePayer: staker,
|
|
2119
|
+
recentBlockhash: params.recentBlockhash,
|
|
2120
|
+
}).add(instruction);
|
|
2121
|
+
},
|
|
2122
|
+
buildSlashOracleTx(params) {
|
|
2123
|
+
const governanceAuthority = new PublicKey(params.governanceAuthority);
|
|
2124
|
+
const oracle = new PublicKey(params.oracle);
|
|
2125
|
+
const staker = new PublicKey(params.staker);
|
|
2126
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2127
|
+
const [stakePositionPda] = deriveOracleStakePda({
|
|
2128
|
+
programId,
|
|
2129
|
+
oracle,
|
|
2130
|
+
staker,
|
|
2131
|
+
});
|
|
2132
|
+
const instruction = new TransactionInstruction({
|
|
2133
|
+
programId,
|
|
2134
|
+
keys: [
|
|
2135
|
+
{ pubkey: governanceAuthority, isSigner: true, isWritable: false },
|
|
2136
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2137
|
+
{ pubkey: stakePositionPda, isSigner: false, isWritable: true },
|
|
2138
|
+
{ pubkey: new PublicKey(params.stakeVault), isSigner: false, isWritable: true },
|
|
2139
|
+
{ pubkey: new PublicKey(params.slashTreasuryTokenAccount), isSigner: false, isWritable: true },
|
|
2140
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2141
|
+
],
|
|
2142
|
+
data: encodeSlashOracleData(params),
|
|
2143
|
+
});
|
|
2144
|
+
return new Transaction({
|
|
2145
|
+
feePayer: governanceAuthority,
|
|
2146
|
+
recentBlockhash: params.recentBlockhash,
|
|
2147
|
+
}).add(instruction);
|
|
2148
|
+
},
|
|
2149
|
+
buildCreatePoolV2Tx(params) {
|
|
2150
|
+
const authority = new PublicKey(params.authority);
|
|
2151
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2152
|
+
const [poolAddress] = derivePoolPda({
|
|
2153
|
+
programId,
|
|
2154
|
+
authority,
|
|
2155
|
+
poolId: params.poolId,
|
|
2156
|
+
});
|
|
2157
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2158
|
+
programId,
|
|
2159
|
+
poolAddress,
|
|
2160
|
+
});
|
|
2161
|
+
const [oraclePolicyPda] = derivePoolOraclePolicyPda({
|
|
2162
|
+
programId,
|
|
2163
|
+
poolAddress,
|
|
2164
|
+
});
|
|
2165
|
+
const instruction = new TransactionInstruction({
|
|
2166
|
+
programId,
|
|
2167
|
+
keys: [
|
|
2168
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2169
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2170
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
2171
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: true },
|
|
2172
|
+
{ pubkey: oraclePolicyPda, isSigner: false, isWritable: true },
|
|
2173
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2174
|
+
],
|
|
2175
|
+
data: encodeCreatePoolV2Data(params),
|
|
2176
|
+
});
|
|
2177
|
+
return new Transaction({
|
|
2178
|
+
feePayer: authority,
|
|
2179
|
+
recentBlockhash: params.recentBlockhash,
|
|
2180
|
+
}).add(instruction);
|
|
2181
|
+
},
|
|
2182
|
+
buildSetPoolOraclePolicyTx(params) {
|
|
2183
|
+
const authority = new PublicKey(params.authority);
|
|
2184
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2185
|
+
const [oraclePolicyPda] = derivePoolOraclePolicyPda({
|
|
2186
|
+
programId,
|
|
2187
|
+
poolAddress,
|
|
2188
|
+
});
|
|
2189
|
+
const instruction = new TransactionInstruction({
|
|
2190
|
+
programId,
|
|
2191
|
+
keys: [
|
|
2192
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2193
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2194
|
+
{ pubkey: oraclePolicyPda, isSigner: false, isWritable: true },
|
|
2195
|
+
],
|
|
2196
|
+
data: encodeSetPoolOraclePolicyData(params),
|
|
2197
|
+
});
|
|
2198
|
+
return new Transaction({
|
|
2199
|
+
feePayer: authority,
|
|
2200
|
+
recentBlockhash: params.recentBlockhash,
|
|
2201
|
+
}).add(instruction);
|
|
2202
|
+
},
|
|
2203
|
+
buildSetPoolTermsHashTx(params) {
|
|
2204
|
+
const authority = new PublicKey(params.authority);
|
|
2205
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2206
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2207
|
+
programId,
|
|
2208
|
+
poolAddress,
|
|
2209
|
+
});
|
|
2210
|
+
const instruction = new TransactionInstruction({
|
|
2211
|
+
programId,
|
|
2212
|
+
keys: [
|
|
2213
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2214
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2215
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: true },
|
|
2216
|
+
],
|
|
2217
|
+
data: encodeSetPoolTermsHashData(params),
|
|
2218
|
+
});
|
|
2219
|
+
return new Transaction({
|
|
2220
|
+
feePayer: authority,
|
|
2221
|
+
recentBlockhash: params.recentBlockhash,
|
|
2222
|
+
}).add(instruction);
|
|
2223
|
+
},
|
|
2224
|
+
buildRegisterOutcomeSchemaTx(params) {
|
|
2225
|
+
const publisher = new PublicKey(params.publisher);
|
|
2226
|
+
const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
|
|
2227
|
+
const [schemaPda] = deriveSchemaPda({
|
|
2228
|
+
programId,
|
|
2229
|
+
schemaKeyHash,
|
|
2230
|
+
});
|
|
2231
|
+
const instruction = new TransactionInstruction({
|
|
2232
|
+
programId,
|
|
2233
|
+
keys: [
|
|
2234
|
+
{ pubkey: publisher, isSigner: true, isWritable: true },
|
|
2235
|
+
{ pubkey: schemaPda, isSigner: false, isWritable: true },
|
|
2236
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2237
|
+
],
|
|
2238
|
+
data: encodeRegisterOutcomeSchemaData(params),
|
|
2239
|
+
});
|
|
2240
|
+
return new Transaction({
|
|
2241
|
+
feePayer: publisher,
|
|
2242
|
+
recentBlockhash: params.recentBlockhash,
|
|
2243
|
+
}).add(instruction);
|
|
2244
|
+
},
|
|
2245
|
+
buildVerifyOutcomeSchemaTx(params) {
|
|
2246
|
+
const governanceAuthority = new PublicKey(params.governanceAuthority);
|
|
2247
|
+
const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
|
|
2248
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2249
|
+
const [schemaPda] = deriveSchemaPda({
|
|
2250
|
+
programId,
|
|
2251
|
+
schemaKeyHash,
|
|
2252
|
+
});
|
|
2253
|
+
const instruction = new TransactionInstruction({
|
|
2254
|
+
programId,
|
|
2255
|
+
keys: [
|
|
2256
|
+
{ pubkey: governanceAuthority, isSigner: true, isWritable: false },
|
|
2257
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2258
|
+
{ pubkey: schemaPda, isSigner: false, isWritable: true },
|
|
2259
|
+
],
|
|
2260
|
+
data: encodeVerifyOutcomeSchemaData(params),
|
|
2261
|
+
});
|
|
2262
|
+
return new Transaction({
|
|
2263
|
+
feePayer: governanceAuthority,
|
|
2264
|
+
recentBlockhash: params.recentBlockhash,
|
|
2265
|
+
}).add(instruction);
|
|
2266
|
+
},
|
|
2267
|
+
buildSetPoolOutcomeRuleTx(params) {
|
|
2268
|
+
const authority = new PublicKey(params.authority);
|
|
2269
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2270
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
2271
|
+
const schemaKeyHash = fromHex(params.schemaKeyHashHex, 32);
|
|
2272
|
+
const [schemaPda] = deriveSchemaPda({
|
|
2273
|
+
programId,
|
|
2274
|
+
schemaKeyHash,
|
|
2275
|
+
});
|
|
2276
|
+
const [poolRulePda] = derivePoolRulePda({
|
|
2277
|
+
programId,
|
|
2278
|
+
poolAddress,
|
|
2279
|
+
ruleHash,
|
|
2280
|
+
});
|
|
2281
|
+
const instruction = new TransactionInstruction({
|
|
2282
|
+
programId,
|
|
2283
|
+
keys: [
|
|
2284
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2285
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2286
|
+
{ pubkey: schemaPda, isSigner: false, isWritable: false },
|
|
2287
|
+
{ pubkey: poolRulePda, isSigner: false, isWritable: true },
|
|
2288
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2289
|
+
],
|
|
2290
|
+
data: encodeSetPoolOutcomeRuleData(params),
|
|
2291
|
+
});
|
|
2292
|
+
return new Transaction({
|
|
2293
|
+
feePayer: authority,
|
|
2294
|
+
recentBlockhash: params.recentBlockhash,
|
|
2295
|
+
}).add(instruction);
|
|
2296
|
+
},
|
|
2297
|
+
buildRegisterInviteIssuerTx(params) {
|
|
2298
|
+
const issuer = new PublicKey(params.issuer);
|
|
2299
|
+
const [inviteIssuerPda] = deriveInviteIssuerPda({
|
|
2300
|
+
programId,
|
|
2301
|
+
issuer,
|
|
2302
|
+
});
|
|
2303
|
+
const instruction = new TransactionInstruction({
|
|
2304
|
+
programId,
|
|
2305
|
+
keys: [
|
|
2306
|
+
{ pubkey: issuer, isSigner: true, isWritable: true },
|
|
2307
|
+
{ pubkey: inviteIssuerPda, isSigner: false, isWritable: true },
|
|
2308
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2309
|
+
],
|
|
2310
|
+
data: encodeRegisterInviteIssuerData(params),
|
|
2311
|
+
});
|
|
2312
|
+
return new Transaction({
|
|
2313
|
+
feePayer: issuer,
|
|
2314
|
+
recentBlockhash: params.recentBlockhash,
|
|
2315
|
+
}).add(instruction);
|
|
2316
|
+
},
|
|
2317
|
+
buildEnrollMemberOpenTx(params) {
|
|
2318
|
+
const member = new PublicKey(params.member);
|
|
2319
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2320
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2321
|
+
programId,
|
|
2322
|
+
poolAddress,
|
|
2323
|
+
member,
|
|
2324
|
+
});
|
|
2325
|
+
const instruction = new TransactionInstruction({
|
|
2326
|
+
programId,
|
|
2327
|
+
keys: [
|
|
2328
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2329
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2330
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: true },
|
|
2331
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2332
|
+
],
|
|
2333
|
+
data: encodeEnrollMemberOpenData(params),
|
|
2334
|
+
});
|
|
2335
|
+
return new Transaction({
|
|
2336
|
+
feePayer: member,
|
|
2337
|
+
recentBlockhash: params.recentBlockhash,
|
|
2338
|
+
}).add(instruction);
|
|
2339
|
+
},
|
|
2340
|
+
buildEnrollMemberTokenGateTx(params) {
|
|
2341
|
+
const member = new PublicKey(params.member);
|
|
2342
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2343
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2344
|
+
programId,
|
|
2345
|
+
poolAddress,
|
|
2346
|
+
member,
|
|
2347
|
+
});
|
|
2348
|
+
const instruction = new TransactionInstruction({
|
|
2349
|
+
programId,
|
|
2350
|
+
keys: [
|
|
2351
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2352
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2353
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: true },
|
|
2354
|
+
{ pubkey: new PublicKey(params.tokenGateAccount), isSigner: false, isWritable: false },
|
|
2355
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2356
|
+
],
|
|
2357
|
+
data: encodeEnrollMemberTokenGateData(params),
|
|
2358
|
+
});
|
|
2359
|
+
return new Transaction({
|
|
2360
|
+
feePayer: member,
|
|
2361
|
+
recentBlockhash: params.recentBlockhash,
|
|
2362
|
+
}).add(instruction);
|
|
2363
|
+
},
|
|
2364
|
+
buildEnrollMemberInvitePermitTx(params) {
|
|
2365
|
+
const member = new PublicKey(params.member);
|
|
2366
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2367
|
+
const issuer = new PublicKey(params.issuer);
|
|
2368
|
+
const nonceHash = fromHex(params.nonceHashHex, 32);
|
|
2369
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2370
|
+
programId,
|
|
2371
|
+
poolAddress,
|
|
2372
|
+
member,
|
|
2373
|
+
});
|
|
2374
|
+
const [inviteIssuerPda] = deriveInviteIssuerPda({
|
|
2375
|
+
programId,
|
|
2376
|
+
issuer,
|
|
2377
|
+
});
|
|
2378
|
+
const [replayPda] = deriveEnrollmentReplayPda({
|
|
2379
|
+
programId,
|
|
2380
|
+
poolAddress,
|
|
2381
|
+
member,
|
|
2382
|
+
nonceHash,
|
|
2383
|
+
});
|
|
2384
|
+
const instruction = new TransactionInstruction({
|
|
2385
|
+
programId,
|
|
2386
|
+
keys: [
|
|
2387
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2388
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2389
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: true },
|
|
2390
|
+
{ pubkey: issuer, isSigner: true, isWritable: false },
|
|
2391
|
+
{ pubkey: inviteIssuerPda, isSigner: false, isWritable: false },
|
|
2392
|
+
{ pubkey: replayPda, isSigner: false, isWritable: true },
|
|
2393
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2394
|
+
],
|
|
2395
|
+
data: encodeEnrollMemberInvitePermitData(params),
|
|
2396
|
+
});
|
|
2397
|
+
return new Transaction({
|
|
2398
|
+
feePayer: member,
|
|
2399
|
+
recentBlockhash: params.recentBlockhash,
|
|
2400
|
+
}).add(instruction);
|
|
2401
|
+
},
|
|
2402
|
+
buildSetClaimDelegateTx(params) {
|
|
2403
|
+
const member = new PublicKey(params.member);
|
|
2404
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2405
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2406
|
+
programId,
|
|
2407
|
+
poolAddress,
|
|
2408
|
+
member,
|
|
2409
|
+
});
|
|
2410
|
+
const [claimDelegatePda] = deriveClaimDelegatePda({
|
|
2411
|
+
programId,
|
|
2412
|
+
poolAddress,
|
|
2413
|
+
member,
|
|
2414
|
+
});
|
|
2415
|
+
const instruction = new TransactionInstruction({
|
|
2416
|
+
programId,
|
|
2417
|
+
keys: [
|
|
2418
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2419
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2420
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
2421
|
+
{ pubkey: claimDelegatePda, isSigner: false, isWritable: true },
|
|
2422
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2423
|
+
],
|
|
2424
|
+
data: encodeSetClaimDelegateData(params),
|
|
2425
|
+
});
|
|
2426
|
+
return new Transaction({
|
|
2427
|
+
feePayer: member,
|
|
2428
|
+
recentBlockhash: params.recentBlockhash,
|
|
2429
|
+
}).add(instruction);
|
|
2430
|
+
},
|
|
2431
|
+
buildFundPoolSolTx(params) {
|
|
2432
|
+
const funder = new PublicKey(params.funder);
|
|
2433
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2434
|
+
const instruction = new TransactionInstruction({
|
|
2435
|
+
programId,
|
|
2436
|
+
keys: [
|
|
2437
|
+
{ pubkey: funder, isSigner: true, isWritable: true },
|
|
2438
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
2439
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2440
|
+
],
|
|
2441
|
+
data: encodeFundPoolSolData(params),
|
|
2442
|
+
});
|
|
2443
|
+
return new Transaction({
|
|
2444
|
+
feePayer: funder,
|
|
2445
|
+
recentBlockhash: params.recentBlockhash,
|
|
2446
|
+
}).add(instruction);
|
|
2447
|
+
},
|
|
2448
|
+
buildFundPoolSplTx(params) {
|
|
2449
|
+
const funder = new PublicKey(params.funder);
|
|
2450
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2451
|
+
const payoutMint = new PublicKey(params.payoutMint);
|
|
2452
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2453
|
+
programId,
|
|
2454
|
+
poolAddress,
|
|
2455
|
+
});
|
|
2456
|
+
const [poolAssetVaultPda] = derivePoolAssetVaultPda({
|
|
2457
|
+
programId,
|
|
2458
|
+
poolAddress,
|
|
2459
|
+
payoutMint,
|
|
2460
|
+
});
|
|
2461
|
+
const instruction = new TransactionInstruction({
|
|
2462
|
+
programId,
|
|
2463
|
+
keys: [
|
|
2464
|
+
{ pubkey: funder, isSigner: true, isWritable: true },
|
|
2465
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2466
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: false },
|
|
2467
|
+
{ pubkey: payoutMint, isSigner: false, isWritable: true },
|
|
2468
|
+
{ pubkey: poolAssetVaultPda, isSigner: false, isWritable: true },
|
|
2469
|
+
{ pubkey: new PublicKey(params.poolVaultTokenAccount), isSigner: true, isWritable: true },
|
|
2470
|
+
{ pubkey: new PublicKey(params.funderTokenAccount), isSigner: false, isWritable: true },
|
|
2471
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2472
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2473
|
+
],
|
|
2474
|
+
data: encodeFundPoolSplData(params),
|
|
2475
|
+
});
|
|
2476
|
+
return new Transaction({
|
|
2477
|
+
feePayer: funder,
|
|
2478
|
+
recentBlockhash: params.recentBlockhash,
|
|
2479
|
+
}).add(instruction);
|
|
2480
|
+
},
|
|
2481
|
+
buildSubmitRewardClaimTx(params) {
|
|
2482
|
+
validateRewardClaimOptionalAccounts(params);
|
|
2483
|
+
const claimant = new PublicKey(params.claimant);
|
|
2484
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2485
|
+
const member = new PublicKey(params.member);
|
|
2486
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
2487
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
2488
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2489
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2490
|
+
programId,
|
|
2491
|
+
poolAddress,
|
|
2492
|
+
});
|
|
2493
|
+
const [oraclePolicyPda] = derivePoolOraclePolicyPda({
|
|
2494
|
+
programId,
|
|
2495
|
+
poolAddress,
|
|
2496
|
+
});
|
|
2497
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2498
|
+
programId,
|
|
2499
|
+
poolAddress,
|
|
2500
|
+
member,
|
|
2501
|
+
});
|
|
2502
|
+
const [aggregatePda] = deriveOutcomeAggregatePda({
|
|
2503
|
+
programId,
|
|
2504
|
+
poolAddress,
|
|
2505
|
+
member,
|
|
2506
|
+
cycleHash,
|
|
2507
|
+
ruleHash,
|
|
2508
|
+
});
|
|
2509
|
+
const [claimRecordPda] = deriveClaimV2Pda({
|
|
2510
|
+
programId,
|
|
2511
|
+
poolAddress,
|
|
2512
|
+
member,
|
|
2513
|
+
cycleHash,
|
|
2514
|
+
ruleHash,
|
|
2515
|
+
});
|
|
2516
|
+
const [claimDelegatePda] = deriveClaimDelegatePda({
|
|
2517
|
+
programId,
|
|
2518
|
+
poolAddress,
|
|
2519
|
+
member,
|
|
2520
|
+
});
|
|
2521
|
+
const optionPlaceholder = programId;
|
|
2522
|
+
const claimDelegateAccount = params.claimDelegate ? claimDelegatePda : optionPlaceholder;
|
|
2523
|
+
const poolAssetVaultAccount = params.poolAssetVault
|
|
2524
|
+
? new PublicKey(params.poolAssetVault)
|
|
2525
|
+
: optionPlaceholder;
|
|
2526
|
+
const poolVaultTokenAccount = params.poolVaultTokenAccount
|
|
2527
|
+
? new PublicKey(params.poolVaultTokenAccount)
|
|
2528
|
+
: optionPlaceholder;
|
|
2529
|
+
const recipientTokenAccount = params.recipientTokenAccount
|
|
2530
|
+
? new PublicKey(params.recipientTokenAccount)
|
|
2531
|
+
: optionPlaceholder;
|
|
2532
|
+
const instruction = new TransactionInstruction({
|
|
2533
|
+
programId,
|
|
2534
|
+
keys: [
|
|
2535
|
+
{ pubkey: claimant, isSigner: true, isWritable: true },
|
|
2536
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2537
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
2538
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: false },
|
|
2539
|
+
{ pubkey: oraclePolicyPda, isSigner: false, isWritable: false },
|
|
2540
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
2541
|
+
{ pubkey: aggregatePda, isSigner: false, isWritable: true },
|
|
2542
|
+
{ pubkey: new PublicKey(params.recipientSystemAccount), isSigner: false, isWritable: true },
|
|
2543
|
+
{ pubkey: claimDelegateAccount, isSigner: false, isWritable: false },
|
|
2544
|
+
{ pubkey: poolAssetVaultAccount, isSigner: false, isWritable: false },
|
|
2545
|
+
{ pubkey: poolVaultTokenAccount, isSigner: false, isWritable: params.poolVaultTokenAccount != null },
|
|
2546
|
+
{ pubkey: recipientTokenAccount, isSigner: false, isWritable: params.recipientTokenAccount != null },
|
|
2547
|
+
{ pubkey: claimRecordPda, isSigner: false, isWritable: true },
|
|
2548
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2549
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2550
|
+
],
|
|
2551
|
+
data: encodeSubmitRewardClaimData(params),
|
|
2552
|
+
});
|
|
2553
|
+
return new Transaction({
|
|
2554
|
+
feePayer: claimant,
|
|
2555
|
+
recentBlockhash: params.recentBlockhash,
|
|
2556
|
+
}).add(instruction);
|
|
2557
|
+
},
|
|
2558
|
+
buildRegisterCoverageProductV2Tx(params) {
|
|
2559
|
+
const authority = new PublicKey(params.authority);
|
|
2560
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2561
|
+
const productIdHash = fromHex(params.productIdHashHex, 32);
|
|
2562
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2563
|
+
const [coverageProductPda] = deriveCoverageProductPda({
|
|
2564
|
+
programId,
|
|
2565
|
+
poolAddress,
|
|
2566
|
+
productIdHash,
|
|
2567
|
+
});
|
|
2568
|
+
const instruction = new TransactionInstruction({
|
|
2569
|
+
programId,
|
|
2570
|
+
keys: [
|
|
2571
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2572
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2573
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2574
|
+
{ pubkey: coverageProductPda, isSigner: false, isWritable: true },
|
|
2575
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2576
|
+
],
|
|
2577
|
+
data: encodeRegisterCoverageProductV2Data(params),
|
|
2578
|
+
});
|
|
2579
|
+
return new Transaction({
|
|
2580
|
+
feePayer: authority,
|
|
2581
|
+
recentBlockhash: params.recentBlockhash,
|
|
2582
|
+
}).add(instruction);
|
|
2583
|
+
},
|
|
2584
|
+
buildUpdateCoverageProductV2Tx(params) {
|
|
2585
|
+
const authority = new PublicKey(params.authority);
|
|
2586
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2587
|
+
const productIdHash = fromHex(params.productIdHashHex, 32);
|
|
2588
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2589
|
+
const [coverageProductPda] = deriveCoverageProductPda({
|
|
2590
|
+
programId,
|
|
2591
|
+
poolAddress,
|
|
2592
|
+
productIdHash,
|
|
2593
|
+
});
|
|
2594
|
+
const instruction = new TransactionInstruction({
|
|
2595
|
+
programId,
|
|
2596
|
+
keys: [
|
|
2597
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2598
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2599
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2600
|
+
{ pubkey: coverageProductPda, isSigner: false, isWritable: true },
|
|
2601
|
+
],
|
|
2602
|
+
data: encodeUpdateCoverageProductV2Data(params),
|
|
2603
|
+
});
|
|
2604
|
+
return new Transaction({
|
|
2605
|
+
feePayer: authority,
|
|
2606
|
+
recentBlockhash: params.recentBlockhash,
|
|
2607
|
+
}).add(instruction);
|
|
2608
|
+
},
|
|
2609
|
+
buildSubscribeCoverageProductV2Tx(params) {
|
|
2610
|
+
const member = new PublicKey(params.member);
|
|
2611
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2612
|
+
const productIdHash = fromHex(params.productIdHashHex, 32);
|
|
2613
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2614
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2615
|
+
programId,
|
|
2616
|
+
poolAddress,
|
|
2617
|
+
member,
|
|
2618
|
+
});
|
|
2619
|
+
const [coverageProductPda] = deriveCoverageProductPda({
|
|
2620
|
+
programId,
|
|
2621
|
+
poolAddress,
|
|
2622
|
+
productIdHash,
|
|
2623
|
+
});
|
|
2624
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2625
|
+
programId,
|
|
2626
|
+
poolAddress,
|
|
2627
|
+
member,
|
|
2628
|
+
});
|
|
2629
|
+
const [coverageNftPda] = deriveCoverageNftPda({
|
|
2630
|
+
programId,
|
|
2631
|
+
poolAddress,
|
|
2632
|
+
member,
|
|
2633
|
+
});
|
|
2634
|
+
const instruction = new TransactionInstruction({
|
|
2635
|
+
programId,
|
|
2636
|
+
keys: [
|
|
2637
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2638
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2639
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2640
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
2641
|
+
{ pubkey: coverageProductPda, isSigner: false, isWritable: false },
|
|
2642
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2643
|
+
{ pubkey: coverageNftPda, isSigner: false, isWritable: true },
|
|
2644
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2645
|
+
],
|
|
2646
|
+
data: encodeSubscribeCoverageProductV2Data(params),
|
|
2647
|
+
});
|
|
2648
|
+
return new Transaction({
|
|
2649
|
+
feePayer: member,
|
|
2650
|
+
recentBlockhash: params.recentBlockhash,
|
|
2651
|
+
}).add(instruction);
|
|
2652
|
+
},
|
|
2653
|
+
buildIssueCoveragePolicyFromProductV2Tx(params) {
|
|
2654
|
+
const authority = new PublicKey(params.authority);
|
|
2655
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2656
|
+
const member = new PublicKey(params.member);
|
|
2657
|
+
const productIdHash = fromHex(params.productIdHashHex, 32);
|
|
2658
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2659
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2660
|
+
programId,
|
|
2661
|
+
poolAddress,
|
|
2662
|
+
member,
|
|
2663
|
+
});
|
|
2664
|
+
const [coverageProductPda] = deriveCoverageProductPda({
|
|
2665
|
+
programId,
|
|
2666
|
+
poolAddress,
|
|
2667
|
+
productIdHash,
|
|
2668
|
+
});
|
|
2669
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2670
|
+
programId,
|
|
2671
|
+
poolAddress,
|
|
2672
|
+
member,
|
|
2673
|
+
});
|
|
2674
|
+
const [coverageNftPda] = deriveCoverageNftPda({
|
|
2675
|
+
programId,
|
|
2676
|
+
poolAddress,
|
|
2677
|
+
member,
|
|
2678
|
+
});
|
|
2679
|
+
const instruction = new TransactionInstruction({
|
|
2680
|
+
programId,
|
|
2681
|
+
keys: [
|
|
2682
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2683
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2684
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2685
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
2686
|
+
{ pubkey: coverageProductPda, isSigner: false, isWritable: false },
|
|
2687
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2688
|
+
{ pubkey: coverageNftPda, isSigner: false, isWritable: true },
|
|
2689
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2690
|
+
],
|
|
2691
|
+
data: encodeIssueCoveragePolicyFromProductV2Data(params),
|
|
2692
|
+
});
|
|
2693
|
+
return new Transaction({
|
|
2694
|
+
feePayer: authority,
|
|
2695
|
+
recentBlockhash: params.recentBlockhash,
|
|
2696
|
+
}).add(instruction);
|
|
2697
|
+
},
|
|
2698
|
+
buildCreateCoveragePolicyTx(params) {
|
|
2699
|
+
const authority = new PublicKey(params.authority);
|
|
2700
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2701
|
+
const member = new PublicKey(params.member);
|
|
2702
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2703
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2704
|
+
programId,
|
|
2705
|
+
poolAddress,
|
|
2706
|
+
member,
|
|
2707
|
+
});
|
|
2708
|
+
const [coverageNftPda] = deriveCoverageNftPda({
|
|
2709
|
+
programId,
|
|
2710
|
+
poolAddress,
|
|
2711
|
+
member,
|
|
2712
|
+
});
|
|
2713
|
+
const instruction = new TransactionInstruction({
|
|
2714
|
+
programId,
|
|
2715
|
+
keys: [
|
|
2716
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2717
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2718
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2719
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2720
|
+
{ pubkey: coverageNftPda, isSigner: false, isWritable: true },
|
|
2721
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2722
|
+
],
|
|
2723
|
+
data: encodeCreateCoveragePolicyData(params),
|
|
2724
|
+
});
|
|
2725
|
+
return new Transaction({
|
|
2726
|
+
feePayer: authority,
|
|
2727
|
+
recentBlockhash: params.recentBlockhash,
|
|
2728
|
+
}).add(instruction);
|
|
2729
|
+
},
|
|
2730
|
+
buildMintPolicyNftTx(params) {
|
|
2731
|
+
const authority = new PublicKey(params.authority);
|
|
2732
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2733
|
+
const member = new PublicKey(params.member);
|
|
2734
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2735
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2736
|
+
programId,
|
|
2737
|
+
poolAddress,
|
|
2738
|
+
member,
|
|
2739
|
+
});
|
|
2740
|
+
const [coverageNftPda] = deriveCoverageNftPda({
|
|
2741
|
+
programId,
|
|
2742
|
+
poolAddress,
|
|
2743
|
+
member,
|
|
2744
|
+
});
|
|
2745
|
+
const instruction = new TransactionInstruction({
|
|
2746
|
+
programId,
|
|
2747
|
+
keys: [
|
|
2748
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2749
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2750
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2751
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2752
|
+
{ pubkey: coverageNftPda, isSigner: false, isWritable: true },
|
|
2753
|
+
],
|
|
2754
|
+
data: encodeMintPolicyNftData(params),
|
|
2755
|
+
});
|
|
2756
|
+
return new Transaction({
|
|
2757
|
+
feePayer: authority,
|
|
2758
|
+
recentBlockhash: params.recentBlockhash,
|
|
2759
|
+
}).add(instruction);
|
|
2760
|
+
},
|
|
2761
|
+
buildPayPremiumOnchainTx(params) {
|
|
2762
|
+
const payer = new PublicKey(params.payer);
|
|
2763
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2764
|
+
const member = new PublicKey(params.member);
|
|
2765
|
+
const payoutMint = new PublicKey(params.payoutMint);
|
|
2766
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2767
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2768
|
+
programId,
|
|
2769
|
+
poolAddress,
|
|
2770
|
+
});
|
|
2771
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2772
|
+
programId,
|
|
2773
|
+
poolAddress,
|
|
2774
|
+
member,
|
|
2775
|
+
});
|
|
2776
|
+
const [premiumLedgerPda] = derivePremiumLedgerPda({
|
|
2777
|
+
programId,
|
|
2778
|
+
poolAddress,
|
|
2779
|
+
member,
|
|
2780
|
+
});
|
|
2781
|
+
const [poolAssetVaultPda] = derivePoolAssetVaultPda({
|
|
2782
|
+
programId,
|
|
2783
|
+
poolAddress,
|
|
2784
|
+
payoutMint,
|
|
2785
|
+
});
|
|
2786
|
+
const instruction = new TransactionInstruction({
|
|
2787
|
+
programId,
|
|
2788
|
+
keys: [
|
|
2789
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
2790
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2791
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2792
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: false },
|
|
2793
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2794
|
+
{ pubkey: member, isSigner: false, isWritable: false },
|
|
2795
|
+
{ pubkey: premiumLedgerPda, isSigner: false, isWritable: true },
|
|
2796
|
+
{ pubkey: poolAssetVaultPda, isSigner: false, isWritable: false },
|
|
2797
|
+
{ pubkey: new PublicKey(params.payerTokenAccount), isSigner: false, isWritable: true },
|
|
2798
|
+
{ pubkey: new PublicKey(params.poolVaultTokenAccount), isSigner: false, isWritable: true },
|
|
2799
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2800
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2801
|
+
],
|
|
2802
|
+
data: encodePayPremiumOnchainData(params),
|
|
2803
|
+
});
|
|
2804
|
+
return new Transaction({
|
|
2805
|
+
feePayer: payer,
|
|
2806
|
+
recentBlockhash: params.recentBlockhash,
|
|
2807
|
+
}).add(instruction);
|
|
2808
|
+
},
|
|
2809
|
+
buildAttestPremiumPaidOffchainTx(params) {
|
|
2810
|
+
const oracle = new PublicKey(params.oracle);
|
|
2811
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2812
|
+
const member = new PublicKey(params.member);
|
|
2813
|
+
const replayHash = fromHex(params.replayHashHex, 32);
|
|
2814
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2815
|
+
const [oracleEntryPda] = deriveOraclePda({
|
|
2816
|
+
programId,
|
|
2817
|
+
oracle,
|
|
2818
|
+
});
|
|
2819
|
+
const [poolOraclePda] = derivePoolOraclePda({
|
|
2820
|
+
programId,
|
|
2821
|
+
poolAddress,
|
|
2822
|
+
oracle,
|
|
2823
|
+
});
|
|
2824
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2825
|
+
programId,
|
|
2826
|
+
poolAddress,
|
|
2827
|
+
member,
|
|
2828
|
+
});
|
|
2829
|
+
const [premiumLedgerPda] = derivePremiumLedgerPda({
|
|
2830
|
+
programId,
|
|
2831
|
+
poolAddress,
|
|
2832
|
+
member,
|
|
2833
|
+
});
|
|
2834
|
+
const [premiumReplayPda] = derivePremiumReplayPda({
|
|
2835
|
+
programId,
|
|
2836
|
+
poolAddress,
|
|
2837
|
+
member,
|
|
2838
|
+
replayHash,
|
|
2839
|
+
});
|
|
2840
|
+
const instruction = new TransactionInstruction({
|
|
2841
|
+
programId,
|
|
2842
|
+
keys: [
|
|
2843
|
+
{ pubkey: oracle, isSigner: true, isWritable: true },
|
|
2844
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2845
|
+
{ pubkey: oracleEntryPda, isSigner: false, isWritable: false },
|
|
2846
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2847
|
+
{ pubkey: poolOraclePda, isSigner: false, isWritable: false },
|
|
2848
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2849
|
+
{ pubkey: premiumLedgerPda, isSigner: false, isWritable: true },
|
|
2850
|
+
{ pubkey: premiumReplayPda, isSigner: false, isWritable: true },
|
|
2851
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2852
|
+
],
|
|
2853
|
+
data: encodeAttestPremiumPaidOffchainData(params),
|
|
2854
|
+
});
|
|
2855
|
+
return new Transaction({
|
|
2856
|
+
feePayer: oracle,
|
|
2857
|
+
recentBlockhash: params.recentBlockhash,
|
|
2858
|
+
}).add(instruction);
|
|
2859
|
+
},
|
|
2860
|
+
buildSubmitCoverageClaimTx(params) {
|
|
2861
|
+
const claimant = new PublicKey(params.claimant);
|
|
2862
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2863
|
+
const member = new PublicKey(params.member);
|
|
2864
|
+
const intentHash = fromHex(params.intentHashHex, 32);
|
|
2865
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2866
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2867
|
+
programId,
|
|
2868
|
+
poolAddress,
|
|
2869
|
+
member,
|
|
2870
|
+
});
|
|
2871
|
+
const [claimDelegatePda] = deriveClaimDelegatePda({
|
|
2872
|
+
programId,
|
|
2873
|
+
poolAddress,
|
|
2874
|
+
member,
|
|
2875
|
+
});
|
|
2876
|
+
const [coverageClaimPda] = deriveCoverageClaimPda({
|
|
2877
|
+
programId,
|
|
2878
|
+
poolAddress,
|
|
2879
|
+
member,
|
|
2880
|
+
intentHash,
|
|
2881
|
+
});
|
|
2882
|
+
const claimDelegateAccount = params.claimDelegate ? claimDelegatePda : programId;
|
|
2883
|
+
const instruction = new TransactionInstruction({
|
|
2884
|
+
programId,
|
|
2885
|
+
keys: [
|
|
2886
|
+
{ pubkey: claimant, isSigner: true, isWritable: true },
|
|
2887
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2888
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2889
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2890
|
+
{ pubkey: claimDelegateAccount, isSigner: false, isWritable: false },
|
|
2891
|
+
{ pubkey: coverageClaimPda, isSigner: false, isWritable: true },
|
|
2892
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2893
|
+
],
|
|
2894
|
+
data: encodeSubmitCoverageClaimData(params),
|
|
2895
|
+
});
|
|
2896
|
+
return new Transaction({
|
|
2897
|
+
feePayer: claimant,
|
|
2898
|
+
recentBlockhash: params.recentBlockhash,
|
|
2899
|
+
}).add(instruction);
|
|
2900
|
+
},
|
|
2901
|
+
buildSettleCoverageClaimTx(params) {
|
|
2902
|
+
const authority = new PublicKey(params.authority);
|
|
2903
|
+
const claimant = new PublicKey(params.claimant);
|
|
2904
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2905
|
+
const member = new PublicKey(params.member);
|
|
2906
|
+
const intentHash = fromHex(params.intentHashHex, 32);
|
|
2907
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
2908
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2909
|
+
programId,
|
|
2910
|
+
poolAddress,
|
|
2911
|
+
});
|
|
2912
|
+
const [coveragePolicyPda] = deriveCoveragePolicyPda({
|
|
2913
|
+
programId,
|
|
2914
|
+
poolAddress,
|
|
2915
|
+
member,
|
|
2916
|
+
});
|
|
2917
|
+
const [coverageClaimPda] = deriveCoverageClaimPda({
|
|
2918
|
+
programId,
|
|
2919
|
+
poolAddress,
|
|
2920
|
+
member,
|
|
2921
|
+
intentHash,
|
|
2922
|
+
});
|
|
2923
|
+
const instruction = new TransactionInstruction({
|
|
2924
|
+
programId,
|
|
2925
|
+
keys: [
|
|
2926
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
2927
|
+
{ pubkey: claimant, isSigner: true, isWritable: false },
|
|
2928
|
+
{ pubkey: configV2Pda, isSigner: false, isWritable: false },
|
|
2929
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: true },
|
|
2930
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: false },
|
|
2931
|
+
{ pubkey: coveragePolicyPda, isSigner: false, isWritable: true },
|
|
2932
|
+
{ pubkey: coverageClaimPda, isSigner: false, isWritable: true },
|
|
2933
|
+
{ pubkey: new PublicKey(params.recipientSystemAccount), isSigner: false, isWritable: true },
|
|
2934
|
+
{ pubkey: new PublicKey(params.poolAssetVault), isSigner: false, isWritable: false },
|
|
2935
|
+
{ pubkey: new PublicKey(params.poolVaultTokenAccount), isSigner: false, isWritable: true },
|
|
2936
|
+
{ pubkey: new PublicKey(params.recipientTokenAccount), isSigner: false, isWritable: true },
|
|
2937
|
+
{ pubkey: new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), isSigner: false, isWritable: false },
|
|
2938
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2939
|
+
],
|
|
2940
|
+
data: encodeSettleCoverageClaimData(params),
|
|
2941
|
+
});
|
|
2942
|
+
return new Transaction({
|
|
2943
|
+
feePayer: authority,
|
|
2944
|
+
recentBlockhash: params.recentBlockhash,
|
|
2945
|
+
}).add(instruction);
|
|
2946
|
+
},
|
|
2947
|
+
buildMigratePoolV1ToV2Tx(params) {
|
|
2948
|
+
const authority = new PublicKey(params.authority);
|
|
2949
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2950
|
+
const [poolTermsPda] = derivePoolTermsPda({
|
|
2951
|
+
programId,
|
|
2952
|
+
poolAddress,
|
|
2953
|
+
});
|
|
2954
|
+
const [oraclePolicyPda] = derivePoolOraclePolicyPda({
|
|
2955
|
+
programId,
|
|
2956
|
+
poolAddress,
|
|
2957
|
+
});
|
|
2958
|
+
const instruction = new TransactionInstruction({
|
|
2959
|
+
programId,
|
|
2960
|
+
keys: [
|
|
2961
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
2962
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2963
|
+
{ pubkey: poolTermsPda, isSigner: false, isWritable: true },
|
|
2964
|
+
{ pubkey: oraclePolicyPda, isSigner: false, isWritable: true },
|
|
2965
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2966
|
+
],
|
|
2967
|
+
data: encodeMigratePoolV1ToV2Data(params),
|
|
2968
|
+
});
|
|
2969
|
+
return new Transaction({
|
|
2970
|
+
feePayer: authority,
|
|
2971
|
+
recentBlockhash: params.recentBlockhash,
|
|
2972
|
+
}).add(instruction);
|
|
2973
|
+
},
|
|
2974
|
+
buildMigrateMembershipV1ToV2Tx(params) {
|
|
2975
|
+
const member = new PublicKey(params.member);
|
|
2976
|
+
const poolAddress = new PublicKey(params.poolAddress);
|
|
2977
|
+
const [membershipPda] = deriveMembershipPda({
|
|
2978
|
+
programId,
|
|
2979
|
+
poolAddress,
|
|
2980
|
+
member,
|
|
2981
|
+
});
|
|
2982
|
+
const [claimDelegatePda] = deriveClaimDelegatePda({
|
|
2983
|
+
programId,
|
|
2984
|
+
poolAddress,
|
|
2985
|
+
member,
|
|
2986
|
+
});
|
|
2987
|
+
const instruction = new TransactionInstruction({
|
|
2988
|
+
programId,
|
|
2989
|
+
keys: [
|
|
2990
|
+
{ pubkey: member, isSigner: true, isWritable: true },
|
|
2991
|
+
{ pubkey: poolAddress, isSigner: false, isWritable: false },
|
|
2992
|
+
{ pubkey: membershipPda, isSigner: false, isWritable: false },
|
|
2993
|
+
{ pubkey: claimDelegatePda, isSigner: false, isWritable: true },
|
|
2994
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
2995
|
+
],
|
|
2996
|
+
data: IX_MIGRATE_MEMBERSHIP_V1_TO_V2,
|
|
2997
|
+
});
|
|
2998
|
+
return new Transaction({
|
|
2999
|
+
feePayer: member,
|
|
3000
|
+
recentBlockhash: params.recentBlockhash,
|
|
3001
|
+
}).add(instruction);
|
|
3002
|
+
},
|
|
3003
|
+
async fetchProtocolConfig() {
|
|
3004
|
+
const [configPda] = deriveConfigPda(programId);
|
|
3005
|
+
const account = await connection.getAccountInfo(configPda, 'confirmed');
|
|
3006
|
+
if (!account)
|
|
3007
|
+
return null;
|
|
3008
|
+
return decodeProtocolConfigAccount(configPda.toBase58(), account.data);
|
|
3009
|
+
},
|
|
3010
|
+
async fetchPool(poolAddress) {
|
|
3011
|
+
const address = new PublicKey(poolAddress);
|
|
3012
|
+
const account = await connection.getAccountInfo(address, 'confirmed');
|
|
3013
|
+
if (!account)
|
|
3014
|
+
return null;
|
|
3015
|
+
return decodePoolAccount(address.toBase58(), account.data);
|
|
3016
|
+
},
|
|
3017
|
+
async fetchOracleRegistryEntry(oracle) {
|
|
3018
|
+
const [pda] = deriveOraclePda({
|
|
3019
|
+
programId,
|
|
3020
|
+
oracle,
|
|
3021
|
+
});
|
|
3022
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3023
|
+
if (!account)
|
|
3024
|
+
return null;
|
|
3025
|
+
return decodeOracleRegistryEntryAccount(pda.toBase58(), account.data);
|
|
3026
|
+
},
|
|
3027
|
+
async fetchPoolOracleApproval(params) {
|
|
3028
|
+
const [pda] = derivePoolOraclePda({
|
|
3029
|
+
programId,
|
|
3030
|
+
poolAddress: params.poolAddress,
|
|
3031
|
+
oracle: params.oracle,
|
|
3032
|
+
});
|
|
3033
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3034
|
+
if (!account)
|
|
3035
|
+
return null;
|
|
3036
|
+
return decodePoolOracleApprovalAccount(pda.toBase58(), account.data);
|
|
3037
|
+
},
|
|
3038
|
+
async fetchMembershipRecord(params) {
|
|
3039
|
+
const [pda] = deriveMembershipPda({
|
|
3040
|
+
programId,
|
|
3041
|
+
poolAddress: params.poolAddress,
|
|
3042
|
+
member: params.member,
|
|
3043
|
+
});
|
|
3044
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3045
|
+
if (!account)
|
|
3046
|
+
return null;
|
|
3047
|
+
return decodeMembershipRecordAccount(pda.toBase58(), account.data);
|
|
3048
|
+
},
|
|
3049
|
+
async fetchCycleOutcome(params) {
|
|
3050
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
3051
|
+
const [pda] = deriveCycleOutcomePda({
|
|
3052
|
+
programId,
|
|
3053
|
+
poolAddress: params.poolAddress,
|
|
3054
|
+
member: params.member,
|
|
3055
|
+
cycleHash,
|
|
3056
|
+
});
|
|
3057
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3058
|
+
if (!account)
|
|
3059
|
+
return null;
|
|
3060
|
+
return decodeCycleOutcomeAccount(pda.toBase58(), account.data);
|
|
3061
|
+
},
|
|
3062
|
+
async fetchCycleWindow(params) {
|
|
3063
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
3064
|
+
const [pda] = deriveCycleWindowPda({
|
|
3065
|
+
programId,
|
|
3066
|
+
poolAddress: params.poolAddress,
|
|
3067
|
+
cycleHash,
|
|
3068
|
+
});
|
|
3069
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3070
|
+
if (!account)
|
|
3071
|
+
return null;
|
|
3072
|
+
return decodeCycleWindowAccount(pda.toBase58(), account.data);
|
|
3073
|
+
},
|
|
3074
|
+
async fetchClaimRecord(params) {
|
|
3075
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
3076
|
+
const [pda] = deriveClaimPda({
|
|
3077
|
+
programId,
|
|
3078
|
+
poolAddress: params.poolAddress,
|
|
3079
|
+
member: params.member,
|
|
3080
|
+
cycleHash,
|
|
3081
|
+
});
|
|
3082
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3083
|
+
if (!account)
|
|
3084
|
+
return null;
|
|
3085
|
+
return decodeClaimRecordAccount(pda.toBase58(), account.data);
|
|
3086
|
+
},
|
|
3087
|
+
async fetchCycleOutcomeAggregate(params) {
|
|
3088
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
3089
|
+
const ruleHash = fromHex(params.ruleHashHex, 32);
|
|
3090
|
+
const [pda] = deriveOutcomeAggregatePda({
|
|
3091
|
+
programId,
|
|
3092
|
+
poolAddress: params.poolAddress,
|
|
3093
|
+
member: params.member,
|
|
3094
|
+
cycleHash,
|
|
3095
|
+
ruleHash,
|
|
3096
|
+
});
|
|
3097
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3098
|
+
if (!account)
|
|
3099
|
+
return null;
|
|
3100
|
+
return decodeCycleOutcomeAggregateAccount(pda.toBase58(), account.data);
|
|
3101
|
+
},
|
|
3102
|
+
async fetchProtocolConfigV2() {
|
|
3103
|
+
const [configV2Pda] = deriveConfigV2Pda(programId);
|
|
3104
|
+
const account = await connection.getAccountInfo(configV2Pda, 'confirmed');
|
|
3105
|
+
if (!account)
|
|
3106
|
+
return null;
|
|
3107
|
+
return decodeProtocolConfigV2Account(configV2Pda.toBase58(), account.data);
|
|
3108
|
+
},
|
|
3109
|
+
async fetchOracleProfile(oracle) {
|
|
3110
|
+
const [pda] = deriveOracleProfilePda({
|
|
3111
|
+
programId,
|
|
3112
|
+
oracle,
|
|
3113
|
+
});
|
|
3114
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3115
|
+
if (!account)
|
|
3116
|
+
return null;
|
|
3117
|
+
return decodeOracleProfileAccount(pda.toBase58(), account.data);
|
|
3118
|
+
},
|
|
3119
|
+
async fetchOracleStakePosition(params) {
|
|
3120
|
+
const [pda] = deriveOracleStakePda({
|
|
3121
|
+
programId,
|
|
3122
|
+
oracle: params.oracle,
|
|
3123
|
+
staker: params.staker,
|
|
3124
|
+
});
|
|
3125
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3126
|
+
if (!account)
|
|
3127
|
+
return null;
|
|
3128
|
+
return decodeOracleStakePositionAccount(pda.toBase58(), account.data);
|
|
3129
|
+
},
|
|
3130
|
+
async fetchPoolOraclePolicy(poolAddress) {
|
|
3131
|
+
const [pda] = derivePoolOraclePolicyPda({
|
|
3132
|
+
programId,
|
|
3133
|
+
poolAddress,
|
|
3134
|
+
});
|
|
3135
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3136
|
+
if (!account)
|
|
3137
|
+
return null;
|
|
3138
|
+
return decodePoolOraclePolicyAccount(pda.toBase58(), account.data);
|
|
3139
|
+
},
|
|
3140
|
+
async fetchPoolTerms(poolAddress) {
|
|
3141
|
+
const [pda] = derivePoolTermsPda({
|
|
3142
|
+
programId,
|
|
3143
|
+
poolAddress,
|
|
3144
|
+
});
|
|
3145
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3146
|
+
if (!account)
|
|
3147
|
+
return null;
|
|
3148
|
+
return decodePoolTermsAccount(pda.toBase58(), account.data);
|
|
3149
|
+
},
|
|
3150
|
+
async fetchPoolAssetVault(params) {
|
|
3151
|
+
const [pda] = derivePoolAssetVaultPda({
|
|
3152
|
+
programId,
|
|
3153
|
+
poolAddress: params.poolAddress,
|
|
3154
|
+
payoutMint: params.payoutMint,
|
|
3155
|
+
});
|
|
3156
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3157
|
+
if (!account)
|
|
3158
|
+
return null;
|
|
3159
|
+
return decodePoolAssetVaultAccount(pda.toBase58(), account.data);
|
|
3160
|
+
},
|
|
3161
|
+
async fetchOutcomeSchema(schemaKeyHashHex) {
|
|
3162
|
+
const [pda] = deriveSchemaPda({
|
|
3163
|
+
programId,
|
|
3164
|
+
schemaKeyHash: fromHex(schemaKeyHashHex, 32),
|
|
3165
|
+
});
|
|
3166
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3167
|
+
if (!account)
|
|
3168
|
+
return null;
|
|
3169
|
+
return decodeOutcomeSchemaAccount(pda.toBase58(), account.data);
|
|
3170
|
+
},
|
|
3171
|
+
async fetchPoolOutcomeRule(params) {
|
|
3172
|
+
const [pda] = derivePoolRulePda({
|
|
3173
|
+
programId,
|
|
3174
|
+
poolAddress: params.poolAddress,
|
|
3175
|
+
ruleHash: fromHex(params.ruleHashHex, 32),
|
|
3176
|
+
});
|
|
3177
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3178
|
+
if (!account)
|
|
3179
|
+
return null;
|
|
3180
|
+
return decodePoolOutcomeRuleAccount(pda.toBase58(), account.data);
|
|
3181
|
+
},
|
|
3182
|
+
async fetchInviteIssuer(issuer) {
|
|
3183
|
+
const [pda] = deriveInviteIssuerPda({
|
|
3184
|
+
programId,
|
|
3185
|
+
issuer,
|
|
3186
|
+
});
|
|
3187
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3188
|
+
if (!account)
|
|
3189
|
+
return null;
|
|
3190
|
+
return decodeInviteIssuerAccount(pda.toBase58(), account.data);
|
|
3191
|
+
},
|
|
3192
|
+
async fetchEnrollmentPermitReplay(params) {
|
|
3193
|
+
const [pda] = deriveEnrollmentReplayPda({
|
|
3194
|
+
programId,
|
|
3195
|
+
poolAddress: params.poolAddress,
|
|
3196
|
+
member: params.member,
|
|
3197
|
+
nonceHash: fromHex(params.nonceHashHex, 32),
|
|
3198
|
+
});
|
|
3199
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3200
|
+
if (!account)
|
|
3201
|
+
return null;
|
|
3202
|
+
return decodeEnrollmentPermitReplayAccount(pda.toBase58(), account.data);
|
|
3203
|
+
},
|
|
3204
|
+
async fetchAttestationVote(params) {
|
|
3205
|
+
const [pda] = deriveAttestationVotePda({
|
|
3206
|
+
programId,
|
|
3207
|
+
poolAddress: params.poolAddress,
|
|
3208
|
+
member: params.member,
|
|
3209
|
+
cycleHash: hashStringTo32(params.cycleId),
|
|
3210
|
+
ruleHash: fromHex(params.ruleHashHex, 32),
|
|
3211
|
+
oracle: params.oracle,
|
|
3212
|
+
});
|
|
3213
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3214
|
+
if (!account)
|
|
3215
|
+
return null;
|
|
3216
|
+
return decodeAttestationVoteAccount(pda.toBase58(), account.data);
|
|
3217
|
+
},
|
|
3218
|
+
async fetchClaimDelegate(params) {
|
|
3219
|
+
const [pda] = deriveClaimDelegatePda({
|
|
3220
|
+
programId,
|
|
3221
|
+
poolAddress: params.poolAddress,
|
|
3222
|
+
member: params.member,
|
|
3223
|
+
});
|
|
3224
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3225
|
+
if (!account)
|
|
3226
|
+
return null;
|
|
3227
|
+
return decodeClaimDelegateAccount(pda.toBase58(), account.data);
|
|
3228
|
+
},
|
|
3229
|
+
async fetchClaimRecordV2(params) {
|
|
3230
|
+
const cycleHash = hashStringTo32(params.cycleId);
|
|
3231
|
+
const [pda] = deriveClaimV2Pda({
|
|
3232
|
+
programId,
|
|
3233
|
+
poolAddress: params.poolAddress,
|
|
3234
|
+
member: params.member,
|
|
3235
|
+
cycleHash,
|
|
3236
|
+
ruleHash: fromHex(params.ruleHashHex, 32),
|
|
3237
|
+
});
|
|
3238
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3239
|
+
if (!account)
|
|
3240
|
+
return null;
|
|
3241
|
+
return decodeClaimRecordV2Account(pda.toBase58(), account.data);
|
|
3242
|
+
},
|
|
3243
|
+
async fetchCoverageProduct(params) {
|
|
3244
|
+
const [pda] = deriveCoverageProductPda({
|
|
3245
|
+
programId,
|
|
3246
|
+
poolAddress: params.poolAddress,
|
|
3247
|
+
productIdHash: fromHex(params.productIdHashHex, 32),
|
|
3248
|
+
});
|
|
3249
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3250
|
+
if (!account)
|
|
3251
|
+
return null;
|
|
3252
|
+
return decodeCoverageProductAccount(pda.toBase58(), account.data);
|
|
3253
|
+
},
|
|
3254
|
+
async fetchCoveragePolicy(params) {
|
|
3255
|
+
const [pda] = deriveCoveragePolicyPda({
|
|
3256
|
+
programId,
|
|
3257
|
+
poolAddress: params.poolAddress,
|
|
3258
|
+
member: params.member,
|
|
3259
|
+
});
|
|
3260
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3261
|
+
if (!account)
|
|
3262
|
+
return null;
|
|
3263
|
+
return decodeCoveragePolicyAccount(pda.toBase58(), account.data);
|
|
3264
|
+
},
|
|
3265
|
+
async fetchCoveragePolicyPositionNft(params) {
|
|
3266
|
+
const [pda] = deriveCoverageNftPda({
|
|
3267
|
+
programId,
|
|
3268
|
+
poolAddress: params.poolAddress,
|
|
3269
|
+
member: params.member,
|
|
3270
|
+
});
|
|
3271
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3272
|
+
if (!account)
|
|
3273
|
+
return null;
|
|
3274
|
+
return decodeCoveragePolicyPositionNftAccount(pda.toBase58(), account.data);
|
|
3275
|
+
},
|
|
3276
|
+
async fetchPremiumLedger(params) {
|
|
3277
|
+
const [pda] = derivePremiumLedgerPda({
|
|
3278
|
+
programId,
|
|
3279
|
+
poolAddress: params.poolAddress,
|
|
3280
|
+
member: params.member,
|
|
3281
|
+
});
|
|
3282
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3283
|
+
if (!account)
|
|
3284
|
+
return null;
|
|
3285
|
+
return decodePremiumLedgerAccount(pda.toBase58(), account.data);
|
|
3286
|
+
},
|
|
3287
|
+
async fetchPremiumAttestationReplay(params) {
|
|
3288
|
+
const [pda] = derivePremiumReplayPda({
|
|
3289
|
+
programId,
|
|
3290
|
+
poolAddress: params.poolAddress,
|
|
3291
|
+
member: params.member,
|
|
3292
|
+
replayHash: fromHex(params.replayHashHex, 32),
|
|
3293
|
+
});
|
|
3294
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3295
|
+
if (!account)
|
|
3296
|
+
return null;
|
|
3297
|
+
return decodePremiumAttestationReplayAccount(pda.toBase58(), account.data);
|
|
3298
|
+
},
|
|
3299
|
+
async fetchCoverageClaimRecord(params) {
|
|
3300
|
+
const [pda] = deriveCoverageClaimPda({
|
|
3301
|
+
programId,
|
|
3302
|
+
poolAddress: params.poolAddress,
|
|
3303
|
+
member: params.member,
|
|
3304
|
+
intentHash: fromHex(params.intentHashHex, 32),
|
|
3305
|
+
});
|
|
3306
|
+
const account = await connection.getAccountInfo(pda, 'confirmed');
|
|
3307
|
+
if (!account)
|
|
3308
|
+
return null;
|
|
3309
|
+
return decodeCoverageClaimRecordAccount(pda.toBase58(), account.data);
|
|
3310
|
+
},
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3313
|
+
export function derivePoolAddress(params) {
|
|
3314
|
+
const [pool] = derivePoolPda({
|
|
3315
|
+
programId: params.programId,
|
|
3316
|
+
authority: params.authority,
|
|
3317
|
+
poolId: params.poolId,
|
|
3318
|
+
});
|
|
3319
|
+
return pool.toBase58();
|
|
3320
|
+
}
|