Skip to content

Commit 1231f3b

Browse files
authored
fix: thegraph detector (#960)
1 parent db3138d commit 1231f3b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

packages/payment-detection/src/thegraph/info-retriever.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ export class TheGraphInfoRetriever {
5050

5151
private filterPaymentEvents(payment: PaymentEventResultFragment, params: TransferEventsParams) {
5252
// Check contract address matches expected
53-
if (formatAddress(payment.contractAddress) !== params.contractAddress) {
53+
if (formatAddress(payment.contractAddress) !== formatAddress(params.contractAddress)) {
5454
return false;
5555
}
5656
// Check paid token tokens matches expected (conversion only)
5757
if (
5858
payment.tokenAddress &&
59+
params.acceptedTokens &&
60+
params.acceptedTokens.length > 0 &&
5961
!params.acceptedTokens?.includes(formatAddress(payment.tokenAddress, 'tokenAddress'))
6062
) {
6163
return false;

packages/payment-detection/test/erc20/fee-proxy-contract.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,77 @@ describe('api/erc20/fee-proxy-contract', () => {
365365
expect(parameters.gasUsed).toBe('79220');
366366
expect(parameters.gasPrice).toBe('1500000011');
367367
});
368+
369+
it('can retrieve payment using thegraph info retriever', async () => {
370+
const mockRequest: RequestLogicTypes.IRequest = {
371+
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
372+
currency: {
373+
network: 'mainnet',
374+
type: RequestLogicTypes.CURRENCY.ERC20,
375+
value: '0x967da4048cd07ab37855c090aaf366e4ce1b9f48',
376+
},
377+
events: [],
378+
expectedAmount: '168040800000000000000000',
379+
extensions: {
380+
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT]: {
381+
events: [
382+
{
383+
name: 'create',
384+
parameters: {
385+
feeAddress: '0x35d0e078755Cd84D3E0656cAaB417Dee1d7939c7',
386+
feeAmount: '13386000000000000000',
387+
paymentAddress: '0x6c9E04997000d6A8a353951231923d776d4Cdff2',
388+
salt: 'c75c317e05c52f12',
389+
},
390+
timestamp: 1665989825,
391+
},
392+
],
393+
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT,
394+
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
395+
values: {
396+
salt: 'c75c317e05c52f12',
397+
paymentAddress: '0x6c9E04997000d6A8a353951231923d776d4Cdff2',
398+
feeAddress: '0x35d0e078755Cd84D3E0656cAaB417Dee1d7939c7',
399+
feeAmount: '13386000000000000000',
400+
},
401+
version: '0.2.0',
402+
},
403+
},
404+
extensionsData: [],
405+
requestId: '01169f05b855a57396552cc0052b161f70590bdf9c5371649cd89a70c65fb586db',
406+
state: RequestLogicTypes.STATE.CREATED,
407+
timestamp: 0,
408+
version: '0.2',
409+
};
410+
erc20FeeProxyContract = new ERC20FeeProxyPaymentDetector({
411+
advancedLogic: mockAdvancedLogic,
412+
currencyManager,
413+
getSubgraphClient: () => ({
414+
GetPaymentsAndEscrowState: jest.fn().mockImplementation(({ reference }) => ({
415+
payments: [
416+
{
417+
contractAddress: '0x370de27fdb7d1ff1e1baa7d11c5820a324cf623c',
418+
tokenAddress: '0x967da4048cd07ab37855c090aaf366e4ce1b9f48',
419+
to: '0x6c9e04997000d6a8a353951231923d776d4cdff2',
420+
from: '0x15339d48fbe31e349a507fd6d48eb01c45fdc79a',
421+
amount: '168040800000000000000000',
422+
feeAmount: '13386000000000000000',
423+
reference: '0x5ac7241d9e6f419409e439c8429eea2f8f089d76528fd1d5df7496a3e58b5ce1',
424+
block: 15767215,
425+
txHash: '0x456d67cba236778e91a901e97c71684e82317dc2679d1b5c6bfa6d420d636b7d',
426+
gasUsed: '73152',
427+
gasPrice: '12709127644',
428+
},
429+
].filter((x) => x.reference.toLowerCase() === reference.toLowerCase()),
430+
escrowEvents: [],
431+
})),
432+
GetLastSyncedBlock: jest.fn(),
433+
GetSyncedBlock: jest.fn(),
434+
}),
435+
});
436+
437+
const { balance, error } = await erc20FeeProxyContract.getBalance(mockRequest);
438+
expect(error).toBeUndefined();
439+
expect(balance).toBe('168040800000000000000000');
440+
});
368441
});

0 commit comments

Comments
 (0)