Skip to content
Open
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
419 changes: 327 additions & 92 deletions app2/src/lib/components/SettingsModal.svelte

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app2/src/lib/components/stake/BalanceCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Button from "$lib/components/ui/Button.svelte"
import Card from "$lib/components/ui/Card.svelte"
import Tabs from "$lib/components/ui/Tabs.svelte"
import { runPromiseExit$ } from "$lib/runtime"
import { DESTINATION_CHANNEL_ID } from "$lib/stake/config"
import { lstConfig } from "$lib/stake/config.svelte.ts"
import { predictProxy } from "$lib/stake/instantiate2"
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
import { Utils } from "@unionlabs/sdk"
Expand Down Expand Up @@ -78,7 +78,7 @@ const proxyDustData = runPromiseExit$(() => {
Effect.gen(function*() {
const proxy = yield* predictProxy({
path: 0n,
channel: DESTINATION_CHANNEL_ID,
channel: lstConfig.DESTINATION_CHANNEL_ID,
sender: address,
})

Expand Down
40 changes: 21 additions & 19 deletions app2/src/lib/components/stake/BondComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
import { runPromiseExit$ } from "$lib/runtime"
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
import {
DESTINATION_CHANNEL_ID,
ETHEREUM_CHAIN_ID,
SOURCE_CHANNEL_ID,
UCS03_EVM_ADDRESS,
UCS03_MINTER_ON_UNION,
UCS03_ZKGM,
UNION_CHAIN_ID,
} from "$lib/stake/config"
import { lstConfig } from "$lib/stake/config.svelte.ts"
import { predictProxy } from "$lib/stake/instantiate2"
import { type StakingRates } from "$lib/stake/schemas"
import { uiStore } from "$lib/stores/ui.svelte"
Expand Down Expand Up @@ -64,12 +56,11 @@ import {
import * as O from "effect/Option"
import { graphql } from "gql.tada"
import { custom } from "viem"
import { mainnet } from "viem/chains"
import QuickAmountButtons from "./QuickAmountButtons.svelte"
import SlippageSelector from "./SlippageSelector.svelte"
import StatusDisplay from "./StatusDisplay.svelte"

const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })

interface Props {
evmChain: O.Option<Chain>
Expand Down Expand Up @@ -236,11 +227,11 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
Effect.gen(function*() {
// minMintAmount is already calculated with purchase rate and slippage applied

const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)
const proxy = yield* predictProxy({
path: 0n,
channel: DESTINATION_CHANNEL_ID,
channel: lstConfig.DESTINATION_CHANNEL_ID,
sender,
})

Expand Down Expand Up @@ -282,7 +273,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
const increaseAllowanceCall = yield* pipe(
{
increase_allowance: {
spender: UCS03_MINTER_ON_UNION.address,
spender: lstConfig.UCS03_MINTER_ON_UNION.address,
amount: minMintAmount,
},
} as const,
Expand Down Expand Up @@ -319,7 +310,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
Effect.flatMap(Schema.encode(Ucs03.Ucs03WithInstructionFromHex)),
Effect.map((instruction) => ({
send: {
channel_id: DESTINATION_CHANNEL_ID,
channel_id: lstConfig.DESTINATION_CHANNEL_ID,
timeout_height: 0n,
timeout_timestamp,
salt,
Expand All @@ -330,7 +321,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
Effect.map((msg) => ({
wasm: {
execute: {
contract_addr: UCS03_ZKGM.address,
contract_addr: lstConfig.UCS03_ZKGM.address,
msg,
funds: [],
},
Expand Down Expand Up @@ -363,7 +354,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
const request = ZkgmClientRequest.make({
source: ethereumChain,
destination: unionChain,
channelId: SOURCE_CHANNEL_ID,
channelId: lstConfig.SOURCE_CHANNEL_ID,
ucs03Address: UCS03_EVM.address,
instruction: batch,
})
Expand Down Expand Up @@ -393,7 +384,18 @@ runPromiseExit$(() =>

bondState = BondState.SwitchingChain()

const VIEM_CHAIN = mainnet
const VIEM_CHAIN = yield* pipe(
evmChain,
Effect.flatMap(chain =>
pipe(
chain.toViemChain(),
O.match({
onNone: () => Effect.fail(new Error("No viem chain available")),
onSome: Effect.succeed,
}),
)
),
)

const connectorClient = yield* getWagmiConnectorClient

Expand Down
41 changes: 22 additions & 19 deletions app2/src/lib/components/stake/ProxyDustRecovery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import Button from "$lib/components/ui/Button.svelte"
import { runPromiseExit$ } from "$lib/runtime"
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
import {
DESTINATION_CHANNEL_ID,
ETHEREUM_CHAIN_ID,
SOURCE_CHANNEL_ID,
UCS03_EVM_ADDRESS,
UCS03_MINTER_ON_UNION,
UCS03_ZKGM,
UNION_CHAIN_ID,
} from "$lib/stake/config"
import { lstConfig } from "$lib/stake/config.svelte.ts"
import { predictProxy } from "$lib/stake/instantiate2"
import { uiStore } from "$lib/stores/ui.svelte"
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
Expand All @@ -37,7 +29,6 @@ import { extractErrorDetails } from "@unionlabs/sdk/utils/index"
import { BigDecimal, Data, Effect, Layer, Match, pipe, Schema } from "effect"
import * as O from "effect/Option"
import { custom } from "viem"
import { mainnet } from "viem/chains"
import StatusDisplay from "./StatusDisplay.svelte"
import TokenBalanceRow from "./TokenBalanceRow.svelte"

Expand All @@ -62,7 +53,7 @@ const JsonFromBase64 = Schema.compose(
Schema.parseJson(),
)

const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })

// Dust withdrawal state machine
type DustWithdrawState = Data.TaggedEnum<{
Expand Down Expand Up @@ -131,14 +122,14 @@ const executeDustWithdrawal = (
proxyAddr: string,
) =>
Effect.gen(function*() {
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)

// For dust withdrawal, we need to transfer eU from proxy to user's wallet on Union
// then send it to Ethereum
const proxy = yield* predictProxy({
path: 0n,
channel: DESTINATION_CHANNEL_ID,
channel: lstConfig.DESTINATION_CHANNEL_ID,
sender,
})

Expand All @@ -149,7 +140,7 @@ const executeDustWithdrawal = (
const increaseAllowanceCall = yield* pipe(
{
increase_allowance: {
spender: UCS03_MINTER_ON_UNION.address,
spender: lstConfig.UCS03_MINTER_ON_UNION.address,
amount: dustAmountRaw.toString(),
},
} as const,
Expand Down Expand Up @@ -187,7 +178,7 @@ const executeDustWithdrawal = (
Effect.flatMap(Schema.encode(Ucs03.Ucs03WithInstructionFromHex)),
Effect.map((instruction) => ({
send: {
channel_id: DESTINATION_CHANNEL_ID,
channel_id: lstConfig.DESTINATION_CHANNEL_ID,
timeout_height: 0n,
timeout_timestamp,
salt,
Expand All @@ -198,7 +189,7 @@ const executeDustWithdrawal = (
Effect.map((msg) => ({
wasm: {
execute: {
contract_addr: UCS03_ZKGM.address,
contract_addr: lstConfig.UCS03_ZKGM.address,
msg,
funds: [],
},
Expand All @@ -224,7 +215,7 @@ const executeDustWithdrawal = (
const request = ZkgmClientRequest.make({
source: ethereumChain,
destination: unionChain,
channelId: SOURCE_CHANNEL_ID,
channelId: lstConfig.SOURCE_CHANNEL_ID,
ucs03Address: UCS03_EVM.address,
instruction: batchInstruction,
})
Expand Down Expand Up @@ -256,7 +247,19 @@ runPromiseExit$(() =>

dustWithdrawState = DustWithdrawState.SwitchingChain()

const VIEM_CHAIN = mainnet
const VIEM_CHAIN = yield* pipe(
evmChain,
Effect.flatMap(chain =>
pipe(
chain.toViemChain(),
O.match({
onNone: () => Effect.fail(new Error("No viem chain available")),
onSome: Effect.succeed,
}),
)
),
)

const connectorClient = yield* getWagmiConnectorClient
const isSafeWallet = getLastConnectedWalletId() === "safe"

Expand Down
43 changes: 36 additions & 7 deletions app2/src/lib/components/stake/QuickWithdrawComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
import { runPromiseExit$ } from "$lib/runtime"
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
import { lstConfig } from "$lib/stake/config.svelte.ts"
import { uiStore } from "$lib/stores/ui.svelte"
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
import { safeOpts } from "$lib/transfer/shared/services/handlers/safe"
Expand All @@ -19,7 +20,6 @@ import { extractErrorDetails } from "@unionlabs/sdk/utils/index"
import { BigDecimal, Data, Effect, Layer, Match, pipe } from "effect"
import * as O from "effect/Option"
import { createPublicClient, custom, http } from "viem"
import { mainnet } from "viem/chains"
import QuickAmountButtons from "./QuickAmountButtons.svelte"
import StatusDisplay from "./StatusDisplay.svelte"

Expand Down Expand Up @@ -132,9 +132,22 @@ const expectedUAmount = $derived<O.Option<BigDecimal.BigDecimal>>(pipe(
runPromiseExit$(() =>
shouldCheckActive
? Effect.gen(function*() {
const viemChain = yield* pipe(
evmChain,
Effect.flatMap(chain =>
pipe(
chain.toViemChain(),
O.match({
onNone: () => Effect.fail(new Error("No viem chain available")),
onSome: Effect.succeed,
}),
)
),
)

const publicClient = createPublicClient({
chain: mainnet,
transport: http("https://rpc.1.ethereum.chain.kitchen"),
chain: viemChain,
transport: http(lstConfig.EVM_RPC_ENDPOINT),
})

const active = yield* pipe(
Expand Down Expand Up @@ -222,7 +235,7 @@ const checkAndSubmitAllowance = (sender: `0x${string}`, sendAmount: bigint) =>
Effect.tap(() => Effect.sleep("500 millis")),
)

const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint) =>
const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint, viemChain: any) =>
Effect.gen(function*() {
quickWithdrawState = QuickWithdrawState.ConfirmingWithdraw()

Expand All @@ -238,7 +251,7 @@ const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint) =>
functionName: "withdraw",
args: [sendAmount],
account: sender,
chain: mainnet,
chain: viemChain,
})

quickWithdrawState = QuickWithdrawState.WithdrawSubmitted({ txHash })
Expand Down Expand Up @@ -279,7 +292,19 @@ runPromiseExit$(() =>

quickWithdrawState = QuickWithdrawState.SwitchingChain()

const VIEM_CHAIN = mainnet
const VIEM_CHAIN = yield* pipe(
evmChain,
Effect.flatMap(chain =>
pipe(
chain.toViemChain(),
O.match({
onNone: () => Effect.fail(new Error("No viem chain available")),
onSome: Effect.succeed,
}),
)
),
)

const connectorClient = yield* getWagmiConnectorClient
const isSafeWallet = getLastConnectedWalletId() === "safe"

Expand Down Expand Up @@ -311,7 +336,11 @@ runPromiseExit$(() =>
Effect.tapError((error) => Effect.logError("Approval flow failed", error)),
)

const { txHash, receivedAmount } = yield* executeQuickWithdraw(sender.address, sendAmount)
const { txHash, receivedAmount } = yield* executeQuickWithdraw(
sender.address,
sendAmount,
VIEM_CHAIN,
)
.pipe(
Effect.provide(walletClient),
Effect.provide(publicClient),
Expand Down
33 changes: 18 additions & 15 deletions app2/src/lib/components/stake/UnbondComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
import { runPromiseExit$ } from "$lib/runtime"
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
import {
DESTINATION_CHANNEL_ID,
ETHEREUM_CHAIN_ID,
SOURCE_CHANNEL_ID,
UCS03_EVM_ADDRESS,
UCS03_ZKGM,
UNION_CHAIN_ID,
} from "$lib/stake/config"
import { lstConfig } from "$lib/stake/config.svelte.ts"
import { predictProxy } from "$lib/stake/instantiate2"
import { type StakingRates, StakingRatesSchema } from "$lib/stake/schemas"
import { uiStore } from "$lib/stores/ui.svelte"
Expand Down Expand Up @@ -58,11 +51,10 @@ import {
import * as O from "effect/Option"
import { graphql } from "gql.tada"
import { custom } from "viem"
import { mainnet } from "viem/chains"
import QuickAmountButtons from "./QuickAmountButtons.svelte"
import StatusDisplay from "./StatusDisplay.svelte"

const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })

interface Props {
evmChain: O.Option<Chain>
Expand Down Expand Up @@ -218,11 +210,11 @@ const checkAndSubmitAllowance = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =

const executeUnbond = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =>
Effect.gen(function*() {
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)
const proxy = yield* predictProxy({
path: 0n,
channel: DESTINATION_CHANNEL_ID,
channel: lstConfig.DESTINATION_CHANNEL_ID,
sender,
})

Expand Down Expand Up @@ -301,7 +293,7 @@ const executeUnbond = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =>
const request = ZkgmClientRequest.make({
source: ethereumChain,
destination: unionChain,
channelId: SOURCE_CHANNEL_ID,
channelId: lstConfig.SOURCE_CHANNEL_ID,
ucs03Address: UCS03_EVM.address,
instruction: batch,
})
Expand Down Expand Up @@ -331,7 +323,18 @@ runPromiseExit$(() =>

unbondState = UnbondState.SwitchingChain()

const VIEM_CHAIN = mainnet
const VIEM_CHAIN = yield* pipe(
evmChain,
Effect.flatMap(chain =>
pipe(
chain.toViemChain(),
O.match({
onNone: () => Effect.fail(new Error("No viem chain available")),
onSome: Effect.succeed,
}),
)
),
)

const connectorClient = yield* getWagmiConnectorClient

Expand Down
Loading