Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/ua-parser-js-0.7.34
Browse files Browse the repository at this point in the history
  • Loading branch information
MantisClone committed Sep 25, 2023
2 parents 104fe2f + 1e7e2ce commit 5544047
Show file tree
Hide file tree
Showing 96 changed files with 4,298 additions and 5,604 deletions.
15 changes: 1 addition & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ references:
cd storage-subgraph
yarn
yarn codegen ./subgraph-private.yaml
yarn create-local ./subgraph-private.yaml
yarn create-local
yarn deploy-local --version-label v0.0.1 ./subgraph-private.yaml
sleep 5
step_wait_for_node: &step_wait_for_node
Expand Down Expand Up @@ -523,16 +523,6 @@ jobs:
- run:
name: 'Publish Coverage'
command: 'yarn publish-coverage'
test-prototype-estimator:
docker:
- *node_image
working_directory: *working_directory
steps:
- attach_workspace:
at: *working_directory
- run:
name: 'Build prototype-estimator'
command: 'yarn workspace @requestnetwork/prototype-estimator run build'
test-nightly:
docker:
- *node_image
Expand Down Expand Up @@ -672,9 +662,6 @@ workflows:
- test-integration-graph-node:
requires:
- build
- test-prototype-estimator:
requires:
- build
- test-payment-detection:
requires:
- build
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/auto_assign_pr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: 'Auto Assign'
on:
pull_request:
pull_request_target:
types: [opened, ready_for_review]
branches: [master]

permissions:
contents: read
pull-requests: write

jobs:
add-reviews:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default abstract class AddressBasedPaymentNetwork<
if (!currency) {
throw new UnsupportedCurrencyError({ value: symbol, network });
}
return CurrencyManager.validateAddress(address, currency);
return currencyManager.validateAddress(address, currency);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import { FeeReferenceBasedPaymentNetwork } from '../fee-reference-based';

const CURRENT_VERSION = '0.1.0';
const CURRENT_VERSION = '0.2.0';

