feat: add more drift actions

This commit is contained in:
michaelessiet
2025-01-17 17:12:34 +01:00
parent 79fe5b0cb4
commit 0c840d9bcb
12 changed files with 625 additions and 1 deletions

View File

@@ -0,0 +1,65 @@
import { z } from "zod";
import type { Action } from "../../types";
import { getEntryQuoteOfPerpTrade } from "../../tools";
const entryQuoteOfPerpTradeAction: Action = {
name: "DRIFT_GET_ENTRY_QUOTE_OF_PERP_TRADE_ACTION",
description: "Get the entry quote of a perpetual trade on Drift",
similes: [
"get the entry quote of a perpetual trade on drift",
"get the entry quote of a perp trade on drift",
"get the entry quote of the BTC-PERP trade on drift",
"get the entry quote of the SOL-PERP trade on drift",
"get the entry quote of a 1000 USDC long on the SOL-PERP market",
"get the entry quote of a 1000 USDC short on the SOL-PERP market",
"quote for a $1000 long on the BTC-PERP market",
],
examples: [
[
{
input: {
marketSymbol: "BTC-PERP",
type: "long",
amount: 1000,
},
output: {
status: "success",
data: {
entryPrice: 100000,
priceImpact: 0.0001,
bestPrice: 100001,
worstPrice: 99999,
baseFilled: 1000,
quoteFilled: 1000,
},
},
explanation:
"Get the entry quote of a $1000 long on the BTC-PERP market",
},
],
],
schema: z.object({
marketSymbol: z.string().describe("Symbol of the perpetual market"),
type: z.enum(["long", "short"]).describe("Type of trade"),
amount: z.number().positive().describe("Amount to trade"),
}),
handler: async (agent, input) => {
try {
const data = await getEntryQuoteOfPerpTrade(
input.marketSymbol,
input.amount,
input.type,
);
return data;
} catch (e) {
return {
status: "error",
// @ts-expect-error error is not a string
message: e.message,
};
}
},
};
export default entryQuoteOfPerpTradeAction;

View File

@@ -0,0 +1,52 @@
import { z } from "zod";
import type { Action } from "../../types";
import { getLendingAndBorrowAPY } from "../../tools";
const lendAndBorrowAPYAction: Action = {
name: "DRIFT_GET_LEND_AND_BORROW_APY_ACTION",
description: "Get the lending and borrowing APY (in %) of a token on Drift",
similes: [
"get the lending and borrowing APY of a token on drift",
"get the lending and borrowing APY of a token on drift",
"get the lending and borrowing APY of the USDC token on drift",
"get the lending and borrowing APY of the SOL token on drift",
],
examples: [
[
{
input: {
symbol: "USDC",
},
output: {
status: "success",
data: {
lendingAPY: 10,
borrowingAPY: 12.1,
},
},
explanation: "Get the lending and borrowing APY of the USDC token",
},
],
],
schema: z.object({
symbol: z.string().describe("Symbol of the token"),
}),
handler: async (agent, input) => {
try {
const data = await getLendingAndBorrowAPY(agent, input.symbol);
return {
status: "success",
data,
};
} catch (e) {
return {
status: "error",
// @ts-expect-error error is not a string
message: e.message,
};
}
},
};
export default lendAndBorrowAPYAction;

View File

@@ -0,0 +1,61 @@
import { z } from "zod";
import type { Action } from "../../types";
import { calculatePerpMarketFundingRate } from "../../tools";
const perpMarktetFundingRateAction: Action = {
name: "DRIFT_PERP_MARKET_FUNDING_RATE_ACTION",
description: "Get the funding rate of a perpetual market on Drift",
similes: [
"get the yearly funding rate of a perpetual market on drift",
"get the funding rate of a perp market on drift",
"get the hourly funding rate of a perpetual market on drift",
"get the funding rate of the BTC-PERP market on drift",
"get the funding rate of the SOL-PERP market on drift",
],
examples: [
[
{
input: {
marketSymbol: "BTC-PERP",
},
output: {
status: "success",
data: {
longRate: 0.0001,
shortRate: 0.0002,
},
},
explanation: "Get the funding rate of the BTC-PERP market",
},
],
],
schema: z.object({
marketSymbol: z
.string()
.toUpperCase()
.describe("Symbol of the perpetual market"),
period: z.enum(["year", "hour"]).default("hour").optional(),
}),
handler: async (agent, input) => {
try {
const data = await calculatePerpMarketFundingRate(
agent,
input.marketSymbol,
input.period,
);
return {
status: "success",
data,
};
} catch (e) {
return {
status: "error",
// @ts-expect-error error is not a string
message: e.message,
};
}
},
};
export default perpMarktetFundingRateAction;

View File

@@ -64,6 +64,9 @@ import stakeToDriftInsuranceFundAction from "./drift/stakeToDriftInsuranceFund";
import requestUnstakeFromDriftInsuranceFundAction from "./drift/requestUnstakeFromDriftInsuranceFund";
import unstakeFromDriftInsuranceFundAction from "./drift/unstakeFromDriftInsuranceFund";
import driftSpotTokenSwapAction from "./drift/swapSpotToken";
import perpMarktetFundingRateAction from "./drift/perpMarketFundingRate";
import entryQuoteOfPerpTradeAction from "./drift/entryQuoteOfPerpTrade";
import lendAndBorrowAPYAction from "./drift/getLendAndBorrowAPY";
export const ACTIONS = {
WALLET_ADDRESS_ACTION: getWalletAddressAction,
@@ -134,6 +137,9 @@ export const ACTIONS = {
requestUnstakeFromDriftInsuranceFundAction,
UNSTAKE_FROM_DRIFT_INSURANCE_FUND_ACTION: unstakeFromDriftInsuranceFundAction,
DRIFT_SPOT_TOKEN_SWAP_ACTION: driftSpotTokenSwapAction,
DRIFT_PERP_MARKET_FUNDING_RATE_ACTION: perpMarktetFundingRateAction,
DRIFT_GET_ENTRY_QUOTE_OF_PERP_TRADE_ACTION: entryQuoteOfPerpTradeAction,
DRIFT_GET_LEND_AND_BORROW_APY_ACTION: lendAndBorrowAPYAction,
};
export type { Action, ActionExample, Handler } from "../types/action";