Skip to content

Commit

Permalink
fix: make multiSig createdAt in sync with the blockchain, unify the h…
Browse files Browse the repository at this point in the history
…elper for getting an iso date from a timestamp
  • Loading branch information
bassgeta committed Aug 2, 2024
1 parent 98a3d79 commit 71015c9
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/graphql/fragments/multiSig.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ fragment ColonyMultiSig on ColonyMultiSig {
executedBy
rejectedAt
rejectedBy
createdAt
}
9 changes: 9 additions & 0 deletions src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ export type ColonyMultiSig = {
action?: Maybe<ColonyAction>;
/** Colony address the multiSig belongs to */
colonyAddress: Scalars['ID'];
/** The timestamp when the motion was created at */
createdAt: Scalars['AWSDateTime'];
/** The timestamp when the motion was finalized */
executedAt?: Maybe<Scalars['AWSDateTime']>;
Expand Down Expand Up @@ -1540,6 +1541,7 @@ export type CreateColonyMotionInput = {

export type CreateColonyMultiSigInput = {
colonyAddress: Scalars['ID'];
createdAt?: InputMaybe<Scalars['AWSDateTime']>;
executedAt?: InputMaybe<Scalars['AWSDateTime']>;
executedBy?: InputMaybe<Scalars['ID']>;
hasActionCompleted: Scalars['Boolean'];
Expand Down Expand Up @@ -3044,6 +3046,7 @@ export type ModelColonyMotionFilterInput = {
export type ModelColonyMultiSigConditionInput = {
and?: InputMaybe<Array<InputMaybe<ModelColonyMultiSigConditionInput>>>;
colonyAddress?: InputMaybe<ModelIdInput>;
createdAt?: InputMaybe<ModelStringInput>;
executedAt?: InputMaybe<ModelStringInput>;
executedBy?: InputMaybe<ModelIdInput>;
hasActionCompleted?: InputMaybe<ModelBooleanInput>;
Expand All @@ -3070,6 +3073,7 @@ export type ModelColonyMultiSigConnection = {
export type ModelColonyMultiSigFilterInput = {
and?: InputMaybe<Array<InputMaybe<ModelColonyMultiSigFilterInput>>>;
colonyAddress?: InputMaybe<ModelIdInput>;
createdAt?: InputMaybe<ModelStringInput>;
executedAt?: InputMaybe<ModelStringInput>;
executedBy?: InputMaybe<ModelIdInput>;
hasActionCompleted?: InputMaybe<ModelBooleanInput>;
Expand Down Expand Up @@ -4141,6 +4145,7 @@ export type ModelSubscriptionColonyMultiSigFilterInput = {
Array<InputMaybe<ModelSubscriptionColonyMultiSigFilterInput>>
>;
colonyAddress?: InputMaybe<ModelSubscriptionIdInput>;
createdAt?: InputMaybe<ModelSubscriptionStringInput>;
executedAt?: InputMaybe<ModelSubscriptionStringInput>;
executedBy?: InputMaybe<ModelSubscriptionIdInput>;
hasActionCompleted?: InputMaybe<ModelSubscriptionBooleanInput>;
Expand Down Expand Up @@ -8632,6 +8637,7 @@ export type UpdateColonyMotionInput = {

export type UpdateColonyMultiSigInput = {
colonyAddress?: InputMaybe<Scalars['ID']>;
createdAt?: InputMaybe<Scalars['AWSDateTime']>;
executedAt?: InputMaybe<Scalars['AWSDateTime']>;
executedBy?: InputMaybe<Scalars['ID']>;
hasActionCompleted?: InputMaybe<Scalars['Boolean']>;
Expand Down Expand Up @@ -9483,6 +9489,7 @@ export type ColonyMultiSigFragment = {
executedBy?: string | null;
rejectedAt?: string | null;
rejectedBy?: string | null;
createdAt: string;
signatures?: {
__typename?: 'ModelMultiSigUserSignatureConnection';
items: Array<{
Expand Down Expand Up @@ -10906,6 +10913,7 @@ export type GetColonyMultiSigQuery = {
executedBy?: string | null;
rejectedAt?: string | null;
rejectedBy?: string | null;
createdAt: string;
signatures?: {
__typename?: 'ModelMultiSigUserSignatureConnection';
items: Array<{
Expand Down Expand Up @@ -11370,6 +11378,7 @@ export const ColonyMultiSig = gql`
executedBy
rejectedAt
rejectedBy
createdAt
}
${MultiSigUserSignature}
`;
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/motions/motionEventSet/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExtensionEventListener } from '~eventListeners';
import { EventHandler } from '~types';
import { verbose, getVotingClient } from '~utils';
import { getBlockChainTimestampISODate } from '~utils/dates';

import {
getMotionDatabaseId,
Expand Down Expand Up @@ -35,10 +36,10 @@ export const handleMotionEventSet: EventHandler = async (event, listener) => {
motionStateHistory: {
...motion.motionStateHistory,
allVotesSubmittedAt: eventIndex.eq(1)
? new Date(timestamp * 1000).toISOString()
? getBlockChainTimestampISODate(timestamp)
: motion.motionStateHistory.allVotesSubmittedAt,
allVotesRevealedAt: eventIndex.eq(2)
? new Date(timestamp * 1000).toISOString()
? getBlockChainTimestampISODate(timestamp)
: motion.motionStateHistory.allVotesRevealedAt,
},
});
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/motions/motionFinalized/motionFinalized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ExtensionEventListener } from '~eventListeners';
import { EventHandler, MotionEvents } from '~types';
import { getVotingClient } from '~utils';
import { linkPendingMetadata } from '~utils/colonyMetadata';
import { getBlockChainTimestampISODate } from '~utils/dates';

import {
getMotionDatabaseId,
Expand Down Expand Up @@ -88,7 +89,7 @@ export const handleMotionFinalized: EventHandler = async (event, listener) => {
isFinalized: true,
motionStateHistory: {
...finalizedMotion.motionStateHistory,
finalizedAt: new Date(timestamp * 1000).toISOString(),
finalizedAt: getBlockChainTimestampISODate(timestamp),
},
};

Expand Down
3 changes: 2 additions & 1 deletion src/handlers/motions/motionStaked/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { mutate, query } from '~amplifyClient';
import { getUserStakeDatabaseId } from '~utils/stakes';
import { getMotionSide, getColonyStakeId } from '../helpers';
import { getBlockChainTimestampISODate } from '~utils/dates';

export const getRequiredStake = (
skillRep: BigNumber,
Expand Down Expand Up @@ -382,7 +383,7 @@ export const updateUserStake = async (
actionId: transactionHash,
amount: amount.toString(),
isClaimed: false,
createdAt: new Date(timestamp * 1000).toISOString(),
createdAt: getBlockChainTimestampISODate(timestamp),
},
},
);
Expand Down
5 changes: 3 additions & 2 deletions src/handlers/motions/motionStaked/motionStaked.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExtensionEventListener } from '~eventListeners';
import { EventHandler, MotionSide } from '~types';
import { verbose, getVotingClient } from '~utils';
import { getBlockChainTimestampISODate } from '~utils/dates';
import {
getMotionDatabaseId,
getMotionFromDB,
Expand Down Expand Up @@ -92,11 +93,11 @@ export const handleMotionStaked: EventHandler = async (
...stakedMotion.motionStateHistory,
yaySideFullyStakedAt:
yaySideFullyStaked && stakerSide === MotionSide.YAY
? new Date(timestamp * 1000).toISOString()
? getBlockChainTimestampISODate(timestamp)
: stakedMotion.motionStateHistory.yaySideFullyStakedAt,
naySideFullyStakedAt:
naySideFullyStaked && stakerSide === MotionSide.NAY
? new Date(timestamp * 1000).toISOString()
? getBlockChainTimestampISODate(timestamp)
: stakedMotion.motionStateHistory.naySideFullyStakedAt,
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/multiSig/approvalChanged/approvalChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const handleMultiSigApprovalChanged: EventHandler = async (
event,
listener,
) => {
const { contractAddress: multiSigExtensionAddress } = event;
const { contractAddress: multiSigExtensionAddress, timestamp } = event;

const { colonyAddress } = listener as ExtensionEventListener;

Expand Down Expand Up @@ -45,6 +45,7 @@ export const handleMultiSigApprovalChanged: EventHandler = async (
userAddress,
colonyAddress,
vote: MultiSigVote.Approve,
timestamp,
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/multiSig/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
CreateMultiSigVoteMutationVariables,
CreateMultiSigVoteDocument,
} from '~graphql';
import { getBlockChainTimestampISODate } from '~utils/dates';
import { output } from '~utils/logger';

export const getMultiSigDatabaseId = (
Expand Down Expand Up @@ -97,6 +98,7 @@ interface addMultiSigVoteParams {
multiSigId: string;
role: number;
vote: MultiSigVote.Approve | MultiSigVote.Reject;
timestamp: number;
}

export const addMultiSigVote = async ({
Expand All @@ -105,6 +107,7 @@ export const addMultiSigVote = async ({
userAddress,
colonyAddress,
vote,
timestamp,
}: addMultiSigVoteParams): Promise<void> => {
await mutate<CreateMultiSigVoteMutation, CreateMultiSigVoteMutationVariables>(
CreateMultiSigVoteDocument,
Expand All @@ -115,6 +118,7 @@ export const addMultiSigVote = async ({
userAddress,
role,
vote,
createdAt: getBlockChainTimestampISODate(timestamp),
},
},
);
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/multiSig/multiSigCancelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EventHandler } from '~types';
import { verbose } from '~utils';
import { getMultiSigDatabaseId } from './helpers';
import { getChainId } from '~provider';
import { getBlockChainTimestampISODate } from '~utils/dates';

export const handleMultiSigMotionCancelled: EventHandler = async (event) => {
const {
Expand All @@ -34,7 +35,7 @@ export const handleMultiSigMotionCancelled: EventHandler = async (event) => {
id: multiSigDatabaseId,
hasActionCompleted: false,
isRejected: true,
rejectedAt: new Date(timestamp * 1000).toISOString(),
rejectedAt: getBlockChainTimestampISODate(timestamp),
rejectedBy: userAddress,
},
});
Expand Down
5 changes: 5 additions & 0 deletions src/handlers/multiSig/multiSigCreated/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
output,
createColonyAction,
} from '~utils';
import { getBlockChainTimestampISODate } from '~utils/dates';
import { getMultiSigDatabaseId } from '../helpers';

const createColonyMultiSig = async (
Expand All @@ -43,6 +44,7 @@ interface GetMultiSigDataArgs {
multiSigClient: AnyMultisigPermissionsClient;
colonyAddress: string;
isDecision?: boolean;
timestamp: number;
}

export const getMultiSigData = async ({
Expand All @@ -53,6 +55,7 @@ export const getMultiSigData = async ({
multiSigClient,
colonyAddress,
isDecision = false,
timestamp,
}: GetMultiSigDataArgs): Promise<ColonyMultiSig> => {
const chainId = getChainId();
const multiSigDatabaseId = getMultiSigDatabaseId(
Expand All @@ -73,6 +76,7 @@ export const getMultiSigData = async ({
isRejected: false,
isDecision,
hasActionCompleted: false,
createdAt: getBlockChainTimestampISODate(timestamp),
};
};

Expand Down Expand Up @@ -152,6 +156,7 @@ export const createMultiSigInDB = async (
requiredPermissions,
colonyAddress,
isDecision: !!input.colonyDecisionId,
timestamp,
});

const rootHash = await networkClient.getReputationRootHash({
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/multiSig/multiSigExecuted/multiSigExecuted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../helpers';
import { getMultiSigClient, verbose } from '~utils';
import { linkPendingMetadata } from '~utils/colonyMetadata';
import { getBlockChainTimestampISODate } from '~utils/dates';

export const handleMultiSigMotionExecuted: EventHandler = async (
event,
Expand Down Expand Up @@ -63,7 +64,7 @@ export const handleMultiSigMotionExecuted: EventHandler = async (
// @NOTE failing execution is allowed only after 1 week so the motion doesn't end up floating around
const updatedMultiSigData = {
id: multiSigDatabaseId,
executedAt: new Date(timestamp * 1000).toISOString(),
executedAt: getBlockChainTimestampISODate(timestamp),
executedBy: userAddress,
isExecuted: true,
hasActionCompleted: success,
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/multiSig/rejectionChanged/rejectionChanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const handleMultiSigRejectionChanged: EventHandler = async (
event,
listener,
) => {
const { contractAddress: multiSigExtensionAddress } = event;
const { contractAddress: multiSigExtensionAddress, timestamp } = event;

const { colonyAddress } = listener as ExtensionEventListener;

Expand Down Expand Up @@ -49,6 +49,7 @@ export const handleMultiSigRejectionChanged: EventHandler = async (
userAddress,
colonyAddress,
vote: MultiSigVote.Reject,
timestamp,
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/actions/writeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { toNumber, verbose, getColonyExtensions } from '~utils';
import { ContractEvent } from '~types';
import networkClient from '~networkClient';
import { getBlockChainTimestampISODate } from '~utils/dates';

export type ActionFields = Omit<
CreateColonyActionInput,
Expand Down Expand Up @@ -60,7 +61,7 @@ export const writeActionFromEvent = async (
id: transactionHash,
colonyId: colonyAddress,
blockNumber,
createdAt: new Date(timestamp * 1000).toISOString(),
createdAt: getBlockChainTimestampISODate(timestamp),
showInActionsList,
rootHash,
isMotionFinalization,
Expand Down Expand Up @@ -139,7 +140,7 @@ export const createColonyAction = async (
{
input: {
...actionData,
createdAt: new Date(blockTimestamp * 1000).toISOString(),
createdAt: getBlockChainTimestampISODate(blockTimestamp),
},
},
);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getBlockChainTimestampISODate = (
blockTimestamp: number,
): string => {
return new Date(blockTimestamp * 1000).toISOString();
};

0 comments on commit 71015c9

Please sign in to comment.