Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions app2/src/lib/gasprice/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chainInfoMap } from "$lib/services/cosmos/chain-info/config"
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { createViemPublicClient } from "@unionlabs/sdk/evm"
import { type Chain, NumberFromHexString, UniversalChainId } from "@unionlabs/sdk/schema"
import {
Expand All @@ -11,11 +12,12 @@ import {
Option as O,
pipe,
Record as R,
Schedule,
Schema as S,
unsafeCoerce,
} from "effect"
import { type GetGasPriceErrorType, http } from "viem"
import type * as V from "viem"
import * as V from "viem"
import { publicActionsL2 } from "viem/op-stack"
import { GasPriceError } from "./error"
import * as GasPrice from "./service"
Expand All @@ -37,22 +39,37 @@ export class GasPriceMap extends LayerMap.Service<GasPriceMap>()("GasPriceByChai
new GasPriceError({
module: "Evm",
method: "chain",
description: "could not convert internal chain to viem chain",
description: "Could not convert internal chain to viem chain",
cause,
})
),
)

/**
* For resilience, try wagmi connector or fail eventually with viem default RPC
*/
const transport = yield* pipe(
getWagmiConnectorClient,
Effect.retry(
Schedule.compose(
Schedule.spaced("200 millis"),
Schedule.recurs(10),
),
),
Effect.map(V.custom),
Effect.orElseSucceed(() => V.http()),
)

