
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



1·Take
A caller-supplied parameter named percent is declared, to be filled in at execution time.
2·Take
Another caller-supplied parameter named buy_token is declared, provided by the caller when the plug runs.
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·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·Get price
The latest Chainlink price of the buy_token in USD is read, normalized to 18 decimals.
6·Get constant
A named constant of 10,000, the basis-point denominator, is loaded for later proportional math.
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·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·Get token balance
The socket's own balance of the buy_token is read before any swap, establishing the pre-swap baseline.
10·Get address
The solver address is held as a named value to serve as the transfer destination.
11·Transfer tokens
The USDC spend amount is transferred to the solver address referenced from step 9.
12·Get solution
The solver takes the transferred USDC, routes it, and the outcome is verified.
13·Get token balance
After routing, the socket's buy_token balance is read again to capture the post-swap holding.
14·Calculate
Subtracting the pre-swap buy_token balance from the post-swap balance yields the amount actually received.
15·Get constant
A named constant WAD equal to 1e18 is loaded for 18-decimal scaling.
16·Calculate
Ten raised to the power of twelve gives the factor for twelve decimals.
17·Calculate
Multiplying the step 7 figure by the WAD constant scales it up to 18 decimals.
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·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·End block
The open block is closed here.
21·Bubble
The post-swap buy_token balance is surfaced as the output of this plug.
On other protocols · 2