Skip to content

Commit

Permalink
upgrade ethers to v6
Browse files Browse the repository at this point in the history
fix bugs
  • Loading branch information
chaitanyapotti committed Jun 23, 2023
1 parent 6ff549b commit 9af76ff
Show file tree
Hide file tree
Showing 29 changed files with 1,535 additions and 1,512 deletions.
2,021 changes: 663 additions & 1,358 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,17 @@
"eth-json-rpc-filters": "^6.0.0",
"eth-query": "^2.1.2",
"eth-rpc-errors": "^4.0.3",
"ethers": "^5.7.2",
"ethers": "^6.6.0",
"ethjs-query": "^0.3.8",
"fast-json-patch": "^3.1.1",
"human-standard-collectible-abi": "^1.0.2",
"human-standard-token-abi": "^2.0.0",
"jsonschema": "^1.4.1",
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"multi-token-standard-abi": "1.0.4",
"pify": "^5.0.0",
"pump": "^3.0.0",
"readable-stream": "^4.4.0",
"register-service-worker": "^1.7.2",
"single-call-balance-checker-abi": "^1.0.0",
"swappable-obj-proxy": "^1.1.0",
"vue": "^2.7.14",
"vue-content-loader": "^0.2.3",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Confirm/ConfirmForm/ConfirmForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@

