Skip to content

Commit

Permalink
chore: upgrade ethers to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder authored and RanGojo committed Sep 8, 2024
1 parent 8c52163 commit 3a20446
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 1,434 deletions.
6 changes: 3 additions & 3 deletions examples/queue-manager-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"@rango-dev/wallets-react": "^0.22.1-next.1",
"@rango-dev/wallets-shared": "^0.36.1-next.1",
"bignumber.js": "^9.1.1",
"ethers": "^5.7.2",
"rango-sdk-basic": "^0.1.44",
"ethers": "^6.13.2",
"rango-sdk-basic": "^0.1.54",
"rango-types": "^0.1.69"
}
}
}
2 changes: 1 addition & 1 deletion examples/queue-manager-demo/src/flows/rango/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ export function convertRawAccountToFullAccount(
* Otherwise, we stop executing this function.
*/
const isUknownAndEvmBased =
network === Networks.Unknown && ethers.utils.isAddress(address);
network === Networks.Unknown && ethers.isAddress(address);
if (isUnknown && !isUknownAndEvmBased) {
return;
}
Expand Down
53 changes: 30 additions & 23 deletions examples/queue-manager-demo/src/wallet.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
import { providers } from 'ethers';
import { BrowserProvider } from 'ethers';

const { ethereum } = window;

let activeAccount = null;

export async function connect(){
export async function connect() {
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
activeAccount = accounts[0];
console.log("connected", activeAccount)
console.log('connected', activeAccount);
}


export async function switchNetwork(chainId){
export async function switchNetwork(chainId) {
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId}],
params: [{ chainId }],
});

console.log("network switched.")
console.log('network switched.');
}


export async function signEvmTx(evmTransaction){
let provider = new providers.Web3Provider(ethereum);
let signer = provider.getSigner();
export async function signEvmTx(evmTransaction) {
const provider = new BrowserProvider(ethereum);
const signer = await provider.getSigner();

let tx = {};
if (!!evmTransaction.from) tx = { ...tx, from: evmTransaction.from };
if (!!evmTransaction.txTo) tx = { ...tx, to: evmTransaction.txTo };
if (!!evmTransaction.txData) tx = { ...tx, data: evmTransaction.txData };
if (!!evmTransaction.value) tx = { ...tx, value: evmTransaction.value };
if (!!evmTransaction.gasLimit) tx = { ...tx, gasLimit: evmTransaction.gasLimit };
if (!!evmTransaction.gasPrice) tx = { ...tx, gasPrice: evmTransaction.gasPrice };
if (!!evmTransaction.nonce) tx = { ...tx, nonce: evmTransaction.nonce };
if (!!evmTransaction.from) {
tx = { ...tx, from: evmTransaction.from };
}
if (!!evmTransaction.txTo) {
tx = { ...tx, to: evmTransaction.txTo };
}
if (!!evmTransaction.txData) {
tx = { ...tx, data: evmTransaction.txData };
}
if (!!evmTransaction.value) {
tx = { ...tx, value: evmTransaction.value };
}
if (!!evmTransaction.gasLimit) {
tx = { ...tx, gasLimit: evmTransaction.gasLimit };
}
if (!!evmTransaction.gasPrice) {
tx = { ...tx, gasPrice: evmTransaction.gasPrice };
}
if (!!evmTransaction.nonce) {
tx = { ...tx, nonce: evmTransaction.nonce };
}

const tr = await signer.sendTransaction(tx);
return tr.hash;
}

// Switch network
// Make a transaction and run
// check status from server
// notif the resul
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"ethereum-waffle": "^4.0.10",
"execa": "^7.1.1",
"filesize": "^10.1.2",
"lint-staged": "^13.2.2",
Expand Down
4 changes: 1 addition & 3 deletions signers/signer-evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"@ethersproject/abstract-provider": "^5.7.0",
"eth-rpc-errors": "^4.0.3",
"ethers": "^5.7.2",
"ethers": "^6.13.2",
"rango-types": "^0.1.69"
},
"publishConfig": {
Expand Down
104 changes: 27 additions & 77 deletions signers/signer-evm/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,52 @@
import type { SignerError as SignerErrorType } from 'rango-types';

import { getMessageFromCode } from 'eth-rpc-errors';
import { isError } from 'ethers';
import {
RPCErrorCode as RangoRPCErrorCode,
SignerError,
SignerErrorCode,
} from 'rango-types';

import { MetamaskErrorCodes, RPCErrorCode, RPCErrorMessage } from './types.js';

export const cleanEvmError = (error: any): SignerErrorType => {
if (!error) {
return new SignerError(SignerErrorCode.SEND_TX_ERROR);
}

if (SignerError.isSignerError(error)) {
return error;
}
const hasMessage = Object.prototype.hasOwnProperty.call(error, 'message');
const hasCode = Object.prototype.hasOwnProperty.call(error, 'code');
if (hasMessage && hasCode) {
const { message: errorMessage, code: errorCode } = error;
// rejection error
if (
RPCErrorCode.ACTION_REJECTED === errorCode ||
MetamaskErrorCodes.provider.userRejectedRequest === errorCode
) {

if (error.code) {
if (isError(error, 'UNKNOWN_ERROR')) {
const msg = error.error?.message || error.message;
return new SignerError(
SignerErrorCode.REJECTED_BY_USER,
SignerErrorCode.SEND_TX_ERROR,
undefined,
error,
RangoRPCErrorCode.REJECTION,
msg,
RangoRPCErrorCode.UNKNOWN_ERROR,
error
);
}
if (typeof errorCode === 'number') {
// provider errors
if (Object.values(MetamaskErrorCodes.provider).includes(errorCode)) {
const msg = getMessageFromCode(errorCode);
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
msg,
RangoRPCErrorCode.UNKNOWN_ERROR,
error
);
}
// rpc errors
else if (Object.values(MetamaskErrorCodes.rpc).includes(errorCode)) {
// underpriced errors are sent as internal errors
if (
errorCode === MetamaskErrorCodes.rpc.internal &&
(errorMessage?.includes(RPCErrorMessage.UNDER_PRICED) ||
errorMessage?.includes(RPCErrorMessage.REPLACEMENT_FEE_TOO_LOW))
) {
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
'Transaction is underpriced.',
RangoRPCErrorCode.UNDER_PRICED,
error
);
}
// gas limit errors are sent as internal errors
if (
errorMessage?.includes(RPCErrorMessage.INTRINSIC_GAS_TOO_LOW) ||
errorMessage?.includes(RPCErrorMessage.OUT_OF_GAS)
) {
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
'Gas limit is low.',
RangoRPCErrorCode.OUT_OF_GAS,
error
);
}

const msg = getMessageFromCode(errorCode);
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
msg ?? error,
RangoRPCErrorCode.UNKNOWN_ERROR,
error
);
}
}
switch (errorCode) {
case RPCErrorCode.INVALID_ARGUMENT: {
const msg = (error.reason || error.message) ?? error;
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
msg,
RangoRPCErrorCode.UNKNOWN_ERROR,
error
);
}
if (isError(error, 'ACTION_REJECTED')) {
const msg = error.shortMessage.replace('action', `'${error.action}'`);
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
msg,
RangoRPCErrorCode.REJECTION,
error
);
}

const msg = error.shortMessage || error.message;
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
undefined,
msg,
RangoRPCErrorCode.UNKNOWN_ERROR,
error
);
}
return new SignerError(
SignerErrorCode.SEND_TX_ERROR,
Expand Down
Loading

0 comments on commit 3a20446

Please sign in to comment.