Merge branch 'main' into feat/squads_multisig

This commit is contained in:
A91y
2025-01-08 22:58:50 +05:30
65 changed files with 10161 additions and 320 deletions

View File

@@ -9,6 +9,12 @@ import {
SolanaAgentKit,
} from "../index";
import { create_image, FEE_TIERS, generateOrdersfromPattern } from "../tools";
import { marketTokenMap } from "../utils/flashUtils";
import {
CreateCollectionOptions,
CreateSingleOptions,
StoreInitOptions,
} from "@3land/listings-sdk/dist/types/implementation/implementationTypes";
export class SolanaBalanceTool extends Tool {
name = "solana_balance";
@@ -774,6 +780,135 @@ export class SolanaGetWalletAddressTool extends Tool {
}
}
export class SolanaFlashOpenTrade extends Tool {
name = "solana_flash_open_trade";
description = `This tool can be used to open a new leveraged trading position on Flash.Trade exchange.
Inputs ( input is a JSON string ):
token: string, eg "SOL", "BTC", "ETH" (required)
type: string, eg "long", "short" (required)
collateral: number, eg 10, 100, 1000 (required)
leverage: number, eg 5, 10, 20 (required)
Example prompt is Open a 20x leveraged trade for SOL on long side using flash trade with 500 USD as collateral`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
// Validate input parameters
if (!parsedInput.token) {
throw new Error("Token is required, received: " + parsedInput.token);
}
if (!Object.keys(marketTokenMap).includes(parsedInput.token)) {
throw new Error(
"Token must be one of " +
Object.keys(marketTokenMap).join(", ") +
", received: " +
parsedInput.token +
"\n" +
"Please check https://beast.flash.trade/ for the list of supported tokens",
);
}
if (!["long", "short"].includes(parsedInput.type)) {
throw new Error(
'Type must be either "long" or "short", received: ' +
parsedInput.type,
);
}
if (!parsedInput.collateral || parsedInput.collateral <= 0) {
throw new Error(
"Collateral amount must be positive, received: " +
parsedInput.collateral,
);
}
if (!parsedInput.leverage || parsedInput.leverage <= 0) {
throw new Error(
"Leverage must be positive, received: " + parsedInput.leverage,
);
}
const tx = await this.solanaKit.flashOpenTrade({
token: parsedInput.token,
side: parsedInput.type,
collateralUsd: parsedInput.collateral,
leverage: parsedInput.leverage,
});
return JSON.stringify({
status: "success",
message: "Flash trade position opened successfully",
transaction: tx,
token: parsedInput.token,
side: parsedInput.type,
collateral: parsedInput.collateral,
leverage: parsedInput.leverage,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaFlashCloseTrade extends Tool {
name = "solana_flash_close_trade";
description = `Close an existing leveraged trading position on Flash.Trade exchange.
Inputs ( input is a JSON string ):
token: string, eg "SOL", "BTC", "ETH" (required)
side: string, eg "long", "short" (required)
Example prompt is Close a 20x leveraged trade for SOL on long side`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
// Validate input parameters
if (!parsedInput.token) {
throw new Error("Token is required");
}
if (!["SOL", "BTC", "ETH"].includes(parsedInput.token)) {
throw new Error('Token must be one of ["SOL", "BTC", "ETH"]');
}
if (!["long", "short"].includes(parsedInput.side)) {
throw new Error('Side must be either "long" or "short"');
}
const tx = await this.solanaKit.flashCloseTrade({
token: parsedInput.token,
side: parsedInput.side,
});
return JSON.stringify({
status: "success",
message: "Flash trade position closed successfully",
transaction: tx,
token: parsedInput.token,
side: parsedInput.side,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaPumpfunTokenLaunchTool extends Tool {
name = "solana_launch_pumpfun_token";
@@ -2125,6 +2260,181 @@ export class SolanaFetchTokenDetailedReportTool extends Tool {
}
}
export class Solana3LandCreateSingle extends Tool {
name = "3land_minting_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
itemAmount (required): the amount of the NFTs that can be minted
itemDescription (required): the description of the NFT
traits (required): the traits of the NFT [{trait_type: string, value: string}]
price (required): the price of the item, if is 0 the listing will be free
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
`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
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 collectionAccount = inputFormat.collectionAccount;
const itemName = inputFormat?.itemName;
const sellerFee = inputFormat?.sellerFee;
const itemAmount = inputFormat?.itemAmount;
const itemSymbol = inputFormat?.itemSymbol;
const itemDescription = inputFormat?.itemDescription;
const traits = inputFormat?.traits;
const price = inputFormat?.price;
const mainImageUrl = inputFormat?.mainImageUrl;
const coverImageUrl = inputFormat?.coverImageUrl;
const splHash = inputFormat?.splHash;
const createItemOptions: CreateSingleOptions = {
...(itemName && { itemName }),
...(sellerFee && { sellerFee }),
...(itemAmount && { itemAmount }),
...(itemSymbol && { itemSymbol }),
...(itemDescription && { itemDescription }),
...(traits && { traits }),
...(price && { price }),
...(mainImageUrl && { mainImageUrl }),
...(coverImageUrl && { coverImageUrl }),
...(splHash && { splHash }),
};
if (!collectionAccount) {
throw new Error("Collection account is required");
}
const tx = await this.solanaKit.create3LandNft(
optionsWithBase58,
collectionAccount,
createItemOptions,
isMainnet,
);
return JSON.stringify({
status: "success",
message: `Created listing successfully ${tx}`,
transaction: tx,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class Solana3LandCreateCollection extends Tool {
name = "3land_minting_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
collectionDescription (required): the description of the collection
mainImageUrl (required): the image of the collection
coverImageUrl (optional): the cover image of the collection
`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
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;
const mainImageUrl = inputFormat?.mainImageUrl;
const coverImageUrl = inputFormat?.coverImageUrl;
const collectionOpts: CreateCollectionOptions = {
...(collectionSymbol && { collectionSymbol }),
...(collectionName && { collectionName }),
...(collectionDescription && { collectionDescription }),
...(mainImageUrl && { mainImageUrl }),
...(coverImageUrl && { coverImageUrl }),
};
const tx = await this.solanaKit.create3LandCollection(
optionsWithBase58,
collectionOpts,
);
return JSON.stringify({
status: "success",
message: `Created Collection successfully ${tx}`,
transaction: tx,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaCloseEmptyTokenAccounts extends Tool {
name = "close_empty_token_accounts";
description = `Close all empty spl-token accounts and reclaim the rent`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(): Promise<string> {
try {
const { signature, size } =
await this.solanaKit.closeEmptyTokenAccounts();
return JSON.stringify({
status: "success",
message: `${size} accounts closed successfully. ${size === 48 ? "48 accounts can be closed in a single transaction try again to close more accounts" : ""}`,
signature,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaCreate2by2Multisig extends Tool {
name = "create_2by2_multisig";
description = `Create a 2-of-2 multisig account on Solana with the user and the agent, where both approvals will be required to run the transactions.
@@ -2428,10 +2738,16 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaTipLinkTool(solanaKit),
new SolanaListNFTForSaleTool(solanaKit),
new SolanaCancelNFTListingTool(solanaKit),
new SolanaCloseEmptyTokenAccounts(solanaKit),
new SolanaFetchTokenReportSummaryTool(solanaKit),
new SolanaFetchTokenDetailedReportTool(solanaKit),
new Solana3LandCreateSingle(solanaKit),
new Solana3LandCreateCollection(solanaKit),
new SolanaPerpOpenTradeTool(solanaKit),
new SolanaPerpCloseTradeTool(solanaKit),
new SolanaFlashOpenTrade(solanaKit),
new SolanaFlashCloseTrade(solanaKit),
new Solana3LandCreateSingle(solanaKit),
new SolanaCreate2by2Multisig(solanaKit),
new SolanaDepositTo2by2Multisig(solanaKit),
new SolanaTransferFrom2by2Multisig(solanaKit),