Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/distributed-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
alecdwm committed Nov 14, 2023
2 parents 6e39409 + 6e29f20 commit 1581274
Show file tree
Hide file tree
Showing 161 changed files with 5,042 additions and 4,189 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-toys-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talismn/chain-connector": patch
---

Improved error handling in Websocket connector
8 changes: 8 additions & 0 deletions .changeset/moody-moons-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@talismn/balances-evm-native": patch
"@talismn/chain-connector-evm": patch
"@talismn/balances-evm-erc20": patch
"@talismn/util": patch
---

replace ethers by viem
6 changes: 6 additions & 0 deletions .changeset/quiet-papayas-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@talismn/chain-connector": patch
"@talismn/util": patch
---

Error handling improvements
6 changes: 6 additions & 0 deletions .changeset/witty-spiders-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@talismn/chain-connector-evm": minor
"@talismn/on-chain-id": minor
---

replace ethers by viem
6 changes: 4 additions & 2 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"@babel/eslint-parser": "^7.19.1",
"@dnd-kit/core": "6.0.7",
"@dnd-kit/sortable": "7.0.2",
"@eth-optimism/contracts-ts": "^0.17.0",
"@ethereumjs/util": "8.0.3",
"@floating-ui/react": "0.24.3",
"@floating-ui/react-dom": "2.0.1",
"@headlessui/react": "1.7.13",
"@hookform/resolvers": "2.9.11",
"@ledgerhq/hw-app-eth": "6.33.3",
"@ledgerhq/hw-app-eth": "6.34.8",
"@ledgerhq/hw-transport-webusb": "6.27.14",
"@metamask/browser-passworder": "4.1.0",
"@metamask/eth-sig-util": "5.1.0",
Expand Down Expand Up @@ -92,7 +93,6 @@
"dotenv-webpack": "^7.1.1",
"downshift": "^6.1.12",
"eth-phishing-detect": "latest",
"ethers": "5.7.2",
"fork-ts-checker-notifier-webpack-plugin": "^6.0.0",
"fork-ts-checker-webpack-plugin": "^7.2.14",
"framer-motion": "10.12.18",
Expand Down Expand Up @@ -129,6 +129,7 @@
"scale-codec": "^0.11.0",
"semver": "^7.5.4",
"style-loader": "3.3.3",
"subshape": "^0.14.0",
"talisman-ui": "workspace:*",
"terser-webpack-plugin": "5.3.9",
"toml": "^3.0.0",
Expand All @@ -137,6 +138,7 @@
"typescript": "^5.2.2",
"url-join": "^5.0.0",
"uuid": "^8.3.2",
"viem": "^1.18.9",
"webextension-polyfill": "0.8.0",
"webpack": "^5.88.1",
"webpack-cli": "^4.10.0",
Expand Down
8 changes: 3 additions & 5 deletions apps/extension/src/@talisman/util/formatEthValue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { formatDecimals } from "@talismn/util"
import { BigNumber, BigNumberish } from "ethers"
import { formatUnits } from "ethers/lib/utils"
import { formatDecimals, planckToTokens } from "@talismn/util"

