diff --git a/apps/web/src/composables/ethers.ts b/apps/web/src/composables/ethers.ts index fd9bdcf2d..c22c6c738 100644 --- a/apps/web/src/composables/ethers.ts +++ b/apps/web/src/composables/ethers.ts @@ -51,10 +51,9 @@ export default function useEthers() { const etherAmount = ethers.utils.parseEther(value) const tx = { to, - value: etherAmount, + value: etherAmount } - const { hash } = await signer.sendTransaction(tx) - return hash + return await signer.sendTransaction(tx) } async function signEthersMessage(messageInit: MessageInit): Promise { diff --git a/apps/web/src/composables/ledger.ts b/apps/web/src/composables/ledger.ts index 5559d7843..aad4b0343 100644 --- a/apps/web/src/composables/ledger.ts +++ b/apps/web/src/composables/ledger.ts @@ -5,7 +5,7 @@ import { MessageInit } from '@/interfaces/MessageInit' import useEnvironment from '@/composables/environment' import useEthers from '@/composables/ethers' -const ledgerPath = '44\'/60\'/0\'/0/0' +const ledgerPath = 'm/44\'/60\'/0\'/0/0' export default function useLedger() { const { ethereumURL, ledgerType, speculosURL } = useEnvironment() @@ -29,20 +29,14 @@ export default function useLedger() { async function sendLedgerTransaction({ from, to, value }: TransactionInit) { const signer = getEthersLedgerSigner() const provider = signer.provider as ethers.providers.Provider - const { chainId } = await provider.getNetwork() - const nonce = await provider.getTransactionCount(from) const unsignedTransaction = { to, - data: '0x00', - nonce, - chainId, - value: ethers.utils.parseUnits(value) + value: ethers.utils.parseUnits(value), + type: 0 } as ethers.UnsignedTransaction - const { gasPrice, gasLimit } = await getGasPriceAndLimit(ethereumURL, unsignedTransaction as ethers.utils.Deferrable) - unsignedTransaction.gasPrice = gasPrice - unsignedTransaction.gasLimit = gasLimit - + // Todo check before click (user can +/- gas limit accordingly) + const { gasPrice, gasLimit } = await getGasPriceAndLimit(ethereumURL, unsignedTransaction as ethers.utils.Deferrable) const balance = await provider.getBalance(from) const required = gasPrice.mul(gasLimit).add(ethers.utils.parseEther(value)) console.log('Balance', ethers.utils.formatEther(balance)) diff --git a/apps/web/src/composables/wallet.ts b/apps/web/src/composables/wallet.ts index c27f6331a..69aafa002 100644 --- a/apps/web/src/composables/wallet.ts +++ b/apps/web/src/composables/wallet.ts @@ -151,7 +151,7 @@ export default function useWallet() { let signer = ethersSignerCreator[signerKey](selectedProvider.value) if (isWalletConnectSigner(signer)) signer = await signer const value = ethers.utils.parseEther(amountToStake.value) - await ssv.connect(signer as ethers.Signer).deposit({ value }) + await ssv.connect(signer as ethers.Signer).deposit({ value, type: 0 }) } else { // Todo @ccali11 this should happen sooner - ideally we'll this disable method if missing ssv provider console.log('Please connect to one of the following providers:', ethersProviderList) diff --git a/common/ethers-ledger-signer/src/index.ts b/common/ethers-ledger-signer/src/index.ts index 4e7e3bc15..b4e5d235d 100644 --- a/common/ethers-ledger-signer/src/index.ts +++ b/common/ethers-ledger-signer/src/index.ts @@ -1,9 +1,9 @@ import { ethers } from 'ethers' -import Eth from '@ledgerhq/hw-app-eth' +import Eth, { ledgerService } from '@ledgerhq/hw-app-eth' import useTransports from './providers/transports' import { EthersLedgerSignerOptions } from './interfaces/EthersLedgerSignerOptions' -const defaultPath = '44\'/60\'/0\'/0/0' +const defaultPath = 'm/44\'/60\'/0\'/0/0' const defaultType = 'usb' const { createUSBTransport, createSpeculosTransport } = useTransports() const transportCreators = { @@ -76,7 +76,7 @@ export default class EthersLedgerSigner extends ethers.Signer { } async signMessage(message: ethers.utils.Bytes | string): Promise { - if (typeof(message) === 'string') { + if (typeof (message) === 'string') { message = ethers.utils.toUtf8Bytes(message) } const messageHex = ethers.utils.hexlify(message).substring(2) @@ -90,19 +90,19 @@ export default class EthersLedgerSigner extends ethers.Signer { async signTransaction(transaction: ethers.providers.TransactionRequest): Promise { const tx = await ethers.utils.resolveProperties(transaction) const baseTx: ethers.utils.UnsignedTransaction = { - chainId: tx.chainId || undefined, - data: tx.data || undefined, - gasLimit: tx.gasLimit || undefined, - gasPrice: tx.gasPrice || undefined, - nonce: tx.nonce ? ethers.BigNumber.from(tx.nonce).toNumber() : undefined, - to: tx.to || undefined, - value: tx.value || undefined, + chainId: (tx.chainId || undefined), + data: (tx.data || undefined), + gasLimit: (tx.gasLimit || undefined), + gasPrice: (tx.gasPrice || undefined), + nonce: (tx.nonce ? ethers.BigNumber.from(tx.nonce).toNumber(): undefined), + to: (tx.to || undefined), + value: (tx.value || undefined), + type: (tx.type || undefined) } const unsignedTx = ethers.utils.serializeTransaction(baseTx).substring(2) - const signature = await this._retry((eth) => eth.signTransaction(this.path, unsignedTx)) - - console.log('Signed tx', tx) + const resolution = await ledgerService.resolveTransaction(unsignedTx, {}, {}) + const signature = await this._retry((eth) => eth.signTransaction(this.path, unsignedTx, resolution)) return ethers.utils.serializeTransaction(baseTx, { v: ethers.BigNumber.from('0x' + signature.v).toNumber(), @@ -111,6 +111,14 @@ export default class EthersLedgerSigner extends ethers.Signer { }) } + // Populates all fields in a transaction, signs it and sends it to the network + async sendTransaction(transaction: ethers.utils.Deferrable): Promise { + this._checkProvider('sendTransaction') + const tx = await this.populateTransaction(transaction) + const signedTx = await this.signTransaction(tx) + return await (this.provider as ethers.providers.JsonRpcProvider).sendTransaction(signedTx) + } + connect(provider: ethers.providers.Provider): ethers.Signer { const options = { provider, diff --git a/scripts/local/dev b/scripts/local/dev index 36243d562..440a36c58 100755 --- a/scripts/local/dev +++ b/scripts/local/dev @@ -33,7 +33,7 @@ seed=$(aws secretsmanager get-secret-value \ export BIP39_SEED="$seed" # Get args -while getopts :a:f:l:m:n:t: flag +while getopts :a:f:l:m:n:t:x: flag do case "${flag}" in a) app=${OPTARG};; @@ -46,14 +46,6 @@ do esac done -echo "APP set to $app" -echo "EXPOSE set to $external" -echo "FORK set to $fork" -echo "LEDGER set to $ledger" -echo "MOCK set to $mock" -echo "NETWORK set to $network" -echo "TREZOR set to $trezor" - # Default to mainnet if fork is set vaguely if [ "$fork" = true ]; then fork=mainnet