🇺🇲
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 API
  2. Swagger

Estimate Logics Result

PreviousRequest QuoteNextRequest Transaction Data

Last updated 1 year ago

Estimates of how much funds will be spent (funds) and how many balances will be obtained (balances) from this transaction. It will also identify any approvals that the user needs to execute (approvals) before the transaction and whether there is any Permit2 data that the user needs to sign before proceeding (permitData).

In the current implementation of Permit2, users have two options for authorizing to spend their assets: permit and approve. These methods provide distinct approaches to token authorization, allowing users to choose the one that best suits their needs. If not specified, permit is the default behavior.

The permit method involves obtaining authorization data (permitData) for the ERC20 tokens being spent in the router data. Users are required to sign this data. The permitData and the associated signature are then sent to the Protocolink API as part of the transaction.

The approve method provides users with the necessary transactions to approve the expenditure of ERC20 tokens in the router data. Users must complete these approval transactions before sending the router transaction.

const getEstimateResult = async (chainId, account, logics, permit2Type) => {
    const result = await client.post(
    `/v1/transactions/estimate?permit2Type=${permit2Type}`, {
        body: {
            chainId: chainId,
            account: account,
            logics: logics,
        }
    });
    return result.data;
}

const chainId = 1;
const account = USER_ADDRESS;
const logics = [swapLogic, supplyLogic];

const estimateResult = await getEstimateResult(chainId, account, logics);

The result contains a list of chains that looks the following:

{
  "funds": [
    {
      "token": {
        "chainId": 1,
        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "decimals": 6,
        "symbol": "USDC",
        "name": "USD Coin"
      },
      "amount": "1000"
    },
    ... // all other tokens will be spent
  ],
  "balances": [
    {
      "token": {
        "chainId": 1,
        "address": "0x5Ee5bf7ae06D1Be5997A1A72006FE6C607eC6DE8",
        "decimals": 8,
        "symbol": "aEthWBTC",
        "name": "Aave Ethereum WBTC"
      },
      "amount": "0.03579397"
    },
    ... // all other tokens will be obtained
  ],
  "fees": [
    {
      "rid": "permit2:pull-token",
      "feeAmount": {
        "token": {
          "chainId": 1,
          "address": "0x0000000000000000000000000000000000000000",
          "decimals": 18,
          "symbol": "ETH",
          "name": "Ethereum"
        },
        "amount": "0.001240475451939898"
      }
    },
    ... // all other fees will be charged
  ],
  "approvals": [
    {
      "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "data": "0x095ea7b3000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
    },
    ... // all other needs to execute (approvals) before the transaction
  ],
  "permitData": {
    "domain": {
      "name": "Permit2",
      "chainId": 1,
      "verifyingContract": "0x000000000022D473030F116dDEE9F6B43aC78BA3"
    },
    "types": {
      "PermitSingle": [
        {
          "name": "details",
          "type": "PermitDetails"
        },
        {
          "name": "spender",
          "type": "address"
        },
        {
          "name": "sigDeadline",
          "type": "uint256"
        }
      ],
      "PermitDetails": [
        {
          "name": "token",
          "type": "address"
        },
        {
          "name": "amount",
          "type": "uint160"
        },
        {
          "name": "expiration",
          "type": "uint48"
        },
        {
          "name": "nonce",
          "type": "uint48"
        }
      ]
    },
    "values": {
      "details": {
        "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "amount": "0xffffffffffffffffffffffffffffffffffffffff",
        "expiration": 1683990224,
        "nonce": 0
      },
      "spender": "0x9E2A2394C69874545C013492d52d1DC0c607b208",
      "sigDeadline": 1681400024
    }
  }
}

Funds (Initial Funds)

This denotes the amount of initial funds required in the logic combination. For instance, if the subsequent logic generates tokens from the previous logic, then the user need not transfer them again, and thus they are not counted in the total.

Balances (You will receive)