export const formatEtherValue = (value: BigNumberish, decimals: number, symbol?: string) => {
return `${formatDecimals(formatUnits(BigNumber.from(value), decimals))}${
export const formatEthValue = (value: bigint, decimals: number, symbol?: string) => {
return `${formatDecimals(planckToTokens(value.toString(), decimals))}${
symbol ? ` ${symbol}` : ""
}`
}
4 changes: 4 additions & 0 deletions apps/extension/src/core/config/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const initSentry = (sentry: typeof SentryBrowser | typeof SentryReact) =>
release: process.env.RELEASE,
sampleRate: 1,
maxBreadcrumbs: 20,
ignoreErrors: [
/(No window with id: )(\d+).?/,
/(disconnected from wss)[(]?:\/\/[\w./:-]+: \d+:: Normal Closure[)]?/,
],
// prevents sending the event if user has disabled error tracking
beforeSend: async (event) => ((await firstValueFrom(useErrorTracking)) ? event : null),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/core/domains/accounts/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ export default class AccountsHandler extends ExtensionHandler {
const { err, val } = await getPairForAddressSafely(address, async (pair) => {
assert(pair.type === "ethereum", "Private key cannot be exported for this account type")

const pk = getPrivateKey(pair, pw as string)
const pk = getPrivateKey(pair, pw as string, "hex")

talismanAnalytics.capture("account export", { type: pair.type, mode: "pk" })

return pk.toString("hex")
return pk
})

if (err) throw new Error(val as string)
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/core/domains/encrypt/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class EncryptHandler extends ExtensionHandler {
const pw = this.stores.password.getPassword()
assert(pw, "Unable to retreive password from store.")

const pk = getPrivateKey(pair, pw)
const pk = getPrivateKey(pair, pw, "u8a")
const kp = { publicKey: pair.publicKey, secretKey: u8aToU8a(pk) } as Keypair

assert(kp.secretKey.length === 64, "Talisman secretKey is incorrect length")
Expand Down Expand Up @@ -66,7 +66,7 @@ export default class EncryptHandler extends ExtensionHandler {
const pw = this.stores.password.getPassword()
assert(pw, "Unable to retreive password from store.")

const pk = getPrivateKey(pair, pw)
const pk = getPrivateKey(pair, pw, "u8a")

assert(pk.length === 64, "Talisman secretKey is incorrect length")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from "ethers"
import { parseGwei } from "viem"

import {
getEthDerivationPath,
Expand All @@ -8,78 +8,71 @@ import {
isSafeImageUrl,
} from "../helpers"

const baseFeePerGas = ethers.utils.parseUnits("2", "gwei")
const maxPriorityFeePerGas = ethers.utils.parseUnits("8", "gwei")
const baseFeePerGas = parseGwei("2")
const maxPriorityFeePerGas = parseGwei("8")

describe("Test ethereum helpers", () => {
test("getMaxFeePerGas 0 block", async () => {
const result = getMaxFeePerGas(baseFeePerGas, maxPriorityFeePerGas, 0).toString()
const expected = ethers.utils.parseUnits("10", "gwei").toString()
const result = getMaxFeePerGas(baseFeePerGas, maxPriorityFeePerGas, 0)
const expected = parseGwei("10")

expect(result).toEqual(expected)
})

test("getMaxFeePerGas 8 block", async () => {
const result = getMaxFeePerGas(baseFeePerGas, maxPriorityFeePerGas, 8).toString()
const expected = ethers.utils.parseUnits("13131569026", "wei").toString()
const result = getMaxFeePerGas(baseFeePerGas, maxPriorityFeePerGas, 8)

expect(result).toEqual(expected)
expect(result).toEqual(13131569026n)
})

test("getTotalFeesFromGasSettings - EIP1559 maxFee lower than baseFee", () => {
const { estimatedFee, maxFee } = getTotalFeesFromGasSettings(
{
type: 2,
maxFeePerGas: ethers.utils.parseUnits("1.5", "gwei"),
maxPriorityFeePerGas: ethers.utils.parseUnits("0.5", "gwei"),
gasLimit: 22000,
type: "eip1559",
maxFeePerGas: parseGwei("1.5"),
maxPriorityFeePerGas: parseGwei("0.5"),
gas: 22000n,
},
21000,
baseFeePerGas
) //

const expectedEstimatedFee = ethers.utils.parseUnits("42000000000000", "wei").toString()
const expectedMaxFee = ethers.utils.parseUnits("44000000000000", "wei").toString()
21000n,
baseFeePerGas,
0n
)

expect(estimatedFee.toString()).toEqual(expectedEstimatedFee)
expect(maxFee.toString()).toEqual(expectedMaxFee)
expect(estimatedFee).toEqual(42000000000000n)
expect(maxFee).toEqual(44000000000000n)
})

test("getTotalFeesFromGasSettings - EIP1559 classic", () => {
const { estimatedFee, maxFee } = getTotalFeesFromGasSettings(
{
type: 2,
maxFeePerGas: ethers.utils.parseUnits("3.5", "gwei"),
maxPriorityFeePerGas: ethers.utils.parseUnits("0.5", "gwei"),
gasLimit: 22000,
type: "eip1559",
maxFeePerGas: parseGwei("3.5"),
maxPriorityFeePerGas: parseGwei("0.5"),
gas: 22000n,
},
21000,
baseFeePerGas
21000n,
baseFeePerGas,
0n
)

const expectedEstimatedFee = ethers.utils.parseUnits("52500000000000", "wei").toString()
const expectedMaxFee = ethers.utils.parseUnits("88000000000000", "wei").toString()

expect(estimatedFee.toString()).toEqual(expectedEstimatedFee)
expect(maxFee.toString()).toEqual(expectedMaxFee)
expect(estimatedFee).toEqual(52500000000000n)
expect(maxFee).toEqual(88000000000000n)
})

test("getTotalFeesFromGasSettings - Legacy", () => {
const { estimatedFee, maxFee } = getTotalFeesFromGasSettings(
{
type: 0,
gasPrice: baseFeePerGas.add(maxPriorityFeePerGas),
gasLimit: 22000,
type: "legacy",
gasPrice: baseFeePerGas + maxPriorityFeePerGas,
gas: 22000n,
},
21000,
baseFeePerGas
21000n,
baseFeePerGas,
0n
)

const expectedEstimatedFee = ethers.utils.parseUnits("210000", "gwei").toString()
const expectedMaxFee = ethers.utils.parseUnits("220000", "gwei").toString()

expect(estimatedFee.toString()).toEqual(expectedEstimatedFee)
expect(maxFee.toString()).toEqual(expectedMaxFee)
expect(estimatedFee).toEqual(parseGwei("210000"))
expect(maxFee).toEqual(parseGwei("220000"))
})

test("getEthDerivationPath", () => {
Expand Down
Loading

0 comments on commit 1581274

Please sign in to comment.