Repository navigation
feat(studio): play a scenario with a paused or a running clock #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6db89f0
f165aee
c3467d2
bd44da9
b711966
d85dc17
c0ad325
4de56c0
b81f5ba
dec49c8
3f7983a
f03987e
2a6185b
39e45df
b794d00
bdf952d
392beda
e3959c1
08a7c87
396ac1a
2edaa03
e216e1d
2520905
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { Switch } from '@surfpool/ui'; | ||
|
|
||
| interface FetchBeforeUseSwitchProps { | ||
| checked: boolean; | ||
| onChange: (checked: boolean) => void; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| export default function FetchBeforeUseSwitch({ checked, onChange, disabled }: FetchBeforeUseSwitchProps) { | ||
| // DERIVED STATE | ||
| const hint = checked | ||
| ? 'Play fetches each account from the upstream datasource before changing it.' | ||
| : 'Play changes each account as it is in the local VM, so state prepared there is kept. An account that is not there is skipped.'; | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="flex items-center justify-between"> | ||
| <span className="text-sm font-medium text-zinc-300">Fetch before use</span> | ||
| <Switch | ||
| aria-label="Fetch before use" | ||
| checked={checked} | ||
| onChange={onChange} | ||
| disabled={disabled} | ||
| color="purple" | ||
| /> | ||
| </div> | ||
| <p className="mt-1.5 text-xs text-zinc-500">{hint}</p> | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import { | |
| ListboxOption, | ||
| } from '@surfpool/ui'; | ||
| import { useEffect, useState, type ChangeEvent, type FormEvent } from 'react'; | ||
| import FetchBeforeUseSwitch from './fetch-before-use-switch'; | ||
| import { findOptionByTypedValue } from './token-selector-options'; | ||
|
|
||
| const PhoenixStateMode = { | ||
|
|
@@ -228,6 +229,7 @@ export default function PhoenixStateDialog({ open, studioUrl, rpcUrl, onClose, o | |
| const [depth, setDepth] = useState<LiquidationDepth>(LiquidationDepth.OneLiquidation); | ||
| const [movePercent, setMovePercent] = useState('2'); | ||
| const [unit, setUnit] = useState<PhoenixUnit>('percent'); | ||
| const [fetchBeforeUse, setFetchBeforeUse] = useState(false); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defaults to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defaults to |
||
| const [error, setError] = useState<string | null>(null); | ||
| const [isCreating, setIsCreating] = useState(false); | ||
| const [marketOptions, setMarketOptions] = useState<DynamicRefOption[]>([]); | ||
|
|
@@ -317,7 +319,7 @@ export default function PhoenixStateDialog({ open, studioUrl, rpcUrl, onClose, o | |
| if (unhealthy.length) { | ||
| throw new Error(`${unhealthy.map((plan) => plan.trader).join(', ')} would not stay healthy until the move.`); | ||
| } | ||
| return createPhoenixCollateralLiquidationScenario(studioUrl, prepared, moves); | ||
| return createPhoenixCollateralLiquidationScenario(studioUrl, prepared, moves, fetchBeforeUse); | ||
| }; | ||
|
|
||
| // HANDLERS | ||
|
|
@@ -385,12 +387,12 @@ export default function PhoenixStateDialog({ open, studioUrl, rpcUrl, onClose, o | |
| try { | ||
| const result = | ||
| mode === PhoenixStateMode.MarketMove | ||
| ? await createPhoenixMarketMoveScenario(studioUrl, marketSymbol, rawAmount) | ||
| ? await createPhoenixMarketMoveScenario(studioUrl, marketSymbol, rawAmount, fetchBeforeUse) | ||
| : mode === PhoenixStateMode.OraclePrice | ||
| ? await createPhoenixOraclePriceScenario(studioUrl, marketSymbol, rawAmount) | ||
| ? await createPhoenixOraclePriceScenario(studioUrl, marketSymbol, rawAmount, fetchBeforeUse) | ||
| : isCollateralLiquidation | ||
| ? await createCollateralLiquidationScenario() | ||
| : await createPhoenixMaintenanceMarginScenario(studioUrl, marketSymbol, rawAmount); | ||
| : await createPhoenixMaintenanceMarginScenario(studioUrl, marketSymbol, rawAmount, fetchBeforeUse); | ||
| onCreated(result.id); | ||
| } catch (requestError) { | ||
| setError(requestError instanceof Error ? requestError.message : 'Failed to create Phoenix state scenario'); | ||
|
|
@@ -538,6 +540,7 @@ export default function PhoenixStateDialog({ open, studioUrl, rpcUrl, onClose, o | |
| </div> | ||
| )} | ||
| {amountField} | ||
| <FetchBeforeUseSwitch checked={fetchBeforeUse} onChange={setFetchBeforeUse} disabled={isCreating} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR body says Phoenix collateral hides this switch and that a test covers it. Here the switch renders in every mode, and its value goes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The switch now shows in every mode, including collateral liquidation, and its value reaches The comment in |
||
| {!!error && <p className="text-sm text-red-400">{error}</p>} | ||
| </div> | ||
| <DialogActions> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import { createPumpSwapPriceShockScenario } from '@/lib/scenarios-api'; | ||
| import { Button, Dialog, DialogActions, DialogDescription, DialogTitle, Input } from '@surfpool/ui'; | ||
| import { type ChangeEvent, type FormEvent, useState } from 'react'; | ||
| import FetchBeforeUseSwitch from './fetch-before-use-switch'; | ||
|
|
||
| interface PumpSwapPriceShockDialogProps { | ||
| open: boolean; | ||
|
|
@@ -20,6 +21,7 @@ export default function PumpSwapPriceShockDialog({ | |
| // STATE | ||
| const [tokenMint, setTokenMint] = useState(''); | ||
| const [virtualQuoteReserves, setVirtualQuoteReserves] = useState(''); | ||
| const [fetchBeforeUse, setFetchBeforeUse] = useState(true); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a successful create, the dialog resets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a successful create, |
||
| const [error, setError] = useState<string | null>(null); | ||
| const [isCreating, setIsCreating] = useState(false); | ||
|
|
||
|
|
@@ -53,7 +55,7 @@ export default function PumpSwapPriceShockDialog({ | |
| setError(null); | ||
|
|
||
| try { | ||
| const result = await createPumpSwapPriceShockScenario(studioUrl, tokenMint, normalizedReserves); | ||
| const result = await createPumpSwapPriceShockScenario(studioUrl, tokenMint, normalizedReserves, fetchBeforeUse); | ||
| setTokenMint(''); | ||
| setVirtualQuoteReserves(''); | ||
| onCreated(result.id); | ||
|
|
@@ -101,6 +103,7 @@ export default function PumpSwapPriceShockDialog({ | |
| Raw WSOL units written to the pool's virtual quote reserves. | ||
| </p> | ||
| </div> | ||
| <FetchBeforeUseSwitch checked={fetchBeforeUse} onChange={setFetchBeforeUse} disabled={isCreating} /> | ||
| {!!error && <p className="text-sm text-red-400">{error}</p>} | ||
| </div> | ||
| <DialogActions> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Phoenix, turning this on is the risky choice (a refetch puts one account out of sync with the market's other accounts), but the "on" hint describes it neutrally. Consider an optional
warningprop so the Phoenix dialog can say this next to the switch.