Skip to content

oraichain/lfg-protos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LFG Protos

TypeScript codegen library for the LFG protocol on Oraichain. This package provides auto-generated TypeScript types, message classes, and client interfaces from Protocol Buffers definitions for all LFG protocol modules.

Features

  • 🔧 Auto-generated Types: Complete TypeScript type definitions from protobuf schemas
  • 📦 Message Classes: Ready-to-use message classes with encode/decode functionality
  • 🔄 Perpetuals: Type definitions for perpetual futures trading
  • 📊 CLOB: Central Limit Order Book message types and operations
  • 🏦 Vault: Investment vault management types
  • 💱 Assets: Asset management and configuration types
  • 🎯 Subaccounts: Advanced account management with subaccount support
  • 🔧 Governance: GovPlus governance protocol types
  • 📈 Prices: Price feed and market parameter types
  • 🏛️ Bridge: Cross-chain bridge operation types
  • 💰 Rewards & Vesting: Rewards distribution and token vesting types
  • 🔒 Rate Limiting: Rate limiting protocol types
  • 🎲 MEV Protection: MEV protection mechanism types
  • 🚀 Zero Dependencies: Pure TypeScript with minimal runtime dependencies

Installation

Install the package using npm or yarn:

npm install @oraichain/lfg-protos

or

yarn add @oraichain/lfg-protos

Quick Start

Basic Usage

import { lfg } from "@oraichain/lfg-protos";

// Access all LFG protocol message types and clients
console.log(lfg.clob); // CLOB message types and RPC clients
console.log(lfg.perpetuals); // Perpetual message types
console.log(lfg.vault); // Vault message types
console.log(lfg.subaccounts); // Subaccount message types

Creating and Encoding Messages

import { lfg } from "@oraichain/lfg-protos";

// Create a CLOB pair message
const clobPair = lfg.clob.ClobPair.create({
  id: 1,
  stepBaseQuantums: "1000000",
  subticksPerTick: 100,
  quantumConversionExponent: -6,
  status: lfg.clob.ClobPair_Status.STATUS_ACTIVE,
  perpetualClobMetadata: {
    perpetualId: 1,
  },
});

// Encode to bytes
const encoded = lfg.clob.ClobPair.encode(clobPair).finish();
console.log("Encoded message:", encoded);

API Reference

Core Message Types

The LFG protos library provides the following main message types and RPC clients:

lfg.clob

Central Limit Order Book message types for spot and perpetual trading.

import { lfg } from "@oraichain/lfg-protos";

// Message types
const ClobPair = lfg.clob.ClobPair;
const Order = lfg.clob.Order;
const Matches = lfg.clob.Matches;

// RPC clients
const QueryClient = lfg.clob.QueryClient;
const MsgClient = lfg.clob.MsgClient;

lfg.perpetuals

Perpetual futures message types and management.

// Message types
const Perpetual = lfg.perpetuals.Perpetual;
const PerpetualParams = lfg.perpetuals.PerpetualParams;
const LiquidityTier = lfg.perpetuals.LiquidityTier;

// RPC clients
const QueryClient = lfg.perpetuals.QueryClient;
const MsgClient = lfg.perpetuals.MsgClient;

lfg.subaccounts

Advanced account management message types with subaccount support.

// Message types
const Subaccount = lfg.subaccounts.Subaccount;
const SubaccountId = lfg.subaccounts.SubaccountId;
const AssetPosition = lfg.subaccounts.AssetPosition;
const PerpetualPosition = lfg.subaccounts.PerpetualPosition;

// RPC clients
const QueryClient = lfg.subaccounts.QueryClient;

lfg.vault

Investment vault message types and management.

// Message types
const Vault = lfg.vault.Vault;
const Share = lfg.vault.Share;
const VaultParams = lfg.vault.VaultParams;

// RPC clients
const QueryClient = lfg.vault.QueryClient;
const MsgClient = lfg.vault.MsgClient;

lfg.assets

Asset management message types and configuration.

// Message types
const Asset = lfg.assets.Asset;

// RPC clients
const QueryClient = lfg.assets.QueryClient;
const MsgClient = lfg.assets.MsgClient;

lfg.prices

Price feed and market data message types.

// Message types
const MarketPrice = lfg.prices.MarketPrice;
const MarketParam = lfg.prices.MarketParam;

// RPC clients
const QueryClient = lfg.prices.QueryClient;
const MsgClient = lfg.prices.MsgClient;

