Skip to content

Commit f209e19

Browse files
authored
Merge pull request #219 from JoinColony/feat/2206-claim-streaming-payments
Feat/2206 claim streaming payments
2 parents 80b035f + 7ecee0f commit f209e19

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

src/eventListeners/extension/streamingPayments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const setupListenersForStreamingPayments = (
2626
ContractEventsSignatures.StartTimeSet,
2727
ContractEventsSignatures.EndTimeSet,
2828
ContractEventsSignatures.ClaimWaived,
29+
ContractEventsSignatures.StreamingPaymentClaimed,
2930
];
3031

3132
events.forEach((eventSignature) =>

src/eventProcessor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
handleSetTokenAuthority,
5454
handleExpenditureStateChanged,
5555
handleStreamingPaymentEndTimeSet,
56+
handleStreamingPaymentClaimed,
5657
} from './handlers';
5758

5859
dotenv.config();
@@ -361,6 +362,11 @@ export default async (event: ContractEvent): Promise<void> => {
361362
return;
362363
}
363364

365+
case ContractEventsSignatures.StreamingPaymentClaimed: {
366+
await handleStreamingPaymentClaimed(event);
367+
return;
368+
}
369+
364370
default: {
365371
return;
366372
}

src/graphql/generated.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ export type CreateSafeTransactionInput = {
14761476
};
14771477

14781478
export type CreateStreamingPaymentInput = {
1479+
claims?: InputMaybe<Array<StreamingPaymentClaimInput>>;
14791480
createdAt?: InputMaybe<Scalars['AWSDateTime']>;
14801481
endTime: Scalars['AWSTimestamp'];
14811482
id?: InputMaybe<Scalars['ID']>;
@@ -6745,6 +6746,7 @@ export type StakerRewardsInput = {
67456746
export type StreamingPayment = {
67466747
__typename?: 'StreamingPayment';
67476748
actions?: Maybe<ModelColonyActionConnection>;
6749+
claims?: Maybe<Array<StreamingPaymentClaim>>;
67486750
createdAt: Scalars['AWSDateTime'];
67496751
endTime: Scalars['AWSTimestamp'];
67506752
id: Scalars['ID'];
@@ -6767,6 +6769,19 @@ export type StreamingPaymentActionsArgs = {
67676769
sortDirection?: InputMaybe<ModelSortDirection>;
67686770
};
67696771

6772+
export type StreamingPaymentClaim = {
6773+
__typename?: 'StreamingPaymentClaim';
6774+
amount: Scalars['String'];
6775+
timestamp: Scalars['AWSTimestamp'];
6776+
tokenAddress: Scalars['ID'];
6777+
};
6778+
6779+
export type StreamingPaymentClaimInput = {
6780+
amount: Scalars['String'];
6781+
timestamp: Scalars['AWSTimestamp'];
6782+
tokenAddress: Scalars['ID'];
6783+
};
6784+
67706785
export enum StreamingPaymentEndCondition {
67716786
FixedTime = 'FIXED_TIME',
67726787
LimitReached = 'LIMIT_REACHED',
@@ -7944,6 +7959,7 @@ export type UpdateSafeTransactionInput = {
79447959
};
79457960

79467961
export type UpdateStreamingPaymentInput = {
7962+
claims?: InputMaybe<Array<StreamingPaymentClaimInput>>;
79477963
createdAt?: InputMaybe<Scalars['AWSDateTime']>;
79487964
endTime?: InputMaybe<Scalars['AWSTimestamp']>;
79497965
id: Scalars['ID'];
@@ -9239,6 +9255,12 @@ export type GetStreamingPaymentQuery = {
92399255
tokenAddress: string;
92409256
isClaimed: boolean;
92419257
}> | null;
9258+
claims?: Array<{
9259+
__typename?: 'StreamingPaymentClaim';
9260+
amount: string;
9261+
tokenAddress: string;
9262+
timestamp: number;
9263+
}> | null;
92429264
} | null;
92439265
};
92449266

@@ -10353,6 +10375,11 @@ export const GetStreamingPaymentDocument = gql`
1035310375
tokenAddress
1035410376
isClaimed
1035510377
}
10378+
claims {
10379+
amount
10380+
tokenAddress
10381+
timestamp
10382+
}
1035610383
}
1035710384
}
1035810385
`;

src/graphql/queries/expenditures.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ query GetStreamingPayment($id: ID!) {
3737
tokenAddress
3838
isClaimed
3939
}
40+
claims {
41+
amount
42+
tokenAddress
43+
timestamp
44+
}
4045
}
4146
}

src/handlers/expenditures/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export { default as handleStreamingPaymentEndTimeSet } from './streamingPaymentE
1818
export { default as handleExpenditureMadeViaStake } from './expenditureMadeViaStake';
1919
export { default as handlePaymentTokenUpdated } from './paymentTokenUpdated';
2020
export { default as handleExpenditureStateChanged } from './expenditureStateChanged';
21+
export { default as handleStreamingPaymentClaimed } from './streamingPaymentClaimed';
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { mutate } from '~amplifyClient';
2+
import {
3+
StreamingPaymentClaim,
4+
UpdateStreamingPaymentDocument,
5+
UpdateStreamingPaymentMutation,
6+
UpdateStreamingPaymentMutationVariables,
7+
} from '~graphql';
8+
import { ContractEvent } from '~types';
9+
import { getExpenditureDatabaseId, output, toNumber } from '~utils';
10+
import { getStreamingPaymentFromDB } from './helpers';
11+
12+
export default async (event: ContractEvent): Promise<void> => {
13+
const { colonyAddress, timestamp } = event;
14+
const { amount, streamingPaymentId, token: tokenAddress } = event.args;
15+
const convertedNativeId = toNumber(streamingPaymentId);
16+
17+
if (!colonyAddress) {
18+
return;
19+
}
20+
21+
const databaseId = getExpenditureDatabaseId(colonyAddress, convertedNativeId);
22+
23+
const streamingPayment = await getStreamingPaymentFromDB(databaseId);
24+
if (!streamingPayment) {
25+
output(
26+
`Could not find streaming payment with ID: ${databaseId} in the db. This is a bug and needs investigating.`,
27+
);
28+
return;
29+
}
30+
31+
const newClaim: StreamingPaymentClaim = {
32+
amount: amount.toString(),
33+
tokenAddress,
34+
timestamp,
35+
};
36+
const claims: StreamingPaymentClaim[] = streamingPayment.claims
37+
? [...streamingPayment.claims, newClaim]
38+
: [newClaim];
39+
40+
await mutate<
41+
UpdateStreamingPaymentMutation,
42+
UpdateStreamingPaymentMutationVariables
43+
>(UpdateStreamingPaymentDocument, {
44+
input: {
45+
id: databaseId,
46+
claims,
47+
},
48+
});
49+
};

src/types/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export enum ContractEventsSignatures {
9898
StartTimeSet = 'StartTimeSet(address,uint256,uint256)',
9999
EndTimeSet = 'EndTimeSet(address,uint256,uint256)',
100100
ClaimWaived = 'ClaimWaived(address,uint256,address)',
101+
StreamingPaymentClaimed = 'StreamingPaymentClaimed(address,uint256,address,uint256)',
101102

102103
// Annotations
103104
AnnotateTransaction = 'Annotation(address,bytes32,string)',

0 commit comments

Comments
 (0)