core
framework provides the following components:
- actions: Action type definitions and interfaces for all plugin types
- queries: Query type definitions for retrieving protocol data
- schemas: Zod validation schemas for requests and responses
- pluginType.ts: Core plugin type definitions
- index.ts: Main exports for plugin development
EmberPlugin
interface, while pluginType.ts defines the plugin types (lending, liquidity, swap, perpetuals) and maps each type to its available actions and queries. The actions directory provides the executable operations (supply, borrow, swap, etc.) with their callback signatures, while queries enable data retrieval without transactions. All inputs and outputs are validated through schemas, ensuring type safety and data consistency across the system.
Ember Plugin Interface
The framework defines anEmberPlugin<Type>
interface, and each plugin must implement this interface:
Lending
: Supply, borrow, repay, and withdraw operationsliquidity
: Add and remove liquidity from poolsswap
: Token exchange operationsperpetuals
: Long, short, and close perpetual positions
Actions
Each plugin type defines specific actions it can execute. For example, lending plugins can dolending-supply
, lending-borrow
, lending-repay
, and lending-withdraw
. Each action has callback functions that define its request and response.
Queries
Each plugin type can define queries to retrieve protocol data without executing transactions:- Lending: Get user positions, health factors, and borrowing capacity
- Liquidity: Get wallet LP positions and available pools
- Perpetuals: Get markets, active positions, and pending orders
- Swap: No queries (stateless operations)
Schema Architecture
The schema system provides comprehensive type safety with Zod validation: Core Schemas (schemas/core.ts
):
TokenSchema
: Complete token metadata, including native token handlingTransactionPlanSchema
: Standardized transaction format for all chainsFeeBreakdownSchema
: Service fees and slippage cost structureBalanceSchema
: User wallet balance representation
- Lending (
schemas/lending.ts
): Supply, borrow, repay, and withdraw operations with comprehensive position tracking - Liquidity (
schemas/liquidity.ts
): Advanced liquidity provision with discriminated unions for full/limited range positions - Swap (
schemas/swap.ts
): Token exchange with slippage tolerance and price tracking - Perpetuals (
schemas/perpetuals.ts
): Integration with GMX SDK for complex derivatives trading
Plugin Registry
The registry (registry.ts
) manages plugin discovery and registration. You can initialize a registry using initializePublicRegistry().
Use registerDeferredPlugin()
for plugin initialization: