mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-20 23:26:44 +00:00
Merge branch 'main' into feat/drift-tool
This commit is contained in:
@@ -14,6 +14,8 @@ import stakeWithJupAction from "./jupiter/stakeWithJup";
|
||||
import stakeWithSolayerAction from "./solayer/stakeWithSolayer";
|
||||
import registerDomainAction from "./sns/registerDomain";
|
||||
import lendAssetAction from "./lulo/lendAsset";
|
||||
import luloLendAction from "./lulo/luloLend";
|
||||
import luloWithdrawAction from "./lulo/luloWithdraw";
|
||||
import createGibworkTaskAction from "./gibwork/createGibworkTask";
|
||||
import resolveSolDomainAction from "./sns/resolveSolDomain";
|
||||
import pythFetchPriceAction from "./pyth/pythFetchPrice";
|
||||
@@ -67,6 +69,9 @@ import driftSpotTokenSwapAction from "./drift/swapSpotToken";
|
||||
import perpMarktetFundingRateAction from "./drift/perpMarketFundingRate";
|
||||
import entryQuoteOfPerpTradeAction from "./drift/entryQuoteOfPerpTrade";
|
||||
import lendAndBorrowAPYAction from "./drift/getLendAndBorrowAPY";
|
||||
import getVoltrPositionValuesAction from "./voltr/getPositionValues";
|
||||
import depositVoltrStrategyAction from "./voltr/depositStrategy";
|
||||
import withdrawVoltrStrategyAction from "./voltr/withdrawStrategy";
|
||||
|
||||
export const ACTIONS = {
|
||||
WALLET_ADDRESS_ACTION: getWalletAddressAction,
|
||||
@@ -86,6 +91,8 @@ export const ACTIONS = {
|
||||
STAKE_WITH_SOLAYER_ACTION: stakeWithSolayerAction,
|
||||
REGISTER_DOMAIN_ACTION: registerDomainAction,
|
||||
LEND_ASSET_ACTION: lendAssetAction,
|
||||
LULO_LEND_ACTION: luloLendAction,
|
||||
LULO_WITHDRAW_ACTION: luloWithdrawAction,
|
||||
CREATE_GIBWORK_TASK_ACTION: createGibworkTaskAction,
|
||||
RESOLVE_SOL_DOMAIN_ACTION: resolveSolDomainAction,
|
||||
PYTH_FETCH_PRICE_ACTION: pythFetchPriceAction,
|
||||
@@ -140,6 +147,9 @@ export const ACTIONS = {
|
||||
DRIFT_PERP_MARKET_FUNDING_RATE_ACTION: perpMarktetFundingRateAction,
|
||||
DRIFT_GET_ENTRY_QUOTE_OF_PERP_TRADE_ACTION: entryQuoteOfPerpTradeAction,
|
||||
DRIFT_GET_LEND_AND_BORROW_APY_ACTION: lendAndBorrowAPYAction,
|
||||
GET_VOLTR_POSITION_VALUES_ACTION: getVoltrPositionValuesAction,
|
||||
DEPOSIT_VOLTR_STRATEGY_ACTION: depositVoltrStrategyAction,
|
||||
WITHDRAW_VOLTR_STRATEGY_ACTION: withdrawVoltrStrategyAction,
|
||||
};
|
||||
|
||||
export type { Action, ActionExample, Handler } from "../types/action";
|
||||
|
||||
62
src/actions/lulo/luloLend.ts
Normal file
62
src/actions/lulo/luloLend.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { luloLend } from "../../tools/lulo";
|
||||
|
||||
const luloLendAction: Action = {
|
||||
name: "LULO_LEND",
|
||||
similes: [
|
||||
"lend USDC with lulo",
|
||||
"lend PYUSD with lulo",
|
||||
"lend USDS with lulo",
|
||||
"lend USDT with lulo",
|
||||
"lend SQL with lulo",
|
||||
"lend jitoSQL with lulo",
|
||||
"lend bSQL with lulo",
|
||||
"lend mSQL with lulo",
|
||||
"lend BONK with lulo",
|
||||
"lend JUP with lulo",
|
||||
],
|
||||
description: "Lend SPL tokens using Lulo protocol",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
amount: 100,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "4xKpN2...",
|
||||
message: "Successfully lend 100 USDC",
|
||||
},
|
||||
explanation: "Lend 100 USDC on Lulo",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
mintAddress: z.string().describe("SPL Mint address"),
|
||||
amount: z.number().positive().describe("Amount to lend"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const mintAddress = input.mintAddress as string;
|
||||
const amount = input.amount as number;
|
||||
|
||||
const response = await luloLend(agent, mintAddress, amount);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: response,
|
||||
message: `Successfully lend ${amount} of token ${mintAddress}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Lend failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default luloLendAction;
|
||||
62
src/actions/lulo/luloWithdraw.ts
Normal file
62
src/actions/lulo/luloWithdraw.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { luloWithdraw } from "../../tools/lulo";
|
||||
|
||||
const luloWithdrawAction: Action = {
|
||||
name: "LULO_WITHDRAW",
|
||||
similes: [
|
||||
"withdraw USDC with lulo",
|
||||
"withdraw PYUSD with lulo",
|
||||
"withdraw USDS with lulo",
|
||||
"withdraw USDT with lulo",
|
||||
"withdraw SQL with lulo",
|
||||
"withdraw jitoSQL with lulo",
|
||||
"withdraw bSQL with lulo",
|
||||
"withdraw mSQL with lulo",
|
||||
"withdraw BONK with lulo",
|
||||
"withdraw JUP with lulo",
|
||||
],
|
||||
description: "Withdraw SPL tokens using Lulo protocol",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
amount: 100,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "4xKpN2...",
|
||||
message: "Successfully withdraw 100 USDC",
|
||||
},
|
||||
explanation: "Withdraw 100 USDC on Lulo",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
mintAddress: z.string().describe("SPL Mint address"),
|
||||
amount: z.number().positive().describe("Amount to lend"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const mintAddress = input.mintAddress as string;
|
||||
const amount = input.amount as number;
|
||||
|
||||
const response = await luloWithdraw(agent, mintAddress, amount);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: response,
|
||||
message: `Successfully withdraw ${amount} of token ${mintAddress}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Withdraw failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default luloWithdrawAction;
|
||||
83
src/actions/voltr/depositStrategy.ts
Normal file
83
src/actions/voltr/depositStrategy.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
|
||||
const depositVoltrStrategyAction: Action = {
|
||||
name: "DEPOSIT_VOLTR_STRATEGY",
|
||||
similes: [
|
||||
"deposit to voltr strategy",
|
||||
"add funds to voltr vault strategy",
|
||||
"invest in voltr strategy",
|
||||
"deposit assets to voltr",
|
||||
"contribute to voltr vault",
|
||||
"fund voltr strategy",
|
||||
],
|
||||
description: "Deposit assets into a specific strategy within a Voltr vault",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
depositAmount: "1000000000", // 1 USDC with 6 decimals
|
||||
vault: "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K",
|
||||
strategy: "9ZQQYvr4x7AMqd6abVa1f5duGjti5wk1MHsX6hogPsLk",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
vault: "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K",
|
||||
strategy: "9ZQQYvr4x7AMqd6abVa1f5duGjti5wk1MHsX6hogPsLk",
|
||||
signature: "2ZE7Rz...",
|
||||
message: "Successfully deposited 1000000000 into strategy",
|
||||
},
|
||||
explanation: "Deposit 1 USDC into a Voltr vault strategy",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
depositAmount: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The amount to deposit (in base units including decimals)"),
|
||||
vault: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe(
|
||||
"The public key of the Voltr source vault to take assets from, e.g., 'Ga27...'",
|
||||
),
|
||||
strategy: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe(
|
||||
"The public key of the initialized target strategy to deposit into, e.g., 'Jheh...'",
|
||||
),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const depositAmount = new BN(input.depositAmount);
|
||||
const vault = new PublicKey(input.vault);
|
||||
const strategy = new PublicKey(input.strategy);
|
||||
|
||||
const signature = await agent.voltrDepositStrategy(
|
||||
depositAmount,
|
||||
vault,
|
||||
strategy,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
vault: vault.toBase58(),
|
||||
strategy: strategy.toBase58(),
|
||||
signature,
|
||||
message: `Successfully deposited ${input.depositAmount} into strategy`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to deposit into strategy: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default depositVoltrStrategyAction;
|
||||
74
src/actions/voltr/getPositionValues.ts
Normal file
74
src/actions/voltr/getPositionValues.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
const getVoltrPositionValuesAction: Action = {
|
||||
name: "GET_VOLTR_POSITION_VALUES",
|
||||
similes: [
|
||||
"get voltr vault value",
|
||||
"check voltr position",
|
||||
"get voltr vault assets",
|
||||
"view voltr holdings",
|
||||
"check voltr portfolio",
|
||||
"get voltr vault breakdown",
|
||||
],
|
||||
description:
|
||||
"Get the current position values and total assets for a Voltr vault",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
vault: "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
data: {
|
||||
totalValue: 1000000,
|
||||
positions: [
|
||||
{
|
||||
strategy: "4JHtgXyMb9gFJ1hGd2sh645jrZcxurSG3QP7Le3aTMTx",
|
||||
value: 600000,
|
||||
},
|
||||
{
|
||||
strategy: "4i9kzGr1UkxBCCUkQUQ4vsF51fjdt2knKxrwM1h1NW4g",
|
||||
value: 400000,
|
||||
},
|
||||
],
|
||||
},
|
||||
message: "Successfully retrieved Voltr vault position values",
|
||||
},
|
||||
explanation:
|
||||
"Get position values for a Voltr vault showing total value and value per strategy",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
vault: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The public key of the Voltr vault to query, e.g., 'Ga27...'"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const vault = new PublicKey(input.vault);
|
||||
|
||||
const result = await agent.voltrGetPositionValues(vault);
|
||||
const positionData = JSON.parse(result);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
vault: vault.toBase58(),
|
||||
data: positionData,
|
||||
message: "Successfully retrieved Voltr vault position values",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get vault position values: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getVoltrPositionValuesAction;
|
||||
83
src/actions/voltr/withdrawStrategy.ts
Normal file
83
src/actions/voltr/withdrawStrategy.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Action } from "../../types/action";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
|
||||
const withdrawVoltrStrategyAction: Action = {
|
||||
name: "WITHDRAW_VOLTR_STRATEGY",
|
||||
similes: [
|
||||
"withdraw from voltr strategy",
|
||||
"remove funds from voltr vault strategy",
|
||||
"take out from voltr strategy",
|
||||
"withdraw assets from voltr",
|
||||
"pull from voltr vault",
|
||||
"redeem from voltr strategy",
|
||||
],
|
||||
description: "Withdraw assets from a specific strategy within a Voltr vault",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
withdrawAmount: "1000000000", // 1 USDC with 6 decimals
|
||||
vault: "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K",
|
||||
strategy: "9ZQQYvr4x7AMqd6abVa1f5duGjti5wk1MHsX6hogPsLk",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
vault: "7opUkqYtxmQRriZvwZkPcg6LqmGjAh1RSEsVrdsGDx5K",
|
||||
strategy: "9ZQQYvr4x7AMqd6abVa1f5duGjti5wk1MHsX6hogPsLk",
|
||||
signature: "2ZE7Rz...",
|
||||
message: "Successfully withdrew 1000000000 from strategy",
|
||||
},
|
||||
explanation: "Withdraw 1 USDC from a Voltr vault strategy",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
withdrawAmount: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The amount to withdraw (in base units including decimals)"),
|
||||
vault: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe(
|
||||
"The public key of the Voltr source vault to deposit assets into, e.g., 'Ga27...'",
|
||||
),
|
||||
strategy: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe(
|
||||
"The public key of the initialized target strategy to withdraw from, e.g., 'Jheh...'",
|
||||
),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const withdrawAmount = new BN(input.withdrawAmount);
|
||||
const vault = new PublicKey(input.vault);
|
||||
const strategy = new PublicKey(input.strategy);
|
||||
|
||||
const signature = await agent.voltrWithdrawStrategy(
|
||||
withdrawAmount,
|
||||
vault,
|
||||
strategy,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
vault: vault.toBase58(),
|
||||
strategy: strategy.toBase58(),
|
||||
signature,
|
||||
message: `Successfully withdrew ${input.withdrawAmount} from strategy`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to withdraw from strategy: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default withdrawVoltrStrategyAction;
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
getPrimaryDomain,
|
||||
launchPumpFunToken,
|
||||
lendAsset,
|
||||
luloLend,
|
||||
luloWithdraw,
|
||||
mintCollectionNFT,
|
||||
openbookCreateMarket,
|
||||
manifestCreateMarket,
|
||||
@@ -107,6 +109,9 @@ import {
|
||||
calculatePerpMarketFundingRate,
|
||||
getEntryQuoteOfPerpTrade,
|
||||
getLendingAndBorrowAPY,
|
||||
voltrGetPositionValues,
|
||||
voltrDepositStrategy,
|
||||
voltrWithdrawStrategy,
|
||||
} from "../tools";
|
||||
import {
|
||||
Config,
|
||||
@@ -320,6 +325,14 @@ export class SolanaAgentKit {
|
||||
return lendAsset(this, amount);
|
||||
}
|
||||
|
||||
async luloLend(mintAddress: string, amount: number): Promise<string> {
|
||||
return luloLend(this, mintAddress, amount);
|
||||
}
|
||||
|
||||
async luloWithdraw(mintAddress: string, amount: number): Promise<string> {
|
||||
return luloWithdraw(this, mintAddress, amount);
|
||||
}
|
||||
|
||||
async getTPS(): Promise<number> {
|
||||
return getTPS(this);
|
||||
}
|
||||
@@ -640,24 +653,43 @@ export class SolanaAgentKit {
|
||||
}
|
||||
|
||||
async create3LandCollection(
|
||||
optionsWithBase58: StoreInitOptions,
|
||||
collectionOpts: CreateCollectionOptions,
|
||||
isDevnet: boolean = false,
|
||||
): Promise<string> {
|
||||
let optionsWithBase58: StoreInitOptions = {
|
||||
privateKey: this.wallet.secretKey,
|
||||
};
|
||||
if (isDevnet) {
|
||||
optionsWithBase58.isMainnet = false;
|
||||
} else {
|
||||
optionsWithBase58.isMainnet = true;
|
||||
}
|
||||
|
||||
const tx = await createCollection(optionsWithBase58, collectionOpts);
|
||||
return `Transaction: ${tx}`;
|
||||
}
|
||||
|
||||
async create3LandNft(
|
||||
optionsWithBase58: StoreInitOptions,
|
||||
collectionAccount: string,
|
||||
createItemOptions: CreateSingleOptions,
|
||||
isMainnet: boolean,
|
||||
isDevnet: boolean = false,
|
||||
withPool: boolean = false,
|
||||
): Promise<string> {
|
||||
let optionsWithBase58: StoreInitOptions = {
|
||||
privateKey: this.wallet.secretKey,
|
||||
};
|
||||
if (isDevnet) {
|
||||
optionsWithBase58.isMainnet = false;
|
||||
} else {
|
||||
optionsWithBase58.isMainnet = true;
|
||||
}
|
||||
|
||||
const tx = await createSingle(
|
||||
optionsWithBase58,
|
||||
collectionAccount,
|
||||
createItemOptions,
|
||||
isMainnet,
|
||||
!isDevnet,
|
||||
withPool,
|
||||
);
|
||||
return `Transaction: ${tx}`;
|
||||
}
|
||||
@@ -736,6 +768,7 @@ export class SolanaAgentKit {
|
||||
async createDriftUserAccount(depositAmount: number, depositSymbol: string) {
|
||||
return await createDriftUserAccount(this, depositAmount, depositSymbol);
|
||||
}
|
||||
|
||||
async createDriftVault(params: {
|
||||
name: string;
|
||||
marketName: `${string}-${string}`;
|
||||
@@ -749,6 +782,7 @@ export class SolanaAgentKit {
|
||||
}) {
|
||||
return await createVault(this, params);
|
||||
}
|
||||
|
||||
async depositIntoDriftVault(amount: number, vault: string) {
|
||||
return await depositIntoVault(this, amount, vault);
|
||||
}
|
||||
@@ -830,6 +864,7 @@ export class SolanaAgentKit {
|
||||
async updateDriftVaultDelegate(vaultAddress: string, delegate: string) {
|
||||
return await updateVaultDelegate(this, vaultAddress, delegate);
|
||||
}
|
||||
|
||||
getAvailableDriftMarkets(type?: "spot" | "perp") {
|
||||
switch (type) {
|
||||
case "spot":
|
||||
@@ -889,5 +924,24 @@ export class SolanaAgentKit {
|
||||
}
|
||||
async getLendAndBorrowAPY(symbol: string) {
|
||||
return getLendingAndBorrowAPY(this, symbol);
|
||||
|
||||
async voltrDepositStrategy(
|
||||
depositAmount: BN,
|
||||
vault: PublicKey,
|
||||
strategy: PublicKey,
|
||||
): Promise<string> {
|
||||
return voltrDepositStrategy(this, depositAmount, vault, strategy);
|
||||
}
|
||||
|
||||
async voltrWithdrawStrategy(
|
||||
withdrawAmount: BN,
|
||||
vault: PublicKey,
|
||||
strategy: PublicKey,
|
||||
): Promise<string> {
|
||||
return voltrWithdrawStrategy(this, withdrawAmount, vault, strategy);
|
||||
}
|
||||
|
||||
async voltrGetPositionValues(vault: PublicKey): Promise<string> {
|
||||
return voltrGetPositionValues(this, vault);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ export class Solana3LandCreateCollection extends Tool {
|
||||
description = `Creates an NFT Collection that you can visit on 3.land's website (3.land/collection/{collectionAccount})
|
||||
|
||||
Inputs:
|
||||
privateKey (required): represents the privateKey of the wallet - can be an array of numbers, Uint8Array or base58 string
|
||||
isMainnet (required): defines is the tx takes places in mainnet
|
||||
collectionSymbol (required): the symbol of the collection
|
||||
collectionName (required): the name of the collection
|
||||
@@ -26,14 +25,8 @@ export class Solana3LandCreateCollection extends Tool {
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const privateKey = inputFormat.privateKey;
|
||||
const isMainnet = inputFormat.isMainnet;
|
||||
|
||||
const optionsWithBase58: StoreInitOptions = {
|
||||
...(privateKey && { privateKey }),
|
||||
...(isMainnet && { isMainnet }),
|
||||
};
|
||||
|
||||
const collectionSymbol = inputFormat?.collectionSymbol;
|
||||
const collectionName = inputFormat?.collectionName;
|
||||
const collectionDescription = inputFormat?.collectionDescription;
|
||||
@@ -49,8 +42,8 @@ export class Solana3LandCreateCollection extends Tool {
|
||||
};
|
||||
|
||||
const tx = await this.solanaKit.create3LandCollection(
|
||||
optionsWithBase58,
|
||||
collectionOpts,
|
||||
!isMainnet,
|
||||
);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
|
||||
@@ -10,7 +10,6 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
description = `Creates an NFT and lists it on 3.land's website
|
||||
|
||||
Inputs:
|
||||
privateKey (required): represents the privateKey of the wallet - can be an array of numbers, Uint8Array or base58 string
|
||||
collectionAccount (optional): represents the account for the nft collection
|
||||
itemName (required): the name of the NFT
|
||||
sellerFee (required): the fee of the seller
|
||||
@@ -21,7 +20,9 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
mainImageUrl (required): the main image of the NFT
|
||||
coverImageUrl (optional): the cover image of the NFT
|
||||
splHash (optional): the hash of the spl token, if not provided listing will be in $SOL
|
||||
isMainnet (required): defines is the tx takes places in mainnet
|
||||
poolName (optional): the name of the pool
|
||||
isMainnet (required): defines if the tx takes places in mainnet
|
||||
withPool (optional): defines if minted edition will be tied to a liquidity pool
|
||||
`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
@@ -31,13 +32,9 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const privateKey = inputFormat.privateKey;
|
||||
const isMainnet = inputFormat.isMainnet;
|
||||
|
||||
const optionsWithBase58: StoreInitOptions = {
|
||||
...(privateKey && { privateKey }),
|
||||
...(isMainnet && { isMainnet }),
|
||||
};
|
||||
const withPool = inputFormat.withPool;
|
||||
const poolName = inputFormat.poolName;
|
||||
|
||||
const collectionAccount = inputFormat.collectionAccount;
|
||||
|
||||
@@ -52,6 +49,15 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
const coverImageUrl = inputFormat?.coverImageUrl;
|
||||
const splHash = inputFormat?.splHash;
|
||||
|
||||
if (withPool) {
|
||||
if (!poolName) {
|
||||
throw new Error("poolName is required when withPool is true");
|
||||
}
|
||||
if (!splHash) {
|
||||
throw new Error("splHash is required when withPool is true");
|
||||
}
|
||||
}
|
||||
|
||||
const createItemOptions: CreateSingleOptions = {
|
||||
...(itemName && { itemName }),
|
||||
...(sellerFee && { sellerFee }),
|
||||
@@ -63,6 +69,7 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
...(mainImageUrl && { mainImageUrl }),
|
||||
...(coverImageUrl && { coverImageUrl }),
|
||||
...(splHash && { splHash }),
|
||||
...(poolName && { poolName }),
|
||||
};
|
||||
|
||||
if (!collectionAccount) {
|
||||
@@ -70,10 +77,10 @@ export class Solana3LandCreateSingle extends Tool {
|
||||
}
|
||||
|
||||
const tx = await this.solanaKit.create3LandNft(
|
||||
optionsWithBase58,
|
||||
collectionAccount,
|
||||
createItemOptions,
|
||||
isMainnet,
|
||||
!isMainnet,
|
||||
withPool,
|
||||
);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
|
||||
@@ -26,6 +26,7 @@ export * from "./lightprotocol";
|
||||
export * from "./squads";
|
||||
export * from "./helius";
|
||||
export * from "./drift";
|
||||
export * from "./voltr";
|
||||
|
||||
import type { SolanaAgentKit } from "../agent";
|
||||
import {
|
||||
@@ -42,6 +43,8 @@ import {
|
||||
SolanaPumpfunTokenLaunchTool,
|
||||
SolanaCreateImageTool,
|
||||
SolanaLendAssetTool,
|
||||
SolanaLuloLendTool,
|
||||
SolanaLuloWithdrawTool,
|
||||
SolanaTPSCalculatorTool,
|
||||
SolanaStakeTool,
|
||||
SolanaRestakeTool,
|
||||
@@ -121,6 +124,9 @@ import {
|
||||
SolanaRequestUnstakeFromDriftInsuranceFundTool,
|
||||
SolanaStakeToDriftInsuranceFundTool,
|
||||
SolanaUnstakeFromDriftInsuranceFundTool,
|
||||
SolanaVoltrGetPositionValues,
|
||||
SolanaVoltrDepositStrategy,
|
||||
SolanaVoltrWithdrawStrategy,
|
||||
} from "./index";
|
||||
|
||||
export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
@@ -138,6 +144,8 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaPumpfunTokenLaunchTool(solanaKit),
|
||||
new SolanaCreateImageTool(solanaKit),
|
||||
new SolanaLendAssetTool(solanaKit),
|
||||
new SolanaLuloLendTool(solanaKit),
|
||||
new SolanaLuloWithdrawTool(solanaKit),
|
||||
new SolanaTPSCalculatorTool(solanaKit),
|
||||
new SolanaStakeTool(solanaKit),
|
||||
new SolanaRestakeTool(solanaKit),
|
||||
@@ -222,5 +230,8 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaDriftLendAndBorrowAPYTool(solanaKit),
|
||||
new SolanaDriftEntryQuoteOfPerpTradeTool(solanaKit),
|
||||
new SolanaDriftPerpMarketFundingRateTool(solanaKit),
|
||||
new SolanaVoltrGetPositionValues(solanaKit),
|
||||
new SolanaVoltrDepositStrategy(solanaKit),
|
||||
new SolanaVoltrWithdrawStrategy(solanaKit),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./lend_asset";
|
||||
export * from "./lulo_lend";
|
||||
export * from "./lulo_withdraw";
|
||||
|
||||
37
src/langchain/lulo/lulo_lend.ts
Normal file
37
src/langchain/lulo/lulo_lend.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
export class SolanaLuloLendTool extends Tool {
|
||||
name = "solana_lulo_lend";
|
||||
description = `Lend token for yield using Lulo. (support USDC/PYUSD/USDS/USDT/SOL/jitoSOL/bSOL/mSOL/BONK/JUP)
|
||||
Inputs:
|
||||
mintAddress: string, eg "So11111111111111111111111111111111111111112" (required)
|
||||
amount: number, eg 1, 0.01 (required)`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const parsedInput = JSON.parse(input);
|
||||
const mintAddress = parsedInput.mintAddress
|
||||
const amount = parsedInput.amount;
|
||||
|
||||
const tx = await this.solanaKit.luloLend(mintAddress, amount);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Asset lent successfully",
|
||||
transaction: tx,
|
||||
amount,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/langchain/lulo/lulo_withdraw.ts
Normal file
37
src/langchain/lulo/lulo_withdraw.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
|
||||
export class SolanaLuloWithdrawTool extends Tool {
|
||||
name = "solana_lulo_withdraw";
|
||||
description = `Withdraw token USDC using Lulo. (support USDC/PYUSD/USDS/USDT/SOL/jitoSOL/bSOL/mSOL/BONK/JUP)
|
||||
Inputs (input is a json string):
|
||||
mintAddress: string, eg "So11111111111111111111111111111111111111112" (required)
|
||||
amount: number, eg 1, 0.01 (required)`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const parsedInput = JSON.parse(input);
|
||||
const mintAddress = parsedInput.mintAddress
|
||||
const amount = parsedInput.amount;
|
||||
|
||||
const tx = await this.solanaKit.luloWithdraw(mintAddress, amount);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Asset withdraw successfully",
|
||||
transaction: tx,
|
||||
amount,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/langchain/voltr/deposit_strategy.ts
Normal file
39
src/langchain/voltr/deposit_strategy.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
|
||||
export class SolanaVoltrDepositStrategy extends Tool {
|
||||
name = "solana_voltr_deposit_strategy";
|
||||
description = `Deposit amount into a strategy for Voltr's vaults
|
||||
|
||||
Inputs (input is a json string):
|
||||
depositAmount: number (required)
|
||||
vault: string (required)
|
||||
strategy: string (required)
|
||||
`;
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const tx = await this.solanaKit.voltrDepositStrategy(
|
||||
new BN(inputFormat.depositAmount),
|
||||
new PublicKey(inputFormat.vault),
|
||||
new PublicKey(inputFormat.strategy),
|
||||
);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: `Deposited ${inputFormat.depositAmount} into strategy ${inputFormat.strategy} of vault ${inputFormat.vault} successfully`,
|
||||
transaction: tx,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/langchain/voltr/get_position_values.ts
Normal file
18
src/langchain/voltr/get_position_values.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
export class SolanaVoltrGetPositionValues extends Tool {
|
||||
name = "solana_voltr_get_position_values";
|
||||
description = `Get the total asset value and current value for each strategy of a given Voltr vault
|
||||
|
||||
Inputs:
|
||||
vault: string (required)
|
||||
`;
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
async _call(input: string): Promise<string> {
|
||||
return this.solanaKit.voltrGetPositionValues(new PublicKey(input));
|
||||
}
|
||||
}
|
||||
3
src/langchain/voltr/index.ts
Normal file
3
src/langchain/voltr/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./deposit_strategy";
|
||||
export * from "./withdraw_strategy";
|
||||
export * from "./get_position_values";
|
||||
39
src/langchain/voltr/withdraw_strategy.ts
Normal file
39
src/langchain/voltr/withdraw_strategy.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "bn.js";
|
||||
|
||||
export class SolanaVoltrWithdrawStrategy extends Tool {
|
||||
name = "solana_voltr_withdraw_strategy";
|
||||
description = `Withdraw amount from a strategy for Voltr's vaults
|
||||
|
||||
Inputs (input is a json string):
|
||||
withdrawAmount: number (required)
|
||||
vault: string (required)
|
||||
strategy: string (required)
|
||||
`;
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const inputFormat = JSON.parse(input);
|
||||
const tx = await this.solanaKit.voltrWithdrawStrategy(
|
||||
new BN(inputFormat.withdrawAmount),
|
||||
new PublicKey(inputFormat.vault),
|
||||
new PublicKey(inputFormat.strategy),
|
||||
);
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: `Withdrew ${inputFormat.withdrawAmount} from strategy ${inputFormat.strategy} of vault ${inputFormat.vault} successfully`,
|
||||
transaction: tx,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ export async function createSingle(
|
||||
optionsWithBase58: StoreInitOptions,
|
||||
collectionAccount: string,
|
||||
createItemOptions: CreateSingleOptions,
|
||||
isMainnet: boolean,
|
||||
isMainnet: boolean = false,
|
||||
withPool: boolean = false,
|
||||
) {
|
||||
try {
|
||||
const landStore = isMainnet
|
||||
@@ -49,6 +50,8 @@ export async function createSingle(
|
||||
landStore,
|
||||
collectionAccount,
|
||||
createItemOptions,
|
||||
true, //isAI
|
||||
withPool,
|
||||
);
|
||||
return singleEditionTx;
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -25,3 +25,4 @@ export * from "./tiplink";
|
||||
export * from "./lightprotocol";
|
||||
export * from "./squads";
|
||||
export * from "./helius";
|
||||
export * from "./voltr";
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
export * from "./lend";
|
||||
export * from "./lulo_lend";
|
||||
export * from "./lulo_withdraw";
|
||||
|
||||
64
src/tools/lulo/lulo_lend.ts
Normal file
64
src/tools/lulo/lulo_lend.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Lend tokens for yields using Lulo
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param mintAddress SPL Mint address
|
||||
* @param amount Amount to lend
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function luloLend(
|
||||
agent: SolanaAgentKit,
|
||||
mintAddress: string,
|
||||
amount: number,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.flexlend.fi/generate/account/deposit?priorityFee=50000`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(),
|
||||
"x-api-key": process.env.FLEXLEND_API_KEY!
|
||||
},
|
||||
body: JSON.stringify({
|
||||
owner: agent.wallet.publicKey.toBase58(),
|
||||
mintAddress: mintAddress,
|
||||
depositAmount: amount.toString(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
const { data: { transactionMeta } } = await response.json()
|
||||
|
||||
// Deserialize the transaction
|
||||
const luloTxn = VersionedTransaction.deserialize(
|
||||
Buffer.from(transactionMeta[0].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, {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
69
src/tools/lulo/lulo_withdraw.ts
Normal file
69
src/tools/lulo/lulo_withdraw.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../../index";
|
||||
|
||||
/**
|
||||
* Withdraw tokens for yields using Lulo
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param mintAddress SPL Mint address
|
||||
* @param amount Amount to withdraw
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function luloWithdraw(
|
||||
agent: SolanaAgentKit,
|
||||
mintAddress: string,
|
||||
amount: number,
|
||||
): Promise<string> {
|
||||
try {
|
||||
if (!agent.config.FLEXLEND_API_KEY) {
|
||||
throw new Error("Lulo API key not found in agent configuration");
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://api.flexlend.fi/generate/account/withdraw?priorityFee=50000`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(),
|
||||
"x-api-key": agent.config.FLEXLEND_API_KEY
|
||||
},
|
||||
body: JSON.stringify({
|
||||
owner: agent.wallet.publicKey.toBase58(),
|
||||
mintAddress: mintAddress,
|
||||
depositAmount: amount,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const { data: { transactionMeta } } = await response.json()
|
||||
|
||||
// Deserialize the transaction
|
||||
const luloTxn = VersionedTransaction.deserialize(
|
||||
Buffer.from(transactionMeta[0].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, {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
3
src/tools/voltr/index.ts
Normal file
3
src/tools/voltr/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./voltr_deposit_strategy";
|
||||
export * from "./voltr_withdraw_strategy";
|
||||
export * from "./voltr_get_position_values";
|
||||
99
src/tools/voltr/voltr_deposit_strategy.ts
Normal file
99
src/tools/voltr/voltr_deposit_strategy.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import {
|
||||
PublicKey,
|
||||
sendAndConfirmTransaction,
|
||||
Transaction,
|
||||
} from "@solana/web3.js";
|
||||
import { VoltrClient } from "@voltr/vault-sdk";
|
||||
import BN from "bn.js";
|
||||
|
||||
/**
|
||||
* Deposits assets into a Voltr strategy
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param depositAmount Amount to deposit in base units (BN)
|
||||
* @param vault Public key of the target vault
|
||||
* @param strategy Public key of the target strategy
|
||||
* @returns Transaction signature for the deposit
|
||||
*/
|
||||
export async function voltrDepositStrategy(
|
||||
agent: SolanaAgentKit,
|
||||
depositAmount: BN,
|
||||
vault: PublicKey,
|
||||
strategy: PublicKey,
|
||||
): Promise<string> {
|
||||
const vc = new VoltrClient(agent.connection, agent.wallet);
|
||||
const vaultAccount = await vc.fetchVaultAccount(vault);
|
||||
const vaultAssetMint = vaultAccount.asset.mint;
|
||||
const assetTokenProgram = await agent.connection
|
||||
.getAccountInfo(new PublicKey(vaultAssetMint))
|
||||
.then((account) => account?.owner);
|
||||
|
||||
if (
|
||||
!assetTokenProgram ||
|
||||
!(
|
||||
assetTokenProgram.equals(TOKEN_PROGRAM_ID) ||
|
||||
assetTokenProgram.equals(TOKEN_2022_PROGRAM_ID)
|
||||
)
|
||||
) {
|
||||
throw new Error("Invalid asset token program");
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://voltr.xyz/api/remaining-accounts/deposit-strategy?vault=${vault.toBase58()}&strategy=${strategy.toBase58()}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const data = (await response.json()).data as {
|
||||
instructionDiscriminator: number[] | null;
|
||||
additionalArgs: number[] | null;
|
||||
remainingAccounts:
|
||||
| {
|
||||
pubkey: string;
|
||||
isSigner: boolean;
|
||||
isWritable: boolean;
|
||||
}[]
|
||||
| null;
|
||||
};
|
||||
|
||||
const additionalArgs = data.additionalArgs
|
||||
? Buffer.from(data.additionalArgs)
|
||||
: null;
|
||||
const instructionDiscriminator = data.instructionDiscriminator
|
||||
? Buffer.from(data.instructionDiscriminator)
|
||||
: null;
|
||||
const remainingAccounts =
|
||||
data.remainingAccounts?.map((account) => ({
|
||||
pubkey: new PublicKey(account.pubkey),
|
||||
isSigner: account.isSigner,
|
||||
isWritable: account.isWritable,
|
||||
})) ?? [];
|
||||
|
||||
const depositIx = await vc.createDepositStrategyIx(
|
||||
{
|
||||
depositAmount,
|
||||
additionalArgs,
|
||||
instructionDiscriminator,
|
||||
},
|
||||
{
|
||||
vault,
|
||||
vaultAssetMint,
|
||||
strategy: strategy,
|
||||
assetTokenProgram,
|
||||
remainingAccounts,
|
||||
},
|
||||
);
|
||||
|
||||
const transaction = new Transaction();
|
||||
transaction.add(depositIx);
|
||||
|
||||
const txSig = await sendAndConfirmTransaction(agent.connection, transaction, [
|
||||
agent.wallet,
|
||||
]);
|
||||
return txSig;
|
||||
}
|
||||
20
src/tools/voltr/voltr_get_position_values.ts
Normal file
20
src/tools/voltr/voltr_get_position_values.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { VoltrClient } from "@voltr/vault-sdk";
|
||||
|
||||
/**
|
||||
* Gets the value of assets in a Voltr vault
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param vault Public key of the target vault
|
||||
* @returns Position and total values for the vault
|
||||
*/
|
||||
export async function voltrGetPositionValues(
|
||||
agent: SolanaAgentKit,
|
||||
vault: PublicKey,
|
||||
): Promise<string> {
|
||||
const vc = new VoltrClient(agent.connection, agent.wallet);
|
||||
const positionAndTotalValues =
|
||||
await vc.getPositionAndTotalValuesForVault(vault);
|
||||
|
||||
return JSON.stringify(positionAndTotalValues);
|
||||
}
|
||||
99
src/tools/voltr/voltr_withdraw_strategy.ts
Normal file
99
src/tools/voltr/voltr_withdraw_strategy.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { SolanaAgentKit } from "../../agent";
|
||||
import {
|
||||
PublicKey,
|
||||
sendAndConfirmTransaction,
|
||||
Transaction,
|
||||
} from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
||||
import { VoltrClient } from "@voltr/vault-sdk";
|
||||
|
||||
/**
|
||||
* Withdraws assets from a Voltr strategy
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param withdrawAmount Amount to withdraw in base units (BN)
|
||||
* @param vault Public key of the target vault
|
||||
* @param strategy Public key of the target strategy
|
||||
* @returns Transaction signature for the deposit
|
||||
*/
|
||||
export async function voltrWithdrawStrategy(
|
||||
agent: SolanaAgentKit,
|
||||
withdrawAmount: BN,
|
||||
vault: PublicKey,
|
||||
strategy: PublicKey,
|
||||
): Promise<string> {
|
||||
const vc = new VoltrClient(agent.connection, agent.wallet);
|
||||
const vaultAccount = await vc.fetchVaultAccount(vault);
|
||||
const vaultAssetMint = vaultAccount.asset.mint;
|
||||
const assetTokenProgram = await agent.connection
|
||||
.getAccountInfo(new PublicKey(vaultAssetMint))
|
||||
.then((account) => account?.owner);
|
||||
|
||||
if (
|
||||
!assetTokenProgram ||
|
||||
!(
|
||||
assetTokenProgram.equals(TOKEN_PROGRAM_ID) ||
|
||||
assetTokenProgram.equals(TOKEN_2022_PROGRAM_ID)
|
||||
)
|
||||
) {
|
||||
throw new Error("Invalid asset token program");
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://voltr.xyz/api/remaining-accounts/deposit-strategy?vault=${vault.toBase58()}&strategy=${strategy.toBase58()}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const data = (await response.json()).data as {
|
||||
instructionDiscriminator: number[] | null;
|
||||
additionalArgs: number[] | null;
|
||||
remainingAccounts:
|
||||
| {
|
||||
pubkey: string;
|
||||
isSigner: boolean;
|
||||
isWritable: boolean;
|
||||
}[]
|
||||
| null;
|
||||
};
|
||||
|
||||
const additionalArgs = data.additionalArgs
|
||||
? Buffer.from(data.additionalArgs)
|
||||
: null;
|
||||
const instructionDiscriminator = data.instructionDiscriminator
|
||||
? Buffer.from(data.instructionDiscriminator)
|
||||
: null;
|
||||
const remainingAccounts =
|
||||
data.remainingAccounts?.map((account) => ({
|
||||
pubkey: new PublicKey(account.pubkey),
|
||||
isSigner: account.isSigner,
|
||||
isWritable: account.isWritable,
|
||||
})) ?? [];
|
||||
|
||||
const withdrawIx = await vc.createWithdrawStrategyIx(
|
||||
{
|
||||
withdrawAmount,
|
||||
additionalArgs,
|
||||
instructionDiscriminator,
|
||||
},
|
||||
{
|
||||
vault,
|
||||
vaultAssetMint,
|
||||
strategy,
|
||||
assetTokenProgram,
|
||||
remainingAccounts,
|
||||
},
|
||||
);
|
||||
|
||||
const transaction = new Transaction();
|
||||
transaction.add(withdrawIx);
|
||||
|
||||
const txSig = await sendAndConfirmTransaction(agent.connection, transaction, [
|
||||
agent.wallet,
|
||||
]);
|
||||
return txSig;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ export interface Config {
|
||||
JUPITER_REFERRAL_ACCOUNT?: string;
|
||||
JUPITER_FEE_BPS?: number;
|
||||
FLASH_PRIVILEGE?: string;
|
||||
FLEXLEND_API_KEY?: string;
|
||||
HELIUS_API_KEY?: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user