Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dc410f6
WIP
alexandre-abrioux Jan 31, 2023
ed3b672
WIP
alexandre-abrioux Feb 3, 2023
924a70e
fixes
alexandre-abrioux Feb 3, 2023
4aee325
Merge branch 'master' into networks
alexandre-abrioux Feb 3, 2023
bae4830
fix ERC20 order
alexandre-abrioux Feb 3, 2023
e7ecfb9
fix indentation
alexandre-abrioux Feb 3, 2023
8771389
fix tests
alexandre-abrioux Feb 3, 2023
d48802d
rollback changes
alexandre-abrioux Feb 3, 2023
753fe99
fix tests
alexandre-abrioux Feb 3, 2023
5bc4f96
fix tests
alexandre-abrioux Feb 3, 2023
5363d3c
fix tests
alexandre-abrioux Feb 3, 2023
256b6df
fix tests
alexandre-abrioux Feb 3, 2023
21b92fc
rollback test
alexandre-abrioux Feb 3, 2023
7bd75c7
fix tests
alexandre-abrioux Feb 3, 2023
b2ed93b
Merge branch 'master' into networks
alexandre-abrioux Feb 7, 2023
d6ae451
remove aurora from evm
alexandre-abrioux Feb 7, 2023
c7b3112
remove unused export
alexandre-abrioux Feb 7, 2023
e52eb10
fix missing export
alexandre-abrioux Feb 7, 2023
a446daf
change chaindefinition type name
alexandre-abrioux Feb 7, 2023
f454936
edit README
alexandre-abrioux Feb 7, 2023
05ab7d5
refactor chain types to classes
alexandre-abrioux Feb 7, 2023
ddf73ac
fix test
alexandre-abrioux Feb 7, 2023
94cf0e8
remove unusued utils
alexandre-abrioux Feb 7, 2023
c3d01ad
fix some more types
alexandre-abrioux Feb 7, 2023
ead5d9b
fix some more types
alexandre-abrioux Feb 7, 2023
a9a3029
fix test types
alexandre-abrioux Feb 7, 2023
737aee6
fix test
alexandre-abrioux Feb 7, 2023
f44f683
fix near typing
alexandre-abrioux Feb 7, 2023
87c5cd0
fix currencyManager
alexandre-abrioux Feb 7, 2023
3d7c730
fix aggregators type
alexandre-abrioux Feb 7, 2023
2b1fd4f
fix aggregators type
alexandre-abrioux Feb 8, 2023
9baa2f8
fix chainlink test
alexandre-abrioux Feb 8, 2023
100f709
rollback currency manager change
alexandre-abrioux Feb 8, 2023
1c240b7
rollback addagregator change
alexandre-abrioux Feb 8, 2023
729096e
fix ArtifactDeploymentInfo
alexandre-abrioux Feb 8, 2023
97b3438
fix type for ERC20Currency
alexandre-abrioux Feb 16, 2023
8f56b91
Merge branch 'master' into networks
alexandre-abrioux Feb 16, 2023
3452fd1
add README
alexandre-abrioux Feb 16, 2023
71f0809
Merge branch 'master' into networks
alexandre-abrioux Feb 22, 2023
9c014a9
Merge remote-tracking branch 'origin/master' into networks
alexandre-abrioux Mar 7, 2023
8d815f0
fix build
alexandre-abrioux Mar 7, 2023
51030c1
fix missing type
alexandre-abrioux Mar 7, 2023
0190ec2
Merge branch 'master' into networks
alexandre-abrioux Mar 7, 2023
0b99099
fix type errors
alexandre-abrioux Mar 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency';
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import {
CurrencyTypes,
ExtensionTypes,
IdentityTypes,
RequestLogicTypes,
} from '@requestnetwork/types';
import { areEqualIdentities, deepCopy } from '@requestnetwork/utils';
import DeclarativePaymentNetwork from './declarative';

