Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const CollateralSwapActionsViaCowAdapters = ({
allowPermit: !disablePermitDueToActiveOrder, // CoW Adapters do support permit but avoid nonce reuse
trackingHandlers,
swapType: state.swapType,
validTo,
});

// Use centralized gas estimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const DebtSwapActionsViaCoW = ({
type: 'delegation', // Debt swap uses delegation
trackingHandlers,
swapType: state.swapType,
validTo,
});

// Use centralized gas estimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const RepayWithCollateralActionsViaCoW = ({
allowPermit: !disablePermitDueToActiveOrder, // avoid nonce reuse if active order present
trackingHandlers,
swapType: state.swapType,
validTo,
});

// Use centralized gas estimation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export const SwapActionsViaCoW = ({
state.sourceToken.addressToSwap
);

const validTo = useMemo(
() => Math.floor(Date.now() / 1000) + ExpiryToSecondsMap[state.expiry],
[state.expiry]
);

const {
requiresApproval,
requiresApprovalReset,
Expand All @@ -101,6 +106,7 @@ export const SwapActionsViaCoW = ({
allowPermit: !disablePermitDueToActiveOrder,
trackingHandlers,
swapType: state.swapType,
validTo,
});

// Use centralized gas estimation
Expand All @@ -112,11 +118,6 @@ export const SwapActionsViaCoW = ({
approvalTxState,
});

const validTo = useMemo(
() => Math.floor(Date.now() / 1000) + ExpiryToSecondsMap[state.expiry],
[state.expiry]
);

const { sendTx } = useWeb3Context();

const slippageInPercent = state.slippage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export type SwapTokenApprovalParams = {
type?: 'approval' | 'delegation';
trackingHandlers?: TrackAnalyticsHandlers;
swapType: SwapType;
/** Unix timestamp (seconds) for the order's validTo. When provided, the permit deadline
* will match this value so the permit stays valid for the order's entire lifetime. */
validTo?: number;
};

export type SignatureLike = {
Expand Down Expand Up @@ -93,6 +96,7 @@ export const useSwapTokenApproval = ({
type = 'approval',
trackingHandlers,
swapType,
validTo,
}: SwapTokenApprovalParams) => {
const [approvedAmount, setApprovedAmount] = useState<string | undefined>();
const [approvedAddress, setApprovedAddress] = useState<string | undefined>();
Expand Down Expand Up @@ -335,7 +339,7 @@ export const useSwapTokenApproval = ({
if (usePermit) {
// Permit approval
try {
const deadline = Math.floor(Date.now() / 1000 + 3600).toString();
const deadline = (validTo ?? Math.floor(Date.now() / 1000 + 3600)).toString();
let signatureRequest: string;
if (type === 'delegation') {
signatureRequest = await generateCreditDelegationSignatureRequest({
Expand Down
Loading