@agentix/plugin-solana-solayer
Version:
119 lines (114 loc) • 3.11 kB
JavaScript
// src/index.ts
import { PluginBase, SolanaWalletBase as SolanaWalletBase2 } from "agentix";
// src/actions/stakeWithSolayer.ts
import { z } from "zod";
// src/tools/stake_with_solayer.ts
import { VersionedTransaction } from "@solana/web3.js";
import { signOrSendTX } from "agentix";
async function stakeWithSolayer(agent, amount) {
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.getAddress()
})
}
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.message || "Staking request failed");
}
const data = await response.json();
const txn = VersionedTransaction.deserialize(
Buffer.from(data.transaction, "base64")
);
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
txn.message.recentBlockhash = blockhash;
return await signOrSendTX(agent, txn);
} catch (error) {
console.error(error);
throw new Error(`Solayer sSOL staking failed: ${error.message}`);
}
}
// src/actions/stakeWithSolayer.ts
var stakeWithSolayerAction = {
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
},
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, input) => {
try {
const amount = input.amount;
const res = await stakeWithSolayer(agent, amount);
return {
status: "success",
transaction: res,
message: `Successfully staked ${amount} SOL for Solayer SOL (sSOL)`
};
} catch (error) {
return {
status: "error",
message: `Solayer staking failed: ${error.message}`
};
}
}
};
var stakeWithSolayer_default = stakeWithSolayerAction;
// src/index.ts
var SolayerPlugin = class extends PluginBase {
constructor() {
const methods = {
stakeWithSolayer
};
const actions = [
stakeWithSolayer_default
];
const supportedChains = [
{
type: "solana"
}
];
super("solayer", methods, actions, supportedChains);
}
supportsWallet(wallet) {
return wallet instanceof SolanaWalletBase2;
}
};
var index_default = SolayerPlugin;
export {
index_default as default
};