Skip to content

Commit

Permalink
Merge branch 'master' into ivo-escrow-detector-class
Browse files Browse the repository at this point in the history
  • Loading branch information
KolevDarko committed Feb 14, 2022
2 parents 02b18c3 + c2fe1f9 commit 1e9f05c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 73 deletions.
9 changes: 6 additions & 3 deletions 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 @@ -95,7 +95,7 @@ export class AnyToERC20PaymentDetector extends ERC20FeeProxyPaymentDetectorBase<
const {
address: conversionProxyContractAddress,
creationBlockNumber: conversionProxyCreationBlockNumber,
} = this.getProxyDeploymentInformation(paymentChain, paymentNetwork.version);
} = AnyToERC20PaymentDetector.getDeploymentInformation(paymentChain, paymentNetwork.version);

const conversionProxyAbi = erc20ConversionProxy.getContractAbi(paymentNetwork.version);

Expand Down Expand Up @@ -138,7 +138,10 @@ export class AnyToERC20PaymentDetector extends ERC20FeeProxyPaymentDetectorBase<
return network;
}

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

Expand Down
15 changes: 10 additions & 5 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,11 +74,12 @@ export class AnyToEthFeeProxyPaymentDetector extends AnyToAnyDetector<
if (!address) {
return [];
}
const contractInfo = this.getProxyDeploymentInformation(paymentChain, paymentNetwork.version);

if (!contractInfo) {
throw Error('ETH conversion proxy contract not found');
}
const contractInfo = AnyToEthFeeProxyPaymentDetector.getDeploymentInformation(
paymentChain,
paymentNetwork.version,
);

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

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

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

Expand Down
2 changes: 2 additions & 0 deletions packages/payment-detection/src/erc20/escrow-info-retriever.ts
@@ -1,6 +1,8 @@
import { PaymentTypes } from '@requestnetwork/types';

import { BigNumber, ethers } from 'ethers';
import { IEventRetriever } from '../types';

import { getDefaultProvider } from '../provider';
import { parseLogArgs } from '../utils';

Expand Down
31 changes: 9 additions & 22 deletions packages/payment-detection/src/erc20/fee-proxy-contract.ts
@@ -1,4 +1,4 @@
import { erc20FeeProxyArtifact } from '@requestnetwork/smart-contracts';
import { DeploymentInformation, erc20FeeProxyArtifact } from '@requestnetwork/smart-contracts';
import {
AdvancedLogicTypes,
ExtensionTypes,
Expand All @@ -13,7 +13,6 @@ import TheGraphInfoRetriever from './thegraph-info-retriever';
import { loadCurrencyFromContract } from './currency';
import { FeeReferenceBasedDetector } from '../fee-reference-based-detector';
import { makeGetDeploymentInformation } from '../utils';
import { NetworkNotSupported, VersionNotSupported } from '../balance-error';

const PROXY_CONTRACT_ADDRESS_MAP = {
['0.1.0']: '0.1.0',
Expand Down Expand Up @@ -97,25 +96,10 @@ export class ERC20FeeProxyPaymentDetector extends ERC20FeeProxyPaymentDetectorBa
return Promise.resolve([]);
}

const deploymentInformation = this.getProxyDeploymentInformation(
paymentChain,
paymentNetwork.version,
);

if (!deploymentInformation) {
throw new VersionNotSupported(
`Payment network version not supported: ${paymentNetwork.version}`,
);
}

const proxyContractAddress: string | undefined = deploymentInformation.address;
const proxyCreationBlockNumber: number = deploymentInformation.creationBlockNumber;

if (!proxyContractAddress) {
throw new NetworkNotSupported(
`Network not supported for this payment network: ${requestCurrency.network}`,
);
}
const {
address: proxyContractAddress,
creationBlockNumber: proxyCreationBlockNumber,
} = ERC20FeeProxyPaymentDetector.getDeploymentInformation(paymentChain, paymentNetwork.version);

const infoRetriever = networkSupportsTheGraph(paymentChain)
? new TheGraphInfoRetriever(
Expand All @@ -141,7 +125,10 @@ export class ERC20FeeProxyPaymentDetector extends ERC20FeeProxyPaymentDetectorBa
>;
}

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

Expand Down
27 changes: 5 additions & 22 deletions packages/payment-detection/src/erc20/proxy-contract.ts
Expand Up @@ -4,8 +4,8 @@ import {
PaymentTypes,
RequestLogicTypes,
} from '@requestnetwork/types';

import { DeploymentInformation, erc20ProxyArtifact } from '@requestnetwork/smart-contracts';
import { NetworkNotSupported, VersionNotSupported } from '../balance-error';
import ProxyInfoRetriever from './proxy-info-retriever';
import TheGraphInfoRetriever from './thegraph-info-retriever';
import { networkSupportsTheGraph } from '../thegraph';
Expand Down Expand Up @@ -55,27 +55,10 @@ export class ERC20ProxyPaymentDetector extends ReferenceBasedDetector<
return [];
}