const client = yield* pipe(
createViemPublicClient({
chain: viemChain,
transport: http(),
transport,
}),
Effect.mapError((cause) =>
new GasPriceError({
module: "Evm",
method: "of",
description: "Could not create public client.",
description: "Could not create public client",
cause,
})
),
Expand Down
5 changes: 3 additions & 2 deletions app2/src/lib/services/evm/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
createWalletClient,
type CreateWalletClientErrorType,
custom,
http,
type PublicClient,
} from "viem"
import {
Expand Down Expand Up @@ -44,6 +43,8 @@ export const getPublicClient = (chain: Chain) =>
Effect.gen(function*() {
const viemChain = chain.toViemChain()

const connectorClient = yield* getWagmiConnectorClient

if (Option.isNone(viemChain)) {
return yield* new NoViemChainError({ chain })
}
Expand All @@ -52,7 +53,7 @@ export const getPublicClient = (chain: Chain) =>
try: () =>
createPublicClient({
chain: viemChain.value,
transport: http(),
transport: custom(connectorClient),
}),
catch: err =>
new CreatePublicClientError({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { AllowanceCheckError } from "$lib/transfer/shared/errors"
import type { TransferContext } from "$lib/transfer/shared/services/filling/create-context"
import { Token, Ucs05, Utils, ZkgmClientRequest } from "@unionlabs/sdk"
Expand All @@ -7,7 +8,7 @@ import type { Chain } from "@unionlabs/sdk/schema"
import { Data, Effect, HashMap, Match, Option, pipe, Tuple } from "effect"
import * as A from "effect/Array"
import * as S from "effect/Schema"
import { type Address, http } from "viem"
import { type Address, custom, http } from "viem"

export class ApprovalStep extends Data.TaggedClass("ApprovalStep")<{
token: Token.Any
Expand Down Expand Up @@ -96,12 +97,18 @@ const handleEvmAllowances = (
> =>
Effect.gen(function*() {
const chain = yield* sourceChain.toViemChain().pipe(
Effect.mapError(() => new AllowanceCheckError({ message: "could not" })),
Effect.mapError(() => new AllowanceCheckError({ message: "Could not determine viem chain" })),
)

const connectorClient = yield* getWagmiConnectorClient.pipe(
Effect.mapError(() =>
new AllowanceCheckError({ message: "Could not determine wagmi client" })
),
)

const client = Evm.PublicClient.Live({
chain,
transport: http(),
transport: custom(connectorClient),
})

return yield* pipe(
Expand Down
34 changes: 29 additions & 5 deletions app2/src/lib/wallet/evm/wagmi-config.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const transports: Transports = {
key: "unstable_connector-injected-mainnet",
name: "unstable_connector-injected-mainnet",
}),
http(`https://rpc.1.ethereum.chain.kitchen`, {
name: "Chain Kitchen - Mainnet",
http(`https://rpc.${mainnet.id}.ethereum.chain.kitchen`, {
name: "Chain Kitchen - Ethereum",
}),
http(sepolia.rpcUrls.default.http.at(0), {
http(mainnet.rpcUrls.default.http.at(0), {
name: "default Mainnet RPC",
}),
]),
Expand All @@ -58,7 +58,7 @@ const transports: Transports = {
key: "unstable_connector-injected-sepolia",
name: "unstable_connector-injected-sepolia",
}),
http(`https://rpc.11155111.sepolia.chain.kitchen`, {
http(`https://rpc.${sepolia.id}.ethereum.chain.kitchen`, {
name: "Chain Kitchen - Sepolia",
}),
http(sepolia.rpcUrls.default.http.at(0), {
Expand All @@ -72,7 +72,7 @@ const transports: Transports = {
key: "unstable_connector-injected-holesky",
name: "unstable_connector-injected-holesky",
}),
http(`https://rpc.17000.holesky.chain.kitchen`, {
http(`https://rpc.${holesky.id}.ethereum.chain.kitchen`, {
name: "Chain Kitchen - Holesky",
}),
http(holesky.rpcUrls.default.http.at(0), {
Expand Down Expand Up @@ -119,6 +119,9 @@ const transports: Transports = {
key: "unstable_connector-injected-bob-sepolia",
name: "unstable_connector-injected-bob-sepolia",
}),
http(`https://rpc.${bobSepolia.id}.bob.chain.kitchen`, {
name: "Chain Kitchen - BOB Sepolia",
}),
http(bobSepolia.rpcUrls.default.http.at(0), {
name: "default Bob Sepolia RPC",
}),
Expand All @@ -130,6 +133,9 @@ const transports: Transports = {
key: "unstable_connector-injected-bob",
name: "unstable_connector-injected-bob",
}),
http(`https://rpc.${bob.id}.bob.chain.kitchen`, {
name: "Chain Kitchen - BOB",
}),
http(bob.rpcUrls.default.http.at(0), { name: "default Bob RPC" }),
]),
[corn.id]: fallback([
Expand All @@ -139,6 +145,9 @@ const transports: Transports = {
key: "unstable_connector-injected-corn",
name: "unstable_connector-injected-corn",
}),
http(`https://rpc.${corn.id}.corn.chain.kitchen`, {
name: "Chain Kitchen - Corn",
}),
http(corn.rpcUrls.default.http.at(0), { name: "default Corn RPC" }),
]),
[cornTestnet.id]: fallback([
Expand All @@ -148,6 +157,9 @@ const transports: Transports = {
key: "unstable_connector-injected-corn-testnet",
name: "unstable_connector-injected-corn-testnet",
}),
http(`https://rpc.${cornTestnet.id}.corn.chain.kitchen`, {
name: "Chain Kitchen - Corn Testnet",
}),
http(cornTestnet.rpcUrls.default.http.at(0), {
name: "default Corn Testnet RPC",
}),
Expand All @@ -159,6 +171,9 @@ const transports: Transports = {
key: "unstable_connector-injected-sei",
name: "unstable_connector-injected-sei",
}),
http(`https://evm-rpc.${sei.id}.sei.chain.kitchen`, {
name: "Chain Kitchen - Sei",
}),
http(sei.rpcUrls.default.http.at(0), { name: "default Sei RPC" }),
]),
[seiTestnet.id]: fallback([
Expand All @@ -168,6 +183,9 @@ const transports: Transports = {
key: "unstable_connector-injected-sei-testnet",
name: "unstable_connector-injected-sei-testnet",
}),
http(`https://evm-rpc.${seiTestnet.id}.sei.chain.kitchen`, {
name: "Chain Kitchen - Sei Testnet",
}),
http(seiTestnet.rpcUrls.default.http.at(0), { name: "default Sei Testnet RPC" }),
]),
[bsc.id]: fallback([
Expand All @@ -177,6 +195,9 @@ const transports: Transports = {
key: "unstable_connector-injected-bsc",
name: "unstable_connector-injected-bsc",
}),
http(`https://rpc.${bsc.id}.bsc.chain.kitchen`, {
name: "Chain Kitchen - BNB Chain",
}),
http(bsc.rpcUrls.default.http.at(0), { name: "default BSC RPC" }),
]),
[bscTestnet.id]: fallback([
Expand All @@ -186,6 +207,9 @@ const transports: Transports = {
key: "unstable_connector-injected-bsc-testnet",
name: "unstable_connector-injected-bsc-testnet",
}),
http(`https://rpc.${bscTestnet.id}.bsc.chain.kitchen`, {
name: "Chain Kitchen - BNB Chain Testnet",
}),
http(bscTestnet.rpcUrls.default.http.at(0), { name: "default BSC Testnet RPC" }),
]),
}
Expand Down