Skip to content

Commit

Permalink
Fix gasless endate
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Feb 8, 2024
1 parent f56fe1f commit 113b93c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/context/createProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,27 @@ const CreateProposalWrapper: React.FC<Props> = ({
(
params: CreateMajorityVotingProposalParams
): GaslessProposalCreationParams => {
const gaslessEndDate = new Date(params.endDate!);
gaslessEndDate.setMinutes(params.endDate!.getMinutes() + 1);
// If the onchain end date is too close to the minimum end date, the estimation or either the transaction will fail
// Above all if we are using days or hours to create the proposal, at the time that we are calculating the end date
// it will take the beginning of the actual minute, causing the estimation to be some seconds ahead of the calculated
// date.
// To avoid this, in order to have a concordance between onchain and ofchain endates, we add an offset to the end date
const endDateOffset = 5; // Minutes
const finalEndDate = new Date(params.endDate!); // We ensure that the onchain endate is not undefined, during the calculation of the CreateMajorityVotingProposalParams
finalEndDate.setMinutes(params.endDate!.getMinutes() + endDateOffset);

// The offchain offset is used to ensure that the offchain proposal is enough long to don't overlap the onchain proposal
// limits. As both chains don't use the same clock, and we are calculating the times using blocks, we ensure that
// the times will be properly set to let the voters vote between the onchain proposal limits.
const offchainOffsets = 1; // Minutes
const gaslessEndDate = new Date(finalEndDate);
gaslessEndDate.setMinutes(finalEndDate.getMinutes() + offchainOffsets);
let gaslessStartDate;
if (params.startDate) {
gaslessStartDate = new Date(params.startDate);
gaslessStartDate.setMinutes(params.startDate.getMinutes() - 1);
gaslessStartDate.setMinutes(
params.startDate.getMinutes() - offchainOffsets
);
}
return {
...params,
Expand All @@ -635,8 +650,7 @@ const CreateProposalWrapper: React.FC<Props> = ({
// We could define a different expiration date for this proposal but is not designed
// to do this at ux level. (kon)
tallyEndDate: undefined,
// We ensure that the onchain endate is not undefined, during the calculation of the CreateMajorityVotingProposalParams
endDate: params.endDate!,
endDate: finalEndDate,
// Add offset to the end date to avoid onchain proposal finish before the offchain proposal
gaslessEndDate,
// Add offset to ensure offchain is started when proposal starts
Expand Down Expand Up @@ -1004,13 +1018,6 @@ const CreateProposalWrapper: React.FC<Props> = ({
async function setProposalData() {
if (showTxModal && creationProcessState === TransactionState.WAITING) {
if (gasless) {
// const {params} = await getProposalCreationParams();
// // console.log(
// // 'XXXXXXXXXXXXXXXXX',
// // (await getProposalCreationParams()).params.endDate,
// // gaslessParamsxx.endDate,
// // getOffChainProposalParams(gaslessParamsxx).endDate
// // );
setProposalCreationData(
getOffChainProposalParams(
(await getProposalCreationParams()).params
Expand Down

0 comments on commit 113b93c

Please sign in to comment.