Skip to content

Commit

Permalink
Merge pull request #261 from JoinColony/refactor/2572-motion-gas-esti…
Browse files Browse the repository at this point in the history
…mate-rework

feat: remove gas estimation for motions
  • Loading branch information
bassgeta authored Aug 12, 2024
2 parents 268f816 + ad4e920 commit 1564942
Show file tree
Hide file tree
Showing 24 changed files with 13 additions and 219 deletions.
10 changes: 0 additions & 10 deletions src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,11 +959,6 @@ export type ColonyMotion = {
expenditureId?: Maybe<Scalars['ID']>;
/** Id of the expenditure stage payment to be released if the motion pass, if any */
expenditureSlotId?: Maybe<Scalars['Int']>;
/**
* An option to manually specify the amount of gas to estimate for the finalization of this motion.
* Particularly useful for "heavy" actions, such as a multicall.
*/
gasEstimate: Scalars['String'];
/** Simple flag indicating whether both sides of staking have been activated */
hasObjection: Scalars['Boolean'];
/**
Expand Down Expand Up @@ -1407,7 +1402,6 @@ export type CreateColonyMotionInput = {
expenditureFunding?: InputMaybe<Array<ExpenditureFundingItemInput>>;
expenditureId?: InputMaybe<Scalars['ID']>;
expenditureSlotId?: InputMaybe<Scalars['Int']>;
gasEstimate: Scalars['String'];
hasObjection: Scalars['Boolean'];
id?: InputMaybe<Scalars['ID']>;
isDecision: Scalars['Boolean'];
Expand Down Expand Up @@ -2835,7 +2829,6 @@ export type ModelColonyMotionConditionInput = {
createdBy?: InputMaybe<ModelStringInput>;
expenditureId?: InputMaybe<ModelIdInput>;
expenditureSlotId?: InputMaybe<ModelIntInput>;
gasEstimate?: InputMaybe<ModelStringInput>;
hasObjection?: InputMaybe<ModelBooleanInput>;
isDecision?: InputMaybe<ModelBooleanInput>;
isFinalized?: InputMaybe<ModelBooleanInput>;
Expand Down Expand Up @@ -2864,7 +2857,6 @@ export type ModelColonyMotionFilterInput = {
createdBy?: InputMaybe<ModelStringInput>;
expenditureId?: InputMaybe<ModelIdInput>;
expenditureSlotId?: InputMaybe<ModelIntInput>;
gasEstimate?: InputMaybe<ModelStringInput>;
hasObjection?: InputMaybe<ModelBooleanInput>;
id?: InputMaybe<ModelIdInput>;
isDecision?: InputMaybe<ModelBooleanInput>;
Expand Down Expand Up @@ -3869,7 +3861,6 @@ export type ModelSubscriptionColonyMotionFilterInput = {
createdBy?: InputMaybe<ModelSubscriptionStringInput>;
expenditureId?: InputMaybe<ModelSubscriptionIdInput>;
expenditureSlotId?: InputMaybe<ModelSubscriptionIntInput>;
gasEstimate?: InputMaybe<ModelSubscriptionStringInput>;
hasObjection?: InputMaybe<ModelSubscriptionBooleanInput>;
id?: InputMaybe<ModelSubscriptionIdInput>;
isDecision?: InputMaybe<ModelSubscriptionBooleanInput>;
Expand Down Expand Up @@ -8100,7 +8091,6 @@ export type UpdateColonyMotionInput = {
expenditureFunding?: InputMaybe<Array<ExpenditureFundingItemInput>>;
expenditureId?: InputMaybe<Scalars['ID']>;
expenditureSlotId?: InputMaybe<Scalars['Int']>;
gasEstimate?: InputMaybe<Scalars['String']>;
hasObjection?: InputMaybe<Scalars['Boolean']>;
id: Scalars['ID'];
isDecision?: InputMaybe<Scalars['Boolean']>;
Expand Down
3 changes: 0 additions & 3 deletions src/handlers/motions/motionCreated/handlers/addDomain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { getPendingMetadataDatabaseId } from '~utils';
Expand All @@ -8,7 +7,6 @@ export const handleAddDomainMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { transactionHash } = event;
if (!colonyAddress) {
Expand All @@ -25,6 +23,5 @@ export const handleAddDomainMotion = async (
await createMotionInDB(colonyAddress, event, {
type: motionNameMapping[name],
pendingDomainMetadataId,
gasEstimate: gasEstimate.toString(),
});
};
3 changes: 0 additions & 3 deletions src/handlers/motions/motionCreated/handlers/editColony.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { getPendingMetadataDatabaseId } from '~utils';
Expand All @@ -8,7 +7,6 @@ export const handleEditColonyMotion = async (
colonyAddress: string,
event: ContractEvent,
{ name }: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { transactionHash } = event;
if (!colonyAddress) {
Expand All @@ -22,6 +20,5 @@ export const handleEditColonyMotion = async (
await createMotionInDB(colonyAddress, event, {
type: motionNameMapping[name],
pendingColonyMetadataId,
gasEstimate: gasEstimate.toString(),
});
};
3 changes: 0 additions & 3 deletions src/handlers/motions/motionCreated/handlers/editDomain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { getDomainDatabaseId, getPendingMetadataDatabaseId } from '~utils';
Expand All @@ -8,7 +7,6 @@ export const handleEditDomainMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { transactionHash } = event;
if (!colonyAddress) {
Expand All @@ -27,6 +25,5 @@ export const handleEditDomainMotion = async (
type: motionNameMapping[name],
pendingDomainMetadataId,
fromDomainId: getDomainDatabaseId(colonyAddress, nativeDomainId),
gasEstimate: gasEstimate.toString(),
});
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { createMotionInDB } from '../../helpers';
Expand All @@ -12,7 +11,6 @@ export default async (
colonyAddress: string,
event: ContractEvent,
{ name, args: actionArgs }: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { args } = event;
const [, , expenditureId] = actionArgs;
Expand All @@ -27,7 +25,6 @@ export default async (
fromDomainId: colonyAddress
? getDomainDatabaseId(colonyAddress, domainId)
: undefined,
gasEstimate: gasEstimate.toString(),
expenditureId: getExpenditureDatabaseId(
colonyAddress,
toNumber(expenditureId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { createMotionInDB } from '../../helpers';
Expand All @@ -12,7 +11,6 @@ export default async (
colonyAddress: string,
event: ContractEvent,
{ name, args: actionArgs }: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { args } = event;
const [, , , , expenditureId] = actionArgs;
Expand All @@ -23,7 +21,6 @@ export default async (
fromDomainId: colonyAddress
? getDomainDatabaseId(colonyAddress, domainId)
: undefined,
gasEstimate: gasEstimate.toString(),
expenditureId: getExpenditureDatabaseId(
colonyAddress,
toNumber(expenditureId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { createMotionInDB } from '../../helpers';
Expand All @@ -12,7 +11,6 @@ export default async (
colonyAddress: string,
event: ContractEvent,
{ name, args: actionArgs }: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { args } = event;
const [, , expenditureId] = actionArgs;
Expand All @@ -27,7 +25,6 @@ export default async (
fromDomainId: colonyAddress
? getDomainDatabaseId(colonyAddress, domainId)
: undefined,
gasEstimate: gasEstimate.toString(),
expenditureId: getExpenditureDatabaseId(
colonyAddress,
toNumber(expenditureId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TransactionDescription } from 'ethers/lib/utils';
import { Id } from '@colony/colony-js';
import { BigNumber } from 'ethers';
import { ContractEvent, motionNameMapping } from '~types';
import { getDomainDatabaseId } from '~utils';

Expand All @@ -10,7 +9,6 @@ export const handleMakeArbitraryTransactionsMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { name, args: actionArgs } = parsedAction;
const [recipients] = actionArgs;
Expand All @@ -19,6 +17,5 @@ export const handleMakeArbitraryTransactionsMotion = async (
type: motionNameMapping[name],
recipientAddress: recipients[0],
fromDomainId: getDomainDatabaseId(colonyAddress, Id.RootDomain),
gasEstimate: gasEstimate.toString(),
});
};
5 changes: 0 additions & 5 deletions src/handlers/motions/motionCreated/handlers/metadataDelta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ColonyActionType } from '~graphql';
import { ContractEvent } from '~types';
Expand All @@ -16,7 +15,6 @@ export const handleMetadataDeltaMotion = async (
colonyAddress: string,
event: ContractEvent,
desc: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
try {
const operationString = desc.args[0];
Expand All @@ -36,23 +34,20 @@ export const handleMetadataDeltaMotion = async (
await createMotionInDB(colonyAddress, event, {
type: ColonyActionType.AddVerifiedMembersMotion,
members: operation.payload,
gasEstimate: gasEstimate.toString(),
});
}

if (isRemoveVerifiedMembersOperation(operation)) {
await createMotionInDB(colonyAddress, event, {
type: ColonyActionType.RemoveVerifiedMembersMotion,
members: operation.payload,
gasEstimate: gasEstimate.toString(),
});
}

if (isManageTokensOperation(operation)) {
await manageTokensMotionHandler({
colonyAddress,
event,
gasEstimate,
operation,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import {
import { createMotionInDB } from '../../helpers';
import { ColonyActionType } from '~graphql';
import { ContractEvent } from '~types';
import { BigNumber } from 'ethers';

export const manageTokensMotionHandler = async ({
colonyAddress,
event,
gasEstimate,
operation,
}: {
colonyAddress: string;
event: ContractEvent;
gasEstimate: BigNumber;
operation: MetadataDeltaOperation;
}): Promise<void> => {
const tokenAddresses = operation.payload;
Expand All @@ -40,6 +37,5 @@ export const manageTokensMotionHandler = async ({
removed: modifiedTokenAddresses.removed,
unaffected: unaffectedTokenAddresses,
},
gasEstimate: gasEstimate.toString(),
});
};
3 changes: 0 additions & 3 deletions src/handlers/motions/motionCreated/handlers/mintTokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { getColonyTokenAddress, getDomainDatabaseId } from '~utils';
Expand All @@ -8,7 +7,6 @@ export const handleMintTokensMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const {
args: { domainId },
Expand All @@ -26,6 +24,5 @@ export const handleMintTokensMotion = async (
tokenAddress,
fromDomainId: getDomainDatabaseId(colonyAddress, domainId),
amount,
gasEstimate: gasEstimate.toString(),
});
};
2 changes: 0 additions & 2 deletions src/handlers/motions/motionCreated/handlers/moveFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const handleMoveFundsMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { blockNumber } = event;

Expand Down Expand Up @@ -64,6 +63,5 @@ export const handleMoveFundsMotion = async (
toDomainId: toDomainId
? getDomainDatabaseId(colonyAddress, toNumber(toDomainId))
: undefined,
gasEstimate: gasEstimate.toString(),
});
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Result, TransactionDescription } from 'ethers/lib/utils';
import { BigNumber, utils } from 'ethers';
import { utils } from 'ethers';
import { getCachedColonyClient, output } from '~utils';
import { ContractEvent, ContractMethodSignatures } from '~types';
import { AnyColonyClient } from '@colony/colony-js';
Expand Down Expand Up @@ -52,7 +52,6 @@ export const handleMulticallMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const colonyClient = await getCachedColonyClient(colonyAddress);

Expand All @@ -63,12 +62,6 @@ export const handleMulticallMotion = async (
// Multicall takes an array of an array of encoded function calls
const encodedFunctions = parsedAction.args[0];

// Multicall can have an arbitrary number of underlying function calls. Difficult to predict in advance how much
// gas executing this action will consume. Let's start by assuming 100k gas per action.
const updatedGasEstimate = gasEstimate
.add(BigNumber.from(encodedFunctions.length ?? 0).mul(100000))
.toString();

// We need to determine which multicallMotion this is and pass it to the appropriate handler
const decodedFunctions = decodeFunctions(encodedFunctions, colonyClient);

Expand All @@ -78,7 +71,6 @@ export const handleMulticallMotion = async (
colonyAddress,
event,
decodedFunctions,
gasEstimate: updatedGasEstimate,
});

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const isEditLockedExpenditureMotion: MulticallValidator = ({
export const editLockedExpenditureMotionHandler: MulticallHandler = async ({
colonyAddress,
event,
gasEstimate,
decodedFunctions,
}) => {
/**
Expand Down Expand Up @@ -106,7 +105,6 @@ export const editLockedExpenditureMotionHandler: MulticallHandler = async ({

createMotionInDB(colonyAddress, event, {
type: ColonyActionType.EditExpenditureMotion,
gasEstimate,
expenditureId: expenditure.id,
editedExpenditureSlots: updatedSlots,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const fundExpenditureMotionHandler: MulticallHandler = async ({
colonyAddress,
event,
decodedFunctions,
gasEstimate,
}) => {
// @NOTE: We get the target pot ID from the first multicall function
// This means if the multicall funds multiple expenditures, we will only create a motion for the first one
Expand Down Expand Up @@ -66,7 +65,6 @@ export const fundExpenditureMotionHandler: MulticallHandler = async ({

await createMotionInDB(colonyAddress, event, {
type: ColonyActionType.FundExpenditureMotion,
gasEstimate,
expenditureId: expenditure.id,
expenditureFunding: fundingItems,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { DecodedFunction } from '../multicall';
interface MulticallHandlerParams {
colonyAddress: string;
event: ContractEvent;
gasEstimate: string;
decodedFunctions: DecodedFunction[];
}

export type MulticallHandler = ({
event,
decodedFunctions,
gasEstimate,
}: MulticallHandlerParams) => void | Promise<void>;

export type MulticallValidator = ({
Expand Down
3 changes: 0 additions & 3 deletions src/handlers/motions/motionCreated/handlers/networkUpgrade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TransactionDescription } from 'ethers/lib/utils';
import { BigNumber } from 'ethers';

import { ContractEvent, motionNameMapping } from '~types';
import { toNumber } from '~utils';
Expand All @@ -10,13 +9,11 @@ export const handleNetworkUpgradeMotion = async (
colonyAddress: string,
event: ContractEvent,
parsedAction: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { name, args: actionArgs } = parsedAction;
const newVersion = actionArgs[0];
await createMotionInDB(colonyAddress, event, {
type: motionNameMapping[name],
newColonyVersion: toNumber(newVersion),
gasEstimate: gasEstimate.toString(),
});
};
Loading

0 comments on commit 1564942

Please sign in to comment.