From 02cd442f2706dc80f1a504e53ed3e2c5a30d817b Mon Sep 17 00:00:00 2001 From: Mauro Piazza Date: Tue, 2 Apr 2024 19:03:09 +0200 Subject: [PATCH 1/5] chore(get-router-state): stringify final json for output processings --- lib/get-router-state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/get-router-state.js b/lib/get-router-state.js index 2910e23..10d7d65 100644 --- a/lib/get-router-state.js +++ b/lib/get-router-state.js @@ -462,12 +462,12 @@ const getRouterState = _routerAddress => .then(getSafeVaultContractOwnerAndAddToState) .then(getSafeVaultContractStateAndAddToState) .then(prepareOutputAndPutInState) - .then(_state => console.dir(_state[OUTPUT_STATE_KEY], { depth: null })) + .then(_state => console.log(JSON.stringify(_state[OUTPUT_STATE_KEY]))) .catch(console.warn) const getSupportedTokens = _routerAddress => getSupportedTokensList(_routerAddress) - .then(_state => console.dir(_state[TOKEN_INFOS_STATE_KEY], { depth: null })) + .then(_state => console.dir(JSON.stringify(_state[TOKEN_INFOS_STATE_KEY], { depth: null }))) .catch(console.warn) module.exports = { From 69402c8607156b21cb11df81f8d678a4aeb89e63 Mon Sep 17 00:00:00 2001 From: Mauro Piazza Date: Wed, 3 Apr 2024 13:50:44 +0200 Subject: [PATCH 2/5] chore(get-router-state): add `actualAmount` & `originChainId` to node operators fees info --- lib/get-router-state.js | 24 +++++++++++++++++++++++- package-lock.json | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/get-router-state.js b/lib/get-router-state.js index 10d7d65..3f0b18c 100644 --- a/lib/get-router-state.js +++ b/lib/get-router-state.js @@ -4,6 +4,8 @@ const { curry, assoc, flatten, + toPairs, + fromPairs, } = require('ramda') /* eslint-disable-next-line no-shadow */ const ethers = require('ethers') @@ -43,6 +45,7 @@ const VAULT_CONTRACTS_STATE_KEY = 'vaultContracts' const ROUTER_CONTRACT_STATE_KEY = 'routerContract' const TOKEN_ADDRESSES_STATE_KEY = 'tokenAddresses' const SAFE_VAULT_STATE_STATE_KEY = 'safeVaultState' +const ORIGIN_CHAIN_ID_STATE_KEY = 'originChainId' const SUPPORTED_TOKENS_STATE_KEY = 'supportedTokens' const GET_SUPPORTED_TOKENS_FXN = 'getSupportedTokens' const CHAIN_MULTIPLIERS_STATE_KEY = 'chainMultipliers' @@ -315,6 +318,7 @@ const getAllTokenBalances = (_tokenInfos, _tokenContracts, _address) => .divUnsafe(FixedNumber.fromString(`${1e18}`)) .round(4) } ${_tokenInfos[_i].symbol}`, + actualAmount: _balance.toString(), address: _tokenInfos[_i].address, } return assoc(_tokenInfos[_i].symbol, balanceInfo, _obj) @@ -331,12 +335,30 @@ const getSafeVaultTokenBalancesAndAddToState = _state => ) .then(_balances => assoc(SAFE_VAULT_CONTRACT_TOKEN_BALANCES_STATE_KEY, _balances, _state)) +// _keyValuePair is +// ['pNAME', { balance: '...', approxAmount: '..', address: '..'} ] +// Will get +// ['pNAME', { balance: '...', approxAmount: '..', address: '..', originChainId: '..'} ] +const attachOriginChainId = curry((_signer, _keyValuePair) => + Promise.resolve(getErc777Contract(_signer, _keyValuePair[1].address)) + .then(_contract => _contract.ORIGIN_CHAIN_ID()) + .then(_originChainId => assoc(ORIGIN_CHAIN_ID_STATE_KEY, _originChainId, _keyValuePair[1])) + .then(_newObj => [_keyValuePair[0], _newObj]) +) + +const attachOriginChainIdToEachTokenBalance = curry((_signer, _balances) => + Promise.resolve(toPairs(_balances)) + .then(_pairs => Promise.all(_pairs.map(attachOriginChainId(_signer)))) + .then(fromPairs) +) + const getNodeOperatorFeeSinkTokenBalancesAndAddToState = _state => getAllTokenBalances( _state[TOKEN_INFOS_STATE_KEY], _state[TOKEN_CONTRACTS_STATE_KEY], _state[FEE_SINK_ADDRESSES_STATE_KEY].nodeOperatorsFeeSinkAddress ) + .then(attachOriginChainIdToEachTokenBalance(_state[ROUTER_CONTRACT_STATE_KEY].signer)) .then(_balances => assoc(NODE_OPERATORS_FEE_TOKEN_BALANCES_STATE_KEY, _balances, _state)) const getNetworkFeeSinkTokenBalancesAndAddToState = _state => @@ -462,7 +484,7 @@ const getRouterState = _routerAddress => .then(getSafeVaultContractOwnerAndAddToState) .then(getSafeVaultContractStateAndAddToState) .then(prepareOutputAndPutInState) - .then(_state => console.log(JSON.stringify(_state[OUTPUT_STATE_KEY]))) + .then(_state => console.info(JSON.stringify(_state[OUTPUT_STATE_KEY]))) .catch(console.warn) const getSupportedTokens = _routerAddress => diff --git a/package-lock.json b/package-lock.json index dff63e9..9cdce00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ptokens-router-contract", - "version": "2.2.0", + "version": "2.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ptokens-router-contract", - "version": "2.2.0", + "version": "2.3.0", "license": "MIT", "dependencies": { "@nomiclabs/hardhat-etherscan": "^3.1.7", From c8a565c88f58ea2f9b479130cd314fc7849069a0 Mon Sep 17 00:00:00 2001 From: Mauro Piazza Date: Wed, 3 Apr 2024 15:22:34 +0200 Subject: [PATCH 3/5] chore(get-router-state): add human readable chain id --- lib/get-router-state.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/get-router-state.js b/lib/get-router-state.js index 3f0b18c..d8477df 100644 --- a/lib/get-router-state.js +++ b/lib/get-router-state.js @@ -6,6 +6,7 @@ const { flatten, toPairs, fromPairs, + mergeAll, } = require('ramda') /* eslint-disable-next-line no-shadow */ const ethers = require('ethers') @@ -34,6 +35,7 @@ const VAULT_DICTIONARY = 'vaultDictionary' const TOKEN_INFOS_STATE_KEY = 'tokenInfos' const FEE_CONTRACT_STATE_KEY = 'feeContract' const ORIGIN_CHAIN_ID_FXN = 'ORIGIN_CHAIN_ID' +const ORIGIN_CHAIN_STATE_KEY = 'originChain' const CHAIN_ID_NAMES = keys(metadataChainIds) const GLOBAL_MIN_FEE_STATE_KEY = 'globalMinFee' const SAFE_VAULT_ADDRESS_STATE_KEY = 'safeVault' @@ -193,9 +195,9 @@ const getTokenDetailsFromContract = (_tokenContract, _maybeAddress = null) => name: normalizeName(_name), address: _tokenContract.address, symbol: normalizeSymbol(_symbol), - originChainId: _originChainIdHex, + [ORIGIN_CHAIN_ID_STATE_KEY]: _originChainIdHex, totalSupply: _totalSupply.toString(), - originChain: getHumanReadableOriginChainIdFromHex(_originChainIdHex) + [ORIGIN_CHAIN_STATE_KEY]: getHumanReadableOriginChainIdFromHex(_originChainIdHex) } if (_maybeBalance === false) @@ -342,7 +344,10 @@ const getSafeVaultTokenBalancesAndAddToState = _state => const attachOriginChainId = curry((_signer, _keyValuePair) => Promise.resolve(getErc777Contract(_signer, _keyValuePair[1].address)) .then(_contract => _contract.ORIGIN_CHAIN_ID()) - .then(_originChainId => assoc(ORIGIN_CHAIN_ID_STATE_KEY, _originChainId, _keyValuePair[1])) + .then(_originChainId => mergeAll([_keyValuePair[1], { + [ORIGIN_CHAIN_ID_STATE_KEY]: _originChainId, + [ORIGIN_CHAIN_STATE_KEY]: getHumanReadableOriginChainIdFromHex(_originChainId), + }])) .then(_newObj => [_keyValuePair[0], _newObj]) ) From 21d28026e5b6e050915b7e4a7e914d2d4ade8fc5 Mon Sep 17 00:00:00 2001 From: Mauro Piazza Date: Wed, 3 Apr 2024 15:24:16 +0200 Subject: [PATCH 4/5] fix(hardhat.config.js): require `dotenv` --- hardhat.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/hardhat.config.js b/hardhat.config.js index 72b2853..9628047 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -12,6 +12,7 @@ require('hardhat-storage-layout') require('@nomiclabs/hardhat-waffle') require('@nomiclabs/hardhat-etherscan') require('@openzeppelin/hardhat-upgrades') +require('dotenv').config() const SUPPORTED_NETWORKS = [ 'rinkeby', From 5cd4cbc2798497aefeff53d8b4c78f45abe61755 Mon Sep 17 00:00:00 2001 From: Mauro Piazza Date: Wed, 3 Apr 2024 15:24:26 +0200 Subject: [PATCH 5/5] chore(package.json): bump minor --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83071f4..a4deb60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ptokens-router-contract", - "version": "2.3.0", + "version": "2.4.0", "description": "The pTokens interim-chain router contract & CLI", "main": "cli.js", "scripts": {