fix: lint

This commit is contained in:
aryan
2024-12-25 17:20:17 +05:30
parent 755456fb01
commit 8c1ce69743
3 changed files with 69 additions and 59 deletions

View File

@@ -324,7 +324,7 @@ export class SolanaAgentKit {
tags: string[],
tokenMintAddress: string,
tokenAmount: number,
payer?: string
payer?: string,
): Promise<GibworkCreateTaskReponse> {
return create_gibwork_task(
this,
@@ -334,7 +334,7 @@ export class SolanaAgentKit {
tags,
new PublicKey(tokenMintAddress),
tokenAmount,
payer ? new PublicKey(payer) : undefined
payer ? new PublicKey(payer) : undefined,
);
}
}

View File

@@ -1,7 +1,11 @@
import { PublicKey } from "@solana/web3.js";
import Decimal from "decimal.js";
import { Tool } from "langchain/tools";
import { GibworkCreateTaskReponse, PythFetchPriceResponse, SolanaAgentKit } from "../index";
import {
GibworkCreateTaskReponse,
PythFetchPriceResponse,
SolanaAgentKit,
} from "../index";
import { create_image } from "../tools/create_image";
import { BN } from "@coral-xyz/anchor";
import { FEE_TIERS } from "../tools";

View File

@@ -1,4 +1,4 @@
import { SendTransactionError, Transaction, VersionedTransaction } from "@solana/web3.js";
import { VersionedTransaction } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";
import { GibworkCreateTaskReponse, SolanaAgentKit } from "../index";
@@ -15,61 +15,67 @@ import { GibworkCreateTaskReponse, SolanaAgentKit } from "../index";
* @returns Object containing task creation transaction and generated taskId
*/
export async function create_gibwork_task(
agent: SolanaAgentKit,
title: string,
content: string,
requirements: string,
tags: string[],
tokenMintAddress: PublicKey,
tokenAmount: number,
payer?: PublicKey,
agent: SolanaAgentKit,
title: string,
content: string,
requirements: string,
tags: string[],
tokenMintAddress: PublicKey,
tokenAmount: number,
payer?: PublicKey,
): Promise<GibworkCreateTaskReponse> {
try {
const apiResponse = await fetch('https://api2.gib.work/tasks/public/transaction', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: title,
content: content,
requirements: requirements,
tags: tags,
payer: payer?.toBase58() || agent.wallet.publicKey.toBase58(),
token: {
mintAddress: tokenMintAddress.toBase58(),
amount: tokenAmount
}
})
});
try {
const apiResponse = await fetch(
"https://api2.gib.work/tasks/public/transaction",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title,
content: content,
requirements: requirements,
tags: tags,
payer: payer?.toBase58() || agent.wallet.publicKey.toBase58(),
token: {
mintAddress: tokenMintAddress.toBase58(),
amount: tokenAmount,
},
}),
},
);
const responseData = await apiResponse.json();
if (!responseData.taskId && !responseData.serializedTransaction) {
throw new Error(`${responseData.message}`);
}
const serializedTransaction = Buffer.from(responseData.serializedTransaction, "base64");
const tx = VersionedTransaction.deserialize(serializedTransaction);
tx.sign([agent.wallet]);
const signature = await agent.connection.sendTransaction(tx, {
preflightCommitment: "confirmed",
maxRetries: 3,
});
const latestBlockhash = await agent.connection.getLatestBlockhash();
await agent.connection.confirmTransaction({
signature,
blockhash: latestBlockhash.blockhash,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
});
return {
status: "success",
taskId: responseData.taskId,
signature: signature
};
} catch (err: any) {
throw new Error(`${err.message}`);
const responseData = await apiResponse.json();
if (!responseData.taskId && !responseData.serializedTransaction) {
throw new Error(`${responseData.message}`);
}
}
const serializedTransaction = Buffer.from(
responseData.serializedTransaction,
"base64",
);
const tx = VersionedTransaction.deserialize(serializedTransaction);
tx.sign([agent.wallet]);
const signature = await agent.connection.sendTransaction(tx, {
preflightCommitment: "confirmed",
maxRetries: 3,
});
const latestBlockhash = await agent.connection.getLatestBlockhash();
await agent.connection.confirmTransaction({
signature,
blockhash: latestBlockhash.blockhash,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
});
return {
status: "success",
taskId: responseData.taskId,
signature: signature,
};
} catch (err: any) {
throw new Error(`${err.message}`);
}
}