diff --git a/packages/advanced-logic/src/advanced-logic.ts b/packages/advanced-logic/src/advanced-logic.ts index 4784ee0179..b415bdc121 100644 --- a/packages/advanced-logic/src/advanced-logic.ts +++ b/packages/advanced-logic/src/advanced-logic.ts @@ -5,7 +5,7 @@ import { IdentityTypes, RequestLogicTypes, } from '@requestnetwork/types'; -import { ICurrencyManager, NearChains, isSameChain } from '@requestnetwork/currency'; +import { NearChains, isSameChain } from '@requestnetwork/currency'; import ContentData from './extensions/content-data'; import AddressBasedBtc from './extensions/payment-network/bitcoin/mainnet-address-based'; @@ -51,9 +51,9 @@ export default class AdvancedLogic implements AdvancedLogicTypes.IAdvancedLogic erc20TransferableReceivable: Erc20TransferableReceivablePaymentNetwork; }; - private currencyManager: ICurrencyManager; + private currencyManager: CurrencyTypes.ICurrencyManager; - constructor(currencyManager: ICurrencyManager) { + constructor(currencyManager: CurrencyTypes.ICurrencyManager) { this.currencyManager = currencyManager; this.extensions = { addressBasedBtc: new AddressBasedBtc(currencyManager), diff --git a/packages/advanced-logic/src/extensions/payment-network/address-based.ts b/packages/advanced-logic/src/extensions/payment-network/address-based.ts index c9a3f12985..eb38c466ff 100644 --- a/packages/advanced-logic/src/extensions/payment-network/address-based.ts +++ b/packages/advanced-logic/src/extensions/payment-network/address-based.ts @@ -1,4 +1,4 @@ -import { ICurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; +import { UnsupportedCurrencyError } from '@requestnetwork/currency'; import { CurrencyTypes, ExtensionTypes, @@ -17,7 +17,7 @@ export default abstract class AddressBasedPaymentNetwork< ExtensionTypes.PnAddressBased.ICreationParameters = ExtensionTypes.PnAddressBased.ICreationParameters, > extends DeclarativePaymentNetwork { protected constructor( - protected currencyManager: ICurrencyManager, + protected currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID, currentVersion: string, public readonly supportedCurrencyType: RequestLogicTypes.CURRENCY, diff --git a/packages/advanced-logic/src/extensions/payment-network/any-to-erc20-proxy.ts b/packages/advanced-logic/src/extensions/payment-network/any-to-erc20-proxy.ts index c6ff3cb629..90184b10e9 100644 --- a/packages/advanced-logic/src/extensions/payment-network/any-to-erc20-proxy.ts +++ b/packages/advanced-logic/src/extensions/payment-network/any-to-erc20-proxy.ts @@ -1,16 +1,12 @@ -import { - conversionSupportedNetworks, - ICurrencyManager, - UnsupportedCurrencyError, -} from '@requestnetwork/currency'; -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { conversionSupportedNetworks, UnsupportedCurrencyError } from '@requestnetwork/currency'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import Erc20FeeProxyPaymentNetwork from './erc20/fee-proxy-contract'; const CURRENT_VERSION = '0.1.0'; export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .ANY_TO_ERC20_PROXY, currentVersion: string = CURRENT_VERSION, diff --git a/packages/advanced-logic/src/extensions/payment-network/any-to-eth-proxy.ts b/packages/advanced-logic/src/extensions/payment-network/any-to-eth-proxy.ts index 425bd47f4d..76c84b5240 100644 --- a/packages/advanced-logic/src/extensions/payment-network/any-to-eth-proxy.ts +++ b/packages/advanced-logic/src/extensions/payment-network/any-to-eth-proxy.ts @@ -1,11 +1,11 @@ -import { ICurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { UnsupportedCurrencyError } from '@requestnetwork/currency'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import EthereumFeeProxyPaymentNetwork from './ethereum/fee-proxy-contract'; const CURRENT_VERSION = '0.2.0'; export default class AnyToEthProxyPaymentNetwork extends EthereumFeeProxyPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { super(currencyManager, ExtensionTypes.PAYMENT_NETWORK_ID.ANY_TO_ETH_PROXY, CURRENT_VERSION); } diff --git a/packages/advanced-logic/src/extensions/payment-network/any-to-native.ts b/packages/advanced-logic/src/extensions/payment-network/any-to-native.ts index a090ed8336..ed349fbaba 100644 --- a/packages/advanced-logic/src/extensions/payment-network/any-to-native.ts +++ b/packages/advanced-logic/src/extensions/payment-network/any-to-native.ts @@ -1,11 +1,10 @@ import { FeeReferenceBasedPaymentNetwork } from './fee-reference-based'; import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import { InvalidPaymentAddressError, UnsupportedNetworkError } from './address-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; export default abstract class AnyToNativeTokenPaymentNetwork extends FeeReferenceBasedPaymentNetwork { protected constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID, currentVersion: string, public readonly supportedNetworks: CurrencyTypes.ChainName[], diff --git a/packages/advanced-logic/src/extensions/payment-network/bitcoin/mainnet-address-based.ts b/packages/advanced-logic/src/extensions/payment-network/bitcoin/mainnet-address-based.ts index e8ca2ab647..2905a4887f 100644 --- a/packages/advanced-logic/src/extensions/payment-network/bitcoin/mainnet-address-based.ts +++ b/packages/advanced-logic/src/extensions/payment-network/bitcoin/mainnet-address-based.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import AddressBasedPaymentNetwork from '../address-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.1.0'; const BITCOIN_NETWORK = 'mainnet'; @@ -13,7 +12,7 @@ const BITCOIN_NETWORK = 'mainnet'; */ export default class BitcoinAddressBasedPaymentNetwork extends AddressBasedPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .BITCOIN_ADDRESS_BASED, ) { diff --git a/packages/advanced-logic/src/extensions/payment-network/bitcoin/testnet-address-based.ts b/packages/advanced-logic/src/extensions/payment-network/bitcoin/testnet-address-based.ts index 962d62d51b..3ecc957fc3 100644 --- a/packages/advanced-logic/src/extensions/payment-network/bitcoin/testnet-address-based.ts +++ b/packages/advanced-logic/src/extensions/payment-network/bitcoin/testnet-address-based.ts @@ -1,6 +1,5 @@ import BitcoinAddressBasedPaymentNetwork from './mainnet-address-based'; -import { ExtensionTypes } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes, ExtensionTypes } from '@requestnetwork/types'; const BITCOIN_NETWORK = 'testnet'; @@ -12,7 +11,7 @@ const BITCOIN_NETWORK = 'testnet'; * Important: the addresses must be exclusive to the request */ export default class BitcoinTestnetAddressBasedPaymentNetwork extends BitcoinAddressBasedPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { super(currencyManager, ExtensionTypes.PAYMENT_NETWORK_ID.TESTNET_BITCOIN_ADDRESS_BASED); } diff --git a/packages/advanced-logic/src/extensions/payment-network/erc20/address-based.ts b/packages/advanced-logic/src/extensions/payment-network/erc20/address-based.ts index fa99dd6b13..2c0b4f1067 100644 --- a/packages/advanced-logic/src/extensions/payment-network/erc20/address-based.ts +++ b/packages/advanced-logic/src/extensions/payment-network/erc20/address-based.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import AddressBasedPaymentNetwork from '../address-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.1.0'; @@ -11,7 +10,7 @@ const CURRENT_VERSION = '0.1.0'; * Important: the addresses must be exclusive to the request */ export default class Erc20AddressBasedPaymentNetwork extends AddressBasedPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { super( currencyManager, ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_ADDRESS_BASED, diff --git a/packages/advanced-logic/src/extensions/payment-network/erc20/fee-proxy-contract.ts b/packages/advanced-logic/src/extensions/payment-network/erc20/fee-proxy-contract.ts index d156322edb..8f62ba49f2 100644 --- a/packages/advanced-logic/src/extensions/payment-network/erc20/fee-proxy-contract.ts +++ b/packages/advanced-logic/src/extensions/payment-network/erc20/fee-proxy-contract.ts @@ -1,5 +1,5 @@ import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; -import { ICurrencyManager, NearChains, isSameChain } from '@requestnetwork/currency'; +import { NearChains, isSameChain } from '@requestnetwork/currency'; import { UnsupportedNetworkError } from '../address-based'; import { FeeReferenceBasedPaymentNetwork } from '../fee-reference-based'; @@ -17,7 +17,7 @@ export default class Erc20FeeProxyPaymentNetwork< * @param network is only relevant for non-EVM chains (Near and Near testnet) */ public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .ERC20_FEE_PROXY_CONTRACT, currentVersion?: string | undefined, diff --git a/packages/advanced-logic/src/extensions/payment-network/erc20/proxy-contract.ts b/packages/advanced-logic/src/extensions/payment-network/erc20/proxy-contract.ts index c9540d68f3..ce99eb33cf 100644 --- a/packages/advanced-logic/src/extensions/payment-network/erc20/proxy-contract.ts +++ b/packages/advanced-logic/src/extensions/payment-network/erc20/proxy-contract.ts @@ -1,5 +1,4 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import ReferenceBasedPaymentNetwork from '../reference-based'; const CURRENT_VERSION = '0.1.0'; @@ -11,7 +10,7 @@ export default class Erc20ProxyPaymentNetwork< TCreationParameters extends ExtensionTypes.PnReferenceBased.ICreationParameters = ExtensionTypes.PnReferenceBased.ICreationParameters, > extends ReferenceBasedPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { super( currencyManager, ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_PROXY_CONTRACT, diff --git a/packages/advanced-logic/src/extensions/payment-network/erc20/transferable-receivable.ts b/packages/advanced-logic/src/extensions/payment-network/erc20/transferable-receivable.ts index 56d20ddb24..2306769cb2 100644 --- a/packages/advanced-logic/src/extensions/payment-network/erc20/transferable-receivable.ts +++ b/packages/advanced-logic/src/extensions/payment-network/erc20/transferable-receivable.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import { FeeReferenceBasedPaymentNetwork } from '../fee-reference-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.2.0'; @@ -12,7 +11,7 @@ export default class Erc20TransferableReceivablePaymentNetwork< ExtensionTypes.PnFeeReferenceBased.ICreationParameters = ExtensionTypes.PnFeeReferenceBased.ICreationParameters, > extends FeeReferenceBasedPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .ERC20_TRANSFERABLE_RECEIVABLE, currentVersion: string = CURRENT_VERSION, diff --git a/packages/advanced-logic/src/extensions/payment-network/erc777/stream.ts b/packages/advanced-logic/src/extensions/payment-network/erc777/stream.ts index b7100f9f4f..370f5a0f5b 100644 --- a/packages/advanced-logic/src/extensions/payment-network/erc777/stream.ts +++ b/packages/advanced-logic/src/extensions/payment-network/erc777/stream.ts @@ -1,7 +1,11 @@ -import { ExtensionTypes, RequestLogicTypes, TypesUtils } from '@requestnetwork/types'; +import { + CurrencyTypes, + ExtensionTypes, + RequestLogicTypes, + TypesUtils, +} from '@requestnetwork/types'; import ReferenceBasedPaymentNetwork from '../reference-based'; import { isValidAmount } from '@requestnetwork/utils'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.1.0'; /** @@ -11,7 +15,7 @@ export default class Erc777StreamPaymentNetwork< TCreationParameters extends ExtensionTypes.PnStreamReferenceBased.ICreationParameters = ExtensionTypes.PnStreamReferenceBased.ICreationParameters, > extends ReferenceBasedPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { super( currencyManager, ExtensionTypes.PAYMENT_NETWORK_ID.ERC777_STREAM, diff --git a/packages/advanced-logic/src/extensions/payment-network/ethereum/fee-proxy-contract.ts b/packages/advanced-logic/src/extensions/payment-network/ethereum/fee-proxy-contract.ts index 3d537b68fa..0d64909689 100644 --- a/packages/advanced-logic/src/extensions/payment-network/ethereum/fee-proxy-contract.ts +++ b/packages/advanced-logic/src/extensions/payment-network/ethereum/fee-proxy-contract.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import { FeeReferenceBasedPaymentNetwork } from '../fee-reference-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.2.0'; @@ -12,7 +11,7 @@ export default class EthereumFeeProxyPaymentNetwork< ExtensionTypes.PnFeeReferenceBased.ICreationParameters = ExtensionTypes.PnFeeReferenceBased.ICreationParameters, > extends FeeReferenceBasedPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .ETH_FEE_PROXY_CONTRACT, currentVersion: string = CURRENT_VERSION, diff --git a/packages/advanced-logic/src/extensions/payment-network/ethereum/input-data.ts b/packages/advanced-logic/src/extensions/payment-network/ethereum/input-data.ts index 03fe8edb10..0454c6299c 100644 --- a/packages/advanced-logic/src/extensions/payment-network/ethereum/input-data.ts +++ b/packages/advanced-logic/src/extensions/payment-network/ethereum/input-data.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import ReferenceBasedPaymentNetwork from '../reference-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.3.0'; @@ -10,7 +9,7 @@ const CURRENT_VERSION = '0.3.0'; */ export default class EthInputPaymentNetwork extends ReferenceBasedPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID = ExtensionTypes.PAYMENT_NETWORK_ID .ETH_INPUT_DATA, currentVersion: string = CURRENT_VERSION, diff --git a/packages/advanced-logic/src/extensions/payment-network/fee-reference-based.ts b/packages/advanced-logic/src/extensions/payment-network/fee-reference-based.ts index d3c7419dec..de0a49eaaa 100644 --- a/packages/advanced-logic/src/extensions/payment-network/fee-reference-based.ts +++ b/packages/advanced-logic/src/extensions/payment-network/fee-reference-based.ts @@ -1,7 +1,11 @@ -import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { + CurrencyTypes, + ExtensionTypes, + IdentityTypes, + RequestLogicTypes, +} from '@requestnetwork/types'; import ReferenceBasedPaymentNetwork from './reference-based'; import { areEqualIdentities, deepCopy, isValidAmount } from '@requestnetwork/utils'; -import { ICurrencyManager } from '@requestnetwork/currency'; /** * Core of the reference based with fee payment networks @@ -12,7 +16,7 @@ export abstract class FeeReferenceBasedPaymentNetwork< ExtensionTypes.PnFeeReferenceBased.ICreationParameters = ExtensionTypes.PnFeeReferenceBased.ICreationParameters, > extends ReferenceBasedPaymentNetwork { protected constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID, currentVersion: string, supportedCurrencyType: RequestLogicTypes.CURRENCY, diff --git a/packages/advanced-logic/src/extensions/payment-network/native-token.ts b/packages/advanced-logic/src/extensions/payment-network/native-token.ts index 03548c40eb..f6cf9c4e54 100644 --- a/packages/advanced-logic/src/extensions/payment-network/native-token.ts +++ b/packages/advanced-logic/src/extensions/payment-network/native-token.ts @@ -2,14 +2,13 @@ import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwor import { InvalidPaymentAddressError, UnsupportedNetworkError } from './address-based'; import ReferenceBasedPaymentNetwork from './reference-based'; -import { ICurrencyManager } from '@requestnetwork/currency'; /** * Implementation of the payment network to pay in ETH based on input data. */ export default abstract class NativeTokenPaymentNetwork extends ReferenceBasedPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, extensionId: ExtensionTypes.PAYMENT_NETWORK_ID, currentVersion: string, public readonly supportedNetworks: CurrencyTypes.ChainName[], diff --git a/packages/advanced-logic/src/extensions/payment-network/near/any-to-near-testnet.ts b/packages/advanced-logic/src/extensions/payment-network/near/any-to-near-testnet.ts index 0c848ea398..0e92c229e9 100644 --- a/packages/advanced-logic/src/extensions/payment-network/near/any-to-near-testnet.ts +++ b/packages/advanced-logic/src/extensions/payment-network/near/any-to-near-testnet.ts @@ -1,8 +1,8 @@ -import { ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes } from '@requestnetwork/types'; import AnyToNearPaymentNetwork from './any-to-near'; export default class AnyToNearTestnetPaymentNetwork extends AnyToNearPaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { // testnet PN version is the same as mainnet, can be overridden here if needed super(currencyManager, ['aurora-testnet', 'near-testnet']); } diff --git a/packages/advanced-logic/src/extensions/payment-network/near/any-to-near.ts b/packages/advanced-logic/src/extensions/payment-network/near/any-to-near.ts index 187550fee6..64373ad91c 100644 --- a/packages/advanced-logic/src/extensions/payment-network/near/any-to-near.ts +++ b/packages/advanced-logic/src/extensions/payment-network/near/any-to-near.ts @@ -1,4 +1,4 @@ -import { ICurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; +import { UnsupportedCurrencyError } from '@requestnetwork/currency'; import { CurrencyTypes, ExtensionTypes, @@ -11,7 +11,7 @@ const CURRENT_VERSION = '0.1.0'; export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, supportedNetworks: CurrencyTypes.NearChainName[] = [ 'aurora', // FIXME: enable near network support diff --git a/packages/advanced-logic/src/extensions/payment-network/near/near-native.ts b/packages/advanced-logic/src/extensions/payment-network/near/near-native.ts index 245ebf40e7..8cc43f8792 100644 --- a/packages/advanced-logic/src/extensions/payment-network/near/near-native.ts +++ b/packages/advanced-logic/src/extensions/payment-network/near/near-native.ts @@ -1,6 +1,5 @@ import { CurrencyTypes, ExtensionTypes } from '@requestnetwork/types'; import NativeTokenPaymentNetwork from '../native-token'; -import { ICurrencyManager } from '@requestnetwork/currency'; const CURRENT_VERSION = '0.2.0'; @@ -9,7 +8,7 @@ const CURRENT_VERSION = '0.2.0'; */ export default class NearNativePaymentNetwork extends NativeTokenPaymentNetwork { public constructor( - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, supportedNetworks: CurrencyTypes.NearChainName[] = [ 'aurora', // FIXME: enable near network support diff --git a/packages/advanced-logic/src/extensions/payment-network/near/near-testnet-native.ts b/packages/advanced-logic/src/extensions/payment-network/near/near-testnet-native.ts index af114b2753..1015e67137 100644 --- a/packages/advanced-logic/src/extensions/payment-network/near/near-testnet-native.ts +++ b/packages/advanced-logic/src/extensions/payment-network/near/near-testnet-native.ts @@ -1,11 +1,11 @@ +import { CurrencyTypes } from '@requestnetwork/types'; import NearNativePaymentNetwork from './near-native'; -import { ICurrencyManager } from '@requestnetwork/currency'; /** * Implementation of the payment network to pay in Near on testnet based on input data. */ export default class NearTestnetNativeNativePaymentNetwork extends NearNativePaymentNetwork { - public constructor(currencyManager: ICurrencyManager) { + public constructor(currencyManager: CurrencyTypes.ICurrencyManager) { // testnet PN version is the same as mainnet, can be overridden here if needed super(currencyManager, ['aurora-testnet', 'near-testnet']); } diff --git a/packages/advanced-logic/test/advanced-logic.test.ts b/packages/advanced-logic/test/advanced-logic.test.ts index baaf086b6c..0c3d12fe35 100644 --- a/packages/advanced-logic/test/advanced-logic.test.ts +++ b/packages/advanced-logic/test/advanced-logic.test.ts @@ -1,3 +1,4 @@ +import { CurrencyManager } from '@requestnetwork/currency'; import { AdvancedLogicTypes, ExtensionTypes } from '@requestnetwork/types'; import * as DataBTCCreate from './utils/payment-network/bitcoin/generator-data-create'; @@ -5,7 +6,6 @@ import * as DataDeclarativeCreate from './utils/payment-network/any/generator-da import * as DataTestnetBTCCreate from './utils/payment-network/bitcoin/testnet-generator-data-create'; import { deepCopy } from '@requestnetwork/utils'; -import { CurrencyManager } from '@requestnetwork/currency'; import { AdvancedLogic } from '../src/index'; diff --git a/packages/advanced-logic/test/extensions/payment-network/erc20/fee-proxy-contract.test.ts b/packages/advanced-logic/test/extensions/payment-network/erc20/fee-proxy-contract.test.ts index d3e831c9a7..1fa5bcb2ed 100644 --- a/packages/advanced-logic/test/extensions/payment-network/erc20/fee-proxy-contract.test.ts +++ b/packages/advanced-logic/test/extensions/payment-network/erc20/fee-proxy-contract.test.ts @@ -8,9 +8,8 @@ import { deepCopy } from '@requestnetwork/utils'; import { CurrencyManager } from '@requestnetwork/currency'; import { AdvancedLogic } from '../../../../src'; -const currencyManager = new CurrencyManager(CurrencyManager.getDefaultList()); +const advancedLogic = new AdvancedLogic(CurrencyManager.getDefault()); -const advancedLogic = new AdvancedLogic(currencyManager); const erc20FeeProxyContract = advancedLogic.getFeeProxyContractErc20ForNetwork(); /* eslint-disable @typescript-eslint/no-unused-expressions */ diff --git a/packages/advanced-logic/test/extensions/payment-network/native-token.test.ts b/packages/advanced-logic/test/extensions/payment-network/native-token.test.ts index e6a2be6c7e..f0f34cd45f 100644 --- a/packages/advanced-logic/test/extensions/payment-network/native-token.test.ts +++ b/packages/advanced-logic/test/extensions/payment-network/native-token.test.ts @@ -1,3 +1,4 @@ +import { CurrencyManager } from '@requestnetwork/currency'; import NativeTokenPaymentNetwork from '../../../src/extensions/payment-network/native-token'; import NearNativePaymentNetwork from '../../../src/extensions/payment-network/near/near-native'; import { @@ -12,11 +13,12 @@ import { import { AdvancedLogic } from '../../../src'; import { arbitraryTimestamp, payeeRaw } from '../../utils/test-data-generator'; import { CurrencyTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; -import { CurrencyManager } from '@requestnetwork/currency'; import NearTestnetNativeNativePaymentNetwork from '../../../src/extensions/payment-network/near/near-testnet-native'; const salt = arbitrarySalt; + const currencyManager = CurrencyManager.getDefault(); +const advancedLogic = new AdvancedLogic(currencyManager); describe('extensions/payment-network/native-token', () => { const nearCurrency = { @@ -172,8 +174,6 @@ describe('extensions/payment-network/native-token', () => { describe('AdvancedLogic.applyActionToExtension', () => { const mainnetTestCase = nativeTokenTestCases[0]; it('works with state and action on the same network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); - const requestState: typeof requestStateNoExtensions = { ...requestStateNoExtensions, currency: mainnetTestCase.currency, @@ -198,8 +198,6 @@ describe('extensions/payment-network/native-token', () => { expect(newExtensionState).toEqual(extensionStateWithNativeTokenPaymentAndRefund); }); it('works with an action without payment network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); - const requestState: typeof requestStateNoExtensions = { ...requestStateNoExtensions, currency: mainnetTestCase.currency, @@ -224,7 +222,6 @@ describe('extensions/payment-network/native-token', () => { expect(newExtensionState).toEqual(extensionStateWithNativeTokenPaymentAndRefund); }); it('works when adding a payment address to a created state', () => { - const advancedLogic = new AdvancedLogic(currencyManager); const nearPn = new NearNativePaymentNetwork(currencyManager); const requestState: typeof requestStateNoExtensions = { @@ -257,7 +254,6 @@ describe('extensions/payment-network/native-token', () => { expect(newExtensionState).toEqual(extensionStateWithPaymentAddressAdded); }); it('throws when creating the extension on a different network from the request network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); const nearPn = new NearTestnetNativeNativePaymentNetwork(currencyManager); const requestState: typeof requestStateNoExtensions = { @@ -278,7 +274,6 @@ describe('extensions/payment-network/native-token', () => { ); }); it('throws when adding a payment address a different network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); const nearPn = new NearNativePaymentNetwork(currencyManager); const requestState: typeof requestStateNoExtensions = { @@ -301,8 +296,6 @@ describe('extensions/payment-network/native-token', () => { }).toThrowError("paymentAddress 'pay.testnet' is not a valid address"); }); it('throws with no state or action payment network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); - const wrongNativeTokenRequestState: typeof requestStateNoExtensions = { ...requestStateNoExtensions, currency: { @@ -330,7 +323,6 @@ describe('extensions/payment-network/native-token', () => { ).toThrowError('extension with id: pn-native-token not found for network: undefined'); }); it('throws on a wrong payment network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); const wrongNetwork = `wrong network` as CurrencyTypes.EvmChainName; const wrongNativeTokenRequestState: typeof requestStateNoExtensions = { @@ -360,8 +352,6 @@ describe('extensions/payment-network/native-token', () => { ).toThrowError('extension with id: pn-native-token not found for network: wrong network'); }); it('throws on a different payment network', () => { - const advancedLogic = new AdvancedLogic(currencyManager); - const requestState = { ...requestStateNoExtensions, currency: mainnetTestCase.currency, @@ -389,7 +379,6 @@ describe('extensions/payment-network/native-token', () => { }); it('keeps the version used at creation', () => { - const advancedLogic = new AdvancedLogic(currencyManager); const requestState = { ...requestStateNoExtensions, currency: mainnetTestCase.currency, @@ -406,7 +395,6 @@ describe('extensions/payment-network/native-token', () => { it('requires a version at creation', () => { expect(() => { - const advancedLogic = new AdvancedLogic(currencyManager); const requestState = { ...requestStateNoExtensions, currency: mainnetTestCase.currency, diff --git a/packages/currency/src/chains/ChainsAbstract.ts b/packages/currency/src/chains/ChainsAbstract.ts index d498baa959..dba788f096 100644 --- a/packages/currency/src/chains/ChainsAbstract.ts +++ b/packages/currency/src/chains/ChainsAbstract.ts @@ -1,10 +1,9 @@ -import { Chain, NamedNativeCurrency, TokenMap } from '../types'; import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; import { nativeCurrencies } from '../native'; export abstract class ChainsAbstract< CHAIN_NAME extends CurrencyTypes.ChainName, - CHAIN extends Chain, + CHAIN extends CurrencyTypes.Chain, CHAIN_ID extends string | number, > { public chains: Record; @@ -26,11 +25,11 @@ export abstract class ChainsAbstract< currencyType: RequestLogicTypes.CURRENCY.ETH | RequestLogicTypes.CURRENCY.BTC, ): void { this.chainNames.forEach((chainName) => { - const nativeCurrency = (nativeCurrencies[currencyType] as NamedNativeCurrency[]).find( - (currency) => currency.network === chainName, - ); + const nativeCurrency = ( + nativeCurrencies[currencyType] as CurrencyTypes.NamedNativeCurrency[] + ).find((currency) => currency.network === chainName); if (nativeCurrency) { - const chainCurrencies: TokenMap = this.chains[chainName].currencies || {}; + const chainCurrencies: CurrencyTypes.TokenMap = this.chains[chainName].currencies || {}; chainCurrencies.native = nativeCurrency; this.chains[chainName].currencies = chainCurrencies; } diff --git a/packages/currency/src/chains/btc/index.ts b/packages/currency/src/chains/btc/index.ts index 7c46a09b8e..4bd034af42 100644 --- a/packages/currency/src/chains/btc/index.ts +++ b/packages/currency/src/chains/btc/index.ts @@ -1,10 +1,9 @@ import { CurrencyTypes } from '@requestnetwork/types'; -import { Chain } from '../../types'; import * as MainnetDefinition from './data/mainnet'; import * as TestnetDefinition from './data/testnet'; -export type BtcChain = Chain & { +export type BtcChain = CurrencyTypes.Chain & { chainId: string; }; diff --git a/packages/currency/src/chains/declarative/index.ts b/packages/currency/src/chains/declarative/index.ts index 6e38952bd8..a83e9163e6 100644 --- a/packages/currency/src/chains/declarative/index.ts +++ b/packages/currency/src/chains/declarative/index.ts @@ -1,10 +1,9 @@ import { CurrencyTypes } from '@requestnetwork/types'; -import { Chain } from '../../types'; import * as TronDefinition from './data/tron'; import * as SolanaDefinition from './data/solana'; -export type DeclarativeChain = Chain; +export type DeclarativeChain = CurrencyTypes.Chain; export const chains: Record = { tron: TronDefinition, diff --git a/packages/currency/src/chains/evm/data/avalanche.ts b/packages/currency/src/chains/evm/data/avalanche.ts index 6bd1c9f5d6..c81c7184f3 100644 --- a/packages/currency/src/chains/evm/data/avalanche.ts +++ b/packages/currency/src/chains/evm/data/avalanche.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedAvalancheERC20 } from '../../../erc20/chains/avalanche'; export const chainId = 43114; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedAvalancheERC20, }; diff --git a/packages/currency/src/chains/evm/data/base.ts b/packages/currency/src/chains/evm/data/base.ts index e9e169645e..e5a59bb077 100644 --- a/packages/currency/src/chains/evm/data/base.ts +++ b/packages/currency/src/chains/evm/data/base.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedBaseERC20 } from '../../../erc20/chains/base'; export const chainId = 8453; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedBaseERC20, }; diff --git a/packages/currency/src/chains/evm/data/bsc.ts b/packages/currency/src/chains/evm/data/bsc.ts index b13f8f522a..23f9b1cddb 100644 --- a/packages/currency/src/chains/evm/data/bsc.ts +++ b/packages/currency/src/chains/evm/data/bsc.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedBSCERC20 } from '../../../erc20/chains/bsc'; export const chainId = 56; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedBSCERC20, }; diff --git a/packages/currency/src/chains/evm/data/bsctest.ts b/packages/currency/src/chains/evm/data/bsctest.ts index 7fc2bc374e..3999b4ebd2 100644 --- a/packages/currency/src/chains/evm/data/bsctest.ts +++ b/packages/currency/src/chains/evm/data/bsctest.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedBSCTestERC20 } from '../../../erc20/chains/bsctest'; export const chainId = 97; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedBSCTestERC20, }; diff --git a/packages/currency/src/chains/evm/data/celo.ts b/packages/currency/src/chains/evm/data/celo.ts index f07c603cd4..136aa8dc08 100644 --- a/packages/currency/src/chains/evm/data/celo.ts +++ b/packages/currency/src/chains/evm/data/celo.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedCeloERC20 } from '../../../erc20/chains/celo'; export const chainId = 42220; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedCeloERC20, }; diff --git a/packages/currency/src/chains/evm/data/fantom.ts b/packages/currency/src/chains/evm/data/fantom.ts index 596a2db0db..ac68f6b4a2 100644 --- a/packages/currency/src/chains/evm/data/fantom.ts +++ b/packages/currency/src/chains/evm/data/fantom.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedFantomERC20 } from '../../../erc20/chains/fantom'; export const chainId = 250; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedFantomERC20, }; diff --git a/packages/currency/src/chains/evm/data/goerli.ts b/packages/currency/src/chains/evm/data/goerli.ts index 2f700bcfbd..e4fee26de4 100644 --- a/packages/currency/src/chains/evm/data/goerli.ts +++ b/packages/currency/src/chains/evm/data/goerli.ts @@ -1,8 +1,8 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedGoerliERC20 } from '../../../erc20/chains/goerli'; export const chainId = 5; export const testnet = true; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedGoerliERC20, }; diff --git a/packages/currency/src/chains/evm/data/mainnet.ts b/packages/currency/src/chains/evm/data/mainnet.ts index 4e6bb83ceb..2be9434314 100644 --- a/packages/currency/src/chains/evm/data/mainnet.ts +++ b/packages/currency/src/chains/evm/data/mainnet.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedMainnetERC20 } from '../../../erc20/chains/mainnet'; export const chainId = 1; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedMainnetERC20, }; diff --git a/packages/currency/src/chains/evm/data/matic.ts b/packages/currency/src/chains/evm/data/matic.ts index a7738d898c..71ca52ee11 100644 --- a/packages/currency/src/chains/evm/data/matic.ts +++ b/packages/currency/src/chains/evm/data/matic.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedMaticERC20 } from '../../../erc20/chains/matic'; export const chainId = 137; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedMaticERC20, }; diff --git a/packages/currency/src/chains/evm/data/moonbeam.ts b/packages/currency/src/chains/evm/data/moonbeam.ts index de586f0b7b..bbd10c93ed 100644 --- a/packages/currency/src/chains/evm/data/moonbeam.ts +++ b/packages/currency/src/chains/evm/data/moonbeam.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedMoonbeamERC20 } from '../../../erc20/chains/moonbeam'; export const chainId = 1284; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedMoonbeamERC20, }; diff --git a/packages/currency/src/chains/evm/data/optimism.ts b/packages/currency/src/chains/evm/data/optimism.ts index 447d2f2300..148505bc05 100644 --- a/packages/currency/src/chains/evm/data/optimism.ts +++ b/packages/currency/src/chains/evm/data/optimism.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedOptimismERC20 } from '../../../erc20/chains/optimism'; export const chainId = 10; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedOptimismERC20, }; diff --git a/packages/currency/src/chains/evm/data/rinkeby.ts b/packages/currency/src/chains/evm/data/rinkeby.ts index aa9da936d3..41892377fd 100644 --- a/packages/currency/src/chains/evm/data/rinkeby.ts +++ b/packages/currency/src/chains/evm/data/rinkeby.ts @@ -1,10 +1,10 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedRinkebyERC20 } from '../../../erc20/chains/rinkeby'; import { supportedRinkebyERC777 } from '../../../erc777/chains/rinkeby'; export const chainId = 4; export const testnet = true; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedRinkebyERC20, ...supportedRinkebyERC777, }; diff --git a/packages/currency/src/chains/evm/data/sepolia.ts b/packages/currency/src/chains/evm/data/sepolia.ts index 9b90d7f875..8c7d7999d3 100644 --- a/packages/currency/src/chains/evm/data/sepolia.ts +++ b/packages/currency/src/chains/evm/data/sepolia.ts @@ -1,8 +1,8 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedSepoliaERC20 } from '../../../erc20/chains/sepolia'; export const chainId = 11155111; export const testnet = true; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedSepoliaERC20, }; diff --git a/packages/currency/src/chains/evm/data/xdai.ts b/packages/currency/src/chains/evm/data/xdai.ts index edbf8ba0ce..9d32ec8489 100644 --- a/packages/currency/src/chains/evm/data/xdai.ts +++ b/packages/currency/src/chains/evm/data/xdai.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; import { supportedXDAIERC20 } from '../../../erc20/chains/xdai'; export const chainId = 100; -export const currencies: TokenMap = { +export const currencies: CurrencyTypes.TokenMap = { ...supportedXDAIERC20, }; diff --git a/packages/currency/src/chains/evm/index.ts b/packages/currency/src/chains/evm/index.ts index 445b9fbec6..6c4123071b 100644 --- a/packages/currency/src/chains/evm/index.ts +++ b/packages/currency/src/chains/evm/index.ts @@ -1,5 +1,4 @@ import { CurrencyTypes } from '@requestnetwork/types'; -import { Chain } from '../../types'; import * as AlfajoresDefinition from './data/alfajores'; import * as ArbitrumOneDefinition from './data/arbitrum-one'; @@ -30,7 +29,7 @@ import * as ZkSyncEraTestnetDefinition from './data/zksync-era-testnet'; import * as ZkSyncEraDefinition from './data/zksync-era'; import * as BaseDefinition from './data/base'; -export type EvmChain = Chain & { +export type EvmChain = CurrencyTypes.Chain & { chainId: number; }; diff --git a/packages/currency/src/chains/near/index.ts b/packages/currency/src/chains/near/index.ts index 923cce384f..fed367a6ce 100644 --- a/packages/currency/src/chains/near/index.ts +++ b/packages/currency/src/chains/near/index.ts @@ -1,10 +1,9 @@ import { CurrencyTypes } from '@requestnetwork/types'; -import { Chain } from '../../types'; import * as NearDefinition from './data/near'; import * as NearTestnetDefinition from './data/near-testnet'; -export type NearChain = Chain; +export type NearChain = CurrencyTypes.Chain; export const chains: Record = { aurora: NearDefinition, diff --git a/packages/currency/src/conversion-aggregators.ts b/packages/currency/src/conversion-aggregators.ts index b37affbe4a..9d0f4e0ddf 100644 --- a/packages/currency/src/conversion-aggregators.ts +++ b/packages/currency/src/conversion-aggregators.ts @@ -1,5 +1,5 @@ import GRAPH from 'node-dijkstra'; -import { CurrencyDefinition } from './types'; +import { CurrencyTypes } from '@requestnetwork/types'; import privateAggregator from './aggregators/private.json'; import mainnetAggregator from './aggregators/mainnet.json'; @@ -8,24 +8,9 @@ import sepoliaAggregator from './aggregators/sepolia.json'; import rinkebyAggregator from './aggregators/rinkeby.json'; import maticAggregator from './aggregators/matic.json'; import fantomAggregator from './aggregators/fantom.json'; -import { CurrencyTypes } from '@requestnetwork/types'; - -/** - * currencyFrom => currencyTo => cost - */ -export type CurrencyPairs = Record>; - -/** - * Aggregators maps define pairs of currencies for which an onchain oracle exists, by network. - * - * Network => currencyFrom => currencyTo => cost - */ -export type AggregatorsMap = Partial< - Record ->; // Pairs supported by Chainlink (can be generated from requestNetwork/toolbox/src/chainlinkConversionPathTools.ts) -const chainlinkCurrencyPairs: AggregatorsMap = { +const chainlinkCurrencyPairs: CurrencyTypes.AggregatorsMap = { private: privateAggregator, goerli: goerliAggregator, rinkeby: rinkebyAggregator, @@ -37,7 +22,7 @@ const chainlinkCurrencyPairs: AggregatorsMap = { // FIXME: This fix enables to get these networks registered in conversionSupportedNetworks. // Could be improved by removing the supported network check from the protocol -const noConversionNetworks: AggregatorsMap = { +const noConversionNetworks: CurrencyTypes.AggregatorsMap = { 'arbitrum-rinkeby': {}, 'arbitrum-one': {}, xdai: {}, @@ -54,7 +39,7 @@ const noConversionNetworks: AggregatorsMap = { * Conversion paths per network used by default if no other path given to the Currency Manager. * Must be updated every time an aggregator is added to one network. */ -export const defaultConversionPairs: AggregatorsMap = { +export const defaultConversionPairs: CurrencyTypes.AggregatorsMap = { ...chainlinkCurrencyPairs, ...noConversionNetworks, }; @@ -74,8 +59,8 @@ export const conversionSupportedNetworks = Object.keys( * @returns conversion path */ export function getPath( - currencyFrom: Pick, - currencyTo: Pick, + currencyFrom: Pick, + currencyTo: Pick, network: CurrencyTypes.ChainName = 'mainnet', pairs = defaultConversionPairs, ): string[] | null { diff --git a/packages/currency/src/currency-utils.ts b/packages/currency/src/currency-utils.ts index 9da5ca87b0..0464b9d4bc 100644 --- a/packages/currency/src/currency-utils.ts +++ b/packages/currency/src/currency-utils.ts @@ -1,11 +1,4 @@ -import { - CurrencyInput, - ERC20CurrencyInput, - ERC777CurrencyInput, - ISO4217CurrencyInput, - NativeCurrencyInput, -} from './types'; -import { RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; /** * Checks if a Near address is valid according to a currency network. @@ -48,21 +41,29 @@ export const isValidNearAddress = (address: string, network?: string): boolean = * Enable filtering per currency type */ -export const isNativeCurrency = (currency: CurrencyInput): currency is NativeCurrencyInput => { +export const isNativeCurrency = ( + currency: CurrencyTypes.CurrencyInput, +): currency is CurrencyTypes.NativeCurrencyInput => { return ( currency.type === RequestLogicTypes.CURRENCY.BTC || currency.type === RequestLogicTypes.CURRENCY.ETH ); }; -export const isISO4217Currency = (currency: CurrencyInput): currency is ISO4217CurrencyInput => { +export const isISO4217Currency = ( + currency: CurrencyTypes.CurrencyInput, +): currency is CurrencyTypes.ISO4217CurrencyInput => { return currency.type === RequestLogicTypes.CURRENCY.ISO4217; }; -export const isERC20Currency = (currency: CurrencyInput): currency is ERC20CurrencyInput => { +export const isERC20Currency = ( + currency: CurrencyTypes.CurrencyInput, +): currency is CurrencyTypes.ERC20CurrencyInput => { return currency.type === RequestLogicTypes.CURRENCY.ERC20; }; -export const isERC777Currency = (currency: CurrencyInput): currency is ERC777CurrencyInput => { +export const isERC777Currency = ( + currency: CurrencyTypes.CurrencyInput, +): currency is CurrencyTypes.ERC777CurrencyInput => { return currency.type === RequestLogicTypes.CURRENCY.ERC777; }; diff --git a/packages/currency/src/currencyManager.ts b/packages/currency/src/currencyManager.ts index d5e9d22907..3bc12f63d5 100644 --- a/packages/currency/src/currencyManager.ts +++ b/packages/currency/src/currencyManager.ts @@ -6,16 +6,7 @@ import { getSupportedERC777Tokens } from './erc777'; import { getHash } from './getHash'; import iso4217 from './iso4217'; import { nativeCurrencies } from './native'; -import { - StorageCurrency, - CurrencyDefinition, - CurrencyInput, - ERC20Currency, - ICurrencyManager, - LegacyTokenMap, - NativeCurrencyType, -} from './types'; -import { defaultConversionPairs, AggregatorsMap, getPath } from './conversion-aggregators'; +import { defaultConversionPairs, getPath } from './conversion-aggregators'; import { isValidNearAddress } from './currency-utils'; import { NearChains } from './chains'; @@ -24,10 +15,10 @@ const { BTC, ERC20, ERC777, ETH, ISO4217 } = RequestLogicTypes.CURRENCY; /** * Handles a list of currencies and provide features to retrieve them, as well as convert to/from storage format */ -export class CurrencyManager implements ICurrencyManager { - private readonly knownCurrencies: CurrencyDefinition[]; - private readonly legacyTokens: LegacyTokenMap; - private readonly conversionPairs: AggregatorsMap; +export class CurrencyManager implements CurrencyTypes.ICurrencyManager { + private readonly knownCurrencies: CurrencyTypes.CurrencyDefinition[]; + private readonly legacyTokens: CurrencyTypes.LegacyTokenMap; + private readonly conversionPairs: CurrencyTypes.AggregatorsMap; private static defaultInstance: CurrencyManager; @@ -38,9 +29,9 @@ export class CurrencyManager implements ICurrencyManager * @param conversionPairs A mapping of possible conversions by network (network => currencyFrom => currencyTo => cost) */ constructor( - inputCurrencies: (CurrencyInput & { id?: string; meta?: TMeta })[], - legacyTokens?: LegacyTokenMap, - conversionPairs?: AggregatorsMap, + inputCurrencies: (CurrencyTypes.CurrencyInput & { id?: string; meta?: TMeta })[], + legacyTokens?: CurrencyTypes.LegacyTokenMap, + conversionPairs?: CurrencyTypes.AggregatorsMap, ) { this.knownCurrencies = []; for (const input of inputCurrencies) { @@ -64,7 +55,7 @@ export class CurrencyManager implements ICurrencyManager from( currencyIdentifier: string | undefined, network?: CurrencyTypes.ChainName, - ): CurrencyDefinition | undefined { + ): CurrencyTypes.CurrencyDefinition | undefined { if (!currencyIdentifier) { return; } @@ -90,9 +81,9 @@ export class CurrencyManager implements ICurrencyManager } /** - * Gets a supported currency from its CurrencyDefinition id + * Gets a supported currency from its CurrencyTypes.CurrencyDefinition id */ - fromId(id: string): CurrencyDefinition | undefined { + fromId(id: string): CurrencyTypes.CurrencyDefinition | undefined { return this.knownCurrencies.find((knownCurrency) => knownCurrency.id === id); } @@ -100,7 +91,10 @@ export class CurrencyManager implements ICurrencyManager * Gets a supported currency from its address and network. * If more than one currency are found, undefined is returned */ - fromAddress(address: string, network?: string): CurrencyDefinition | undefined { + fromAddress( + address: string, + network?: string, + ): CurrencyTypes.CurrencyDefinition | undefined { address = utils.getAddress(address); const matches = this.knownCurrencies.filter( (x) => @@ -109,7 +103,7 @@ export class CurrencyManager implements ICurrencyManager (!network || x.network === network), ); if (matches.length > 1) { - const networks = matches.map((x) => (x as ERC20Currency).network).join(', '); + const networks = matches.map((x) => (x as CurrencyTypes.ERC20Currency).network).join(', '); console.warn( `${address} has several matches on ${networks}. To avoid errors, specify a network.`, ); @@ -124,7 +118,7 @@ export class CurrencyManager implements ICurrencyManager fromSymbol( symbol: string, network?: CurrencyTypes.ChainName, - ): CurrencyDefinition | undefined { + ): CurrencyTypes.CurrencyDefinition | undefined { symbol = symbol?.toUpperCase(); network = network?.toLowerCase() as CurrencyTypes.ChainName | undefined; @@ -140,7 +134,7 @@ export class CurrencyManager implements ICurrencyManager ); } - fromHash(hash: string, network?: string): CurrencyDefinition | undefined { + fromHash(hash: string, network?: string): CurrencyTypes.CurrencyDefinition | undefined { return this.knownCurrencies.find( (x) => x.hash.toLowerCase() === hash.toLowerCase() && @@ -150,7 +144,9 @@ export class CurrencyManager implements ICurrencyManager /** * Retrieves a currency given its storage format (ICurrency) */ - fromStorageCurrency(currency: StorageCurrency): CurrencyDefinition | undefined { + fromStorageCurrency( + currency: CurrencyTypes.StorageCurrency, + ): CurrencyTypes.CurrencyDefinition | undefined { if (!currency) { return; } @@ -173,15 +169,15 @@ export class CurrencyManager implements ICurrencyManager * Retrieves a Native currency for a type and network */ getNativeCurrency( - type: NativeCurrencyType, + type: CurrencyTypes.NativeCurrencyType, network: string, - ): CurrencyDefinition | undefined { + ): CurrencyTypes.CurrencyDefinition | undefined { return this.knownCurrencies.find((x) => x.type === type && x.network === network); } getConversionPath( - from: Pick, - to: Pick, + from: Pick, + to: Pick, network: CurrencyTypes.ChainName, ): string[] | null { try { @@ -192,21 +188,25 @@ export class CurrencyManager implements ICurrencyManager } supportsConversion( - currency: Pick, + currency: Pick, network: CurrencyTypes.ChainName, ): boolean { return !!this.conversionPairs[network]?.[currency.hash.toLowerCase()]; } /** - * Adds computed parameters to a CurrencyInput + * Adds computed parameters to a CurrencyTypes.CurrencyInput */ static fromInput({ id, hash, meta, ...input - }: CurrencyInput & { id?: string; hash?: string; meta?: TMeta }): CurrencyDefinition { + }: CurrencyTypes.CurrencyInput & { + id?: string; + hash?: string; + meta?: TMeta; + }): CurrencyTypes.CurrencyDefinition { if ('address' in input) { if (input.address.startsWith('0x') && input.address.length === 42) { input.address = utils.getAddress(input.address); @@ -230,7 +230,7 @@ export class CurrencyManager implements ICurrencyManager /** * Converts a currency to the storage format (ICurrency) */ - static toStorageCurrency(currency: CurrencyInput): StorageCurrency { + static toStorageCurrency(currency: CurrencyTypes.CurrencyInput): CurrencyTypes.StorageCurrency { return { type: currency.type, value: @@ -243,7 +243,10 @@ export class CurrencyManager implements ICurrencyManager * Validates an address for a given currency. * Throws if the currency is an ISO4217 currency. */ - validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean { + validateAddress( + address: string, + currency: CurrencyTypes.CurrencyInput | CurrencyTypes.StorageCurrency, + ): boolean { if (currency.type === RequestLogicTypes.CURRENCY.ISO4217) { throw new Error(`Could not validate an address for an ISO4217 currency`); } @@ -271,7 +274,7 @@ export class CurrencyManager implements ICurrencyManager /** * Validate the correctness of a Storage Currency */ - validateCurrency(currency: StorageCurrency): boolean { + validateCurrency(currency: CurrencyTypes.StorageCurrency): boolean { if ( currency.type === RequestLogicTypes.CURRENCY.ISO4217 || currency.type === RequestLogicTypes.CURRENCY.ETH || @@ -291,22 +294,34 @@ export class CurrencyManager implements ICurrencyManager * - NEAR, YEL, ZIL, BTC * - ETH-rinkeby, FAU-rinkeby, CTBK-rinkeby */ - static getDefaultList(): CurrencyDefinition[] { - const isoCurrencies: CurrencyInput[] = iso4217.map((cc) => ({ + static getDefaultList(): CurrencyTypes.CurrencyDefinition[] { + const isoCurrencies: CurrencyTypes.CurrencyInput[] = iso4217.map((cc) => ({ decimals: cc.digits, name: cc.currency, symbol: cc.code, type: ISO4217, })); - const eth: CurrencyInput[] = nativeCurrencies.ETH.map((x) => ({ ...x, type: ETH })); - const btc: CurrencyInput[] = nativeCurrencies.BTC.map((x) => ({ ...x, type: BTC })); + const eth: CurrencyTypes.CurrencyInput[] = nativeCurrencies.ETH.map((x) => ({ + ...x, + type: ETH, + })); + const btc: CurrencyTypes.CurrencyInput[] = nativeCurrencies.BTC.map((x) => ({ + ...x, + type: BTC, + })); const erc20Tokens = getSupportedERC20Tokens(); - const erc20Currencies: CurrencyInput[] = erc20Tokens.map((x) => ({ ...x, type: ERC20 })); + const erc20Currencies: CurrencyTypes.CurrencyInput[] = erc20Tokens.map((x) => ({ + ...x, + type: ERC20, + })); const erc777Tokens = getSupportedERC777Tokens(); - const erc777Currencies: CurrencyInput[] = erc777Tokens.map((x) => ({ ...x, type: ERC777 })); + const erc777Currencies: CurrencyTypes.CurrencyInput[] = erc777Tokens.map((x) => ({ + ...x, + type: ERC777, + })); return isoCurrencies .concat(erc20Currencies) @@ -319,7 +334,7 @@ export class CurrencyManager implements ICurrencyManager /** * Returns the default list of legacy names (for symbol or network) */ - static getDefaultLegacyTokens(): LegacyTokenMap { + static getDefaultLegacyTokens(): CurrencyTypes.LegacyTokenMap { return { near: { NEAR: ['NEAR', 'aurora'], @@ -327,7 +342,7 @@ export class CurrencyManager implements ICurrencyManager }; } - static getDefaultConversionPairs(): AggregatorsMap { + static getDefaultConversionPairs(): CurrencyTypes.AggregatorsMap { return defaultConversionPairs; } diff --git a/packages/currency/src/erc20/chains/avalanche.ts b/packages/currency/src/erc20/chains/avalanche.ts index b9ca4bd490..3b01b8688c 100644 --- a/packages/currency/src/erc20/chains/avalanche.ts +++ b/packages/currency/src/erc20/chains/avalanche.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsc network tokens -export const supportedAvalancheERC20: TokenMap = { +export const supportedAvalancheERC20: CurrencyTypes.TokenMap = { '0x9fB1d52596c44603198fB0aee434fac3a679f702': { name: 'Jarvis Synthetic Euro', symbol: 'jEUR', diff --git a/packages/currency/src/erc20/chains/base.ts b/packages/currency/src/erc20/chains/base.ts index b3f9c892aa..4e6ce9c84d 100644 --- a/packages/currency/src/erc20/chains/base.ts +++ b/packages/currency/src/erc20/chains/base.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported base network tokens -export const supportedBaseERC20: TokenMap = { +export const supportedBaseERC20: CurrencyTypes.TokenMap = { '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb': { name: 'Dai Stablecoin', symbol: 'DAI', diff --git a/packages/currency/src/erc20/chains/bsc.ts b/packages/currency/src/erc20/chains/bsc.ts index c423a1003d..2344cc7138 100644 --- a/packages/currency/src/erc20/chains/bsc.ts +++ b/packages/currency/src/erc20/chains/bsc.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsc network tokens -export const supportedBSCERC20: TokenMap = { +export const supportedBSCERC20: CurrencyTypes.TokenMap = { '0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3': { name: 'Binance-Peg Dai Token', symbol: 'DAI', diff --git a/packages/currency/src/erc20/chains/bsctest.ts b/packages/currency/src/erc20/chains/bsctest.ts index e5dd428752..766a5dbf30 100644 --- a/packages/currency/src/erc20/chains/bsctest.ts +++ b/packages/currency/src/erc20/chains/bsctest.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsctest network tokens -export const supportedBSCTestERC20: TokenMap = { +export const supportedBSCTestERC20: CurrencyTypes.TokenMap = { '0xEC5dCb5Dbf4B114C9d0F65BcCAb49EC54F6A0867': { name: 'DAI Token', symbol: 'DAI', diff --git a/packages/currency/src/erc20/chains/celo.ts b/packages/currency/src/erc20/chains/celo.ts index 9e56e7882f..aa3be99dfa 100644 --- a/packages/currency/src/erc20/chains/celo.ts +++ b/packages/currency/src/erc20/chains/celo.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported celo network tokens -export const supportedCeloERC20: TokenMap = { +export const supportedCeloERC20: CurrencyTypes.TokenMap = { // https://explorer.celo.org/address/0x765de816845861e75a25fca122bb6898b8b1282a/read_contract '0x765DE816845861e75A25fCA122bb6898B8B1282a': { // FIXME: should be cUSD, need to work on the retrocompatibility diff --git a/packages/currency/src/erc20/chains/fantom.ts b/packages/currency/src/erc20/chains/fantom.ts index 33c47b9b79..e83d66a31c 100644 --- a/packages/currency/src/erc20/chains/fantom.ts +++ b/packages/currency/src/erc20/chains/fantom.ts @@ -1,6 +1,6 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; -export const supportedFantomERC20: TokenMap = { +export const supportedFantomERC20: CurrencyTypes.TokenMap = { '0xD3b71117E6C1558c1553305b44988cd944e97300': { name: 'YEL Token', symbol: 'YEL', diff --git a/packages/currency/src/erc20/chains/goerli.ts b/packages/currency/src/erc20/chains/goerli.ts index 68596661dd..dedf62dcd2 100644 --- a/packages/currency/src/erc20/chains/goerli.ts +++ b/packages/currency/src/erc20/chains/goerli.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported goerli ERC20 tokens -export const supportedGoerliERC20: TokenMap = { +export const supportedGoerliERC20: CurrencyTypes.TokenMap = { // Faucet Token on goerli network. '0xBA62BCfcAaFc6622853cca2BE6Ac7d845BC0f2Dc': { decimals: 18, diff --git a/packages/currency/src/erc20/chains/index.ts b/packages/currency/src/erc20/chains/index.ts index fa2dad08d9..832cd639c0 100644 --- a/packages/currency/src/erc20/chains/index.ts +++ b/packages/currency/src/erc20/chains/index.ts @@ -1,4 +1,3 @@ -import { TokenMap } from '../../types'; import { CurrencyTypes } from '@requestnetwork/types'; import { supportedAvalancheERC20 } from './avalanche'; @@ -15,7 +14,9 @@ import { supportedRinkebyERC20 } from './rinkeby'; import { supportedXDAIERC20 } from './xdai'; import { supportedSepoliaERC20 } from './sepolia'; -export const supportedNetworks: Partial> = { +export const supportedNetworks: Partial< + Record +> = { celo: supportedCeloERC20, // FIXME: Rinkeby is deprecated rinkeby: supportedRinkebyERC20, diff --git a/packages/currency/src/erc20/chains/mainnet.ts b/packages/currency/src/erc20/chains/mainnet.ts index 4026029f12..762091c181 100644 --- a/packages/currency/src/erc20/chains/mainnet.ts +++ b/packages/currency/src/erc20/chains/mainnet.ts @@ -1,5 +1,5 @@ import * as metamaskContractMap from '@metamask/contract-metadata'; -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // These interfaces are declared here because they should be used only in this context // A Token description from the eth-contract-metadata list @@ -74,7 +74,7 @@ export const extraERC20Tokens = { }; // Merge metamask contracts list with our own -export const supportedMainnetERC20: TokenMap = { +export const supportedMainnetERC20: CurrencyTypes.TokenMap = { ...Object.entries(metamaskContractMap as IMetamaskTokenMap) .filter(([, val]) => val.erc20) .reduce( diff --git a/packages/currency/src/erc20/chains/matic.ts b/packages/currency/src/erc20/chains/matic.ts index a3b8a01a7a..29bbbe3059 100644 --- a/packages/currency/src/erc20/chains/matic.ts +++ b/packages/currency/src/erc20/chains/matic.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported matic network tokens -export const supportedMaticERC20: TokenMap = { +export const supportedMaticERC20: CurrencyTypes.TokenMap = { '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063': { name: '(PoS) Dai Stablecoin', symbol: 'DAI', diff --git a/packages/currency/src/erc20/chains/moonbeam.ts b/packages/currency/src/erc20/chains/moonbeam.ts index 12aca53a59..06e6e562ef 100644 --- a/packages/currency/src/erc20/chains/moonbeam.ts +++ b/packages/currency/src/erc20/chains/moonbeam.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsc network tokens -export const supportedMoonbeamERC20: TokenMap = { +export const supportedMoonbeamERC20: CurrencyTypes.TokenMap = { '0x818ec0A7Fe18Ff94269904fCED6AE3DaE6d6dC0b': { name: 'USDC Multichain', symbol: 'USDC-multichain', diff --git a/packages/currency/src/erc20/chains/optimism.ts b/packages/currency/src/erc20/chains/optimism.ts index 439c079c8c..9a2677cbae 100644 --- a/packages/currency/src/erc20/chains/optimism.ts +++ b/packages/currency/src/erc20/chains/optimism.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsc network tokens -export const supportedOptimismERC20: TokenMap = { +export const supportedOptimismERC20: CurrencyTypes.TokenMap = { '0x7F5c764cBc14f9669B88837ca1490cCa17c31607': { name: 'USD Coin', symbol: 'USDC', diff --git a/packages/currency/src/erc20/chains/rinkeby.ts b/packages/currency/src/erc20/chains/rinkeby.ts index 8540c0faab..2eff4a66cc 100644 --- a/packages/currency/src/erc20/chains/rinkeby.ts +++ b/packages/currency/src/erc20/chains/rinkeby.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported rinkeby ERC20 tokens -export const supportedRinkebyERC20: TokenMap = { +export const supportedRinkebyERC20: CurrencyTypes.TokenMap = { // Request Central Bank token, used for testing on rinkeby. '0x995d6A8C21F24be1Dd04E105DD0d83758343E258': { decimals: 18, diff --git a/packages/currency/src/erc20/chains/sepolia.ts b/packages/currency/src/erc20/chains/sepolia.ts index bf834503cb..aae4553438 100644 --- a/packages/currency/src/erc20/chains/sepolia.ts +++ b/packages/currency/src/erc20/chains/sepolia.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported goerli ERC20 tokens -export const supportedSepoliaERC20: TokenMap = { +export const supportedSepoliaERC20: CurrencyTypes.TokenMap = { // Faucet Token on goerli network. '0x370DE27fdb7D1Ff1e1BaA7D11c5820a324Cf623C': { decimals: 18, diff --git a/packages/currency/src/erc20/chains/xdai.ts b/packages/currency/src/erc20/chains/xdai.ts index 2dbbbb4114..8268436a0a 100644 --- a/packages/currency/src/erc20/chains/xdai.ts +++ b/packages/currency/src/erc20/chains/xdai.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported bsc network tokens -export const supportedXDAIERC20: TokenMap = { +export const supportedXDAIERC20: CurrencyTypes.TokenMap = { '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83': { name: 'USDC token on xDai', symbol: 'USDC', diff --git a/packages/currency/src/erc20/index.ts b/packages/currency/src/erc20/index.ts index b0f4f6b316..76a14c92b2 100644 --- a/packages/currency/src/erc20/index.ts +++ b/packages/currency/src/erc20/index.ts @@ -1,4 +1,3 @@ -import { ERC20Currency, TokenMap } from '../types'; import { supportedNetworks } from './chains'; import { CurrencyTypes } from '@requestnetwork/types'; @@ -7,20 +6,19 @@ import { CurrencyTypes } from '@requestnetwork/types'; * * @returns List of supported ERC20 tokens */ -export function getSupportedERC20Tokens(): ERC20Currency[] { - return (Object.entries(supportedNetworks) as [CurrencyTypes.EvmChainName, TokenMap][]).reduce( - (acc: ERC20Currency[], [networkName, supportedCurrencies]) => { - return [ - ...acc, - ...Object.entries(supportedCurrencies).map(([address, token]) => ({ - address, - network: networkName, - decimals: token.decimals, - symbol: token.symbol, - id: token.id, - })), - ]; - }, - [], - ); +export function getSupportedERC20Tokens(): CurrencyTypes.ERC20Currency[] { + return ( + Object.entries(supportedNetworks) as [CurrencyTypes.EvmChainName, CurrencyTypes.TokenMap][] + ).reduce((acc: CurrencyTypes.ERC20Currency[], [networkName, supportedCurrencies]) => { + return [ + ...acc, + ...Object.entries(supportedCurrencies).map(([address, token]) => ({ + address, + network: networkName, + decimals: token.decimals, + symbol: token.symbol, + id: token.id, + })), + ]; + }, []); } diff --git a/packages/currency/src/erc777/chains/index.ts b/packages/currency/src/erc777/chains/index.ts index 05d09408bb..88e78b2a78 100644 --- a/packages/currency/src/erc777/chains/index.ts +++ b/packages/currency/src/erc777/chains/index.ts @@ -1,7 +1,8 @@ import { supportedRinkebyERC777 } from './rinkeby'; -import { TokenMap } from '../../types'; import { CurrencyTypes } from '@requestnetwork/types'; -export const supportedNetworks: Partial> = { +export const supportedNetworks: Partial< + Record +> = { rinkeby: supportedRinkebyERC777, }; diff --git a/packages/currency/src/erc777/chains/rinkeby.ts b/packages/currency/src/erc777/chains/rinkeby.ts index 407297a0ea..6b3b2e9df7 100644 --- a/packages/currency/src/erc777/chains/rinkeby.ts +++ b/packages/currency/src/erc777/chains/rinkeby.ts @@ -1,7 +1,7 @@ -import { TokenMap } from '../../types'; +import { CurrencyTypes } from '@requestnetwork/types'; // List of the supported rinkeby ERC777 tokens -export const supportedRinkebyERC777: TokenMap = { +export const supportedRinkebyERC777: CurrencyTypes.TokenMap = { // Faucet Token on rinkeby network. Easy to use on tests. '0x745861AeD1EEe363b4AaA5F1994Be40b1e05Ff90': { decimals: 18, diff --git a/packages/currency/src/erc777/index.ts b/packages/currency/src/erc777/index.ts index 36e2f5f53a..f3dde1a83b 100644 --- a/packages/currency/src/erc777/index.ts +++ b/packages/currency/src/erc777/index.ts @@ -1,4 +1,3 @@ -import { ERC777Currency, TokenMap } from '../types'; import { supportedNetworks } from './chains'; import { CurrencyTypes } from '@requestnetwork/types'; @@ -7,19 +6,18 @@ import { CurrencyTypes } from '@requestnetwork/types'; * * @returns List of supported ERC777 tokens */ -export function getSupportedERC777Tokens(): ERC777Currency[] { - return (Object.entries(supportedNetworks) as [CurrencyTypes.EvmChainName, TokenMap][]).reduce( - (acc: ERC777Currency[], [networkName, supportedCurrencies]) => { - return [ - ...acc, - ...Object.entries(supportedCurrencies).map(([address, token]) => ({ - address, - network: networkName, - decimals: token.decimals, - symbol: token.symbol, - })), - ]; - }, - [], - ); +export function getSupportedERC777Tokens(): CurrencyTypes.ERC777Currency[] { + return ( + Object.entries(supportedNetworks) as [CurrencyTypes.EvmChainName, CurrencyTypes.TokenMap][] + ).reduce((acc: CurrencyTypes.ERC777Currency[], [networkName, supportedCurrencies]) => { + return [ + ...acc, + ...Object.entries(supportedCurrencies).map(([address, token]) => ({ + address, + network: networkName, + decimals: token.decimals, + symbol: token.symbol, + })), + ]; + }, []); } diff --git a/packages/currency/src/index.ts b/packages/currency/src/index.ts index e3f77834d2..986d1daac4 100644 --- a/packages/currency/src/index.ts +++ b/packages/currency/src/index.ts @@ -1,13 +1,8 @@ export * from './chains'; export { getSupportedERC20Tokens } from './erc20'; export { getSupportedERC777Tokens } from './erc777'; -export { - conversionSupportedNetworks, - CurrencyPairs, - AggregatorsMap, -} from './conversion-aggregators'; +export { conversionSupportedNetworks } from './conversion-aggregators'; export { getHash as getCurrencyHash } from './getHash'; export { CurrencyManager } from './currencyManager'; -export * from './types'; export * from './errors'; export * from './currency-utils'; diff --git a/packages/currency/src/native.ts b/packages/currency/src/native.ts index 356df2776f..ac7aae6dc7 100644 --- a/packages/currency/src/native.ts +++ b/packages/currency/src/native.ts @@ -1,10 +1,11 @@ import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; -import { NamedNativeCurrency } from './types'; -type NativeEthCurrency = NamedNativeCurrency & { +type NativeEthCurrency = CurrencyTypes.NamedNativeCurrency & { network: CurrencyTypes.EvmChainName | CurrencyTypes.NearChainName; }; -type NativeBtcCurrency = NamedNativeCurrency & { network: CurrencyTypes.BtcChainName }; +type NativeBtcCurrency = CurrencyTypes.NamedNativeCurrency & { + network: CurrencyTypes.BtcChainName; +}; export const nativeCurrencies: Record & Record = { diff --git a/packages/currency/src/types.ts b/packages/currency/src/types.ts deleted file mode 100644 index c976b3871b..0000000000 --- a/packages/currency/src/types.ts +++ /dev/null @@ -1,144 +0,0 @@ -import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; - -/** - * Common types used in token configuration files - */ -type TokenAddress = string; -type TokenDefinition = { name: string; symbol: string; decimals: number; id?: string }; -export type TokenMap = Record; - -/** - * Common types used in chain configuration files - */ -export type Chain = { - chainId: number | string; - testnet?: boolean; - currencies?: TokenMap; -}; - -/** - * A native blockchain token (ETH, MATIC, ETH-rinkeby...) - */ -export type NativeCurrency = { - symbol: string; - decimals: number; - network: CurrencyTypes.ChainName; -}; -type NamedCurrency = { name: string }; -export type NamedNativeCurrency = NativeCurrency & NamedCurrency; - -/** Native Currency types */ -export type NativeCurrencyType = RequestLogicTypes.CURRENCY.BTC | RequestLogicTypes.CURRENCY.ETH; - -/** - * A Fiat currency (EUR, USD...) - */ -export type ISO4217Currency = { - symbol: string; - decimals: number; -}; - -/** - * An ERC20 token (DAI, USDT...) - */ -export type ERC20Currency = { - symbol: string; - decimals: number; - network: - | CurrencyTypes.EvmChainName - | CurrencyTypes.NearChainName - | CurrencyTypes.DeclarativeChainName; - address: string; -}; - -/** - * An ERC777 SuperToken (DAIx, USDCx...) - */ -export type ERC777Currency = { - symbol: string; - decimals: number; - network: CurrencyTypes.EvmChainName; - address: string; -}; - -/** - * The minimum properties of a native Currency - */ -export type NativeCurrencyInput = { - type: RequestLogicTypes.CURRENCY.ETH | RequestLogicTypes.CURRENCY.BTC; -} & NativeCurrency; - -/** - * The minimum properties of an ISO4217 Currency - */ -export type ISO4217CurrencyInput = { - type: RequestLogicTypes.CURRENCY.ISO4217; -} & ISO4217Currency; - -/** - * The minimum properties of an ERC20 Currency - */ -export type ERC20CurrencyInput = { - type: RequestLogicTypes.CURRENCY.ERC20; -} & ERC20Currency; - -/** - * The minimum properties of an ERC777 Currency - */ -export type ERC777CurrencyInput = { - type: RequestLogicTypes.CURRENCY.ERC777; -} & ERC777Currency; - -/** - * The minimum properties of a Currency - */ -export type CurrencyInput = - | NativeCurrencyInput - | ISO4217CurrencyInput - | ERC20CurrencyInput - | ERC777CurrencyInput; - -/** - * The description of Currency, its core properties and some computed properties. - * `meta` enables applications to add any metadata they need to a Currency - */ -export type CurrencyDefinition = CurrencyInput & { - id: string; - hash: string; - meta: TMeta; -}; - -/** - * Alias for ICurrency for clarity in the context - */ -export type StorageCurrency = RequestLogicTypes.ICurrency; - -/** - * A Currency manager handles a list of currencies and provides utility to retrieve and change format - */ -export interface ICurrencyManager { - from(symbolOrAddress: string, network?: string): CurrencyDefinition | undefined; - fromAddress(address: string, network?: string): CurrencyDefinition | undefined; - fromSymbol(symbol: string, network?: string): CurrencyDefinition | undefined; - fromHash(hash: string, network?: string): CurrencyDefinition | undefined; - fromStorageCurrency(currency: StorageCurrency): CurrencyDefinition | undefined; - getNativeCurrency( - type: NativeCurrencyType, - network: string, - ): CurrencyDefinition | undefined; - getConversionPath( - from: Pick, - to: Pick, - network: string, - ): string[] | null; - supportsConversion(currency: Pick, network: string): boolean; - validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean; - validateCurrency(currency: StorageCurrency): boolean; -} - -/** - * A mapping from old to new name for a given currency. - * - * Format { "chainName": {"TOKEN": ["NEW_TOKEN","NEW_CHAIN"]}} - */ -export type LegacyTokenMap = Record>; diff --git a/packages/currency/test/chainlink-path-aggregators.test.ts b/packages/currency/test/chainlink-path-aggregators.test.ts index ad91d2f1db..9ea1198d9e 100644 --- a/packages/currency/test/chainlink-path-aggregators.test.ts +++ b/packages/currency/test/chainlink-path-aggregators.test.ts @@ -1,5 +1,6 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ -import { AggregatorsMap, getPath } from '../src/conversion-aggregators'; +import { CurrencyTypes } from '@requestnetwork/types'; + +import { getPath } from '../src/conversion-aggregators'; import { CurrencyManager } from '../src'; const currencyManager = CurrencyManager.getDefault(); const USD = currencyManager.from('USD')!; @@ -8,7 +9,7 @@ const EUR = currencyManager.from('EUR')!; const fakeDAI = { hash: '0x38cf23c52bb4b13f051aec09580a2de845a7fa35' }; describe('getPath', () => { - const mockAggregatorPaths: AggregatorsMap = { + const mockAggregatorPaths: CurrencyTypes.AggregatorsMap = { private: { [fakeDAI.hash]: { [USD.hash]: 1, diff --git a/packages/currency/test/currencyManager.test.ts b/packages/currency/test/currencyManager.test.ts index 9a20b14103..7f2f02177f 100644 --- a/packages/currency/test/currencyManager.test.ts +++ b/packages/currency/test/currencyManager.test.ts @@ -1,13 +1,10 @@ -import { RequestLogicTypes } from '@requestnetwork/types'; -import { - CurrencyInput, - CurrencyDefinition, - CurrencyManager, - ERC20Currency, - StorageCurrency, -} from '../src'; - -const testCasesPerNetwork: Record>> = { +import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyManager } from '../src'; + +const testCasesPerNetwork: Record< + string, + Record> +> = { mainnet: { ETH: { symbol: 'ETH', network: 'mainnet' }, SAI: { @@ -116,7 +113,7 @@ describe('CurrencyManager', () => { }); it('can instantiate a currency manager based on a currency list', () => { - const list: CurrencyInput[] = [ + const list: CurrencyTypes.CurrencyInput[] = [ { type: RequestLogicTypes.CURRENCY.ETH, decimals: 18, network: 'mainnet', symbol: 'ANY' }, ]; currencyManager = new CurrencyManager(list); @@ -126,7 +123,7 @@ describe('CurrencyManager', () => { it('fails if there is a duplicate token in the list', () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const dai = CurrencyManager.getDefaultList().find((x) => x.id === 'DAI-mainnet')!; - const list: CurrencyInput[] = [dai, dai, dai, dai]; + const list: CurrencyTypes.CurrencyInput[] = [dai, dai, dai, dai]; expect(() => new CurrencyManager(list)).toThrowError('Duplicate found: DAI-mainnet'); }); @@ -140,7 +137,7 @@ describe('CurrencyManager', () => { network: 'private', }, ]); - const fake = currencyManager.from('FAKE') as ERC20Currency; + const fake = currencyManager.from('FAKE') as CurrencyTypes.ERC20Currency; // right case expect(fake.address).toBe('0x38cF23C52Bb4B13F051Aec09580a2dE845a7FA35'); @@ -495,7 +492,7 @@ describe('CurrencyManager', () => { const extendedTestCasesPerNetwork: Record< string, - Record> + Record> > = { ...testCasesPerNetwork, aurora: { @@ -521,7 +518,7 @@ describe('CurrencyManager', () => { const testValidateAddressForCurrency = ( address: string, - currency: CurrencyDefinition | undefined, + currency: CurrencyTypes.CurrencyDefinition | undefined, expectedResult = true, ) => { if (!currency) { @@ -599,7 +596,7 @@ describe('CurrencyManager', () => { describe('Validate currencies', () => { describe('Valid cases', () => { - const currencies: { currency: StorageCurrency; label: string }[] = [ + const currencies: { currency: CurrencyTypes.StorageCurrency; label: string }[] = [ { currency: { type: RequestLogicTypes.CURRENCY.ISO4217, @@ -655,7 +652,7 @@ describe('CurrencyManager', () => { }); describe('Invalid cases', () => { - const currencies: { currency: StorageCurrency; label: string }[] = [ + const currencies: { currency: CurrencyTypes.StorageCurrency; label: string }[] = [ { currency: { type: RequestLogicTypes.CURRENCY.ERC20, @@ -689,7 +686,9 @@ describe('CurrencyManager', () => { }); describe('Conversion paths', () => { - let eur: CurrencyDefinition, usd: CurrencyDefinition, dai: CurrencyDefinition; + let eur: CurrencyTypes.CurrencyDefinition, + usd: CurrencyTypes.CurrencyDefinition, + dai: CurrencyTypes.CurrencyDefinition; beforeEach(() => { eur = currencyManager.from('EUR')!; usd = currencyManager.from('USD')!; @@ -728,7 +727,7 @@ describe('CurrencyManager', () => { id: 'USDC-matic', decimals: 6, type: RequestLogicTypes.CURRENCY.ERC20, - } as CurrencyInput, + } as CurrencyTypes.CurrencyInput, { address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', name: 'USD Coin', @@ -737,7 +736,7 @@ describe('CurrencyManager', () => { id: 'USDCn-matic', decimals: 6, type: RequestLogicTypes.CURRENCY.ERC20, - } as CurrencyInput, + } as CurrencyTypes.CurrencyInput, ]; const currencyManager = new CurrencyManager(USDC_LIST); it('Detects USDCe matic by USDC-matic id', () => { diff --git a/packages/integration-test/test/layers.test.ts b/packages/integration-test/test/layers.test.ts index 1f2e6f64f6..993d519ded 100644 --- a/packages/integration-test/test/layers.test.ts +++ b/packages/integration-test/test/layers.test.ts @@ -1,5 +1,4 @@ import { getCurrentTimestampInSecond } from '@requestnetwork/utils'; - import { CurrencyManager } from '@requestnetwork/currency'; import { AdvancedLogic } from '@requestnetwork/advanced-logic'; import { EthereumPrivateKeyDecryptionProvider } from '@requestnetwork/epk-decryption'; @@ -130,7 +129,7 @@ describe('Request system', () => { const transactionManager = new TransactionManager(dataAccess, decryptionProvider); // Advanced Logic setup - advancedLogic = new AdvancedLogic(new CurrencyManager(CurrencyManager.getDefaultList())); + advancedLogic = new AdvancedLogic(CurrencyManager.getDefault()); // Logic setup requestLogic = new RequestLogic(transactionManager, signatureProvider, advancedLogic); diff --git a/packages/integration-test/test/node-client.test.ts b/packages/integration-test/test/node-client.test.ts index 03f41e1fbf..be84ca486e 100644 --- a/packages/integration-test/test/node-client.test.ts +++ b/packages/integration-test/test/node-client.test.ts @@ -7,12 +7,13 @@ import { PaymentTypes, RequestLogicTypes, ExtensionTypes, + CurrencyTypes, } from '@requestnetwork/types'; import { payRequest, approveErc20ForProxyConversionIfNeeded, } from '@requestnetwork/payment-processor'; -import { CurrencyInput, CurrencyManager } from '@requestnetwork/currency'; +import { CurrencyManager } from '@requestnetwork/currency'; import { Wallet, providers, BigNumber } from 'ethers'; import { @@ -561,7 +562,7 @@ describe('ERC20 localhost request creation and detection test', () => { it('can create ERC20 requests with any to erc20 proxy', async () => { const tokenContractAddress = '0x38cF23C52Bb4B13F051Aec09580a2dE845a7FA35'; - const currencies: CurrencyInput[] = [ + const currencies: CurrencyTypes.CurrencyInput[] = [ ...CurrencyManager.getDefaultList(), { address: tokenContractAddress, @@ -574,7 +575,7 @@ describe('ERC20 localhost request creation and detection test', () => { const requestNetwork = new RequestNetwork({ signatureProvider, useMockStorage: true, - currencies, + currencyManager: new CurrencyManager(currencies), }); const paymentNetworkAnyToERC20: PaymentTypes.PaymentNetworkCreateParameters = { @@ -658,7 +659,7 @@ describe('ETH localhost request creation and detection test', () => { const requestNetwork = new RequestNetwork({ signatureProvider, useMockStorage: true, - currencies, + currencyManager: new CurrencyManager(currencies), }); const paymentNetworkETHFeeProxy: PaymentTypes.PaymentNetworkCreateParameters = { @@ -702,7 +703,7 @@ describe('ETH localhost request creation and detection test', () => { }); it('can create & pay a request with any to eth proxy', async () => { - const currencies: CurrencyInput[] = [ + const currencies: CurrencyTypes.CurrencyInput[] = [ ...CurrencyManager.getDefaultList(), { network: 'private', @@ -715,7 +716,7 @@ describe('ETH localhost request creation and detection test', () => { const requestNetwork = new RequestNetwork({ signatureProvider, useMockStorage: true, - currencies, + currencyManager: new CurrencyManager(currencies), }); const paymentNetworkAnyToETH: PaymentTypes.PaymentNetworkCreateParameters = { diff --git a/packages/integration-test/test/scheduled/native-token.test.ts b/packages/integration-test/test/scheduled/native-token.test.ts index 9d0b983dc0..7b413889c0 100644 --- a/packages/integration-test/test/scheduled/native-token.test.ts +++ b/packages/integration-test/test/scheduled/native-token.test.ts @@ -3,7 +3,7 @@ import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; import { AdvancedLogic } from '@requestnetwork/advanced-logic'; import { CurrencyManager } from '@requestnetwork/currency'; -const advancedLogic = new AdvancedLogic(new CurrencyManager(CurrencyManager.getDefaultList())); +const advancedLogic = new AdvancedLogic(CurrencyManager.getDefault()); const createCreationActionParams: ExtensionTypes.PnReferenceBased.ICreationParameters = { paymentAddress: 'payment.testnet', diff --git a/packages/payment-detection/src/any-to-any-detector.ts b/packages/payment-detection/src/any-to-any-detector.ts index 14930f68bf..eb8d3e12b9 100644 --- a/packages/payment-detection/src/any-to-any-detector.ts +++ b/packages/payment-detection/src/any-to-any-detector.ts @@ -1,6 +1,5 @@ -import { ExtensionTypes } from '@requestnetwork/types'; +import { CurrencyTypes, ExtensionTypes } from '@requestnetwork/types'; import { FeeReferenceBasedDetector } from './fee-reference-based-detector'; -import { ICurrencyManager } from '@requestnetwork/currency'; import { generate8randomBytes } from '@requestnetwork/utils'; /** @@ -16,7 +15,7 @@ export abstract class AnyToAnyDetector< protected constructor( paymentNetworkId: ExtensionTypes.PAYMENT_NETWORK_ID, extension: TExtension, - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, ) { super(paymentNetworkId, extension, currencyManager); } diff --git a/packages/payment-detection/src/any/retrievers/any-to-any-proxy.ts b/packages/payment-detection/src/any/retrievers/any-to-any-proxy.ts index 3963d2949a..6b2ac4d3f1 100644 --- a/packages/payment-detection/src/any/retrievers/any-to-any-proxy.ts +++ b/packages/payment-detection/src/any/retrievers/any-to-any-proxy.ts @@ -1,5 +1,4 @@ -import { CurrencyDefinition } from '@requestnetwork/currency'; -import { PaymentTypes } from '@requestnetwork/types'; +import { CurrencyTypes, PaymentTypes } from '@requestnetwork/types'; import { BigNumber, ethers } from 'ethers'; import { parseLogArgs, unpadAmountFromChainlink } from '../../utils'; import type { JsonFragment } from '@ethersproject/abi'; @@ -41,7 +40,7 @@ export abstract class ConversionInfoRetriever { * @param network The Ethereum network to use */ constructor( - protected requestCurrency: CurrencyDefinition, + protected requestCurrency: CurrencyTypes.CurrencyDefinition, protected paymentReference: string, protected conversionProxyContractAddress: string, protected conversionProxyCreationBlockNumber: number, diff --git a/packages/payment-detection/src/erc20/currency.ts b/packages/payment-detection/src/erc20/currency.ts index a8d938a673..766661a187 100644 --- a/packages/payment-detection/src/erc20/currency.ts +++ b/packages/payment-detection/src/erc20/currency.ts @@ -1,19 +1,12 @@ -import { - CurrencyDefinition, - CurrencyManager, - EvmChains, - getCurrencyHash, - StorageCurrency, -} from '@requestnetwork/currency'; -import { RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyManager, EvmChains, getCurrencyHash } from '@requestnetwork/currency'; +import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; import { ERC20__factory } from '@requestnetwork/smart-contracts/types'; import { isAddress } from 'ethers/lib/utils'; import { getDefaultProvider } from '@requestnetwork/utils'; -import { ERC20CurrencyInput } from '@requestnetwork/currency/src'; export const loadCurrencyFromContract = async ( - currency: StorageCurrency, -): Promise => { + currency: CurrencyTypes.StorageCurrency, +): Promise => { try { const { network, value } = currency; @@ -34,7 +27,7 @@ export const loadCurrencyFromContract = async ( return null; } - const definition: ERC20CurrencyInput = { + const definition: CurrencyTypes.ERC20CurrencyInput = { address: value, decimals, symbol, diff --git a/packages/payment-detection/src/erc20/fee-proxy-contract.ts b/packages/payment-detection/src/erc20/fee-proxy-contract.ts index e562ff76a8..80b694c72e 100644 --- a/packages/payment-detection/src/erc20/fee-proxy-contract.ts +++ b/packages/payment-detection/src/erc20/fee-proxy-contract.ts @@ -5,13 +5,7 @@ import { PaymentTypes, RequestLogicTypes, } from '@requestnetwork/types'; -import { - CurrencyDefinition, - EvmChains, - ICurrencyManager, - NearChains, - isSameChain, -} from '@requestnetwork/currency'; +import { EvmChains, NearChains, isSameChain } from '@requestnetwork/currency'; import ProxyInfoRetriever from './proxy-info-retriever'; import { loadCurrencyFromContract } from './currency'; @@ -42,14 +36,14 @@ export abstract class ERC20FeeProxyPaymentDetectorBase< protected constructor( paymentNetworkId: ExtensionTypes.PAYMENT_NETWORK_ID, extension: TExtension, - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, ) { super(paymentNetworkId, extension, currencyManager); } protected async getCurrency( storageCurrency: RequestLogicTypes.ICurrency, - ): Promise { + ): Promise { const currency = this.currencyManager.fromStorageCurrency(storageCurrency); if (currency) { return currency; diff --git a/packages/payment-detection/src/fee-reference-based-detector.ts b/packages/payment-detection/src/fee-reference-based-detector.ts index 9ba9342ee0..6761be6c90 100644 --- a/packages/payment-detection/src/fee-reference-based-detector.ts +++ b/packages/payment-detection/src/fee-reference-based-detector.ts @@ -1,6 +1,10 @@ import { BigNumber } from 'ethers'; -import { ExtensionTypes, PaymentTypes, RequestLogicTypes } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; +import { + CurrencyTypes, + ExtensionTypes, + PaymentTypes, + RequestLogicTypes, +} from '@requestnetwork/types'; import { ReferenceBasedDetector } from './reference-based-detector'; import { generate8randomBytes } from '@requestnetwork/utils'; @@ -21,7 +25,7 @@ export abstract class FeeReferenceBasedDetector< protected constructor( paymentNetworkId: ExtensionTypes.PAYMENT_NETWORK_ID, extension: TExtension, - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, ) { super(paymentNetworkId, extension, currencyManager); } diff --git a/packages/payment-detection/src/near/retrievers/near-conversion-info-retriever.ts b/packages/payment-detection/src/near/retrievers/near-conversion-info-retriever.ts index 3e4280bf0c..081d4f1e96 100644 --- a/packages/payment-detection/src/near/retrievers/near-conversion-info-retriever.ts +++ b/packages/payment-detection/src/near/retrievers/near-conversion-info-retriever.ts @@ -1,5 +1,4 @@ import { CurrencyTypes, PaymentTypes } from '@requestnetwork/types'; -import { CurrencyDefinition } from '@requestnetwork/currency'; import { NearInfoRetriever, NearPaymentEvent } from './near-info-retriever'; import { TheGraphClient } from '../../thegraph'; @@ -7,7 +6,7 @@ export type TransferEventsParams = { /** The reference to identify the payment*/ paymentReference: string; /** Request denomination (usually fiat) */ - requestCurrency: CurrencyDefinition; + requestCurrency: CurrencyTypes.CurrencyDefinition; /** The recipient of the transfer */ toAddress: string; /** The address of the payment proxy */ diff --git a/packages/payment-detection/src/payment-network-factory.ts b/packages/payment-detection/src/payment-network-factory.ts index 9dc2a66a02..cb85d23a69 100644 --- a/packages/payment-detection/src/payment-network-factory.ts +++ b/packages/payment-detection/src/payment-network-factory.ts @@ -5,7 +5,6 @@ import { PaymentTypes, RequestLogicTypes, } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; import { ContractBasedDetector, IPaymentNetworkModuleByType, @@ -96,7 +95,7 @@ export class PaymentNetworkFactory { */ constructor( private readonly advancedLogic: AdvancedLogicTypes.IAdvancedLogic, - private readonly currencyManager: ICurrencyManager, + private readonly currencyManager: CurrencyTypes.ICurrencyManager, options?: Partial, ) { this.options = this.buildOptions(options || {}); diff --git a/packages/payment-detection/src/reference-based-detector.ts b/packages/payment-detection/src/reference-based-detector.ts index 433fd52700..894c91c6b7 100644 --- a/packages/payment-detection/src/reference-based-detector.ts +++ b/packages/payment-detection/src/reference-based-detector.ts @@ -5,7 +5,6 @@ import { RequestLogicTypes, TypesUtils, } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; import * as PaymentReferenceCalculator from './payment-reference-calculator'; import { DeclarativePaymentDetectorBase } from './declarative'; @@ -29,7 +28,7 @@ export abstract class ReferenceBasedDetector< protected constructor( paymentNetworkId: ExtensionTypes.PAYMENT_NETWORK_ID, extension: TExtension, - protected readonly currencyManager: ICurrencyManager, + protected readonly currencyManager: CurrencyTypes.ICurrencyManager, ) { super(paymentNetworkId, extension); if (!TypesUtils.isPaymentNetworkId(paymentNetworkId)) { diff --git a/packages/payment-detection/src/thegraph/conversion-info-retriever.ts b/packages/payment-detection/src/thegraph/conversion-info-retriever.ts index ab3160a703..3c5846c43d 100644 --- a/packages/payment-detection/src/thegraph/conversion-info-retriever.ts +++ b/packages/payment-detection/src/thegraph/conversion-info-retriever.ts @@ -1,5 +1,4 @@ -import { PaymentTypes } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes, PaymentTypes } from '@requestnetwork/types'; import { utils } from 'ethers'; import { TheGraphClient } from './client'; import { TheGraphInfoRetriever } from './info-retriever'; @@ -12,7 +11,7 @@ import { ConversionTransferEventsParams } from '../types'; export class TheGraphConversionInfoRetriever extends TheGraphInfoRetriever { constructor( protected readonly client: TheGraphClient, - protected readonly currencyManager: ICurrencyManager, + protected readonly currencyManager: CurrencyTypes.ICurrencyManager, ) { super(client, currencyManager); } diff --git a/packages/payment-detection/src/thegraph/info-retriever.ts b/packages/payment-detection/src/thegraph/info-retriever.ts index 2e3d756c91..ea9efbfd1a 100644 --- a/packages/payment-detection/src/thegraph/info-retriever.ts +++ b/packages/payment-detection/src/thegraph/info-retriever.ts @@ -1,5 +1,4 @@ -import { PaymentTypes } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes, PaymentTypes } from '@requestnetwork/types'; import { utils } from 'ethers'; import type { TheGraphClient } from './client'; import type { EscrowEventResultFragment, PaymentEventResultFragment } from './generated/graphql'; @@ -14,7 +13,7 @@ export class TheGraphInfoRetriever({ args, eventFragment }: LogDescription): T => { */ export const padAmountForChainlink = ( amount: BigNumberish, - currency: Pick, + currency: Pick, ): BigNumber => { // eslint-disable-next-line no-magic-numbers return BigNumber.from(amount).mul(10 ** getChainlinkPaddingSize(currency)); @@ -34,7 +34,7 @@ export const padAmountForChainlink = ( export const unpadAmountFromChainlink = ( amount: BigNumberish, - currency: Pick, + currency: Pick, ): BigNumber => { // eslint-disable-next-line no-magic-numbers return BigNumber.from(amount).div(10 ** getChainlinkPaddingSize(currency)); @@ -43,7 +43,7 @@ export const unpadAmountFromChainlink = ( const getChainlinkPaddingSize = ({ type, decimals, -}: Pick): number => { +}: Pick): number => { switch (type) { case RequestLogicTypes.CURRENCY.ISO4217: { const chainlinkFiatDecimal = 8; diff --git a/packages/payment-detection/test/near/near-native-conversion.test.ts b/packages/payment-detection/test/near/near-native-conversion.test.ts index 5f4fcb54e1..119db7c56d 100644 --- a/packages/payment-detection/test/near/near-native-conversion.test.ts +++ b/packages/payment-detection/test/near/near-native-conversion.test.ts @@ -4,7 +4,7 @@ import { PaymentTypes, RequestLogicTypes, } from '@requestnetwork/types'; -import { CurrencyDefinition, CurrencyManager } from '@requestnetwork/currency'; +import { CurrencyManager } from '@requestnetwork/currency'; import { PaymentNetworkFactory } from '../../src/payment-network-factory'; import * as PaymentReferenceCalculator from '../../src/payment-reference-calculator'; import { @@ -24,7 +24,7 @@ const feeAddress = 'fee.near'; const network = 'aurora'; const feeAmount = '5'; const receiptId = 'FYVnCvJFoNtK7LE2uAdTFfReFMGiCUHMczLsvEni1Cpf'; -const requestCurrency = currencyManager.from('USD') as CurrencyDefinition; +const requestCurrency = currencyManager.from('USD') as CurrencyTypes.CurrencyDefinition; const request: any = { requestId: '01c9190b6d015b3a0b2bbd0e492b9474b0734ca19a16f2fda8f7adec10d0fa3e7a', currency: { diff --git a/packages/payment-processor/src/payment/any-to-erc20-proxy.ts b/packages/payment-processor/src/payment/any-to-erc20-proxy.ts index 224ae89192..8f49533a59 100644 --- a/packages/payment-processor/src/payment/any-to-erc20-proxy.ts +++ b/packages/payment-processor/src/payment/any-to-erc20-proxy.ts @@ -1,13 +1,9 @@ import { constants, ContractTransaction, Signer, providers, BigNumberish, BigNumber } from 'ethers'; -import { - CurrencyDefinition, - CurrencyManager, - UnsupportedCurrencyError, -} from '@requestnetwork/currency'; +import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; import { AnyToERC20PaymentDetector } from '@requestnetwork/payment-detection'; import { Erc20ConversionProxy__factory } from '@requestnetwork/smart-contracts/types'; -import { ClientTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { ClientTypes, CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; import { ITransactionOverrides } from './transaction-overrides'; import { @@ -96,7 +92,7 @@ export function encodePayAnyToErc20ProxyRequest( export function getConversionPathForErc20Request( request: ClientTypes.IRequestData, paymentSettings: IConversionPaymentSettings, -): { path: string[]; requestCurrency: CurrencyDefinition } { +): { path: string[]; requestCurrency: CurrencyTypes.CurrencyDefinition } { if (!paymentSettings.currency) { throw new Error('currency must be provided in the paymentSettings'); } diff --git a/packages/payment-processor/src/payment/any-to-eth-proxy.ts b/packages/payment-processor/src/payment/any-to-eth-proxy.ts index 6c311160d6..d638a3452a 100644 --- a/packages/payment-processor/src/payment/any-to-eth-proxy.ts +++ b/packages/payment-processor/src/payment/any-to-eth-proxy.ts @@ -1,13 +1,9 @@ import { constants, ContractTransaction, Signer, providers, BigNumberish, BigNumber } from 'ethers'; -import { - CurrencyDefinition, - CurrencyManager, - UnsupportedCurrencyError, -} from '@requestnetwork/currency'; +import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; import { AnyToEthFeeProxyPaymentDetector } from '@requestnetwork/payment-detection'; import { EthConversionProxy__factory } from '@requestnetwork/smart-contracts/types'; -import { ClientTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { ClientTypes, CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; import { ITransactionOverrides } from './transaction-overrides'; import { getAmountToPay, getProvider, getRequestPaymentValues, getSigner } from './utils'; @@ -104,7 +100,7 @@ export function prepareAnyToEthProxyPaymentTransaction( export function getConversionPathForEthRequest( request: ClientTypes.IRequestData, paymentSettings: IConversionPaymentSettings, -): { path: string[]; requestCurrency: CurrencyDefinition } { +): { path: string[]; requestCurrency: CurrencyTypes.CurrencyDefinition } { const currencyManager = paymentSettings.currencyManager || CurrencyManager.getDefault(); if (!request.currencyInfo) { diff --git a/packages/payment-processor/src/payment/batch-conversion-proxy.ts b/packages/payment-processor/src/payment/batch-conversion-proxy.ts index ea77ce0d6d..1469c9b747 100644 --- a/packages/payment-processor/src/payment/batch-conversion-proxy.ts +++ b/packages/payment-processor/src/payment/batch-conversion-proxy.ts @@ -29,7 +29,7 @@ import { IPreparedTransaction } from './prepared-transaction'; import { IConversionPaymentSettings } from './index'; import { getConversionPathForErc20Request } from './any-to-erc20-proxy'; import { checkErc20Allowance, encodeApproveAnyErc20 } from './erc20'; -import { CurrencyDefinition, CurrencyManager, ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyManager } from '@requestnetwork/currency'; import { BatchPaymentNetworks, EnrichedRequest, @@ -330,7 +330,7 @@ function getUSDPathsForFeeLimit( requestDetails: PaymentTypes.RequestDetail[], network: string, skipFeeUSDLimit: boolean, - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, hasNativePayment: boolean, ): string[][] { if (skipFeeUSDLimit) return []; @@ -356,9 +356,9 @@ function getUSDPathsForFeeLimit( .filter((value, index, self) => self.indexOf(value) === index); // get the token currencies and keep the one that are defined - const tokenCurrencies: Array> = tokenAddresses + const tokenCurrencies: Array> = tokenAddresses .map((token) => currencyManager.fromAddress(token, network)) - .filter((value): value is CurrencyDefinition => !!value); + .filter((value): value is CurrencyTypes.CurrencyDefinition => !!value); // get all the conversion paths to USD when it exists and return it const path = tokenCurrencies diff --git a/packages/payment-processor/src/payment/index.ts b/packages/payment-processor/src/payment/index.ts index 342e2213de..4bd6b57e2a 100644 --- a/packages/payment-processor/src/payment/index.ts +++ b/packages/payment-processor/src/payment/index.ts @@ -1,6 +1,6 @@ import { ContractTransaction, Signer, BigNumber, BigNumberish, providers } from 'ethers'; -import { ClientTypes, ExtensionTypes, TypesUtils } from '@requestnetwork/types'; +import { ClientTypes, CurrencyTypes, ExtensionTypes, TypesUtils } from '@requestnetwork/types'; import { getBtcPaymentUrl } from './btc-address-based'; import { _getErc20PaymentUrl, getAnyErc20Balance } from './erc20'; @@ -16,7 +16,7 @@ import { payAnyToErc20ProxyRequest } from './any-to-erc20-proxy'; import { payAnyToEthProxyRequest } from './any-to-eth-proxy'; import { WalletConnection } from 'near-api-js'; import { isNearAccountSolvent } from './utils-near'; -import { ICurrencyManager, NearChains } from '@requestnetwork/currency'; +import { NearChains } from '@requestnetwork/currency'; import { encodeRequestErc20Approval } from './encoder-approval'; import { encodeRequestPayment } from './encoder-payment'; import { IPreparedTransaction } from './prepared-transaction'; @@ -36,7 +36,7 @@ export const noConversionNetworks = [ export interface IConversionPaymentSettings { currency?: RequestLogicTypes.ICurrency; maxToSpend: BigNumberish; - currencyManager?: ICurrencyManager; + currencyManager?: CurrencyTypes.ICurrencyManager; } const getPaymentNetwork = ( diff --git a/packages/payment-processor/src/types.ts b/packages/payment-processor/src/types.ts index c82e94872a..37947419f8 100644 --- a/packages/payment-processor/src/types.ts +++ b/packages/payment-processor/src/types.ts @@ -1,5 +1,9 @@ -import { ICurrencyManager } from '@requestnetwork/currency'; -import { ClientTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types'; +import { + ClientTypes, + CurrencyTypes, + ExtensionTypes, + RequestLogicTypes, +} from '@requestnetwork/types'; import { BigNumber, BigNumberish } from 'ethers'; import { IConversionPaymentSettings } from './payment'; import { ITransactionOverrides } from './payment/transaction-overrides'; @@ -33,7 +37,7 @@ export interface IConversionSettings { /** maximum number of tokens to be spent when the conversion is made */ maxToSpend?: BigNumberish; /** a currency manager to access currencies property, like decimals */ - currencyManager?: ICurrencyManager; + currencyManager?: CurrencyTypes.ICurrencyManager; /** maximum time in seconds of how old chainlink rate can be used, default is zero for infinitely old */ maxRateAge?: number; } diff --git a/packages/payment-processor/test/payment/shared.ts b/packages/payment-processor/test/payment/shared.ts index c4bcd56a7d..97f170c078 100644 --- a/packages/payment-processor/test/payment/shared.ts +++ b/packages/payment-processor/test/payment/shared.ts @@ -1,5 +1,5 @@ -import { CurrencyManager, CurrencyDefinition } from '@requestnetwork/currency'; -import { RequestLogicTypes } from '@requestnetwork/types'; +import { CurrencyManager } from '@requestnetwork/currency'; +import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; export const currencyManager = new CurrencyManager([ ...CurrencyManager.getDefaultList(), @@ -16,6 +16,6 @@ export const currencyManager = new CurrencyManager([ decimals: 18, symbol: 'ERC20_' + i, type: RequestLogicTypes.CURRENCY.ERC20, - }) as CurrencyDefinition, + }) as CurrencyTypes.CurrencyDefinition, ), ]); diff --git a/packages/request-client.js/src/api/request-network.ts b/packages/request-client.js/src/api/request-network.ts index cf4721fb83..169ec5d5cf 100644 --- a/packages/request-client.js/src/api/request-network.ts +++ b/packages/request-client.js/src/api/request-network.ts @@ -4,6 +4,7 @@ import { RequestLogic } from '@requestnetwork/request-logic'; import { TransactionManager } from '@requestnetwork/transaction-manager'; import { AdvancedLogicTypes, + CurrencyTypes, DataAccessTypes, DecryptionProviderTypes, EncryptionTypes, @@ -14,11 +15,7 @@ import { TransactionTypes, } from '@requestnetwork/types'; import { deepCopy, supportedIdentities } from '@requestnetwork/utils'; -import { - CurrencyManager, - ICurrencyManager, - UnsupportedCurrencyError, -} from '@requestnetwork/currency'; +import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency'; import * as Types from '../types'; import ContentDataExtension from './content-data-extension'; import Request from './request'; @@ -36,7 +33,7 @@ export default class RequestNetwork { private advancedLogic: AdvancedLogicTypes.IAdvancedLogic; private contentData: ContentDataExtension; - private currencyManager: ICurrencyManager; + private currencyManager: CurrencyTypes.ICurrencyManager; /** * @param dataAccess instance of data-access layer @@ -54,7 +51,7 @@ export default class RequestNetwork { dataAccess: DataAccessTypes.IDataAccess; signatureProvider?: SignatureProviderTypes.ISignatureProvider; decryptionProvider?: DecryptionProviderTypes.IDecryptionProvider; - currencyManager?: ICurrencyManager; + currencyManager?: CurrencyTypes.ICurrencyManager; paymentOptions?: Partial; }) { this.currencyManager = currencyManager || CurrencyManager.getDefault(); diff --git a/packages/request-client.js/src/api/request.ts b/packages/request-client.js/src/api/request.ts index c40656814d..2763889bb1 100644 --- a/packages/request-client.js/src/api/request.ts +++ b/packages/request-client.js/src/api/request.ts @@ -10,7 +10,6 @@ import { PaymentTypes, RequestLogicTypes, } from '@requestnetwork/types'; -import { ICurrencyManager } from '@requestnetwork/currency'; import * as Types from '../types'; import ContentDataExtension from './content-data-extension'; import localUtils from './utils'; @@ -77,7 +76,7 @@ export default class Request { /** * A list of known tokens */ - private currencyManager: ICurrencyManager; + private currencyManager: CurrencyTypes.ICurrencyManager; /** * Creates an instance of Request @@ -92,7 +91,7 @@ export default class Request { constructor( requestId: RequestLogicTypes.RequestId, requestLogic: RequestLogicTypes.IRequestLogic, - currencyManager: ICurrencyManager, + currencyManager: CurrencyTypes.ICurrencyManager, options?: { paymentNetwork?: PaymentTypes.IPaymentNetwork | null; contentDataExtension?: ContentDataExtension | null; diff --git a/packages/request-client.js/src/http-request-network.ts b/packages/request-client.js/src/http-request-network.ts index 6762f1343d..bb4ad85fac 100644 --- a/packages/request-client.js/src/http-request-network.ts +++ b/packages/request-client.js/src/http-request-network.ts @@ -1,6 +1,7 @@ -import { CurrencyInput, CurrencyManager, ICurrencyManager } from '@requestnetwork/currency'; +import { CurrencyManager } from '@requestnetwork/currency'; import { ClientTypes, + CurrencyTypes, DataAccessTypes, DecryptionProviderTypes, SignatureProviderTypes, @@ -32,7 +33,6 @@ export default class HttpRequestNetwork extends RequestNetwork { nodeConnectionConfig, signatureProvider, useMockStorage, - currencies, currencyManager, paymentOptions, }: { @@ -41,8 +41,7 @@ export default class HttpRequestNetwork extends RequestNetwork { nodeConnectionConfig?: Partial; signatureProvider?: SignatureProviderTypes.ISignatureProvider; useMockStorage?: boolean; - currencies?: CurrencyInput[]; - currencyManager?: ICurrencyManager; + currencyManager?: CurrencyTypes.ICurrencyManager; paymentOptions?: Partial; } = { httpConfig: {}, @@ -54,7 +53,7 @@ export default class HttpRequestNetwork extends RequestNetwork { : new HttpDataAccess({ httpConfig, nodeConnectionConfig }); if (!currencyManager) { - currencyManager = new CurrencyManager(currencies || CurrencyManager.getDefaultList()); + currencyManager = CurrencyManager.getDefault(); } super({ dataAccess, signatureProvider, decryptionProvider, currencyManager, paymentOptions }); diff --git a/packages/request-client.js/test/declarative-payments.test.ts b/packages/request-client.js/test/declarative-payments.test.ts index b06ac6e33b..ab83249298 100644 --- a/packages/request-client.js/test/declarative-payments.test.ts +++ b/packages/request-client.js/test/declarative-payments.test.ts @@ -338,7 +338,7 @@ describe('request-client.js: declarative payments', () => { const requestNetwork = new RequestNetwork({ signatureProvider: TestData.fakeSignatureProvider, useMockStorage: true, - currencies: [ + currencyManager: new CurrencyManager([ ...CurrencyManager.getDefaultList(), { type: RequestLogicTypes.CURRENCY.ERC20, @@ -347,7 +347,7 @@ describe('request-client.js: declarative payments', () => { network: 'private', // private network forces RPC-based `getLogs` symbol: 'FAKE', }, - ], + ]), }); // provider data is irrelevant in this test diff --git a/packages/request-client.js/test/index.test.ts b/packages/request-client.js/test/index.test.ts index 183ad15a98..ba41b14881 100644 --- a/packages/request-client.js/test/index.test.ts +++ b/packages/request-client.js/test/index.test.ts @@ -2000,7 +2000,7 @@ describe('request-client.js', () => { const requestNetwork = new RequestNetwork({ signatureProvider: TestData.fakeSignatureProvider, useMockStorage: true, - currencies: [ + currencyManager: new CurrencyManager([ { network: 'mainnet', type: RequestLogicTypes.CURRENCY.ETH, @@ -2014,7 +2014,7 @@ describe('request-client.js', () => { decimals: 18, symbol: '_TEST', }, - ], + ]), }); it('allows creating a request by currency properties', async () => { diff --git a/packages/toolbox/src/commands/chainlink/aggregatorsUtils.ts b/packages/toolbox/src/commands/chainlink/aggregatorsUtils.ts index 917b1957d4..4fc4251efb 100644 --- a/packages/toolbox/src/commands/chainlink/aggregatorsUtils.ts +++ b/packages/toolbox/src/commands/chainlink/aggregatorsUtils.ts @@ -1,4 +1,4 @@ -import { AggregatorsMap, CurrencyInput, CurrencyManager } from '@requestnetwork/currency'; +import { CurrencyManager } from '@requestnetwork/currency'; import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types'; type Feed = { @@ -87,10 +87,10 @@ export const getAvailableAggregators = async ( const CURRENCY_API_URL = 'https://api.request.finance/currency'; export const getCurrencyManager = async (list?: string): Promise => { - const aggregators: AggregatorsMap = await fetch(`${CURRENCY_API_URL}/aggregators`).then((r) => - r.json(), - ); - const currencyList: CurrencyInput[] = list + const aggregators: CurrencyTypes.AggregatorsMap = await fetch( + `${CURRENCY_API_URL}/aggregators`, + ).then((r) => r.json()); + const currencyList: CurrencyTypes.CurrencyInput[] = list ? await fetch(`${CURRENCY_API_URL}/list/${list}`).then((r) => r.json()) : CurrencyManager.getDefaultList(); return new CurrencyManager(currencyList, undefined, aggregators); diff --git a/packages/types/src/currency-types.ts b/packages/types/src/currency-types.ts index be9a49238a..0282c3908b 100644 --- a/packages/types/src/currency-types.ts +++ b/packages/types/src/currency-types.ts @@ -1,3 +1,5 @@ +import * as RequestLogicTypes from './request-logic-types'; + /** * List of supported EVM chains */ @@ -53,3 +55,155 @@ export type ChainName = EvmChainName | BtcChainName | NearChainName | Declarativ * Virtual machin chains, where payment proxy contracts can be deployed */ export type VMChainName = EvmChainName | NearChainName; + +/** + * Common types used in token configuration files + */ +type TokenAddress = string; +type TokenDefinition = { name: string; symbol: string; decimals: number; id?: string }; +export type TokenMap = Record; + +/** + * Common types used in chain configuration files + */ +export type Chain = { + chainId: number | string; + testnet?: boolean; + currencies?: TokenMap; +}; + +/** + * A native blockchain token (ETH, MATIC, ETH-rinkeby...) + */ +export type NativeCurrency = { + symbol: string; + decimals: number; + network: ChainName; +}; +type NamedCurrency = { name: string }; +export type NamedNativeCurrency = NativeCurrency & NamedCurrency; + +/** Native Currency types */ +export type NativeCurrencyType = RequestLogicTypes.CURRENCY.BTC | RequestLogicTypes.CURRENCY.ETH; + +/** + * A Fiat currency (EUR, USD...) + */ +export type ISO4217Currency = { + symbol: string; + decimals: number; +}; + +/** + * An ERC20 token (DAI, USDT...) + */ +export type ERC20Currency = { + symbol: string; + decimals: number; + network: EvmChainName | NearChainName | DeclarativeChainName; + address: string; +}; + +/** + * An ERC777 SuperToken (DAIx, USDCx...) + */ +export type ERC777Currency = { + symbol: string; + decimals: number; + network: EvmChainName; + address: string; +}; + +/** + * The minimum properties of a native Currency + */ +export type NativeCurrencyInput = { + type: RequestLogicTypes.CURRENCY.ETH | RequestLogicTypes.CURRENCY.BTC; +} & NativeCurrency; + +/** + * The minimum properties of an ISO4217 Currency + */ +export type ISO4217CurrencyInput = { + type: RequestLogicTypes.CURRENCY.ISO4217; +} & ISO4217Currency; + +/** + * The minimum properties of an ERC20 Currency + */ +export type ERC20CurrencyInput = { + type: RequestLogicTypes.CURRENCY.ERC20; +} & ERC20Currency; + +/** + * The minimum properties of an ERC777 Currency + */ +export type ERC777CurrencyInput = { + type: RequestLogicTypes.CURRENCY.ERC777; +} & ERC777Currency; + +/** + * The minimum properties of a Currency + */ +export type CurrencyInput = + | NativeCurrencyInput + | ISO4217CurrencyInput + | ERC20CurrencyInput + | ERC777CurrencyInput; + +/** + * The description of Currency, its core properties and some computed properties. + * `meta` enables applications to add any metadata they need to a Currency + */ +export type CurrencyDefinition = CurrencyInput & { + id: string; + hash: string; + meta: TMeta; +}; + +/** + * Alias for ICurrency for clarity in the context + */ +export type StorageCurrency = RequestLogicTypes.ICurrency; + +/** + * A Currency manager handles a list of currencies and provides utility to retrieve and change format + */ +export interface ICurrencyManager { + from(symbolOrAddress: string, network?: string): CurrencyDefinition | undefined; + fromAddress(address: string, network?: string): CurrencyDefinition | undefined; + fromSymbol(symbol: string, network?: string): CurrencyDefinition | undefined; + fromHash(hash: string, network?: string): CurrencyDefinition | undefined; + fromStorageCurrency(currency: StorageCurrency): CurrencyDefinition | undefined; + getNativeCurrency( + type: NativeCurrencyType, + network: string, + ): CurrencyDefinition | undefined; + getConversionPath( + from: Pick, + to: Pick, + network: string, + ): string[] | null; + supportsConversion(currency: Pick, network: string): boolean; + validateAddress(address: string, currency: CurrencyInput | StorageCurrency): boolean; + validateCurrency(currency: StorageCurrency): boolean; +} + +/** + * A mapping from old to new name for a given currency. + * + * Format { "chainName": {"TOKEN": ["NEW_TOKEN","NEW_CHAIN"]}} + */ +export type LegacyTokenMap = Record>; + +/** + * currencyFrom => currencyTo => cost + */ +export type CurrencyPairs = Record>; + +/** + * Aggregators maps define pairs of currencies for which an onchain oracle exists, by network. + * + * Network => currencyFrom => currencyTo => cost + */ +export type AggregatorsMap = Partial>;