🇺🇲
Protocolink
  • 🔮Overview
  • 🌟Why Protocolink?
  • 💡Use Cases
    • Flash Loans
    • Permit2 Amplifier
    • Zap-in & Zap-out
    • Position Management
    • Multi-Action Bundling
  • 📋Networks & Protocols
  • 🛡️Security & Audits
  • 💎Fees
  • ❓FAQ
  • Protocolink API
    • 🔮Overview
      • Swap & Supply (Example)
    • 📗Swagger
      • Request Protocols
      • Request Tokens
      • Request Quote
      • Estimate Logics Result
      • Request Transaction Data
  • Protocolink SDK
    • 🔮Overview
    • 1️⃣Install SDK
    • 2️⃣Build Logics
    • 3️⃣Estimate Router Data
    • 4️⃣Send Router Transaction
    • ⚒️API SDK Interfaces
      • Global Types
      • FlashLoan Logic
      • Aave V2
      • Aave V3
      • Balancer V2
      • Compound V3
      • Iolend
      • Magicsea
      • Morphoblue
      • OpenOcean V2
      • ParaSwap V5
      • Permit2
      • Spark
      • Stargate
      • Stargate V2
      • SyncSwap
      • Uniswap V3
      • Utility
      • Wagmi
      • ZeroEx V4
    • ⚒️Common SDK Interfaces
      • Constants
      • Network
      • Token
      • Web3Toolkit
      • Utility Functions
  • Lending SDK
    • 🔮Overview
    • ✳️SDK
      • Open By Collateral
      • Open By Debt
      • Close
      • Leverage By Collateral
      • Leverage By Debt
      • Deleverage
      • Collateral swap
      • Debt swap
      • Zap supply
      • Zap withdraw
      • Zap repay
      • Zap borrow
  • Smart Contract
    • 🔮Overview
      • Router
      • Agent
      • Callback
      • Fees
      • Utility
      • Data Type
      • ERC721/ERC1155 Support
    • 📑Deployment Addresses
    • 🧑‍💻Security Review Details
  • COMPOUND KIT
    • 🔮Overview
    • ✳️SDK
      • Leverage
      • Deleverage
      • Collateral Swap
      • Zap Supply
      • Zap Withdraw
      • Zap Repay
      • Zap Borrow
    • 📗API
  • Video Tutorials
    • 1. Introducing Protocolink
    • 2. Lending SDK
    • 3. Protocolink Q&A
  • Social medias
    • Twitter
  • Support
Powered by GitBook
On this page
  1. Protocolink SDK
  2. Common SDK Interfaces

Utility Functions

This section contains utility functions that can be used to perform various common operations in dApp development.

  • toSmallUnit: Converts an amount in decimal units to an amount in the smallest unit of a token, given the number of decimal places. Returns a BigNumber.

  • toBigUnit:

    • Converts an amount in the smallest unit of a token to an amount in decimal units, given the number of decimal places. Returns a string.

    • options (optional) is an object that can contain the following properties:

      • displayDecimals (optional): number of decimal places to include in the output string (default is the given decimals).

      • mode (optional): rounding mode to use ('ceil', 'round', or 'floor', default is 'floor').

  • formatBigUnit:

    • Used to convert a big unit amount into a format based on the specified displayDecimals.

    • mode (optional): rounding mode to use ('ceil', 'round', or 'floor', default is 'round').

  • calcSlippage: Calculates the maximum amount of slippage, given an amount and a slippage percentage. base (optional) is the base number used to calculate slippage (default is 10000).

  • calcFee: Calculates the amount of a fee, given an amount and a premium percentage. base (optional) is the base number used to calculate slippage (default is 10000).

  • calcBps: Calculates the amount of an asset as a basis point of the total balance.

  • reverseAmountWithFee: Used to reverse-calculate the original amount before the deduction of a fee from a given amount that includes the fee.

  • shortenAddress: Shortens an address to a specified number of digits (default is 4).

  • shortenTransactionHash: Shortens an transaction hash to a specified number of digits (default is 4).

PreviousWeb3ToolkitNextOverview

Last updated 1 year ago

⚒️