mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-18 15:10:33 +00:00
feat: add Solayer staking tool (#116)
# Pull Request Description ## Related Issue Fixes # (issue number) ## Changes Made This PR adds the following changes: <!-- List the key changes made in this PR --> - Add staking to Solayer through a Solana Actions/Blink endpoint - ## Implementation Details <!-- Provide technical details about the implementation --> - Added stakeWithSolayer action - Added stake_with_solayer tool - Added tool to langchain ## Transaction executed by agent <!-- If applicable, provide example usage, transactions, or screenshots --> Example transaction: [https://solscan.io/tx/3jauR9XevrX9BFaz7VicPe3m3Xw3co6SPmCfZsj69WVAdkM8D4M3CkUH3Wayd794tEsmdHJ2zoqEmp7i5eX9L6uE](https://solscan.io/tx/3jauR9XevrX9BFaz7VicPe3m3Xw3co6SPmCfZsj69WVAdkM8D4M3CkUH3Wayd794tEsmdHJ2zoqEmp7i5eX9L6uE) ## Prompt Used <!-- If relevant, include the prompt or configuration used --> ``` ``` ## Additional Notes <!-- Any additional information that reviewers should know --> ## Checklist - [x] I have tested these changes locally - [x] I have updated the documentation - [x] I have added a transaction link - [ ] I have added the prompt used to test it
This commit is contained in:
10
README.md
10
README.md
@@ -59,6 +59,7 @@ Anyone - whether an SF-based AI researcher or a crypto-native builder - can brin
|
||||
- Lending by Lulo (Best APR for USDC)
|
||||
- Send Arcade Games
|
||||
- JupSOL staking
|
||||
- Solayer SOL (sSOL)staking
|
||||
|
||||
- **Non-Financial Actions**
|
||||
- Gib Work for registering bounties
|
||||
@@ -173,6 +174,15 @@ const signature = await agent.stake(
|
||||
);
|
||||
```
|
||||
|
||||
### Stake SOL on Solayer
|
||||
|
||||
```typescript
|
||||
const signature = await agent.restake(
|
||||
1 // amount in SOL to stake
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
### Send an SPL Token Airdrop via ZK Compression
|
||||
|
||||
```typescript
|
||||
|
||||
3267
pnpm-lock.yaml
generated
3267
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ import getTokenDataAction from "./getTokenData";
|
||||
import getTPSAction from "./getTPS";
|
||||
import fetchPriceAction from "./fetchPrice";
|
||||
import stakeWithJupAction from "./stakeWithJup";
|
||||
import stakeWithSolayerAction from "./stakeWithSolayer";
|
||||
import registerDomainAction from "./registerDomain";
|
||||
import lendAssetAction from "./lendAsset";
|
||||
import createGibworkTaskAction from "./createGibworkTask";
|
||||
@@ -42,6 +43,7 @@ export const ACTIONS = {
|
||||
GET_TPS_ACTION: getTPSAction,
|
||||
FETCH_PRICE_ACTION: fetchPriceAction,
|
||||
STAKE_WITH_JUP_ACTION: stakeWithJupAction,
|
||||
STAKE_WITH_SOLAYER_ACTION : stakeWithSolayerAction,
|
||||
REGISTER_DOMAIN_ACTION: registerDomainAction,
|
||||
LEND_ASSET_ACTION: lendAssetAction,
|
||||
CREATE_GIBWORK_TASK_ACTION: createGibworkTaskAction,
|
||||
|
||||
60
src/actions/stakeWithSolayer.ts
Normal file
60
src/actions/stakeWithSolayer.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { stakeWithSolayer } from "../tools";
|
||||
|
||||
const stakeWithSolayerAction: Action = {
|
||||
name: "STAKE_WITH_SOLAYER",
|
||||
similes: [
|
||||
"stake sol",
|
||||
"solayer sol",
|
||||
"ssol",
|
||||
"stake with solayer",
|
||||
"solayer restaking",
|
||||
"solayer staking",
|
||||
"stake with sol",
|
||||
"liquid staking solayer",
|
||||
"get solayer sol",
|
||||
"solayer sol restaking",
|
||||
"solayer sol staking",
|
||||
],
|
||||
description:
|
||||
"Stake native SOL with Solayer's restaking protocol to receive Solayer SOL (sSOL)",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
amount: 1.0,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "3FgHn9...",
|
||||
message: "Successfully staked 1.0 SOL for Solayer SOL (sSOL)",
|
||||
},
|
||||
explanation: "Stake 1.0 SOL to receive Solayer SOL (sSOL)",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
amount: z.number().positive().describe("Amount of SOL to stake"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const amount = input.amount as number;
|
||||
|
||||
const res = await stakeWithSolayer(agent, amount);
|
||||
return {
|
||||
status: "success",
|
||||
res,
|
||||
message: `Successfully staked ${amount} SOL for Solayer SOL (sSOL)`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Solayer staking failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default stakeWithSolayerAction;
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
getTokenDataByAddress,
|
||||
getTokenDataByTicker,
|
||||
stakeWithJup,
|
||||
stakeWithSolayer,
|
||||
sendCompressedAirdrop,
|
||||
orcaCreateSingleSidedLiquidityPool,
|
||||
orcaCreateCLMM,
|
||||
@@ -254,6 +255,10 @@ export class SolanaAgentKit {
|
||||
return stakeWithJup(this, amount);
|
||||
}
|
||||
|
||||
async restake(amount: number): Promise<string> {
|
||||
return stakeWithSolayer(this, amount);
|
||||
}
|
||||
|
||||
async sendCompressedAirdrop(
|
||||
mintAddress: string,
|
||||
amount: number,
|
||||
|
||||
@@ -862,6 +862,39 @@ export class SolanaStakeTool extends Tool {
|
||||
}
|
||||
}
|
||||
|
||||
export class SolanaRestakeTool extends Tool {
|
||||
name = "solana_restake";
|
||||
description = `This tool can be used to restake your SOL on Solayer to receive Solayer SOL (sSOL) as a Liquid Staking Token (LST).
|
||||
|
||||
Inputs:
|
||||
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.restake(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
|
||||
*/
|
||||
@@ -1997,6 +2030,7 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
|
||||
new SolanaLendAssetTool(solanaKit),
|
||||
new SolanaTPSCalculatorTool(solanaKit),
|
||||
new SolanaStakeTool(solanaKit),
|
||||
new SolanaRestakeTool(solanaKit),
|
||||
new SolanaFetchPriceTool(solanaKit),
|
||||
new SolanaGetDomainTool(solanaKit),
|
||||
new SolanaTokenDataTool(solanaKit),
|
||||
|
||||
@@ -21,6 +21,7 @@ export * from "./lend";
|
||||
export * from "./get_tps";
|
||||
export * from "./get_token_data";
|
||||
export * from "./stake_with_jup";
|
||||
export * from "./stake_with_solayer";
|
||||
export * from "./fetch_price";
|
||||
export * from "./send_compressed_airdrop";
|
||||
export * from "./orca_close_position";
|
||||
|
||||
64
src/tools/stake_with_solayer.ts
Normal file
64
src/tools/stake_with_solayer.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { VersionedTransaction } from "@solana/web3.js";
|
||||
import { SolanaAgentKit } from "../index";
|
||||
|
||||
/**
|
||||
* Stake SOL with Solayer
|
||||
* @param agent SolanaAgentKit instance
|
||||
* @param amount Amount of SOL to stake
|
||||
* @returns Transaction signature
|
||||
*/
|
||||
export async function stakeWithSolayer(
|
||||
agent: SolanaAgentKit,
|
||||
amount: number,
|
||||
): Promise<string> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`https://app.solayer.org/api/action/restake/ssol?amount=${amount}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
account: agent.wallet.publicKey.toBase58(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || 'Staking request failed');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Deserialize and prepare transaction
|
||||
const txn = VersionedTransaction.deserialize(
|
||||
Buffer.from(data.transaction, "base64"),
|
||||
);
|
||||
|
||||
// Update blockhash
|
||||
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,
|
||||
});
|
||||
|
||||
// Wait for confirmation
|
||||
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(`Solayer sSOL staking failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user