mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-03 07:36:45 +00:00
feat: drift perp trade, account creation, withdraw, and deposit
This commit is contained in:
59
src/actions/drift/createDriftUserAccount.ts
Normal file
59
src/actions/drift/createDriftUserAccount.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { z } from "zod";
|
||||
import type { Action } from "../../types";
|
||||
import { createDriftUserAccount } from "../../tools";
|
||||
|
||||
const createDriftUserAccountAction: Action = {
|
||||
name: "CREATE_DRIFT_USER_ACCOUNT",
|
||||
similes: [
|
||||
"create drift account",
|
||||
"create drift user account",
|
||||
"create user account on drift",
|
||||
],
|
||||
description: "Create a new user account on Drift protocol",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
amount: 100,
|
||||
symbol: "SOL",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "User account created with 100 SOL successfully deposited",
|
||||
account: "4xKpN2...",
|
||||
},
|
||||
explanation: "Create a new user account with 100 SOL",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
amount: z.number().positive().describe("Amount of the token to deposit"),
|
||||
symbol: z.string().describe("Symbol of the token to deposit"),
|
||||
}),
|
||||
handler: async (agent, input) => {
|
||||
try {
|
||||
const res = await createDriftUserAccount(
|
||||
agent,
|
||||
input.amount,
|
||||
input.symbol,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message:
|
||||
res.message ??
|
||||
`User account created with ${input.amount} ${input.symobl} successfully deposited.`,
|
||||
account: res.account,
|
||||
signature: res.txSignature,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
status: "error",
|
||||
// @ts-expect-error - error message is a string
|
||||
message: `Failed to create user account: ${e.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default createDriftUserAccountAction;
|
||||
Reference in New Issue
Block a user