LP Code Examples

TypeScript examples for LP operations and automation rules.

TypeScript — Vault + Offer Setup

const API = 'https://api.lavarage.xyz';
const headers = { 'x-lp-api-key': process.env.LP_API_KEY!, 'Content-Type': 'application/json' };

// Create vault
const { signature: vaultSig } = await fetch(API + '/api/v1/lp/tx/create-vault', {
  method: 'POST', headers,
  body: JSON.stringify({ mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', liquidationLtv: 9000 }),
}).then(r => r.json());

// Deposit 1000 USDC
const { signature: depositSig } = await fetch(API + '/api/v1/lp/tx/deposit', {
  method: 'POST', headers,
  body: JSON.stringify({ mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', amount: '1000000000' }),
}).then(r => r.json());

// Create offer
const { signature: offerSig } = await fetch(API + '/api/v1/lp/tx/create-offer', {
  method: 'POST', headers,
  body: JSON.stringify({
    mintAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
    collateralMintAddress: 'So11111111111111111111111111111111111111112',
    interestRate: 50,
    feedId: 'ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
    maxExposure: '500000000',
    openLtv: 5000,
  }),
}).then(r => r.json());

Automation Rules API

// Create rule: disable offer when mcap > $10M
const rule = await fetch(API + '/api/v1/lp/rules', {
  method: 'POST', headers,
  body: JSON.stringify({
    offerPublicKey: 'YOUR_OFFER',
    ruleType: 'MCAP_CLOSE',
    config: { mcapThreshold: 10_000_000, direction: 'above' },
  }),
}).then(r => r.json());

// List rules
const rules = await fetch(API + '/api/v1/lp/rules', { headers }).then(r => r.json());

// Toggle off
await fetch(API + '/api/v1/lp/rules/' + rule.id + '/toggle', { method: 'PATCH', headers });

// Delete
await fetch(API + '/api/v1/lp/rules/' + rule.id, { method: 'DELETE', headers });