Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions apps/dapp/src/modules/create-auction/prepare-dtl-parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { getDuration, getTimestamp } from "utils/date";
import { toBasisPoints } from "utils/number";
import { getAddress, zeroAddress } from "viem";
import { CreateAuctionForm } from "pages/create-auction-page";

type BaseDtlOnCreateParams = Pick<
CreateAuctionForm,
| "dtlProceedsPercent"
| "dtlVestingStart"
| "dtlVestingDuration"
| "dtlRecipient"
>;

/** Prepares onCreate parameters for BaseDirectToLiquidity */
export function prepareBaseDTLParameters(values: BaseDtlOnCreateParams) {
const poolPercent = values.dtlProceedsPercent
? toBasisPoints(values.dtlProceedsPercent[0] ?? 0)
: 0;

const vestingStart = values.dtlVestingStart
? getTimestamp(values.dtlVestingStart)
: 0;

const vestingExpiry =
vestingStart === 0
? 0
: vestingStart + getDuration(Number(values.dtlVestingDuration ?? 0));

const recipient = !values.dtlRecipient
? zeroAddress
: getAddress(values.dtlRecipient);

return {
poolPercent,
vestingStart,
vestingExpiry,
recipient,
};
}

export const baseDtlOnCreateParams = {
components: [
{
type: "uint24",
name: "poolPercent",
},
{
type: "uint48",
name: "vestingStart",
},
{
type: "uint48",
name: "vestingExpiry",
},
{
type: "address",
name: "recipient",
},
{
type: "bytes",
name: "implParams",
},
],
type: "tuple",
name: "OnCreateParams",
};
145 changes: 42 additions & 103 deletions apps/dapp/src/pages/create-auction-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ import { useStoredAuctionConfig } from "state/auction-config";
import type { Token } from "@repo/types";
import { DownloadIcon, ShareIcon, TrashIcon } from "lucide-react";
import { TriggerMessage } from "components/trigger-message";
import {
baseDtlOnCreateParams,
prepareBaseDTLParameters,
} from "modules/create-auction/prepare-dtl-parameters";

const optionalURL = z.union([z.string().url().optional(), z.literal("")]);

Expand Down Expand Up @@ -145,6 +149,7 @@ const schema = z
.string()
.regex(/^(0x)?[0-9a-fA-F]{40}$/)
.optional(),
dtlUniMaxSlippage: z.array(z.number()).optional(),
dtlUniV3PoolFee: z.string().optional(),
customCallbackData: z
.string()
Expand Down Expand Up @@ -584,121 +589,39 @@ export default function CreateAuctionPage() {
break;
}
case CallbacksType.UNIV2_DTL: {
const proceedsPercent = values.dtlProceedsPercent
? toBasisPoints(values.dtlProceedsPercent[0] ?? 0)
: 0;
const vestingStart = values.dtlVestingStart
? getTimestamp(values.dtlVestingStart)
: 0;
const vestingExpiry =
vestingStart === 0
? 0
: vestingStart +
getDuration(Number(values.dtlVestingDuration ?? 0));
const recipient = !values.dtlRecipient
? zeroAddress
: getAddress(values.dtlRecipient);
const implParams = toHex("");
const baseDTLArgs = prepareBaseDTLParameters(values);
const maxSlippage = toBasisPoints(values.dtlUniMaxSlippage?.[0] ?? 0);

const implParams = encodeAbiParameters(
parseAbiParameters("uint24 maxSlippage"),
[maxSlippage],
);

callbackData = encodeAbiParameters(
[
{
components: [
{
type: "uint24",
name: "proceedsUtilisationPercent",
},
{
type: "uint48",
name: "vestingStart",
},
{
type: "uint48",
name: "vestingExpiry",
},
{
type: "address",
name: "recipient",
},
{
type: "bytes",
name: "implParams",
},
],
type: "tuple",
name: "OnCreateParams",
},
],
[
{
proceedsUtilisationPercent: proceedsPercent,
vestingStart: vestingStart,
vestingExpiry: vestingExpiry,
recipient: recipient,
implParams: implParams,
},
],
[baseDtlOnCreateParams],
[{ ...baseDTLArgs, implParams }],
);

break;
}

case CallbacksType.UNIV3_DTL: {
const proceedsPercent = values.dtlProceedsPercent
? toBasisPoints(values.dtlProceedsPercent[0] ?? 0)
: 0;
const vestingStart = values.dtlVestingStart
? getTimestamp(values.dtlVestingStart)
: 0;
const vestingExpiry =
vestingStart === 0
? 0
: vestingStart +
getDuration(Number(values.dtlVestingDuration ?? 0));
const recipient = (values.dtlRecipient ?? zeroAddress) as `0x${string}`;
const baseDTLArgs = prepareBaseDTLParameters(values);

const poolFee = values.dtlUniV3PoolFee
? Number(values.dtlUniV3PoolFee)
: 0;

const maxSlippage = toBasisPoints(values.dtlUniMaxSlippage?.[0] ?? 0);

const implParams = encodeAbiParameters(
parseAbiParameters("uint24 poolFee"),
[poolFee],
parseAbiParameters("uint24 poolFee, uint24 maxSlippage"),
[poolFee, maxSlippage],
);

callbackData = encodeAbiParameters(
[
{
components: [
{
type: "uint24",
name: "proceedsUtilisationPercent",
},
{
type: "uint48",
name: "vestingStart",
},
{
type: "uint48",
name: "vestingExpiry",
},
{
type: "address",
name: "recipient",
},
{
type: "bytes",
name: "implParams",
},
],
type: "tuple",
name: "OnCreateParams",
},
],
[
{
proceedsUtilisationPercent: proceedsPercent,
vestingStart: vestingStart,
vestingExpiry: vestingExpiry,
recipient: recipient,
implParams: implParams,
},
],
[baseDtlOnCreateParams],
[{ ...baseDTLArgs, implParams }],
);
break;
}
Expand Down Expand Up @@ -1872,6 +1795,22 @@ export default function CreateAuctionPage() {
</FormItemWrapper>
)}
/>
<FormField
control={form.control}
name="dtlUniMaxSlippage"
render={({ field }) => (
<FormItemWrapper
className="mt-4"
label="Max Slippage"
tooltip="The maximum slippage allowed when adding liquidity, in percent."
>
<PercentageSlider
field={field}
defaultValue={1}
/>
</FormItemWrapper>
)}
/>
</>
)}
{callbacksType === CallbacksType.UNIV3_DTL && (
Expand Down