Expand Down Expand Up @@ -155,7 +160,7 @@ export default abstract class AddressBasedPaymentNetwork<
protected isValidAddressForSymbolAndNetwork(
address: string,
symbol: string,
network: string,
network: CurrencyTypes.ChainName,
): boolean {
const currencyManager = CurrencyManager.getDefault();
const currency = currencyManager.from(symbol, network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
anyToErc20Proxy.createCreationAction({
paymentAddress: '0x0000000000000000000000000000000000000001',
salt: 'ea3bc7caf64110ca',
network: 'kovan',
network: 'goerli',
acceptedTokens: ['0x0000000000000000000000000000000000000003'],
});
}).toThrowError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../utils/payment-network/any/generator-data-create';
import { AdvancedLogic } from '../../../src';
import { arbitraryTimestamp, payeeRaw, payerRaw } from '../../utils/test-data-generator';
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import AnyToNearPaymentNetwork from '../../../src/extensions/payment-network/near/any-to-near';
import AnyToNativeTokenPaymentNetwork from '../../../src/extensions/payment-network/any-to-native';
import { CurrencyManager } from '@requestnetwork/currency';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('extensions/payment-network/any-to-native-token', () => {
maxRateTimespan: 100000,
feeAmount: '100',
},
];
] as const;

anyToNativeTokenTestCases.forEach((testCase) => {
describe(`action creations for ${testCase.name}`, () => {
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('extensions/payment-network/any-to-native-token', () => {
expect(() => {
new AnyToNearPaymentNetwork(currencyManager).createCreationAction({
...partialCreationParams,
network: 'another-chain',
network: 'another-chain' as CurrencyTypes.EvmChainName,
});
}).toThrowError(
`Payment network 'another-chain' is not supported by this extension (only aurora)`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../utils/payment-network/mocked_native_data';
import { AdvancedLogic } from '../../../src';
import { arbitraryTimestamp, payeeRaw } from '../../utils/test-data-generator';
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import NearTestnetNativeNativePaymentNetwork from '../../../src/extensions/payment-network/near/near-testnet-native';

const salt = arbitrarySalt;
Expand All @@ -21,17 +21,17 @@ describe('extensions/payment-network/native-token', () => {
type: RequestLogicTypes.CURRENCY.ETH,
value: 'NEAR',
network: 'aurora',
};
} as const;
const auroraTestnetCurrency = {
type: RequestLogicTypes.CURRENCY.ETH,
value: 'NEAR-testnet',
network: 'aurora-testnet',
};
} as const;
const nearTestnetCurrency = {
type: RequestLogicTypes.CURRENCY.ETH,
value: 'NEAR-testnet',
network: 'near-testnet',
};
} as const;
const nativeTokenTestCases = [
{
name: 'Near',
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('extensions/payment-network/native-token', () => {
currency: nearTestnetCurrency,
wrongCurrency: nearCurrency,
},
];
] as const;

nativeTokenTestCases.forEach((testCase) => {
describe(`action creations for ${testCase.name}`, () => {
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('extensions/payment-network/native-token', () => {
});
it('throws on a wrong payment network', () => {
const advancedLogic = new AdvancedLogic();
const wrongNetwork = `wrong network`;
const wrongNetwork = `wrong network` as CurrencyTypes.EvmChainName;

const wrongNativeTokenRequestState: typeof requestStateNoExtensions = {
...requestStateNoExtensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const baseRequestState = {
state: RequestLogicTypes.STATE.CREATED,
timestamp: TestData.arbitraryTimestamp,
version,
};
} as const;

const baseRequestEvent = {
actionSigner: {
Expand All @@ -174,7 +174,7 @@ const baseRequestEvent = {
isSignedRequest: false,
},
timestamp: arbitraryTimestamp,
};
} as const;

export const requestStateNoExtensions: RequestLogicTypes.IRequest = {
...baseRequestState,
Expand Down
32 changes: 32 additions & 0 deletions packages/currency/src/chains/btc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { BtcChainDefinition } from '../../types';
import { addNativeCurrenciesToChains, genericAssertChainSupported } from '../utils';

import * as MainnetDefinition from './mainnet';
import * as TestnetDefinition from './testnet';

export const chains: Record<CurrencyTypes.BtcChainName, BtcChainDefinition> = {
mainnet: MainnetDefinition,
testnet: TestnetDefinition,
};

export const chainNames = Object.keys(chains) as CurrencyTypes.BtcChainName[];

// add native currencies
addNativeCurrenciesToChains(chains, RequestLogicTypes.CURRENCY.BTC);

/**
* Asserts if a specific chain is supported across BTC-type supported chains
* @param chainName
*/
export function assertChainSupported(
chainName: string,
): asserts chainName is CurrencyTypes.BtcChainName {
genericAssertChainSupported<CurrencyTypes.BtcChainName>(chainName, chainNames);
}

export const getChainId = (chainName: CurrencyTypes.BtcChainName): string =>
chains[chainName].chainId;

export const getChainName = (chainId: string): CurrencyTypes.BtcChainName | undefined =>
chainNames.find((chainName) => chains[chainName].chainId === chainId);
1 change: 1 addition & 0 deletions packages/currency/src/chains/btc/mainnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
1 change: 1 addition & 0 deletions packages/currency/src/chains/btc/testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943';
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/alfajores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 44787;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/arbitrum-one.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 42161;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/arbitrum-rinkeby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 421611;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/aurora-testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 1313161555;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/aurora.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 1313161554;
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/avalanche.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedAvalancheERC20 } from '../../erc20/chains/avalanche';

export const chainId = 43114;
export const currencies: TokenMap = {
...supportedAvalancheERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/bsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedBSCERC20 } from '../../erc20/chains/bsc';

export const chainId = 56;
export const currencies: TokenMap = {
...supportedBSCERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/bsctest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedBSCTestERC20 } from '../../erc20/chains/bsctest';

export const chainId = 97;
export const currencies: TokenMap = {
...supportedBSCTestERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/celo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedCeloERC20 } from '../../erc20/chains/celo';

export const chainId = 42220;
export const currencies: TokenMap = {
...supportedCeloERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/fantom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedFantomTokens } from '../../erc20/chains/fantom';

export const chainId = 250;
export const currencies: TokenMap = {
...supportedFantomTokens,
};
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/fuse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 122;
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/goerli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedGoerliERC20 } from '../../erc20/chains/goerli';

export const chainId = 5;
export const currencies: TokenMap = {
...supportedGoerliERC20,
};
76 changes: 76 additions & 0 deletions packages/currency/src/chains/evm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { EvmChainDefinition } from '../../types';
import { addNativeCurrenciesToChains, genericAssertChainSupported } from '../utils';

import * as AlfajoresDefinition from './alfajores';
import * as ArbitrumOneDefinition from './arbitrum-one';
import * as ArbitrumRinkebyDefinition from './arbitrum-rinkeby';
import * as AuroraDefinition from './aurora';
import * as AuroraTestnetDefinition from './aurora-testnet';
import * as AvalancheDefinition from './avalanche';
import * as BscDefinition from './bsc';
import * as BscTestDefinition from './bsctest';
import * as CeloDefinition from './celo';
import * as FantomDefinition from './fantom';
import * as FuseDefinition from './fuse';
import * as GoerliDefinition from './goerli';
import * as MainnetDefinition from './mainnet';
import * as MaticDefinition from './matic';
import * as MoonbeamDefinition from './moonbeam';
import * as MumbaiDefinition from './mumbai';
import * as OptimismDefinition from './optimism';
import * as PrivateDefinition from './private';
import * as RinkebyDefinition from './rinkeby';
import * as RoninDefinition from './ronin';
import * as SokolDefinition from './sokol';
import * as TombchainDefinition from './tombchain';
import * as XDaiDefinition from './xdai';

export const chains: Record<CurrencyTypes.EvmChainName, EvmChainDefinition> = {
alfajores: AlfajoresDefinition,
'arbitrum-one': ArbitrumOneDefinition,
'arbitrum-rinkeby': ArbitrumRinkebyDefinition,
aurora: AuroraDefinition,
'aurora-testnet': AuroraTestnetDefinition,
avalanche: AvalancheDefinition,
bsc: BscDefinition,
bsctest: BscTestDefinition,
celo: CeloDefinition,
fantom: FantomDefinition,
fuse: FuseDefinition,
goerli: GoerliDefinition,
mainnet: MainnetDefinition,
matic: MaticDefinition,
moonbeam: MoonbeamDefinition,
mumbai: MumbaiDefinition,
'near-testnet': AuroraTestnetDefinition,
optimism: OptimismDefinition,
private: PrivateDefinition,
// FIXME: Rinkeby is deprecated
rinkeby: RinkebyDefinition,
ronin: RoninDefinition,
sokol: SokolDefinition,
tombchain: TombchainDefinition,
xdai: XDaiDefinition,
};

export const chainNames = Object.keys(chains) as CurrencyTypes.EvmChainName[];

// add native currencies
addNativeCurrenciesToChains(chains, RequestLogicTypes.CURRENCY.ETH);

/**
* Asserts if a specific chain is supported across EVM-type supported chains
* @param chainName
*/
export function assertChainSupported(
chainName: string,
): asserts chainName is CurrencyTypes.EvmChainName {
genericAssertChainSupported<CurrencyTypes.EvmChainName>(chainName, chainNames);
}

export const getChainId = (chainName: CurrencyTypes.EvmChainName): number =>
chains[chainName].chainId;

export const getChainName = (chainId: number): CurrencyTypes.EvmChainName | undefined =>
chainNames.find((chainName) => chains[chainName].chainId === chainId);
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/mainnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedMainnetERC20 } from '../../erc20/chains/mainnet';

export const chainId = 1;
export const currencies: TokenMap = {
...supportedMainnetERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/matic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedMaticERC20 } from '../../erc20/chains/matic';

export const chainId = 137;
export const currencies: TokenMap = {
...supportedMaticERC20,
};
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/moonbeam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedMoonbeamERC20 } from '../../erc20/chains/moonbeam';

export const chainId = 1284;
export const currencies: TokenMap = {
...supportedMoonbeamERC20,
};
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/mumbai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 80001;
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/optimism.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedOptimismERC20 } from '../../erc20/chains/optimism';

export const chainId = 10;
export const currencies: TokenMap = {
...supportedOptimismERC20,
};
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/private.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 0;
9 changes: 9 additions & 0 deletions packages/currency/src/chains/evm/rinkeby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TokenMap } from '../../types';
import { supportedRinkebyERC20 } from '../../erc20/chains/rinkeby';
import { supportedRinkebyERC777 } from '../../erc777/chains/rinkeby';

export const chainId = 4;
export const currencies: TokenMap = {
...supportedRinkebyERC20,
...supportedRinkebyERC777,
};
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/ronin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 2020;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/sokol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 77;
1 change: 1 addition & 0 deletions packages/currency/src/chains/evm/tombchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const chainId = 6969;
7 changes: 7 additions & 0 deletions packages/currency/src/chains/evm/xdai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenMap } from '../../types';
import { supportedXDAIERC20 } from '../../erc20/chains/xdai';

export const chainId = 100;
export const currencies: TokenMap = {
...supportedXDAIERC20,
};
25 changes: 25 additions & 0 deletions packages/currency/src/chains/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CurrencyTypes } from '@requestnetwork/types';
import * as EVM from './evm';
import * as BTC from './btc';

/**
* Asserts if a specific chain is supported across all supported chain types (EVM + BTC)
* @param chainName
*/
export function assertChainSupported(
chainName: string,
): asserts chainName is CurrencyTypes.EvmChainName {
const chainSupported = [EVM, BTC].some((chainType) => {
try {
chainType.assertChainSupported(chainName);
return true;
} catch (e) {
return false;
}
});
if (!chainSupported) {
throw new Error(`Unsupported chain ${chainName}`);
}
}

export { EVM, BTC };
Loading