Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: escrow detector class #773

Merged
merged 35 commits into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4493bcf
wip: first step towards merging events from escrow and payments
yomarion Jan 4, 2022
312b168
get contract events
Dadogg80 Jan 5, 2022
377600b
escrowcustomEventParameters
Dadogg80 Jan 5, 2022
b1bcf51
Escrow-events
Dadogg80 Jan 5, 2022
2833cce
wip: generic network event type
yomarion Jan 5, 2022
c7e322c
test: escrow-info-retriever
Dadogg80 Jan 6, 2022
a5c8a2b
info retriever tests
Dadogg80 Jan 6, 2022
3d4041e
test: escrow-info-retriever
Dadogg80 Jan 6, 2022
5af0d3c
fix custom-detector
Dadogg80 Jan 10, 2022
df91be0
custom events
Dadogg80 Jan 11, 2022
02b18c3
feat: payment-detection for escrow and custom contracts (#726)
yomarion Feb 14, 2022
1e9f05c
Merge branch 'master' into ivo-escrow-detector-class
KolevDarko Feb 14, 2022
36b5692
renamed Escrow data type to EscrowData and created escrow.ts in reque…
KolevDarko Feb 15, 2022
1454eb9
fixed import from payment-detection
KolevDarko Feb 16, 2022
2dd3fed
exposing request data from Request and added v2 config in custom dete…
KolevDarko Feb 17, 2022
1f0bb29
testing getEscrow method
KolevDarko Feb 17, 2022
9c1cb14
removed only from erc20-fee-proxy test
KolevDarko Feb 17, 2022
b0bc079
removed only from escrow proxy contract test
KolevDarko Feb 17, 2022
16b34f3
removed getProxyDeploymentInformation
KolevDarko Mar 2, 2022
7e4386a
merged master into ivo-escrow-detector-class
KolevDarko Mar 2, 2022
bf3b5e3
renamed custom detector to escrow detector and replaced usages
KolevDarko Mar 2, 2022
3382b0a
getting payments and escrow in one graph call
KolevDarko Mar 2, 2022
21f545c
getEvents methods return a list of escrowEvents, refactoring all info…
KolevDarko Mar 7, 2022
4044ef3
fixing tests
KolevDarko Mar 8, 2022
59d388d
removed getProxyDeployment function and not exporting default class E…
KolevDarko Mar 8, 2022
0adbf28
merged master into ivo-escrow-detector-class
KolevDarko Mar 8, 2022
00cd565
removed unused import
KolevDarko Mar 8, 2022
667d9c0
set escrowEvents list optional in AllNetworkEvents
KolevDarko Mar 8, 2022
024f2f9
removed escrow.ts from request-client and fixed integration test
KolevDarko Mar 8, 2022
6cf8746
fixed multiple tests
KolevDarko Mar 8, 2022
8e3a9a5
removed empty escrowEvent return arrays
KolevDarko Mar 8, 2022
50fe68b
removed unused function
KolevDarko Mar 10, 2022
2b9ef15
added type to allEvents in eth/input-data.ts
KolevDarko Mar 10, 2022
a4afa0f
sorting escrow events in getBalance
KolevDarko Mar 10, 2022
657fa58
merged master into ivo-escrow-detector-class
KolevDarko Mar 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 15 additions & 49 deletions packages/integration-test/test/scheduled/erc20-fee-proxy.test.ts
@@ -1,10 +1,5 @@
import { Erc20PaymentNetwork } from '@requestnetwork/payment-detection';
import {
ExtensionTypes,
IdentityTypes,
PaymentTypes,
RequestLogicTypes,
} from '@requestnetwork/types';
import { PaymentTypes, RequestLogicTypes } from '@requestnetwork/types';
import { CurrencyManager } from '@requestnetwork/currency';

import { mockAdvancedLogic } from './mocks';
Expand All @@ -17,57 +12,24 @@ import {
privateErc20Address,
requestNetwork,
} from './fixtures';

const createMockRequest = ({
network,
tokenAddress,
paymentAddress,
salt,
requestId,
}: Record<
'network' | 'tokenAddress' | 'paymentAddress' | 'salt' | 'requestId',
string
>): RequestLogicTypes.IRequest => ({
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
currency: {
network,
type: RequestLogicTypes.CURRENCY.ERC20,
value: tokenAddress,
},
events: [],
expectedAmount: '0',
extensions: {
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT]: {
events: [],
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT,
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {
paymentAddress,
salt,
},
version: '0.1.0',
},
},
extensionsData: [],
requestId,
state: RequestLogicTypes.STATE.CREATED,
timestamp: 0,
version: '0.2',
});
import { createMockErc20FeeRequest } from '../utils';

const erc20FeeProxy = new Erc20PaymentNetwork.ERC20FeeProxyPaymentDetector({
// FIXME: the mocked advanced logic is address based
advancedLogic: mockAdvancedLogic,
currencyManager: CurrencyManager.getDefault(),
});