<script>
import BigNumber from 'bignumber.js'
import { utils } from 'ethers'
import { formatEther } from 'ethers'
import log from 'loglevel'
import VueJsonPretty from 'vue-json-pretty'
import { mapActions, mapGetters } from 'vuex'
Expand Down Expand Up @@ -721,7 +721,7 @@ export default {
log.info(txParams, 'txParams')
const { reason = '' } = simulationFails || {}
if (value) {
finalValue = new BigNumber(utils.formatEther(value.toString()))
finalValue = new BigNumber(formatEther(value.toString()))
}
let txDataParameters = ''
if (contractParams.isSpecial && transactionCategory.toLowerCase() === TRANSACTION_TYPES.TOKEN_METHOD_TRANSFER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default {
}
},
setErrorState(error) {
this.error = error && error.message && error.message.includes('invalid password') ? this.t('accountMenu.incorrectPassword') : error
this.error = error && error.message && error.message.includes('incorrect password') ? this.t('accountMenu.incorrectPassword') : error
this.canShowError = true
log.error(error)
this.isLoadingKeystore = false
Expand Down
6 changes: 3 additions & 3 deletions src/components/WalletHome/AddAsset/AddAsset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ export default {
...mapActions(['addCustomNft']),
async populateNftDetails(contractAddress, tokenId) {
try {
this.currentNft = new NftHandler({ address: contractAddress, tokenId, userAddress: this.selectedAddress, provider: torus.ethersProvider })
const balance = await this.currentNft.fetchNftBalance()
const currentNft = new NftHandler({ address: contractAddress, tokenId, userAddress: this.selectedAddress, provider: torus.ethersProvider })
const balance = await currentNft.fetchNftBalance()
this.isOwner = balance > 0
if (this.isOwner) {
const { nftName, nftImageLink, description, nftStandard } = await this.currentNft.getNftMetadata()
const { nftName, nftImageLink, description, nftStandard } = await currentNft.getNftMetadata()
this.nftName = nftName
this.nftImageLink = nftImageLink
this.description = description
Expand Down
11 changes: 5 additions & 6 deletions src/components/WalletHome/EditToken/EditToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export default {
customDecimals: 0,
customName: '',
customBalance: '',
currentToken: undefined,
isValidAddress: true,
rules: {
required: (value) => !!value || this.t('walletSettings.required'),
Expand Down Expand Up @@ -190,12 +189,12 @@ export default {
this.isValidAddress = await validateContractAddress(torus.ethersProvider, this.customAddress, this.$store.state.networkId)
if (this.isValidAddress) {
try {
this.currentToken = new TokenHandler({ address: this.customAddress.toLowerCase(), provider: torus.ethersProvider })
const currentToken = new TokenHandler({ address: this.customAddress.toLowerCase(), provider: torus.ethersProvider })
const [symbol, name, balance, decimals] = await Promise.all([
this.currentToken.getSymbol(),
this.currentToken.getName(),
this.currentToken.getUserBalance(this.selectedAddress.toLowerCase()),
this.currentToken.getDecimals(),
currentToken.getSymbol(),
currentToken.getName(),
currentToken.getUserBalance(this.selectedAddress.toLowerCase()),
currentToken.getDecimals(),
])
const computedBalance = new BigNumber(`0x${balance}`).dividedBy(new BigNumber(10).pow(new BigNumber(decimals))) || new BigNumber(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ export default {
this.averageGasPriceSpeed = avgWait
this.fastestGasPriceSpeed = fastestWait
} else {
const gasPrice = await torus.ethersProvider.getGasPrice()
const gasPrice = await torus.ethersProvider.send('eth_gasPrice')
log.info(gasPrice, 'fetched gas price from provider')
this.averageGasPrice = new BigNumber(gasPrice.toHexString()).div(new BigNumber(10).pow(new BigNumber(9)))
this.averageGasPrice = new BigNumber(gasPrice, 16).div(new BigNumber(10).pow(new BigNumber(9)))
this.fastestGasPrice = this.averageGasPrice.gt(0) ? this.averageGasPrice.plus(new BigNumber('5')) : this.averageGasPrice
}
// Set selected gas price from confirm
Expand Down
5 changes: 3 additions & 2 deletions src/containers/WalletHistory/WalletHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ export default {
const { fastest: fastestTimes10 } = await resp.json()
gasPrice = new BigNumber(fastestTimes10).div(new BigNumber('10'))
} else {
const recommended = await torus.ethersProvider.getGasPrice()
gasPrice = new BigNumber(recommended.toHexString()).div(new BigNumber(10).pow(new BigNumber(9))).plus(new BigNumber('5'))
const recommended = await torus.ethersProvider.send('eth_gasPrice')
log.info(recommended, 'fetched gas price from provider')
gasPrice = new BigNumber(recommended, 16).div(new BigNumber(10).pow(new BigNumber(9))).plus(new BigNumber('5'))
}
const percent10Extra = gasPrice.times(new BigNumber('1.1'))
// Add 5 to fastest recommended by transfer page
Expand Down
2 changes: 1 addition & 1 deletion src/containers/WalletSwap/WalletSwap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default {
}
this.sendingTx = true
const transaction = {
data: this.currentSwapQuote.methodParameters.calldata,
data: this.currentSwapQuote.methodParameters.callData,
to: config.uniswapContractAddress,
value: this.currentSwapQuote.methodParameters.value,
from: this.selectedAddress,
Expand Down
78 changes: 40 additions & 38 deletions src/containers/WalletTransfer/WalletTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,8 @@
import BigNumber from 'bignumber.js'
import Das from 'das-sdk'
import { Contract } from 'ethers'
import erc721TransferABI from 'human-standard-collectible-abi'
import erc20TransferABI from 'human-standard-token-abi'
import { cloneDeep, isEqual } from 'lodash'
import log from 'loglevel'
import { ERC1155 as erc1155Abi } from 'multi-token-standard-abi'
import { QrcodeStream } from 'vue-qrcode-reader'
import { mapActions, mapGetters, mapState } from 'vuex'
Expand All @@ -522,6 +519,7 @@ import AddContact from '../../components/WalletTransfer/AddContact'
import MessageModal from '../../components/WalletTransfer/MessageModal'
import config from '../../config'
import torus from '../../torus'
import { ecr20Abi, erc721Abi, erc1155Abi } from '../../utils/abis'
import {
BIT,
BIT_HOST_URL,
Expand Down Expand Up @@ -1092,8 +1090,9 @@ export default {
this.toEthAddress = await this.calculateEthAddress()
}
},
calculateGas(toAddress) {
async calculateGas(toAddress) {
this.sendEthToContractError = false
const signer = await torus.ethersProvider.getSigner()
if (isAddressByChainId(toAddress, this.$store.state.networkId)) {
// eslint-disable-next-line no-unused-vars
return new Promise((resolve, reject) => {
Expand All @@ -1103,9 +1102,9 @@ export default {
.dp(0, BigNumber.ROUND_DOWN)
.toString(16)}`
torus.ethersProvider
.estimateGas({ to: toAddress.toLowerCase(), value, from: this.selectedAddress.toLowerCase() })
.send('eth_estimateGas', [{ to: toAddress.toLowerCase(), value, from: this.selectedAddress.toLowerCase() }])
.then((response) => {
let resolved = new BigNumber(response.toHexString() || '0')
let resolved = new BigNumber(response.toString(16) || '0', 16)
if (!resolved.eq(new BigNumber('21000'))) {
resolved = new BigNumber(resolved.times(new BigNumber('1.1')).toFixed(0))
this.sendEthToContractError = this.isSendAll
Expand All @@ -1122,11 +1121,11 @@ export default {
.times(new BigNumber(10).pow(new BigNumber(this.selectedItem.decimals)))
.dp(0, BigNumber.ROUND_DOWN)
.toString(16)}`
this.getTransferContract(this.contractType)
.estimateGas.transfer(toAddress.toLowerCase(), value, { from: this.selectedAddress.toLowerCase() })
this.getTransferContract(signer, this.contractType)
.transfer.estimateGas(toAddress.toLowerCase(), value, { from: this.selectedAddress.toLowerCase() })
.then((response) => {
log.info(response, 'gas')
resolve(new BigNumber(response.toHexString() || '0'))
resolve(new BigNumber(response.toString(16) || '0', 16))
})
.catch((error) => {
log.error(error)
Expand All @@ -1136,20 +1135,22 @@ export default {
this.contractType === CONTRACT_TYPE_ERC721 &&
Object.prototype.hasOwnProperty.call(OLD_ERC721_LIST, this.selectedTokenAddress.toLowerCase())
) {
this.getNftTransferContract(this.contractType)
.estimateGas.transfer(toAddress, this.assetSelected.tokenId, { from: this.selectedAddress.toLowerCase() })
this.getNftTransferContract(signer, this.contractType)
.transfer.estimateGas(toAddress, this.assetSelected.tokenId, { from: this.selectedAddress.toLowerCase() })
.then((response) => {
resolve(new BigNumber(response.toHexString() || '0'))
resolve(new BigNumber(response.toString(16) || '0', 16))
})
.catch((error) => {
log.error(error)
resolve(new BigNumber('0'))
})
} else if (this.contractType === CONTRACT_TYPE_ERC721) {
this.getNftTransferContract(this.contractType)
.estimateGas.safeTransferFrom(this.selectedAddress, toAddress, this.assetSelected.tokenId, { from: this.selectedAddress.toLowerCase() })
this.getNftTransferContract(signer, this.contractType)
.safeTransferFrom.estimateGas(this.selectedAddress, toAddress, this.assetSelected.tokenId, {
from: this.selectedAddress.toLowerCase(),
})
.then((response) => {
resolve(new BigNumber(response.toHexString() || '0'))
resolve(new BigNumber(response.toString(16) || '0', 16))
})
.catch((error) => {
log.error(error)
Expand All @@ -1158,12 +1159,12 @@ export default {
} else if (this.contractType === CONTRACT_TYPE_ERC1155) {
const val =
Number.parseInt(this.assetSelected.tokenBalance, 10) === 1 ? new BigNumber(this.assetSelected.tokenBalance) : this.erc1155DisplayAmount
this.getNftTransferContract(this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, val)
.estimateGas.safeTransferFrom(this.selectedAddress, toAddress, this.assetSelected.tokenId, val, '0x', {
this.getNftTransferContract(signer, this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, val)
.safeTransferFrom.estimateGas(this.selectedAddress, toAddress, this.assetSelected.tokenId, val, '0x', {
from: this.selectedAddress.toLowerCase(),
})
.then((response) => {
resolve(new BigNumber(response.toHexString() || '0'))
resolve(new BigNumber(response.toString(16) || '0', 16))
})
.catch((error) => {
log.error(error)
Expand All @@ -1172,63 +1173,63 @@ export default {
}
})
}
return Promise.resolve(new BigNumber('0'))
return new BigNumber('0')
},
getTransferMethod(contractType, toAddress, value, params = {}) {
getTransferMethod(signer, contractType, toAddress, value, params = {}) {
// For support of older ERC721
if (Object.prototype.hasOwnProperty.call(OLD_ERC721_LIST, this.selectedTokenAddress.toLowerCase()) || contractType === CONTRACT_TYPE_ERC20) {
const contractInstance = new Contract(this.selectedTokenAddress.toLowerCase(), erc20TransferABI, torus.ethersProvider.getSigner())
return contractInstance.populateTransaction.transfer(toAddress.toLowerCase(), value, { from: this.selectedAddress.toLowerCase(), ...params })
const contractInstance = new Contract(this.selectedTokenAddress.toLowerCase(), ecr20Abi, signer)
return contractInstance.transfer.populateTransaction(toAddress.toLowerCase(), value, { from: this.selectedAddress.toLowerCase(), ...params })
}
throw new Error('Invalid Contract Type')
},
getTransferContract(contractType) {
getTransferContract(signer, contractType) {
// For support of older ERC721
if (Object.prototype.hasOwnProperty.call(OLD_ERC721_LIST, this.selectedTokenAddress.toLowerCase()) || contractType === CONTRACT_TYPE_ERC20) {
const contractInstance = new Contract(this.selectedTokenAddress.toLowerCase(), erc20TransferABI, torus.ethersProvider.getSigner())
const contractInstance = new Contract(this.selectedTokenAddress.toLowerCase(), ecr20Abi, signer)
return contractInstance
}
throw new Error('Invalid Contract Type')
},
getNftTransferMethod(contractType, selectedAddress, toAddress, tokenId, value = 1, params = {}) {
getNftTransferMethod(signer, contractType, selectedAddress, toAddress, tokenId, value = 1, params = {}) {
if (contractType === CONTRACT_TYPE_ERC721 && Object.prototype.hasOwnProperty.call(OLD_ERC721_LIST, this.selectedTokenAddress.toLowerCase())) {
const contractInstance = new Contract(this.selectedTokenAddress, erc20TransferABI, torus.ethersProvider.getSigner())
return contractInstance.populateTransaction.transfer(toAddress, tokenId, { from: this.selectedAddress.toLowerCase(), ...params })
const contractInstance = new Contract(this.selectedTokenAddress, ecr20Abi, signer)
return contractInstance.transfer.populateTransaction(toAddress, tokenId, { from: this.selectedAddress.toLowerCase(), ...params })
}
if (contractType === CONTRACT_TYPE_ERC721) {
const contractInstance = new Contract(this.selectedTokenAddress, erc721TransferABI, torus.ethersProvider.getSigner())
return contractInstance.populateTransaction.safeTransferFrom(selectedAddress, toAddress, tokenId, {
const contractInstance = new Contract(this.selectedTokenAddress, erc721Abi, signer)
return contractInstance.safeTransferFrom.populateTransaction(selectedAddress, toAddress, tokenId, {
from: this.selectedAddress.toLowerCase(),
...params,
})
}
if (contractType === CONTRACT_TYPE_ERC1155) {
const contractInstance = new Contract(this.selectedTokenAddress, erc1155Abi.abi, torus.ethersProvider.getSigner())
return contractInstance.populateTransaction.safeTransferFrom(selectedAddress, toAddress, tokenId, value, '0x', {
const contractInstance = new Contract(this.selectedTokenAddress, erc1155Abi.abi, signer)
return contractInstance.safeTransferFrom.populateTransaction(selectedAddress, toAddress, tokenId, value, '0x', {
from: this.selectedAddress.toLowerCase(),
...params,
})
}
throw new Error('Invalid Contract Type')
},
getNftTransferContract(contractType) {
getNftTransferContract(signer, contractType) {
if (contractType === CONTRACT_TYPE_ERC721 && Object.prototype.hasOwnProperty.call(OLD_ERC721_LIST, this.selectedTokenAddress.toLowerCase())) {
const contractInstance = new Contract(this.selectedTokenAddress, erc20TransferABI, torus.ethersProvider.getSigner())
const contractInstance = new Contract(this.selectedTokenAddress, ecr20Abi, signer)
return contractInstance
}
if (contractType === CONTRACT_TYPE_ERC721) {
const contractInstance = new Contract(this.selectedTokenAddress, erc721TransferABI, torus.ethersProvider.getSigner())
const contractInstance = new Contract(this.selectedTokenAddress, erc721Abi, signer)
return contractInstance
}
if (contractType === CONTRACT_TYPE_ERC1155) {
const contractInstance = new Contract(this.selectedTokenAddress, erc1155Abi.abi, torus.ethersProvider.getSigner())
const contractInstance = new Contract(this.selectedTokenAddress, erc1155Abi.abi, signer)
return contractInstance
}
Expand Down Expand Up @@ -1409,6 +1410,7 @@ export default {
gasPrice: fastGasPrice,
}
}
const signer = await torus.ethersProvider.getSigner()
if (this.contractType === CONTRACT_TYPE_ETH) {
const value = `0x${this.amount
.times(new BigNumber(10).pow(new BigNumber(18)))
Expand Down Expand Up @@ -1452,7 +1454,7 @@ export default {
.dp(0, BigNumber.ROUND_DOWN)
.toString(16)}`
log.info('amount', this.amount)
const data = await this.getTransferMethod(this.contractType, toAddress, value, {})
const data = await this.getTransferMethod(signer, this.contractType, toAddress, value, {})
const finalData = {
...data,
gas: this.gas.eq(new BigNumber('0')) ? undefined : `0x${this.gas.toString(16)}`,
Expand Down Expand Up @@ -1483,7 +1485,7 @@ export default {
log.error(error)
})
} else if (this.contractType === CONTRACT_TYPE_ERC721) {
const data = await this.getNftTransferMethod(this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, {})
const data = await this.getNftTransferMethod(signer, this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, {})
const finalData = {
...data,
Expand Down Expand Up @@ -1517,7 +1519,7 @@ export default {
} else if (this.contractType === CONTRACT_TYPE_ERC1155) {
const val =
Number.parseInt(this.assetSelected.tokenBalance, 10) === 1 ? new BigNumber(this.assetSelected.tokenBalance) : this.erc1155DisplayAmount
const data = await this.getNftTransferMethod(this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, val, {})
const data = await this.getNftTransferMethod(signer, this.contractType, this.selectedAddress, toAddress, this.assetSelected.tokenId, val, {})
const finalData = {
...data,
Expand Down
Loading

0 comments on commit 9af76ff

Please sign in to comment.