apow-cli 0.6.1 → 0.6.2
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/bridge/solana.js +23 -10
- package/package.json +1 -1
package/dist/bridge/solana.js
CHANGED
|
@@ -125,18 +125,31 @@ async function getSplTokenBalance(publicKeyBase58, mintAddress) {
|
|
|
125
125
|
const parsed = accounts.value[0].account.data.parsed;
|
|
126
126
|
return parsed?.info?.tokenAmount?.uiAmount ?? 0;
|
|
127
127
|
}
|
|
128
|
-
/** Deserialize, sign, and submit a
|
|
129
|
-
async function signAndSendTransaction(
|
|
130
|
-
const { Connection, VersionedTransaction } = await Promise.resolve().then(() => __importStar(require("@solana/web3.js")));
|
|
128
|
+
/** Deserialize, sign, and submit a serialized Solana transaction (hex or base64). */
|
|
129
|
+
async function signAndSendTransaction(serializedTx, keypair) {
|
|
130
|
+
const { Connection, VersionedTransaction, Transaction } = await Promise.resolve().then(() => __importStar(require("@solana/web3.js")));
|
|
131
131
|
const connection = new Connection(getSolanaRpcUrl(), "confirmed");
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
preflightCommitment: "confirmed",
|
|
138
|
-
});
|
|
132
|
+
// deBridge returns hex (0x...), other bridges may return base64
|
|
133
|
+
const txBuffer = serializedTx.startsWith("0x")
|
|
134
|
+
? Buffer.from(serializedTx.slice(2), "hex")
|
|
135
|
+
: Buffer.from(serializedTx, "base64");
|
|
136
|
+
// Get fresh blockhash (deBridge-generated txs may have stale ones)
|
|
139
137
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
138
|
+
// Try versioned transaction first, fall back to legacy.
|
|
139
|
+
// Skip preflight: deBridge Jupiter routes may fail simulation but succeed on-chain.
|
|
140
|
+
let signature;
|
|
141
|
+
try {
|
|
142
|
+
const tx = VersionedTransaction.deserialize(txBuffer);
|
|
143
|
+
tx.message.recentBlockhash = blockhash;
|
|
144
|
+
tx.sign([keypair]);
|
|
145
|
+
signature = await connection.sendTransaction(tx, { skipPreflight: true });
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
const tx = Transaction.from(txBuffer);
|
|
149
|
+
tx.recentBlockhash = blockhash;
|
|
150
|
+
tx.sign(keypair);
|
|
151
|
+
signature = await connection.sendRawTransaction(tx.serialize(), { skipPreflight: true });
|
|
152
|
+
}
|
|
140
153
|
await connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight }, "confirmed");
|
|
141
154
|
return signature;
|
|
142
155
|
}
|