Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change chaindefinition type name
  • Loading branch information
alexandre-abrioux committed Feb 7, 2023
commit a446daf0e9f19858b4f56f9aa5cfb8e7802a0ecc
21 changes: 11 additions & 10 deletions packages/currency/src/chains/btc/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { BtcChainDefinition } from '../../types';
import { Chain } from '../../types';
import {
addNativeCurrenciesToChains,
genericAssertChainSupported,
Expand All @@ -10,7 +10,11 @@ import {
import * as MainnetDefinition from './mainnet';
import * as TestnetDefinition from './testnet';

export const chains: Record<CurrencyTypes.BtcChainName, BtcChainDefinition> = {
type BtcChain = Chain & {
chainId: string;
};

export const chains: Record<CurrencyTypes.BtcChainName, BtcChain> = {
mainnet: MainnetDefinition,
testnet: TestnetDefinition,
};
Expand All @@ -29,15 +33,12 @@ export const assertChainSupported =
/**
* Get the BTC chain ID from the chain name
*/
export const getChainId = genericGetChainId<CurrencyTypes.BtcChainName, BtcChainDefinition, string>(
chains,
);
export const getChainId = genericGetChainId<CurrencyTypes.BtcChainName, BtcChain, string>(chains);

/**
* Get the BTC chain name from its ID
*/
export const getChainName = genericGetChainName<
CurrencyTypes.BtcChainName,
BtcChainDefinition,
string
>(chains, chainNames);
export const getChainName = genericGetChainName<CurrencyTypes.BtcChainName, BtcChain, string>(
chains,
chainNames,
);
21 changes: 11 additions & 10 deletions packages/currency/src/chains/evm/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { EvmChainDefinition } from '../../types';
import { Chain } from '../../types';
import {
addNativeCurrenciesToChains,
genericAssertChainSupported,
Expand Down Expand Up @@ -29,7 +29,11 @@ import * as SokolDefinition from './sokol';
import * as TombchainDefinition from './tombchain';
import * as XDaiDefinition from './xdai';

export const chains: Record<CurrencyTypes.EvmChainName, EvmChainDefinition> = {
type EvmChain = Chain & {
chainId: number;
};

export const chains: Record<CurrencyTypes.EvmChainName, EvmChain> = {
alfajores: AlfajoresDefinition,
'arbitrum-one': ArbitrumOneDefinition,
'arbitrum-rinkeby': ArbitrumRinkebyDefinition,
Expand Down Expand Up @@ -67,15 +71,12 @@ export const assertChainSupported =
/**
* Get the EVM chain ID from the chain name
*/
export const getChainId = genericGetChainId<CurrencyTypes.EvmChainName, EvmChainDefinition, number>(
chains,
);
export const getChainId = genericGetChainId<CurrencyTypes.EvmChainName, EvmChain, number>(chains);

/**
* Get the EVM chain name from its ID
*/
export const getChainName = genericGetChainName<
CurrencyTypes.EvmChainName,
EvmChainDefinition,
number
>(chains, chainNames);
export const getChainName = genericGetChainName<CurrencyTypes.EvmChainName, EvmChain, number>(
chains,
chainNames,
);
21 changes: 9 additions & 12 deletions packages/currency/src/chains/near/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
import { NearChainDefinition } from '../../types';
import { Chain } from '../../types';
import {
addNativeCurrenciesToChains,
genericAssertChainSupported,
Expand All @@ -10,7 +10,9 @@ import {
import * as NearDefinition from './near';
import * as NearTestnetDefinition from './near-testnet';

export const chains: Record<CurrencyTypes.NearChainName, NearChainDefinition> = {
type NearChain = Chain;

export const chains: Record<CurrencyTypes.NearChainName, NearChain> = {
aurora: NearDefinition, // FIXME: aurora should be removed from near chains (it is a mistake)
'aurora-testnet': NearTestnetDefinition, // FIXME: aurora should be removed from near chains (it is a mistake)
near: NearDefinition,
Expand All @@ -31,17 +33,12 @@ export const assertChainSupported =
/**
* Get the NEAR chain ID from the chain name
*/
export const getChainId = genericGetChainId<
CurrencyTypes.NearChainName,
NearChainDefinition,
string
>(chains);
export const getChainId = genericGetChainId<CurrencyTypes.NearChainName, NearChain, string>(chains);

/**
* Get the NEAR chain name from its ID
*/
export const getChainName = genericGetChainName<
CurrencyTypes.NearChainName,
NearChainDefinition,
string
>(chains, chainNames);
export const getChainName = genericGetChainName<CurrencyTypes.NearChainName, NearChain, string>(
chains,
chainNames,
);
8 changes: 4 additions & 4 deletions packages/currency/src/chains/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nativeCurrencies } from '../native';
import { ChainDefinition, NamedNativeCurrency, TokenMap } from '../types';
import { Chain, NamedNativeCurrency, TokenMap } from '../types';
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';

export const genericAssertChainSupported = <T extends string>(chainNames: T[]) => {
Expand All @@ -10,7 +10,7 @@ export const genericAssertChainSupported = <T extends string>(chainNames: T[]) =
};

export const addNativeCurrenciesToChains = (
chains: Record<string, ChainDefinition>,
chains: Record<string, Chain>,
currencyType: RequestLogicTypes.CURRENCY.ETH | RequestLogicTypes.CURRENCY.BTC,
): void => {
const chainNames = Object.keys(chains);
Expand All @@ -27,14 +27,14 @@ export const addNativeCurrenciesToChains = (
};

export const genericGetChainId =
<T extends CurrencyTypes.ChainName, D extends ChainDefinition, S extends string | number>(
<T extends CurrencyTypes.ChainName, D extends Chain, S extends string | number>(
chains: Record<T, D>,
) =>
(chainName: T): S =>
chains[chainName].chainId as S;

export const genericGetChainName =
<T extends CurrencyTypes.ChainName, D extends ChainDefinition, S extends string | number>(
<T extends CurrencyTypes.ChainName, D extends Chain, S extends string | number>(
chains: Record<T, D>,
chainNames: T[],
) =>
Expand Down
16 changes: 6 additions & 10 deletions packages/currency/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
type TokenAddress = string;
type TokenDefinition = { name: string; symbol: string; decimals: number };
export type TokenMap = Record<TokenAddress, TokenDefinition>;
export type ChainDefinition = {

/**
* Common types used in chain configuration files
*/
export type Chain = {
chainId: number | string;
currencies?: TokenMap;
};
export type EvmChainDefinition = ChainDefinition & {
chainId: number;
};
export type BtcChainDefinition = ChainDefinition & {
chainId: string;
};
export type NearChainDefinition = ChainDefinition;

type NamedCurrency = { name: string };

/**
* A native blockchain token (ETH, MATIC, ETH-rinkeby...)
Expand All @@ -28,6 +23,7 @@ export type NativeCurrency = {
decimals: number;
network: CurrencyTypes.ChainName;
};
type NamedCurrency = { name: string };
export type NamedNativeCurrency = NativeCurrency & NamedCurrency;

/** Native Currency types */
Expand Down