Skip to content

Commit

Permalink
feat: enable handler for streaming payment actions made via motions
Browse files Browse the repository at this point in the history
  • Loading branch information
rumzledz authored and jakubcolony committed Jun 25, 2024
1 parent f5922ad commit c4711ec
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/graphql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ export enum ColonyActionType {
CancelExpenditureMotion = 'CANCEL_EXPENDITURE_MOTION',
/** An action related to cancelling a streaming payment */
CancelStreamingPayment = 'CANCEL_STREAMING_PAYMENT',
/** An action related to cancelling a streaming payment via a motion */
CancelStreamingPaymentMotion = 'CANCEL_STREAMING_PAYMENT_MOTION',
/** An action related to editing a Colony's details */
ColonyEdit = 'COLONY_EDIT',
/** An action related to editing a Colony's details via a motion */
Expand Down
1 change: 1 addition & 0 deletions src/handlers/motions/motionCreated/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { handleMulticallMotion } from './multicall';
export { handleMakeArbitraryTransactionsMotion } from './makeArbitraryTransactions';
export { handleMetadataDeltaMotion } from './metadataDelta';
export * from './expenditures';
export * from './streamingPayments.ts';
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { BigNumber } from 'ethers';
import { TransactionDescription } from 'ethers/lib/utils';
import { ContractEvent, motionNameMapping } from '~types';
import { createMotionInDB } from '../../helpers';
import {
getDomainDatabaseId,
getExpenditureDatabaseId,
toNumber,
} from '~utils';

export default async (
colonyAddress: string,
event: ContractEvent,
{ name, args: actionArgs }: TransactionDescription,
gasEstimate: BigNumber,
): Promise<void> => {
const { args } = event;
const [, , streamingPaymentId] = actionArgs;
const [, , domainId] = args;

await createMotionInDB(colonyAddress, event, {
type: motionNameMapping[name],
fromDomainId: colonyAddress
? getDomainDatabaseId(colonyAddress, domainId)
: undefined,
gasEstimate: gasEstimate.toString(),
streamingPaymentId: getExpenditureDatabaseId(
colonyAddress,
toNumber(streamingPaymentId),
),
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as handleCancelStreamingPaymentsMotion } from './cancelStreamingPaymentsMotion';
2 changes: 2 additions & 0 deletions src/handlers/motions/motionCreated/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AnyStakedExpenditureClient,
AnyStagedExpenditureClient,
AnyVotingReputationClient,
AnyStreamingPaymentsClient,
} from '@colony/colony-js';

import { ColonyOperations, ContractEvent, MotionEvents } from '~types';
Expand Down Expand Up @@ -45,6 +46,7 @@ interface MotionActionClients {
oneTxPaymentClient?: AnyOneTxPaymentClient | null;
stakedExpenditureClient?: AnyStakedExpenditureClient | null;
stagedExpenditureClient?: AnyStagedExpenditureClient | null;
streamingPaymentsClient?: AnyStreamingPaymentsClient | null;
}

export const parseAction = (
Expand Down
23 changes: 22 additions & 1 deletion src/handlers/motions/motionCreated/motionCreated.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { BigNumber, constants } from 'ethers';
import { StaticJsonRpcProvider } from '@ethersproject/providers';

import { ColonyOperations, EventHandler } from '~types';
import {
ColonyOperations,
EventHandler,
StreamingPaymentsOperations,
} from '~types';
import {
getCachedColonyClient,
getStakedExpenditureClient,
getStagedExpenditureClient,
getOneTxPaymentClient,
getVotingClient,
verbose,
getStreamingPaymentsClient,
} from '~utils';
import { SimpleTransactionDescription, parseAction } from './helpers';
import {
Expand All @@ -30,6 +35,7 @@ import {
handleCancelExpenditureViaArbitrationMotion,
handleFinalizeExpenditureViaArbitrationMotion,
handleReleaseStagedPaymentViaArbitration,
handleCancelStreamingPaymentsMotion,
} from './handlers';
import { ExtensionEventListener } from '~eventListeners';

Expand Down Expand Up @@ -60,6 +66,10 @@ export const handleMotionCreated: EventHandler = async (
colonyAddress,
);

const streamingPaymentsClient = await getStreamingPaymentsClient(
colonyAddress,
);

const motion = await votingReputationClient.getMotion(motionId, {
blockTag: blockNumber,
});
Expand All @@ -68,6 +78,7 @@ export const handleMotionCreated: EventHandler = async (
oneTxPaymentClient,
stakedExpenditureClient,
stagedExpenditureClient,
streamingPaymentsClient,
});

let gasEstimate: BigNumber;
Expand Down Expand Up @@ -313,6 +324,16 @@ export const handleMotionCreated: EventHandler = async (
break;
}

case StreamingPaymentsOperations.CancelStreamingPayment: {
await handleCancelStreamingPaymentsMotion(
colonyAddress,
event,
parsedAction,
gasEstimate,
);
break;
}

default: {
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/motions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export enum ColonyOperations {
ReleaseStagedPaymentViaArbitration = 'releaseStagedPaymentViaArbitration',
}

export enum StreamingPaymentsOperations {
CancelStreamingPayment = 'cancel',
}

export enum MotionEvents {
MotionCreated = 'MotionCreated',
MotionStaked = 'MotionStaked',
Expand Down Expand Up @@ -69,6 +73,8 @@ export const motionNameMapping: { [key: string]: ColonyActionType } = {
ColonyActionType.SetExpenditureStateMotion,
[ColonyOperations.ReleaseStagedPaymentViaArbitration]:
ColonyActionType.ReleaseStagedPaymentMotion,
[StreamingPaymentsOperations.CancelStreamingPayment]:
ColonyActionType.CancelStreamingPaymentMotion,
};

export enum MotionSide {
Expand Down

0 comments on commit c4711ec

Please sign in to comment.