This is a projection of the amount of money that will be refunded to your wallet upon completion of the transaction, which can be conveniently displayed to the user.

Fees

Approvals

After the current estimation, there are transactions that necessitate user authorization, such as when a user uses Permit2 or borrows delegation for the first time.

PermitData

The first time the token is approved for Protocolink by Permit2, the user's signature is required. The default validity period of the signature is 30 minutes, and the expiration time of the Token permit is 30 days.

Protocolink will calculate fees based on the logics included in the transaction, which can be conveniently displayed to the user. You can refer to our section for a list of logics that may incur fees.

📗
Fees
  • POSTGet the estimated results along with the necessary approval data for signing
  • Funds (Initial Funds)
  • Balances (You will receive)
  • Fees
  • Approvals
  • PermitData
Agent

Get the estimated results along with the necessary approval data for signing

post
Query parameters
permit2TypestringOptional

permit2 approaches to token authorization. Example: permit(default) or approve

Example: permit
Body
chainIdintegerRequiredExample: 42161
accountstringRequiredExample: 0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB
Responses
200
OK
application/json
post
POST /v1/transactions/estimate HTTP/1.1
Host: api.protocolink.com
Content-Type: application/json
Accept: */*
Content-Length: 631

{
  "chainId": 42161,
  "account": "0xa3C1C91403F0026b9dd086882aDbC8Cdbc3b3cfB",
  "logics": [
    {
      "rid": "uniswap-v3:swap-token",
      "fields": {
        "tradeType": "exactIn",
        "input": {
          "token": {
            "chainId": 42161,
            "address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
            "decimals": 6,
            "symbol": "USDC",
            "name": "USDCoin"
          },
          "amount": "1000"
        },
        "output": {
          "token": {
            "chainId": 42161,
            "address": "0x0000000000000000000000000000000000000000",
            "decimals": 18,
            "symbol": "ETH",
            "name": "Ethereum"
          },
          "amount": "0.532050407772720708"
        },
        "path": "0xaf88d065e77c8cc2239327c5edb3a432268e5831000064fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9000bb882af49447d8a07e3bd95bd0d56f35241523fbab1",
        "slippage": 100
      }
    }
  ]
}
200

OK

{
  "funds": [
    {
      "token": {
        "chainId": 42161,
        "address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
        "decimals": 6,
        "symbol": "USDC",
        "name": "USDCoin"
      },
      "amount": "1000"
    }
  ],
  "balances": [
    {
      "token": {
        "chainId": 42161,
        "address": "0x0000000000000000000000000000000000000000",
        "decimals": 18,
        "symbol": "ETH",
        "name": "Ethereum"
      },
      "amount": "0.532050407772720708"
    }
  ],
  "approvals": [
    {
      "to": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
      "data": "0x095ea7b3000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
    }
  ],
  "permitData": {
    "domain": {
      "name": "Permit2",
      "chainId": 42161,
      "verifyingContract": "0x000000000022D473030F116dDEE9F6B43aC78BA3"
    },
    "types": {
      "PermitSingle": [
        {
          "name": "details",
          "type": "PermitDetails"
        },
        {
          "name": "spender",
          "type": "address"
        },
        {
          "name": "sigDeadline",
          "type": "uint256"
        }
      ],
      "PermitDetails": [
        {
          "name": "token",
          "type": "address"
        },
        {
          "name": "amount",
          "type": "uint160"
        },
        {
          "name": "expiration",
          "type": "uint48"
        },
        {
          "name": "nonce",
          "type": "uint48"
        }
      ]
    },
    "values": {
      "details": {
        "token": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
        "amount": "0xffffffffffffffffffffffffffffffffffffffff",
        "expiration": 1691892575,
        "nonce": 0
      },
      "spender": "0x2C0e22b8d5070cb2500628E0bf43925a5c7b1559",
      "sigDeadline": 1689302375
    }
  }
}