
Database · Acts onchain
Reads a stored value from the socket's persistent storage by key. Scope chooses socket storage, shared by every plug the socket runs, or plug storage, private to this plug bundle. The value is whatever a set stored under the key, returned as the committed value. Reach for it to carry state between executions, such as the last execution price, a running total, or a cursor, and feed it into a comparison or calculation in the next step.
Loop at Target HF + Trailing Stop Loss



1·Read stored value
This reads the stored exited_loop flag from plug storage, pulling the marker that tracks whether the loop has already been closed out.
2·Compare two values
Here the plug compares a value against 1 using an equality operator, producing a boolean about that comparison.
3·Predicate
A require gate enforces that the value in slot 1.0 equals 0 (false), so execution halts unless exited_loop has not been tripped.
4·Get asset data
Live reserve data for WETH on Ethereum is read from Aave, exposing its rates and token addresses.
5·Get token balance
Using the token address surfaced by the reserve read at slot 3.1.8, this fetches the balance held by 0x4844...3a88.
6·Set
The measured aWETH balance is stored under aWETH_supply_balance for later reference.
7·Get price
Oracle price for the WETH token in the same market is read.
8·Get account data
Overall account data in the market is read, giving collateral, debt, borrow capacity, and health factor.
9·Get liquidation LTV
Liquidation LTV for WETH in the Ethereum market is read.
10·Read stored value
The stored last_peak_price is pulled from plug storage.
11·Compare two values
This compares aWETH_supply_balance against 0 for equality, returning a boolean.
12·Set
That equality result is captured as is_aWETH_supply_balance_0.
13·Compare two values
A comparison checks whether the value in slot 9.0 equals 0, producing a boolean.
14·Set
The result is saved as is_last_peak_price_0.
15·Compare two values
This tests whether the price in slot 6.4 is greater than the value in slot 9.0, the last peak price.
16·Set
That test is stored as is_price_above_last_peak_price.
17·Calculate
Arithmetic multiplies the value in slot 9.0 by 0.10, giving ten percent of the last peak price.
18·Set
The product is held as stop_distance_from_last_peak_price.
19·Calculate
Subtracting stop_distance_from_last_peak_price from the value in slot 9.0 yields the trailing stop level.
20·Set
That difference is stored as stop_price.
21·Compare two values
Here the price in slot 6.4 is checked against stop_price with a less than or equal operator.
22·Set
The outcome is saved as is_price_at_or_below_stop_price.
23·Calculate proportional value
A proportional calculation takes the value in slot 8.2 in basis points of the value in slot 7.1.0, deriving the debt ceiling before liquidation.
24·Set
That figure is stored as max_debt_before_liquidation.
25·Calculate
Dividing max_debt_before_liquidation by 1.5 sets the target debt with a buffer under the ceiling.
26·Set
The quotient is held as target_debt.
27·Compare two values
This compares current debt in slot 7.1.1 against target_debt for inequality.
28·Set
The inequality result is stored as is_debt_not_equal_to_target_debt.
29·Compare two values
An or combines is_aWETH_supply_balance_0 with is_price_at_or_below_stop_price.
30·Compare two values
Another or combines is_price_above_last_peak_price with the debt inequality result from slot 27.
31·Compare two values
A final or joins slot 28 with slot 29, folding all trigger conditions together.
32·Set
That combined trigger is saved as is_supply_peak_update_rebalance_or_stop_needed.
33·Predicate
A require enforces that the combined trigger from slot 31 equals 1 (true), so the plug proceeds only when at least one condition holds.
34·Predicate
An if opens on is_aWETH_supply_balance_0 being true, branching for the case of no existing supply.
35·Supply
Inside that branch, 5 of the WETH token is supplied to the market to seed the position.
36·End block
The branch closes here.
37·Predicate
An if opens on is_last_peak_price_zero being true.
38·Set stored value
When true, the stored last_peak_price key is written with the current price in slot 6.4, initializing the peak.
39·End block
That branch closes.
40·Predicate
An if opens on is_price_above_last_peak_price being true.
41·Set stored value
When the price has made a new high, the stored peak key is updated to the price in slot 6.4.
42·End block
This closes the peak update branch.
43·Predicate
An if opens on is_price_at_or_below_stop_price being true, the trailing stop trigger.
44·Set stored value
Hitting the stop writes 1 to the exited_loop key, marking the position as closed out.
45·Get asset data
USDC reserve data on the Ethereum market is read to reach its debt token.
46·Get token balance
Using the token address from slot 44.1.10, the balance held by 0x4844...3a88 is read.
47·Set
That measured amount is stored as vUSDC_debt_balance.
48·Repay
The full vUSDC_debt_balance of USDC is repaid to the market, clearing the borrow.
49·Withdraw
The entire aWETH_supply_balance of WETH collateral is withdrawn from the market, unwinding the position.
50·Else branch
An else opens for the case where the stop was not hit.
51·Compare two values
This compares current debt in slot 7.1.1 against target_debt with a greater than operator.
52·Predicate
An if opens on that comparison being true, meaning debt sits above target.
53·Calculate
Subtracting target_debt from current debt in slot 7.1.1 gives the excess to repay.
54·Set
The result is held as repay_amount.
55·Calculate
Dividing repay_amount by the price in slot 6.4 converts the repay amount into collateral units.
56·Set
That quotient is stored as withdraw_amount.
57·Repay
The repay_amount of USDC is repaid to the market.
58·Withdraw
The withdraw_amount of WETH collateral is withdrawn from the market, deleveraging toward target.
59·Else branch
An else opens for the case where debt is at or below target.
60·Calculate
Subtracting current debt in slot 7.1.1 from target_debt gives the shortfall to add.
61·Set
That difference is stored as borrow_amount.
62·Calculate
Dividing borrow_amount by the price in slot 6.4 converts it into collateral units.
63·Set
The quotient is held as supply_amount.
64·Supply
The supply_amount of WETH collateral is supplied to the market.
65·Borrow
The borrow_amount of USDC is borrowed from the market against the fresh collateral, levering up toward target.
66·End block
This closes the inner debt branch.
67·End block
The outer stop versus rebalance branch closes here.
On other protocols · 1