@omegax/protocol-sdk 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/claims.js +17 -25
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/protocol.d.ts +6 -2
- package/dist/protocol.js +1217 -3
- package/dist/protocol_seeds.d.ts +45 -0
- package/dist/protocol_seeds.js +78 -0
- package/dist/rpc.js +3 -2
- package/dist/transactions.d.ts +10 -0
- package/dist/transactions.js +104 -0
- package/dist/types.d.ts +303 -1
- package/package.json +2 -1
package/dist/claims.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import bs58 from 'bs58';
|
|
2
1
|
import nacl from 'tweetnacl';
|
|
3
2
|
import { PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
|
|
4
3
|
import { anchorDiscriminator, encodeU64Le, fromHex, hashStringTo32, } from './utils.js';
|
|
4
|
+
import { decodeSolanaTransaction, solanaTransactionFirstSignature, solanaTransactionMessageBytes, solanaTransactionRequiredSigner, solanaTransactionSignerSignature, } from './transactions.js';
|
|
5
5
|
import { deriveClaimDelegatePda, deriveClaimPda, deriveClaimV2Pda, deriveConfigV2Pda, deriveOutcomeAggregatePda, derivePoolOraclePolicyPda, derivePoolTermsPda, deriveCycleWindowPda, deriveCycleOutcomePda, deriveMembershipPda, } from './protocol_seeds.js';
|
|
6
6
|
const SUBMIT_CLAIM_DISCRIMINATOR = anchorDiscriminator('global', 'submit_claim');
|
|
7
7
|
const SUBMIT_REWARD_CLAIM_DISCRIMINATOR = anchorDiscriminator('global', 'submit_reward_claim');
|
|
@@ -207,18 +207,10 @@ export function buildUnsignedRewardClaimTx(params) {
|
|
|
207
207
|
requiredSigner: claimant.toBase58(),
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
|
-
function firstSignatureBase58(tx) {
|
|
211
|
-
if (tx.signatures.length === 0)
|
|
212
|
-
return null;
|
|
213
|
-
const first = tx.signatures[0];
|
|
214
|
-
if (!first?.signature)
|
|
215
|
-
return null;
|
|
216
|
-
return bs58.encode(first.signature);
|
|
217
|
-
}
|
|
218
210
|
export function validateSignedClaimTx(params) {
|
|
219
211
|
let tx;
|
|
220
212
|
try {
|
|
221
|
-
tx =
|
|
213
|
+
tx = decodeSolanaTransaction(params.signedTxBase64);
|
|
222
214
|
}
|
|
223
215
|
catch {
|
|
224
216
|
return {
|
|
@@ -230,30 +222,30 @@ export function validateSignedClaimTx(params) {
|
|
|
230
222
|
}
|
|
231
223
|
if (typeof params.expectedUnsignedTxBase64 === 'string' && params.expectedUnsignedTxBase64.length > 0) {
|
|
232
224
|
try {
|
|
233
|
-
const expectedUnsignedTx =
|
|
234
|
-
const signedMessageBytes = tx
|
|
235
|
-
const expectedMessageBytes = expectedUnsignedTx
|
|
225
|
+
const expectedUnsignedTx = decodeSolanaTransaction(params.expectedUnsignedTxBase64);
|
|
226
|
+
const signedMessageBytes = solanaTransactionMessageBytes(tx);
|
|
227
|
+
const expectedMessageBytes = solanaTransactionMessageBytes(expectedUnsignedTx);
|
|
236
228
|
if (signedMessageBytes.length !== expectedMessageBytes.length
|
|
237
229
|
|| !signedMessageBytes.every((value, index) => value === expectedMessageBytes[index])) {
|
|
238
230
|
return {
|
|
239
231
|
valid: false,
|
|
240
|
-
txSignature:
|
|
232
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
241
233
|
reason: 'intent_message_mismatch',
|
|
242
|
-
signer: tx
|
|
234
|
+
signer: solanaTransactionRequiredSigner(tx),
|
|
243
235
|
};
|
|
244
236
|
}
|
|
245
237
|
}
|
|
246
238
|
catch {
|
|
247
239
|
return {
|
|
248
240
|
valid: false,
|
|
249
|
-
txSignature:
|
|
241
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
250
242
|
reason: 'intent_message_mismatch',
|
|
251
|
-
signer: tx
|
|
243
|
+
signer: solanaTransactionRequiredSigner(tx),
|
|
252
244
|
};
|
|
253
245
|
}
|
|
254
246
|
}
|
|
255
247
|
const expectedSigner = params.requiredSigner.trim();
|
|
256
|
-
const signer = tx
|
|
248
|
+
const signer = solanaTransactionRequiredSigner(tx);
|
|
257
249
|
if (!signer) {
|
|
258
250
|
return {
|
|
259
251
|
valid: false,
|
|
@@ -265,32 +257,32 @@ export function validateSignedClaimTx(params) {
|
|
|
265
257
|
if (signer !== expectedSigner) {
|
|
266
258
|
return {
|
|
267
259
|
valid: false,
|
|
268
|
-
txSignature:
|
|
260
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
269
261
|
reason: 'required_signer_mismatch',
|
|
270
262
|
signer,
|
|
271
263
|
};
|
|
272
264
|
}
|
|
273
|
-
const
|
|
274
|
-
if (!
|
|
265
|
+
const requiredSignature = solanaTransactionSignerSignature(tx, expectedSigner);
|
|
266
|
+
if (!requiredSignature) {
|
|
275
267
|
return {
|
|
276
268
|
valid: false,
|
|
277
|
-
txSignature:
|
|
269
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
278
270
|
reason: 'missing_required_signature',
|
|
279
271
|
signer,
|
|
280
272
|
};
|
|
281
273
|
}
|
|
282
|
-
const ok = nacl.sign.detached.verify(tx
|
|
274
|
+
const ok = nacl.sign.detached.verify(solanaTransactionMessageBytes(tx), requiredSignature, new PublicKey(expectedSigner).toBytes());
|
|
283
275
|
if (!ok) {
|
|
284
276
|
return {
|
|
285
277
|
valid: false,
|
|
286
|
-
txSignature:
|
|
278
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
287
279
|
reason: 'invalid_required_signature',
|
|
288
280
|
signer,
|
|
289
281
|
};
|
|
290
282
|
}
|
|
291
283
|
return {
|
|
292
284
|
valid: true,
|
|
293
|
-
txSignature:
|
|
285
|
+
txSignature: solanaTransactionFirstSignature(tx),
|
|
294
286
|
reason: null,
|
|
295
287
|
signer,
|
|
296
288
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/protocol.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import type { ProtocolClient } from './types.js';
|
|
1
|
+
import { AddressLookupTableAccount, Connection, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import type { ProtocolClient, ProtocolCycleQuoteFields } from './types.js';
|
|
3
3
|
export declare const PROTOCOL_PROGRAM_ID = "Bn6eixac1QEEVErGBvBjxAd6pgB9e2q4XHvAkinQ5y1B";
|
|
4
|
+
export declare function buildCycleQuoteMessage(fields: ProtocolCycleQuoteFields): Buffer;
|
|
5
|
+
export declare function buildCycleQuoteHash(input: ProtocolCycleQuoteFields | Uint8Array): Buffer;
|
|
6
|
+
export declare function buildCycleQuoteSignatureMessage(input: ProtocolCycleQuoteFields | Uint8Array): Buffer;
|
|
7
|
+
export declare function compileTransactionToV0(transaction: Transaction, lookupTableAccounts: AddressLookupTableAccount[]): VersionedTransaction;
|
|
4
8
|
export declare function createProtocolClient(connection: Connection, programIdInput: string): ProtocolClient;
|
|
5
9
|
export declare function derivePoolAddress(params: {
|
|
6
10
|
programId: string;
|