From 99104763e39a3de396ca6a78178295bf0adda19c Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Thu, 26 Jun 2025 10:43:32 +0200 Subject: [PATCH] Add Reusable EVM Schemas --- packages/agent-sdk/src/index.ts | 1 + packages/agent-sdk/src/openai/index.ts | 3 ++ packages/agent-sdk/src/openai/params.ts | 35 ++++++++++++++ packages/agent-sdk/src/openai/response.ts | 19 ++++++++ packages/agent-sdk/src/openai/schema.ts | 58 +++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 packages/agent-sdk/src/openai/index.ts create mode 100644 packages/agent-sdk/src/openai/params.ts create mode 100644 packages/agent-sdk/src/openai/response.ts create mode 100644 packages/agent-sdk/src/openai/schema.ts diff --git a/packages/agent-sdk/src/index.ts b/packages/agent-sdk/src/index.ts index 7efab6a..534309d 100644 --- a/packages/agent-sdk/src/index.ts +++ b/packages/agent-sdk/src/index.ts @@ -3,3 +3,4 @@ export * from "./evm"; export * from "./request"; export * from "./error"; export * from "./misc"; +export * from "./openai"; diff --git a/packages/agent-sdk/src/openai/index.ts b/packages/agent-sdk/src/openai/index.ts new file mode 100644 index 0000000..62a7925 --- /dev/null +++ b/packages/agent-sdk/src/openai/index.ts @@ -0,0 +1,3 @@ +export * from "./params"; +export * from "./response"; +export * from "./schema"; diff --git a/packages/agent-sdk/src/openai/params.ts b/packages/agent-sdk/src/openai/params.ts new file mode 100644 index 0000000..f3d68c1 --- /dev/null +++ b/packages/agent-sdk/src/openai/params.ts @@ -0,0 +1,35 @@ +export const chainIdParam = { + name: "chainId", + in: "query", + required: true, + description: "EVM Network (aka chain ID)", + schema: { type: "number" }, + example: 100, +}; + +export const addressParam = { + name: "address", + in: "query", + required: true, + description: "20 byte Ethereum address with 0x prefix", + schema: { type: "string" }, +}; + +export const addressOrSymbolParam = { + name: "address", + in: "query", + required: true, + description: + "The ERC-20 token symbol or address to be sold, if provided with the symbol do not try to infer the address.", + schema: { type: "string" }, + example: "0x6810e776880c02933d47db1b9fc05908e5386b96", +}; + +export const amountParam = { + name: "amount", + in: "query", + required: true, + description: "Amount in human-readable units (not wei)", + schema: { type: "number" }, + example: 0.123, +}; diff --git a/packages/agent-sdk/src/openai/response.ts b/packages/agent-sdk/src/openai/response.ts new file mode 100644 index 0000000..9da9046 --- /dev/null +++ b/packages/agent-sdk/src/openai/response.ts @@ -0,0 +1,19 @@ +export const SignRequestResponse200 = { + description: "Successful signing request", + content: { + "application/json": { + schema: { + type: "object", + required: ["transaction"], + properties: { + transaction: { $ref: "#/components/schemas/SignRequest" }, + meta: { + type: "object", + additionalProperties: true, + example: { message: "Submitted" }, + }, + }, + }, + }, + }, +}; diff --git a/packages/agent-sdk/src/openai/schema.ts b/packages/agent-sdk/src/openai/schema.ts new file mode 100644 index 0000000..afcb88e --- /dev/null +++ b/packages/agent-sdk/src/openai/schema.ts @@ -0,0 +1,58 @@ +export const AddressSchema = { + description: "20 byte Ethereum address encoded as a hex with `0x` prefix.", + type: "string", + example: "0x6810e776880c02933d47db1b9fc05908e5386b96", +}; + +export const MetaTransactionSchema = { + type: "object", + description: "Sufficient data representing an EVM transaction", + properties: { + to: { $ref: "#/components/schemas/Address" }, + data: { + type: "string", + description: "Transaction calldata", + example: "0xd0e30db0", + }, + value: { + type: "string", + description: "Transaction value", + example: "0x1b4fbd92b5f8000", + }, + }, + required: ["to", "data", "value"], +}; + +export const SignRequestSchema = { + type: "object", + required: ["method", "chainId", "params"], + properties: { + method: { + type: "string", + enum: [ + "eth_sign", + "personal_sign", + "eth_sendTransaction", + "eth_signTypedData", + "eth_signTypedData_v4", + ], + description: "The signing method to be used.", + }, + chainId: { + type: "integer", + description: "The ID of the Ethereum chain.", + }, + params: { + oneOf: [ + { + type: "array", + items: { $ref: "#/components/schemas/MetaTransaction" }, + }, + { + type: "array", + items: { type: "string" }, + }, + ], + }, + }, +};