Integration Guide
How to integrate with Yield Forge smart contracts from your own code.
Building on Yield Forge? All interactions go through a single Diamond Proxy address. You call facet functions on this address, and the Diamond routes them to the correct logic.
Getting the ABI
Since the protocol uses the Diamond Pattern, each facet has its own ABI. For convenience, we provide a unified ABI that combines all public functions from all facets into one JSON file.
You can also import individual facet ABIs from the @yield-forge/contracts package:
import { LiquidityFacetABI } from '@yield-forge/contracts/abi/LiquidityFacet'
import { YieldForgeMarketFacetABI } from '@yield-forge/contracts/abi/YieldForgeMarketFacet'
Deployment Addresses
Import deployment addresses per chain:
import deployments from '@yield-forge/contracts/deployments/42161.json' // Arbitrum
const diamondAddress = deployments.diamond
Core Interactions
Reading Pool Data
Query pool state using view functions on PoolRegistryFacet and LiquidityFacet:
function getPoolInfo(bytes32 poolId) external view returns (PoolInfo memory);
function getCurrentCycle(bytes32 poolId) external view returns (CycleInfo memory);
Swapping PT
To trade on the PT AMM, approve the Diamond to spend your tokens, then call:
// Buy PT with quote tokens
function swapQuoteForPT(
bytes32 poolId,
uint256 quoteAmount,
uint256 minPTOut
) external returns (uint256 ptOut);
// Sell PT for quote tokens
function swapPTForQuote(
bytes32 poolId,
uint256 ptAmount,
uint256 minQuoteOut
) external returns (uint256 quoteOut);
Adding Liquidity
function addLiquidity(
bytes32 poolId,
uint256 amount0,
uint256 amount1
) external returns (uint256 ptMinted, uint256 ytMinted);
YT Orders
function placeSellOrder(bytes32 poolId, uint256 ytAmount, uint256 pricePerYT) external;
function placeBuyOrder(bytes32 poolId, uint256 ytAmount, uint256 pricePerYT) external;
function fillOrder(uint256 orderId, uint256 amount) external;
function cancelOrder(uint256 orderId) external;
Pattern: Approve → Execute
All functions that transfer tokens from the user require a prior ERC-20 approve() call on the Diamond address. The typical pattern:
- Check current allowance
- If insufficient, call
approve(diamondAddress, amount) - Call the Diamond function
Events
The protocol emits events for all state changes. Key events for integrators:
| Event | When |
|---|---|
LiquidityAdded | User deposits liquidity |
YieldForgeSwap | PT is traded on the AMM |
OrderPlaced / OrderFilled | YT orderbook activity |
YieldHarvested / YieldClaimed | Yield collection |
PTRedeemed | PT is redeemed post-maturity |