Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arihantbansal committed Nov 27, 2024
1 parent 9265164 commit 2658a88
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const signature = await trade(
### Lend Tokens

```typescript
import { lend } from 'solana-agent-kit';
import { lendAsset } from 'solana-agent-kit';
import { PublicKey } from '@solana/web3.js';

const signature = await lendAsset(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"typedoc": "^0.26.11"
},
"devDependencies": {
"@types/node": "^22.9.0"
"@types/node": "^22.9.0",
"ts-node": "^10.9.2"
}
}
129 changes: 129 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/tools/lend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export async function lendAsset(

const request = {
owner: agent.wallet.publicKey.toBase58(),
mintAddress: asset,
depositAmount: amount,
mintAddress: asset.toBase58(),
depositAmount: amount.toString(),
};

const priority = `?priorityFee=${getPriorityFees(agent.connection)}`;
const priorityFees = await getPriorityFees(agent.connection);
const priority = `?priorityFee=${priorityFees.median}`;

const response = await fetch(
`${LULO_API}/generate/account/deposit${priority}`,
{
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"x-wallet-pubkey": agent.wallet.publicKey.toBase58(),
"x-api-key": LULO_API_KEY,
Expand Down
13 changes: 11 additions & 2 deletions src/utils/send_tx.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { SolanaAgentKit } from "../agent";
import { Transaction, Keypair } from "@solana/web3.js";
import { Transaction, Keypair, TransactionInstruction } from "@solana/web3.js";
import { Connection, ComputeBudgetProgram } from "@solana/web3.js";

/**
* Get priority fees for the current block
* @param connection - Solana RPC connection
* @returns Priority fees statistics and instructions for different fee levels
*/
export async function getPriorityFees(connection: Connection) {
export async function getPriorityFees(connection: Connection): Promise<{
min: number;
median: number;
max: number;
instructions?: {
low: TransactionInstruction;
medium: TransactionInstruction;
high: TransactionInstruction;
};
}> {
try {
// Get recent prioritization fees
const priorityFees = await connection.getRecentPrioritizationFees();
Expand Down
Loading

0 comments on commit 2658a88

Please sign in to comment.