Skip to content

Commit 19660cf

Browse files
Merge branch 'master' into data-format-constraint
2 parents c172038 + 520d348 commit 19660cf

File tree

4 files changed

+219
-9
lines changed

4 files changed

+219
-9
lines changed

packages/payment-detection/src/erc777/superfluid-retriever.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class SuperFluidInfoRetriever {
3939

4040
private getGraphVariables(): GraphPaymentQueryParams {
4141
return {
42-
reference: ethersUtils.keccak256(`0x${this.paymentReference}`),
42+
reference: '0xbeefac' + ethersUtils.keccak256(`0x${this.paymentReference}`).slice(2),
4343
to: this.toAddress,
4444
tokenAddress: this.tokenContractAddress,
4545
};
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
const mockUntagged = [
2+
{
3+
transactionHash: '0x4e334bd4436ad812e30f74b358580cc3bed0407814133147edfb56ad6672bf75',
4+
blockNumber: '9806859',
5+
timestamp: '1639387673',
6+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
7+
flowRate: '0',
8+
oldFlowRate: '385802469135800',
9+
type: 2,
10+
},
11+
{
12+
transactionHash: '0x7fb5c94f9bf20420447576eca6d29c5096241e32bad9522b2b4bfd2d0f2c4134',
13+
blockNumber: '9807033',
14+
timestamp: '1639390285',
15+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
16+
flowRate: '0',
17+
oldFlowRate: '385802469135800',
18+
type: 2,
19+
},
20+
{
21+
transactionHash: '0xaccd30ecb52a3e73d5383a4814d2b284197eae7194127f7a9bf11e6602c65024',
22+
blockNumber: '9814376',
23+
timestamp: '1639500811',
24+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
25+
flowRate: '0',
26+
oldFlowRate: '385802469135800',
27+
type: 2,
28+
},
29+
{
30+
transactionHash: '0xa608d53c68dd9f65b3580b0567cb9f1aa9cb6f53f2ea8474afa81b4288f3056b',
31+
blockNumber: '9989333',
32+
timestamp: '1642161136',
33+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
34+
flowRate: '0',
35+
oldFlowRate: '385802469135800',
36+
type: 2,
37+
},
38+
{
39+
transactionHash: '0x09439c18b22dbc19542781ffb43c322023028f9243663ffdb20709b05b3b5933',
40+
blockNumber: '10014227',
41+
timestamp: '1642534760',
42+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
43+
flowRate: '0',
44+
oldFlowRate: '1666666666666666',
45+
type: 2,
46+
},
47+
{
48+
transactionHash: '0xe06f952a8938570c6cd885fadc85d88a156799a1b9caeb33ecc2e844eac33245',
49+
blockNumber: '10014270',
50+
timestamp: '1642535405',
51+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
52+
flowRate: '0',
53+
oldFlowRate: '1748842592592592',
54+
type: 2,
55+
},
56+
{
57+
transactionHash: '0x6ad94a65ce782dee743fa48981f1bfd53a63b8c3a5a9c4b82db4b05d1a051d07',
58+
blockNumber: '10663840',
59+
timestamp: '1652368813',
60+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
61+
flowRate: '0',
62+
oldFlowRate: '38026486208173',
63+
type: 2,
64+
},
65+
];
66+
const mockFlows = [
67+
[
68+
{
69+
transactionHash: '0xc331a269515c27836051cc4618097f5f1a1c37f79dcb975361022fe3ecfb5cbf',
70+
blockNumber: '9945527',
71+
timestamp: '1641495527',
72+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
73+
flowRate: '385802469135800',
74+
oldFlowRate: '0',
75+
type: 0,
76+
},
77+
{
78+
transactionHash: '0xe472ca1b52751b058fbdaeaffebd98c0cc43b45aa31794b3eb06834ede19f7be',
79+
blockNumber: '9945543',
80+
timestamp: '1641495767',
81+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
82+
flowRate: '0',
83+
oldFlowRate: '385802469135800',
84+
type: 2,
85+
},
86+
{
87+
transactionHash: '0x01b4afd22bbebb8f1d412e65eff38d6375b4802402dc8f42e4a7616507dd59ac',
88+
blockNumber: '9948966',
89+
timestamp: '1641547132',
90+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
91+
flowRate: '385802469135800',
92+
oldFlowRate: '0',
93+
type: 0,
94+
},
95+
{
96+
transactionHash: '0x8c6b3a5fbb91fc0d473958929e561d2f60093954fc208b4a63fb64f17ecba802',
97+
blockNumber: '9948972',
98+
timestamp: '1641547222',
99+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
100+
flowRate: '0',
101+
oldFlowRate: '385802469135800',
102+
type: 2,
103+
},
104+
{
105+
transactionHash: '0x48939ad7fc41180f0bfb0f6b0c24b4acfb6a4c94a5a9d9acf853b6292f029290',
106+
blockNumber: '9989326',
107+
timestamp: '1642161031',
108+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
109+
flowRate: '385802469135800',
110+
oldFlowRate: '0',
111+
type: 0,
112+
},
113+
{
114+
transactionHash: '0x477a848eb92acc640e4f361a6e6aaeaac405a1b18818d4654246621b06dc3cc9',
115+
blockNumber: '10052015',
116+
timestamp: '1643101943',
117+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
118+
flowRate: '385802469135800',
119+
oldFlowRate: '0',
120+
type: 0,
121+
},
122+
{
123+
transactionHash: '0xd2f15b75edba55cd47d7cfee1f2664e8b2ac085bf2f2b07640ab34d6a5b85ee1',
124+
blockNumber: '10052021',
125+
timestamp: '1643102033',
126+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
127+
flowRate: '0',
128+
oldFlowRate: '385802469135800',
129+
type: 2,
130+
},
131+
{
132+
transactionHash: '0x26b91a535858449cf41a9dd07a8195915f1ca96deccff6a5ccc74270db140ed2',
133+
blockNumber: '10185715',
134+
timestamp: '1645131298',
135+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
136+
flowRate: '385802469135800',
137+
oldFlowRate: '0',
138+
type: 0,
139+
},
140+
{
141+
transactionHash: '0xebbe717d09890e51f4f294ca329546e3d70e327a44c0cb2f9148c0e0b72d8c60',
142+
blockNumber: '10185738',
143+
timestamp: '1645131643',
144+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
145+
flowRate: '0',
146+
oldFlowRate: '385802469135800',
147+
type: 2,
148+
},
149+
],
150+
[
151+
{
152+
transactionHash: '0xef22a2e12e75b0737c31cef697e2ba915b7e5ad4d3cb79d027ec823559a882a6',
153+
blockNumber: '10024755',
154+
timestamp: '1642692777',
155+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
156+
flowRate: '385802469135800',
157+
oldFlowRate: '3858024691358',
158+
type: 1,
159+
},
160+
{
161+
transactionHash: '0x0fefa02d90be46eb51a82f02b7a787084c35a895bd833a7c9f0560e315bb4061',
162+
blockNumber: '10024811',
163+
timestamp: '1642693617',
164+
sender: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
165+
flowRate: '0',
166+
oldFlowRate: '385802469135800',
167+
type: 2,
168+
},
169+
],
170+
[
171+
{
172+
transactionHash: '0xdb44f35aa1490d2ddc8bbe7b82e0e3a370f3bf171a55da7a8a5886996e9c468d',
173+
blockNumber: '10047970',
174+
timestamp: '1643041225',
175+
sender: '0x165a26628ac843e97f657e648b004226fbb7f7c5',
176+
flowRate: '1',
177+
oldFlowRate: '0',
178+
type: 0,
179+
},
180+
],
181+
];
182+
export const mockSuperfluidSubgraph = [
183+
{
184+
untagged: mockUntagged,
185+
flow: mockFlows[0],
186+
},
187+
{
188+
untagged: mockUntagged,
189+
flow: mockFlows[1],
190+
},
191+
{
192+
untagged: [],
193+
flow: mockFlows[2],
194+
},
195+
];

packages/payment-detection/test/erc777/superfluid-retriever.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import { SuperFluidInfoRetriever } from '../../src/erc777/superfluid-retriever';
22
import PaymentReferenceCalculator from '../../src/payment-reference-calculator';
33
import { utils } from 'ethers';
44
import { PaymentTypes } from '@requestnetwork/types';
5+
import { GraphQLClient } from 'graphql-request';
6+
import { mocked } from 'ts-jest/utils';
7+
import { mockSuperfluidSubgraph } from './mocks';
8+
9+
jest.mock('graphql-request');
10+
const graphql = mocked(GraphQLClient.prototype);
511

612
describe('api/erc777/superfluid-info-retriever', () => {
713
describe('on untagged requests', () => {
814
it('should get payment events from SuperFluid via subgraph with 1 request', async () => {
915
const paymentData = {
10-
reference: '0xf81e1f6b6ff7cd15ab5538b403c8fdf3fed1f254ce6abcddf18941354039c752',
16+
reference: '0xbeefacf81e1f6b6ff7cd15ab5538b403c8fdf3fed1f254ce6abcddf18941354039c752',
1117
txHash: '0xe472ca1b52751b058fbdaeaffebd98c0cc43b45aa31794b3eb06834ede19f7be',
1218
from: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
1319
to: '0x52e5bcfa46393894afcfe6cd98a6761fa692c594',
@@ -18,12 +24,14 @@ describe('api/erc777/superfluid-info-retriever', () => {
1824
block: '9945543',
1925
token: '0x745861aed1eee363b4aaa5f1994be40b1e05ff90', //fDAIx
2026
};
27+
graphql.request.mockResolvedValue(mockSuperfluidSubgraph[0]);
28+
2129
const paymentReference = PaymentReferenceCalculator.calculate(
2230
paymentData.requestId,
2331
paymentData.salt,
2432
paymentData.to,
2533
);
26-
const onChainReference = utils.keccak256(`0x${paymentReference}`);
34+
const onChainReference = '0xbeefac' + utils.keccak256(`0x${paymentReference}`).slice(2);
2735
expect(onChainReference).toEqual(paymentData.reference);
2836

2937
const graphRetriever = new SuperFluidInfoRetriever(
@@ -48,7 +56,7 @@ describe('api/erc777/superfluid-info-retriever', () => {
4856
describe('on 2 nested requests', () => {
4957
it('should get payment event from SuperFluid via subgraph with 2 requests', async () => {
5058
const paymentData = {
51-
reference: '0x23b12cbc2c59e39389f3c7cd652c4594a3a7595d7e9af265d07878345a6fe488',
59+
reference: '0xbeefac23b12cbc2c59e39389f3c7cd652c4594a3a7595d7e9af265d07878345a6fe488',
5260
from: '0x9c040e2d6fd83a8b35069aa7154b69674961e0f7',
5361
to: '0x52e5bcfa46393894afcfe6cd98a6761fa692c594',
5462
network: 'rinkeby',
@@ -58,12 +66,14 @@ describe('api/erc777/superfluid-info-retriever', () => {
5866
requestId: '0288792633ff0ec72a7dbdefb886d2db6cccfa98287320839c2f273c7a4e3ce7e2',
5967
token: '0x745861aed1eee363b4aaa5f1994be40b1e05ff90', //fDAIx
6068
};
69+
graphql.request.mockResolvedValue(mockSuperfluidSubgraph[1]);
70+
6171
const paymentReference = PaymentReferenceCalculator.calculate(
6272
paymentData.requestId,
6373
paymentData.salt,
6474
paymentData.to,
6575
);
66-
const onChainReference = utils.keccak256(`0x${paymentReference}`);
76+
const onChainReference = '0xbeefac' + utils.keccak256(`0x${paymentReference}`).slice(2);
6777
expect(onChainReference).toEqual(paymentData.reference);
6878
const graphRetriever = new SuperFluidInfoRetriever(
6979
paymentReference,
@@ -83,22 +93,24 @@ describe('api/erc777/superfluid-info-retriever', () => {
8393
describe('on ongoing request', () => {
8494
it('should get payment event from SuperFluid via subgraph with ongoing request', async () => {
8595
const paymentData = {
86-
reference: '0x272b93b983e5435bdba30902066ca3a0839cdb05bd526d648f6b0db79adbd2b5',
96+
reference: '0xbeefac272b93b983e5435bdba30902066ca3a0839cdb05bd526d648f6b0db79adbd2b5',
8797
from: '0x165a26628ac843e97f657e648b004226fbb7f7c5',
8898
to: '0xe7e6431f08db273d915b49888f0c67ef61802e05',
8999
network: 'rinkeby',
90100
salt: '0ee84db293a752c6',
91101
amount: '1',
92102
requestId: '0688792633ff0ec72a7dbdefb886d2db6cccfa98287320839c2f273c7a4e3ce7e2',
93-
token: '0x0f1d7c55a2b133e000ea10eec03c774e0d6796e8', //fDAIx
103+
token: '0x0f1d7c55a2b133e000ea10eec03c774e0d6796e8', //fUSDCx
94104
timestamp: 1643041225,
95105
};
106+
graphql.request.mockResolvedValue(mockSuperfluidSubgraph[2]);
107+
96108
const paymentReference = PaymentReferenceCalculator.calculate(
97109
paymentData.requestId,
98110
paymentData.salt,
99111
paymentData.to,
100112
);
101-
const onChainReference = utils.keccak256(`0x${paymentReference}`);
113+
const onChainReference = '0xbeefac' + utils.keccak256(`0x${paymentReference}`).slice(2);
102114
expect(onChainReference).toEqual(paymentData.reference);
103115
const graphRetriever = new SuperFluidInfoRetriever(
104116
paymentReference,

packages/payment-processor/src/payment/erc777-stream.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ export async function payErc777StreamRequest(
4747
// - use expectedStartDate to compute offset between start of invoicing and start of streaming
4848
// - start fee streaming
4949
const { paymentReference, paymentAddress, expectedFlowRate } = getRequestPaymentValues(request);
50+
// Superfluid payments of requests use the generic field `userData` to index payments.
51+
// Since it's a multi-purpose field, payments will use a fix-prefix heading the payment reference,
52+
// in order to speed up the indexing and payment detection.
5053
const streamPayOp = sf.cfaV1.createFlow({
5154
flowRate: expectedFlowRate ?? '0',
5255
receiver: paymentAddress,
5356
superToken: superToken.address,
54-
userData: `0x${paymentReference}`,
57+
userData: `0xbeefac${paymentReference}`,
5558
overrides: overrides,
5659
});
5760
const batchCall = sf.batchCall([streamPayOp]);

0 commit comments

Comments
 (0)