Vols Finance

Interaction Guides

1) First approve the Exchange contract to spend your tokens:

// Approve ETH token
await ETHContract.approve(exchangeAddress, ethers.constants.MaxUint256);

// Approve USDC token  
await USDCContract.approve(exchangeAddress, ethers.constants.MaxUint256);

2) Place Buy Order

// Place a buy order
// price: Price in USDC (6 decimals)
// amount: Amount of ETH to buy (18 decimals)
const price = ethers.utils.parseUnits("1000", 6); // 1000 USDC per ETH
const amount = ethers.utils.parseUnits("1", 18);  // Buy 1 ETH

// Place the order
await exchangeContract.newBuyOrder(price, amount);

// Place buy order for another address
await exchangeContract.newBuyOrderTo(price, amount, receiverAddress);

3) Place Sell Order

// Place a sell order
// price: Price in USDC (6 decimals)
// amount: Amount of ETH to sell (18 decimals)
const price = ethers.utils.parseUnits("1000", 6); // 1000 USDC per ETH
const amount = ethers.utils.parseUnits("1", 18);  // Sell 1 ETH

// Place the order
await exchangeContract.newSellOrder(price, amount);

// Place sell order for another address
await exchangeContract.newSellOrderTo(price, amount, receiverAddress);

4) Cancel Orders

// Cancel a buy order
await exchangeContract.deleteBuyOrder(price, orderId);

// Cancel a sell order
await exchangeContract.deleteSellOrder(price, orderId);

5) Get Active Orders

// Get your active buy orders
const buyOrders = await exchangeContract.activeBuyOrders();

// Get your active sell orders
const sellOrders = await exchangeContract.activeSellOrders();

// Get all buy orders at a specific price
const buyOrdersAtPrice = await exchangeContract.getAllBuyOrders(price);

// Get all sell orders at a specific price
const sellOrdersAtPrice = await exchangeContract.getAllSellOrders(price);

6) Get Order Book State

// Get full order book state
const [sellOB, buyOB] = await exchangeContract.getPVobs();

// Get all active orders across all prices
const [orders, prices] = await exchangeContract.getAllActiveBuyOrders();
const [sellOrders, sellPrices] = await exchangeContract.getAllActiveSellOrders();

7) Price Discovery

// Get output amount for a trade
const {outputAmount, price} = await exchangeContract.getOutputAmount(
    inputTokenAddress,
    inputAmount
);