Fix: remove buyNFT not working with sdk

This commit is contained in:
Lautaro
2024-12-30 14:00:55 -03:00
parent 35781f4dc1
commit 9fba6484b5
3 changed files with 0 additions and 81 deletions

View File

@@ -38,7 +38,6 @@ import {
rock_paper_scissor,
create_TipLink,
listNFTForSale,
buyNFT,
cancelListing,
} from "../tools";
import {
@@ -360,10 +359,6 @@ export class SolanaAgentKit {
return listNFTForSale(this, nftMint, price);
}
async tensorBuyNFT(nftMint: PublicKey, maxPrice: number): Promise<string> {
return buyNFT(this, nftMint, maxPrice);
}
async tensorCancelListing(nftMint: PublicKey): Promise<string> {
return cancelListing(this, nftMint);
}

View File

@@ -1380,43 +1380,6 @@ export class SolanaListNFTForSaleTool extends Tool {
}
}
export class SolanaBuyNFTTool extends Tool {
name = "solana_buy_nft";
description = `Buy an NFT listed on Tensor Trade.
Inputs (input is a JSON string):
nftMint: string, the mint address of the NFT (required)
maxPrice: number, maximum price willing to pay in SOL (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = JSON.parse(input);
const tx = await this.solanaKit.tensorBuyNFT(
new PublicKey(parsedInput.nftMint),
parsedInput.maxPrice,
);
return JSON.stringify({
status: "success",
message: "NFT purchased successfully",
transaction: tx,
maxPrice: parsedInput.maxPrice,
nftMint: parsedInput.nftMint,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export class SolanaCancelNFTListingTool extends Tool {
name = "solana_cancel_nft_listing";
@@ -1490,7 +1453,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaRockPaperScissorsTool(solanaKit),
new SolanaTipLinkTool(solanaKit),
new SolanaListNFTForSaleTool(solanaKit),
new SolanaBuyNFTTool(solanaKit),
new SolanaCancelNFTListingTool(solanaKit),
];
}

View File

@@ -72,44 +72,6 @@ export async function listNFTForSale(
}
}
export async function buyNFT(
agent: SolanaAgentKit,
nftMint: PublicKey,
maxPrice: number,
): Promise<string> {
const provider = new AnchorProvider(
agent.connection,
new Wallet(agent.wallet),
AnchorProvider.defaultOptions(),
);
const tensorSwapSdk = new TensorSwapSDK({ provider });
const maxPriceInLamports = new BN(maxPrice * 1e9);
const nftBuyerAcc = await getAssociatedTokenAddress(
nftMint,
agent.wallet_address,
);
const { tx } = await tensorSwapSdk.buySingleListingT22({
nftMint,
nftBuyerAcc,
owner: agent.wallet_address,
buyer: agent.wallet_address,
maxPrice: maxPriceInLamports,
takerBroker: null,
compute: null,
priorityMicroLamports: null,
transferHook: null,
});
const transaction = new Transaction();
transaction.add(...tx.ixs);
return await agent.connection.sendTransaction(transaction, [
agent.wallet,
...tx.extraSigners,
]);
}
export async function cancelListing(
agent: SolanaAgentKit,
nftMint: PublicKey,