Aktionariat Documentation
  • Introduction to Aktionariat
    • ⚡Quick Start
  • 🛠️APIs
    • 📊Subgraph
      • Schema
      • Query Examples
        • Platform data
        • Token Data
        • Brokerbot Data
        • Swaps Data
    • ⚙️External API
      • ⚙️External API (Gitbook)
  • 🌐Web
    • Integrate with Ethers.js
      • Brokerbot Quoter
    • Integrate Aktionariat Widgets
  • ⛓️Smart Contracts
    • 📔Contracts Overview
    • 👷‍♂️Guides
      • Implement A Trade
        • Direct Trades
        • Multihop Trades
      • Get Brokerbot Contract for Token
      • Buy Shares
      • Sell Shares
    • Technical Reference
      • Allowlist
      • Brokerbot
      • Drag-Along
      • Infinite Allowances
      • Multi-Signature Contract
      • Recovery
      • Shareholder Registry
  • 📖Reference
    • Brokerbot Architecture
    • Github
    • Whitepaper
    • Brokerbot Analytics
  • 💬Socials
    • Twitter
    • Telegram
    • LinkedIn
    • Youtube
Powered by GitBook
On this page
  • Deployment addresses
  • Get a quote with ethers v5
  • Set up
  • Getting quote for buying shares
  • Getting quote for selling shares
  • Getting quote for buying shares with USDC and a Uniswap path
  • Getting quote for selling shares for USDC and a with Uniswap path
  • Full example code

Was this helpful?

Edit on GitHub
  1. Web
  2. Integrate with Ethers.js

Brokerbot Quoter

A UniswapV3 Quoter like interface to get prices

PreviousIntegrate with Ethers.jsNextIntegrate Aktionariat Widgets

Last updated 1 year ago

Was this helpful?

Link to

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:

🌐
GitHub source code
https://github.com/aktionariat/contracts/blob/gitbook-examples/scripts/gitbook-example-quote.js