From 99d7c74231583926cce8ea537918c0bad3627531 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 3 Jul 2024 09:51:46 -0700 Subject: [PATCH 1/6] Rename info payload cleaner argument --- src/algorand/algorandInfo.ts | 2 +- src/algorand/algorandTestnetInfo.ts | 2 +- src/binance/binanceInfo.ts | 2 +- src/cardano/cardanoInfo.ts | 2 +- src/cardano/cardanoTestnetInfo.ts | 2 +- src/common/innerPlugin.ts | 6 +++--- src/cosmos/info/axelarInfo.ts | 2 +- src/cosmos/info/coreumInfo.ts | 2 +- src/cosmos/info/cosmoshubInfo.ts | 2 +- src/cosmos/info/osmosisInfo.ts | 2 +- src/cosmos/info/thorchainruneInfo.ts | 2 +- src/eos/info/eosInfo.ts | 2 +- src/eos/info/telosInfo.ts | 2 +- src/eos/info/waxInfo.ts | 2 +- src/ethereum/ethereumTypes.ts | 1 + src/ethereum/info/arbitrumInfo.ts | 2 +- src/ethereum/info/avalancheInfo.ts | 2 +- src/ethereum/info/baseInfo.ts | 2 +- src/ethereum/info/binancesmartchainInfo.ts | 2 +- src/ethereum/info/bobevmInfo.ts | 2 +- src/ethereum/info/celoInfo.ts | 2 +- src/ethereum/info/ethDevInfo.ts | 2 +- src/ethereum/info/ethereumInfo.ts | 2 +- src/ethereum/info/ethereumclassicInfo.ts | 2 +- src/ethereum/info/ethereumpowInfo.ts | 2 +- src/ethereum/info/fantomInfo.ts | 2 +- src/ethereum/info/filecoinFevmCalibrationInfo.ts | 2 +- src/ethereum/info/filecoinFevmInfo.ts | 2 +- src/ethereum/info/goerliInfo.ts | 2 +- src/ethereum/info/kovanInfo.ts | 2 +- src/ethereum/info/mumbaiInfo.ts | 2 +- src/ethereum/info/optimismInfo.ts | 2 +- src/ethereum/info/polygonInfo.ts | 2 +- src/ethereum/info/pulsechainInfo.ts | 2 +- src/ethereum/info/rinkebyInfo.ts | 2 +- src/ethereum/info/ropstenInfo.ts | 2 +- src/ethereum/info/rskInfo.ts | 2 +- src/ethereum/info/zksyncInfo.ts | 2 +- src/filecoin/calibrationInfo.ts | 2 +- src/filecoin/filecoinInfo.ts | 2 +- src/fio/fioInfo.ts | 2 +- src/hedera/hederaInfo.ts | 2 +- src/hedera/hederaTestnetInfo.ts | 2 +- src/piratechain/piratechainInfo.ts | 2 +- src/polkadot/info/liberlandInfo.ts | 2 +- src/polkadot/info/liberlandTestnetInfo.ts | 2 +- src/polkadot/info/polkadotInfo.ts | 2 +- src/ripple/rippleInfo.ts | 2 +- src/solana/solanaInfo.ts | 2 +- src/stellar/stellarInfo.ts | 2 +- src/tezos/tezosInfo.ts | 2 +- src/tron/tronInfo.ts | 2 +- src/zcash/zcashInfo.ts | 2 +- 53 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/algorand/algorandInfo.ts b/src/algorand/algorandInfo.ts index 913dbf00c..d422540a3 100644 --- a/src/algorand/algorandInfo.ts +++ b/src/algorand/algorandInfo.ts @@ -75,7 +75,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const algorand = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asAlgorandInfoPayload, + asInfoPayload: asAlgorandInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/algorand/algorandTestnetInfo.ts b/src/algorand/algorandTestnetInfo.ts index 98fc489b8..001f2b5ed 100644 --- a/src/algorand/algorandTestnetInfo.ts +++ b/src/algorand/algorandTestnetInfo.ts @@ -71,7 +71,7 @@ export const algorandtestnet = makeOuterPlugin< >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asAlgorandInfoPayload, + asInfoPayload: asAlgorandInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/binance/binanceInfo.ts b/src/binance/binanceInfo.ts index 3fdffa921..ff771e4a5 100644 --- a/src/binance/binanceInfo.ts +++ b/src/binance/binanceInfo.ts @@ -39,7 +39,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const binance = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asBinanceInfoPayload, + asInfoPayload: asBinanceInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/cardano/cardanoInfo.ts b/src/cardano/cardanoInfo.ts index 9298d17d1..d39c1d15c 100644 --- a/src/cardano/cardanoInfo.ts +++ b/src/cardano/cardanoInfo.ts @@ -31,7 +31,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const cardano = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asCardanoInfoPayload, + asInfoPayload: asCardanoInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/cardano/cardanoTestnetInfo.ts b/src/cardano/cardanoTestnetInfo.ts index 76c7f1d70..21b7b712d 100644 --- a/src/cardano/cardanoTestnetInfo.ts +++ b/src/cardano/cardanoTestnetInfo.ts @@ -32,7 +32,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const cardanotestnet = makeOuterPlugin( { currencyInfo, - infoPayloadCleaner: asCardanoInfoPayload, + asInfoPayload: asCardanoInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/common/innerPlugin.ts b/src/common/innerPlugin.ts index 834b2116a..aa0dce362 100644 --- a/src/common/innerPlugin.ts +++ b/src/common/innerPlugin.ts @@ -45,7 +45,7 @@ export interface InnerPlugin { export interface OuterPlugin { builtinTokens?: EdgeTokenMap currencyInfo: EdgeCurrencyInfo - infoPayloadCleaner: Cleaner> + asInfoPayload: Cleaner> networkInfo: NetworkInfo checkEnvironment?: () => void getInnerPlugin: () => Promise> @@ -63,7 +63,7 @@ export function makeOuterPlugin( builtinTokens = {}, currencyInfo, networkInfo: defaultNetworkInfo, - infoPayloadCleaner, + asInfoPayload, otherMethodNames = [], checkEnvironment = () => {} } = template @@ -72,7 +72,7 @@ export function makeOuterPlugin( try { networkInfo = mergeDeeply( defaultNetworkInfo, - infoPayloadCleaner(env.infoPayload) + asInfoPayload(env.infoPayload) ) } catch (e) { env.log.warn('infoPayload cleaner error:', e) diff --git a/src/cosmos/info/axelarInfo.ts b/src/cosmos/info/axelarInfo.ts index 00dd8b2db..ae32c8617 100644 --- a/src/cosmos/info/axelarInfo.ts +++ b/src/cosmos/info/axelarInfo.ts @@ -47,7 +47,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const axelar = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/coreumInfo.ts b/src/cosmos/info/coreumInfo.ts index 9a664ddc2..7df60ede6 100644 --- a/src/cosmos/info/coreumInfo.ts +++ b/src/cosmos/info/coreumInfo.ts @@ -172,7 +172,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const coreum = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/cosmoshubInfo.ts b/src/cosmos/info/cosmoshubInfo.ts index 23f4d2909..97cee2457 100644 --- a/src/cosmos/info/cosmoshubInfo.ts +++ b/src/cosmos/info/cosmoshubInfo.ts @@ -47,7 +47,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const cosmoshub = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/cosmos/info/osmosisInfo.ts b/src/cosmos/info/osmosisInfo.ts index 907f3fbdb..0732e6642 100644 --- a/src/cosmos/info/osmosisInfo.ts +++ b/src/cosmos/info/osmosisInfo.ts @@ -63,7 +63,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const osmosis = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, builtinTokens, diff --git a/src/cosmos/info/thorchainruneInfo.ts b/src/cosmos/info/thorchainruneInfo.ts index 98100511f..2997b0c3c 100644 --- a/src/cosmos/info/thorchainruneInfo.ts +++ b/src/cosmos/info/thorchainruneInfo.ts @@ -52,7 +52,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const thorchainrune = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asCosmosInfoPayload, + asInfoPayload: asCosmosInfoPayload, networkInfo, checkEnvironment() { diff --git a/src/eos/info/eosInfo.ts b/src/eos/info/eosInfo.ts index 4c0343fa0..a61076d04 100644 --- a/src/eos/info/eosInfo.ts +++ b/src/eos/info/eosInfo.ts @@ -55,7 +55,7 @@ export const eosCurrencyInfo: EdgeCurrencyInfo = { 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..dcb1f6daf 100644 --- a/src/eos/info/telosInfo.ts +++ b/src/eos/info/telosInfo.ts @@ -47,7 +47,7 @@ export const telosCurrencyInfo: EdgeCurrencyInfo = { 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..e00719097 100644 --- a/src/eos/info/waxInfo.ts +++ b/src/eos/info/waxInfo.ts @@ -43,7 +43,7 @@ export const waxCurrencyInfo: EdgeCurrencyInfo = { export const wax = makeOuterPlugin({ currencyInfo: waxCurrencyInfo, - infoPayloadCleaner: asEosInfoPayload, + asInfoPayload: asEosInfoPayload, networkInfo: waxNetworkInfo, otherMethodNames: eosOtherMethodNames, diff --git a/src/ethereum/ethereumTypes.ts b/src/ethereum/ethereumTypes.ts index 58d41972c..cf113cc27 100644 --- a/src/ethereum/ethereumTypes.ts +++ b/src/ethereum/ethereumTypes.ts @@ -103,6 +103,7 @@ const asNetworkAdaptorConfig = asObject({ servers: asArray(asString), ethBalCheckerContract: asOptional(asString) }) + export const asEthereumInfoPayload = asObject({ networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)) }) diff --git a/src/ethereum/info/arbitrumInfo.ts b/src/ethereum/info/arbitrumInfo.ts index 723c89e1d..8af8f431a 100644 --- a/src/ethereum/info/arbitrumInfo.ts +++ b/src/ethereum/info/arbitrumInfo.ts @@ -203,7 +203,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const arbitrum = makeOuterPlugin({ 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..5eb692cab 100644 --- a/src/ethereum/info/avalancheInfo.ts +++ b/src/ethereum/info/avalancheInfo.ts @@ -244,7 +244,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const avalanche = makeOuterPlugin({ 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..fe4afb0f9 100644 --- a/src/ethereum/info/baseInfo.ts +++ b/src/ethereum/info/baseInfo.ts @@ -118,7 +118,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const base = makeOuterPlugin({ 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..d6e0ab3bf 100644 --- a/src/ethereum/info/binancesmartchainInfo.ts +++ b/src/ethereum/info/binancesmartchainInfo.ts @@ -197,7 +197,7 @@ export const binancesmartchain = makeOuterPlugin< >({ 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..dbcc5866e 100644 --- a/src/ethereum/info/bobevmInfo.ts +++ b/src/ethereum/info/bobevmInfo.ts @@ -102,7 +102,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const bobevm = makeOuterPlugin({ 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..8e1af5747 100644 --- a/src/ethereum/info/celoInfo.ts +++ b/src/ethereum/info/celoInfo.ts @@ -118,7 +118,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const celo = makeOuterPlugin({ 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..f5af34e9a 100644 --- a/src/ethereum/info/ethDevInfo.ts +++ b/src/ethereum/info/ethDevInfo.ts @@ -157,7 +157,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const ethDev = makeOuterPlugin({ 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..9d26ad5ad 100644 --- a/src/ethereum/info/ethereumInfo.ts +++ b/src/ethereum/info/ethereumInfo.ts @@ -1213,7 +1213,7 @@ export const currencyInfo: EdgeCurrencyInfo = { export const ethereum = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, otherMethodNames: ethOtherMethodNames, diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 54b600a62..6fa75e71a 100644 --- a/src/ethereum/info/ethereumclassicInfo.ts +++ b/src/ethereum/info/ethereumclassicInfo.ts @@ -151,7 +151,7 @@ export const ethereumclassic = makeOuterPlugin< >({ 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..c83a8750a 100644 --- a/src/ethereum/info/ethereumpowInfo.ts +++ b/src/ethereum/info/ethereumpowInfo.ts @@ -117,7 +117,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const ethereumpow = makeOuterPlugin({ 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..d4c62c3db 100644 --- a/src/ethereum/info/fantomInfo.ts +++ b/src/ethereum/info/fantomInfo.ts @@ -344,7 +344,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const fantom = makeOuterPlugin({ 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..06abdcaa8 100644 --- a/src/ethereum/info/filecoinFevmCalibrationInfo.ts +++ b/src/ethereum/info/filecoinFevmCalibrationInfo.ts @@ -140,7 +140,7 @@ export const filecoinfevmcalibration = makeOuterPlugin< >({ 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..a54aa29bf 100644 --- a/src/ethereum/info/filecoinFevmInfo.ts +++ b/src/ethereum/info/filecoinFevmInfo.ts @@ -138,7 +138,7 @@ export const filecoinfevm = makeOuterPlugin( { builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/ethereum/info/goerliInfo.ts b/src/ethereum/info/goerliInfo.ts index 3c9ee16bc..977f6a955 100644 --- a/src/ethereum/info/goerliInfo.ts +++ b/src/ethereum/info/goerliInfo.ts @@ -167,7 +167,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const goerli = makeOuterPlugin({ 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..7586c26ec 100644 --- a/src/ethereum/info/kovanInfo.ts +++ b/src/ethereum/info/kovanInfo.ts @@ -286,7 +286,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const kovan = makeOuterPlugin({ 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..b1304c36a 100644 --- a/src/ethereum/info/mumbaiInfo.ts +++ b/src/ethereum/info/mumbaiInfo.ts @@ -236,7 +236,7 @@ export const currencyInfo: EdgeCurrencyInfo = { export const mumbai = makeOuterPlugin({ 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..bb5f78c25 100644 --- a/src/ethereum/info/optimismInfo.ts +++ b/src/ethereum/info/optimismInfo.ts @@ -231,7 +231,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const optimism = makeOuterPlugin({ 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..6536b9116 100644 --- a/src/ethereum/info/polygonInfo.ts +++ b/src/ethereum/info/polygonInfo.ts @@ -247,7 +247,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const polygon = makeOuterPlugin({ 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..678877919 100644 --- a/src/ethereum/info/pulsechainInfo.ts +++ b/src/ethereum/info/pulsechainInfo.ts @@ -118,7 +118,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const pulsechain = makeOuterPlugin({ 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..e410c6d37 100644 --- a/src/ethereum/info/rinkebyInfo.ts +++ b/src/ethereum/info/rinkebyInfo.ts @@ -139,7 +139,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const rinkeby = makeOuterPlugin({ 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..e31325ddd 100644 --- a/src/ethereum/info/ropstenInfo.ts +++ b/src/ethereum/info/ropstenInfo.ts @@ -144,7 +144,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const ropsten = makeOuterPlugin({ 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..6b277e4ae 100644 --- a/src/ethereum/info/rskInfo.ts +++ b/src/ethereum/info/rskInfo.ts @@ -103,7 +103,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const rsk = makeOuterPlugin({ 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..664e9b37d 100644 --- a/src/ethereum/info/zksyncInfo.ts +++ b/src/ethereum/info/zksyncInfo.ts @@ -139,7 +139,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const zksync = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asEthereumInfoPayload, + asInfoPayload: asEthereumInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/filecoin/calibrationInfo.ts b/src/filecoin/calibrationInfo.ts index c159267e6..1152b3e95 100644 --- a/src/filecoin/calibrationInfo.ts +++ b/src/filecoin/calibrationInfo.ts @@ -68,7 +68,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const calibration = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asFilecoinInfoPayload, + asInfoPayload: asFilecoinInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/filecoin/filecoinInfo.ts b/src/filecoin/filecoinInfo.ts index c3f463fbd..0383a97b7 100644 --- a/src/filecoin/filecoinInfo.ts +++ b/src/filecoin/filecoinInfo.ts @@ -74,7 +74,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const filecoin = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asFilecoinInfoPayload, + asInfoPayload: asFilecoinInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/fio/fioInfo.ts b/src/fio/fioInfo.ts index ab20f1b97..396d8e18e 100644 --- a/src/fio/fioInfo.ts +++ b/src/fio/fioInfo.ts @@ -80,7 +80,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const fio = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asFioInfoPayload, + asInfoPayload: asFioInfoPayload, networkInfo, otherMethodNames: fioOtherMethodNames, diff --git a/src/hedera/hederaInfo.ts b/src/hedera/hederaInfo.ts index 11336acaa..301988eb1 100644 --- a/src/hedera/hederaInfo.ts +++ b/src/hedera/hederaInfo.ts @@ -41,7 +41,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const hedera = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asHederaInfoPayload, + asInfoPayload: asHederaInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/hedera/hederaTestnetInfo.ts b/src/hedera/hederaTestnetInfo.ts index 8ffb44c8d..953f09f4c 100644 --- a/src/hedera/hederaTestnetInfo.ts +++ b/src/hedera/hederaTestnetInfo.ts @@ -38,7 +38,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const hederatestnet = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asHederaInfoPayload, + asInfoPayload: asHederaInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/piratechain/piratechainInfo.ts b/src/piratechain/piratechainInfo.ts index 31aafc048..bb9a1f603 100644 --- a/src/piratechain/piratechainInfo.ts +++ b/src/piratechain/piratechainInfo.ts @@ -49,7 +49,7 @@ export const piratechain = makeOuterPlugin< PiratechainTools >({ currencyInfo, - infoPayloadCleaner: asPiratechainInfoPayload, + asInfoPayload: asPiratechainInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/polkadot/info/liberlandInfo.ts b/src/polkadot/info/liberlandInfo.ts index 88b9dc541..8e6a8814c 100644 --- a/src/polkadot/info/liberlandInfo.ts +++ b/src/polkadot/info/liberlandInfo.ts @@ -54,7 +54,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const liberland = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/polkadot/info/liberlandTestnetInfo.ts b/src/polkadot/info/liberlandTestnetInfo.ts index 5db714b03..72a675359 100644 --- a/src/polkadot/info/liberlandTestnetInfo.ts +++ b/src/polkadot/info/liberlandTestnetInfo.ts @@ -54,7 +54,7 @@ export const liberlandtestnet = makeOuterPlugin< >({ builtinTokens, currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/polkadot/info/polkadotInfo.ts b/src/polkadot/info/polkadotInfo.ts index 539329c29..5bc14b68d 100644 --- a/src/polkadot/info/polkadotInfo.ts +++ b/src/polkadot/info/polkadotInfo.ts @@ -37,7 +37,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const polkadot = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asPolkadotInfoPayload, + asInfoPayload: asPolkadotInfoPayload, networkInfo, checkEnvironment: () => { diff --git a/src/ripple/rippleInfo.ts b/src/ripple/rippleInfo.ts index 3af34e637..9587a4f4b 100644 --- a/src/ripple/rippleInfo.ts +++ b/src/ripple/rippleInfo.ts @@ -117,7 +117,7 @@ export const builtinTokens: EdgeTokenMap = { export const ripple = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asXrpInfoPayload, + asInfoPayload: asXrpInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/solana/solanaInfo.ts b/src/solana/solanaInfo.ts index 6383d63a3..25b02cf20 100644 --- a/src/solana/solanaInfo.ts +++ b/src/solana/solanaInfo.ts @@ -131,7 +131,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const solana = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asSolanaInfoPayload, + asInfoPayload: asSolanaInfoPayload, networkInfo, builtinTokens, diff --git a/src/stellar/stellarInfo.ts b/src/stellar/stellarInfo.ts index 0c7e24604..00e575aaa 100644 --- a/src/stellar/stellarInfo.ts +++ b/src/stellar/stellarInfo.ts @@ -39,7 +39,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const stellar = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asStellarInfoPayload, + asInfoPayload: asStellarInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/tezos/tezosInfo.ts b/src/tezos/tezosInfo.ts index 3a4074085..791502d1a 100644 --- a/src/tezos/tezosInfo.ts +++ b/src/tezos/tezosInfo.ts @@ -63,7 +63,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const tezos = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asTezosInfoPayload, + asInfoPayload: asTezosInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/tron/tronInfo.ts b/src/tron/tronInfo.ts index 834b7dd03..2a0bcb243 100644 --- a/src/tron/tronInfo.ts +++ b/src/tron/tronInfo.ts @@ -147,7 +147,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const tron = makeOuterPlugin({ builtinTokens, currencyInfo, - infoPayloadCleaner: asTronInfoPayload, + asInfoPayload: asTronInfoPayload, networkInfo, async getInnerPlugin() { diff --git a/src/zcash/zcashInfo.ts b/src/zcash/zcashInfo.ts index ed938b846..83678deef 100644 --- a/src/zcash/zcashInfo.ts +++ b/src/zcash/zcashInfo.ts @@ -41,7 +41,7 @@ const currencyInfo: EdgeCurrencyInfo = { export const zcash = makeOuterPlugin({ currencyInfo, - infoPayloadCleaner: asZcashInfoPayload, + asInfoPayload: asZcashInfoPayload, networkInfo, async getInnerPlugin() { From 0ab18b15423615ec86fcba0bfc9be6ee641e69a0 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 3 Jul 2024 15:56:02 -0700 Subject: [PATCH 2/6] Rename EthereumNetworkInfo defaultNetworkFee to `networkFees` --- src/ethereum/EthereumEngine.ts | 8 +++----- src/ethereum/ethereumTypes.ts | 3 +-- src/ethereum/fees/ethMiningFees.ts | 4 ++-- src/ethereum/info/arbitrumInfo.ts | 4 ++-- src/ethereum/info/avalancheInfo.ts | 4 ++-- src/ethereum/info/baseInfo.ts | 4 ++-- src/ethereum/info/binancesmartchainInfo.ts | 4 ++-- src/ethereum/info/bobevmInfo.ts | 4 ++-- src/ethereum/info/celoInfo.ts | 4 ++-- src/ethereum/info/ethDevInfo.ts | 4 ++-- src/ethereum/info/ethereumInfo.ts | 4 ++-- src/ethereum/info/ethereumclassicInfo.ts | 4 ++-- src/ethereum/info/ethereumpowInfo.ts | 4 ++-- src/ethereum/info/fantomInfo.ts | 4 ++-- src/ethereum/info/filecoinFevmCalibrationInfo.ts | 4 ++-- src/ethereum/info/filecoinFevmInfo.ts | 4 ++-- src/ethereum/info/goerliInfo.ts | 4 ++-- src/ethereum/info/kovanInfo.ts | 4 ++-- src/ethereum/info/mumbaiInfo.ts | 4 ++-- src/ethereum/info/optimismInfo.ts | 4 ++-- src/ethereum/info/polygonInfo.ts | 4 ++-- src/ethereum/info/pulsechainInfo.ts | 4 ++-- src/ethereum/info/rinkebyInfo.ts | 4 ++-- src/ethereum/info/ropstenInfo.ts | 4 ++-- src/ethereum/info/rskInfo.ts | 4 ++-- src/ethereum/info/zksyncInfo.ts | 4 ++-- 26 files changed, 52 insertions(+), 55 deletions(-) diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 8fdd61395..8f8021252 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -124,7 +124,7 @@ export class EthereumEngine extends CurrencyEngine< blobBaseFeeScalar: '659851' } } - this.networkFees = this.networkInfo.defaultNetworkFees + this.networkFees = this.networkInfo.networkFees this.fetchCors = getFetchCors(env.io) // Update network fees from other providers @@ -430,8 +430,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 @@ -673,8 +672,7 @@ export class EthereumEngine extends CurrencyEngine< return } - const defaultNetworkFee: EthereumFee = - this.networkInfo.defaultNetworkFees.default + const defaultNetworkFee: EthereumFee = this.networkInfo.networkFees.default // The minimum priority fee for slow transactions const minPriorityFee = diff --git a/src/ethereum/ethereumTypes.ts b/src/ethereum/ethereumTypes.ts index cf113cc27..db89adc1b 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[] diff --git a/src/ethereum/fees/ethMiningFees.ts b/src/ethereum/fees/ethMiningFees.ts index d9392ddfc..d2fc41284 100644 --- a/src/ethereum/fees/ethMiningFees.ts +++ b/src/ethereum/fees/ethMiningFees.ts @@ -57,7 +57,7 @@ export function calcMiningFees( if (gasPrice != null && gasPrice !== '') { const minGasPrice = networkFees.default?.gasPrice?.minGasPrice ?? - networkInfo.defaultNetworkFees.default.gasPrice?.minGasPrice + networkInfo.networkFees.default.gasPrice?.minGasPrice if (minGasPrice != null) { const gasPriceInWei = mul(gasPrice, WEI_MULTIPLIER) if (lt(gasPriceInWei, minGasPrice) || /^\s*$/.test(gasPrice)) { @@ -75,7 +75,7 @@ export function calcMiningFees( if (gasLimit != null && gasLimit !== '') { const minGasLimit = networkFees.default?.gasLimit?.minGasLimit ?? - networkInfo.defaultNetworkFees.default.gasLimit?.minGasLimit + networkInfo.networkFees.default.gasLimit?.minGasLimit if ( (minGasLimit != null && lt(gasLimit, minGasLimit)) || /^\s*$/.test(gasLimit) diff --git a/src/ethereum/info/arbitrumInfo.ts b/src/ethereum/info/arbitrumInfo.ts index 8af8f431a..ba547e85b 100644 --- a/src/ethereum/info/arbitrumInfo.ts +++ b/src/ethereum/info/arbitrumInfo.ts @@ -106,7 +106,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -170,7 +170,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'arbitrumMnemonic', pluginRegularKeyName: 'arbitrumKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/avalancheInfo.ts b/src/ethereum/info/avalancheInfo.ts index 5eb692cab..b6a401966 100644 --- a/src/ethereum/info/avalancheInfo.ts +++ b/src/ethereum/info/avalancheInfo.ts @@ -155,7 +155,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -211,7 +211,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'avalancheMnemonic', pluginRegularKeyName: 'avalancheKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/baseInfo.ts b/src/ethereum/info/baseInfo.ts index fe4afb0f9..be82f8345 100644 --- a/src/ethereum/info/baseInfo.ts +++ b/src/ethereum/info/baseInfo.ts @@ -27,7 +27,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -85,7 +85,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'baseMnemonic', pluginRegularKeyName: 'baseKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/binancesmartchainInfo.ts b/src/ethereum/info/binancesmartchainInfo.ts index d6e0ab3bf..462ccf828 100644 --- a/src/ethereum/info/binancesmartchainInfo.ts +++ b/src/ethereum/info/binancesmartchainInfo.ts @@ -114,7 +114,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -161,7 +161,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'binancesmartchainMnemonic', pluginRegularKeyName: 'binancesmartchainKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/bobevmInfo.ts b/src/ethereum/info/bobevmInfo.ts index dbcc5866e..5afa34b8e 100644 --- a/src/ethereum/info/bobevmInfo.ts +++ b/src/ethereum/info/bobevmInfo.ts @@ -18,7 +18,7 @@ import { const builtinTokens: EdgeTokenMap = {} // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -69,7 +69,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'bobevmMnemonic', pluginRegularKeyName: 'bobevmKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/celoInfo.ts b/src/ethereum/info/celoInfo.ts index 8e1af5747..a21e44a2a 100644 --- a/src/ethereum/info/celoInfo.ts +++ b/src/ethereum/info/celoInfo.ts @@ -35,7 +35,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -85,7 +85,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'celoMnemonic', pluginRegularKeyName: 'celoKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/ethDevInfo.ts b/src/ethereum/info/ethDevInfo.ts index f5af34e9a..d415a4432 100644 --- a/src/ethereum/info/ethDevInfo.ts +++ b/src/ethereum/info/ethDevInfo.ts @@ -42,7 +42,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -119,7 +119,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethDevMnemonic', pluginRegularKeyName: 'ethDevKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/ethereumInfo.ts b/src/ethereum/info/ethereumInfo.ts index 9d26ad5ad..afa63b73a 100644 --- a/src/ethereum/info/ethereumInfo.ts +++ b/src/ethereum/info/ethereumInfo.ts @@ -1063,7 +1063,7 @@ export const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -1175,7 +1175,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumMnemonic', pluginRegularKeyName: 'ethereumKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } export const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 6fa75e71a..316b9e699 100644 --- a/src/ethereum/info/ethereumclassicInfo.ts +++ b/src/ethereum/info/ethereumclassicInfo.ts @@ -26,7 +26,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -110,7 +110,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumclassicMnemonic', pluginRegularKeyName: 'ethereumclassicKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/ethereumpowInfo.ts b/src/ethereum/info/ethereumpowInfo.ts index c83a8750a..09dad208b 100644 --- a/src/ethereum/info/ethereumpowInfo.ts +++ b/src/ethereum/info/ethereumpowInfo.ts @@ -26,7 +26,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -79,7 +79,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ethereumpowMnemonic', pluginRegularKeyName: 'ethereumpowKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/fantomInfo.ts b/src/ethereum/info/fantomInfo.ts index d4c62c3db..91028043c 100644 --- a/src/ethereum/info/fantomInfo.ts +++ b/src/ethereum/info/fantomInfo.ts @@ -258,7 +258,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -311,7 +311,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'fantomMnemonic', pluginRegularKeyName: 'fantomKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/filecoinFevmCalibrationInfo.ts b/src/ethereum/info/filecoinFevmCalibrationInfo.ts index 06abdcaa8..4a94f7c24 100644 --- a/src/ethereum/info/filecoinFevmCalibrationInfo.ts +++ b/src/ethereum/info/filecoinFevmCalibrationInfo.ts @@ -29,7 +29,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -75,7 +75,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'filecoinfevmcalibrationMnemonic', pluginRegularKeyName: 'filecoinfevmcalibrationKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/filecoinFevmInfo.ts b/src/ethereum/info/filecoinFevmInfo.ts index a54aa29bf..5381a4e8b 100644 --- a/src/ethereum/info/filecoinFevmInfo.ts +++ b/src/ethereum/info/filecoinFevmInfo.ts @@ -29,7 +29,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -75,7 +75,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'filecoinfevmMnemonic', pluginRegularKeyName: 'filecoinfevmKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/goerliInfo.ts b/src/ethereum/info/goerliInfo.ts index 977f6a955..6571135c7 100644 --- a/src/ethereum/info/goerliInfo.ts +++ b/src/ethereum/info/goerliInfo.ts @@ -43,7 +43,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -129,7 +129,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'goerliMnemonic', pluginRegularKeyName: 'goerliKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/kovanInfo.ts b/src/ethereum/info/kovanInfo.ts index 7586c26ec..1aca5aa18 100644 --- a/src/ethereum/info/kovanInfo.ts +++ b/src/ethereum/info/kovanInfo.ts @@ -163,7 +163,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -248,7 +248,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'kovanMnemonic', pluginRegularKeyName: 'kovanKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/mumbaiInfo.ts b/src/ethereum/info/mumbaiInfo.ts index b1304c36a..9744bc257 100644 --- a/src/ethereum/info/mumbaiInfo.ts +++ b/src/ethereum/info/mumbaiInfo.ts @@ -149,7 +149,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -198,7 +198,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'mumbaiMnemonic', pluginRegularKeyName: 'mumbaiKey', ethGasStationUrl: '', - defaultNetworkFees + networkFees } export const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/optimismInfo.ts b/src/ethereum/info/optimismInfo.ts index bb5f78c25..74713d045 100644 --- a/src/ethereum/info/optimismInfo.ts +++ b/src/ethereum/info/optimismInfo.ts @@ -147,7 +147,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -198,7 +198,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'optimismMnemonic', pluginRegularKeyName: 'optimismKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/polygonInfo.ts b/src/ethereum/info/polygonInfo.ts index 6536b9116..d4940603d 100644 --- a/src/ethereum/info/polygonInfo.ts +++ b/src/ethereum/info/polygonInfo.ts @@ -155,7 +155,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -209,7 +209,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'polygonMnemonic', pluginRegularKeyName: 'polygonKey', ethGasStationUrl: 'https://gasstation-mainnet.matic.network/', - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/pulsechainInfo.ts b/src/ethereum/info/pulsechainInfo.ts index 678877919..4cc7633b4 100644 --- a/src/ethereum/info/pulsechainInfo.ts +++ b/src/ethereum/info/pulsechainInfo.ts @@ -26,7 +26,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -80,7 +80,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'pulsechainMnemonic', pluginRegularKeyName: 'pulsechainKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/rinkebyInfo.ts b/src/ethereum/info/rinkebyInfo.ts index e410c6d37..eafca12a7 100644 --- a/src/ethereum/info/rinkebyInfo.ts +++ b/src/ethereum/info/rinkebyInfo.ts @@ -17,7 +17,7 @@ import { const builtinTokens: EdgeTokenMap = {} -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -101,7 +101,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'rinkebyMnemonic', pluginRegularKeyName: 'rinkebyKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/ropstenInfo.ts b/src/ethereum/info/ropstenInfo.ts index e31325ddd..26feb7a06 100644 --- a/src/ethereum/info/ropstenInfo.ts +++ b/src/ethereum/info/ropstenInfo.ts @@ -17,7 +17,7 @@ import { const builtinTokens: EdgeTokenMap = {} -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -106,7 +106,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'ropstenMnemonic', pluginRegularKeyName: 'ropstenKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/rskInfo.ts b/src/ethereum/info/rskInfo.ts index 6b277e4ae..db3d6bbc4 100644 --- a/src/ethereum/info/rskInfo.ts +++ b/src/ethereum/info/rskInfo.ts @@ -26,7 +26,7 @@ const builtinTokens: EdgeTokenMap = { } } -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: undefined, @@ -70,7 +70,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'rskMnemonic', pluginRegularKeyName: 'rskKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { diff --git a/src/ethereum/info/zksyncInfo.ts b/src/ethereum/info/zksyncInfo.ts index 664e9b37d..4f0cd8ba4 100644 --- a/src/ethereum/info/zksyncInfo.ts +++ b/src/ethereum/info/zksyncInfo.ts @@ -50,7 +50,7 @@ const builtinTokens: EdgeTokenMap = { } // Fees are in Wei -const defaultNetworkFees: EthereumFees = { +const networkFees: EthereumFees = { default: { baseFee: undefined, baseFeeMultiplier: { @@ -99,7 +99,7 @@ const networkInfo: EthereumNetworkInfo = { pluginMnemonicKeyName: 'zksyncMnemonic', pluginRegularKeyName: 'zksyncKey', ethGasStationUrl: null, - defaultNetworkFees + networkFees } const currencyInfo: EdgeCurrencyInfo = { From bf155ad74c9e3d27f6104f25860380f31e9475b7 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 3 Jul 2024 16:21:35 -0700 Subject: [PATCH 3/6] Use networkFees from networkInfo in EthereumEngine --- src/ethereum/EthereumEngine.ts | 40 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index 8f8021252..c6a576351 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.networkFees 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 @@ -483,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 @@ -517,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 } } @@ -538,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)}`) } @@ -665,7 +668,7 @@ 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) { @@ -729,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,7 +811,7 @@ export class EthereumEngine extends CurrencyEngine< // Use our calcMiningFee function to calculate the fees: const miningFees = calcMiningFees( spendInfo, - this.networkFees, + this.networkInfo.networkFees, null, this.networkInfo ) @@ -986,7 +992,7 @@ export class EthereumEngine extends CurrencyEngine< const edgeToken = tokenId != null ? this.builtinTokens[tokenId] : null const miningFees = calcMiningFees( edgeSpendInfo, - this.networkFees, + this.networkInfo.networkFees, edgeToken, this.networkInfo ) @@ -997,7 +1003,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()) ) @@ -1399,7 +1405,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 From 42a32de72c50d6772a9ad3d03098b1e43c2b601e Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 3 Jul 2024 16:24:01 -0700 Subject: [PATCH 4/6] Remove unnecessary networkFees parameter in calcMiningFees --- src/ethereum/EthereumEngine.ts | 12 +++--------- src/ethereum/fees/ethMiningFees.ts | 22 ++++++++-------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/ethereum/EthereumEngine.ts b/src/ethereum/EthereumEngine.ts index c6a576351..201b9b666 100644 --- a/src/ethereum/EthereumEngine.ts +++ b/src/ethereum/EthereumEngine.ts @@ -809,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.networkInfo.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: @@ -991,10 +986,9 @@ export class EthereumEngine extends CurrencyEngine< const edgeToken = tokenId != null ? this.builtinTokens[tokenId] : null const miningFees = calcMiningFees( + this.networkInfo, edgeSpendInfo, - this.networkInfo.networkFees, - edgeToken, - this.networkInfo + edgeToken ) // Translate legacy transaction types to EIP-1559 transaction type diff --git a/src/ethereum/fees/ethMiningFees.ts b/src/ethereum/fees/ethMiningFees.ts index d2fc41284..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.networkFees.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.networkFees.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 From fb532fb1470260a9036dd13364674a30cdc63383 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Tue, 9 Jul 2024 09:57:20 -0700 Subject: [PATCH 5/6] Add updateInfoPayload implementation to --- CHANGELOG.md | 2 + src/algorand/AlgorandTools.ts | 14 ++- src/algorand/algorandInfo.ts | 12 ++- src/algorand/algorandTestnetInfo.ts | 9 +- src/algorand/algorandTypes.ts | 15 ++-- src/binance/BinanceTools.ts | 14 ++- src/binance/binanceInfo.ts | 12 ++- src/binance/binanceTypes.ts | 15 ++-- src/cardano/CardanoTools.ts | 14 ++- src/cardano/cardanoInfo.ts | 12 ++- src/cardano/cardanoTestnetInfo.ts | 38 ++++---- src/cardano/cardanoTypes.ts | 17 ++-- src/common/innerPlugin.ts | 89 +++++++++++++------ src/cosmos/CosmosTools.ts | 14 ++- src/cosmos/cosmosTypes.ts | 14 ++- src/cosmos/info/axelarInfo.ts | 12 ++- src/cosmos/info/coreumInfo.ts | 12 ++- src/cosmos/info/cosmoshubInfo.ts | 12 ++- src/cosmos/info/osmosisInfo.ts | 12 ++- src/cosmos/info/thorchainruneInfo.ts | 12 ++- src/eos/EosTools.ts | 15 +++- src/eos/eosTypes.ts | 19 ++-- src/eos/info/eosInfo.ts | 3 +- src/eos/info/telosInfo.ts | 3 +- src/eos/info/waxInfo.ts | 3 +- src/ethereum/EthereumTools.ts | 17 +++- src/ethereum/ethereumTypes.ts | 13 ++- src/ethereum/info/arbitrumInfo.ts | 7 +- src/ethereum/info/avalancheInfo.ts | 7 +- src/ethereum/info/baseInfo.ts | 7 +- src/ethereum/info/binancesmartchainInfo.ts | 4 +- src/ethereum/info/bobevmInfo.ts | 7 +- src/ethereum/info/celoInfo.ts | 7 +- src/ethereum/info/ethDevInfo.ts | 7 +- src/ethereum/info/ethereumInfo.ts | 9 +- src/ethereum/info/ethereumclassicInfo.ts | 4 +- src/ethereum/info/ethereumpowInfo.ts | 7 +- src/ethereum/info/fantomInfo.ts | 7 +- .../info/filecoinFevmCalibrationInfo.ts | 4 +- src/ethereum/info/filecoinFevmInfo.ts | 23 ++--- src/ethereum/info/goerliInfo.ts | 7 +- src/ethereum/info/kovanInfo.ts | 7 +- src/ethereum/info/mumbaiInfo.ts | 7 +- src/ethereum/info/optimismInfo.ts | 7 +- src/ethereum/info/polygonInfo.ts | 7 +- src/ethereum/info/pulsechainInfo.ts | 7 +- src/ethereum/info/rinkebyInfo.ts | 7 +- src/ethereum/info/ropstenInfo.ts | 7 +- src/ethereum/info/rskInfo.ts | 7 +- src/ethereum/info/zksyncInfo.ts | 7 +- src/filecoin/FilecoinTools.ts | 14 ++- src/filecoin/calibrationInfo.ts | 12 ++- src/filecoin/filecoinInfo.ts | 12 ++- src/filecoin/filecoinTypes.ts | 26 +++--- src/fio/FioTools.ts | 13 +++ src/fio/fioInfo.ts | 3 +- src/fio/fioTypes.ts | 23 +++-- src/hedera/HederaTools.ts | 18 +++- src/hedera/hederaInfo.ts | 12 ++- src/hedera/hederaTestnetInfo.ts | 12 ++- src/hedera/hederaTypes.ts | 13 ++- src/piratechain/PiratechainTools.ts | 14 ++- src/piratechain/piratechainInfo.ts | 4 +- src/piratechain/piratechainTypes.ts | 25 +++--- src/polkadot/PolkadotTools.ts | 14 ++- src/polkadot/info/liberlandInfo.ts | 12 ++- src/polkadot/info/liberlandTestnetInfo.ts | 9 +- src/polkadot/info/polkadotInfo.ts | 12 ++- src/polkadot/polkadotTypes.ts | 13 ++- src/ripple/RippleTools.ts | 13 +++ src/ripple/rippleInfo.ts | 8 +- src/ripple/rippleTypes.ts | 13 ++- src/solana/SolanaTools.ts | 14 ++- src/solana/solanaInfo.ts | 12 ++- src/solana/solanaTypes.ts | 15 ++-- src/stellar/StellarTools.ts | 14 ++- src/stellar/stellarInfo.ts | 12 ++- src/stellar/stellarTypes.ts | 13 ++- src/tezos/TezosTools.ts | 13 +++ src/tezos/tezosInfo.ts | 12 ++- src/tezos/tezosTypes.ts | 15 ++-- src/tron/TronTools.ts | 14 ++- src/tron/tronInfo.ts | 12 ++- src/tron/tronTypes.ts | 15 ++-- src/zcash/ZcashTools.ts | 14 ++- src/zcash/zcashInfo.ts | 12 ++- src/zcash/zcashTypes.ts | 25 +++--- 87 files changed, 861 insertions(+), 240 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e9374ea..1826e36be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: Implemented common `updateInfoPayload` method for all plugins + ## 4.11.1 (2024-07-08) changed: Upgrade @polkadot/api to v12.1.1 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 d422540a3..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,7 +76,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const algorand = makeOuterPlugin({ +export const algorand = makeOuterPlugin< + AlgorandNetworkInfo, + AlgorandTools, + AlgorandInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asAlgorandInfoPayload, diff --git a/src/algorand/algorandTestnetInfo.ts b/src/algorand/algorandTestnetInfo.ts index 001f2b5ed..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,7 +71,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const algorandtestnet = makeOuterPlugin< AlgorandNetworkInfo, - AlgorandTools + AlgorandTools, + AlgorandInfoPayload >({ builtinTokens, currencyInfo, 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 ff771e4a5..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,7 +41,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 128 }] } -export const binance = makeOuterPlugin({ +export const binance = makeOuterPlugin< + BinanceNetworkInfo, + BinanceTools, + BinanceInfoPayload +>({ currencyInfo, asInfoPayload: asBinanceInfoPayload, networkInfo, 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 d39c1d15c..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,7 +33,11 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const cardano = makeOuterPlugin({ +export const cardano = makeOuterPlugin< + CardanoNetworkInfo, + CardanoTools, + CardanoInfoPayload +>({ currencyInfo, asInfoPayload: asCardanoInfoPayload, networkInfo, diff --git a/src/cardano/cardanoTestnetInfo.ts b/src/cardano/cardanoTestnetInfo.ts index 21b7b712d..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, - asInfoPayload: 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 aa0dce362..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,27 +39,50 @@ 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 - asInfoPayload: 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 { @@ -68,28 +94,20 @@ export function makeOuterPlugin( checkEnvironment = () => {} } = template - let networkInfo: NetworkInfo = defaultNetworkInfo - try { - networkInfo = mergeDeeply( - defaultNetworkInfo, - asInfoPayload(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 ae32c8617..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,7 +49,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const axelar = makeOuterPlugin({ +export const axelar = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, asInfoPayload: asCosmosInfoPayload, networkInfo, diff --git a/src/cosmos/info/coreumInfo.ts b/src/cosmos/info/coreumInfo.ts index 7df60ede6..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,7 +173,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const coreum = makeOuterPlugin({ +export const coreum = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asCosmosInfoPayload, diff --git a/src/cosmos/info/cosmoshubInfo.ts b/src/cosmos/info/cosmoshubInfo.ts index 97cee2457..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,7 +49,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const cosmoshub = makeOuterPlugin({ +export const cosmoshub = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, asInfoPayload: asCosmosInfoPayload, networkInfo, diff --git a/src/cosmos/info/osmosisInfo.ts b/src/cosmos/info/osmosisInfo.ts index 0732e6642..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,7 +65,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const osmosis = makeOuterPlugin({ +export const osmosis = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, asInfoPayload: asCosmosInfoPayload, networkInfo, diff --git a/src/cosmos/info/thorchainruneInfo.ts b/src/cosmos/info/thorchainruneInfo.ts index 2997b0c3c..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,7 +54,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 250 }] } -export const thorchainrune = makeOuterPlugin({ +export const thorchainrune = makeOuterPlugin< + CosmosNetworkInfo, + CosmosTools, + CosmosInfoPayload +>({ currencyInfo, asInfoPayload: asCosmosInfoPayload, networkInfo, 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 a61076d04..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,7 +54,7 @@ export const eosCurrencyInfo: EdgeCurrencyInfo = { ] } -export const eos = makeOuterPlugin({ +export const eos = makeOuterPlugin({ currencyInfo: eosCurrencyInfo, asInfoPayload: asEosInfoPayload, networkInfo: eosNetworkInfo, diff --git a/src/eos/info/telosInfo.ts b/src/eos/info/telosInfo.ts index dcb1f6daf..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,7 +46,7 @@ export const telosCurrencyInfo: EdgeCurrencyInfo = { ] } -export const telos = makeOuterPlugin({ +export const telos = makeOuterPlugin({ currencyInfo: telosCurrencyInfo, asInfoPayload: asEosInfoPayload, networkInfo: telosNetworkInfo, diff --git a/src/eos/info/waxInfo.ts b/src/eos/info/waxInfo.ts index e00719097..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,7 +42,7 @@ export const waxCurrencyInfo: EdgeCurrencyInfo = { ] } -export const wax = makeOuterPlugin({ +export const wax = makeOuterPlugin({ currencyInfo: waxCurrencyInfo, asInfoPayload: asEosInfoPayload, networkInfo: waxNetworkInfo, 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 db89adc1b..fbf14c741 100644 --- a/src/ethereum/ethereumTypes.ts +++ b/src/ethereum/ethereumTypes.ts @@ -103,10 +103,6 @@ const asNetworkAdaptorConfig = asObject({ ethBalCheckerContract: asOptional(asString) }) -export const asEthereumInfoPayload = asObject({ - networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)) -}) - /** * Other Methods from EthereumTools */ @@ -539,3 +535,12 @@ export const asMaybeEvmOverrideGasLimitLocation = asMaybe( overrideGasLimit: asIntegerString }) ) + +// +// Info Payload +// + +export const asEthereumInfoPayload = asObject({ + networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)) +}) +export type EthereumInfoPayload = ReturnType diff --git a/src/ethereum/info/arbitrumInfo.ts b/src/ethereum/info/arbitrumInfo.ts index ba547e85b..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 { @@ -200,7 +201,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const arbitrum = makeOuterPlugin({ +export const arbitrum = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/avalancheInfo.ts b/src/ethereum/info/avalancheInfo.ts index b6a401966..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 { @@ -241,7 +242,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const avalanche = makeOuterPlugin({ +export const avalanche = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/baseInfo.ts b/src/ethereum/info/baseInfo.ts index be82f8345..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 { @@ -115,7 +116,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const base = makeOuterPlugin({ +export const base = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/binancesmartchainInfo.ts b/src/ethereum/info/binancesmartchainInfo.ts index 462ccf828..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 { @@ -193,7 +194,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const binancesmartchain = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, diff --git a/src/ethereum/info/bobevmInfo.ts b/src/ethereum/info/bobevmInfo.ts index 5afa34b8e..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 { @@ -99,7 +100,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const bobevm = makeOuterPlugin({ +export const bobevm = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/celoInfo.ts b/src/ethereum/info/celoInfo.ts index a21e44a2a..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 { @@ -115,7 +116,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const celo = makeOuterPlugin({ +export const celo = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/ethDevInfo.ts b/src/ethereum/info/ethDevInfo.ts index d415a4432..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 { @@ -154,7 +155,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ethDev = makeOuterPlugin({ +export const ethDev = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/ethereumInfo.ts b/src/ethereum/info/ethereumInfo.ts index afa63b73a..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' @@ -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, - asInfoPayload: asEthereumInfoPayload, networkInfo, otherMethodNames: ethOtherMethodNames, diff --git a/src/ethereum/info/ethereumclassicInfo.ts b/src/ethereum/info/ethereumclassicInfo.ts index 316b9e699..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 { @@ -147,7 +148,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const ethereumclassic = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, diff --git a/src/ethereum/info/ethereumpowInfo.ts b/src/ethereum/info/ethereumpowInfo.ts index 09dad208b..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 { @@ -114,7 +115,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ethereumpow = makeOuterPlugin({ +export const ethereumpow = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/fantomInfo.ts b/src/ethereum/info/fantomInfo.ts index 91028043c..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 { @@ -341,7 +342,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const fantom = makeOuterPlugin({ +export const fantom = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/filecoinFevmCalibrationInfo.ts b/src/ethereum/info/filecoinFevmCalibrationInfo.ts index 4a94f7c24..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' @@ -136,7 +137,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const filecoinfevmcalibration = makeOuterPlugin< EthereumNetworkInfo, - EthereumTools + EthereumTools, + EthereumInfoPayload >({ builtinTokens, currencyInfo, diff --git a/src/ethereum/info/filecoinFevmInfo.ts b/src/ethereum/info/filecoinFevmInfo.ts index 5381a4e8b..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' @@ -134,15 +135,17 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const filecoinfevm = makeOuterPlugin( - { - builtinTokens, - currencyInfo, - asInfoPayload: 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 6571135c7..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 { @@ -164,7 +165,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const goerli = makeOuterPlugin({ +export const goerli = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/kovanInfo.ts b/src/ethereum/info/kovanInfo.ts index 1aca5aa18..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 { @@ -283,7 +284,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const kovan = makeOuterPlugin({ +export const kovan = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/mumbaiInfo.ts b/src/ethereum/info/mumbaiInfo.ts index 9744bc257..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 { @@ -233,7 +234,11 @@ export const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const mumbai = makeOuterPlugin({ +export const mumbai = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/optimismInfo.ts b/src/ethereum/info/optimismInfo.ts index 74713d045..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 { @@ -228,7 +229,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const optimism = makeOuterPlugin({ +export const optimism = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/polygonInfo.ts b/src/ethereum/info/polygonInfo.ts index d4940603d..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 { @@ -244,7 +245,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const polygon = makeOuterPlugin({ +export const polygon = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/pulsechainInfo.ts b/src/ethereum/info/pulsechainInfo.ts index 4cc7633b4..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 { @@ -115,7 +116,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const pulsechain = makeOuterPlugin({ +export const pulsechain = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/rinkebyInfo.ts b/src/ethereum/info/rinkebyInfo.ts index eafca12a7..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 { @@ -136,7 +137,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const rinkeby = makeOuterPlugin({ +export const rinkeby = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/ropstenInfo.ts b/src/ethereum/info/ropstenInfo.ts index 26feb7a06..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 { @@ -141,7 +142,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const ropsten = makeOuterPlugin({ +export const ropsten = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/rskInfo.ts b/src/ethereum/info/rskInfo.ts index db3d6bbc4..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 { @@ -100,7 +101,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const rsk = makeOuterPlugin({ +export const rsk = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, diff --git a/src/ethereum/info/zksyncInfo.ts b/src/ethereum/info/zksyncInfo.ts index 4f0cd8ba4..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 { @@ -136,7 +137,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const zksync = makeOuterPlugin({ +export const zksync = makeOuterPlugin< + EthereumNetworkInfo, + EthereumTools, + EthereumInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asEthereumInfoPayload, 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 1152b3e95..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,7 +70,11 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const calibration = makeOuterPlugin({ +export const calibration = makeOuterPlugin< + FilecoinNetworkInfo, + FilecoinTools, + FilecoinInfoPayload +>({ currencyInfo, asInfoPayload: asFilecoinInfoPayload, networkInfo, diff --git a/src/filecoin/filecoinInfo.ts b/src/filecoin/filecoinInfo.ts index 0383a97b7..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,7 +76,11 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const filecoin = makeOuterPlugin({ +export const filecoin = makeOuterPlugin< + FilecoinNetworkInfo, + FilecoinTools, + FilecoinInfoPayload +>({ currencyInfo, asInfoPayload: asFilecoinInfoPayload, networkInfo, 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 396d8e18e..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,7 +79,7 @@ const currencyInfo: EdgeCurrencyInfo = { } } -export const fio = makeOuterPlugin({ +export const fio = makeOuterPlugin({ currencyInfo, asInfoPayload: asFioInfoPayload, networkInfo, 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 301988eb1..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,7 +43,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', memoName: 'memo', maxLength: 100 }] } -export const hedera = makeOuterPlugin({ +export const hedera = makeOuterPlugin< + HederaNetworkInfo, + HederaTools, + HederaInfoPayload +>({ currencyInfo, asInfoPayload: asHederaInfoPayload, networkInfo, diff --git a/src/hedera/hederaTestnetInfo.ts b/src/hedera/hederaTestnetInfo.ts index 953f09f4c..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,7 +40,11 @@ const currencyInfo: EdgeCurrencyInfo = { ] } -export const hederatestnet = makeOuterPlugin({ +export const hederatestnet = makeOuterPlugin< + HederaNetworkInfo, + HederaTools, + HederaInfoPayload +>({ currencyInfo, asInfoPayload: asHederaInfoPayload, networkInfo, 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 bb9a1f603..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,7 +47,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const piratechain = makeOuterPlugin< PiratechainNetworkInfo, - PiratechainTools + PiratechainTools, + PiratechainInfoPayload >({ currencyInfo, asInfoPayload: asPiratechainInfoPayload, 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 8e6a8814c..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,7 +55,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const liberland = makeOuterPlugin({ +export const liberland = makeOuterPlugin< + PolkadotNetworkInfo, + PolkadotTools, + PolkadotInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asPolkadotInfoPayload, diff --git a/src/polkadot/info/liberlandTestnetInfo.ts b/src/polkadot/info/liberlandTestnetInfo.ts index 72a675359..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,7 +54,8 @@ const currencyInfo: EdgeCurrencyInfo = { export const liberlandtestnet = makeOuterPlugin< PolkadotNetworkInfo, - PolkadotTools + PolkadotTools, + PolkadotInfoPayload >({ builtinTokens, currencyInfo, diff --git a/src/polkadot/info/polkadotInfo.ts b/src/polkadot/info/polkadotInfo.ts index 5bc14b68d..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,7 +39,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [] } -export const polkadot = makeOuterPlugin({ +export const polkadot = makeOuterPlugin< + PolkadotNetworkInfo, + PolkadotTools, + PolkadotInfoPayload +>({ currencyInfo, asInfoPayload: asPolkadotInfoPayload, networkInfo, 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 9587a4f4b..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,7 +114,11 @@ export const builtinTokens: EdgeTokenMap = { } } -export const ripple = makeOuterPlugin({ +export const ripple = makeOuterPlugin< + XrpNetworkInfo, + RippleTools, + XrpInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asXrpInfoPayload, 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 25b02cf20..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,7 +133,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const solana = makeOuterPlugin({ +export const solana = makeOuterPlugin< + SolanaNetworkInfo, + SolanaTools, + SolanaInfoPayload +>({ currencyInfo, asInfoPayload: asSolanaInfoPayload, networkInfo, 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 00e575aaa..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,7 +41,11 @@ const currencyInfo: EdgeCurrencyInfo = { multipleMemos: true } -export const stellar = makeOuterPlugin({ +export const stellar = makeOuterPlugin< + StellarNetworkInfo, + StellarTools, + StellarInfoPayload +>({ currencyInfo, asInfoPayload: asStellarInfoPayload, networkInfo, 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 791502d1a..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,7 +65,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [] } -export const tezos = makeOuterPlugin({ +export const tezos = makeOuterPlugin< + TezosNetworkInfo, + TezosTools, + TezosInfoPayload +>({ currencyInfo, asInfoPayload: asTezosInfoPayload, networkInfo, 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 2a0bcb243..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,7 +148,11 @@ const currencyInfo: EdgeCurrencyInfo = { metaTokens: makeMetaTokens(builtinTokens) } -export const tron = makeOuterPlugin({ +export const tron = makeOuterPlugin< + TronNetworkInfo, + TronTools, + TronInfoPayload +>({ builtinTokens, currencyInfo, asInfoPayload: asTronInfoPayload, 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 83678deef..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,7 +43,11 @@ const currencyInfo: EdgeCurrencyInfo = { memoOptions: [{ type: 'text', maxLength: 512 }] } -export const zcash = makeOuterPlugin({ +export const zcash = makeOuterPlugin< + ZcashNetworkInfo, + ZcashTools, + ZcashInfoPayload +>({ currencyInfo, asInfoPayload: asZcashInfoPayload, networkInfo, 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 From 70e0c1aa4905161d92a0f8f9feb5c9715f579006 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Fri, 5 Jul 2024 11:06:48 -0700 Subject: [PATCH 6/6] Add networkFees to asEthereumInfoPayload cleaner --- CHANGELOG.md | 3 ++- src/ethereum/ethereumTypes.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1826e36be..f43c359f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 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) @@ -22,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/ethereum/ethereumTypes.ts b/src/ethereum/ethereumTypes.ts index fbf14c741..d0691400b 100644 --- a/src/ethereum/ethereumTypes.ts +++ b/src/ethereum/ethereumTypes.ts @@ -541,6 +541,7 @@ export const asMaybeEvmOverrideGasLimitLocation = asMaybe( // export const asEthereumInfoPayload = asObject({ - networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)) + networkAdapterConfigs: asOptional(asArray(asNetworkAdaptorConfig)), + networkFees: asOptional(asEthereumFees) }) export type EthereumInfoPayload = ReturnType