let proxyContractAddress: string;
let proxyCreationBlockNumber: number;
try {
const info = this.getProxyDeploymentInformation(paymentChain, paymentNetwork.version);
proxyContractAddress = info.address;
proxyCreationBlockNumber = info.creationBlockNumber;
} catch (e) {
const errMessage = (e as Error)?.message || '';
if (errMessage.startsWith('No deployment for network')) {
throw new NetworkNotSupported(
`Network not supported for this payment network: ${paymentChain}`,
);
}
if (
errMessage.startsWith('No contract matches payment network version') ||
errMessage.startsWith('No deployment for version')
) {
throw new VersionNotSupported(errMessage);
}
throw e;
}
const {
address: proxyContractAddress,
creationBlockNumber: proxyCreationBlockNumber,
} = ERC20ProxyPaymentDetector.getDeploymentInformation(paymentChain, paymentNetwork.version);

const infoRetriever = networkSupportsTheGraph(paymentChain)
? new TheGraphInfoRetriever(
Expand Down
18 changes: 6 additions & 12 deletions packages/payment-detection/src/eth/input-data.ts
Expand Up @@ -82,11 +82,12 @@ export class EthInputDataPaymentDetector extends ReferenceBasedDetector<
this.explorerApiKeys[paymentChain],
);
const events = await infoRetriever.getTransferEvents();
try {
const proxyContractArtifact = this.getProxyDeploymentInformation(
paymentChain,
paymentNetwork.version,
);
const proxyContractArtifact = EthInputDataPaymentDetector.getDeploymentInformation(
paymentChain,
paymentNetwork.version,
);

if (proxyContractArtifact) {
const proxyInfoRetriever = networkSupportsTheGraph(paymentChain)
? new TheGraphInfoRetriever(
paymentReference,
Expand All @@ -107,13 +108,6 @@ export class EthInputDataPaymentDetector extends ReferenceBasedDetector<

const proxyEvents = await proxyInfoRetriever.getTransferEvents();
events.push(...proxyEvents);
return events;
} catch (e) {
if (e instanceof MissingProxyContract) {
console.log('Missing proxy contract for input data');
} else {
throw e;
}
}
return events;
}
Expand Down
9 changes: 0 additions & 9 deletions packages/types/src/payment-types.ts
Expand Up @@ -111,7 +111,6 @@ export interface ICustomNetworkEvent<TEventParameters, TEventNames = ESCROW_EVEN
extends IPaymentNetworkBaseEvent<TEventNames> {
parameters?: TEventParameters;
}

/**
* Declarative balance and events for detection-based payment networks
*/
Expand Down Expand Up @@ -233,14 +232,6 @@ export type BTCPaymentNetworkEvent = IPaymentNetworkEvent<IBTCPaymentEventParame
/** BTC BalanceWithEvents */
export type BTCBalanceWithEvents = IBalanceWithEvents<IBTCPaymentEventParameters>;

/** Parameters for events of Declarative payments */
export interface IDeclarativePaymentEventParameters {
txHash?: string;
network?: string;
note?: string;
from?: IIdentity;
}

/** Parameters for escrow events from EscrowERC20 contract state changes */
export interface IEscrowEventParameters {
block: number;
Expand Down

0 comments on commit 1e9f05c

Please sign in to comment.