Skip to content

Commit 3b14cf3

Browse files
committed
feat(app): add config
1 parent 55a29b6 commit 3b14cf3

File tree

11 files changed

+569
-209
lines changed

11 files changed

+569
-209
lines changed

app2/src/lib/components/SettingsModal.svelte

Lines changed: 322 additions & 92 deletions
Large diffs are not rendered by default.

app2/src/lib/components/stake/BalanceCard.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Button from "$lib/components/ui/Button.svelte"
33
import Card from "$lib/components/ui/Card.svelte"
44
import Tabs from "$lib/components/ui/Tabs.svelte"
55
import { runPromiseExit$ } from "$lib/runtime"
6-
import { DESTINATION_CHANNEL_ID } from "$lib/stake/config"
6+
import { lstConfig } from "$lib/stake/config.svelte.ts"
77
import { predictProxy } from "$lib/stake/instantiate2"
88
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
99
import { Utils } from "@unionlabs/sdk"
@@ -78,7 +78,7 @@ const proxyDustData = runPromiseExit$(() => {
7878
Effect.gen(function*() {
7979
const proxy = yield* predictProxy({
8080
path: 0n,
81-
channel: DESTINATION_CHANNEL_ID,
81+
channel: lstConfig.DESTINATION_CHANNEL_ID,
8282
sender: address,
8383
})
8484

app2/src/lib/components/stake/BondComponent.svelte

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
66
import { runPromiseExit$ } from "$lib/runtime"
77
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
88
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
9-
import {
10-
DESTINATION_CHANNEL_ID,
11-
ETHEREUM_CHAIN_ID,
12-
SOURCE_CHANNEL_ID,
13-
UCS03_EVM_ADDRESS,
14-
UCS03_MINTER_ON_UNION,
15-
UCS03_ZKGM,
16-
UNION_CHAIN_ID,
17-
} from "$lib/stake/config"
9+
import { lstConfig } from "$lib/stake/config.svelte.ts"
1810
import { predictProxy } from "$lib/stake/instantiate2"
1911
import { type StakingRates } from "$lib/stake/schemas"
2012
import { uiStore } from "$lib/stores/ui.svelte"
@@ -64,12 +56,11 @@ import {
6456
import * as O from "effect/Option"
6557
import { graphql } from "gql.tada"
6658
import { custom } from "viem"
67-
import { mainnet } from "viem/chains"
6859
import QuickAmountButtons from "./QuickAmountButtons.svelte"
6960
import SlippageSelector from "./SlippageSelector.svelte"
7061
import StatusDisplay from "./StatusDisplay.svelte"
7162
72-
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
63+
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })
7364
7465
interface Props {
7566
evmChain: O.Option<Chain>
@@ -236,11 +227,11 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
236227
Effect.gen(function*() {
237228
// minMintAmount is already calculated with purchase rate and slippage applied
238229
239-
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
240-
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
230+
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
231+
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)
241232
const proxy = yield* predictProxy({
242233
path: 0n,
243-
channel: DESTINATION_CHANNEL_ID,
234+
channel: lstConfig.DESTINATION_CHANNEL_ID,
244235
sender,
245236
})
246237
@@ -282,7 +273,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
282273
const increaseAllowanceCall = yield* pipe(
283274
{
284275
increase_allowance: {
285-
spender: UCS03_MINTER_ON_UNION.address,
276+
spender: lstConfig.UCS03_MINTER_ON_UNION.address,
286277
amount: minMintAmount,
287278
},
288279
} as const,
@@ -319,7 +310,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
319310
Effect.flatMap(Schema.encode(Ucs03.Ucs03WithInstructionFromHex)),
320311
Effect.map((instruction) => ({
321312
send: {
322-
channel_id: DESTINATION_CHANNEL_ID,
313+
channel_id: lstConfig.DESTINATION_CHANNEL_ID,
323314
timeout_height: 0n,
324315
timeout_timestamp,
325316
salt,
@@ -330,7 +321,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
330321
Effect.map((msg) => ({
331322
wasm: {
332323
execute: {
333-
contract_addr: UCS03_ZKGM.address,
324+
contract_addr: lstConfig.UCS03_ZKGM.address,
334325
msg,
335326
funds: [],
336327
},
@@ -363,7 +354,7 @@ const executeBond = (sender: Ucs05.EvmDisplay, sendAmount: bigint, minMintAmount
363354
const request = ZkgmClientRequest.make({
364355
source: ethereumChain,
365356
destination: unionChain,
366-
channelId: SOURCE_CHANNEL_ID,
357+
channelId: lstConfig.SOURCE_CHANNEL_ID,
367358
ucs03Address: UCS03_EVM.address,
368359
instruction: batch,
369360
})
@@ -393,7 +384,18 @@ runPromiseExit$(() =>
393384
394385
bondState = BondState.SwitchingChain()
395386
396-
const VIEM_CHAIN = mainnet
387+
const VIEM_CHAIN = yield* pipe(
388+
evmChain,
389+
Effect.flatMap(chain =>
390+
pipe(
391+
chain.toViemChain(),
392+
O.match({
393+
onNone: () => Effect.fail(new Error("No viem chain available")),
394+
onSome: Effect.succeed,
395+
}),
396+
)
397+
),
398+
)
397399
398400
const connectorClient = yield* getWagmiConnectorClient
399401

app2/src/lib/components/stake/ProxyDustRecovery.svelte

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ import Button from "$lib/components/ui/Button.svelte"
33
import { runPromiseExit$ } from "$lib/runtime"
44
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
55
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
6-
import {
7-
DESTINATION_CHANNEL_ID,
8-
ETHEREUM_CHAIN_ID,
9-
SOURCE_CHANNEL_ID,
10-
UCS03_EVM_ADDRESS,
11-
UCS03_MINTER_ON_UNION,
12-
UCS03_ZKGM,
13-
UNION_CHAIN_ID,
14-
} from "$lib/stake/config"
6+
import { lstConfig } from "$lib/stake/config.svelte.ts"
157
import { predictProxy } from "$lib/stake/instantiate2"
168
import { uiStore } from "$lib/stores/ui.svelte"
179
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
@@ -37,7 +29,6 @@ import { extractErrorDetails } from "@unionlabs/sdk/utils/index"
3729
import { BigDecimal, Data, Effect, Layer, Match, pipe, Schema } from "effect"
3830
import * as O from "effect/Option"
3931
import { custom } from "viem"
40-
import { mainnet } from "viem/chains"
4132
import StatusDisplay from "./StatusDisplay.svelte"
4233
import TokenBalanceRow from "./TokenBalanceRow.svelte"
4334
@@ -62,7 +53,7 @@ const JsonFromBase64 = Schema.compose(
6253
Schema.parseJson(),
6354
)
6455
65-
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
56+
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })
6657
6758
// Dust withdrawal state machine
6859
type DustWithdrawState = Data.TaggedEnum<{
@@ -131,14 +122,14 @@ const executeDustWithdrawal = (
131122
proxyAddr: string,
132123
) =>
133124
Effect.gen(function*() {
134-
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
135-
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
125+
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
126+
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)
136127
137128
// For dust withdrawal, we need to transfer eU from proxy to user's wallet on Union
138129
// then send it to Ethereum
139130
const proxy = yield* predictProxy({
140131
path: 0n,
141-
channel: DESTINATION_CHANNEL_ID,
132+
channel: lstConfig.DESTINATION_CHANNEL_ID,
142133
sender,
143134
})
144135
@@ -149,7 +140,7 @@ const executeDustWithdrawal = (
149140
const increaseAllowanceCall = yield* pipe(
150141
{
151142
increase_allowance: {
152-
spender: UCS03_MINTER_ON_UNION.address,
143+
spender: lstConfig.UCS03_MINTER_ON_UNION.address,
153144
amount: dustAmountRaw.toString(),
154145
},
155146
} as const,
@@ -187,7 +178,7 @@ const executeDustWithdrawal = (
187178
Effect.flatMap(Schema.encode(Ucs03.Ucs03WithInstructionFromHex)),
188179
Effect.map((instruction) => ({
189180
send: {
190-
channel_id: DESTINATION_CHANNEL_ID,
181+
channel_id: lstConfig.DESTINATION_CHANNEL_ID,
191182
timeout_height: 0n,
192183
timeout_timestamp,
193184
salt,
@@ -198,7 +189,7 @@ const executeDustWithdrawal = (
198189
Effect.map((msg) => ({
199190
wasm: {
200191
execute: {
201-
contract_addr: UCS03_ZKGM.address,
192+
contract_addr: lstConfig.UCS03_ZKGM.address,
202193
msg,
203194
funds: [],
204195
},
@@ -224,7 +215,7 @@ const executeDustWithdrawal = (
224215
const request = ZkgmClientRequest.make({
225216
source: ethereumChain,
226217
destination: unionChain,
227-
channelId: SOURCE_CHANNEL_ID,
218+
channelId: lstConfig.SOURCE_CHANNEL_ID,
228219
ucs03Address: UCS03_EVM.address,
229220
instruction: batchInstruction,
230221
})
@@ -256,7 +247,19 @@ runPromiseExit$(() =>
256247
257248
dustWithdrawState = DustWithdrawState.SwitchingChain()
258249
259-
const VIEM_CHAIN = mainnet
250+
const VIEM_CHAIN = yield* pipe(
251+
evmChain,
252+
Effect.flatMap(chain =>
253+
pipe(
254+
chain.toViemChain(),
255+
O.match({
256+
onNone: () => Effect.fail(new Error("No viem chain available")),
257+
onSome: Effect.succeed,
258+
}),
259+
)
260+
),
261+
)
262+
260263
const connectorClient = yield* getWagmiConnectorClient
261264
const isSafeWallet = getLastConnectedWalletId() === "safe"
262265

app2/src/lib/components/stake/QuickWithdrawComponent.svelte

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
66
import { runPromiseExit$ } from "$lib/runtime"
77
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
88
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
9+
import { lstConfig } from "$lib/stake/config.svelte.ts"
910
import { uiStore } from "$lib/stores/ui.svelte"
1011
import { wallets as WalletStore } from "$lib/stores/wallets.svelte"
1112
import { safeOpts } from "$lib/transfer/shared/services/handlers/safe"
@@ -19,7 +20,6 @@ import { extractErrorDetails } from "@unionlabs/sdk/utils/index"
1920
import { BigDecimal, Data, Effect, Layer, Match, pipe } from "effect"
2021
import * as O from "effect/Option"
2122
import { createPublicClient, custom, http } from "viem"
22-
import { mainnet } from "viem/chains"
2323
import QuickAmountButtons from "./QuickAmountButtons.svelte"
2424
import StatusDisplay from "./StatusDisplay.svelte"
2525
@@ -132,9 +132,22 @@ const expectedUAmount = $derived<O.Option<BigDecimal.BigDecimal>>(pipe(
132132
runPromiseExit$(() =>
133133
shouldCheckActive
134134
? Effect.gen(function*() {
135+
const viemChain = yield* pipe(
136+
evmChain,
137+
Effect.flatMap(chain =>
138+
pipe(
139+
chain.toViemChain(),
140+
O.match({
141+
onNone: () => Effect.fail(new Error("No viem chain available")),
142+
onSome: Effect.succeed,
143+
}),
144+
)
145+
),
146+
)
147+
135148
const publicClient = createPublicClient({
136-
chain: mainnet,
137-
transport: http("https://rpc.1.ethereum.chain.kitchen"),
149+
chain: viemChain,
150+
transport: http(lstConfig.EVM_RPC_ENDPOINT),
138151
})
139152
140153
const active = yield* pipe(
@@ -222,7 +235,7 @@ const checkAndSubmitAllowance = (sender: `0x${string}`, sendAmount: bigint) =>
222235
Effect.tap(() => Effect.sleep("500 millis")),
223236
)
224237
225-
const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint) =>
238+
const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint, viemChain: any) =>
226239
Effect.gen(function*() {
227240
quickWithdrawState = QuickWithdrawState.ConfirmingWithdraw()
228241
@@ -238,7 +251,7 @@ const executeQuickWithdraw = (sender: `0x${string}`, sendAmount: bigint) =>
238251
functionName: "withdraw",
239252
args: [sendAmount],
240253
account: sender,
241-
chain: mainnet,
254+
chain: viemChain,
242255
})
243256
244257
quickWithdrawState = QuickWithdrawState.WithdrawSubmitted({ txHash })
@@ -279,7 +292,19 @@ runPromiseExit$(() =>
279292
280293
quickWithdrawState = QuickWithdrawState.SwitchingChain()
281294
282-
const VIEM_CHAIN = mainnet
295+
const VIEM_CHAIN = yield* pipe(
296+
evmChain,
297+
Effect.flatMap(chain =>
298+
pipe(
299+
chain.toViemChain(),
300+
O.match({
301+
onNone: () => Effect.fail(new Error("No viem chain available")),
302+
onSome: Effect.succeed,
303+
}),
304+
)
305+
),
306+
)
307+
283308
const connectorClient = yield* getWagmiConnectorClient
284309
const isSafeWallet = getLastConnectedWalletId() === "safe"
285310
@@ -311,7 +336,11 @@ runPromiseExit$(() =>
311336
Effect.tapError((error) => Effect.logError("Approval flow failed", error)),
312337
)
313338
314-
const { txHash, receivedAmount } = yield* executeQuickWithdraw(sender.address, sendAmount)
339+
const { txHash, receivedAmount } = yield* executeQuickWithdraw(
340+
sender.address,
341+
sendAmount,
342+
VIEM_CHAIN,
343+
)
315344
.pipe(
316345
Effect.provide(walletClient),
317346
Effect.provide(publicClient),

app2/src/lib/components/stake/UnbondComponent.svelte

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ import UInput from "$lib/components/ui/UInput.svelte"
66
import { runPromiseExit$ } from "$lib/runtime"
77
import { getWagmiConnectorClient } from "$lib/services/evm/clients"
88
import { switchChain } from "$lib/services/transfer-ucs03-evm/chain"
9-
import {
10-
DESTINATION_CHANNEL_ID,
11-
ETHEREUM_CHAIN_ID,
12-
SOURCE_CHANNEL_ID,
13-
UCS03_EVM_ADDRESS,
14-
UCS03_ZKGM,
15-
UNION_CHAIN_ID,
16-
} from "$lib/stake/config"
9+
import { lstConfig } from "$lib/stake/config.svelte.ts"
1710
import { predictProxy } from "$lib/stake/instantiate2"
1811
import { type StakingRates, StakingRatesSchema } from "$lib/stake/schemas"
1912
import { uiStore } from "$lib/stores/ui.svelte"
@@ -58,11 +51,10 @@ import {
5851
import * as O from "effect/Option"
5952
import { graphql } from "gql.tada"
6053
import { custom } from "viem"
61-
import { mainnet } from "viem/chains"
6254
import QuickAmountButtons from "./QuickAmountButtons.svelte"
6355
import StatusDisplay from "./StatusDisplay.svelte"
6456
65-
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: UCS03_EVM_ADDRESS })
57+
const UCS03_EVM = Ucs05.EvmDisplay.make({ address: lstConfig.UCS03_EVM_ADDRESS })
6658
6759
interface Props {
6860
evmChain: O.Option<Chain>
@@ -218,11 +210,11 @@ const checkAndSubmitAllowance = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =
218210
219211
const executeUnbond = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =>
220212
Effect.gen(function*() {
221-
const ethereumChain = yield* ChainRegistry.byUniversalId(ETHEREUM_CHAIN_ID)
222-
const unionChain = yield* ChainRegistry.byUniversalId(UNION_CHAIN_ID)
213+
const ethereumChain = yield* ChainRegistry.byUniversalId(lstConfig.ETHEREUM_CHAIN_ID)
214+
const unionChain = yield* ChainRegistry.byUniversalId(lstConfig.UNION_CHAIN_ID)
223215
const proxy = yield* predictProxy({
224216
path: 0n,
225-
channel: DESTINATION_CHANNEL_ID,
217+
channel: lstConfig.DESTINATION_CHANNEL_ID,
226218
sender,
227219
})
228220
@@ -301,7 +293,7 @@ const executeUnbond = (sender: Ucs05.EvmDisplay, sendAmount: bigint) =>
301293
const request = ZkgmClientRequest.make({
302294
source: ethereumChain,
303295
destination: unionChain,
304-
channelId: SOURCE_CHANNEL_ID,
296+
channelId: lstConfig.SOURCE_CHANNEL_ID,
305297
ucs03Address: UCS03_EVM.address,
306298
instruction: batch,
307299
})
@@ -331,7 +323,18 @@ runPromiseExit$(() =>
331323
332324
unbondState = UnbondState.SwitchingChain()
333325
334-
const VIEM_CHAIN = mainnet
326+
const VIEM_CHAIN = yield* pipe(
327+
evmChain,
328+
Effect.flatMap(chain =>
329+
pipe(
330+
chain.toViemChain(),
331+
O.match({
332+
onNone: () => Effect.fail(new Error("No viem chain available")),
333+
onSome: Effect.succeed,
334+
}),
335+
)
336+
),
337+
)
335338
336339
const connectorClient = yield* getWagmiConnectorClient
337340

0 commit comments

Comments
 (0)