Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thearyanag committed Dec 27, 2024
1 parent 6895018 commit 5ab8724
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class SolanaAgentKit {
) {
return rock_paper_scissor(this, amount, choice);
}
async createTiplink(amount: number , splmintAddress?:PublicKey){
return create_TipLink(this,amount,splmintAddress)
async createTiplink(amount: number, splmintAddress?: PublicKey) {
return create_TipLink(this, amount, splmintAddress);
}
}
11 changes: 6 additions & 5 deletions src/langchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,11 +1299,13 @@ export class SolanaTipLinkTool extends Tool {
}

const amount = parseFloat(parsedInput.amount);
const splmintAddress = parsedInput.splmintAddress ? new PublicKey(parsedInput.splmintAddress) : undefined;
const splmintAddress = parsedInput.splmintAddress
? new PublicKey(parsedInput.splmintAddress)
: undefined;

const { url, signature } = await this.solanaKit.createTiplink(
amount,
splmintAddress
splmintAddress,
);

return JSON.stringify({
Expand All @@ -1312,14 +1314,13 @@ export class SolanaTipLinkTool extends Tool {
signature,
amount,
tokenType: splmintAddress ? "SPL" : "SOL",
message: `TipLink created successfully`
message: `TipLink created successfully`,
});

} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR"
code: error.code || "UNKNOWN_ERROR",
});
}
}
Expand Down
46 changes: 26 additions & 20 deletions src/tools/create_tiplinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import {
PublicKey,
ComputeBudgetProgram,
} from "@solana/web3.js";
import {
getAssociatedTokenAddress,
import {
getAssociatedTokenAddress,
createTransferInstruction,
getMint,
createAssociatedTokenAccountInstruction,
} from "@solana/spl-token";
import { SolanaAgentKit } from "../index";

const MINIMUM_SOL_BALANCE = 0.003 * LAMPORTS_PER_SOL;
const MINIMUM_SOL_BALANCE = 0.003 * LAMPORTS_PER_SOL;

export async function create_TipLink(
agent: SolanaAgentKit,
amount: number,
splmintAddress?: PublicKey,
): Promise<{ url: string, signature: string }> {
): Promise<{ url: string; signature: string }> {
try {
const tiplink = await TipLink.create();

Expand All @@ -34,64 +34,70 @@ export async function create_TipLink(
lamports: amount * LAMPORTS_PER_SOL,
}),
);

const signature = await sendAndConfirmTransaction(
agent.connection,
transaction,
[agent.wallet],
{ commitment: "confirmed" }
{ commitment: "confirmed" },
);

return {
url: tiplink.url.toString(),
signature,
};
} else {
const fromAta = await getAssociatedTokenAddress(splmintAddress, agent.wallet_address);
const toAta = await getAssociatedTokenAddress(splmintAddress, tiplink.keypair.publicKey);

const fromAta = await getAssociatedTokenAddress(
splmintAddress,
agent.wallet_address,
);
const toAta = await getAssociatedTokenAddress(
splmintAddress,
tiplink.keypair.publicKey,
);

const mintInfo = await getMint(agent.connection, splmintAddress);
const adjustedAmount = amount * Math.pow(10, mintInfo.decimals);

const transaction = new Transaction();

transaction.add(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 5000
})
microLamports: 5000,
}),
);

transaction.add(
SystemProgram.transfer({
fromPubkey: agent.wallet_address,
toPubkey: tiplink.keypair.publicKey,
lamports: MINIMUM_SOL_BALANCE,
})
}),
);

transaction.add(
createAssociatedTokenAccountInstruction(
agent.wallet_address,
toAta,
tiplink.keypair.publicKey,
splmintAddress
)
splmintAddress,
),
);

transaction.add(
createTransferInstruction(
fromAta,
toAta,
agent.wallet_address,
adjustedAmount
)
adjustedAmount,
),
);

const signature = await sendAndConfirmTransaction(
agent.connection,
transaction,
[agent.wallet],
{ commitment: "confirmed" }
{ commitment: "confirmed" },
);

return {
Expand All @@ -103,4 +109,4 @@ export async function create_TipLink(
console.error("Error creating TipLink or sending funds:", error.message);
throw new Error(`Failed to create TipLink: ${error.message}`);
}
}
}
2 changes: 1 addition & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ export * from "./pyth_fetch_price";
export * from "./create_gibwork_task";

export * from "./rock_paper_scissor";
export * from "./create_tiplinks"
export * from "./create_tiplinks";

0 comments on commit 5ab8724

Please sign in to comment.