/**
* Implementation of the payment network to pay in ERC20 based on a transferable receivable contract.
Expand Down
10 changes: 10 additions & 0 deletions packages/currency/src/chains/declarative/DeclarativeChains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChainsAbstract } from '../ChainsAbstract';
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { DeclarativeChain, chains } from './index';

class DeclarativeChains extends ChainsAbstract<
CurrencyTypes.DeclarativeChainName,
DeclarativeChain,
string
> {}
export default new DeclarativeChains(chains, RequestLogicTypes.CURRENCY.ETH);
1 change: 1 addition & 0 deletions packages/currency/src/chains/declarative/data/tron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 'tron';
10 changes: 10 additions & 0 deletions packages/currency/src/chains/declarative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { CurrencyTypes } from '@requestnetwork/types';
import { Chain } from '../../types';

import * as TronDefinition from './data/tron';

export type DeclarativeChain = Chain;

export const chains: Record<CurrencyTypes.DeclarativeChainName, DeclarativeChain> = {
tron: TronDefinition,
};
2 changes: 2 additions & 0 deletions packages/currency/src/chains/evm/data/mantle-testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const chainId = 5001;
export const testnet = true;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/data/mantle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 5000;
4 changes: 4 additions & 0 deletions packages/currency/src/chains/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import * as FantomDefinition from './data/fantom';
import * as FuseDefinition from './data/fuse';
import * as GoerliDefinition from './data/goerli';
import * as MainnetDefinition from './data/mainnet';
import * as MantleDefinition from './data/mantle';
import * as MantleTestnetDefinition from './data/mantle-testnet';
import * as MaticDefinition from './data/matic';
import * as MoonbeamDefinition from './data/moonbeam';
import * as MumbaiDefinition from './data/mumbai';
Expand Down Expand Up @@ -39,6 +41,8 @@ export const chains: Record<CurrencyTypes.EvmChainName, EvmChain> = {
fuse: FuseDefinition,
goerli: GoerliDefinition,
mainnet: MainnetDefinition,
mantle: MantleDefinition,
'mantle-testnet': MantleTestnetDefinition,
matic: MaticDefinition,
moonbeam: MoonbeamDefinition,
mumbai: MumbaiDefinition,
Expand Down
3 changes: 2 additions & 1 deletion packages/currency/src/chains/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BtcChains from './btc/BtcChains';
import EvmChains from './evm/EvmChains';
import NearChains from './near/NearChains';
import DeclarativeChains from './declarative/DeclarativeChains';
import { isSameChain } from './utils';

export { BtcChains, EvmChains, NearChains, isSameChain };
export { BtcChains, EvmChains, NearChains, DeclarativeChains, isSameChain };
10 changes: 6 additions & 4 deletions packages/currency/src/currencyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
* Validates an address for a given currency.
* Throws if the currency is an ISO4217 currency.
*/
static validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean {
validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean {
if (currency.type === RequestLogicTypes.CURRENCY.ISO4217) {
throw new Error(`Could not validate an address for an ISO4217 currency`);
}
Expand All @@ -246,6 +246,8 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
case RequestLogicTypes.CURRENCY.ERC777:
if (NearChains.isChainSupported(currency.network)) {
return isValidNearAddress(address, currency.network);
} else if (currency.network === 'tron') {
return addressValidator.validate(address, currency.network);
}
return addressValidator.validate(address, 'ETH');
case RequestLogicTypes.CURRENCY.BTC:
Expand All @@ -262,7 +264,7 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
/**
* Validate the correctness of a Storage Currency
*/
static validateCurrency(currency: StorageCurrency): boolean {
validateCurrency(currency: StorageCurrency): boolean {
if (
currency.type === RequestLogicTypes.CURRENCY.ISO4217 ||
currency.type === RequestLogicTypes.CURRENCY.ETH ||
Expand All @@ -282,7 +284,7 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
* - NEAR, YEL, ZIL, BTC
* - ETH-rinkeby, FAU-rinkeby, CTBK-rinkeby
*/
static getDefaultList(): CurrencyDefinition[] {
static getDefaultList<TMeta = unknown>(): CurrencyDefinition<TMeta>[] {
const isoCurrencies: CurrencyInput[] = iso4217.map((cc) => ({
decimals: cc.digits,
name: cc.currency,
Expand All @@ -304,7 +306,7 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
.concat(erc777Currencies)
.concat(eth)
.concat(btc)
.map(CurrencyManager.fromInput);
.map(CurrencyManager.fromInput<TMeta>);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/currency/src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ export const nativeCurrencies: Record<RequestLogicTypes.CURRENCY.ETH, NativeEthC
name: 'Tomb',
network: 'tombchain',
},
{
symbol: 'MNT',
decimals: 18,
name: 'Mantle',
network: 'mantle',
},
{
symbol: 'MNT-testnet',
decimals: 18,
name: 'Mantle Testnet',
network: 'mantle-testnet',
},
],
[RequestLogicTypes.CURRENCY.BTC]: [
{
Expand Down
7 changes: 6 additions & 1 deletion packages/currency/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export type ISO4217Currency = {
export type ERC20Currency = {
symbol: string;
decimals: number;
network: CurrencyTypes.EvmChainName | CurrencyTypes.NearChainName;
network:
| CurrencyTypes.EvmChainName
| CurrencyTypes.NearChainName
| CurrencyTypes.DeclarativeChainName;
address: string;
};

Expand Down Expand Up @@ -129,6 +132,8 @@ export interface ICurrencyManager<TMeta = unknown> {
network: string,
): string[] | null;
supportsConversion(currency: Pick<CurrencyDefinition, 'hash'>, network: string): boolean;
validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean;
validateCurrency(currency: StorageCurrency): boolean;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/currency/test/currencyManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ describe('CurrencyManager', () => {
if (!currency) {
throw new Error('currency is undefined');
}
const result = CurrencyManager.validateAddress(address, currency);
const result = currencyManager.validateAddress(address, currency);
expect(result).toBe(expectedResult);
};

Expand Down Expand Up @@ -590,7 +590,7 @@ describe('CurrencyManager', () => {
it(`should throw for ${currencyTemplate.symbol} currency`, () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const currency = currencyManager.from(currencyTemplate.symbol)!;
expect(() => CurrencyManager.validateAddress('anyAddress', currency)).toThrow();
expect(() => currencyManager.validateAddress('anyAddress', currency)).toThrow();
});
});
});
Expand Down Expand Up @@ -649,7 +649,7 @@ describe('CurrencyManager', () => {
},
];
it.each(currencies)('Should validate $label', ({ currency }) => {
const result = CurrencyManager.validateCurrency(currency);
const result = currencyManager.validateCurrency(currency);
expect(result).toBe(true);
});
});
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('CurrencyManager', () => {
},
];
it.each(currencies)('Should not validate an invalid $label', ({ currency }) => {
const result = CurrencyManager.validateCurrency(currency);
const result = currencyManager.validateCurrency(currency);
expect(result).toBe(false);
});
});
Expand Down
14 changes: 5 additions & 9 deletions packages/ethereum-storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,22 @@ TRUFFLE_GANACHE_HOST="host" TRUFFLE_GANACHE_PORT=1010 yarn run deploy

## IPFS

In order to use the package in a test environment, IPFS should be [installed locally](https://docs.ipfs.io/guides/guides/install/) and can then be started with the following commands:

```bash
yarn init-ipfs # documented below
ipfs daemon
```

In order to use the package in a test environment, IPFS should be running locally.
Local IPFS listening on port 5001 is used by default by the `ethereum-storage` package.

### Setup IPFS private network

Request uses an IPFS private network to allow all nodes to connect to each other directly,
instead of having to navigate through the public IPFS network.

To setup your IPFS node to the private network, you can run the following utility script:
You may use the [Request IPFS docker image](https://github.com/RequestNetwork/docker-images/tree/master/request-ipfs) to setup your IPFS node to the private network. Make sure that [docker is installed](https://docs.docker.com/get-docker/) on your system and then run the following command:

```bash
yarn init-ipfs
docker run -p 4001:4001 -p 5001:5001 requestnetwork/request-ipfs
```

This will pull the [request-ipfs](https://hub.docker.com/r/requestnetwork/request-ipfs) docker image and run it locally.

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
8 changes: 8 additions & 0 deletions packages/ethereum-storage/scripts/init-ipfs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
*
* This script is deprecated and will be removed in the future.
* Use the Request IPFS docker image (https://hub.docker.com/r/requestnetwork/request-ipfs) instead.
*
*
*/

const shell = require('shelljs');
const fs = require('fs');
const path = require('path');
Expand Down
3 changes: 2 additions & 1 deletion packages/ethereum-storage/src/ethereum-storage-ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ export class EthereumStorageEthers implements StorageTypes.IStorageWrite {
ipfs: { size: ipfsSize },
local: { location: ipfsHash },
ethereum: {
nonce: tx.nonce,
transactionHash: tx.hash,
blockConfirmation: tx.confirmations,
blockNumber: Number(tx.blockNumber),
// wrong value, but this metadata will not be used, as it's in Pending state
blockTimestamp: -1,
networkName: this.network,
smartContractAddress: this.txSubmitter.hashSubmitterAddress,
transactionHash: tx.hash,
},
state: StorageTypes.ContentState.PENDING,
storageType: StorageTypes.StorageSystemType.LOCAL,
Expand Down
12 changes: 10 additions & 2 deletions packages/ethereum-storage/src/gas-fee-definer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { BigNumber, providers, constants } from 'ethers';
import { GasDefinerProps } from './ethereum-storage-ethers';
import { estimateGasFees } from '@requestnetwork/utils';
import { LogTypes } from '@requestnetwork/types';

export class GasFeeDefiner {
private readonly logger: LogTypes.ILogger;
private readonly provider: providers.JsonRpcProvider;
private readonly gasPriceMin: BigNumber;

constructor({
logger,
provider,
gasPriceMin,
}: GasDefinerProps & { provider: providers.JsonRpcProvider }) {
}: GasDefinerProps & { logger?: LogTypes.ILogger; provider: providers.JsonRpcProvider }) {
this.logger = logger || console;
this.provider = provider;
this.gasPriceMin = gasPriceMin || constants.Zero;
}
Expand All @@ -18,6 +22,10 @@ export class GasFeeDefiner {
maxFeePerGas?: BigNumber;
maxPriorityFeePerGas?: BigNumber;
}> {
return estimateGasFees({ provider: this.provider, gasPriceMin: this.gasPriceMin });
return estimateGasFees({
logger: this.logger,
provider: this.provider,
gasPriceMin: this.gasPriceMin,
});
}
}
Loading

0 comments on commit 5544047

Please sign in to comment.