Get token balance
Get token balance

Ethereum Virtual Machine · Reads onchain state

Reads a token balance held by an address, native or ERC-20. The native token address routes to the holder's ETH balance; any other address calls the token's balanceOf. The result carries the token's decimals. Reach for it to size an amount at what is actually held, to require a minimum balance before a step runs, or to measure a balance before and after a solver's route so a predicate confirms the outcome.

Card: Buy an 18 Dec Token With X% of USDC

plug
evm
math
21actions
  1. 1·Take

    A caller-supplied parameter named percent is declared, to be filled in at execution time.

  2. 2·Take

    Another caller-supplied parameter named buy_token is declared, provided by the caller when the plug runs.

  3. 3·Get token balance

    The socket's own USDC balance is read, giving the amount of USDC held by this address before anything else happens.

  4. 4·Calculate proportional value

    A proportion is computed: the percent from step 0 applied to the USDC balance just read, yielding the portion of the balance to spend.

  5. 5·Get price

    The latest Chainlink price of the buy_token in USD is read, normalized to 18 decimals.

  6. 6·Get constant

    A named constant of 10,000, the basis-point denominator, is loaded for later proportional math.

  7. 7·Calculate

    Subtracting fifty from the basis-point denominator produces a value of 10,000 minus fifty, which is then used as a scaled figure downstream.

  8. 8·Calculate proportional value

    Taking 10,000 basis points of the spend amount returns the whole of it, since that equals one hundred percent, restating the USDC to spend.

  9. 9·Get token balance

    The socket's own balance of the buy_token is read before any swap, establishing the pre-swap baseline.

  10. 10·Get address

    The solver address is held as a named value to serve as the transfer destination.

  11. 11·Transfer tokens

    The USDC spend amount is transferred to the solver address referenced from step 9.

  12. 12·Get solution

    The solver takes the transferred USDC, routes it, and the outcome is verified.

  13. 13·Get token balance

    After routing, the socket's buy_token balance is read again to capture the post-swap holding.

  14. 14·Calculate

    Subtracting the pre-swap buy_token balance from the post-swap balance yields the amount actually received.

  15. 15·Get constant

    A named constant WAD equal to 1e18 is loaded for 18-decimal scaling.

  16. 16·Calculate

    Ten raised to the power of twelve gives the factor for twelve decimals.

  17. 17·Calculate

    Multiplying the step 7 figure by the WAD constant scales it up to 18 decimals.

  18. 18·Multiply then divide

    Multiplying the twelve-decimal factor by the received-difference and dividing by the value from slot 4.7, rounding down, computes a scaled expected amount.

  19. 19·Predicate

    A requirement enforces that the post-swap buy_token balance is greater than or equal to the expected amount from step 17, reverting otherwise.

  20. 20·End block

    The open block is closed here.

  21. 21·Bubble

    The post-swap buy_token balance is surfaced as the output of this plug.

Take
Take
Get balance of held by
Calculate of
Get price of in
Get constant
Calculate
Calculate of
Get balance of held by
Get
Transfer to
Get solution
Get balance of held by
Calculate
Get constant
Calculate
Calculate
Calculate times divided by rounded
End block
Bubble
  • Card: Buy $50 WBTC With USDC Once a Week

    time
    values
    math
  • Card: Buy an 18 Dec Token With X% of USDC

    plug
    evm
    math
  • Card: Sell X% of an 18 Dec Token for USDC

    plug
    evm
    math
  • Card: Sell 18 Dec Token for USDC

    plug
    chainlink
    math
  • Card: Sell 8 Dec Token for USDC

    plug
    chainlink
    math
  • Card: Buy 8 Dec Token With USDC

    plug
    chainlink
    values
  • Card: Buy 18 Dec Token With USDC

    plug
    chainlink
    values
  • Card: Sell 10% of ETH for USDC

    evm
    math
    chainlink
  • Card: Buy ETH With 10% of USDC

    evm
    math
    chainlink
  • Card: Sell $25 ETH for USDC

    values
    math
    chainlink
  • Card: Buy $25 ETH With USDC

    values
    math
    chainlink
  • Rebalance Holdings to Target

    plug
    values
    evm
  • Get Holding Value

    plug
    evm
    math
  • Swap at Floor

    plug
    evm
    values
  • Swap

    plug
    values
    evm
  • Exit Morpho at Epoch End

    pendle
    time
    boolean
  • Aave: Wind or Unwind Position

    plug
    boolean
    aave
  • Wind

    plug
    aave
    evm
  • Unwind

    plug
    aave
    evm
  • Supply if a Token Balance Is 0

    plug
    aave
    evm
  • Strategy: Loop WETH/USDC at Target HF + Stop Loss

    boolean
    aave
    evm
  • Supply Idle Balance Weekly

    time
    evm
    boolean
  • Borrow + Weekly Repayments

    time
    aave
    evm
  • Borrow Rate Exit Guard (WETH/USDC Loop)

    boolean
    aave
    evm
  • Loop WETH/USDC at Target HF

    aave
    evm
    boolean
  • Swarm: Loop WETH/USDC at Target HF

    boolean
    aave
    evm
  • Loop at Target HF + Trailing Stop Loss

    database
    boolean
    aave
  • Borrow + Term Repayment Schedule

    time
    database
    boolean
  • Loop at Target HF + Borrow Rate Exit Guard

    database
    boolean
    aave
  • Stop Loss (WETH/USDC Loop)

    boolean
    aave
    evm
  • Take Profit (WETH/USDC Loop)

    boolean
    aave
    evm
  • Trailing Stop Loss (WETH/USDC Loop)

    boolean
    aave
    evm
  • Loop at Target HF + Borrow Rate Entry & Exit Guard

    aave
    boolean
    evm

On other protocols · 2