diff --git a/src/graphql/generated.ts b/src/graphql/generated.ts index 97fc6787..e73a8b30 100644 --- a/src/graphql/generated.ts +++ b/src/graphql/generated.ts @@ -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 */ diff --git a/src/handlers/motions/motionCreated/handlers/index.ts b/src/handlers/motions/motionCreated/handlers/index.ts index a56d73e2..a56d9410 100644 --- a/src/handlers/motions/motionCreated/handlers/index.ts +++ b/src/handlers/motions/motionCreated/handlers/index.ts @@ -13,3 +13,4 @@ export { handleMulticallMotion } from './multicall'; export { handleMakeArbitraryTransactionsMotion } from './makeArbitraryTransactions'; export { handleMetadataDeltaMotion } from './metadataDelta'; export * from './expenditures'; +export * from './streamingPayments.ts'; diff --git a/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/cancelStreamingPaymentsMotion.ts b/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/cancelStreamingPaymentsMotion.ts new file mode 100644 index 00000000..e02b9cab --- /dev/null +++ b/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/cancelStreamingPaymentsMotion.ts @@ -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 => { + 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), + ), + }); +}; diff --git a/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/index.ts b/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/index.ts new file mode 100644 index 00000000..d04a4d8c --- /dev/null +++ b/src/handlers/motions/motionCreated/handlers/streamingPayments.ts/index.ts @@ -0,0 +1 @@ +export { default as handleCancelStreamingPaymentsMotion } from './cancelStreamingPaymentsMotion'; diff --git a/src/handlers/motions/motionCreated/helpers.ts b/src/handlers/motions/motionCreated/helpers.ts index ffbfed07..219fe745 100644 --- a/src/handlers/motions/motionCreated/helpers.ts +++ b/src/handlers/motions/motionCreated/helpers.ts @@ -6,6 +6,7 @@ import { AnyStakedExpenditureClient, AnyStagedExpenditureClient, AnyVotingReputationClient, + AnyStreamingPaymentsClient, } from '@colony/colony-js'; import { ColonyOperations, ContractEvent, MotionEvents } from '~types'; @@ -45,6 +46,7 @@ interface MotionActionClients { oneTxPaymentClient?: AnyOneTxPaymentClient | null; stakedExpenditureClient?: AnyStakedExpenditureClient | null; stagedExpenditureClient?: AnyStagedExpenditureClient | null; + streamingPaymentsClient?: AnyStreamingPaymentsClient | null; } export const parseAction = ( diff --git a/src/handlers/motions/motionCreated/motionCreated.ts b/src/handlers/motions/motionCreated/motionCreated.ts index cc0b7c2d..db2c69f1 100644 --- a/src/handlers/motions/motionCreated/motionCreated.ts +++ b/src/handlers/motions/motionCreated/motionCreated.ts @@ -1,7 +1,11 @@ import { BigNumber, constants } from 'ethers'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; -import { ColonyOperations, EventHandler } from '~types'; +import { + ColonyOperations, + EventHandler, + StreamingPaymentsOperations, +} from '~types'; import { getCachedColonyClient, getStakedExpenditureClient, @@ -9,6 +13,7 @@ import { getOneTxPaymentClient, getVotingClient, verbose, + getStreamingPaymentsClient, } from '~utils'; import { SimpleTransactionDescription, parseAction } from './helpers'; import { @@ -30,6 +35,7 @@ import { handleCancelExpenditureViaArbitrationMotion, handleFinalizeExpenditureViaArbitrationMotion, handleReleaseStagedPaymentViaArbitration, + handleCancelStreamingPaymentsMotion, } from './handlers'; import { ExtensionEventListener } from '~eventListeners'; @@ -60,6 +66,10 @@ export const handleMotionCreated: EventHandler = async ( colonyAddress, ); + const streamingPaymentsClient = await getStreamingPaymentsClient( + colonyAddress, + ); + const motion = await votingReputationClient.getMotion(motionId, { blockTag: blockNumber, }); @@ -68,6 +78,7 @@ export const handleMotionCreated: EventHandler = async ( oneTxPaymentClient, stakedExpenditureClient, stagedExpenditureClient, + streamingPaymentsClient, }); let gasEstimate: BigNumber; @@ -313,6 +324,16 @@ export const handleMotionCreated: EventHandler = async ( break; } + case StreamingPaymentsOperations.CancelStreamingPayment: { + await handleCancelStreamingPaymentsMotion( + colonyAddress, + event, + parsedAction, + gasEstimate, + ); + break; + } + default: { break; } diff --git a/src/types/motions.ts b/src/types/motions.ts index 4c7d45b9..73294d48 100644 --- a/src/types/motions.ts +++ b/src/types/motions.ts @@ -26,6 +26,10 @@ export enum ColonyOperations { ReleaseStagedPaymentViaArbitration = 'releaseStagedPaymentViaArbitration', } +export enum StreamingPaymentsOperations { + CancelStreamingPayment = 'cancel', +} + export enum MotionEvents { MotionCreated = 'MotionCreated', MotionStaked = 'MotionStaked', @@ -69,6 +73,8 @@ export const motionNameMapping: { [key: string]: ColonyActionType } = { ColonyActionType.SetExpenditureStateMotion, [ColonyOperations.ReleaseStagedPaymentViaArbitration]: ColonyActionType.ReleaseStagedPaymentMotion, + [StreamingPaymentsOperations.CancelStreamingPayment]: + ColonyActionType.CancelStreamingPaymentMotion, }; export enum MotionSide {