Merge branch 'main' into jup-list

This commit is contained in:
aryan
2024-12-19 05:45:01 +05:30
30 changed files with 3384 additions and 89 deletions

View File

@@ -27,10 +27,6 @@ export async function deploy_token(
);
const mint = Keypair.generate();
console.log("Mint address: ", mint.publicKey.toString());
console.log("Agent address: ", agent.wallet_address.toString());
let account_create_ix = SystemProgram.createAccount({
fromPubkey: agent.wallet_address,
newAccountPubkey: mint.publicKey,
@@ -51,13 +47,6 @@ export async function deploy_token(
let hash = await sendTx(agent, tx, [mint]);
console.log("Transaction hash: ", hash);
console.log(
"Token deployed successfully. Mint address: ",
mint.publicKey.toString()
);
return {
mint: mint.publicKey,
};

35
src/tools/fetch_price.ts Normal file
View File

@@ -0,0 +1,35 @@
import { SolanaAgentKit } from "../index";
import { Tool } from "langchain/tools";
/**
* Fetch the price of a given token in USDC using Jupiter API
* @param agent SolanaAgentKit instance
* @param tokenId The token mint address
* @returns The price of the token in USDC
*/
export async function fetchPrice(
agent: SolanaAgentKit,
tokenId: string
): Promise<string> {
try {
const response = await fetch(
`https://api.jup.ag/price/v2?ids=${tokenId}`
);
if (!response.ok) {
throw new Error(`Failed to fetch price: ${response.statusText}`);
}
const data = await response.json();
const price = data.data[tokenId]?.price;
if (!price) {
throw new Error("Price data not available for the given token.");
}
return price;
} catch (error: any) {
throw new Error(`Price fetch failed: ${error.message}`);
}
}

View File

@@ -10,3 +10,5 @@ export * from "./launch_pumpfun_token";
export * from "./lend";
export * from "./get_tps";
export * from "./get_token_data";
export * from './stake_with_jup';
export * from "./fetch_price";

View File

@@ -38,7 +38,6 @@ async function uploadMetadata(
finalFormData.append('file', files.file);
}
console.log("Final form data:", finalFormData);
const metadataResponse = await fetch("https://pump.fun/api/ipfs", {
method: "POST",
@@ -46,7 +45,6 @@ async function uploadMetadata(
});
if (!metadataResponse.ok) {
console.log("Metadata response:", await metadataResponse.json());
throw new Error(`Metadata upload failed: ${metadataResponse.statusText}`);
}
@@ -152,30 +150,14 @@ export async function launchPumpFunToken(
options?: PumpFunTokenOptions
) {
try {
// TBD : Remove clgs after approval
console.log("Starting token launch process...");
// Generate mint keypair
const mintKeypair = Keypair.generate();
console.log("Mint public key:", mintKeypair.publicKey.toBase58());
// Upload metadata
console.log("Uploading metadata to IPFS...");
const metadataResponse = await uploadMetadata(tokenName, tokenTicker, description, imageUrl, options);
console.log("Metadata response:", metadataResponse);
// Create token transaction
console.log("Creating token transaction...");
const response = await createTokenTransaction(agent, mintKeypair, metadataResponse, options);
const transactionData = await response.arrayBuffer();
const tx = VersionedTransaction.deserialize(new Uint8Array(transactionData));
// Send transaction with proper blockhash handling
console.log("Sending transaction...");
const signature = await signAndSendTransaction(agent, tx, mintKeypair);
console.log("Token launch successful!");
return {
signature,
mint: mintKeypair.publicKey.toBase58(),

View File

@@ -0,0 +1,56 @@
import { VersionedTransaction } from "@solana/web3.js";
import { SolanaAgentKit } from "../agent";
/**
* Stake SOL with Jup validator
* @param agent SolanaAgentKit instance
* @param amount Amount of SOL to stake
* @returns Transaction signature
*/
export async function stakeWithJup(
agent: SolanaAgentKit,
amount: number,
): Promise<string> {
try {
const res = await fetch(
`https://worker.jup.ag/blinks/swap/So11111111111111111111111111111111111111112/jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v/${amount}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
account: agent.wallet.publicKey.toBase58(),
}),
},
);
const data = await res.json();
const txn = VersionedTransaction.deserialize(
Buffer.from(data.transaction, "base64"),
);
const { blockhash } = await agent.connection.getLatestBlockhash();
txn.message.recentBlockhash = blockhash;
// Sign and send transaction
txn.sign([agent.wallet]);
const signature = await agent.connection.sendTransaction(txn, {
preflightCommitment: "confirmed",
maxRetries: 3,
});
const latestBlockhash = await agent.connection.getLatestBlockhash();
await agent.connection.confirmTransaction({
signature,
blockhash: latestBlockhash.blockhash,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
});
return signature;
} catch (error: any) {
console.error(error);
throw new Error(`jupSOL staking failed: ${error.message}`);
}
}

View File

@@ -19,8 +19,6 @@ export async function trade(
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS,
): Promise<string> {
try {
// Get quote for the swap
console.log(inputMint.toString(), outputMint.toString(), inputAmount, slippageBps);
const quoteResponse = await (
await fetch(
`${JUP_API}/quote?` +