describe('ERC20 Fee Proxy detection test-suite', () => {
it('can getBalance on a mainnet request', async () => {
const mockRequest = createMockRequest({
const mockRequest = createMockErc20FeeRequest({
network: 'mainnet',
requestId: '016d4cf8006982f7d91a437f8c72700aa62767de00a605133ee5f84ad8d224ba04',
paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
salt: '8097784e131ee627',
tokenAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F', // DAI
feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7',
feeAmount: '10',
});

const balance = await erc20FeeProxy.getBalance(mockRequest);
Expand All @@ -81,13 +43,15 @@ describe('ERC20 Fee Proxy detection test-suite', () => {
expect(balance.events[0].timestamp).toBe(1599070058);
});

it('can getBalance on a rinkeby request', async () => {
const mockRequest = createMockRequest({
it.only('can getBalance on a rinkeby request', async () => {
KolevDarko marked this conversation as resolved.
Show resolved Hide resolved
const mockRequest = createMockErc20FeeRequest({
network: 'rinkeby',
requestId: '0188791633ff0ec72a7dbdefb886d2db6cccfa98287320839c2f173c7a4e3ce7e1',
paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
salt: '0ee84db293a752c6',
tokenAddress: '0xFab46E002BbF0b4509813474841E0716E6730136', // FAU
feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7',
feeAmount: '1000000000000000',
});

const balance = await erc20FeeProxy.getBalance(mockRequest);
Expand All @@ -96,18 +60,20 @@ describe('ERC20 Fee Proxy detection test-suite', () => {
expect(balance.events).toHaveLength(1);
expect(balance.events[0].name).toBe('payment');
const params = balance.events[0].parameters as PaymentTypes.IERC20FeePaymentEventParameters;
expect(params).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93');
expect(params?.to).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93');
expect(balance.events[0].amount).toBe('1000000000000000000000');
expect(balance.events[0].timestamp).toBe(1599013969);
});

it('can getBalance on a matic request, with TheGraph', async () => {
const mockRequest = createMockRequest({
const mockRequest = createMockErc20FeeRequest({
network: 'matic',
requestId: '014bcd076791fb915af457df1d3f26c81ff66f7e278e4a18f0e48a1705572a6306',
paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
salt: '8c5ea6f8b4a14fe0',
tokenAddress: '0x282d8efce846a88b159800bd4130ad77443fa1a1', // FAU
feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7',
feeAmount: '1000000000000000',
});

const balance = await erc20FeeProxy.getBalance(mockRequest);
Expand All @@ -116,7 +82,7 @@ describe('ERC20 Fee Proxy detection test-suite', () => {
expect(balance.events).toHaveLength(1);
expect(balance.events[0].name).toBe('payment');
const params = balance.events[0].parameters as PaymentTypes.IERC20FeePaymentEventParameters;
expect(params).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93');
expect(params.to).toBe('0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93');
expect(balance.events[0].amount).toBe('1000000000000000000');
expect(balance.events[0].timestamp).toBe(1621953168);
}, 15000);
Expand Down
54 changes: 54 additions & 0 deletions packages/integration-test/test/scheduled/escrow-detector.test.ts
@@ -0,0 +1,54 @@
import { Erc20PaymentNetwork } from '../../../payment-detection/dist';
import { CurrencyManager } from '@requestnetwork/currency';
import { createMockErc20FeeRequest } from '../utils';
import { mockAdvancedLogic } from './mocks';

const customDetector = new Erc20PaymentNetwork.CustomProxyDetector({
advancedLogic: mockAdvancedLogic,
currencyManager: CurrencyManager.getDefault(),
});
const feeProxyDetector = new Erc20PaymentNetwork.ERC20FeeProxyPaymentDetector({
advancedLogic: mockAdvancedLogic,
currencyManager: CurrencyManager.getDefault(),
});

describe('ERC20 Escrow detection test-suite', () => {
it('can getBalance on a matic request, with TheGraph', async () => {
const mockRequest = createMockErc20FeeRequest({
network: 'matic',
requestId: '014bcd076791fb915af457df1d3f26c81ff66f7e278e4a18f0e48a1705572a6306',
paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
salt: '8c5ea6f8b4a14fe0',
tokenAddress: '0x282d8efce846a88b159800bd4130ad77443fa1a1', // FAU
feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7',
feeAmount: '1000000000000000',
});

const balance = await customDetector.getBalance(mockRequest);
const baseBalance = await feeProxyDetector.getBalance(mockRequest);

expect(baseBalance.balance).toBe('1000000000000000000');
expect(balance.balance).toBe('1000000000000000000');
}, 15000);

it('can getBalance on a rinkeby request', async () => {
const mockRequest = createMockErc20FeeRequest({
network: 'rinkeby',
requestId: '0188791633ff0ec72a7dbdefb886d2db6cccfa98287320839c2f173c7a4e3ce7e1',
paymentAddress: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93',
salt: '0ee84db293a752c6',
tokenAddress: '0xFab46E002BbF0b4509813474841E0716E6730136', // FAU
feeAddress: '0x35d0e078755cd84d3e0656caab417dee1d7939c7',
feeAmount: '1000000000000000',
});

const balance = await customDetector.getBalance(mockRequest);
const baseBalance = await feeProxyDetector.getBalance(mockRequest);

// Sanity check
expect(baseBalance.balance).toBe('1000000000000000000');
expect(balance.balance).toBe('1000000000000000000');
const events = await customDetector.getAllEvents(mockRequest);
expect(events).toHaveLength(3);
});
});
11 changes: 11 additions & 0 deletions packages/integration-test/test/scheduled/mocks.ts
Expand Up @@ -8,5 +8,16 @@ export const mockAdvancedLogic: AdvancedLogicTypes.IAdvancedLogic = {
createAddRefundAddressAction: jest.fn(),
createCreationAction: jest.fn(),
},
feeProxyContractErc20: {
supportedNetworks: ['mainnet', 'private', 'matic', 'rinkeby'],
version: '0.1.0',
createAddPaymentAddressAction: jest.fn(),
createAddRefundAddressAction: jest.fn(),
createCreationAction: jest.fn(),
createAddFeeAction: jest.fn(),
// inherited from declarative
createAddPaymentInstructionAction: jest.fn(),
createAddRefundInstructionAction: jest.fn(),
},
},
};
42 changes: 42 additions & 0 deletions packages/integration-test/test/utils.ts
@@ -0,0 +1,42 @@
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';

export const createMockErc20FeeRequest = ({
network,
tokenAddress,
paymentAddress,
salt,
requestId,
feeAddress,
feeAmount,
}: Record<
'network' | 'tokenAddress' | 'paymentAddress' | 'salt' | 'requestId' | 'feeAddress' | 'feeAmount',
string
>): RequestLogicTypes.IRequest => ({
creator: { type: IdentityTypes.TYPE.ETHEREUM_ADDRESS, value: '0x2' },
currency: {
network,
type: RequestLogicTypes.CURRENCY.ERC20,
value: tokenAddress,
},
events: [],
expectedAmount: '0',
extensions: {
[ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT]: {
events: [],
id: ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT,
type: ExtensionTypes.TYPE.PAYMENT_NETWORK,
values: {
paymentAddress,
salt,
feeAddress,
feeAmount,
},
version: '0.1.0',
},
},
extensionsData: [],
requestId,
state: RequestLogicTypes.STATE.CREATED,
timestamp: 0,
version: '0.2.0',
});
9 changes: 8 additions & 1 deletion packages/payment-detection/src/any/any-to-erc20-proxy.ts
@@ -1,4 +1,4 @@
import { erc20ConversionProxy } from '@requestnetwork/smart-contracts';
import { DeploymentInformation, erc20ConversionProxy } from '@requestnetwork/smart-contracts';
import {
AdvancedLogicTypes,
ExtensionTypes,
Expand Down Expand Up @@ -138,6 +138,13 @@ export class AnyToERC20PaymentDetector extends ERC20FeeProxyPaymentDetectorBase<
return network;
}

protected getProxyDeploymentInformation(
networkName: string,
version: string,
): DeploymentInformation {
return AnyToERC20PaymentDetector.getDeploymentInformation(networkName, version);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it replace AnyToERC20PaymentDetector.getDeploymentInformation?

}

public static getDeploymentInformation = makeGetDeploymentInformation(
erc20ConversionProxy,
PROXY_CONTRACT_ADDRESS_MAP,
Expand Down
10 changes: 10 additions & 0 deletions packages/payment-detection/src/any/any-to-eth-proxy.ts
Expand Up @@ -13,6 +13,7 @@ import { AnyToAnyDetector } from '../any-to-any-detector';
import { makeGetDeploymentInformation } from '../utils';
import { networkSupportsTheGraph } from '../thegraph';
import { TheGraphConversionRetriever } from './retrievers/thegraph';
import { DeploymentInformation } from '@requestnetwork/smart-contracts';

// interface of the object indexing the proxy contract version
interface IProxyContractVersion {
Expand Down Expand Up @@ -73,10 +74,12 @@ export class AnyToEthFeeProxyPaymentDetector extends AnyToAnyDetector<
if (!address) {
return [];
}

const contractInfo = AnyToEthFeeProxyPaymentDetector.getDeploymentInformation(
paymentChain,
paymentNetwork.version,
);

const abi = SmartContracts.ethConversionArtifact.getContractAbi(contractInfo.contractVersion);

const currency = this.currencyManager.fromStorageCurrency(requestCurrency);
Expand Down Expand Up @@ -126,6 +129,13 @@ export class AnyToEthFeeProxyPaymentDetector extends AnyToAnyDetector<
return network;
}

protected getProxyDeploymentInformation(
networkName: string,
version: string,
): DeploymentInformation {
return AnyToEthFeeProxyPaymentDetector.getDeploymentInformation(networkName, version);
}

/*
* Returns deployment information for the underlying smart contract for a given payment network version
*/
Expand Down