Skip to content

Commit a24df3e

Browse files
authored
Add real data to stable surge simulator (#5)
* Add real data to Stable Surge simulator * Add token names
1 parent 8798283 commit a24df3e

File tree

9 files changed

+5550
-10
lines changed

9 files changed

+5550
-10
lines changed
File renamed without changes.

client/src/pool-types/reclamm/ReClamm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
calculateInvariant,
2626
computePriceRatioFromBalances,
2727
} from './ReClammMath';
28-
import { MIN_SWAP, NETWORKS } from './constants';
28+
import { MIN_SWAP, NETWORKS } from '../../constants';
2929

3030
import { formatTime } from '../../utils/Time';
3131
import { toFixedDecimals } from '../../utils/ToFixedLib';

client/src/pool-types/stable-surge/StableSurge.tsx

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { stableInvariant } from '../stable-pool/StableMath';
1515
import { StableSurgeChart } from './StableSurgeChart';
1616
import { getTokenBalanceGivenInvariantAndAllOtherBalances } from '../stable-pool/StableMath';
1717
import { calculateImbalance, getSurgeFeePercentage } from './StableSurgeHook';
18+
import { NETWORKS } from '../../constants';
1819
export default function StableSurge() {
1920
const [inputBalances, setInputBalances] = useState<number[]>([1000, 1000]);
2021
const [initialBalances, setInitialBalances] = useState<number[]>([
@@ -27,12 +28,12 @@ export default function StableSurge() {
2728
const [tokenNames, setTokenNames] = useState<string[]>(['A', 'B', 'C', 'D']);
2829

2930
const [inputTokenCount, setInputTokenCount] = useState<number>(2);
30-
const [tokenCount, setTokenCount] = useState<number>(2);
3131
const [inputAmplification, setInputAmplification] = useState<number>(100);
3232
const [inputSwapFee, setInputSwapFee] = useState<number>(1);
3333
const [inputMaxSurgeFee, setInputMaxSurgeFee] = useState<number>(10);
3434
const [inputSurgeThreshold, setInputSurgeThreshold] = useState<number>(20);
3535

36+
const [tokenCount, setTokenCount] = useState<number>(2);
3637
const [amplification, setAmplification] = useState<number>(100);
3738
const [swapFee, setSwapFee] = useState<number>(1);
3839
const [maxSurgeFee, setMaxSurgeFee] = useState<number>(10);
@@ -362,11 +363,106 @@ export default function StableSurge() {
362363
});
363364
};
364365

366+
// Add state for real pool loading
367+
const [network, setNetwork] = useState<string>('base-mainnet');
368+
const [address, setAddress] = useState<string>(
369+
'0x7AB124EC4029316c2A42F713828ddf2a192B36db'
370+
);
371+
372+
// Handler to load real pool data
373+
const handleLoadPool = async () => {
374+
const res = await fetch(
375+
`${process.env.REACT_APP_FUNCTION_URL}/stableSurgeData?network=${network}&address=${address}`
376+
);
377+
378+
const data: {
379+
numberOfTokens: number;
380+
tokenNames: string[];
381+
balances: number[];
382+
amplificationParameter: number;
383+
staticSwapFeePercentage: number;
384+
maxSurgeFeePercentage: number;
385+
surgeThreshold: number;
386+
} = await res.json();
387+
388+
setInputTokenCount(data.numberOfTokens);
389+
setTokenCount(data.numberOfTokens);
390+
391+
const balances = data.balances.map(x => x / Math.pow(10, 18));
392+
setInputBalances(balances);
393+
setInitialBalances(balances);
394+
setCurrentBalances(balances);
395+
396+
setInputAmplification(data.amplificationParameter);
397+
setAmplification(data.amplificationParameter);
398+
399+
const staticSwapFeePercentage =
400+
data.staticSwapFeePercentage / Math.pow(10, 16);
401+
setInputSwapFee(staticSwapFeePercentage);
402+
setSwapFee(staticSwapFeePercentage);
403+
404+
const maxSurgeFeePercentage = data.maxSurgeFeePercentage / Math.pow(10, 16);
405+
setInputMaxSurgeFee(maxSurgeFeePercentage);
406+
setMaxSurgeFee(maxSurgeFeePercentage);
407+
408+
const surgeThreshold = data.surgeThreshold / Math.pow(10, 16);
409+
setInputSurgeThreshold(surgeThreshold);
410+
setSurgeThreshold(surgeThreshold);
411+
412+
setTokenNames(data.tokenNames);
413+
414+
setTotalFees(Array(balances.length).fill(0));
415+
};
416+
365417
return (
366418
<Container>
367419
<Grid container spacing={2}>
368420
{/* Left Column - Controls */}
369421
<Grid item xs={3}>
422+
{/* Load Real Pool Section */}
423+
<Accordion>
424+
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
425+
<Typography variant='h6'>Load Real Pool</Typography>
426+
</AccordionSummary>
427+
<AccordionDetails>
428+
<TextField
429+
select
430+
label='Network'
431+
fullWidth
432+
margin='normal'
433+
value={network}
434+
onChange={e => setNetwork(e.target.value)}
435+
SelectProps={{
436+
native: true,
437+
}}
438+
>
439+
{NETWORKS.sort((a, b) => a.name.localeCompare(b.name)).map(
440+
n => (
441+
<option key={n.network} value={n.network}>
442+
{n.name}
443+
</option>
444+
)
445+
)}
446+
</TextField>
447+
<TextField
448+
label='Address'
449+
type='text'
450+
fullWidth
451+
margin='normal'
452+
value={address}
453+
onChange={e => setAddress(e.target.value)}
454+
/>
455+
<Button
456+
variant='contained'
457+
fullWidth
458+
onClick={handleLoadPool}
459+
style={{ marginTop: 16 }}
460+
>
461+
Load Pool
462+
</Button>
463+
</AccordionDetails>
464+
</Accordion>
465+
370466
<Accordion>
371467
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
372468
<Typography variant='h6'>Initialize Pool</Typography>

0 commit comments

Comments
 (0)