@omegax/protocol-sdk 0.4.4 → 0.5.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/NOTICE +5 -0
- package/README.md +74 -16
- package/dist/claims.d.ts +1 -2
- package/dist/claims.js +71 -131
- package/dist/protocol.js +3133 -1245
- package/dist/protocol_seeds.d.ts +78 -33
- package/dist/protocol_seeds.js +171 -52
- package/dist/rpc.js +65 -5
- package/dist/transactions.d.ts +1 -0
- package/dist/transactions.js +17 -0
- package/dist/types.d.ts +837 -315
- package/package.json +10 -3
package/dist/rpc.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { Connection, } from '@solana/web3.js';
|
|
2
2
|
import { normalizeClaimSimulationFailure } from './claims.js';
|
|
3
|
-
import { decodeSolanaTransaction, } from './transactions.js';
|
|
3
|
+
import { decodeSolanaTransaction, serializeSolanaTransaction, } from './transactions.js';
|
|
4
|
+
function shouldRetrySignedSimulationWithoutSigVerify(params) {
|
|
5
|
+
const message = params.error instanceof Error ? params.error.message : String(params.error);
|
|
6
|
+
return (params.sigVerify
|
|
7
|
+
&& /invalid arguments/i.test(message));
|
|
8
|
+
}
|
|
9
|
+
async function simulateSignedTransaction(connection, transaction, options) {
|
|
10
|
+
const rpcRequest = connection._rpcRequest;
|
|
11
|
+
if (typeof rpcRequest !== 'function') {
|
|
12
|
+
return await connection.simulateTransaction(transaction, options);
|
|
13
|
+
}
|
|
14
|
+
const unsafe = await rpcRequest.call(connection, 'simulateTransaction', [
|
|
15
|
+
serializeSolanaTransaction(transaction).toString('base64'),
|
|
16
|
+
{
|
|
17
|
+
encoding: 'base64',
|
|
18
|
+
...options,
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
if (unsafe?.error) {
|
|
22
|
+
throw new Error(unsafe.error.message ?? 'failed to simulate transaction');
|
|
23
|
+
}
|
|
24
|
+
if (!unsafe?.result?.value) {
|
|
25
|
+
throw new Error('failed to simulate transaction: missing RPC result');
|
|
26
|
+
}
|
|
27
|
+
return unsafe.result;
|
|
28
|
+
}
|
|
4
29
|
export const OMEGAX_NETWORKS = {
|
|
5
30
|
devnet: {
|
|
6
31
|
network: 'devnet',
|
|
@@ -85,11 +110,46 @@ export function createRpcClient(connection) {
|
|
|
85
110
|
failure: normalizeClaimSimulationFailure({ err: error, logs: [] }),
|
|
86
111
|
};
|
|
87
112
|
}
|
|
88
|
-
const
|
|
113
|
+
const replaceRecentBlockhash = params.replaceRecentBlockhash ?? true;
|
|
114
|
+
const sigVerify = params.sigVerify ?? true;
|
|
115
|
+
const baseOptions = {
|
|
89
116
|
commitment: params.commitment ?? 'confirmed',
|
|
90
|
-
replaceRecentBlockhash
|
|
91
|
-
sigVerify
|
|
92
|
-
}
|
|
117
|
+
replaceRecentBlockhash,
|
|
118
|
+
sigVerify,
|
|
119
|
+
};
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
result = await simulateSignedTransaction(connection, tx, baseOptions);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (!shouldRetrySignedSimulationWithoutSigVerify({
|
|
126
|
+
error,
|
|
127
|
+
sigVerify,
|
|
128
|
+
})) {
|
|
129
|
+
return {
|
|
130
|
+
ok: false,
|
|
131
|
+
logs: [],
|
|
132
|
+
unitsConsumed: null,
|
|
133
|
+
err: error,
|
|
134
|
+
failure: normalizeClaimSimulationFailure({ err: error, logs: [] }),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
result = await simulateSignedTransaction(connection, tx, {
|
|
139
|
+
...baseOptions,
|
|
140
|
+
sigVerify: false,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (retryError) {
|
|
144
|
+
return {
|
|
145
|
+
ok: false,
|
|
146
|
+
logs: [],
|
|
147
|
+
unitsConsumed: null,
|
|
148
|
+
err: retryError,
|
|
149
|
+
failure: normalizeClaimSimulationFailure({ err: retryError, logs: [] }),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
93
153
|
const logs = result.value.logs ?? [];
|
|
94
154
|
const unitsConsumed = typeof result.value.unitsConsumed === 'number'
|
|
95
155
|
? result.value.unitsConsumed
|
package/dist/transactions.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare function decodeSolanaTransaction(input: string | Uint8Array | Buf
|
|
|
4
4
|
export declare function serializeSolanaTransaction(transaction: SolanaTransaction): Buffer;
|
|
5
5
|
export declare function serializeSolanaTransactionBase64(transaction: SolanaTransaction): string;
|
|
6
6
|
export declare function solanaTransactionMessageBytes(transaction: SolanaTransaction): Uint8Array;
|
|
7
|
+
export declare function solanaTransactionIntentMessageBytes(transaction: SolanaTransaction): Uint8Array;
|
|
7
8
|
export declare function solanaTransactionMessageBase64(input: SolanaTransaction | string | Uint8Array | Buffer): string;
|
|
8
9
|
export declare function solanaTransactionRequiredSigner(transaction: SolanaTransaction): string | null;
|
|
9
10
|
export declare function solanaTransactionFirstSignature(transaction: SolanaTransaction): string | null;
|
package/dist/transactions.js
CHANGED
|
@@ -57,6 +57,23 @@ export function solanaTransactionMessageBytes(transaction) {
|
|
|
57
57
|
}
|
|
58
58
|
return transaction.message.serialize();
|
|
59
59
|
}
|
|
60
|
+
function normalizeSolanaMessageBytesIgnoringRecentBlockhash(messageBytes) {
|
|
61
|
+
const normalized = Uint8Array.from(messageBytes);
|
|
62
|
+
const messagePrefix = normalized[0] ?? 0;
|
|
63
|
+
const isVersioned = (messagePrefix & 0x80) !== 0;
|
|
64
|
+
let cursor = isVersioned ? 1 : 0;
|
|
65
|
+
cursor += 3;
|
|
66
|
+
const { length: accountKeyCount, bytesRead } = decodeShortVecLength(normalized, cursor);
|
|
67
|
+
cursor += bytesRead + accountKeyCount * 32;
|
|
68
|
+
if (cursor + 32 > normalized.length) {
|
|
69
|
+
throw new Error('invalid serialized transaction message');
|
|
70
|
+
}
|
|
71
|
+
normalized.fill(0, cursor, cursor + 32);
|
|
72
|
+
return normalized;
|
|
73
|
+
}
|
|
74
|
+
export function solanaTransactionIntentMessageBytes(transaction) {
|
|
75
|
+
return normalizeSolanaMessageBytesIgnoringRecentBlockhash(solanaTransactionMessageBytes(transaction));
|
|
76
|
+
}
|
|
60
77
|
export function solanaTransactionMessageBase64(input) {
|
|
61
78
|
const transaction = typeof input === 'string' || input instanceof Uint8Array || Buffer.isBuffer(input)
|
|
62
79
|
? decodeSolanaTransaction(input)
|