🔋
Ionic Docs
  • Welcome to Ionic
  • Ionic pools
  • Yield-Bearing Vaults (ERC-4626)
  • Partner & Pool Operator Documents
    • Overview
    • Ionic For Partners
      • Long-tail and exotic asset support
      • Liquid Staking Tokens
      • Forex Markets & Non-US Centric DeFi
      • Delta-Neutral Strategies
      • AMM LP Pools
    • Advanced Features
    • Getting Started
    • Pool Customisations
      • The Markets
      • The Yield
      • Pool Parameters
  • Security
    • Security Outline
      • Oracle Security
      • Yield Bearing 4626 Strategy Risk Scoring
      • Liquidity Monitoring
    • Audit
  • Developers
    • Ionic SDK
      • Chain Configuration and Addresses
      • Data Fetching & Pool Introspection
      • Funding Operations
      • Advanced Use-Cases
      • Liquidations
      • Putting It All Together
      • API Reference, Typing & Interfaces
    • Deployed Contract Addresses
  • Support
    • Media Kit
    • DeFi Terms Glossary
    • FAQ
  • Documents
    • Privacy Policy
    • Terms and Conditions
Powered by GitBook
On this page
  • SDK instantiation
  • Pool Creation
  • Fetching Assets
  1. Developers
  2. Ionic SDK

Putting It All Together

In this guide, we'll showcase how to get the most of the SDK in a real-life project

While this guide is a work-in-progress, we have a full-fledged react-based/wagmi web-app that showcases how to make use of the SDK. You can find it here: TBA

SDK instantiation

// Context
export interface SDKContextData {
  sdk: IonicSdk;
  address: string;
  disconnect: () => void;
  currentChain: Chain & {
    unsupported?: boolean | undefined;
  };
  chains: Chain[];
}

export const SDKContext = createContext<SDKContextData | undefined>(undefined);

// Hook
export function useSDK() {
  const context = useContext(SDKContext);

  if (context === undefined) {
    throw new Error(`useSDK must be used within a SDKProvider`);
  }
  return context;
}


...

const { sdk, address, currentChain } = useSDK();

Source code

Pool Creation

  const { sdk, address, currentChain } = useSDK();
  const deployResult = await sdk.deployPool(
    poolName,
    whitelistedAddresses.length !== 0,
    bigCloseFactor,
    bigLiquidationIncentive,
    oracle,
    { reporter },
    { from: address },
    whitelistedAddresses
);

Source code

Fetching Assets

  const { sdk, address, currentChain } = useSDK();
  
  const { data: allPools } = useQuery(
    ['allPools', address, currentChain.id],
    async () => {
      return await sdk.fetchPoolsManual({
        verification: false,
        options: {
          from: address,
        },
      });
    },
    { cacheTime: Infinity, staleTime: Infinity, enabled: !!address && !!currentChain.id }
  );

Source code

PreviousLiquidationsNextAPI Reference, Typing & Interfaces

Last updated 1 year ago