diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e9374ea..f43c359f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- added: Implemented common `updateInfoPayload` method for all plugins +- changed: (Ethereum) Include network fee info for core info payload + ## 4.11.1 (2024-07-08) changed: Upgrade @polkadot/api to v12.1.1 @@ -20,7 +23,7 @@ changed: Upgrade @polkadot/api to v12.1.1 - added: (Ethereum/Solana) Add BOBBY - added: (zkSync) Add ZK -- changed: (Piratechain) Allow `derivePublicKey` to fail in case native code isn't present +- changed: (Piratechain) Allow `derivePublicKey` to fail in case native code isn't present - removed: (Zcash/Piratechain) Remove `defaultBirthdayHeight` ## 4.8.0 (2024-06-10) diff --git a/src/algorand/AlgorandTools.ts b/src/algorand/AlgorandTools.ts index 8a7f201f2..a74d6fcf3 100644 --- a/src/algorand/AlgorandTools.ts +++ b/src/algorand/AlgorandTools.ts @@ -16,8 +16,9 @@ import { import { PluginEnvironment } from '../common/innerPlugin' import { validateToken } from '../common/tokenHelpers' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { + AlgorandInfoPayload, AlgorandNetworkInfo, asAlgorandPrivateKeys, asMaybeContractAddressLocation, @@ -155,4 +156,15 @@ export async function makeCurrencyTools( return new AlgorandTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: AlgorandInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './AlgorandEngine' diff --git a/src/algorand/algorandInfo.ts b/src/algorand/algorandInfo.ts index 913dbf00c..75bd1f73e 100644 --- a/src/algorand/algorandInfo.ts +++ b/src/algorand/algorandInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import { makeMetaTokens } from '../common/tokenHelpers' import type { AlgorandTools } from './AlgorandTools' -import { AlgorandNetworkInfo, asAlgorandInfoPayload } from './algorandTypes' +import { + AlgorandInfoPayload, + AlgorandNetworkInfo, + asAlgorandInfoPayload +} from './algorandTypes' const builtinTokens: EdgeTokenMap = { '31566704': { @@ -72,10 +76,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const algorand = makeOuterPlugin({ +export const algorand = makeOuterPlugin< + AlgorandNetworkInfo, + AlgorandTools, + AlgorandInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asAlgorandInfoPayload, + asInfoPayload: asAlgorandInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/algorand/algorandTestnetInfo.ts b/src/algorand/algorandTestnetInfo.ts index 98fc489b8..8917ac96e 100644 --- a/src/algorand/algorandTestnetInfo.ts +++ b/src/algorand/algorandTestnetInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import { makeMetaTokens } from '../common/tokenHelpers' import type { AlgorandTools } from './AlgorandTools' -import { AlgorandNetworkInfo, asAlgorandInfoPayload } from './algorandTypes' +import { + AlgorandInfoPayload, + AlgorandNetworkInfo, + asAlgorandInfoPayload +} from './algorandTypes' const builtinTokens: EdgeTokenMap = { '10458941': { @@ -67,11 +71,12 @@ const currencyInfo: EdgeCurrencyInfo = { export const algorandtestnet = makeOuterPlugin< AlgorandNetworkInfo, - AlgorandTools + AlgorandTools, + AlgorandInfoPayload >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asAlgorandInfoPayload, + asInfoPayload: asAlgorandInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/algorand/algorandTypes.ts b/src/algorand/algorandTypes.ts index 76857702c..3fe3e2617 100644 --- a/src/algorand/algorandTypes.ts +++ b/src/algorand/algorandTypes.ts @@ -37,11 +37,6 @@ export interface AlgorandNetworkInfo { minimumAddressBalance: string } -export const asAlgorandInfoPayload = asObject({ - algodServers: asOptional(asArray(asString)), - indexerServers: asOptional(asArray(asString)) -}) - export const asAccountInformation = asObject({ // address: asString, amount: asNumber, @@ -257,3 +252,13 @@ export const asAlgorandWalletConnectPayload = asObject({ ) ) }).withRest + +// +// Info Payload +// + +export const asAlgorandInfoPayload = asObject({ + algodServers: asOptional(asArray(asString)), + indexerServers: asOptional(asArray(asString)) +}) +export type AlgorandInfoPayload = ReturnType diff --git a/src/binance/BinanceTools.ts b/src/binance/BinanceTools.ts index 6f428a5bd..30de9f6ce 100644 --- a/src/binance/BinanceTools.ts +++ b/src/binance/BinanceTools.ts @@ -15,10 +15,11 @@ import { import { PluginEnvironment } from '../common/innerPlugin' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asBnbPrivateKey, asSafeBnbWalletInfo, + BinanceInfoPayload, BinanceNetworkInfo } from './binanceTypes' @@ -152,4 +153,15 @@ export async function makeCurrencyTools( return new BinanceTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: BinanceInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './BinanceEngine' diff --git a/src/binance/binanceInfo.ts b/src/binance/binanceInfo.ts index 3fdffa921..e4d37956a 100644 --- a/src/binance/binanceInfo.ts +++ b/src/binance/binanceInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { BinanceTools } from './BinanceTools' -import { asBinanceInfoPayload, BinanceNetworkInfo } from './binanceTypes' +import { + asBinanceInfoPayload, + BinanceInfoPayload, + BinanceNetworkInfo +} from './binanceTypes' const networkInfo: BinanceNetworkInfo = { binanceApiServers: [ @@ -37,9 +41,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 128 }] } -export const binance = makeOuterPlugin({ +export const binance = makeOuterPlugin< + BinanceNetworkInfo, + BinanceTools, + BinanceInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asBinanceInfoPayload, + asInfoPayload: asBinanceInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/binance/binanceTypes.ts b/src/binance/binanceTypes.ts index 314dfd237..a7535ad1b 100644 --- a/src/binance/binanceTypes.ts +++ b/src/binance/binanceTypes.ts @@ -14,11 +14,6 @@ export interface BinanceNetworkInfo { beaconChainApiServers: string[] } -export const asBinanceInfoPayload = asObject({ - binanceApiServers: asOptional(asArray(asString)), - beaconChainApiServers: asOptional(asArray(asString)) -}) - export const asBinanceApiNodeInfo = asObject({ sync_info: asObject({ latest_block_height: asNumber @@ -89,3 +84,13 @@ export const asBnbPrivateKey = asObject({ binanceKey: asString, binanceMnemonic: asString }) + +// +// Info Payload +// + +export const asBinanceInfoPayload = asObject({ + binanceApiServers: asOptional(asArray(asString)), + beaconChainApiServers: asOptional(asArray(asString)) +}) +export type BinanceInfoPayload = ReturnType diff --git a/src/cardano/CardanoTools.ts b/src/cardano/CardanoTools.ts index 78cec328b..40deddc27 100644 --- a/src/cardano/CardanoTools.ts +++ b/src/cardano/CardanoTools.ts @@ -16,10 +16,11 @@ import { base16 } from 'rfc4648' import { PluginEnvironment } from '../common/innerPlugin' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asCardanoPrivateKeys, asSafeCardanoWalletInfo, + CardanoInfoPayload, CardanoNetworkInfo, EpochParams, SafeCardanoWalletInfo @@ -193,3 +194,14 @@ export async function makeCurrencyTools( } export { makeCurrencyEngine } from './CardanoEngine' + +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: CardanoInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} diff --git a/src/cardano/cardanoInfo.ts b/src/cardano/cardanoInfo.ts index 9298d17d1..5e8233efa 100644 --- a/src/cardano/cardanoInfo.ts +++ b/src/cardano/cardanoInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { CardanoTools } from './CardanoTools' -import { asCardanoInfoPayload, CardanoNetworkInfo } from './cardanoTypes' +import { + asCardanoInfoPayload, + CardanoInfoPayload, + CardanoNetworkInfo +} from './cardanoTypes' const networkInfo: CardanoNetworkInfo = { networkId: 1, @@ -29,9 +33,13 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const cardano = makeOuterPlugin({ +export const cardano = makeOuterPlugin< + CardanoNetworkInfo, + CardanoTools, + CardanoInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asCardanoInfoPayload, + asInfoPayload: asCardanoInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/cardano/cardanoTestnetInfo.ts b/src/cardano/cardanoTestnetInfo.ts index 76c7f1d70..528451b49 100644 --- a/src/cardano/cardanoTestnetInfo.ts +++ b/src/cardano/cardanoTestnetInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { CardanoTools } from './CardanoTools' -import { asCardanoInfoPayload, CardanoNetworkInfo } from './cardanoTypes' +import { + asCardanoInfoPayload, + CardanoInfoPayload, + CardanoNetworkInfo +} from './cardanoTypes' const networkInfo: CardanoNetworkInfo = { networkId: 0, @@ -29,20 +33,22 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const cardanotestnet = makeOuterPlugin( - { - currencyInfo, - infoPayloadCleaner: asCardanoInfoPayload, - networkInfo, - - checkEnvironment: () => { - if (global.BigInt == null) { - throw new Error('Cardano Testnet requires bigint support') - } - }, - - async getInnerPlugin() { - return await import('./CardanoTools') +export const cardanotestnet = makeOuterPlugin< + CardanoNetworkInfo, + CardanoTools, + CardanoInfoPayload +>({ + currencyInfo, + asInfoPayload: asCardanoInfoPayload, + networkInfo, + + checkEnvironment: () => { + if (global.BigInt == null) { + throw new Error('Cardano Testnet requires bigint support') } + }, + + async getInnerPlugin() { + return await import('./CardanoTools') } -) +}) diff --git a/src/cardano/cardanoTypes.ts b/src/cardano/cardanoTypes.ts index e6c4896d6..d9709853f 100644 --- a/src/cardano/cardanoTypes.ts +++ b/src/cardano/cardanoTypes.ts @@ -20,12 +20,6 @@ export interface CardanoNetworkInfo { maestroServer: string } -export const asCardanoInfoPayload = asObject({ - koiosServer: asOptional(asString), - blockfrostServer: asOptional(asString), - maestroServer: asOptional(asString) -}) - export type SafeCardanoWalletInfo = ReturnType export const asSafeCardanoWalletInfo = asWalletInfo( asObject({ @@ -266,3 +260,14 @@ export const asCardanoInitOptions = asObject({ maestroApiKey: asOptional(asString) }) export type CardanoInitOptions = ReturnType + +// +// Info Payload +// + +export const asCardanoInfoPayload = asObject({ + koiosServer: asOptional(asString), + blockfrostServer: asOptional(asString), + maestroServer: asOptional(asString) +}) +export type CardanoInfoPayload = ReturnType diff --git a/src/common/innerPlugin.ts b/src/common/innerPlugin.ts index 834b2116a..6188d6a36 100644 --- a/src/common/innerPlugin.ts +++ b/src/common/innerPlugin.ts @@ -8,11 +8,10 @@ import { EdgeCurrencyTools, EdgeOtherMethods, EdgeTokenMap, - EdgeWalletInfo + EdgeWalletInfo, + JsonObject } from 'edge-core-js/types' -import { mergeDeeply } from './utils' - /** * We pass a more complete plugin environment to the inner plugin, * so we can share the same instance between sibling networks. @@ -27,7 +26,11 @@ export interface PluginEnvironment extends EdgeCorePluginOptions { * These methods involve expensive crypto libraries * that we don't want to load unless we actually have wallets in an account. */ -export interface InnerPlugin { +export interface InnerPlugin< + NetworkInfo, + Tools extends EdgeCurrencyTools, + InfoPayload +> { makeCurrencyEngine: ( env: PluginEnvironment, tools: Tools, @@ -36,60 +39,75 @@ export interface InnerPlugin { ) => Promise makeCurrencyTools: (env: PluginEnvironment) => Promise + + /** + * The plugin's `updateInfoPayload` implementation. + * + * Each plugin should define how the info payload updates the plugin + * environment. Although `InfoPayload` type may share some properties with + * the `NetworkInfo` type, it is not a one-to-one match. + * + * Be aware the `InfoPayload` type for each plugin is ossified by the fact + * that it is shared between the plugin and the info server. + */ + updateInfoPayload: ( + env: PluginEnvironment, + infoPayload: InfoPayload + ) => Promise } /** * These methods involve cheap, static information, * so we don't have to load any crypto libraries. */ -export interface OuterPlugin { +export interface OuterPlugin< + NetworkInfo, + Tools extends EdgeCurrencyTools, + InfoPayload +> { + asInfoPayload: Cleaner builtinTokens?: EdgeTokenMap currencyInfo: EdgeCurrencyInfo - infoPayloadCleaner: Cleaner> networkInfo: NetworkInfo - checkEnvironment?: () => void - getInnerPlugin: () => Promise> - otherMethodNames?: ReadonlyArray + + checkEnvironment?: () => void + getInnerPlugin: () => Promise> } type EdgeCorePluginFactory = (env: EdgeCorePluginOptions) => EdgeCurrencyPlugin -export function makeOuterPlugin( - template: OuterPlugin +export function makeOuterPlugin< + NetworkInfo, + Tools extends EdgeCurrencyTools, + InfoPayload +>( + template: OuterPlugin ): EdgeCorePluginFactory { return (env: EdgeCorePluginOptions): EdgeCurrencyPlugin => { const { builtinTokens = {}, currencyInfo, networkInfo: defaultNetworkInfo, - infoPayloadCleaner, + asInfoPayload, otherMethodNames = [], checkEnvironment = () => {} } = template - let networkInfo: NetworkInfo = defaultNetworkInfo - try { - networkInfo = mergeDeeply( - defaultNetworkInfo, - infoPayloadCleaner(env.infoPayload) - ) - } catch (e) { - env.log.warn('infoPayload cleaner error:', e) - } - - const innerEnv = { + const innerEnv: PluginEnvironment = { ...env, builtinTokens, currencyInfo, - networkInfo + networkInfo: defaultNetworkInfo } // Logic to load the inner plugin: - let pluginPromise: Promise> | undefined + let pluginPromise: + | Promise> + | undefined let toolsPromise: Promise | undefined async function loadInnerPlugin(): Promise<{ - plugin: InnerPlugin + plugin: InnerPlugin tools: Tools }> { checkEnvironment() @@ -101,6 +119,14 @@ export function makeOuterPlugin( toolsPromise = plugin.makeCurrencyTools(innerEnv) } const tools = await toolsPromise + + // Attempt to update the plugin state given the initial infoPayload: + try { + await updateInfoPayload(env.infoPayload) + } catch (e) { + env.log.warn('infoPayload cleaner error:', e) + } + return { plugin, tools } } @@ -123,12 +149,23 @@ export function makeOuterPlugin( const otherMethods = makeOtherMethods(makeCurrencyTools, otherMethodNames) + async function updateInfoPayload(payload: JsonObject): Promise { + const plugin = await pluginPromise + + // If the plugin hasn't been loaded yet, this is a noop. + if (plugin == null) return + + const infoPayload = asInfoPayload(payload) + await plugin.updateInfoPayload(innerEnv, infoPayload) + } + return { currencyInfo, getBuiltinTokens, makeCurrencyTools, makeCurrencyEngine, - otherMethods + otherMethods, + updateInfoPayload } } } diff --git a/src/cosmos/CosmosTools.ts b/src/cosmos/CosmosTools.ts index f9766fc98..81538c22d 100644 --- a/src/cosmos/CosmosTools.ts +++ b/src/cosmos/CosmosTools.ts @@ -23,12 +23,13 @@ import { base16 } from 'rfc4648' import { PluginEnvironment } from '../common/innerPlugin' import { asMaybeContractLocation, validateToken } from '../common/tokenHelpers' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { upgradeRegistryAndCreateMethods } from './cosmosRegistry' import { asCosmosPrivateKeys, asSafeCosmosWalletInfo, CosmosClients, + CosmosInfoPayload, CosmosMethods, CosmosNetworkInfo } from './cosmosTypes' @@ -262,4 +263,15 @@ export async function makeCurrencyTools( return new CosmosTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: CosmosInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './CosmosEngine' diff --git a/src/cosmos/cosmosTypes.ts b/src/cosmos/cosmosTypes.ts index 275b378e1..853357353 100644 --- a/src/cosmos/cosmosTypes.ts +++ b/src/cosmos/cosmosTypes.ts @@ -83,10 +83,6 @@ const asHttpEndpoint = asObject({ url: asString, headers: asObject({ asString }) }) -export const asCosmosInfoPayload = asObject({ - rpcNode: asOptional(asHttpEndpoint), - archiveNode: asOptional(asHttpEndpoint) -}) export const txQueryStrings = [ `coin_spent.spender`, @@ -269,3 +265,13 @@ export interface IbcChannel { channel: string port: string } + +// +// Info Payload +// + +export const asCosmosInfoPayload = asObject({ + rpcNode: asOptional(asHttpEndpoint), + archiveNode: asOptional(asHttpEndpoint) +}) +export type CosmosInfoPayload = ReturnType diff --git a/src/cosmos/info/axelarInfo.ts b/src/cosmos/info/axelarInfo.ts index 00dd8b2db..c1f9b4d5e 100644 --- a/src/cosmos/info/axelarInfo.ts +++ b/src/cosmos/info/axelarInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import type { CosmosTools } from '../CosmosTools' -import { asCosmosInfoPayload, CosmosNetworkInfo } from '../cosmosTypes' +import { + asCosmosInfoPayload, + CosmosInfoPayload, + CosmosNetworkInfo +} from '../cosmosTypes' const networkInfo: CosmosNetworkInfo = { bech32AddressPrefix: 'axelar', @@ -45,9 +49,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const axelar = makeOuterPlugin({ +export const axelar = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/coreumInfo.ts b/src/cosmos/info/coreumInfo.ts index 9a664ddc2..b1fb15a06 100644 --- a/src/cosmos/info/coreumInfo.ts +++ b/src/cosmos/info/coreumInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { CosmosTools } from '../CosmosTools' -import { asCosmosInfoPayload, CosmosNetworkInfo } from '../cosmosTypes' +import { + asCosmosInfoPayload, + CosmosInfoPayload, + CosmosNetworkInfo +} from '../cosmosTypes' const builtinTokens: EdgeTokenMap = { 'usara-core1r9gc0rnxnzpq33u82f44aufgdwvyxv4wyepyck98m9v2pxua6naqr8h03z': { @@ -169,10 +173,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const coreum = makeOuterPlugin({ +export const coreum = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/cosmoshubInfo.ts b/src/cosmos/info/cosmoshubInfo.ts index 23f4d2909..92ea5ba6b 100644 --- a/src/cosmos/info/cosmoshubInfo.ts +++ b/src/cosmos/info/cosmoshubInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import type { CosmosTools } from '../CosmosTools' -import { asCosmosInfoPayload, CosmosNetworkInfo } from '../cosmosTypes' +import { + asCosmosInfoPayload, + CosmosInfoPayload, + CosmosNetworkInfo +} from '../cosmosTypes' const networkInfo: CosmosNetworkInfo = { bech32AddressPrefix: 'cosmos', @@ -45,9 +49,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const cosmoshub = makeOuterPlugin({ +export const cosmoshub = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/osmosisInfo.ts b/src/cosmos/info/osmosisInfo.ts index 907f3fbdb..47cbc6f55 100644 --- a/src/cosmos/info/osmosisInfo.ts +++ b/src/cosmos/info/osmosisInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { CosmosTools } from '../CosmosTools' -import { asCosmosInfoPayload, CosmosNetworkInfo } from '../cosmosTypes' +import { + asCosmosInfoPayload, + CosmosInfoPayload, + CosmosNetworkInfo +} from '../cosmosTypes' import { cosmosCustomTokenTemplate } from './cosmosCommonInfo' const builtinTokens: EdgeTokenMap = { @@ -61,9 +65,13 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const osmosis = makeOuterPlugin({ +export const osmosis = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, builtinTokens, diff --git a/src/cosmos/info/thorchainruneInfo.ts b/src/cosmos/info/thorchainruneInfo.ts index 98100511f..c01e158bb 100644 --- a/src/cosmos/info/thorchainruneInfo.ts +++ b/src/cosmos/info/thorchainruneInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import type { CosmosTools } from '../CosmosTools' -import { asCosmosInfoPayload, CosmosNetworkInfo } from '../cosmosTypes' +import { + asCosmosInfoPayload, + CosmosInfoPayload, + CosmosNetworkInfo +} from '../cosmosTypes' // import { cosmosCustomTokenTemplate } from './cosmosCommonInfo' const networkInfo: CosmosNetworkInfo = { @@ -50,9 +54,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const thorchainrune = makeOuterPlugin({ +export const thorchainrune = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/eos/EosTools.ts b/src/eos/EosTools.ts index ec64cbe4b..28365c1d4 100644 --- a/src/eos/EosTools.ts +++ b/src/eos/EosTools.ts @@ -33,7 +33,8 @@ import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' import { asyncWaterfall, getFetchCors, - getLegacyDenomination + getLegacyDenomination, + mergeDeeply } from '../common/utils' import { asGetActivationCost, @@ -42,6 +43,7 @@ import { import { asEosPrivateKeys, asSafeEosWalletInfo, + EosInfoPayload, EosNetworkInfo } from './eosTypes' @@ -311,4 +313,15 @@ export async function makeCurrencyTools( return new EosTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: EosInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './EosEngine' diff --git a/src/eos/eosTypes.ts b/src/eos/eosTypes.ts index 0c2db137f..e99689141 100644 --- a/src/eos/eosTypes.ts +++ b/src/eos/eosTypes.ts @@ -19,13 +19,6 @@ export interface EosNetworkInfo { uriProtocol: string } -export const asEosInfoPayload = asObject({ - eosDfuseServers: asOptional(asArray(asString)), - eosHyperionNodes: asOptional(asArray(asString)), - eosNodes: asOptional(asArray(asString)), - powerUpServers: asOptional(asArray(asString)) -}) - export const eosOtherMethodNames = [ 'getActivationCost', 'getActivationSupportedCurrencies', @@ -110,3 +103,15 @@ export const asEosPrivateKeys = asObject({ eosOwnerKey: asOptional(asString), eosKey: asString }) + +// +// Info Payload +// + +export const asEosInfoPayload = asObject({ + eosDfuseServers: asOptional(asArray(asString)), + eosHyperionNodes: asOptional(asArray(asString)), + eosNodes: asOptional(asArray(asString)), + powerUpServers: asOptional(asArray(asString)) +}) +export type EosInfoPayload = ReturnType diff --git a/src/eos/info/eosInfo.ts b/src/eos/info/eosInfo.ts index 4c0343fa0..7528fff19 100644 --- a/src/eos/info/eosInfo.ts +++ b/src/eos/info/eosInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import { asEosInfoPayload, + EosInfoPayload, EosNetworkInfo, eosOtherMethodNames } from '../eosTypes' @@ -53,9 +54,9 @@ export const eosCurrencyInfo: EdgeCurrencyInfo = { ] } -export const eos = makeOuterPlugin({ +export const eos = makeOuterPlugin({ currencyInfo: eosCurrencyInfo, - infoPayloadCleaner: asEosInfoPayload, + asInfoPayload: asEosInfoPayload, networkInfo: eosNetworkInfo, otherMethodNames: eosOtherMethodNames, diff --git a/src/eos/info/telosInfo.ts b/src/eos/info/telosInfo.ts index 3a9e80827..cf33a6cfe 100644 --- a/src/eos/info/telosInfo.ts +++ b/src/eos/info/telosInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import { asEosInfoPayload, + EosInfoPayload, EosNetworkInfo, eosOtherMethodNames } from '../eosTypes' @@ -45,9 +46,9 @@ export const telosCurrencyInfo: EdgeCurrencyInfo = { ] } -export const telos = makeOuterPlugin({ +export const telos = makeOuterPlugin({ currencyInfo: telosCurrencyInfo, - infoPayloadCleaner: asEosInfoPayload, + asInfoPayload: asEosInfoPayload, networkInfo: telosNetworkInfo, otherMethodNames: eosOtherMethodNames, diff --git a/src/eos/info/waxInfo.ts b/src/eos/info/waxInfo.ts index 02dc67d8e..15efbfb4b 100644 --- a/src/eos/info/waxInfo.ts +++ b/src/eos/info/waxInfo.ts @@ -4,6 +4,7 @@ import { makeOuterPlugin } from '../../common/innerPlugin' import type { EosTools } from '../EosTools' import { asEosInfoPayload, + EosInfoPayload, EosNetworkInfo, eosOtherMethodNames } from '../eosTypes' @@ -41,9 +42,9 @@ export const waxCurrencyInfo: EdgeCurrencyInfo = { ] } -export const wax = makeOuterPlugin({ +export const wax = makeOuterPlugin({ currencyInfo: waxCurrencyInfo, - infoPayloadCleaner: asEosInfoPayload, + asInfoPayload: asEosInfoPayload, networkInfo: waxNetworkInfo, otherMethodNames: eosOtherMethodNames, diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 8fdd61395..201b9b666 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -103,7 +103,6 @@ export class EthereumEngine extends CurrencyEngine< infoFeeProvider: () => Promise externalFeeProviders: FeeProviderFunction[] optimismRollupParams?: OptimismRollupParams - networkFees: EthereumFees constructor( env: PluginEnvironment, tools: EthereumTools, @@ -124,7 +123,6 @@ export class EthereumEngine extends CurrencyEngine< blobBaseFeeScalar: '659851' } } - this.networkFees = this.networkInfo.defaultNetworkFees this.fetchCors = getFetchCors(env.io) // Update network fees from other providers @@ -347,7 +345,8 @@ export class EthereumEngine extends CurrencyEngine< } let gasPriceNetworkFee = - this.networkFees.default.gasPrice?.standardFeeHigh ?? '0' + this.networkInfo.networkFees.default.gasPrice + ?.standardFeeHigh ?? '0' if (gasPrice == null) { txParam.gasPrice = decimalToHex(gasPriceNetworkFee) } else { @@ -362,7 +361,10 @@ export class EthereumEngine extends CurrencyEngine< } // Get the gasLimit from currency info or from RPC node: - if (this.networkFees.default.gasLimit?.tokenTransaction == null) { + if ( + this.networkInfo.networkFees.default.gasLimit + ?.tokenTransaction == null + ) { this.ethNetwork .multicastRpc('eth_estimateGas', [txParam]) .then((estimateGasResult: any) => { @@ -380,7 +382,8 @@ export class EthereumEngine extends CurrencyEngine< }) } else { deriveNetworkFee( - this.networkFees.default.gasLimit?.tokenTransaction + this.networkInfo.networkFees.default.gasLimit + ?.tokenTransaction ) } break @@ -430,8 +433,7 @@ export class EthereumEngine extends CurrencyEngine< const tryEstimatingGasLimit = async ( attempt: number = 0 ): Promise => { - const defaultGasLimit = - this.networkInfo.defaultNetworkFees.default.gasLimit + const defaultGasLimit = this.networkInfo.networkFees.default.gasLimit try { if (defaultGasLimit != null && !sendingToContract && !hasUserMemo) { // Easy case of sending plain mainnet token with no memo/data @@ -484,7 +486,7 @@ export class EthereumEngine extends CurrencyEngine< if ( lt( gasLimitReturn, - this.networkFees.default.gasLimit?.minGasLimit ?? '21000' + this.networkInfo.networkFees.default.gasLimit?.minGasLimit ?? '21000' ) ) { // Revert gasLimit back to the value from calcMiningFee @@ -518,9 +520,9 @@ export class EthereumEngine extends CurrencyEngine< const k = key as KeysOfEthereumBaseMultiplier ethereumFeeInts[k] = biggyRoundToNearestInt(ethereumFee[k]) }) - if (this.networkFees.default.gasPrice != null) { - this.networkFees.default.gasPrice = { - ...this.networkFees.default.gasPrice, + if (this.networkInfo.networkFees.default.gasPrice != null) { + this.networkInfo.networkFees.default.gasPrice = { + ...this.networkInfo.networkFees.default.gasPrice, ...ethereumFeeInts } } @@ -539,7 +541,7 @@ export class EthereumEngine extends CurrencyEngine< try { const baseFee = await this.ethNetwork.getBaseFeePerGas() if (baseFee == null) return - this.networkFees.default.baseFee = baseFee + this.networkInfo.networkFees.default.baseFee = baseFee } catch (error: any) { this.error(`Error fetching base fee: ${JSON.stringify(error)}`) } @@ -666,15 +668,14 @@ export class EthereumEngine extends CurrencyEngine< if (baseFeePerGas == null) return const baseFeePerGasDecimal = hexToDecimal(baseFeePerGas) - const networkFees: EthereumFees = this.networkFees + const networkFees: EthereumFees = this.networkInfo.networkFees // Make sure there is a default network fee entry and gasPrice entry if (networkFees.default == null || networkFees.default.gasPrice == null) { return } - const defaultNetworkFee: EthereumFee = - this.networkInfo.defaultNetworkFees.default + const defaultNetworkFee: EthereumFee = this.networkInfo.networkFees.default // The minimum priority fee for slow transactions const minPriorityFee = @@ -731,14 +732,17 @@ export class EthereumEngine extends CurrencyEngine< .then(async info => { this.log.warn(`infoFeeProvider:`, JSON.stringify(info, null, 2)) - this.networkFees = mergeDeeply(this.networkFees, info) + this.networkInfo.networkFees = mergeDeeply( + this.networkInfo.networkFees, + info + ) // Update network baseFee: if (this.networkInfo.supportsEIP1559 === true) { try { const baseFee = await this.ethNetwork.getBaseFeePerGas() if (baseFee == null) return - this.networkFees.default.baseFee = baseFee + this.networkInfo.networkFees.default.baseFee = baseFee } catch (error) { this.error(`Error fetching base fee: ${JSON.stringify(error)}`) } @@ -805,12 +809,7 @@ export class EthereumEngine extends CurrencyEngine< spendInfo.spendTargets[0].nativeAmount = balance // Use our calcMiningFee function to calculate the fees: - const miningFees = calcMiningFees( - spendInfo, - this.networkFees, - null, - this.networkInfo - ) + const miningFees = calcMiningFees(this.networkInfo, spendInfo, null) // If our results require a call to the RPC server to estimate the gas limit, then we // need to do that now: @@ -987,10 +986,9 @@ export class EthereumEngine extends CurrencyEngine< const edgeToken = tokenId != null ? this.builtinTokens[tokenId] : null const miningFees = calcMiningFees( + this.networkInfo, edgeSpendInfo, - this.networkFees, - edgeToken, - this.networkInfo + edgeToken ) // Translate legacy transaction types to EIP-1559 transaction type @@ -999,7 +997,7 @@ export class EthereumEngine extends CurrencyEngine< const feeParams = await getFeeParamsByTransactionType( txType, miningFees.gasPrice, - this.networkFees.default.baseFee ?? + this.networkInfo.networkFees.default.baseFee ?? (await this.ethNetwork.getBaseFeePerGas()) ) @@ -1401,7 +1399,7 @@ export class EthereumEngine extends CurrencyEngine< const doubledFeeParams = await getFeeParamsByTransactionType( txType, mul(replacedTxOtherParams.gasPrice, '2'), - this.networkFees.default.baseFee ?? + this.networkInfo.networkFees.default.baseFee ?? (await this.ethNetwork.getBaseFeePerGas()) ) const gasLimit = replacedTxOtherParams.gas diff --git a/src/ethereum/EthereumTools.ts b/src/ethereum/EthereumTools.ts index 5dc4187e1..3a235aa84 100644 --- a/src/ethereum/EthereumTools.ts +++ b/src/ethereum/EthereumTools.ts @@ -22,12 +22,14 @@ import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' import { biggyScience, getLegacyDenomination, + mergeDeeply, multicastEthProviders } from '../common/utils' import { ethereumPlugins } from './ethereumInfos' import { asEthereumPrivateKeys, asSafeEthWalletInfo, + EthereumInfoPayload, EthereumInitOptions, EthereumNetworkInfo } from './ethereumTypes' @@ -398,9 +400,9 @@ export class EthereumTools implements EdgeCurrencyTools { providers: ethProviders }) } -} -// #endregion otherMethods + // #endregion otherMethods +} export async function makeCurrencyTools( env: PluginEnvironment @@ -410,4 +412,15 @@ export async function makeCurrencyTools( return out } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: EthereumInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './EthereumEngine' diff --git a/src/ethereum/ethereumTypes.ts b/src/ethereum/ethereumTypes.ts index 58d41972c..d0691400b 100644 --- a/src/ethereum/ethereumTypes.ts +++ b/src/ethereum/ethereumTypes.ts @@ -78,11 +78,10 @@ export interface EthereumNetworkInfo { arbitrumRollupParams?: { nodeInterfaceAddress: string } - // eslint-disable-next-line no-use-before-define - defaultNetworkFees: EthereumFees ercTokenStandard: string ethGasStationUrl: string | null hdPathCoinType: number + networkFees: EthereumFees pluginMnemonicKeyName: string pluginRegularKeyName: string uriNetworks: string[] @@ -103,9 +102,6 @@ const asNetworkAdaptorConfig = asObject({ servers: asArray(asString), ethBalCheckerContract: asOptional(asString) }) -export const asEthereumInfoPayload = asObject({ - networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)) -}) /** * Other Methods from EthereumTools @@ -539,3 +535,13 @@ export const asMaybeEvmOverrideGasLimitLocation = asMaybe( overrideGasLimit: asIntegerString }) ) + +// +// Info Payload +// + +export const asEthereumInfoPayload = asObject({ + networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)), + networkFees: asOptional(asEthereumFees) +}) +export type EthereumInfoPayload = ReturnType diff --git a/src/ethereum/fees/ethMiningFees.ts b/src/ethereum/fees/ethMiningFees.ts index d9392ddfc..cd3cecb10 100644 --- a/src/ethereum/fees/ethMiningFees.ts +++ b/src/ethereum/fees/ethMiningFees.ts @@ -15,7 +15,6 @@ import { asMaybeEvmOverrideGasLimitLocation, CalcOptimismRollupFeeParams, EthereumFee, - EthereumFees, EthereumMiningFees, EthereumNetworkInfo } from '../ethereumTypes' @@ -28,10 +27,9 @@ export const ES_FEE_CUSTOM = 'custom' const WEI_MULTIPLIER = '1000000000' export function calcMiningFees( + networkInfo: EthereumNetworkInfo, spendInfo: EdgeSpendInfo, - networkFees: EthereumFees, - edgeToken: EdgeToken | null, - networkInfo: EthereumNetworkInfo + edgeToken: EdgeToken | null ): EthereumMiningFees { let useGasLimitDefaults = true let customGasLimit, customGasPrice @@ -55,9 +53,7 @@ export function calcMiningFees( } if (gasPrice != null && gasPrice !== '') { - const minGasPrice = - networkFees.default?.gasPrice?.minGasPrice ?? - networkInfo.defaultNetworkFees.default.gasPrice?.minGasPrice + const minGasPrice = networkInfo.networkFees.default.gasPrice?.minGasPrice if (minGasPrice != null) { const gasPriceInWei = mul(gasPrice, WEI_MULTIPLIER) if (lt(gasPriceInWei, minGasPrice) || /^\s*$/.test(gasPrice)) { @@ -73,9 +69,7 @@ export function calcMiningFees( } if (gasLimit != null && gasLimit !== '') { - const minGasLimit = - networkFees.default?.gasLimit?.minGasLimit ?? - networkInfo.defaultNetworkFees.default.gasLimit?.minGasLimit + const minGasLimit = networkInfo.networkFees.default.gasLimit?.minGasLimit if ( (minGasLimit != null && lt(gasLimit, minGasLimit)) || /^\s*$/.test(gasLimit) @@ -101,16 +95,16 @@ export function calcMiningFees( } } - let networkFeeForGasPrice: EthereumFee = networkFees.default - let networkFeeForGasLimit: EthereumFee = networkFees.default + let networkFeeForGasPrice: EthereumFee = networkInfo.networkFees.default + let networkFeeForGasLimit: EthereumFee = networkInfo.networkFees.default if (typeof spendInfo.spendTargets[0]?.publicAddress === 'string') { // If we have incomplete fees from custom fees, calculate as normal const targetAddress = normalizeAddress( spendInfo.spendTargets[0].publicAddress ) - if (typeof networkFees[targetAddress] !== 'undefined') { - networkFeeForGasLimit = networkFees[targetAddress] + if (typeof networkInfo.networkFees[targetAddress] !== 'undefined') { + networkFeeForGasLimit = networkInfo.networkFees[targetAddress] useGasLimitDefaults = false if (typeof networkFeeForGasLimit.gasPrice !== 'undefined') { networkFeeForGasPrice = networkFeeForGasLimit diff --git a/src/ethereum/info/arbitrumInfo.ts b/src/ethereum/info/arbitrumInfo.ts index 723c89e1d..9fac94b4a 100644 --- a/src/ethereum/info/arbitrumInfo.ts +++ b/src/ethereum/info/arbitrumInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -106,7 +107,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -170,7 +171,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'arbitrumMnemonic', pluginRegularKeyName: 'arbitrumKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -200,10 +201,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const arbitrum = makeOuterPlugin({ +export const arbitrum = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/avalancheInfo.ts b/src/ethereum/info/avalancheInfo.ts index 9f3357e54..614da2c02 100644 --- a/src/ethereum/info/avalancheInfo.ts +++ b/src/ethereum/info/avalancheInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -155,7 +156,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -211,7 +212,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'avalancheMnemonic', pluginRegularKeyName: 'avalancheKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -241,10 +242,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const avalanche = makeOuterPlugin({ +export const avalanche = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/baseInfo.ts b/src/ethereum/info/baseInfo.ts index ae4825e82..cb213c6a3 100644 --- a/src/ethereum/info/baseInfo.ts +++ b/src/ethereum/info/baseInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -27,7 +28,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -85,7 +86,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'baseMnemonic', pluginRegularKeyName: 'baseKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -115,10 +116,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const base = makeOuterPlugin({ +export const base = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/binancesmartchainInfo.ts b/src/ethereum/info/binancesmartchainInfo.ts index 674e9c8b4..f9d22b342 100644 --- a/src/ethereum/info/binancesmartchainInfo.ts +++ b/src/ethereum/info/binancesmartchainInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -114,7 +115,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -161,7 +162,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'binancesmartchainMnemonic', pluginRegularKeyName: 'binancesmartchainKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -193,11 +194,12 @@ const currencyInfo: EdgeCurrencyInfo = { export const binancesmartchain = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/bobevmInfo.ts b/src/ethereum/info/bobevmInfo.ts index 6d79497ed..b88c927a4 100644 --- a/src/ethereum/info/bobevmInfo.ts +++ b/src/ethereum/info/bobevmInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -18,7 +19,7 @@ import { const builtinTokens: EdgeTokenMap = {} // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -69,7 +70,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'bobevmMnemonic', pluginRegularKeyName: 'bobevmKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -99,10 +100,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const bobevm = makeOuterPlugin({ +export const bobevm = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/celoInfo.ts b/src/ethereum/info/celoInfo.ts index 407bd18a3..d4a18e124 100644 --- a/src/ethereum/info/celoInfo.ts +++ b/src/ethereum/info/celoInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -35,7 +36,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -85,7 +86,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'celoMnemonic', pluginRegularKeyName: 'celoKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -115,10 +116,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const celo = makeOuterPlugin({ +export const celo = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/ethDevInfo.ts b/src/ethereum/info/ethDevInfo.ts index fa8bbfb53..cacc0605d 100644 --- a/src/ethereum/info/ethDevInfo.ts +++ b/src/ethereum/info/ethDevInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -42,7 +43,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -119,7 +120,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethDevMnemonic', pluginRegularKeyName: 'ethDevKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -154,10 +155,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ethDev = makeOuterPlugin({ +export const ethDev = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/ethereumInfo.ts b/src/ethereum/info/ethereumInfo.ts index 10dd48525..8a0aeb26b 100644 --- a/src/ethereum/info/ethereumInfo.ts +++ b/src/ethereum/info/ethereumInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo, ethOtherMethodNames } from '../ethereumTypes' @@ -1063,7 +1064,7 @@ export const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -1175,7 +1176,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumMnemonic', pluginRegularKeyName: 'ethereumKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } export const currencyInfo: EdgeCurrencyInfo = { @@ -1210,10 +1211,14 @@ export const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ethereum = makeOuterPlugin({ +export const ethereum = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ + asInfoPayload: asEthereumInfoPayload, builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, networkInfo, otherMethodNames: ethOtherMethodNames, diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 54b600a62..91dfb21cc 100644 --- a/src/ethereum/info/ethereumclassicInfo.ts +++ b/src/ethereum/info/ethereumclassicInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -26,7 +27,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -110,7 +111,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumclassicMnemonic', pluginRegularKeyName: 'ethereumclassicKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -147,11 +148,12 @@ const currencyInfo: EdgeCurrencyInfo = { export const ethereumclassic = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/ethereumpowInfo.ts b/src/ethereum/info/ethereumpowInfo.ts index 3dccce277..fafbcd1a5 100644 --- a/src/ethereum/info/ethereumpowInfo.ts +++ b/src/ethereum/info/ethereumpowInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -26,7 +27,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -79,7 +80,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumpowMnemonic', pluginRegularKeyName: 'ethereumpowKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -114,10 +115,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ethereumpow = makeOuterPlugin({ +export const ethereumpow = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/fantomInfo.ts b/src/ethereum/info/fantomInfo.ts index 5f58020c8..be435d52e 100644 --- a/src/ethereum/info/fantomInfo.ts +++ b/src/ethereum/info/fantomInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -258,7 +259,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -311,7 +312,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'fantomMnemonic', pluginRegularKeyName: 'fantomKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -341,10 +342,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const fantom = makeOuterPlugin({ +export const fantom = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/filecoinFevmCalibrationInfo.ts b/src/ethereum/info/filecoinFevmCalibrationInfo.ts index ca70aed70..21cd53d2f 100644 --- a/src/ethereum/info/filecoinFevmCalibrationInfo.ts +++ b/src/ethereum/info/filecoinFevmCalibrationInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { evmCustomFeeTemplate, evmMemoOptions } from './ethereumCommonInfo' @@ -29,7 +30,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -75,7 +76,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'filecoinfevmcalibrationMnemonic', pluginRegularKeyName: 'filecoinfevmcalibrationKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -136,11 +137,12 @@ const currencyInfo: EdgeCurrencyInfo = { export const filecoinfevmcalibration = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/filecoinFevmInfo.ts b/src/ethereum/info/filecoinFevmInfo.ts index b7ae824c3..99f9fba28 100644 --- a/src/ethereum/info/filecoinFevmInfo.ts +++ b/src/ethereum/info/filecoinFevmInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { evmCustomFeeTemplate, evmMemoOptions } from './ethereumCommonInfo' @@ -29,7 +30,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -75,7 +76,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'filecoinfevmMnemonic', pluginRegularKeyName: 'filecoinfevmKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -134,15 +135,17 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const filecoinfevm = makeOuterPlugin( - { - builtinTokens, - currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, - networkInfo, +export const filecoinfevm = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ + builtinTokens, + currencyInfo, + asInfoPayload: asEthereumInfoPayload, + networkInfo, - async getInnerPlugin() { - return await import('../EthereumTools') - } + async getInnerPlugin() { + return await import('../EthereumTools') } -) +}) diff --git a/src/ethereum/info/goerliInfo.ts b/src/ethereum/info/goerliInfo.ts index 3c9ee16bc..9f9d41e57 100644 --- a/src/ethereum/info/goerliInfo.ts +++ b/src/ethereum/info/goerliInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -43,7 +44,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -129,7 +130,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'goerliMnemonic', pluginRegularKeyName: 'goerliKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -164,10 +165,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const goerli = makeOuterPlugin({ +export const goerli = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/kovanInfo.ts b/src/ethereum/info/kovanInfo.ts index 7451d4569..50d1aa313 100644 --- a/src/ethereum/info/kovanInfo.ts +++ b/src/ethereum/info/kovanInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -163,7 +164,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -248,7 +249,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'kovanMnemonic', pluginRegularKeyName: 'kovanKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -283,10 +284,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const kovan = makeOuterPlugin({ +export const kovan = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/mumbaiInfo.ts b/src/ethereum/info/mumbaiInfo.ts index c8216baac..f09e5050d 100644 --- a/src/ethereum/info/mumbaiInfo.ts +++ b/src/ethereum/info/mumbaiInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -149,7 +150,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -198,7 +199,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'mumbaiMnemonic', pluginRegularKeyName: 'mumbaiKey', ethGasStationUrl: '', - defaultNetworkFees + networkFees } export const currencyInfo: EdgeCurrencyInfo = { @@ -233,10 +234,14 @@ export const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const mumbai = makeOuterPlugin({ +export const mumbai = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/optimismInfo.ts b/src/ethereum/info/optimismInfo.ts index b7c916e05..f20998a1f 100644 --- a/src/ethereum/info/optimismInfo.ts +++ b/src/ethereum/info/optimismInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -147,7 +148,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -198,7 +199,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'optimismMnemonic', pluginRegularKeyName: 'optimismKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -228,10 +229,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const optimism = makeOuterPlugin({ +export const optimism = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/polygonInfo.ts b/src/ethereum/info/polygonInfo.ts index b2c15903e..ff1691b6a 100644 --- a/src/ethereum/info/polygonInfo.ts +++ b/src/ethereum/info/polygonInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -155,7 +156,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -209,7 +210,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'polygonMnemonic', pluginRegularKeyName: 'polygonKey', ethGasStationUrl: 'https://gasstation-mainnet.matic.network/', - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -244,10 +245,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const polygon = makeOuterPlugin({ +export const polygon = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/pulsechainInfo.ts b/src/ethereum/info/pulsechainInfo.ts index 78ad42d69..49f7428a5 100644 --- a/src/ethereum/info/pulsechainInfo.ts +++ b/src/ethereum/info/pulsechainInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -26,7 +27,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -80,7 +81,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'pulsechainMnemonic', pluginRegularKeyName: 'pulsechainKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -115,10 +116,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const pulsechain = makeOuterPlugin({ +export const pulsechain = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/rinkebyInfo.ts b/src/ethereum/info/rinkebyInfo.ts index e36f6c7f7..a598fec72 100644 --- a/src/ethereum/info/rinkebyInfo.ts +++ b/src/ethereum/info/rinkebyInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -17,7 +18,7 @@ import { const builtinTokens: EdgeTokenMap = {} -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -101,7 +102,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'rinkebyMnemonic', pluginRegularKeyName: 'rinkebyKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -136,10 +137,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const rinkeby = makeOuterPlugin({ +export const rinkeby = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/ropstenInfo.ts b/src/ethereum/info/ropstenInfo.ts index 1350f1b3f..b2e045cc9 100644 --- a/src/ethereum/info/ropstenInfo.ts +++ b/src/ethereum/info/ropstenInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -17,7 +18,7 @@ import { const builtinTokens: EdgeTokenMap = {} -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -106,7 +107,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ropstenMnemonic', pluginRegularKeyName: 'ropstenKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -141,10 +142,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ropsten = makeOuterPlugin({ +export const ropsten = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/rskInfo.ts b/src/ethereum/info/rskInfo.ts index d3edb3b73..3aea806ac 100644 --- a/src/ethereum/info/rskInfo.ts +++ b/src/ethereum/info/rskInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -26,7 +27,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -70,7 +71,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'rskMnemonic', pluginRegularKeyName: 'rskKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -100,10 +101,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const rsk = makeOuterPlugin({ +export const rsk = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/zksyncInfo.ts b/src/ethereum/info/zksyncInfo.ts index dc8acd404..2b9854926 100644 --- a/src/ethereum/info/zksyncInfo.ts +++ b/src/ethereum/info/zksyncInfo.ts @@ -6,6 +6,7 @@ import type { EthereumTools } from '../EthereumTools' import { asEthereumInfoPayload, EthereumFees, + EthereumInfoPayload, EthereumNetworkInfo } from '../ethereumTypes' import { @@ -50,7 +51,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -99,7 +100,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'zksyncMnemonic', pluginRegularKeyName: 'zksyncKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { @@ -136,10 +137,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const zksync = makeOuterPlugin({ +export const zksync = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/filecoin/FilecoinTools.ts b/src/filecoin/FilecoinTools.ts index d6b8fec75..079c2b927 100644 --- a/src/filecoin/FilecoinTools.ts +++ b/src/filecoin/FilecoinTools.ts @@ -24,10 +24,11 @@ import { base16 } from 'rfc4648' import { PluginEnvironment } from '../common/innerPlugin' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asFilecoinPrivateKeys, asFilPublicKey, + FilecoinInfoPayload, FilecoinNetworkInfo } from './filecoinTypes' @@ -221,4 +222,15 @@ export async function makeCurrencyTools( return new FilecoinTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: FilecoinInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './FilecoinEngine' diff --git a/src/filecoin/calibrationInfo.ts b/src/filecoin/calibrationInfo.ts index c159267e6..c915ccfbb 100644 --- a/src/filecoin/calibrationInfo.ts +++ b/src/filecoin/calibrationInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { FilecoinTools } from './FilecoinTools' -import { asFilecoinInfoPayload, FilecoinNetworkInfo } from './filecoinTypes' +import { + asFilecoinInfoPayload, + FilecoinInfoPayload, + FilecoinNetworkInfo +} from './filecoinTypes' const networkInfo: FilecoinNetworkInfo = { filfoxUrl: 'https://calibration.filfox.info/api/v1', @@ -66,9 +70,13 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const calibration = makeOuterPlugin({ +export const calibration = makeOuterPlugin< + FilecoinNetworkInfo, + FilecoinTools, + FilecoinInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asFilecoinInfoPayload, + asInfoPayload: asFilecoinInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/filecoin/filecoinInfo.ts b/src/filecoin/filecoinInfo.ts index c3f463fbd..3423397c0 100644 --- a/src/filecoin/filecoinInfo.ts +++ b/src/filecoin/filecoinInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { FilecoinTools } from './FilecoinTools' -import { asFilecoinInfoPayload, FilecoinNetworkInfo } from './filecoinTypes' +import { + asFilecoinInfoPayload, + FilecoinInfoPayload, + FilecoinNetworkInfo +} from './filecoinTypes' const networkInfo: FilecoinNetworkInfo = { filfoxUrl: 'https://filfox.info/api/v1', @@ -72,9 +76,13 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const filecoin = makeOuterPlugin({ +export const filecoin = makeOuterPlugin< + FilecoinNetworkInfo, + FilecoinTools, + FilecoinInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asFilecoinInfoPayload, + asInfoPayload: asFilecoinInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/filecoin/filecoinTypes.ts b/src/filecoin/filecoinTypes.ts index 4280b5c42..7621a434b 100644 --- a/src/filecoin/filecoinTypes.ts +++ b/src/filecoin/filecoinTypes.ts @@ -23,16 +23,6 @@ export interface FilecoinNetworkInfo { } const networkName = asValue('Mainnet', 'Calibration', 'Butterfly') -export const asFilecoinInfoPayload = asObject({ - filfoxUrl: asOptional(asString), - filscanUrl: asOptional(asString), - rpcNode: asOptional( - asObject({ - networkName: networkName, - url: asString - }) - ) -}) export interface FilecoinInitOptions { glifApiKey: string @@ -104,3 +94,19 @@ export const asFilecoinPrivateKeys = ( } ) } + +// +// Info Payload +// + +export const asFilecoinInfoPayload = asObject({ + filfoxUrl: asOptional(asString), + filscanUrl: asOptional(asString), + rpcNode: asOptional( + asObject({ + networkName: networkName, + url: asString + }) + ) +}) +export type FilecoinInfoPayload = ReturnType diff --git a/src/fio/FioTools.ts b/src/fio/FioTools.ts index cc0c90e6e..5885c9aa3 100644 --- a/src/fio/FioTools.ts +++ b/src/fio/FioTools.ts @@ -21,6 +21,7 @@ import { asyncWaterfall, getFetchCors, getLegacyDenomination, + mergeDeeply, safeErrorMessage, shuffleArray } from '../common/utils' @@ -29,6 +30,7 @@ import { fioApiErrorCodes, FioError } from './fioError' import { asFioPrivateKeys, asSafeFioWalletInfo, + FioInfoPayload, FioNetworkInfo } from './fioTypes' @@ -566,4 +568,15 @@ export async function makeCurrencyTools( return new FioTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: FioInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './FioEngine' diff --git a/src/fio/fioInfo.ts b/src/fio/fioInfo.ts index ab20f1b97..30720bd4f 100644 --- a/src/fio/fioInfo.ts +++ b/src/fio/fioInfo.ts @@ -5,6 +5,7 @@ import { fioRegApiErrorCodes } from './fioError' import type { FioTools } from './FioTools' import { asFioInfoPayload, + FioInfoPayload, FioNetworkInfo, fioOtherMethodNames } from './fioTypes' @@ -78,9 +79,9 @@ const currencyInfo: EdgeCurrencyInfo = { } } -export const fio = makeOuterPlugin({ +export const fio = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asFioInfoPayload, + asInfoPayload: asFioInfoPayload, networkInfo, otherMethodNames: fioOtherMethodNames, diff --git a/src/fio/fioTypes.ts b/src/fio/fioTypes.ts index 4a8ed72de..b708597fa 100644 --- a/src/fio/fioTypes.ts +++ b/src/fio/fioTypes.ts @@ -42,15 +42,6 @@ export interface FioNetworkInfo { chainId: string } -export const asFioInfoPayload = asObject({ - apiUrls: asOptional(asArray(asString)), - historyNodeUrls: asOptional(asArray(asString)), - fioRegApiUrl: asOptional(asString), - fioDomainRegUrl: asOptional(asString), - fioAddressRegUrl: asOptional(asString), - fioStakingApyUrl: asOptional(asString) -}) - export type FioRequestTypes = 'PENDING' | 'SENT' export interface FioRefBlock { @@ -236,3 +227,17 @@ export const asFioNothingResponse = ( }) }) ) + +// +// Info Payload +// + +export const asFioInfoPayload = asObject({ + apiUrls: asOptional(asArray(asString)), + historyNodeUrls: asOptional(asArray(asString)), + fioRegApiUrl: asOptional(asString), + fioDomainRegUrl: asOptional(asString), + fioAddressRegUrl: asOptional(asString), + fioStakingApyUrl: asOptional(asString) +}) +export type FioInfoPayload = ReturnType diff --git a/src/hedera/HederaTools.ts b/src/hedera/HederaTools.ts index ba5df2db3..9b2195b3b 100644 --- a/src/hedera/HederaTools.ts +++ b/src/hedera/HederaTools.ts @@ -18,10 +18,15 @@ import { base16 } from 'rfc4648' import { PluginEnvironment } from '../common/innerPlugin' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getFetchCors, getLegacyDenomination } from '../common/utils' +import { + getFetchCors, + getLegacyDenomination, + mergeDeeply +} from '../common/utils' import { asHederaPrivateKeys, asSafeHederaWalletInfo, + HederaInfoPayload, HederaNetworkInfo } from './hederaTypes' import { createChecksum } from './hederaUtils' @@ -196,4 +201,15 @@ export async function makeCurrencyTools( return new HederaTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: HederaInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './HederaEngine' diff --git a/src/hedera/hederaInfo.ts b/src/hedera/hederaInfo.ts index 11336acaa..eeebfbecd 100644 --- a/src/hedera/hederaInfo.ts +++ b/src/hedera/hederaInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { HederaTools } from './HederaTools' -import { asHederaInfoPayload, HederaNetworkInfo } from './hederaTypes' +import { + asHederaInfoPayload, + HederaInfoPayload, + HederaNetworkInfo +} from './hederaTypes' const networkInfo: HederaNetworkInfo = { mirrorNodes: ['https://mainnet-public.mirrornode.hedera.com'], @@ -39,9 +43,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 100 }] } -export const hedera = makeOuterPlugin({ +export const hedera = makeOuterPlugin< + HederaNetworkInfo, + HederaTools, + HederaInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asHederaInfoPayload, + asInfoPayload: asHederaInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/hedera/hederaTestnetInfo.ts b/src/hedera/hederaTestnetInfo.ts index 8ffb44c8d..c466f964c 100644 --- a/src/hedera/hederaTestnetInfo.ts +++ b/src/hedera/hederaTestnetInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { HederaTools } from './HederaTools' -import { asHederaInfoPayload, HederaNetworkInfo } from './hederaTypes' +import { + asHederaInfoPayload, + HederaInfoPayload, + HederaNetworkInfo +} from './hederaTypes' const networkInfo: HederaNetworkInfo = { mirrorNodes: ['https://testnet.mirrornode.hedera.com'], @@ -36,9 +40,13 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const hederatestnet = makeOuterPlugin({ +export const hederatestnet = makeOuterPlugin< + HederaNetworkInfo, + HederaTools, + HederaInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asHederaInfoPayload, + asInfoPayload: asHederaInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/hedera/hederaTypes.ts b/src/hedera/hederaTypes.ts index 3814dcb8c..b08cdeeb7 100644 --- a/src/hedera/hederaTypes.ts +++ b/src/hedera/hederaTypes.ts @@ -19,10 +19,6 @@ export interface HederaNetworkInfo { maxFee: number } -export const asHederaInfoPayload = asObject({ - mirrorNodes: asOptional(asTuple(asString)) -}) - export const asHederaWalletOtherData = asObject({ hederaAccount: asMaybe(asString), latestTimestamp: asMaybe(asString, '1535068800') // genesis '2018-08-24T00:00:00.000Z' @@ -98,3 +94,12 @@ export const asHederaPrivateKeys = ( } ) } + +// +// Info Payload +// + +export const asHederaInfoPayload = asObject({ + mirrorNodes: asOptional(asTuple(asString)) +}) +export type HederaInfoPayload = ReturnType diff --git a/src/piratechain/PiratechainTools.ts b/src/piratechain/PiratechainTools.ts index 867d2e2a8..79b960211 100644 --- a/src/piratechain/PiratechainTools.ts +++ b/src/piratechain/PiratechainTools.ts @@ -17,11 +17,12 @@ import { Tools as ToolsType } from 'react-native-piratechain' import { PluginEnvironment } from '../common/innerPlugin' import { asIntegerString } from '../common/types' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asArrrPublicKey, asPiratechainPrivateKeys, asSafePiratechainWalletInfo, + PiratechainInfoPayload, PiratechainNetworkInfo } from './piratechainTypes' @@ -212,4 +213,15 @@ export async function makeCurrencyTools( return new PiratechainTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: PiratechainInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './PiratechainEngine' diff --git a/src/piratechain/piratechainInfo.ts b/src/piratechain/piratechainInfo.ts index 31aafc048..99273e0e1 100644 --- a/src/piratechain/piratechainInfo.ts +++ b/src/piratechain/piratechainInfo.ts @@ -6,6 +6,7 @@ import { makeOuterPlugin } from '../common/innerPlugin' import type { PiratechainTools } from './PiratechainTools' import { asPiratechainInfoPayload, + PiratechainInfoPayload, PiratechainNetworkInfo } from './piratechainTypes' @@ -46,10 +47,11 @@ const currencyInfo: EdgeCurrencyInfo = { export const piratechain = makeOuterPlugin< PiratechainNetworkInfo, - PiratechainTools + PiratechainTools, + PiratechainInfoPayload >({ currencyInfo, - infoPayloadCleaner: asPiratechainInfoPayload, + asInfoPayload: asPiratechainInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/piratechain/piratechainTypes.ts b/src/piratechain/piratechainTypes.ts index 921ead362..614ac3738 100644 --- a/src/piratechain/piratechainTypes.ts +++ b/src/piratechain/piratechainTypes.ts @@ -24,16 +24,6 @@ export interface PiratechainNetworkInfo { transactionQueryLimit: number } -export const asPiratechainInfoPayload = asObject({ - rpcNode: asOptional( - asObject({ - networkName: asValue('mainnet', 'testnet'), - defaultHost: asString, - defaultPort: asNumber - }) - ) -}) - export interface PiratechainSpendInfo { zatoshi: string toAddress: string @@ -178,3 +168,18 @@ export const asPiratechainPrivateKeys = ( } ) } + +// +// Info Payload +// + +export const asPiratechainInfoPayload = asObject({ + rpcNode: asOptional( + asObject({ + networkName: asValue('mainnet', 'testnet'), + defaultHost: asString, + defaultPort: asNumber + }) + ) +}) +export type PiratechainInfoPayload = ReturnType diff --git a/src/polkadot/PolkadotTools.ts b/src/polkadot/PolkadotTools.ts index 62714b5df..c9eed958d 100644 --- a/src/polkadot/PolkadotTools.ts +++ b/src/polkadot/PolkadotTools.ts @@ -19,10 +19,11 @@ import { import { PluginEnvironment } from '../common/innerPlugin' import { asMaybeContractLocation, validateToken } from '../common/tokenHelpers' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination, isHex } from '../common/utils' +import { getLegacyDenomination, isHex, mergeDeeply } from '../common/utils' import { asPolkapolkadotPrivateKeys, asSafePolkadotWalletInfo, + PolkadotInfoPayload, PolkadotNetworkInfo } from './polkadotTypes' @@ -188,4 +189,15 @@ export async function makeCurrencyTools( return new PolkadotTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: PolkadotInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './PolkadotEngine' diff --git a/src/polkadot/info/liberlandInfo.ts b/src/polkadot/info/liberlandInfo.ts index 88b9dc541..0aa0871f5 100644 --- a/src/polkadot/info/liberlandInfo.ts +++ b/src/polkadot/info/liberlandInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { PolkadotTools } from '../PolkadotTools' -import { asPolkadotInfoPayload, PolkadotNetworkInfo } from '../polkadotTypes' +import { + asPolkadotInfoPayload, + PolkadotInfoPayload, + PolkadotNetworkInfo +} from '../polkadotTypes' const builtinTokens: EdgeTokenMap = { '1': { @@ -51,10 +55,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const liberland = makeOuterPlugin({ +export const liberland = makeOuterPlugin< + PolkadotNetworkInfo, + PolkadotTools, + PolkadotInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/polkadot/info/liberlandTestnetInfo.ts b/src/polkadot/info/liberlandTestnetInfo.ts index 5db714b03..b49baabc6 100644 --- a/src/polkadot/info/liberlandTestnetInfo.ts +++ b/src/polkadot/info/liberlandTestnetInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import { makeMetaTokens } from '../../common/tokenHelpers' import type { PolkadotTools } from '../PolkadotTools' -import { asPolkadotInfoPayload, PolkadotNetworkInfo } from '../polkadotTypes' +import { + asPolkadotInfoPayload, + PolkadotInfoPayload, + PolkadotNetworkInfo +} from '../polkadotTypes' const builtinTokens: EdgeTokenMap = { '1': { @@ -50,11 +54,12 @@ const currencyInfo: EdgeCurrencyInfo = { export const liberlandtestnet = makeOuterPlugin< PolkadotNetworkInfo, - PolkadotTools + PolkadotTools, + PolkadotInfoPayload >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/polkadot/info/polkadotInfo.ts b/src/polkadot/info/polkadotInfo.ts index 539329c29..fea33bcf1 100644 --- a/src/polkadot/info/polkadotInfo.ts +++ b/src/polkadot/info/polkadotInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../../common/innerPlugin' import type { PolkadotTools } from '../PolkadotTools' -import { asPolkadotInfoPayload, PolkadotNetworkInfo } from '../polkadotTypes' +import { + asPolkadotInfoPayload, + PolkadotInfoPayload, + PolkadotNetworkInfo +} from '../polkadotTypes' const networkInfo: PolkadotNetworkInfo = { rpcNodes: ['wss://rpc.polkadot.io'], @@ -35,9 +39,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [] } -export const polkadot = makeOuterPlugin({ +export const polkadot = makeOuterPlugin< + PolkadotNetworkInfo, + PolkadotTools, + PolkadotInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/polkadot/polkadotTypes.ts b/src/polkadot/polkadotTypes.ts index eedfffe92..cb89c9868 100644 --- a/src/polkadot/polkadotTypes.ts +++ b/src/polkadot/polkadotTypes.ts @@ -22,10 +22,6 @@ export interface PolkadotNetworkInfo { partialFeeOffsetMultiplier: string } -export const asPolkadotInfoPayload = asObject({ - rpcNodes: asOptional(asArray(asString)) -}) - export const asPolkadotWalletOtherData = asObject({ txCount: asMaybe(asNumber, 0) }) @@ -93,3 +89,12 @@ export const asPolkapolkadotPrivateKeys = ( } ) } + +// +// Info Payload +// + +export const asPolkadotInfoPayload = asObject({ + rpcNodes: asOptional(asArray(asString)) +}) +export type PolkadotInfoPayload = ReturnType diff --git a/src/ripple/RippleTools.ts b/src/ripple/RippleTools.ts index 2ba190dd2..8f311ad26 100644 --- a/src/ripple/RippleTools.ts +++ b/src/ripple/RippleTools.ts @@ -26,12 +26,14 @@ import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' import { asyncWaterfall, getLegacyDenomination, + mergeDeeply, safeErrorMessage } from '../common/utils' import { asRipplePrivateKeys, asSafeRippleWalletInfo, asXrpNetworkLocation, + XrpInfoPayload, XrpNetworkInfo } from './rippleTypes' import { makeTokenId } from './rippleUtils' @@ -213,4 +215,15 @@ export async function makeCurrencyTools( return new RippleTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: XrpInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './RippleEngine' diff --git a/src/ripple/rippleInfo.ts b/src/ripple/rippleInfo.ts index 3af34e637..3063ade19 100644 --- a/src/ripple/rippleInfo.ts +++ b/src/ripple/rippleInfo.ts @@ -2,7 +2,7 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { RippleTools } from './RippleTools' -import { asXrpInfoPayload, XrpNetworkInfo } from './rippleTypes' +import { asXrpInfoPayload, XrpInfoPayload, XrpNetworkInfo } from './rippleTypes' export const DIVIDE_PRECISION = 18 export const EST_BLOCK_TIME_MS = 3500 @@ -114,10 +114,14 @@ export const builtinTokens: EdgeTokenMap = { } } -export const ripple = makeOuterPlugin({ +export const ripple = makeOuterPlugin< + XrpNetworkInfo, + RippleTools, + XrpInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asXrpInfoPayload, + asInfoPayload: asXrpInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ripple/rippleTypes.ts b/src/ripple/rippleTypes.ts index 3cadcfec8..107118f4d 100644 --- a/src/ripple/rippleTypes.ts +++ b/src/ripple/rippleTypes.ts @@ -19,10 +19,6 @@ export interface XrpNetworkInfo { baseReservePerToken: string } -export const asXrpInfoPayload = asObject({ - rippledServers: asOptional(asArray(asString)) -}) - export interface XrpCustomToken { currencyCode: string currencyName: string @@ -85,3 +81,12 @@ export const asFinalFieldsCanceledOffer = asObject({ TakerGets: asAmount // Add other fields that might appear in `FinalFields` as needed }) + +// +// Info Payload +// + +export const asXrpInfoPayload = asObject({ + rippledServers: asOptional(asArray(asString)) +}) +export type XrpInfoPayload = ReturnType diff --git a/src/solana/SolanaTools.ts b/src/solana/SolanaTools.ts index 2112b2a5f..3752e35ff 100644 --- a/src/solana/SolanaTools.ts +++ b/src/solana/SolanaTools.ts @@ -25,11 +25,12 @@ import { base16 } from 'rfc4648' import { PluginEnvironment } from '../common/innerPlugin' import { asMaybeContractLocation, validateToken } from '../common/tokenHelpers' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asSafeSolanaWalletInfo, asSolanaInitOptions, asSolanaPrivateKeys, + SolanaInfoPayload, SolanaInitOptions, SolanaNetworkInfo } from './solanaTypes' @@ -237,4 +238,15 @@ export async function makeCurrencyTools( return new SolanaTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: SolanaInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './SolanaEngine' diff --git a/src/solana/solanaInfo.ts b/src/solana/solanaInfo.ts index 6383d63a3..6e85df55f 100644 --- a/src/solana/solanaInfo.ts +++ b/src/solana/solanaInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import { makeMetaTokens } from '../common/tokenHelpers' import type { SolanaTools } from './SolanaTools' -import { asSolanaInfoPayload, SolanaNetworkInfo } from './solanaTypes' +import { + asSolanaInfoPayload, + SolanaInfoPayload, + SolanaNetworkInfo +} from './solanaTypes' const builtinTokens: EdgeTokenMap = { DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263: { @@ -129,9 +133,13 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const solana = makeOuterPlugin({ +export const solana = makeOuterPlugin< + SolanaNetworkInfo, + SolanaTools, + SolanaInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asSolanaInfoPayload, + asInfoPayload: asSolanaInfoPayload, networkInfo, builtinTokens, diff --git a/src/solana/solanaTypes.ts b/src/solana/solanaTypes.ts index 1bdd505fd..88e0345ae 100644 --- a/src/solana/solanaTypes.ts +++ b/src/solana/solanaTypes.ts @@ -23,11 +23,6 @@ export interface SolanaNetworkInfo { associatedTokenPublicKey: string } -export const asSolanaInfoPayload = asObject({ - rpcNodes: asOptional(asArray(asString)), - rpcNodesArchival: asOptional(asArray(asString)) -}) - export const asSolanaWalletOtherData = asObject({ newestTxid: asMaybe(asObject(asString), () => ({})) }) @@ -124,3 +119,13 @@ export const asSolanaTxOtherParams = asObject({ }) export const wasSolanaTxOtherParams = uncleaner(asSolanaTxOtherParams) + +// +// Info Payload +// + +export const asSolanaInfoPayload = asObject({ + rpcNodes: asOptional(asArray(asString)), + rpcNodesArchival: asOptional(asArray(asString)) +}) +export type SolanaInfoPayload = ReturnType diff --git a/src/stellar/StellarTools.ts b/src/stellar/StellarTools.ts index 879b14908..6a29e1973 100644 --- a/src/stellar/StellarTools.ts +++ b/src/stellar/StellarTools.ts @@ -18,10 +18,11 @@ import parse from 'url-parse' import { PluginEnvironment } from '../common/innerPlugin' import { makeMetaTokens } from '../common/tokenHelpers' import { parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asSafeStellarWalletInfo, asStellarPrivateKeys, + StellarInfoPayload, StellarNetworkInfo, StellarPrivateKeys } from './stellarTypes' @@ -241,4 +242,15 @@ export async function makeCurrencyTools( return new StellarTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: StellarInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './StellarEngine' diff --git a/src/stellar/stellarInfo.ts b/src/stellar/stellarInfo.ts index 0c7e24604..47b367a6a 100644 --- a/src/stellar/stellarInfo.ts +++ b/src/stellar/stellarInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { StellarTools } from './StellarTools' -import { asStellarInfoPayload, StellarNetworkInfo } from './stellarTypes' +import { + asStellarInfoPayload, + StellarInfoPayload, + StellarNetworkInfo +} from './stellarTypes' const networkInfo: StellarNetworkInfo = { baseReserve: '10000000', @@ -37,9 +41,13 @@ const currencyInfo: EdgeCurrencyInfo = { multipleMemos: true } -export const stellar = makeOuterPlugin({ +export const stellar = makeOuterPlugin< + StellarNetworkInfo, + StellarTools, + StellarInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asStellarInfoPayload, + asInfoPayload: asStellarInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/stellar/stellarTypes.ts b/src/stellar/stellarTypes.ts index 899a426d6..78404a1c7 100644 --- a/src/stellar/stellarTypes.ts +++ b/src/stellar/stellarTypes.ts @@ -14,10 +14,6 @@ export interface StellarNetworkInfo { stellarServers: string[] } -export const asStellarInfoPayload = asObject({ - stellarServers: asOptional(asArray(asString)) -}) - export interface StellarBalance { balance: string buying_liabilities: string @@ -105,3 +101,12 @@ export const asStellarPrivateKeys = asObject({ stellarKey: asString, stellarMnemonic: asMaybe(asString) }) + +// +// Info Payload +// + +export const asStellarInfoPayload = asObject({ + stellarServers: asOptional(asArray(asString)) +}) +export type StellarInfoPayload = ReturnType diff --git a/src/tezos/TezosTools.ts b/src/tezos/TezosTools.ts index bdbf60397..928f6d686 100644 --- a/src/tezos/TezosTools.ts +++ b/src/tezos/TezosTools.ts @@ -11,9 +11,11 @@ import { eztz } from 'eztz.js' import { decodeMainnet, encodeMainnet } from 'tezos-uri' import { PluginEnvironment } from '../common/innerPlugin' +import { mergeDeeply } from '../common/utils' import { asSafeTezosWalletInfo, asTezosPrivateKeys, + TezosInfoPayload, TezosNetworkInfo, UriTransaction } from './tezosTypes' @@ -160,4 +162,15 @@ export async function makeCurrencyTools( return new TezosTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: TezosInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './TezosEngine' diff --git a/src/tezos/tezosInfo.ts b/src/tezos/tezosInfo.ts index 3a4074085..2b2f76282 100644 --- a/src/tezos/tezosInfo.ts +++ b/src/tezos/tezosInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { TezosTools } from './TezosTools' -import { asTezosInfoPayload, TezosNetworkInfo } from './tezosTypes' +import { + asTezosInfoPayload, + TezosInfoPayload, + TezosNetworkInfo +} from './tezosTypes' const networkInfo: TezosNetworkInfo = { // Testnet (alphanet): @@ -61,9 +65,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [] } -export const tezos = makeOuterPlugin({ +export const tezos = makeOuterPlugin< + TezosNetworkInfo, + TezosTools, + TezosInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asTezosInfoPayload, + asInfoPayload: asTezosInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/tezos/tezosTypes.ts b/src/tezos/tezosTypes.ts index b64f560d9..27dc8c616 100644 --- a/src/tezos/tezosTypes.ts +++ b/src/tezos/tezosTypes.ts @@ -23,11 +23,6 @@ export interface TezosNetworkInfo { } } -export const asTezosInfoPayload = asObject({ - tezosRpcNodes: asOptional(asArray(asString)), - tezosApiServers: asOptional(asArray(asString)) -}) - export const asTezosWalletOtherData = asObject({ numberTransactions: asMaybe(asNumber, 0) }) @@ -151,3 +146,13 @@ export const asTezosPrivateKeys = asObject({ mnemonic: asString, privateKey: asString }) + +// +// Info Payload +// + +export const asTezosInfoPayload = asObject({ + tezosRpcNodes: asOptional(asArray(asString)), + tezosApiServers: asOptional(asArray(asString)) +}) +export type TezosInfoPayload = ReturnType diff --git a/src/tron/TronTools.ts b/src/tron/TronTools.ts index 314fb0973..724077bf5 100644 --- a/src/tron/TronTools.ts +++ b/src/tron/TronTools.ts @@ -20,11 +20,12 @@ import { PluginEnvironment } from '../common/innerPlugin' import { parsePixKey } from '../common/smartPay' import { asMaybeContractLocation, validateToken } from '../common/tokenHelpers' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asSafeTronWalletInfo, asTronInitOptions, asTronPrivateKeys, + TronInfoPayload, TronInitOptions, TronKeys, TronNetworkInfo @@ -207,4 +208,15 @@ export async function makeCurrencyTools( return new TronTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: TronInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './TronEngine' diff --git a/src/tron/tronInfo.ts b/src/tron/tronInfo.ts index 834b7dd03..1f8670277 100644 --- a/src/tron/tronInfo.ts +++ b/src/tron/tronInfo.ts @@ -3,7 +3,11 @@ import { EdgeCurrencyInfo, EdgeTokenMap } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import { makeMetaTokens } from '../common/tokenHelpers' import type { TronTools } from './TronTools' -import { asTronInfoPayload, TronNetworkInfo } from './tronTypes' +import { + asTronInfoPayload, + TronInfoPayload, + TronNetworkInfo +} from './tronTypes' const builtinTokens: EdgeTokenMap = { TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn: { @@ -144,10 +148,14 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const tron = makeOuterPlugin({ +export const tron = makeOuterPlugin< + TronNetworkInfo, + TronTools, + TronInfoPayload +>({ builtinTokens, currencyInfo, - infoPayloadCleaner: asTronInfoPayload, + asInfoPayload: asTronInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/tron/tronTypes.ts b/src/tron/tronTypes.ts index e264ae5fe..b55bb3611 100644 --- a/src/tron/tronTypes.ts +++ b/src/tron/tronTypes.ts @@ -35,11 +35,6 @@ export interface TronNetworkInfo { trc20BalCheckerContract: string } -export const asTronInfoPayload = asObject({ - tronApiServers: asOptional(asArray(asString)), - tronNodeServers: asOptional(asArray(asString)) -}) - export const asTxQueryCache = asObject({ txid: asString, timestamp: asNumber @@ -520,3 +515,13 @@ export const asTronPrivateKeys = asObject({ tronKey: asString, derivationPath: asOptional(asString) }) + +// +// Info Payload +// + +export const asTronInfoPayload = asObject({ + tronApiServers: asOptional(asArray(asString)), + tronNodeServers: asOptional(asArray(asString)) +}) +export type TronInfoPayload = ReturnType diff --git a/src/zcash/ZcashTools.ts b/src/zcash/ZcashTools.ts index b2f9a8e47..2bd0972c0 100644 --- a/src/zcash/ZcashTools.ts +++ b/src/zcash/ZcashTools.ts @@ -18,11 +18,12 @@ import { Tools as ToolsType } from 'react-native-zcash' import { PluginEnvironment } from '../common/innerPlugin' import { asIntegerString } from '../common/types' import { encodeUriCommon, parseUriCommon } from '../common/uriHelpers' -import { getLegacyDenomination } from '../common/utils' +import { getLegacyDenomination, mergeDeeply } from '../common/utils' import { asSafeZcashWalletInfo, asZcashPrivateKeys, asZecPublicKey, + ZcashInfoPayload, ZcashNetworkInfo } from './zcashTypes' @@ -212,4 +213,15 @@ export async function makeCurrencyTools( return new ZcashTools(env) } +export async function updateInfoPayload( + env: PluginEnvironment, + infoPayload: ZcashInfoPayload +): Promise { + // In the future, other fields might not be "network info" fields + const { ...networkInfo } = infoPayload + + // Update plugin NetworkInfo: + env.networkInfo = mergeDeeply(env.networkInfo, networkInfo) +} + export { makeCurrencyEngine } from './ZcashEngine' diff --git a/src/zcash/zcashInfo.ts b/src/zcash/zcashInfo.ts index ed938b846..69f31545a 100644 --- a/src/zcash/zcashInfo.ts +++ b/src/zcash/zcashInfo.ts @@ -2,7 +2,11 @@ import { EdgeCurrencyInfo } from 'edge-core-js/types' import { makeOuterPlugin } from '../common/innerPlugin' import type { ZcashTools } from './ZcashTools' -import { asZcashInfoPayload, ZcashNetworkInfo } from './zcashTypes' +import { + asZcashInfoPayload, + ZcashInfoPayload, + ZcashNetworkInfo +} from './zcashTypes' const networkInfo: ZcashNetworkInfo = { rpcNode: { @@ -39,9 +43,13 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 512 }] } -export const zcash = makeOuterPlugin({ +export const zcash = makeOuterPlugin< + ZcashNetworkInfo, + ZcashTools, + ZcashInfoPayload +>({ currencyInfo, - infoPayloadCleaner: asZcashInfoPayload, + asInfoPayload: asZcashInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/zcash/zcashTypes.ts b/src/zcash/zcashTypes.ts index c203f5d0b..3eb1304ff 100644 --- a/src/zcash/zcashTypes.ts +++ b/src/zcash/zcashTypes.ts @@ -39,16 +39,6 @@ export interface ZcashNetworkInfo { defaultNetworkFee: string } -export const asZcashInfoPayload = asObject({ - rpcNode: asOptional( - asObject({ - networkName: asValue('mainnet', 'testnet'), - defaultHost: asString, - defaultPort: asNumber - }) - ) -}) - export const asZcashWalletOtherData = asObject({ cachedAddress: asMaybe(asString), missingAndroidShieldedMemosHack: asMaybe(asArray(asString), () => []), @@ -118,3 +108,18 @@ export const asZcashPrivateKeys = ( } ) } + +// +// Info Payload +// + +export const asZcashInfoPayload = asObject({ + rpcNode: asOptional( + asObject({ + networkName: asValue('mainnet', 'testnet'), + defaultHost: asString, + defaultPort: asNumber + }) + ) +}) +export type ZcashInfoPayload = ReturnType