-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account for Dutch auction schedules/ends in the WASM planner (#1017)
* Account for Dutch auction schedules/ends in the WASM planner * Remove useless conversion * Use real nonce * Create UI to schedule Dutch auctions (#967) * Build out Dutch auction UI * Add more docs to Slider * Fix metadata * Rename Prices -> Price * Fix test name * Create first tests for assembleRequest * Add one more test * Tweak Price layout * Add auction to swap sublinks * Remove tabs for now * Convert to a Record to avoid having to assert presence * Change min output * Change to decimal * Align to the right * Handle exponent when processing amounts * Add test coverage for constants
- Loading branch information
1 parent
a9cb099
commit e68ef74
Showing
42 changed files
with
988 additions
and
97 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/minifront/src/components/swap/dutch-auction/duration-slider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Slider } from '@penumbra-zone/ui/components/ui/slider'; | ||
import { DURATION_OPTIONS } from '../../../state/dutch-auction/constants'; | ||
import { useStoreShallow } from '../../../utils/use-store-shallow'; | ||
import { AllSlices } from '../../../state'; | ||
|
||
const durationSliderSelector = (state: AllSlices) => ({ | ||
duration: state.dutchAuction.duration, | ||
setDuration: state.dutchAuction.setDuration, | ||
}); | ||
|
||
export const DurationSlider = () => { | ||
const { duration, setDuration } = useStoreShallow(durationSliderSelector); | ||
|
||
const handleChange = (newValue: number[]) => { | ||
const value = newValue[0]!; // We don't use multiple values in the slider | ||
const option = DURATION_OPTIONS[value]!; | ||
|
||
setDuration(option); | ||
}; | ||
|
||
return ( | ||
<div className='flex flex-col items-center gap-4'> | ||
<Slider | ||
min={0} | ||
max={DURATION_OPTIONS.length - 1} | ||
value={[DURATION_OPTIONS.indexOf(duration)]} | ||
onValueChange={handleChange} | ||
/> | ||
{duration} | ||
</div> | ||
); | ||
}; |
61 changes: 61 additions & 0 deletions
61
apps/minifront/src/components/swap/dutch-auction/dutch-auction-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Button } from '@penumbra-zone/ui/components/ui/button'; | ||
import { AllSlices } from '../../../state'; | ||
import { useStoreShallow } from '../../../utils/use-store-shallow'; | ||
import { InputBlock } from '../../shared/input-block'; | ||
import InputToken from '../../shared/input-token'; | ||
import { DurationSlider } from './duration-slider'; | ||
import { Price } from './price'; | ||
|
||
const dutchAuctionFormSelector = (state: AllSlices) => ({ | ||
balances: state.dutchAuction.balancesResponses, | ||
assetIn: state.dutchAuction.assetIn, | ||
setAssetIn: state.dutchAuction.setAssetIn, | ||
amount: state.dutchAuction.amount, | ||
setAmount: state.dutchAuction.setAmount, | ||
onSubmit: state.dutchAuction.onSubmit, | ||
submitButtonDisabled: state.dutchAuction.txInProgress || !state.dutchAuction.amount, | ||
}); | ||
|
||
export const DutchAuctionForm = () => { | ||
const { amount, setAmount, assetIn, setAssetIn, balances, onSubmit, submitButtonDisabled } = | ||
useStoreShallow(dutchAuctionFormSelector); | ||
|
||
return ( | ||
<form | ||
className='flex flex-col gap-4 xl:gap-3' | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
void onSubmit(); | ||
}} | ||
> | ||
<InputToken | ||
label='Amount to sell' | ||
balances={balances} | ||
selection={assetIn} | ||
setSelection={setAssetIn} | ||
value={amount} | ||
onChange={e => { | ||
if (Number(e.target.value) < 0) return; | ||
setAmount(e.target.value); | ||
}} | ||
placeholder='Enter an amount' | ||
/> | ||
|
||
<InputBlock label='Duration'> | ||
<div className='pt-2'> | ||
<DurationSlider /> | ||
</div> | ||
</InputBlock> | ||
|
||
<InputBlock label='Price'> | ||
<div className='pt-2'> | ||
<Price /> | ||
</div> | ||
</InputBlock> | ||
|
||
<Button variant='gradient' type='submit' disabled={submitButtonDisabled}> | ||
Start auctions | ||
</Button> | ||
</form> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
apps/minifront/src/components/swap/dutch-auction/dutch-auction-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client'; | ||
import { getSwappableBalancesResponses } from '../helpers'; | ||
import { useStore } from '../../../state'; | ||
import { getAllAssets } from '../../../fetchers/assets'; | ||
|
||
export const DutchAuctionLoader = async () => { | ||
await throwIfPraxNotConnectedTimeout(); | ||
|
||
const [assets, balancesResponses] = await Promise.all([ | ||
getAllAssets(), | ||
getSwappableBalancesResponses(), | ||
]); | ||
useStore.getState().dutchAuction.setBalancesResponses(balancesResponses); | ||
|
||
if (balancesResponses[0]) { | ||
useStore.getState().dutchAuction.setAssetIn(balancesResponses[0]); | ||
useStore.getState().dutchAuction.setAssetOut(assets[0]!); | ||
} | ||
|
||
return assets; | ||
}; |
23 changes: 23 additions & 0 deletions
23
apps/minifront/src/components/swap/dutch-auction/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Card } from '@penumbra-zone/ui/components/ui/card'; | ||
import { EduPanel } from '../../shared/edu-panels/content'; | ||
import { EduInfoCard } from '../../shared/edu-panels/edu-info-card'; | ||
import { DutchAuctionForm } from './dutch-auction-form'; | ||
|
||
export const DutchAuction = () => { | ||
return ( | ||
<div className='grid gap-6 md:grid-cols-2 md:gap-4 xl:grid-cols-3 xl:gap-5'> | ||
<div className='hidden xl:block'></div> | ||
|
||
<Card gradient className='order-3 row-span-2 flex-1 p-5 md:order-1 md:p-4 xl:p-5'> | ||
<DutchAuctionForm /> | ||
</Card> | ||
|
||
<EduInfoCard | ||
className='row-span-1 md:order-2' | ||
src='./auction-gradient.svg' | ||
label='Dutch Auction' | ||
content={EduPanel.SWAP_AUCTION} | ||
/> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.