From 9314ab70ccc0fab09d4dbe4d64ad955adbf4a83f Mon Sep 17 00:00:00 2001 From: David Colon <38386583+Da-Colon@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:33:59 -0400 Subject: [PATCH] switch to createWithTimestampsLL --- src/hooks/streams/useCreateSablierStream.ts | 14 ++++++------- src/hooks/utils/useCreateRoles.ts | 23 ++++++++++++++------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/hooks/streams/useCreateSablierStream.ts b/src/hooks/streams/useCreateSablierStream.ts index e4d8d51d97..1823012ee5 100644 --- a/src/hooks/streams/useCreateSablierStream.ts +++ b/src/hooks/streams/useCreateSablierStream.ts @@ -56,23 +56,20 @@ export default function useCreateSablierStream() { throw new Error('Start date of the stream can not be larger than end date'); } - let cliffDuration = 0; if (cliffDateTs) { if (cliffDateTs <= startDateTs) { throw new Error('Cliff date can not be less or equal than start date'); } else if (cliffDateTs >= endDateTs) { throw new Error('Cliff date can not be larger or equal than end date'); } - cliffDuration = Math.ceil((cliffDateTs - startDateTs) / 1000); } - const streamDuration = Math.ceil((endDateTs - startDateTs) / 1000); - return { ...prepareBasicStreamData(recipient, totalAmount), - durations: { - cliff: cliffDuration, - total: streamDuration + cliffDuration, // Total duration has to include cliff duration + timestamps: { + start: startDateTs, + end: endDateTs, + cliff: cliffDateTs, }, }; }, @@ -116,6 +113,7 @@ export default function useCreateSablierStream() { const assembledStreams: ReturnType[] = []; const streams = groupedStreams[assetAddress]; let totalStreamsAmount = 0n; + console.log("🚀 ~ assetAddress:", assetAddress) const tokenAddress = getAddress(assetAddress); streams.forEach(streamData => { totalStreamsAmount += streamData.totalAmount; @@ -126,7 +124,7 @@ export default function useCreateSablierStream() { preparedStreamCreationTransactions.push({ calldata: encodeFunctionData({ abi: SablierV2BatchAbi, - functionName: 'createWithDurationsLL', // @dev @todo Another option would be to use `createWithTimestampsLL`. Probably makes sense to change the logic to `createWithTimestampsLL` since we drifted away from "durations" and actually operating with timestamps always + functionName: 'createWithTimestampsLL', args: [sablierV2LockupLinear, tokenAddress, assembledStreams], }), targetAddress: sablierV2Batch, diff --git a/src/hooks/utils/useCreateRoles.ts b/src/hooks/utils/useCreateRoles.ts index bc69661d63..4d49ed95b1 100644 --- a/src/hooks/utils/useCreateRoles.ts +++ b/src/hooks/utils/useCreateRoles.ts @@ -174,7 +174,7 @@ const identifyAndPrepareEditedPaymentStreams = ( return modifiedHats.flatMap(formHat => { const currentHat = getHat(formHat.id); if (currentHat === null) { - throw new Error("Couldn't find existing Hat for edited payment stream Hat."); + return []; } if (formHat.payments === undefined) { @@ -211,9 +211,9 @@ const identifyAndPrepareEditedPaymentStreams = ( return { streamId: payment.streamId, recipient: currentHat.smartAddress, - startDateTs: payment.startDate.getTime(), - endDateTs: payment.endDate.getTime(), - cliffDateTs: payment.cliffDate?.getTime() ?? 0, + startDateTs: Math.floor(payment.startDate.getTime() / 1000), + endDateTs: Math.ceil(payment.endDate.getTime() / 1000), + cliffDateTs: Math.floor((payment.cliffDate?.getTime() ?? 0) / 1000), totalAmount: payment.amount.bigintValue, assetAddress: payment.asset.address, roleHatId: BigInt(currentHat.id), @@ -232,7 +232,7 @@ const identifyAndPrepareAddedPaymentStreams = async ( ): Promise => { const preparedStreamDataMapped = await Promise.all( modifiedHats.map(async formHat => { - if (formHat.payments === undefined || formHat.editedRole.status !== EditBadgeStatus.Updated) { + if (formHat.payments === undefined) { return []; } @@ -263,9 +263,9 @@ const identifyAndPrepareAddedPaymentStreams = async ( return { recipient: recipientAddress, - startDateTs: payment.startDate.getTime(), - endDateTs: payment.endDate.getTime(), - cliffDateTs: payment.cliffDate?.getTime() ?? 0, + startDateTs: Math.floor(payment.startDate.getTime() / 1000), + endDateTs: Math.ceil(payment.endDate.getTime() / 1000), + cliffDateTs: Math.floor((payment.cliffDate?.getTime() ?? 0) / 1000), totalAmount: payment.amount.bigintValue, assetAddress: payment.asset.address, }; @@ -731,6 +731,13 @@ export default function useCreateRoles() { hatPaymentEditedTxs.push(...preparedPaymentTransactions.preparedStreamCreationTransactions); } + console.log('🚀 ~ createAndMintHatsTxs:', createAndMintHatsTxs); + console.log("🚀 ~ transferHatTxs:", transferHatTxs) + console.log("🚀 ~ hatDetailsChangedTxs:", hatDetailsChangedTxs) + console.log("🚀 ~ hatPaymentAddedTxs:", hatPaymentAddedTxs) + console.log("🚀 ~ hatPaymentEditedTxs:", hatPaymentEditedTxs) + console.log("🚀 ~ smartAccountTxs:", smartAccountTxs) + console.log("🚀 ~ removeHatTxs:", removeHatTxs) const proposalTransactions = { targets: [ ...createAndMintHatsTxs.map(() => hatsProtocol),