mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-19 23:26:45 +00:00
Updating NFTs to Core and adding token metadata.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
OPENAI_API_KEY=your_openai_api_key_here
|
||||
RPC_URL=your_rpc_url_here
|
||||
SOLANA_PRIVATE_KEY=your_solana_private_key_here
|
||||
SOLANA_PRIVATE_KEY=your_solana_private_key_here
|
||||
|
||||
154
CONTRIBUTING.md
Normal file
154
CONTRIBUTING.md
Normal file
@@ -0,0 +1,154 @@
|
||||
# Contributing to Solana Agent Kit
|
||||
|
||||
First off, thank you for considering contributing to Solana Agent Kit! 🎉 Your contributions are **greatly appreciated**.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Contributing to Solana Agent Kit](#contributing-to-solana-agent-kit)
|
||||
- [Table of Contents](#table-of-contents)
|
||||
- [Code of Conduct](#code-of-conduct)
|
||||
- [How Can I Contribute?](#how-can-i-contribute)
|
||||
- [Reporting Bugs](#reporting-bugs)
|
||||
- [Suggesting Enhancements](#suggesting-enhancements)
|
||||
- [Your First Code Contribution](#your-first-code-contribution)
|
||||
- [Pull Requests](#pull-requests)
|
||||
- [Style Guides](#style-guides)
|
||||
- [Code Style](#code-style)
|
||||
- [Commit Messages](#commit-messages)
|
||||
- [Naming Conventions](#naming-conventions)
|
||||
- [Development Setup](#development-setup)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Installation](#installation)
|
||||
- [Building the Project](#building-the-project)
|
||||
- [Running Tests](#running-tests)
|
||||
- [Generating Documentation](#generating-documentation)
|
||||
- [Security](#security)
|
||||
- [License](#license)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project adheres to the [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct/). By participating, you are expected to uphold this code. Please report unacceptable behavior to [aryan@sendai.fun](mailto:aryan@sendai.fun).
|
||||
|
||||
## How Can I Contribute?
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
**Great**! Opening an issue is the best way to help us improve. Here's how you can report a bug:
|
||||
|
||||
1. **Search** the [existing issues](https://github.com/sendaifun/solana-agent-kit/issues) to make sure it hasn't been reported.
|
||||
2. **Open a new issue** and fill out the template with as much information as possible.
|
||||
3. **Provide reproduction steps** if applicable.
|
||||
|
||||
### Suggesting Enhancements
|
||||
|
||||
We welcome your ideas for improving Solana Agent Kit! To suggest an enhancement:
|
||||
|
||||
1. **Search** the [existing issues](https://github.com/sendaifun/solana-agent-kit/issues) to see if it's already been suggested.
|
||||
2. **Open a new issue** and describe your idea in detail.
|
||||
|
||||
### Your First Code Contribution
|
||||
|
||||
Unsure where to start? You can help out by:
|
||||
|
||||
- Fixing simple bugs.
|
||||
- Improving documentation.
|
||||
- Adding tests.
|
||||
|
||||
Check out the [Good First Issues](https://github.com/sendaifun/solana-agent-kit/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) to get started!
|
||||
|
||||
### Pull Requests
|
||||
|
||||
1. **Fork** the repository.
|
||||
2. **Create** a new branch for your feature or bugfix.
|
||||
```bash
|
||||
git checkout -b feature/your-feature-name
|
||||
```
|
||||
3. **Commit** your changes with clear and descriptive messages.
|
||||
4. **Push** to your fork.
|
||||
```bash
|
||||
git push origin feature/your-feature-name
|
||||
```
|
||||
5. **Open a Pull Request** against the `main` branch of this repository.
|
||||
|
||||
## Style Guides
|
||||
|
||||
### Code Style
|
||||
|
||||
- **Language**: TypeScript
|
||||
- **Formatting**: Follow the existing codebase formatting. Consider using [Prettier](https://prettier.io/) for consistent code formatting.
|
||||
- **Linting**: Adhere to the linting rules defined in `.eslintrc`. Ensure all linting checks pass before submitting a PR.
|
||||
|
||||
### Commit Messages
|
||||
|
||||
Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for your commit messages. Examples:
|
||||
|
||||
- `feat: add ability to deploy new SPL token`
|
||||
- `fix: handle edge case when deploying collection`
|
||||
- `docs: update README with new usage examples`
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
- **Variables and Functions**: `camelCase`
|
||||
- **Classes and Types**: `PascalCase`
|
||||
- **Constants**: `UPPER_SNAKE_CASE`
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- **Node.js**: v23.x or higher
|
||||
- **npm**: v10.x or higher
|
||||
- **Git**: Installed and configured
|
||||
|
||||
### Installation
|
||||
|
||||
1. **Clone** the repository:
|
||||
```bash
|
||||
git clone https://github.com/yourusername/solana-agent-kit.git
|
||||
```
|
||||
2. **Navigate** to the project directory:
|
||||
```bash
|
||||
cd solana-agent-kit
|
||||
```
|
||||
3. **Install** dependencies:
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### Building the Project
|
||||
|
||||
To compile the TypeScript code:
|
||||
|
||||
```bash
|
||||
pnpm run build
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
To execute the test suite:
|
||||
|
||||
```bash
|
||||
pnpm run test
|
||||
```
|
||||
|
||||
### Generating Documentation
|
||||
|
||||
To generate the project documentation using TypeDoc:
|
||||
|
||||
```bash
|
||||
npm run docs
|
||||
```
|
||||
|
||||
The documentation will be available in the `docs/` directory.
|
||||
|
||||
## Security
|
||||
|
||||
This toolkit handles sensitive information such as private keys and API keys. **Ensure you never commit `.env` files or any sensitive data**. Review the `.gitignore` to confirm that sensitive files are excluded.
|
||||
|
||||
For security vulnerabilities, please follow the [responsible disclosure](mailto:aryan@sendai.fun) process.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the [ISC License](LICENSE).
|
||||
|
||||
---
|
||||
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 SendAI
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
28
README.md
28
README.md
@@ -8,6 +8,7 @@ A powerful toolkit for interacting with the Solana blockchain, providing easy-to
|
||||
- Deploy new SPL tokens
|
||||
- Transfer SOL and SPL tokens
|
||||
- Check token balances
|
||||
- Stake SOL
|
||||
|
||||
- 🖼️ NFT Management
|
||||
- Deploy NFT collections
|
||||
@@ -108,6 +109,30 @@ const signature = await lendAsset(
|
||||
);
|
||||
```
|
||||
|
||||
### Stake SOL
|
||||
|
||||
```typescript
|
||||
import { stakeWithJup } from 'solana-agent-kit';
|
||||
|
||||
const signature = await stakeWithJup(
|
||||
agent,
|
||||
1 // amount in SOL
|
||||
);
|
||||
```
|
||||
|
||||
### Fetch Token Price
|
||||
|
||||
```typescript
|
||||
import { fetchPrice } from 'solana-agent-kit';
|
||||
|
||||
const price = await fetchPrice(
|
||||
agent,
|
||||
'JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN' // Token mint address
|
||||
);
|
||||
|
||||
console.log('Price in USDC:', price);
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Core Functions
|
||||
@@ -140,6 +165,9 @@ Check SOL or token balance for the agent's wallet.
|
||||
|
||||
Lend idle assets to earn interest with Lulo.
|
||||
|
||||
#### `stakeWithJup(agent, amount)`
|
||||
Stake SOL with Jupiter to earn rewards.
|
||||
|
||||
## Dependencies
|
||||
|
||||
The toolkit relies on several key Solana and Metaplex libraries:
|
||||
|
||||
@@ -1 +1 @@
|
||||
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE7WbXW/jthKG/wt9K2TNDzmO77LdE6DonnbRzemNEQSMRHuFlSVVojYnCPLfC+rDGpojh7K2Vy1izjsvyUdDSuS+kjJ/rshm+0q+J1lMNpStA5LJgyIb8jVPZSZv9yrTvyWaBKQuU7IhUSqrSlUf7J+vvulDSoL+V7Ih5C3oVUPKjqpRnlW6rCOdlz6SC7s9kA9IIUuVadfpkJgumYCZMxXpJM98Ew/N5+R9lmmqvMZvcWw6P9+jjONSVdWEvCBkTv68UJlMHmWRPH5XL175nZCJ+dlSDNyW6u9aVfpO1pHSd3UW+40BGjbHR6yKNH+5z78rP+Ds9vMz/5Kn6QTekaA5HvZKf5SpzCLlld1qPifvIcn073f3XkmHtnMy6lJm1U75lTPQeB7j+6TSqvyUH2TiN79OyMw+x34T27ecky1VWXxbVUr7PclW85kM33/56stv23RWP2WdRd++1Ifirs78CwcaNtHHCqyTpZJatS3v8zwdBn1XZ01pqD44bc6u/yxcHdV/MZFg7U8yrcqdjFT1ofvprJS10pwucSNai/fWtd7TSJpClZHKtNyrdzNZTX2TWcNzrL9/FM1QoylPG/kPWfMfb8lF13ykJ47XkaR1mUzI2baembLMX2SqXz7KKqm+5EmmJwzkAg2eaShqp32KDRAyPTkO1admkT+Y8LM+hnb+aEXH6Nszz+VYigUW/l63QXdGTFXJPpO6Lt+B/tQMDLvIBBz+/yaZHpr/fnf/p6qKPKtQT6ON/SfCbGumSy+6MLy7430YM6G0jKWWlxgZQi83AycALo1nyirSzH/Q9XOitULXtTHdxRCD9xPzPZZepWpfysO0/EPQbAPP6qlKNIr0aP4hZnb6JEt0ItPPyd91Eif65esf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ng6nNkPKuxyUGGeKu3reTG8ng9yIZALmZfccEaJhQc6ya4n6sXgYBZIXgHJq4mSeX/SBfQY0PPt8nDpEggBHV+Z4dLooEMHHeqn01w8qZqLJzo/yigFGaCeGeivowCVFVBZTVGxx3oJxmjpJdNCEIELf4Mc6Jpfz1ox3V4+GnQAUX5AdVvx4GEGyRfCS2On9GN/l3AQAuPsN8w7pXVhZzwEuQq9RIatL1AKAIch95LpDgzT/sCwylOoyME4c7+B7rfYVbfFDkYc9FL4ibU30Ir2oMSBgAI2qR+b5gqf7K7wASEBhPxYSOs0l+0mXdxu0pWHAxnQZQ667JfY4doASANglftVql6muYYEAgKICD9Eui3LstmyBLCBmEK/MWvPBUG3QDCctkbCs3tJpocKk201NvocTI3cb6Y1utnWipICFeqn0u62giIKMGB+o358cx0MPBh3P6n2QAJAAEpW6DdhwRuBoF8ggcxTqDuL3yo7VSAk7ldGu6rQlgj04QOJE36Jg5UGWXhwkEful8f+ZE8WVhIFKF3Cbybs71nH3T1rQCh4FKnf89P9KGHb/Chh2/4oYRAEwfmV1e6q4aO5alh0Vw0BJgBZ5sfscPwIxgxMRsKPEXAXAoQDWGOrruz40dtfaHm0528OljXcL5vt2k+aK8xPiVVvALV+0HZ3pQEPYKCo30Q73KECvQJp435pa479v7fH/iBxYHoVfkB1t/tBn8CjR/0eveEnEUAGLtX9cn643gZGBnSI+819R/MwAwrMT6H/DRcIA0QxQeIBeeuDGfKT6i+9gXBA2eAeab4PSJEUKk0yRdab+7e3/wDIrU8JNjgAAA==";
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "solana-agent-kit",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "A toolkit for interacting with the Solana blockchain using LangChain",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
launchPumpFunToken,
|
||||
lendAsset,
|
||||
getTPS,
|
||||
stakeWithJup,
|
||||
} from "../tools";
|
||||
import { CollectionOptions, PumpFunTokenOptions } from "../types";
|
||||
import { DEFAULT_OPTIONS } from "../constants";
|
||||
@@ -114,4 +115,10 @@ export class SolanaAgentKit {
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
async stake(
|
||||
amount: number,
|
||||
) {
|
||||
return stakeWithJup(this, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { SolanaAgentKit } from "../index";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { toJSON } from "../utils/toJSON";
|
||||
import { create_image } from "../tools/create_image";
|
||||
import { fetchPrice } from "../tools/fetch_price";
|
||||
|
||||
export class SolanaBalanceTool extends Tool {
|
||||
name = "solana_balance";
|
||||
@@ -54,7 +55,6 @@ export class SolanaTransferTool extends Tool {
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const parsedInput = JSON.parse(input);
|
||||
console.log(parsedInput);
|
||||
|
||||
const recipient = new PublicKey(parsedInput.to);
|
||||
const mintAddress = parsedInput.mint
|
||||
@@ -302,7 +302,6 @@ export class SolanaTradeTool extends Tool {
|
||||
outputToken: parsedInput.outputMint,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.log(error);
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
@@ -423,7 +422,6 @@ export class SolanaPumpfunTokenLaunchTool extends Tool {
|
||||
}
|
||||
|
||||
private validateInput(input: any): void {
|
||||
console.log(input);
|
||||
if (!input.tokenName || typeof input.tokenName !== "string") {
|
||||
throw new Error("tokenName is required and must be a string");
|
||||
}
|
||||
@@ -568,6 +566,71 @@ export class SolanaTPSCalculatorTool extends Tool {
|
||||
}
|
||||
}
|
||||
|
||||
export class SolanaStakeTool extends Tool {
|
||||
name = "solana_stake";
|
||||
description = `This tool can be used to stake your SOL (Solana), also called as SOL staking or liquid staking.
|
||||
|
||||
Inputs ( input is a JSON string ):
|
||||
amount: number, eg 1 or 0.01 (required)`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const parsedInput = JSON.parse(input) || Number(input);
|
||||
|
||||
const tx = await this.solanaKit.stake(parsedInput.amount);
|
||||
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
message: "Staked successfully",
|
||||
transaction: tx,
|
||||
amount: parsedInput.amount,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool to fetch the price of a token in USDC
|
||||
*/
|
||||
export class SolanaFetchPriceTool extends Tool {
|
||||
name = "solana_fetch_price";
|
||||
description = `Fetch the price of a given token in USDC.
|
||||
|
||||
Inputs:
|
||||
- tokenId: string, the mint address of the token, e.g., "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"`;
|
||||
|
||||
constructor(private solanaKit: SolanaAgentKit) {
|
||||
super();
|
||||
}
|
||||
|
||||
async _call(input: string): Promise<string> {
|
||||
try {
|
||||
const price = await fetchPrice(this.solanaKit, input.trim());
|
||||
return JSON.stringify({
|
||||
status: "success",
|
||||
tokenId: input.trim(),
|
||||
priceInUSDC: price,
|
||||
});
|
||||
} catch (error: any) {
|
||||
return JSON.stringify({
|
||||
status: "error",
|
||||
message: error.message,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
return [
|
||||
new SolanaBalanceTool(solanaKit),
|
||||
@@ -583,5 +646,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaCreateImageTool(solanaKit),
|
||||
new SolanaLendAssetTool(solanaKit),
|
||||
new SolanaTPSCalculatorTool(solanaKit),
|
||||
new SolanaStakeTool(solanaKit),
|
||||
new SolanaFetchPriceTool(solanaKit),
|
||||
];
|
||||
}
|
||||
|
||||
35
src/tools/fetch_price.ts
Normal file
35
src/tools/fetch_price.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { SolanaAgentKit } from "../index";
|
||||
import { Tool } from "langchain/tools";
|
||||
|
||||
/**
|
||||
* Fetch the price of a given token in USDC using Jupiter API
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param tokenId The token mint address
|
||||
* @returns The price of the token in USDC
|
||||
*/
|
||||
export async function fetchPrice(
|
||||
agent: SolanaAgentKit,
|
||||
tokenId: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://api.jup.ag/price/v2?ids=${tokenId}`
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch price: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const price = data.data[tokenId]?.price;
|
||||
|
||||
if (!price) {
|
||||
throw new Error("Price data not available for the given token.");
|
||||
}
|
||||
|
||||
return price;
|
||||
} catch (error: any) {
|
||||
throw new Error(`Price fetch failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
@@ -9,3 +9,5 @@ export * from "./register_domain";
|
||||
export * from "./launch_pumpfun_token";
|
||||
export * from "./lend";
|
||||
export * from "./get_tps";
|
||||
export * from './stake_with_jup';
|
||||
export * from "./fetch_price";
|
||||
@@ -38,7 +38,6 @@ async function uploadMetadata(
|
||||
finalFormData.append('file', files.file);
|
||||
}
|
||||
|
||||
console.log("Final form data:", finalFormData);
|
||||
|
||||
const metadataResponse = await fetch("https://pump.fun/api/ipfs", {
|
||||
method: "POST",
|
||||
@@ -46,7 +45,6 @@ async function uploadMetadata(
|
||||
});
|
||||
|
||||
if (!metadataResponse.ok) {
|
||||
console.log("Metadata response:", await metadataResponse.json());
|
||||
throw new Error(`Metadata upload failed: ${metadataResponse.statusText}`);
|
||||
}
|
||||
|
||||
@@ -152,30 +150,14 @@ export async function launchPumpFunToken(
|
||||
options?: PumpFunTokenOptions
|
||||
) {
|
||||
try {
|
||||
// TBD : Remove clgs after approval
|
||||
console.log("Starting token launch process...");
|
||||
|
||||
// Generate mint keypair
|
||||
const mintKeypair = Keypair.generate();
|
||||
console.log("Mint public key:", mintKeypair.publicKey.toBase58());
|
||||
|
||||
// Upload metadata
|
||||
console.log("Uploading metadata to IPFS...");
|
||||
const metadataResponse = await uploadMetadata(tokenName, tokenTicker, description, imageUrl, options);
|
||||
console.log("Metadata response:", metadataResponse);
|
||||
|
||||
// Create token transaction
|
||||
console.log("Creating token transaction...");
|
||||
const response = await createTokenTransaction(agent, mintKeypair, metadataResponse, options);
|
||||
|
||||
const transactionData = await response.arrayBuffer();
|
||||
const tx = VersionedTransaction.deserialize(new Uint8Array(transactionData));
|
||||
|
||||
// Send transaction with proper blockhash handling
|
||||
console.log("Sending transaction...");
|
||||
const signature = await signAndSendTransaction(agent, tx, mintKeypair);
|
||||
|
||||
console.log("Token launch successful!");
|
||||
return {
|
||||
signature,
|
||||
mint: mintKeypair.publicKey.toBase58(),
|
||||
|
||||
56
src/tools/stake_with_jup.ts
Normal file
56
src/tools/stake_with_jup.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
|
||||
/**
|
||||
* Stake SOL with Jup validator
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param amount Amount of SOL to stake
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function stakeWithJup(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://worker.jup.ag/blinks/swap/So11111111111111111111111111111111111111112/jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v/${amount}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
account: agent.wallet.publicKey.toBase58(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
const txn = VersionedTransaction.deserialize(
|
||||
Buffer.from(data.transaction, "base64"),
|
||||
);
|
||||
|
||||
const { blockhash } = await agent.connection.getLatestBlockhash();
|
||||
txn.message.recentBlockhash = blockhash;
|
||||
|
||||
// Sign and send transaction
|
||||
txn.sign([agent.wallet]);
|
||||
const signature = await agent.connection.sendTransaction(txn, {
|
||||
preflightCommitment: "confirmed",
|
||||
maxRetries: 3,
|
||||
});
|
||||
|
||||
const latestBlockhash = await agent.connection.getLatestBlockhash();
|
||||
await agent.connection.confirmTransaction({
|
||||
signature,
|
||||
blockhash: latestBlockhash.blockhash,
|
||||
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
|
||||
});
|
||||
|
||||
return signature;
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
throw new Error(`jupSOL staking failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,6 @@ export async function trade(
|
||||
slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS,
|
||||
): Promise<string> {
|
||||
try {
|
||||
// Get quote for the swap
|
||||
console.log(inputMint.toString(), outputMint.toString(), inputAmount, slippageBps);
|
||||
const quoteResponse = await (
|
||||
await fetch(
|
||||
`${JUP_API}/quote?` +
|
||||
|
||||
@@ -54,3 +54,11 @@ export interface LuloAccountDetailsResponse {
|
||||
minimumRate: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface FetchPriceResponse {
|
||||
status: "success" | "error";
|
||||
tokenId?: string;
|
||||
priceInUSDC?: string;
|
||||
message?: string;
|
||||
code?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user