lfg.govplus

Enhanced governance message types.

// Message types
const GovPlus = lfg.govplus;

// RPC clients
const QueryClient = lfg.govplus.QueryClient;
const MsgClient = lfg.govplus.MsgClient;

lfg.bridge

Cross-chain bridge message types.

// Message types
const BridgeEvent = lfg.bridge.BridgeEvent;
const BridgeEventInfo = lfg.bridge.BridgeEventInfo;

// RPC clients
const QueryClient = lfg.bridge.QueryClient;
const MsgClient = lfg.bridge.MsgClient;

lfg.rewards

Rewards distribution message types and management.

// Message types
const RewardShare = lfg.rewards.RewardShare;
const RewardParams = lfg.rewards.RewardParams;

// RPC clients
const QueryClient = lfg.rewards.QueryClient;
const MsgClient = lfg.rewards.MsgClient;

lfg.vest

Token vesting message types.

// Message types
const VestEntry = lfg.vest.VestEntry;

// RPC clients
const QueryClient = lfg.vest.QueryClient;
const MsgClient = lfg.vest.MsgClient;

Utility Functions

protoTimestampToDate(protoTime: Timestamp): Date

Converts a protobuf timestamp to a JavaScript Date object.

import { protoTimestampToDate } from "@oraichain/lfg-protos";

const date = protoTimestampToDate(timestamp);
console.log(date); // JavaScript Date object

Examples

1. Working with CLOB Messages

import { lfg } from "@oraichain/lfg-protos";

// Create a CLOB pair message
const clobPair = lfg.clob.ClobPair.create({
  id: 1,
  stepBaseQuantums: "1000000",
  subticksPerTick: 100,
  quantumConversionExponent: -6,
  status: lfg.clob.ClobPair_Status.STATUS_ACTIVE,
  perpetualClobMetadata: {
    perpetualId: 1,
  },
});

// Encode the message
const encoded = lfg.clob.ClobPair.encode(clobPair).finish();

// Decode the message
const decoded = lfg.clob.ClobPair.decode(encoded);
console.log("Decoded CLOB pair:", decoded);

2. Managing Subaccount Messages

import { lfg } from "@oraichain/lfg-protos";

// Create a subaccount ID
const subaccountId = lfg.subaccounts.SubaccountId.create({
  owner: "orai1...", // Owner address
  number: 0, // Subaccount number
});

// Create a subaccount message
const subaccount = lfg.subaccounts.Subaccount.create({
  id: subaccountId,
  assetPositions: [],
  perpetualPositions: [],
  marginEnabled: true,
});

// Create an asset position
const assetPosition = lfg.subaccounts.AssetPosition.create({
  assetId: 0,
  size: "1000000", // Position size
  isLong: true,
});

console.log("Subaccount:", subaccount);
console.log("Asset position:", assetPosition);

3. Working with Perpetual Messages

import { lfg } from "@oraichain/lfg-protos";

// Create perpetual parameters
const perpetualParams = lfg.perpetuals.PerpetualParams.create({
  id: 1,
  ticker: "BTC-USD",
  marketId: 0,
  atomicResolution: -8,
  defaultFundingPpm: 1000,
  liquidityTier: 0,
  marketType: lfg.perpetuals.PerpetualMarketType.PERPETUAL_MARKET_TYPE_CROSS,
});

// Create a perpetual message
const perpetual = lfg.perpetuals.Perpetual.create({
  params: perpetualParams,
  fundingIndex: new Uint8Array(),
  openInterest: new Uint8Array(),
});

console.log("Perpetual:", perpetual);

4. Vault Message Operations

import { lfg } from "@oraichain/lfg-protos";

// Create vault parameters
const vaultParams = lfg.vault.VaultParams.create({
  denom: "orai",
  minDepositAmount: "1000000",
  minWithdrawalAmount: "100000",
  maxDepositAmount: "10000000000",
  maxWithdrawalAmount: "1000000000",
});

// Create a vault message
const vault = lfg.vault.Vault.create({
  params: vaultParams,
  // ... other vault fields
});

console.log("Vault:", vault);

5. Price Feed Messages

import { lfg } from "@oraichain/lfg-protos";

// Create market price message
const marketPrice = lfg.prices.MarketPrice.create({
  price: "50000000000", // Price in smallest units
  exponent: -8, // Price exponent
  marketId: 0,
});

