mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-17 15:10:27 +00:00
Merge branch 'main' into jup-sol
This commit is contained in:
@@ -13,7 +13,7 @@ export async function create_image(
|
||||
agent: SolanaAgentKit,
|
||||
prompt: string,
|
||||
size: "256x256" | "512x512" | "1024x1024" = "1024x1024",
|
||||
n: number = 1
|
||||
n: number = 1,
|
||||
) {
|
||||
try {
|
||||
if (!agent.openai_api_key) {
|
||||
@@ -21,7 +21,7 @@ export async function create_image(
|
||||
}
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: agent.openai_api_key
|
||||
apiKey: agent.openai_api_key,
|
||||
});
|
||||
|
||||
const response = await openai.images.generate({
|
||||
@@ -31,9 +31,8 @@ export async function create_image(
|
||||
});
|
||||
|
||||
return {
|
||||
images: response.data.map((img) => img.url),
|
||||
images: response.data.map((img: any) => img.url),
|
||||
};
|
||||
|
||||
} catch (error: any) {
|
||||
throw new Error(`Image generation failed: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
export * from './request_faucet_funds';
|
||||
export * from './deploy_token';
|
||||
export * from './deploy_collection';
|
||||
export * from './get_balance';
|
||||
export * from './mint_nft';
|
||||
export * from './transfer';
|
||||
export * from './trade';
|
||||
export * from './register_domain';
|
||||
export * from './launch_pumpfun_token';
|
||||
export * from "./request_faucet_funds";
|
||||
export * from "./deploy_token";
|
||||
export * from "./deploy_collection";
|
||||
export * from "./get_balance";
|
||||
export * from "./mint_nft";
|
||||
export * from "./transfer";
|
||||
export * from "./trade";
|
||||
export * from "./register_domain";
|
||||
export * from "./launch_pumpfun_token";
|
||||
export * from "./lend";
|
||||
export * from "./get_tps";
|
||||
export * from './stake_with_jup';
|
||||
@@ -1,94 +1,60 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { LuloAccountDetailsResponse, LuloDepositAssetMint } from "../types";
|
||||
import { getPriorityFees } from "../utils/send_tx";
|
||||
import { LULO_API } from "../constants";
|
||||
import { LuloAccountDetailsResponse } from "../types";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
|
||||
/**
|
||||
* Lend tokens for yields using Lulo
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param asset Mint address of the token to lend (as supported by Lulo)
|
||||
* @param amount Amount to lend (in token decimals)
|
||||
* @param LULO_API_KEY Valid API key for Lulo
|
||||
* @param amount Amount of USDC to lend
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function lendAsset(
|
||||
agent: SolanaAgentKit,
|
||||
asset: LuloDepositAssetMint,
|
||||
amount: number,
|
||||
LULO_API_KEY = "",
|
||||
amount: number
|
||||
): Promise<string> {
|
||||
try {
|
||||
if (!LULO_API_KEY) {
|
||||
throw new Error("Missing Lulo API key");
|
||||
}
|
||||
|
||||
const request = {
|
||||
owner: agent.wallet.publicKey.toBase58(),
|
||||
mintAddress: asset.toBase58(),
|
||||
depositAmount: amount.toString(),
|
||||
};
|
||||
|
||||
const priorityFees = await getPriorityFees(agent.connection);
|
||||
const priority = `?priorityFee=${priorityFees.median}`;
|
||||
|
||||
const response = await fetch(
|
||||
`${LULO_API}/generate/account/deposit${priority}`,
|
||||
`https://blink.lulo.fi/actions?amount=${amount}&symbol=USDC`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(),
|
||||
"x-api-key": LULO_API_KEY,
|
||||
},
|
||||
body: JSON.stringify(request),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
account: agent.wallet.publicKey.toBase58(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
const {
|
||||
data: { transactionMeta },
|
||||
} = await response.json();
|
||||
const data = await response.json();
|
||||
|
||||
// Deserialize the transaction
|
||||
const luloTxn = VersionedTransaction.deserialize(
|
||||
Buffer.from(transactionMeta[0].transaction, "base64"),
|
||||
Buffer.from(data.transaction, "base64")
|
||||
);
|
||||
|
||||
// Get a recent blockhash and set it
|
||||
const { blockhash } = await agent.connection.getLatestBlockhash();
|
||||
luloTxn.message.recentBlockhash = blockhash;
|
||||
|
||||
// Sign and send transaction
|
||||
luloTxn.sign([agent.wallet]);
|
||||
const signature = await agent.connection.sendTransaction(luloTxn);
|
||||
|
||||
const signature = await agent.connection.sendTransaction(luloTxn, {
|
||||
preflightCommitment: "confirmed",
|
||||
maxRetries: 3,
|
||||
});
|
||||
|
||||
// Wait for confirmation using the latest strategy
|
||||
const latestBlockhash = await agent.connection.getLatestBlockhash();
|
||||
await agent.connection.confirmTransaction({
|
||||
signature,
|
||||
blockhash: latestBlockhash.blockhash,
|
||||
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
|
||||
});
|
||||
|
||||
return signature;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Lending failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch lending details for agent
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param LULO_API_KEY Valid API key for Lulo
|
||||
* @returns Lending account details
|
||||
*/
|
||||
export async function getLendingDetails(
|
||||
agent: SolanaAgentKit,
|
||||
LULO_API_KEY = "",
|
||||
): Promise<LuloAccountDetailsResponse> {
|
||||
try {
|
||||
if (!LULO_API_KEY) {
|
||||
throw new Error("Missing Lulo API key");
|
||||
}
|
||||
|
||||
const response = await fetch(`${LULO_API}/account`, {
|
||||
headers: {
|
||||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(),
|
||||
"x-api-key": LULO_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
const { data } = await response.json();
|
||||
|
||||
return data as LuloAccountDetailsResponse;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Failed to fetch lending details: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user