Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion lazer/contracts/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"check-trusted-signer": "pnpm ts-node scripts/check_trusted_signer.ts"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
"@coral-xyz/anchor": "^0.30.1",
"@pythnetwork/pyth-lazer-sdk": "^0.3.1",
"@solana/web3.js": "^1.98.0"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
Expand Down
50 changes: 50 additions & 0 deletions lazer/contracts/solana/scripts/add_ed25519_signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
import yargs from "yargs/yargs";
import { readFileSync } from "fs";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";

// Add a trusted signer or change its expiry time.
//
// Example:
// pnpm ts-node scripts/add_ed25519_signer.ts --url 'https://api.testnet.solana.com' \
// --keypair-path .../key.json --trusted-signer HaXscpSUcbCLSnPQB8Z7H6idyANxp1mZAXTbHeYpfrJJ \
// --expiry-time-seconds 2057930841
async function main() {
let argv = await yargs(process.argv.slice(2))
.options({
url: { type: "string", demandOption: true },
"keypair-path": { type: "string", demandOption: true },
"trusted-signer": { type: "string", demandOption: true },
"expiry-time-seconds": { type: "number", demandOption: true },
})
.parse();

const keypair = anchor.web3.Keypair.fromSecretKey(
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))),
);

const wallet = new NodeWallet(keypair);
const connection = new anchor.web3.Connection(argv.url, {
commitment: "confirmed",
});
const provider = new anchor.AnchorProvider(connection, wallet);

const program: Program<PythLazerSolanaContract> = new Program(
pythLazerSolanaContractIdl as PythLazerSolanaContract,
provider,
);

await program.methods
.update(
new anchor.web3.PublicKey(argv.trustedSigner),
new anchor.BN(argv.expiryTimeSeconds),
)
.accounts({})
.rpc();
console.log("signer updated");
}

main();
8 changes: 4 additions & 4 deletions lazer/contracts/solana/scripts/check_trusted_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ async function main() {

// Print storage info
console.log("Storage Account Info:");
console.log("--------------------");
console.log("---------------------");
console.log("Top Authority:", storage.topAuthority.toBase58());
console.log("Treasury:", storage.treasury.toBase58());
console.log("\nTrusted Signers:");
console.log("----------------");
console.log("\nTrusted Ed25519 Signers:");
console.log("------------------------");

const trustedSigners = storage.trustedSigners.slice(
0,
Expand All @@ -67,7 +67,7 @@ async function main() {
}

console.log("\nTrusted ECDSA Signers:");
console.log("----------------");
console.log("----------------------");

const trustedEcdsaSigners = storage.trustedEcdsaSigners.slice(
0,
Expand Down
76 changes: 76 additions & 0 deletions lazer/contracts/solana/scripts/verify_ed25519_message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract";
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json";
import yargs from "yargs/yargs";
import { readFileSync } from "fs";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { createEd25519Instruction } from "@pythnetwork/pyth-lazer-sdk";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually can you move this function to @pythnetwork/pyth-lazer-solana-contract. It makes sense to be here and we want to remove it from js-sdk to remove the solana dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that's a bigger lift that we need to work on sometime later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed solana deps from @pythnetwork/pyth-lazer-sdk and moved the code to ``@pythnetwork/pyth-lazer-solana-contract. Preparing @pythnetwork/pyth-lazer-solana-contract` for publishing is tricky, so I'll leave it for later.

import {
sendAndConfirmTransaction,
SendTransactionError,
SYSVAR_INSTRUCTIONS_PUBKEY,
Transaction,
} from "@solana/web3.js";

async function main() {
let argv = await yargs(process.argv.slice(2))
.options({
url: { type: "string", demandOption: true },
"keypair-path": { type: "string", demandOption: true },
message: { type: "string", demandOption: true },
})
.parse();

const keypair = anchor.web3.Keypair.fromSecretKey(
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))),
);

const wallet = new NodeWallet(keypair);
const connection = new anchor.web3.Connection(argv.url, {
commitment: "confirmed",
});
const provider = new anchor.AnchorProvider(connection, wallet);

const program: Program<PythLazerSolanaContract> = new Program(
pythLazerSolanaContractIdl as PythLazerSolanaContract,
provider,
);

const instructionMessage = Buffer.from(argv.message, "hex");
const ed25519Instruction = createEd25519Instruction(
instructionMessage,
1,
12,
);
const lazerInstruction = await program.methods
.verifyMessage(instructionMessage, 0, 0)
.accounts({
payer: wallet.publicKey,
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
})
.instruction();

const transaction = new Transaction().add(
ed25519Instruction,
lazerInstruction,
);
console.log("transaction:", transaction);

try {
const signature = await sendAndConfirmTransaction(
connection,
transaction,
[wallet.payer],
{
skipPreflight: true,
},
);
console.log("Transaction confirmed with signature:", signature);
} catch (e) {
console.log("error", e);
console.log(e.getLogs());
}
}

main();
52 changes: 23 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading