Set stored value
Set stored value

Database · Acts onchain

Writes a value to the socket's persistent storage under a scope and key. Scope chooses socket storage, shared across every plug the socket runs, or plug storage, private to this plug bundle. The value persists across transactions until overwritten; writing zero deletes it. Read it back with the read stored value action using the same scope and key. Reach for it to persist anything a later run needs: a running total, the timestamp of the last rebalance, a cap consumed so far.

Loop at Target HF + Trailing Stop Loss

database
boolean
aave
67actions
  1. 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. 2·Compare two values

    Here the plug compares a value against 1 using an equality operator, producing a boolean about that comparison.

  3. 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. 4·Get asset data

    Live reserve data for WETH on Ethereum is read from Aave, exposing its rates and token addresses.

  5. 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. 6·Set

    The measured aWETH balance is stored under aWETH_supply_balance for later reference.

  7. 7·Get price

    Oracle price for the WETH token in the same market is read.

  8. 8·Get account data

    Overall account data in the market is read, giving collateral, debt, borrow capacity, and health factor.

  9. 9·Get liquidation LTV

    Liquidation LTV for WETH in the Ethereum market is read.

  10. 10·Read stored value

    The stored last_peak_price is pulled from plug storage.

  11. 11·Compare two values

    This compares aWETH_supply_balance against 0 for equality, returning a boolean.

  12. 12·Set

    That equality result is captured as is_aWETH_supply_balance_0.

  13. 13·Compare two values

    A comparison checks whether the value in slot 9.0 equals 0, producing a boolean.

  14. 14·Set

    The result is saved as is_last_peak_price_0.

  15. 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. 16·Set

    That test is stored as is_price_above_last_peak_price.

  17. 17·Calculate

    Arithmetic multiplies the value in slot 9.0 by 0.10, giving ten percent of the last peak price.

  18. 18·Set

    The product is held as stop_distance_from_last_peak_price.

  19. 19·Calculate

    Subtracting stop_distance_from_last_peak_price from the value in slot 9.0 yields the trailing stop level.

  20. 20·Set

    That difference is stored as stop_price.

  21. 21·Compare two values

    Here the price in slot 6.4 is checked against stop_price with a less than or equal operator.

  22. 22·Set

    The outcome is saved as is_price_at_or_below_stop_price.

  23. 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. 24·Set

    That figure is stored as max_debt_before_liquidation.

  25. 25·Calculate

    Dividing max_debt_before_liquidation by 1.5 sets the target debt with a buffer under the ceiling.

  26. 26·Set

    The quotient is held as target_debt.

  27. 27·Compare two values

    This compares current debt in slot 7.1.1 against target_debt for inequality.

  28. 28·Set

    The inequality result is stored as is_debt_not_equal_to_target_debt.

  29. 29·Compare two values

    An or combines is_aWETH_supply_balance_0 with is_price_at_or_below_stop_price.

  30. 30·Compare two values

    Another or combines is_price_above_last_peak_price with the debt inequality result from slot 27.

  31. 31·Compare two values

    A final or joins slot 28 with slot 29, folding all trigger conditions together.

  32. 32·Set

    That combined trigger is saved as is_supply_peak_update_rebalance_or_stop_needed.

  33. 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. 34·Predicate

    An if opens on is_aWETH_supply_balance_0 being true, branching for the case of no existing supply.

  35. 35·Supply

    Inside that branch, 5 of the WETH token is supplied to the market to seed the position.

  36. 36·End block

    The branch closes here.

  37. 37·Predicate

    An if opens on is_last_peak_price_zero being true.

  38. 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. 39·End block

    That branch closes.

  40. 40·Predicate

    An if opens on is_price_above_last_peak_price being true.

  41. 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. 42·End block

    This closes the peak update branch.

  43. 43·Predicate

    An if opens on is_price_at_or_below_stop_price being true, the trailing stop trigger.

  44. 44·Set stored value

    Hitting the stop writes 1 to the exited_loop key, marking the position as closed out.

  45. 45·Get asset data

    USDC reserve data on the Ethereum market is read to reach its debt token.

  46. 46·Get token balance

    Using the token address from slot 44.1.10, the balance held by 0x4844...3a88 is read.

  47. 47·Set

    That measured amount is stored as vUSDC_debt_balance.

  48. 48·Repay

    The full vUSDC_debt_balance of USDC is repaid to the market, clearing the borrow.

  49. 49·Withdraw

    The entire aWETH_supply_balance of WETH collateral is withdrawn from the market, unwinding the position.

  50. 50·Else branch

    An else opens for the case where the stop was not hit.

  51. 51·Compare two values

    This compares current debt in slot 7.1.1 against target_debt with a greater than operator.

  52. 52·Predicate

    An if opens on that comparison being true, meaning debt sits above target.

  53. 53·Calculate

    Subtracting target_debt from current debt in slot 7.1.1 gives the excess to repay.

  54. 54·Set

    The result is held as repay_amount.

  55. 55·Calculate

    Dividing repay_amount by the price in slot 6.4 converts the repay amount into collateral units.

  56. 56·Set

    That quotient is stored as withdraw_amount.

  57. 57·Repay

    The repay_amount of USDC is repaid to the market.

  58. 58·Withdraw

    The withdraw_amount of WETH collateral is withdrawn from the market, deleveraging toward target.

  59. 59·Else branch

    An else opens for the case where debt is at or below target.

  60. 60·Calculate

    Subtracting current debt in slot 7.1.1 from target_debt gives the shortfall to add.

  61. 61·Set

    That difference is stored as borrow_amount.

  62. 62·Calculate

    Dividing borrow_amount by the price in slot 6.4 converts it into collateral units.

  63. 63·Set

    The quotient is held as supply_amount.

  64. 64·Supply

    The supply_amount of WETH collateral is supplied to the market.

  65. 65·Borrow

    The borrow_amount of USDC is borrowed from the market against the fresh collateral, levering up toward target.

  66. 66·End block

    This closes the inner debt branch.

  67. 67·End block

    The outer stop versus rebalance branch closes here.

Read stored value of in
Is
Get asset data of in
Get balance of held by
Set to
Get price of in
Get account data in
Get liquidation LTV of in
Read stored value of in
Is
Set to
Is
Set to
Is
Set to
Calculate
Set to
Calculate
Set to
Is
Set to
Calculate of
Set to
Calculate
Set to
Is
Set to
Is
Is
Is
Set to
Supply to
End block
Set stored value of in to
End block
Set stored value of in to
End block
Set stored value of in to
Get asset data of in
Get balance of held by
Set to
Repay to
Withdraw from
Else
Is
Calculate
Set to
Calculate
Set to
Repay to
Withdraw from
Else
Calculate
Set to
Calculate
Set to
Supply to
Borrow from
End block
End block
  • 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
  • Trailing Stop Loss (WETH/USDC Loop)

    boolean
    aave
    evm