@blockrun/clawrouter 0.12.0 → 0.12.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/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +27 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1124,12 +1124,16 @@ type SweepError = {
|
|
|
1124
1124
|
/**
|
|
1125
1125
|
* Sweep all USDC from old (legacy secp256k1) wallet to new (SLIP-10) wallet.
|
|
1126
1126
|
*
|
|
1127
|
+
* The NEW wallet pays gas fees (not the old one). Users can't access the old
|
|
1128
|
+
* wallet from Phantom/Solflare, so they can't send SOL to it. Instead they
|
|
1129
|
+
* fund the new (Phantom-compatible) wallet with a tiny bit of SOL for gas.
|
|
1130
|
+
*
|
|
1127
1131
|
* @param oldKeyBytes - 32-byte private key from legacy derivation
|
|
1128
|
-
* @param
|
|
1132
|
+
* @param newKeyBytes - 32-byte private key from SLIP-10 derivation (pays gas)
|
|
1129
1133
|
* @param rpcUrl - Optional RPC URL override
|
|
1130
1134
|
* @returns SweepResult on success, SweepError on failure
|
|
1131
1135
|
*/
|
|
1132
|
-
declare function sweepSolanaWallet(oldKeyBytes: Uint8Array,
|
|
1136
|
+
declare function sweepSolanaWallet(oldKeyBytes: Uint8Array, newKeyBytes: Uint8Array, rpcUrl?: string): Promise<SweepResult | SweepError>;
|
|
1133
1137
|
|
|
1134
1138
|
/**
|
|
1135
1139
|
* Typed Error Classes for ClawRouter
|
package/dist/index.js
CHANGED
|
@@ -821,17 +821,20 @@ function buildTokenTransferInstruction(source, destination, authority, amount) {
|
|
|
821
821
|
data
|
|
822
822
|
};
|
|
823
823
|
}
|
|
824
|
-
async function sweepSolanaWallet(oldKeyBytes,
|
|
824
|
+
async function sweepSolanaWallet(oldKeyBytes, newKeyBytes, rpcUrl) {
|
|
825
825
|
const url = rpcUrl || process["env"].CLAWROUTER_SOLANA_RPC_URL || SOLANA_DEFAULT_RPC2;
|
|
826
826
|
const rpc = createSolanaRpc2(url);
|
|
827
|
-
const oldSigner = await
|
|
827
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
828
|
+
createKeyPairSignerFromPrivateKeyBytes(oldKeyBytes),
|
|
829
|
+
createKeyPairSignerFromPrivateKeyBytes(newKeyBytes)
|
|
830
|
+
]);
|
|
828
831
|
const oldAddress = oldSigner.address;
|
|
832
|
+
const newAddress = newSigner.address;
|
|
829
833
|
const mint = solAddress2(SOLANA_USDC_MINT2);
|
|
830
|
-
|
|
831
|
-
let solBalance;
|
|
834
|
+
let newSolBalance;
|
|
832
835
|
try {
|
|
833
|
-
const solResp = await rpc.getBalance(solAddress2(
|
|
834
|
-
|
|
836
|
+
const solResp = await rpc.getBalance(solAddress2(newAddress)).send();
|
|
837
|
+
newSolBalance = solResp.value;
|
|
835
838
|
} catch (err) {
|
|
836
839
|
return {
|
|
837
840
|
error: `Failed to check SOL balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -869,18 +872,18 @@ async function sweepSolanaWallet(oldKeyBytes, newAddress, rpcUrl) {
|
|
|
869
872
|
error: "No USDC found in old wallet. Nothing to sweep.",
|
|
870
873
|
oldAddress,
|
|
871
874
|
newAddress,
|
|
872
|
-
solBalance,
|
|
875
|
+
solBalance: newSolBalance,
|
|
873
876
|
usdcBalance: 0n
|
|
874
877
|
};
|
|
875
878
|
}
|
|
876
879
|
const MIN_SOL_FOR_GAS = 5000000n;
|
|
877
|
-
if (
|
|
878
|
-
const needed = Number(MIN_SOL_FOR_GAS -
|
|
880
|
+
if (newSolBalance < MIN_SOL_FOR_GAS) {
|
|
881
|
+
const needed = Number(MIN_SOL_FOR_GAS - newSolBalance) / 1e9;
|
|
879
882
|
return {
|
|
880
|
-
error: `Insufficient SOL for transaction fees. Send ~${needed.toFixed(4)} SOL to ${
|
|
883
|
+
error: `Insufficient SOL for transaction fees in your new wallet. Send ~${needed.toFixed(4)} SOL to ${newAddress} (your new Phantom-compatible address) to cover gas. Current SOL balance: ${(Number(newSolBalance) / 1e9).toFixed(6)} SOL`,
|
|
881
884
|
oldAddress,
|
|
882
885
|
newAddress,
|
|
883
|
-
solBalance,
|
|
886
|
+
solBalance: newSolBalance,
|
|
884
887
|
usdcBalance
|
|
885
888
|
};
|
|
886
889
|
}
|
|
@@ -892,23 +895,26 @@ async function sweepSolanaWallet(oldKeyBytes, newAddress, rpcUrl) {
|
|
|
892
895
|
};
|
|
893
896
|
}
|
|
894
897
|
try {
|
|
895
|
-
const newAta = await getAssociatedTokenAddress(
|
|
898
|
+
const newAta = await getAssociatedTokenAddress(solAddress2(newAddress), mint);
|
|
896
899
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
897
900
|
const createAtaIx = buildCreateAtaIdempotentInstruction(
|
|
898
|
-
|
|
901
|
+
newSigner.address,
|
|
902
|
+
// new wallet pays for ATA creation
|
|
899
903
|
newAta,
|
|
900
|
-
|
|
904
|
+
solAddress2(newAddress),
|
|
901
905
|
mint
|
|
902
906
|
);
|
|
903
907
|
const transferIx = buildTokenTransferInstruction(
|
|
904
908
|
solAddress2(oldTokenAccount),
|
|
905
909
|
newAta,
|
|
906
910
|
oldSigner.address,
|
|
911
|
+
// old wallet authorizes the token transfer
|
|
907
912
|
usdcBalance
|
|
908
913
|
);
|
|
909
914
|
const txMessage = pipe(
|
|
910
915
|
createTransactionMessage({ version: 0 }),
|
|
911
|
-
(msg) => setTransactionMessageFeePayer(
|
|
916
|
+
(msg) => setTransactionMessageFeePayer(newSigner.address, msg),
|
|
917
|
+
// new wallet pays gas
|
|
912
918
|
(msg) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, msg),
|
|
913
919
|
(msg) => appendTransactionMessageInstructions([createAtaIx, transferIx], msg)
|
|
914
920
|
);
|
|
@@ -931,7 +937,7 @@ async function sweepSolanaWallet(oldKeyBytes, newAddress, rpcUrl) {
|
|
|
931
937
|
error: `Transaction failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
932
938
|
oldAddress,
|
|
933
939
|
newAddress,
|
|
934
|
-
solBalance,
|
|
940
|
+
solBalance: newSolBalance,
|
|
935
941
|
usdcBalance
|
|
936
942
|
};
|
|
937
943
|
}
|
|
@@ -942,7 +948,7 @@ var init_solana_sweep = __esm({
|
|
|
942
948
|
"use strict";
|
|
943
949
|
SOLANA_USDC_MINT2 = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
944
950
|
SOLANA_DEFAULT_RPC2 = "https://api.mainnet-beta.solana.com";
|
|
945
|
-
TOKEN_PROGRAM = "
|
|
951
|
+
TOKEN_PROGRAM = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
946
952
|
ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
947
953
|
SYSTEM_PROGRAM = "11111111111111111111111111111111";
|
|
948
954
|
}
|
|
@@ -4133,6 +4139,9 @@ async function logMigrationWarning(legacyKeyBytes, newKeyBytes) {
|
|
|
4133
4139
|
console.log(`[ClawRouter]`);
|
|
4134
4140
|
console.log(`[ClawRouter] If you had funds in the old wallet, run:`);
|
|
4135
4141
|
console.log(`[ClawRouter] /wallet migrate-solana`);
|
|
4142
|
+
console.log(`[ClawRouter]`);
|
|
4143
|
+
console.log(`[ClawRouter] The new wallet pays gas. Send ~0.005 SOL to:`);
|
|
4144
|
+
console.log(`[ClawRouter] ${newSigner.address}`);
|
|
4136
4145
|
console.log(`[ClawRouter] \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
4137
4146
|
console.log(`[ClawRouter]`);
|
|
4138
4147
|
} catch {
|
|
@@ -8408,7 +8417,7 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
8408
8417
|
} catch {
|
|
8409
8418
|
}
|
|
8410
8419
|
const { sweepSolanaWallet: sweepSolanaWallet2 } = await Promise.resolve().then(() => (init_solana_sweep(), solana_sweep_exports));
|
|
8411
|
-
const result = await sweepSolanaWallet2(legacyKeyBytes,
|
|
8420
|
+
const result = await sweepSolanaWallet2(legacyKeyBytes, newKeyBytes);
|
|
8412
8421
|
if ("error" in result) {
|
|
8413
8422
|
return {
|
|
8414
8423
|
text: [
|