Skip to content

Commit

Permalink
switch to createWithTimestampsLL
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Colon committed Aug 28, 2024
1 parent d255ab7 commit 9314ab7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
14 changes: 6 additions & 8 deletions src/hooks/streams/useCreateSablierStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
},
Expand Down Expand Up @@ -116,6 +113,7 @@ export default function useCreateSablierStream() {
const assembledStreams: ReturnType<typeof prepareLinearStream>[] = [];
const streams = groupedStreams[assetAddress];
let totalStreamsAmount = 0n;
console.log("πŸš€ ~ assetAddress:", assetAddress)
const tokenAddress = getAddress(assetAddress);
streams.forEach(streamData => {
totalStreamsAmount += streamData.totalAmount;
Expand All @@ -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,
Expand Down
23 changes: 15 additions & 8 deletions src/hooks/utils/useCreateRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -232,7 +232,7 @@ const identifyAndPrepareAddedPaymentStreams = async (
): Promise<PreparedNewStreamData[]> => {
const preparedStreamDataMapped = await Promise.all(
modifiedHats.map(async formHat => {
if (formHat.payments === undefined || formHat.editedRole.status !== EditBadgeStatus.Updated) {
if (formHat.payments === undefined) {
return [];
}

Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 9314ab7

Please sign in to comment.