// Create market parameter message
const marketParam = lfg.prices.MarketParam.create({
  pair: "BTC-USD",
  exponent: -8,
  minExchanges: 3,
  minPriceChangePpm: 1000,
});

console.log("Market price:", marketPrice);
console.log("Market param:", marketParam);

6. Using RPC Clients

import { lfg } from "@oraichain/lfg-protos";
import { createRpcClient } from "@cosmjs/tendermint-rpc";

// Create RPC connection
const client = await createRpcClient("https://rpc.orai.io");

// Create query client
const queryClient = new lfg.clob.QueryClientImpl(client);

// Query CLOB pairs
const response = await queryClient.ClobPairsAll({});
console.log("CLOB pairs:", response);

7. Using Utility Functions

import { lfg, protoTimestampToDate } from "@oraichain/lfg-protos";

// Convert protobuf timestamp to Date
const timestamp = lfg.google.protobuf.Timestamp.create({
  seconds: Math.floor(Date.now() / 1000),
  nanos: 0,
});

const date = protoTimestampToDate(timestamp);
console.log("Converted date:", date);

Generated Modules Overview

This library provides auto-generated TypeScript types and message classes for all LFG protocol modules:

Core Trading Modules

  • CLOB: Central Limit Order Book message types for spot and perpetual trading
  • Perpetuals: Perpetual futures message types and parameters
  • Assets: Asset management message types and configuration
  • Prices: Price feed and market parameter message types

Account Management

  • Subaccounts: Advanced account system message types with subaccount support
  • AssetPosition: Asset position management message types
  • PerpetualPosition: Perpetual position tracking message types

DeFi Operations

  • Vault: Investment vault message types and management
  • Rewards: Rewards distribution message types and management
  • Vest: Token vesting message types
  • RevShare: Revenue sharing mechanism message types

Infrastructure

  • Bridge: Cross-chain bridge message types and operations
  • RateLimit: Rate limiting protocol message types
  • DelayMsg: Delayed message processing types
  • Stats: Protocol statistics and analytics message types

Governance

  • GovPlus: Enhanced governance message types
  • Listing: Asset listing management message types

Daemons

  • Bridge: Bridge daemon message types
  • Liquidation: Liquidation daemon message types
  • PriceFeed: Price feed daemon message types

Generated Types

All types are auto-generated from Protocol Buffers definitions:

// Example: CLOB Order message type
interface Order {
  orderId: number;
  side: Side;
  quantums: number;
  subticks: number;
  timeInForce: TimeInForce;
  reduceOnly: boolean;
  clientMetadata: number;
}

// Example: Subaccount message type
interface Subaccount {
  id?: SubaccountId;
  assetPositions: AssetPosition[];
  perpetualPositions: PerpetualPosition[];
  marginEnabled: boolean;
}

// Example: Vault message types
interface Vault {
  // Generated from protobuf definition
}

interface VaultParams {
  denom: string;
  minDepositAmount: string;
  minWithdrawalAmount: string;
  maxDepositAmount: string;
  maxWithdrawalAmount: string;
}

Dependencies

  • @bufbuild/buf: ^1.19.0-1
  • @cosmjs/amino: ^0.32.1
  • @cosmjs/proto-signing: ^0.32.1
  • @cosmjs/stargate: ^0.32.1
  • @cosmjs/tendermint-rpc: ^0.32.1
  • @osmonauts/lcd: ^0.6.0
  • bech32: ^2.0.0
  • long: ^5.2.1
  • protobufjs: ^7.5.3

Development

Building

yarn build

Testing

yarn test

Watch Mode

yarn test:watch

Cleaning

yarn clean

Clean Build

yarn build:clean

License

This project is licensed under the MIT License.

Support

For support and questions:

Code Generation

This package is auto-generated from Protocol Buffers definitions using @osmonauts/telescope. The generated code includes:

  • Message Classes: Complete TypeScript classes with create(), encode(), decode(), and fromPartial() methods
  • Type Definitions: Full TypeScript interfaces for all protobuf messages
  • RPC Clients: Query and message clients for gRPC communication
  • Enums: TypeScript enums for all protobuf enum types
  • Utility Functions: Helper functions for common operations

Regeneration

To regenerate the code from updated protobuf definitions:

# Install dependencies
yarn

# Run the code generation
yarn build

About

The LFG protocol is a comprehensive DeFi platform built on Oraichain, providing advanced trading, staking, and investment management capabilities. This TypeScript codegen library enables developers to work with all LFG protocol message types and RPC interfaces in a type-safe manner.

Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •