Skip to content

Commit 181857e

Browse files
authored
Merge pull request #240 from JoinColony/feat/2216-cancel-streams-via-motions
Feat: enable handler for the cancel streaming payment motion
2 parents 01aed43 + fb17de1 commit 181857e

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

src/graphql/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ export enum ColonyActionType {
390390
CancelExpenditureMotion = 'CANCEL_EXPENDITURE_MOTION',
391391
/** An action related to cancelling a streaming payment */
392392
CancelStreamingPayment = 'CANCEL_STREAMING_PAYMENT',
393+
/** An action related to cancelling a streaming payment via a motion */
394+
CancelStreamingPaymentMotion = 'CANCEL_STREAMING_PAYMENT_MOTION',
393395
/** An action related to editing a Colony's details */
394396
ColonyEdit = 'COLONY_EDIT',
395397
/** An action related to editing a Colony's details via a motion */

src/handlers/motions/motionCreated/handlers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { handleMulticallMotion } from './multicall';
1313
export { handleMakeArbitraryTransactionsMotion } from './makeArbitraryTransactions';
1414
export { handleMetadataDeltaMotion } from './metadataDelta';
1515
export * from './expenditures';
16+
export * from './streamingPayments.ts';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { BigNumber } from 'ethers';
2+
import { TransactionDescription } from 'ethers/lib/utils';
3+
import { ContractEvent, motionNameMapping } from '~types';
4+
import { createMotionInDB } from '../../helpers';
5+
import {
6+
getDomainDatabaseId,
7+
getExpenditureDatabaseId,
8+
toNumber,
9+
} from '~utils';
10+
11+
export default async (
12+
event: ContractEvent,
13+
{ name, args: actionArgs }: TransactionDescription,
14+
gasEstimate: BigNumber,
15+
): Promise<void> => {
16+
const { args, colonyAddress } = event;
17+
const [, , streamingPaymentId] = actionArgs;
18+
const [, , domainId] = args;
19+
20+
if (!colonyAddress) {
21+
return;
22+
}
23+
24+
await createMotionInDB(event, {
25+
type: motionNameMapping[name],
26+
fromDomainId: getDomainDatabaseId(colonyAddress, domainId),
27+
gasEstimate: gasEstimate.toString(),
28+
streamingPaymentId: getExpenditureDatabaseId(
29+
colonyAddress,
30+
toNumber(streamingPaymentId),
31+
),
32+
});
33+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as handleCancelStreamingPaymentsMotion } from './cancelStreamingPaymentsMotion';

src/handlers/motions/motionCreated/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AnyStakedExpenditureClient,
77
AnyStagedExpenditureClient,
88
AnyVotingReputationClient,
9+
AnyStreamingPaymentsClient,
910
} from '@colony/colony-js';
1011

1112
import { ColonyOperations, ContractEvent, MotionEvents } from '~types';
@@ -45,6 +46,7 @@ interface MotionActionClients {
4546
oneTxPaymentClient?: AnyOneTxPaymentClient | null;
4647
stakedExpenditureClient?: AnyStakedExpenditureClient | null;
4748
stagedExpenditureClient?: AnyStagedExpenditureClient | null;
49+
streamingPaymentsClient?: AnyStreamingPaymentsClient | null;
4850
}
4951

5052
export const parseAction = (

src/handlers/motions/motionCreated/motionCreated.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { BigNumber, constants } from 'ethers';
22
import { StaticJsonRpcProvider } from '@ethersproject/providers';
33

4-
import { ColonyOperations, ContractEvent } from '~types';
4+
import {
5+
ColonyOperations,
6+
ContractEvent,
7+
StreamingPaymentsOperations,
8+
} from '~types';
59
import {
610
getCachedColonyClient,
711
getStakedExpenditureClient,
812
getStagedExpenditureClient,
913
getOneTxPaymentClient,
1014
getVotingClient,
1115
verbose,
16+
getStreamingPaymentsClient,
1217
} from '~utils';
1318
import { SimpleTransactionDescription, parseAction } from './helpers';
1419
import {
@@ -30,6 +35,7 @@ import {
3035
handleCancelExpenditureViaArbitrationMotion,
3136
handleFinalizeExpenditureViaArbitrationMotion,
3237
handleReleaseStagedPaymentViaArbitration,
38+
handleCancelStreamingPaymentsMotion,
3339
} from './handlers';
3440

3541
export default async (event: ContractEvent): Promise<void> => {
@@ -60,6 +66,10 @@ export default async (event: ContractEvent): Promise<void> => {
6066
colonyAddress,
6167
);
6268

69+
const streamingPaymentsClient = await getStreamingPaymentsClient(
70+
colonyAddress,
71+
);
72+
6373
const motion = await votingReputationClient.getMotion(motionId, {
6474
blockTag: blockNumber,
6575
});
@@ -68,6 +78,7 @@ export default async (event: ContractEvent): Promise<void> => {
6878
oneTxPaymentClient,
6979
stakedExpenditureClient,
7080
stagedExpenditureClient,
81+
streamingPaymentsClient,
7182
});
7283

7384
let gasEstimate: BigNumber;
@@ -251,6 +262,15 @@ export default async (event: ContractEvent): Promise<void> => {
251262
break;
252263
}
253264

265+
case StreamingPaymentsOperations.CancelStreamingPayment: {
266+
await handleCancelStreamingPaymentsMotion(
267+
event,
268+
parsedAction,
269+
gasEstimate,
270+
);
271+
break;
272+
}
273+
254274
default: {
255275
break;
256276
}

src/types/motions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export enum ColonyOperations {
2626
ReleaseStagedPaymentViaArbitration = 'releaseStagedPaymentViaArbitration',
2727
}
2828

29+
export enum StreamingPaymentsOperations {
30+
CancelStreamingPayment = 'cancel',
31+
}
32+
2933
export enum MotionEvents {
3034
MotionCreated = 'MotionCreated',
3135
MotionStaked = 'MotionStaked',
@@ -69,6 +73,8 @@ export const motionNameMapping: { [key: string]: ColonyActionType } = {
6973
ColonyActionType.SetExpenditureStateMotion,
7074
[ColonyOperations.ReleaseStagedPaymentViaArbitration]:
7175
ColonyActionType.ReleaseStagedPaymentMotion,
76+
[StreamingPaymentsOperations.CancelStreamingPayment]:
77+
ColonyActionType.CancelStreamingPaymentMotion,
7278
};
7379

7480
export enum MotionSide {

0 commit comments

Comments
 (0)