@omegax/protocol-sdk 0.4.4 → 0.6.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.
Files changed (57) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +88 -20
  3. package/dist/claims.d.ts +1 -2
  4. package/dist/claims.js +101 -166
  5. package/dist/internal/protocol/all.d.ts +283 -0
  6. package/dist/internal/protocol/all.js +7195 -0
  7. package/dist/internal/protocol/builders.d.ts +1 -0
  8. package/dist/internal/protocol/builders.js +1 -0
  9. package/dist/internal/protocol/client.d.ts +1 -0
  10. package/dist/internal/protocol/client.js +1 -0
  11. package/dist/internal/protocol/constants.d.ts +1 -0
  12. package/dist/internal/protocol/constants.js +1 -0
  13. package/dist/internal/protocol/decoders.d.ts +1 -0
  14. package/dist/internal/protocol/decoders.js +1 -0
  15. package/dist/internal/protocol/fetchers.d.ts +1 -0
  16. package/dist/internal/protocol/fetchers.js +1 -0
  17. package/dist/internal/protocol/shared.d.ts +1 -0
  18. package/dist/internal/protocol/shared.js +1 -0
  19. package/dist/internal/protocol-seeds/all.d.ts +265 -0
  20. package/dist/internal/protocol-seeds/all.js +455 -0
  21. package/dist/internal/protocol-seeds/claims.d.ts +1 -0
  22. package/dist/internal/protocol-seeds/claims.js +1 -0
  23. package/dist/internal/protocol-seeds/core.d.ts +1 -0
  24. package/dist/internal/protocol-seeds/core.js +1 -0
  25. package/dist/internal/protocol-seeds/liquidity.d.ts +1 -0
  26. package/dist/internal/protocol-seeds/liquidity.js +1 -0
  27. package/dist/internal/protocol-seeds/oracle.d.ts +1 -0
  28. package/dist/internal/protocol-seeds/oracle.js +1 -0
  29. package/dist/internal/protocol-seeds/policy.d.ts +1 -0
  30. package/dist/internal/protocol-seeds/policy.js +1 -0
  31. package/dist/internal/reward-claim.d.ts +17 -0
  32. package/dist/internal/reward-claim.js +27 -0
  33. package/dist/internal/rpc.d.ts +15 -0
  34. package/dist/internal/rpc.js +26 -0
  35. package/dist/internal/types/all.d.ts +1952 -0
  36. package/dist/internal/types/all.js +1 -0
  37. package/dist/internal/types/builders.d.ts +1 -0
  38. package/dist/internal/types/builders.js +1 -0
  39. package/dist/internal/types/claims.d.ts +1 -0
  40. package/dist/internal/types/claims.js +1 -0
  41. package/dist/internal/types/oracle.d.ts +1 -0
  42. package/dist/internal/types/oracle.js +1 -0
  43. package/dist/internal/types/protocol.d.ts +1 -0
  44. package/dist/internal/types/protocol.js +1 -0
  45. package/dist/internal/types/rpc.d.ts +1 -0
  46. package/dist/internal/types/rpc.js +1 -0
  47. package/dist/oracle.js +3 -2
  48. package/dist/protocol.d.ts +3 -13
  49. package/dist/protocol.js +3 -4534
  50. package/dist/protocol_seeds.d.ts +1 -220
  51. package/dist/protocol_seeds.js +1 -324
  52. package/dist/rpc.js +51 -6
  53. package/dist/transactions.d.ts +1 -0
  54. package/dist/transactions.js +28 -6
  55. package/dist/types.d.ts +1 -1424
  56. package/dist/types.js +1 -1
  57. package/package.json +22 -5
@@ -1,5 +1,5 @@
1
1
  import bs58 from 'bs58';
2
- import { Transaction, VersionedTransaction, } from '@solana/web3.js';
2
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
3
3
  function decodeShortVecLength(bytes, offset = 0) {
4
4
  let length = 0;
5
5
  let size = 0;
@@ -27,7 +27,9 @@ function signatureIsPresent(signature) {
27
27
  return signature.some((value) => value !== 0);
28
28
  }
29
29
  export function decodeSolanaTransaction(input) {
30
- const bytes = typeof input === 'string' ? Buffer.from(input, 'base64') : Buffer.from(input);
30
+ const bytes = typeof input === 'string'
31
+ ? Buffer.from(input, 'base64')
32
+ : Buffer.from(input);
31
33
  const { length: signatureCount, bytesRead } = decodeShortVecLength(bytes);
32
34
  const messageOffset = bytesRead + signatureCount * 64;
33
35
  if (messageOffset >= bytes.length) {
@@ -57,8 +59,27 @@ export function solanaTransactionMessageBytes(transaction) {
57
59
  }
58
60
  return transaction.message.serialize();
59
61
  }
62
+ function normalizeSolanaMessageBytesIgnoringRecentBlockhash(messageBytes) {
63
+ const normalized = Uint8Array.from(messageBytes);
64
+ const messagePrefix = normalized[0] ?? 0;
65
+ const isVersioned = (messagePrefix & 0x80) !== 0;
66
+ let cursor = isVersioned ? 1 : 0;
67
+ cursor += 3;
68
+ const { length: accountKeyCount, bytesRead } = decodeShortVecLength(normalized, cursor);
69
+ cursor += bytesRead + accountKeyCount * 32;
70
+ if (cursor + 32 > normalized.length) {
71
+ throw new Error('invalid serialized transaction message');
72
+ }
73
+ normalized.fill(0, cursor, cursor + 32);
74
+ return normalized;
75
+ }
76
+ export function solanaTransactionIntentMessageBytes(transaction) {
77
+ return normalizeSolanaMessageBytesIgnoringRecentBlockhash(solanaTransactionMessageBytes(transaction));
78
+ }
60
79
  export function solanaTransactionMessageBase64(input) {
61
- const transaction = typeof input === 'string' || input instanceof Uint8Array || Buffer.isBuffer(input)
80
+ const transaction = typeof input === 'string' ||
81
+ input instanceof Uint8Array ||
82
+ Buffer.isBuffer(input)
62
83
  ? decodeSolanaTransaction(input)
63
84
  : input;
64
85
  return Buffer.from(solanaTransactionMessageBytes(transaction)).toString('base64');
@@ -87,14 +108,15 @@ export function solanaTransactionFirstSignature(transaction) {
87
108
  export function solanaTransactionSignerSignature(transaction, signer) {
88
109
  if (transaction instanceof Transaction) {
89
110
  const entry = transaction.signatures.find((candidate) => candidate.publicKey.toBase58() === signer);
90
- return signatureIsPresent(entry?.signature) ? entry?.signature : null;
111
+ return signatureIsPresent(entry?.signature)
112
+ ? entry?.signature
113
+ : null;
91
114
  }
92
115
  const accountKeys = versionedStaticAccountKeys(transaction);
93
116
  const signerIndex = accountKeys.findIndex((candidate) => candidate.toBase58() === signer);
94
117
  if (signerIndex < 0)
95
118
  return null;
96
- const header = transaction.message
97
- .header;
119
+ const header = transaction.message.header;
98
120
  const requiredSignerCount = header?.numRequiredSignatures ?? 0;
99
121
  if (signerIndex >= requiredSignerCount) {
100
122
  return null;