Brokerbot Quoter

A UniswapV3 Quoter like interface to get prices

Link to GitHub source code

Deployment addresses

Network
Address

Ethereum

0x726359d8560aCd175C71a33Edd502B0724A52d80

Get a quote with ethers v5

Set up

import { ethers } from "ethers";

const baseCurrencyAddress = "0xb4272071ecadd69d933adcd19ca99fe80664fc08";
const shareAddress = "0x6f38e0f1a73c96cb3f42598613ea3474f09cb200";

const brokerbotQuoterAddress = "0xcB3e482df38d62E73A7aE0E15a2605caDcc5aE98";
const brokerbotQuoterABI = [
  "function quoteExactOutputSingle(address tokenIn, address tokenOut, uint24 /*fee*/, uint256 amountOut, uint160 /*sqrtPriceLimitX96*/) view returns (uint256 amountIn)",
  "function quoteExactInputSingle(address tokenIn, address tokenOut, uint24, amountIn, uint160) view returns (uint256 amountOut)"
  ];

const amountOfShares = 100;

async function main() {
  // get a RPC provider
  const ethersProvider = new ethers.providers.InfuraProvider();
  // get a signer
  const wallet = ethers.Wallet.createRandom().connect(ethersProvider);
  // get contract instances
  const quoterContract = new ethers.Contract(brokerbotQuoterAddress, brokerbotQuoterABI, wallet);
 ///.... include here the example calls 
 
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
});  

Getting quote for buying shares

  const quoteBuy = await quoterContract.quoteExactOutputSingle(baseCurrencyAddress, shareAddress, 0, 100, 0);
  console.log(`Quote for buying 100 shares: ${ethers.utils.formatUnits(quoteBuy, 18)} XCHF`);

Getting quote for selling shares

  const quoteSell = await quoterContract.quoteExactInputSingle(shareAddress, baseCurrencyAddress, 0, 100, 0);
  console.log(`Quote for selling 100 shares: ${ethers.utils.formatUnits(quoteSell, 18)} XCHF`);Some code

Getting quote for buying shares with USDC and a Uniswap path

  const types = ["address", "uint24","address","uint24","address","uint24","address"];
  const values = [daksAdr, 0, config.baseCurrencyAddress, 100, dchfAdr, 500, config.usdcAddress];
  const path = ethers.utils.solidityPack(types,values);
  const quoteBuyUsdc = await quoterContract.callStatic["quoteExactOutput(bytes,uint256)"](path, 10);
  console.log(`Quote for buying 10 DAKS shares: ${ethers.utils.formatUnits(quoteBuyUsdc, 6)} USDC`);

Getting quote for selling shares for USDC and a with Uniswap path

  const quoteSellUsdc = await quoterContract.callStatic["quoteExactInput(bytes,uint256)"](path, 10);
  console.log(`Quote for selling 10 DAKS shares: ${ethers.utils.formatUnits(quoteSellUsdc, 6)} USDC`);

Full example code

You can find the example code here: https://github.com/aktionariat/contracts/blob/gitbook-examples/scripts/gitbook-example-quote.js

Last updated