Skip to content

Feat: add initial SVM signer utils #2003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@across-protocol/sdk": "4.2.5",
"@arbitrum/sdk": "^4.0.2",
"@consensys/linea-sdk": "^0.2.1",
"@coral-xyz/borsh": "^0.30.1",
"@defi-wonderland/smock": "^2.3.5",
"@eth-optimism/sdk": "^3.3.2",
"@ethersproject/abi": "^5.7.0",
Expand All @@ -26,6 +27,7 @@
"@maticnetwork/maticjs": "^3.6.0",
"@maticnetwork/maticjs-ethers": "^1.0.3",
"@openzeppelin/hardhat-upgrades": "^1.28.0",
"@solana/web3.js": "2.0.0",
"@uma/common": "2.33.0",
"@uma/logger": "^1.3.0",
"axios": "^1.7.4",
Expand Down
28 changes: 28 additions & 0 deletions src/utils/SvmSignerUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
createKeyPairSignerFromPrivateKeyBytes,
KeyPairSigner,
createKeyPairFromBytes,
createSignerFromKeyPair,
Wallet,
} from "./";
import fs from "fs";

export async function getSvmSignerFromEvmSigner(evmSigner: Wallet): Promise<KeyPairSigner> {
// Extract the private key from the evm signer and use it to create a svm signer.
const evmPrivateKey = evmSigner._signingKey().privateKey;
return await getSvmSignerFromPrivateKey(evmPrivateKey);
}

export async function getSvmSignerFromFile(filePath: string): Promise<KeyPairSigner> {
const keypairFile = fs.readFileSync(filePath);
const keypairBytes = new Uint8Array(JSON.parse(keypairFile.toString()));

// Create a KeyPairSigner from the bytes.
const keys = await createKeyPairFromBytes(keypairBytes);
return await createSignerFromKeyPair(keys);
}

export async function getSvmSignerFromPrivateKey(privateKey: string): Promise<KeyPairSigner> {
const privateKeyAsBytes = Uint8Array.from(Buffer.from(privateKey.slice(2), "hex"));
return await createKeyPairSignerFromPrivateKeyBytes(privateKeyAsBytes);
}
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export {
TOKEN_EQUIVALENCE_REMAPPING,
} from "@across-protocol/constants";

export {
createKeyPairSignerFromPrivateKeyBytes,
KeyPairSigner,
createSignerFromKeyPair,
createKeyPairFromBytes,
} from "@solana/web3.js";

// TypeChain exports used in the bot.
export {
getContractInfoFromAddress,
Expand Down
Loading