From 7525a3cee842306165de3303baaa9b843346e802 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 10:47:22 +0100 Subject: [PATCH 01/12] feat(token-contract): <- adds `balanceOf` to abi --- lib/get-token-contract.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/get-token-contract.js b/lib/get-token-contract.js index a5a30b5..fffb143 100644 --- a/lib/get-token-contract.js +++ b/lib/get-token-contract.js @@ -1,16 +1,25 @@ /* eslint-disable-next-line no-shadow */ const ethers = require('ethers') -const TOKEN_ABI = [{ - 'inputs': [ - { 'internalType': 'address', 'name': 'holder', 'type': 'address' }, - { 'internalType': 'address', 'name': 'spender', 'type': 'address' } - ], - 'name': 'allowance', - 'outputs': [ { 'internalType': 'uint256', 'name': '', 'type': 'uint256' } ], - 'stateMutability': 'view', - 'type': 'function' -}] +const TOKEN_ABI = [ + { + 'inputs': [ + { 'internalType': 'address', 'name': 'holder', 'type': 'address' }, + { 'internalType': 'address', 'name': 'spender', 'type': 'address' } + ], + 'name': 'allowance', + 'outputs': [ { 'internalType': 'uint256', 'name': '', 'type': 'uint256' } ], + 'stateMutability': 'view', + 'type': 'function' + }, + { + 'inputs': [ { 'internalType': 'address', 'name': 'tokenHolder', 'type': 'address' } ], + 'name': 'balanceOf', + 'outputs': [ { 'internalType': 'uint256', 'name': '', 'type': 'uint256' } ], + 'stateMutability': 'view', + 'type': 'function' + }, +] const getTokenContract = (_address, _signer) => { console.info(`✔ Getting token contract @ '${_address}'...`) From 2631b2972ef43658906e8ff3eae6821c9d4594c5 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 10:51:44 +0100 Subject: [PATCH 02/12] feat(constants): <- adds contract call timeout time to that & use elsewhere --- lib/check-allowance.js | 5 ++--- lib/constants.js | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/check-allowance.js b/lib/check-allowance.js index eed255a..ae796b4 100644 --- a/lib/check-allowance.js +++ b/lib/check-allowance.js @@ -1,8 +1,7 @@ const { BigNumber } = require('ethers') const { logic } = require('ptokens-utils') const { getTokenContract } = require('./get-token-contract') - -const TIMEOUT_TIME = 3000 +const { CONTRACT_CALL_TIME_OUT_TIME } = require('./constants') const checkAllowanceIsSufficient = ( _amount, @@ -13,7 +12,7 @@ const checkAllowanceIsSufficient = ( ) => console.info(`✔ Checking spender ${_spenderAddress} has sufficient allowance for token ${_tokenAddress}...`) || logic.racePromise( - TIMEOUT_TIME, + CONTRACT_CALL_TIME_OUT_TIME, getTokenContract(_tokenAddress, _signer).allowance, [ _ownerAddress, _spenderAddress ], ) diff --git a/lib/constants.js b/lib/constants.js index 173308a..d462940 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,5 +1,6 @@ module.exports = { ENDPOINT_ENV_VAR_KEY: 'ENDPOINT', + CONTRACT_CALL_TIME_OUT_TIME: 3000, ETHERSCAN_ENV_VAR_KEY: 'ETHERSCAN_API_KEY', HARDHAT_CONFIG_FILE_NAME: 'hardhat.config.js', FLATTENED_CONTRACT_FILE_NAME: 'flattened.sol', From 75f9034b3e7035e552fb36aeb55084d474cb52c8 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 10:52:45 +0100 Subject: [PATCH 03/12] feat(token-balance): <- adds mod to check that --- lib/check-token-balance.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/check-token-balance.js diff --git a/lib/check-token-balance.js b/lib/check-token-balance.js new file mode 100644 index 0000000..7150c3e --- /dev/null +++ b/lib/check-token-balance.js @@ -0,0 +1,24 @@ +const { BigNumber } = require('ethers') +const { logic } = require('ptokens-utils') +const { getTokenContract } = require('./get-token-contract') +const { CONTRACT_CALL_TIME_OUT_TIME } = require('./constants') + +const checkTokenBalanceIsSufficient = (_amount, _tokenOwnerAddress, _tokenAddress, _signer) => + console.info(`✔ Checking spender ${_tokenOwnerAddress} has sufficient balance of token ${_tokenAddress}...`) || + logic.racePromise( + CONTRACT_CALL_TIME_OUT_TIME, + getTokenContract(_tokenAddress, _signer).balanceOf, + [ _tokenOwnerAddress ], + ) + .then(_tokenBalance => { + if (_tokenBalance.lt(BigNumber.from(_amount))) { + return Promise.reject( + new Error(`Insufficient token balance to peg in! Got ${_tokenBalance}, need ${_amount}!`) + ) + } else { + console.info(`✔ Token balance of ${_tokenBalance} is sufficient!`) + return + } + }) + +module.exports = { checkTokenBalanceIsSufficient } From f9d4783d0e50ef5c40028b93c5c14c1fa3c6703a Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 10:59:39 +0100 Subject: [PATCH 04/12] feat(peg-in): <- adds balance-check step to that --- lib/peg-in.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/peg-in.js b/lib/peg-in.js index 97aba67..9055691 100644 --- a/lib/peg-in.js +++ b/lib/peg-in.js @@ -1,9 +1,10 @@ const { getVaultContract } = require('./get-vault-contract') const { checkAllowanceIsSufficient } = require('./check-allowance') const { callFxnInContractAndAwaitReceipt } = require('./contract-utils') +const { checkTokenBalanceIsSufficient } = require('./check-token-balance') const pegIn = ( - _deployedContractAddress, + _vaultAddress, _amount, _tokenAddress, _destinationAddress, @@ -11,18 +12,25 @@ const pegIn = ( _userData = '0x', ) => console.info('✔ Pegging in...') || - getVaultContract(_deployedContractAddress) + getVaultContract(_vaultAddress) .then(_vaultContact => Promise.all([ _vaultContact, _vaultContact.signer.getAddress() ])) - .then(([ _vaultContract, _ownerAddress ]) => + .then(([ _vaultContract, _tokenOwnerAddress ]) => { + const provider = _vaultContract.provider + + // NOTE: We could make both balance & allowance checks in this `Promise.all` but we want them + // sequential since if the balance is insufficient then of course the allowance would also be. + // This way, the user sees the most relevant error first if extant. + return Promise.all([ + _vaultContract, + _tokenOwnerAddress, + provider, + checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, provider) + ]) + }) + .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => Promise.all([ _vaultContract, - checkAllowanceIsSufficient( - _amount, - _deployedContractAddress, // NOTE: This is the "spender" address, the vault in this case! - _ownerAddress, - _tokenAddress, - _vaultContract.provider, - ) + checkAllowanceIsSufficient(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _provider) ]) ) .then(([ _vaultContract ]) => From 0524e4ae401fb3be2094ac69487b32ecce4810e3 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 11:38:44 +0100 Subject: [PATCH 05/12] feat(utils): <- adds one of those to get ethers contracs & uses where needed --- lib/get-token-contract.js | 10 ++++------ lib/get-vault-contract.js | 24 +++++++++++++----------- lib/utils.js | 7 +++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/get-token-contract.js b/lib/get-token-contract.js index fffb143..7de6bb8 100644 --- a/lib/get-token-contract.js +++ b/lib/get-token-contract.js @@ -1,5 +1,4 @@ -/* eslint-disable-next-line no-shadow */ -const ethers = require('ethers') +const { getEthersContract } = require('./utils') const TOKEN_ABI = [ { @@ -21,9 +20,8 @@ const TOKEN_ABI = [ }, ] -const getTokenContract = (_address, _signer) => { - console.info(`✔ Getting token contract @ '${_address}'...`) - return new ethers.Contract(_address, TOKEN_ABI, _signer) -} +const getTokenContract = (_address, _signer) => + console.info(`✔ Getting token contract @ '${_address}'...`) || + getEthersContract(_address, TOKEN_ABI, _signer) module.exports = { getTokenContract } diff --git a/lib/get-vault-contract.js b/lib/get-vault-contract.js index 79d7946..396210b 100644 --- a/lib/get-vault-contract.js +++ b/lib/get-vault-contract.js @@ -1,18 +1,17 @@ -/* eslint-disable-next-line no-shadow */ -const ethers = require('ethers') const { curry } = require('ramda') +const { getEthersContract } = require('./utils') const { getProvider } = require('./get-provider') const { checkEndpoint } = require('./check-endpoint') -const { getVaultAbi } = require('./get-contract-artifacts') const { ENDPOINT_ENV_VAR_KEY } = require('./constants') const { getEthersWallet } = require('./get-ethers-wallet') +const { getVaultAbi } = require('./get-contract-artifacts') const { getEnvConfiguration } = require('./get-env-configuration') const { getEnvironmentVariable } = require('./get-environment-variable') -const getEthersContract = curry((_address, _abi, _signer) => { - console.info(`✔ Getting contract @ '${_address}'...`) - return Promise.resolve(new ethers.Contract(_address, _abi, _signer)) -}) +const getVaultEthersContract = curry((_address, _signer) => + console.info('✔ Getting vault contract...') || + getVaultAbi().then(_abi => getEthersContract(_address, _abi, _signer)) +) const getVaultContract = _deployedContractAddress => console.info(`✔ Getting pToken contract @ '${_deployedContractAddress}'...`) || @@ -20,8 +19,11 @@ const getVaultContract = _deployedContractAddress => .then(() => getEnvironmentVariable(ENDPOINT_ENV_VAR_KEY)) .then(getProvider) .then(checkEndpoint) - .then(_endpoint => Promise.all([ getEthersWallet(_endpoint), getVaultAbi() ])) - .then(([ _wallet, _abi ]) => getEthersContract(_deployedContractAddress, _abi, _wallet)) - .then(_contract => console.info('✔ Contract retrieved!') || _contract) + .then(getEthersWallet) + .then(getVaultEthersContract(_deployedContractAddress)) + .then(_contract => console.info('✔ Vault contract retrieved!') || _contract) -module.exports = { getVaultContract } +module.exports = { + getVaultEthersContract, + getVaultContract, +} diff --git a/lib/utils.js b/lib/utils.js index 4451d7f..97635f4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,6 +1,7 @@ const { has, prop, + curry, } = require('ramda') /* eslint-disable-next-line no-shadow */ const ethers = require('ethers') @@ -46,11 +47,17 @@ const maybeHandleEtherscanTrimErrMsg = _err => )) : Promise.reject(_err) +const getEthersContract = curry((_address, _abi, _signer) => { + console.info(`✔ Getting contract @ '${_address}'...`) + return new ethers.Contract(_address, _abi, _signer) +}) + module.exports = { maybeHandleEtherscanTrimErrMsg, maybeStripHexPrefix, maybeAddHexPrefix, shortenEthAddress, + getEthersContract, checkEthAddress, getKeyFromObj, checkIsHex, From 3b5aa87e916408f94836628b658f7e2a03b21d5a Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 11:42:04 +0100 Subject: [PATCH 06/12] ref(peg-in): <- simplify logic in that --- lib/peg-in.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/peg-in.js b/lib/peg-in.js index 9055691..358f7c9 100644 --- a/lib/peg-in.js +++ b/lib/peg-in.js @@ -13,20 +13,20 @@ const pegIn = ( ) => console.info('✔ Pegging in...') || getVaultContract(_vaultAddress) - .then(_vaultContact => Promise.all([ _vaultContact, _vaultContact.signer.getAddress() ])) - .then(([ _vaultContract, _tokenOwnerAddress ]) => { - const provider = _vaultContract.provider - + .then(_vaultContract => + Promise.all([ _vaultContract, _vaultContract.signer.getAddress(), _vaultContract.provider ]) + ) + .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => // NOTE: We could make both balance & allowance checks in this `Promise.all` but we want them // sequential since if the balance is insufficient then of course the allowance would also be. // This way, the user sees the most relevant error first if extant. - return Promise.all([ + Promise.all([ _vaultContract, _tokenOwnerAddress, - provider, - checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, provider) + _provider, + checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, _provider) ]) - }) + ) .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => Promise.all([ _vaultContract, From 02ea36d66f49d5ead161a206e4fcd8c91c5f13db Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 11:46:55 +0100 Subject: [PATCH 07/12] feat(token-support): <- adds mod to check a token is supported in the vault --- lib/check-token-is-supported.js | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/check-token-is-supported.js diff --git a/lib/check-token-is-supported.js b/lib/check-token-is-supported.js new file mode 100644 index 0000000..f31d609 --- /dev/null +++ b/lib/check-token-is-supported.js @@ -0,0 +1,34 @@ +const { logic } = require('ptokens-utils') +const { getEthersContract } = require('./utils') +const { CONTRACT_CALL_TIME_OUT_TIME } = require('./constants') + +const VAULT_ABI_FRAGMENT = [{ + 'type': 'function', + 'stateMutability': 'view', + 'name': 'isTokenSupported', + 'outputs': [{ 'internalType': 'bool', 'name': '', 'type': 'bool' }], + 'inputs': [{ 'internalType': 'address', 'name': '_token', 'type': 'address' }], +}] + +const getVaultContract = (_address, _provider) => + getEthersContract(_address, VAULT_ABI_FRAGMENT, _provider) + +const checkTokenIsSupportedInVault = (_vaultAddress, _tokenAddress, _provider) => + console.info(`✔ Checking token @ ${_tokenAddress} is supported in vault @ ${_vaultAddress}...`) || + logic.racePromise( + CONTRACT_CALL_TIME_OUT_TIME, + getVaultContract(_vaultAddress, _provider).isTokenSupported, + [ _tokenAddress ], + ) + .then(_tokenIsSupported => { + if (_tokenIsSupported) { + console.info('✔ Token is supported in vault contract!') + return + } else { + return Promise.reject( + new Error(`Token @ ${_tokenAddress} is NOT supported in vault contract @ ${_vaultAddress}!`) + ) + } + }) + +module.exports = { checkTokenIsSupportedInVault } From 827dc9dc2500f2d29f61cfcdb195cf14bbf34402 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 12:23:23 +0100 Subject: [PATCH 08/12] feat(peg-in): <- adds step to that to check token is supported --- lib/get-vault-contract.js | 5 +---- lib/peg-in.js | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/get-vault-contract.js b/lib/get-vault-contract.js index 396210b..df036c4 100644 --- a/lib/get-vault-contract.js +++ b/lib/get-vault-contract.js @@ -23,7 +23,4 @@ const getVaultContract = _deployedContractAddress => .then(getVaultEthersContract(_deployedContractAddress)) .then(_contract => console.info('✔ Vault contract retrieved!') || _contract) -module.exports = { - getVaultEthersContract, - getVaultContract, -} +module.exports = { getVaultContract } diff --git a/lib/peg-in.js b/lib/peg-in.js index 358f7c9..bbe5a1e 100644 --- a/lib/peg-in.js +++ b/lib/peg-in.js @@ -2,6 +2,7 @@ const { getVaultContract } = require('./get-vault-contract') const { checkAllowanceIsSufficient } = require('./check-allowance') const { callFxnInContractAndAwaitReceipt } = require('./contract-utils') const { checkTokenBalanceIsSufficient } = require('./check-token-balance') +const { checkTokenIsSupportedInVault } = require('./check-token-is-supported') const pegIn = ( _vaultAddress, @@ -30,9 +31,16 @@ const pegIn = ( .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => Promise.all([ _vaultContract, + _provider, checkAllowanceIsSufficient(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _provider) ]) ) + .then(([ _vaultContract, _provider ]) => + Promise.all([ + _vaultContract, + checkTokenIsSupportedInVault(_vaultAddress, _tokenAddress, _provider), + ]) + ) .then(([ _vaultContract ]) => callFxnInContractAndAwaitReceipt( 'pegIn(uint256,address,string,bytes,bytes4)', From 6094dc7edfc71c22b65721b3134055c763b763a8 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 12:33:38 +0100 Subject: [PATCH 09/12] feat(token-contract): <- adds approval fxn to abi of that --- lib/get-token-contract.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/get-token-contract.js b/lib/get-token-contract.js index 7de6bb8..02f065c 100644 --- a/lib/get-token-contract.js +++ b/lib/get-token-contract.js @@ -18,6 +18,16 @@ const TOKEN_ABI = [ 'stateMutability': 'view', 'type': 'function' }, + { + 'inputs': [ + { 'internalType': 'address', 'name': 'spender', 'type': 'address' }, + { 'internalType': 'uint256', 'name': 'value', 'type': 'uint256' } + ], + 'name': 'approve', + 'outputs': [ { 'internalType': 'bool', 'name': '', 'type': 'bool' } ], + 'stateMutability': 'nonpayable', + 'type': 'function' + }, ] const getTokenContract = (_address, _signer) => From ec7536cbc4af6f5b0e61b7f6dce4e40d01d0835d Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 12:53:02 +0100 Subject: [PATCH 10/12] feat(peg-in): <- attempts to set allowance if not sufficient when doing that --- lib/check-allowance.js | 28 ---------------------------- lib/maybe-approve-allowance.js | 33 +++++++++++++++++++++++++++++++++ lib/peg-in.js | 23 ++++++++--------------- 3 files changed, 41 insertions(+), 43 deletions(-) delete mode 100644 lib/check-allowance.js create mode 100644 lib/maybe-approve-allowance.js diff --git a/lib/check-allowance.js b/lib/check-allowance.js deleted file mode 100644 index ae796b4..0000000 --- a/lib/check-allowance.js +++ /dev/null @@ -1,28 +0,0 @@ -const { BigNumber } = require('ethers') -const { logic } = require('ptokens-utils') -const { getTokenContract } = require('./get-token-contract') -const { CONTRACT_CALL_TIME_OUT_TIME } = require('./constants') - -const checkAllowanceIsSufficient = ( - _amount, - _spenderAddress, - _ownerAddress, - _tokenAddress, - _signer, -) => - console.info(`✔ Checking spender ${_spenderAddress} has sufficient allowance for token ${_tokenAddress}...`) || - logic.racePromise( - CONTRACT_CALL_TIME_OUT_TIME, - getTokenContract(_tokenAddress, _signer).allowance, - [ _ownerAddress, _spenderAddress ], - ) - .then(_allowance => { - if (_allowance.lt(BigNumber.from(_amount))) { - return Promise.reject(new Error(`Insufficient allowance to peg in! Got ${_allowance}, need ${_amount}!`)) - } else { - console.info(`✔ Allowance of ${_allowance} is sufficient!`) - return - } - }) - -module.exports = { checkAllowanceIsSufficient } diff --git a/lib/maybe-approve-allowance.js b/lib/maybe-approve-allowance.js new file mode 100644 index 0000000..1cee77d --- /dev/null +++ b/lib/maybe-approve-allowance.js @@ -0,0 +1,33 @@ +const { BigNumber } = require('ethers') +const { logic } = require('ptokens-utils') +const { getTokenContract } = require('./get-token-contract') +const { CONTRACT_CALL_TIME_OUT_TIME } = require('./constants') + +const approveAllowance = (_amount, _vaultAddress, _tokenAddress, _signer) => + console.info(`✔ Approving vault to spend ${_amount} tokens, please wait for mining...`) || + getTokenContract(_tokenAddress, _signer) + .approve(_vaultAddress, _amount) + .then(_tx => _tx.wait()) + .then(_ => console.info('✔ Approval succeeded! Continuing with peg in...')) + +const maybeApproveAllowance = (_amount, _vaultAddress, _ownerAddress, _tokenAddress, _signer) => + console.info(`✔ Checking spender ${_vaultAddress} has sufficient allowance for token ${_tokenAddress}...`) || + logic.racePromise( + CONTRACT_CALL_TIME_OUT_TIME, + getTokenContract(_tokenAddress, _signer).allowance, + [ _ownerAddress, _vaultAddress ], + ) + .then(_allowance => { + if (_allowance.lt(BigNumber.from(_amount))) { + // NOTE: At least one of the tokens we bridge has a special approval mechanism whereby if we + // want to change an allowance that is already > 0, we must first set it to 0 and then to our + // desired amount. This logic does NOT currently handle this case. + console.info('✘ Allowance is not sufficient!') + return approveAllowance(_amount, _vaultAddress, _tokenAddress, _signer) + } else { + console.info(`✔ Allowance of ${_allowance} is already sufficient!`) + return + } + }) + +module.exports = { maybeApproveAllowance } diff --git a/lib/peg-in.js b/lib/peg-in.js index bbe5a1e..86c5f6e 100644 --- a/lib/peg-in.js +++ b/lib/peg-in.js @@ -1,5 +1,5 @@ const { getVaultContract } = require('./get-vault-contract') -const { checkAllowanceIsSufficient } = require('./check-allowance') +const { maybeApproveAllowance } = require('./maybe-approve-allowance') const { callFxnInContractAndAwaitReceipt } = require('./contract-utils') const { checkTokenBalanceIsSufficient } = require('./check-token-balance') const { checkTokenIsSupportedInVault } = require('./check-token-is-supported') @@ -14,31 +14,24 @@ const pegIn = ( ) => console.info('✔ Pegging in...') || getVaultContract(_vaultAddress) - .then(_vaultContract => - Promise.all([ _vaultContract, _vaultContract.signer.getAddress(), _vaultContract.provider ]) - ) - .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => - // NOTE: We could make both balance & allowance checks in this `Promise.all` but we want them - // sequential since if the balance is insufficient then of course the allowance would also be. - // This way, the user sees the most relevant error first if extant. + .then(_vaultContract => Promise.all([ _vaultContract, _vaultContract.signer.getAddress() ])) + .then(([ _vaultContract, _tokenOwnerAddress, ]) => Promise.all([ _vaultContract, _tokenOwnerAddress, - _provider, - checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, _provider) + checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, _vaultContract.provider) ]) ) - .then(([ _vaultContract, _tokenOwnerAddress, _provider ]) => + .then(([ _vaultContract, _tokenOwnerAddress ]) => Promise.all([ _vaultContract, - _provider, - checkAllowanceIsSufficient(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _provider) + maybeApproveAllowance(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _vaultContract.signer) ]) ) - .then(([ _vaultContract, _provider ]) => + .then(([ _vaultContract ]) => Promise.all([ _vaultContract, - checkTokenIsSupportedInVault(_vaultAddress, _tokenAddress, _provider), + checkTokenIsSupportedInVault(_vaultAddress, _tokenAddress, _vaultContract.provider), ]) ) .then(([ _vaultContract ]) => From 68250752f15339c7ce03cdab3878cc95ca7ca2df Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 12:56:41 +0100 Subject: [PATCH 11/12] ref(peg-in): <- check for token supportfirst when pegging in --- lib/peg-in.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/peg-in.js b/lib/peg-in.js index 86c5f6e..11dae63 100644 --- a/lib/peg-in.js +++ b/lib/peg-in.js @@ -15,23 +15,24 @@ const pegIn = ( console.info('✔ Pegging in...') || getVaultContract(_vaultAddress) .then(_vaultContract => Promise.all([ _vaultContract, _vaultContract.signer.getAddress() ])) - .then(([ _vaultContract, _tokenOwnerAddress, ]) => + .then(([ _vaultContract, _tokenOwnerAddress ]) => Promise.all([ _vaultContract, _tokenOwnerAddress, - checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, _vaultContract.provider) + checkTokenIsSupportedInVault(_vaultAddress, _tokenAddress, _vaultContract.provider), ]) ) - .then(([ _vaultContract, _tokenOwnerAddress ]) => + .then(([ _vaultContract, _tokenOwnerAddress, ]) => Promise.all([ _vaultContract, - maybeApproveAllowance(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _vaultContract.signer) + _tokenOwnerAddress, + checkTokenBalanceIsSufficient(_amount, _tokenOwnerAddress, _tokenAddress, _vaultContract.provider) ]) ) - .then(([ _vaultContract ]) => + .then(([ _vaultContract, _tokenOwnerAddress ]) => Promise.all([ _vaultContract, - checkTokenIsSupportedInVault(_vaultAddress, _tokenAddress, _vaultContract.provider), + maybeApproveAllowance(_amount, _vaultAddress, _tokenOwnerAddress, _tokenAddress, _vaultContract.signer) ]) ) .then(([ _vaultContract ]) => From 213d624ca7396a7d349a664b119dff055eb8e9f9 Mon Sep 17 00:00:00 2001 From: Greg Kapka Date: Wed, 6 Jul 2022 12:53:23 +0100 Subject: [PATCH 12/12] chore(package.json): <- bump minor version number in that --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa5188a..8b5eef5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ptokens-erc20-vault-smart-contract", - "version": "2.5.0", + "version": "2.6.0", "description": "The pToken ERC20 vault smart-contract & CLI", "main": "cli.js", "scripts": {