@agentix/plugin-solana-sanctum
Version:
703 lines (683 loc) • 22 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
var import_agentix4 = require("agentix");
// src/actions/sanctumGetLSTPrice.ts
var import_zod = require("zod");
// src/tools/sanctum_get_lst_price.ts
var import_redaxios = __toESM(require("redaxios"), 1);
// src/constants/index.ts
var SANCTUM_STAT_API_URI = "https://extra-api.sanctum.so";
var SANCTUM_TRADE_API_URI = "https://sanctum-s-api.fly.dev";
// src/tools/sanctum_get_lst_price.ts
async function sanctumGetLSTPrice(inputs) {
try {
const client = import_redaxios.default.create({
baseURL: SANCTUM_STAT_API_URI
});
const response = await client.get("/v1/sol-value/current", {
params: {
lst: inputs
},
paramsSerializer: (params) => {
return params.lst.map((value) => `lst=${value}`).join("&");
}
});
const result = response.data.solValues;
return result;
} catch (error) {
throw new Error(`Failed to get price: ${error.message}`);
}
}
// src/tools/sanctum_get_lst_apy.ts
var import_redaxios2 = __toESM(require("redaxios"), 1);
async function sanctumGetLSTAPY(inputs) {
try {
const client = import_redaxios2.default.create({
baseURL: SANCTUM_STAT_API_URI
});
const response = await client.get("/v1/apy/latest", {
params: {
lst: inputs
},
paramsSerializer: (params) => {
return params.lst.map((value) => `lst=${value}`).join("&");
}
});
const result = response.data.apys;
return result;
} catch (error) {
throw new Error(`Failed to get apy: ${error.message}`);
}
}
// src/tools/sanctum_get_lst_tvl.ts
var import_redaxios3 = __toESM(require("redaxios"), 1);
async function sanctumGetLSTTVL(inputs) {
try {
const client = import_redaxios3.default.create({
baseURL: SANCTUM_TRADE_API_URI
});
const response = await client.get("/v1/tvl/current", {
params: {
lst: inputs
},
paramsSerializer: (params) => {
return params.lst.map((value) => `lst=${value}`).join("&");
}
});
const result = response.data.tvls;
return result;
} catch (error) {
throw new Error(`Failed to get tvl: ${error.message}`);
}
}
// src/tools/sanctum_add_liquidity.ts
var import_web3 = require("@solana/web3.js");
var import_redaxios4 = __toESM(require("redaxios"), 1);
var import_agentix = require("agentix");
async function sanctumAddLiquidity(agent, lstMint, amount, quotedAmount, priorityFee) {
try {
const client = import_redaxios4.default.create({
baseURL: SANCTUM_TRADE_API_URI
});
const response = await client.post("/v1/liquidity/add", {
amount,
dstLstAcc: null,
lstMint,
priorityFee: {
Auto: {
max_unit_price_micro_lamports: priorityFee,
unit_limit: 3e5
}
},
quotedAmount,
signer: agent.wallet.getAddress(),
srcLstAcc: null
});
const txBuffer = Buffer.from(response.data.tx, "base64");
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
const tx = import_web3.VersionedTransaction.deserialize(txBuffer);
const messages = tx.message;
const instructions = messages.compiledInstructions.map((ix) => {
return new import_web3.TransactionInstruction({
programId: messages.staticAccountKeys[ix.programIdIndex],
keys: ix.accountKeyIndexes.map((i) => ({
pubkey: messages.staticAccountKeys[i],
isSigner: messages.isAccountSigner(i),
isWritable: messages.isAccountWritable(i)
})),
data: Buffer.from(ix.data, "base64")
});
});
const newMessage = new import_web3.TransactionMessage({
payerKey: new import_web3.PublicKey(agent.wallet.getAddress()),
recentBlockhash: blockhash,
instructions
}).compileToV0Message();
const newTx = new import_web3.VersionedTransaction(newMessage);
return await (0, import_agentix.signOrSendTX)(agent, newTx);
} catch (error) {
throw new Error(`Failed to add liquidity: ${error.message}`);
}
}
// src/tools/sanctum_remove_liquidity.ts
var import_web32 = require("@solana/web3.js");
var import_redaxios5 = __toESM(require("redaxios"), 1);
var import_agentix2 = require("agentix");
async function sanctumRemoveLiquidity(agent, lstMint, amount, quotedAmount, priorityFee) {
try {
const client = import_redaxios5.default.create({
baseURL: SANCTUM_TRADE_API_URI
});
const response = await client.post("/v1/liquidity/remove", {
amount,
dstLstAcc: null,
lstMint,
priorityFee: {
Auto: {
max_unit_price_micro_lamports: priorityFee,
unit_limit: 3e5
}
},
quotedAmount,
signer: agent.wallet.getAddress(),
srcLstAcc: null
});
const txBuffer = Buffer.from(response.data.tx, "base64");
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
const tx = import_web32.VersionedTransaction.deserialize(txBuffer);
const messages = tx.message;
const instructions = messages.compiledInstructions.map((ix) => {
return new import_web32.TransactionInstruction({
programId: messages.staticAccountKeys[ix.programIdIndex],
keys: ix.accountKeyIndexes.map((i) => ({
pubkey: messages.staticAccountKeys[i],
isSigner: messages.isAccountSigner(i),
isWritable: messages.isAccountWritable(i)
})),
data: Buffer.from(ix.data, "base64")
});
});
const newMessage = new import_web32.TransactionMessage({
payerKey: new import_web32.PublicKey(agent.wallet.getAddress()),
recentBlockhash: blockhash,
instructions
}).compileToV0Message();
const newTx = new import_web32.VersionedTransaction(newMessage);
return await (0, import_agentix2.signOrSendTX)(agent, newTx);
} catch (error) {
throw new Error(`Remove Liquidity failed: ${error.message}`);
}
}
// src/tools/sanctum_get_owned_lst.ts
var import_spl_token = require("@solana/spl-token");
var import_redaxios6 = __toESM(require("redaxios"), 1);
var import_web33 = require("@solana/web3.js");
async function sanctumGetOwnedLST(agent) {
try {
const [tokenAccountData] = await Promise.all([
agent.wallet.getConnection().getParsedTokenAccountsByOwner(new import_web33.PublicKey(agent.wallet.getAddress()), {
programId: import_spl_token.TOKEN_PROGRAM_ID
})
]);
const removedZeroBalance = tokenAccountData.value.filter(
(v) => v.account.data.parsed.info.tokenAmount.uiAmount !== 0
);
const tokens = await Promise.all(
removedZeroBalance.map(async (v) => {
return {
mint: v.account.data.parsed.info.mint,
amount: v.account.data.parsed.info.tokenAmount.uiAmount,
decimals: v.account.data.parsed.info.tokenAmount.decimals
};
})
);
const lsts = tokens.filter((token) => {
return token.decimals === 9;
});
const addresses = lsts.map((token) => token.mint);
const client = import_redaxios6.default.create({
baseURL: SANCTUM_STAT_API_URI
});
const response = await client.get("/v1/sol-value/current", {
params: {
lst: addresses
},
paramsSerializer: (params) => {
return params.lst.map((value) => `lst=${value}`).join("&");
}
});
const result = Object.keys(response.data.solValues);
const lstsWithValue = await Promise.all(
lsts.map((lst) => {
if (result.includes(lst.mint)) {
return {
mint: lst.mint,
amount: lst.amount
};
}
return null;
}).filter((lst) => lst !== null)
);
return lstsWithValue;
} catch (error) {
throw new Error(`Failed to get owned lst: ${error.message}`);
}
}
// src/tools/sanctum_swap_lst.ts
var import_web34 = require("@solana/web3.js");
var import_web35 = require("@solana/web3.js");
var import_web36 = require("@solana/web3.js");
var import_redaxios7 = __toESM(require("redaxios"), 1);
var import_agentix3 = require("agentix");
async function sanctumSwapLST(agent, inputLstMint, amount, quotedAmount, priorityFee, outputLstMint) {
try {
const client = import_redaxios7.default.create({
baseURL: SANCTUM_TRADE_API_URI
});
const response = await client.post("/v1/swap", {
amount,
dstLstAcc: null,
input: inputLstMint,
mode: "ExactIn",
priorityFee: {
Auto: {
max_unit_price_micro_lamports: priorityFee,
unit_limit: 3e5
}
},
outputLstMint,
quotedAmount,
signer: agent.wallet.getAddress(),
srcLstAcc: null
});
const txBuffer = Buffer.from(response.data.tx, "base64");
const { blockhash } = await agent.wallet.getConnection().getLatestBlockhash();
const tx = import_web34.VersionedTransaction.deserialize(txBuffer);
const messages = tx.message;
const instructions = messages.compiledInstructions.map((ix) => {
return new import_web35.TransactionInstruction({
programId: messages.staticAccountKeys[ix.programIdIndex],
keys: ix.accountKeyIndexes.map((i) => ({
pubkey: messages.staticAccountKeys[i],
isSigner: messages.isAccountSigner(i),
isWritable: messages.isAccountWritable(i)
})),
data: Buffer.from(ix.data, "base64")
});
});
const newMessage = new import_web36.TransactionMessage({
payerKey: new import_web34.PublicKey(agent.wallet.getAddress()),
recentBlockhash: blockhash,
instructions
}).compileToV0Message();
const newTx = new import_web34.VersionedTransaction(newMessage);
return await (0, import_agentix3.signOrSendTX)(agent, newTx);
} catch (error) {
throw new Error(`Failed to swap lst: ${error.message}`);
}
}
// src/actions/sanctumGetLSTPrice.ts
var sanctumGetLSTPriceAction = {
name: "GET_SANCTUM_PRICE",
similes: ["get sanctum LST price", "fetch sanctum LST price"],
description: "Fetch the Price of a LST(Liquid Staking Token) on Sanctum with specified mint addresses or symbols",
examples: [
[
{
input: {
inputs: [
"INF",
"pwrsol",
"mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
"laineSOL"
]
},
output: {
INF: "1303329251",
laineSOL: "1221330946",
mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So: "1279055247",
pwrsol: "1105899448"
},
explanation: "Fetch the prices of LSTs on Sanctum"
}
]
],
schema: import_zod.z.object({
mints: import_zod.z.array(import_zod.z.string())
}),
handler: async (_agent, input) => {
try {
const prices = await sanctumGetLSTPrice(input.mints);
return {
status: "success",
message: "Price fetched successfully",
prices
};
} catch (error) {
return {
status: "error",
message: `Fetching Sanctum LST price failed: ${error.message}`
};
}
}
};
// src/actions/sanctumGetLSTTVL.ts
var import_zod2 = require("zod");
var sanctumGetLSTTVLAction = {
name: "GET_SANCTUM_TVL",
similes: ["get sanctum LST TVL", "fetch sanctum LST TVL"],
description: "Fetch the TVL of a LST(Liquid Staking Token) on Sanctum with specified mint addresses or symbols",
examples: [
[
{
input: {
inputs: [
"INF",
"pwrsol",
"mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
"laineSOL"
]
},
output: {
pwrsol: "3100602224977",
INF: "620838653321879",
mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So: "4892112998338119",
laineSOL: "55512833109331"
},
explanation: "Fetch the TVL of LSTs on Sanctum"
}
]
],
schema: import_zod2.z.object({
inputs: import_zod2.z.array(import_zod2.z.string())
}),
handler: async (_agent, input) => {
try {
const tvls = await sanctumGetLSTTVL(input.inputs);
return {
status: "success",
message: "TVL fetched successfully",
tvls
};
} catch (error) {
return {
status: "error",
message: `Fetching Sanctum LST TVL failed: ${error.message}`
};
}
}
};
// src/actions/sanctumGetLSTAPY.ts
var import_zod3 = require("zod");
var sanctumGetLSTAPYAction = {
name: "GET_SANCTUM_APY",
similes: ["get sanctum LST APY", "fetch sanctum LST APY"],
description: "Fetch the APY of a LST(Liquid Staking Token) on Sanctum with specified mint addresses or symbols",
examples: [
[
{
input: {
inputs: [
"INF",
"pwrsol",
"mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
"laineSOL"
]
},
output: {
pwrsol: 0.08321988140942367,
laineSOL: 0.0831767225669587,
INF: 0.06542961909093714,
mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So: 0.08143705823579084
},
explanation: "Fetch the APY of LSTs on Sanctum"
}
]
],
schema: import_zod3.z.object({
inputs: import_zod3.z.array(import_zod3.z.string())
}),
handler: async (_agent, input) => {
try {
const apys = await sanctumGetLSTAPY(input.inputs);
return {
status: "success",
message: "APY fetched successfully",
apys
};
} catch (error) {
return {
status: "error",
message: `Fetching Sanctum LST APY failed: ${error.message}`
};
}
}
};
// src/actions/sanctumAddLiquidity.ts
var import_zod4 = require("zod");
var sanctumAddLiquidityAction = {
name: "SANCTUM_ADD_LIQUIDITY",
similes: ["add liquidity to sanctum pool", "deposit to sanctum pool"],
description: "Add liquidity to a Sanctum pool with specified parameters",
examples: [
[
{
input: {
lstMint: "So11111111111111111111111111111111111111112",
amount: "1000000000",
quotedAmount: "900000000",
priorityFee: 5e3
},
output: {
status: "success",
message: "Liquidity added successfully",
txId: "2jg87stmvPygRXJrqfpydZQSzGJK9rKvawekzy5mzuEmSjRf8bCmiGpFH8iLa2YrQxtreWcK99319DVTpCJHYZfx"
},
explanation: "Add liquidity to a Sanctum pool"
}
]
],
schema: import_zod4.z.object({
lstMint: import_zod4.z.string(),
amount: import_zod4.z.string(),
quotedAmount: import_zod4.z.string(),
priorityFee: import_zod4.z.number()
}),
handler: async (agent, input) => {
try {
const result = await sanctumAddLiquidity(
agent,
input.lstMint,
input.amount,
input.quotedAmount,
input.priorityFee
);
return {
status: "success",
message: typeof result === "string" ? "Liquidity added successfully" : "Liquidity addition transaction generated successfully. Please send the transaction to the network.",
transaction: result
};
} catch (error) {
return {
status: "error",
message: `Adding liquidity to Sanctum pool failed: ${error.message}`
};
}
}
};
// src/actions/sanctumRemoveLiquidity.ts
var import_zod5 = require("zod");
var sanctumRemoveLiquidityAction = {
name: "SANCTUM_REMOVE_LIQUIDITY",
similes: ["remove liquidity from sanctum pool", "withdraw from sanctum pool"],
description: "Remove liquidity from a Sanctum pool with specified parameters",
examples: [
[
{
input: {
lstMint: "So11111111111111111111111111111111111111112",
amount: "1000000000",
quotedAmount: "900000000",
priorityFee: 5e3
},
output: {
status: "success",
message: "Liquidity removed successfully",
txId: "2FqduazbmVrYAs6VMj7whKvFhEJnCyCvm7GiX4xCj1FSVr4CquPqFoCPDokUuJJ3T24EpXLPxrJWmGq6EnpsrJWf"
},
explanation: "Remove liquidity from a Sanctum pool"
}
]
],
schema: import_zod5.z.object({
lstMint: import_zod5.z.string(),
amount: import_zod5.z.string(),
quotedAmount: import_zod5.z.string(),
priorityFee: import_zod5.z.number()
}),
handler: async (agent, input) => {
try {
const result = await sanctumRemoveLiquidity(
agent,
input.lstMint,
input.amount,
input.quotedAmount,
input.priorityFee
);
return {
status: "success",
message: typeof result === "string" ? "Liquidity removed successfully" : "Liquidity removal transaction generated and signed succesfully. Please send it to the network.",
transaction: result
};
} catch (error) {
return {
status: "error",
message: `Removing liquidity from Sanctum pool failed: ${error.message}`
};
}
}
};
// src/actions/sanctumGetOwnedLST.ts
var import_zod6 = require("zod");
var sanctumGetOwnedLSTAction = {
name: "SANCTUM_GET_OWNED_LST",
similes: [
"get owned lst",
"get owned lst tokens",
"get owned lst assets",
"get owned lst assets list"
],
description: "Fetch the owned LST(Liquid Staking Token) on Sanctum with specified account",
examples: [
[
{
input: {},
output: {
lsts: [
{
mint: "mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So",
balance: 35e-4
}
]
},
explanation: "Owned LSTs fetched successfully"
}
]
],
schema: import_zod6.z.object({}),
handler: async (agent) => {
try {
const result = await sanctumGetOwnedLST(agent);
return {
status: "success",
message: "Owned LSTs fetched successfully",
lsts: result
};
} catch (error) {
return {
status: "error",
message: `Fetching owned LSTs failed: ${error.message}`
};
}
}
};
// src/actions/sanctumSwapLST.ts
var import_zod7 = require("zod");
var sanctumSwapLSTAction = {
name: "SANCTUM_SWAP_LST",
similes: ["swap lst in sanctum", "swap lst", "trade lst in sanctum"],
description: `Swap LST(Liquid Staking Token) on Sanctum with specified parameters`,
examples: [
[
{
input: {
inputLstMint: "So11111111111111111111111111111111111111112",
amount: "1000000000",
quotedAmount: "900000000",
priorityFee: 5e3,
outputLstMint: "bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1"
},
output: {
status: "success",
message: "LST swapped successfully",
txId: "2FqduazbmVrYAs6VMj7whKvFhEJnCyCvm7GiX4xCj1FSVr4CquPqFoCPDokUuJJ3T24EpXLPxrJWmGq6EnpsrJWf"
},
explanation: "Swap lst successfully on Sanctum"
}
]
],
schema: import_zod7.z.object({
inputLstMint: import_zod7.z.string(),
amount: import_zod7.z.string(),
quotedAmount: import_zod7.z.string(),
priorityFee: import_zod7.z.number(),
outputLstMint: import_zod7.z.string()
}),
handler: async (agent, input) => {
try {
const result = await sanctumSwapLST(
agent,
input.inputLstMint,
input.amount,
input.quotedAmount,
input.priorityFee,
input.outputLstMint
);
return {
status: "success",
message: typeof result === "string" ? "LST swapped successfully" : "LST swap transaction signed successfully. Please send the transaction to the network.",
transaction: result
};
} catch (error) {
return {
status: "error",
message: `Swapping LST on Sanctum failed: ${error.message}`
};
}
}
};
// src/index.ts
var SanctumPlugin = class extends import_agentix4.PluginBase {
constructor() {
const methods = {
sanctumAddLiquidity,
sanctumGetLSTAPY,
sanctumGetLSTPrice,
sanctumGetLSTTVL,
sanctumGetOwnedLST,
sanctumRemoveLiquidity,
sanctumSwapLST
};
const actions = [
sanctumAddLiquidityAction,
sanctumGetLSTAPYAction,
sanctumGetLSTPriceAction,
sanctumGetLSTTVLAction,
sanctumGetOwnedLSTAction,
sanctumRemoveLiquidityAction,
sanctumSwapLSTAction
];
const supportedChains = [
{
type: "solana"
}
];
super("sanctum", methods, actions, supportedChains);
}
supportsWallet(wallet) {
return wallet instanceof import_agentix4.SolanaWalletBase;
}
};
var index_default = SanctumPlugin;