From e3955ecd91ebb52bd1d3b52b5860281d0e6a8bb3 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Thu, 10 Aug 2023 12:31:51 -0700 Subject: [PATCH 1/2] . --- packages/bridge-ui/src/bridge/ERC20Bridge.ts | 2 + packages/bridge-ui/src/proof/ProofService.ts | 3 ++ .../utils/checkIfTokenIsDeployedCrossChain.ts | 4 ++ .../bridge-ui/src/utils/getAddressForToken.ts | 2 +- packages/bridge-ui/src/wagmi/watcher.ts | 4 +- .../src/components/Rewards/Rewards.svelte | 12 ++++++ .../StakeForm.svelte/StakeForm.svelte | 7 ++++ .../pos-dashboard/src/utils/switchNetwork.ts | 38 ------------------- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/packages/bridge-ui/src/bridge/ERC20Bridge.ts b/packages/bridge-ui/src/bridge/ERC20Bridge.ts index c098783fb3c..7ec4da0ae36 100644 --- a/packages/bridge-ui/src/bridge/ERC20Bridge.ts +++ b/packages/bridge-ui/src/bridge/ERC20Bridge.ts @@ -59,6 +59,8 @@ export class ERC20Bridge implements Bridge { message.gasLimit = message.gasLimit.add(BigNumber.from(3000000)); } + console.log('isBridgedalreadydeployed', opts.isBridgedTokenAlreadyDeployed); + log('Preparing transaction with message:', message); return { contract, owner, message }; diff --git a/packages/bridge-ui/src/proof/ProofService.ts b/packages/bridge-ui/src/proof/ProofService.ts index a7b4ef126a0..967d2ed4f34 100644 --- a/packages/bridge-ui/src/proof/ProofService.ts +++ b/packages/bridge-ui/src/proof/ProofService.ts @@ -91,6 +91,9 @@ export class ProofService implements Prover { ]); log('Proof from eth_getProof', proof); + log('ProofOpts', opts); + log('Key', key); + log('Proof value', proof.storageProof[0].value); if (proof.storageProof[0].value !== '0x1') { throw Error('invalid proof'); diff --git a/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts b/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts index 0e4c4f022c2..7a7bc48605c 100644 --- a/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts +++ b/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts @@ -23,6 +23,8 @@ export const checkIfTokenIsDeployedCrossChain = async ( ); const tokenAddressOnDestChain = token.addresses[destChain.id]; + console.log('token', token); + console.log('tokenAddressOnDestChain', tokenAddressOnDestChain); if (tokenAddressOnDestChain === '0x00') { // Check if token is already deployed as BridgedERC20 on destination chain @@ -56,6 +58,8 @@ export const checkIfTokenIsDeployedCrossChain = async ( }, ); } + } else { + return true; } } return false; diff --git a/packages/bridge-ui/src/utils/getAddressForToken.ts b/packages/bridge-ui/src/utils/getAddressForToken.ts index 565d9e73e9a..e42d3a722d7 100644 --- a/packages/bridge-ui/src/utils/getAddressForToken.ts +++ b/packages/bridge-ui/src/utils/getAddressForToken.ts @@ -19,7 +19,7 @@ export async function getAddressForToken( // Get the address for the token on the source chain let address = token.addresses[srcChain.id]; - // If the token isn't ETH or has no address... + // If the token isn't ETH and has no address... if (!isETH(token) && (!address || address === '0x00')) { // Find the address on the destination chain instead const destChainAddress = token.addresses[destChain.id]; diff --git a/packages/bridge-ui/src/wagmi/watcher.ts b/packages/bridge-ui/src/wagmi/watcher.ts index 73f786e08a2..d5487fa805c 100644 --- a/packages/bridge-ui/src/wagmi/watcher.ts +++ b/packages/bridge-ui/src/wagmi/watcher.ts @@ -17,12 +17,12 @@ const setChain = (chainId: number) => { srcChain.set(L1Chain); destChain.set(L2Chain); - log(`Network swtiched to ${L1Chain.name}`); + log(`Network switched to ${L1Chain.name}`); } else if (chainId === L2Chain.id) { srcChain.set(L2Chain); destChain.set(L1Chain); - log(`Network swtiched to ${L2Chain.name}`); + log(`Network switched to ${L2Chain.name}`); } else { isSwitchChainModalOpen.set(true); } diff --git a/packages/pos-dashboard/src/components/Rewards/Rewards.svelte b/packages/pos-dashboard/src/components/Rewards/Rewards.svelte index e8227beaea7..0ec283c1b07 100644 --- a/packages/pos-dashboard/src/components/Rewards/Rewards.svelte +++ b/packages/pos-dashboard/src/components/Rewards/Rewards.svelte @@ -8,6 +8,10 @@ import { successToast } from '../NotificationToast.svelte'; import { pendingTransactions } from '../../store/transaction'; import { getTTKOBalance } from '../../utils/getTTKOBalance'; + import { switchNetwork } from '../../utils/switchNetwork'; + import { mainnetChain } from '../../chain/chains'; + import { srcChain } from '../../store/chain'; + let balance: BigNumber = BigNumber.from(0); let ttkoBalanceInWei: BigNumber = BigNumber.from(0); @@ -37,6 +41,10 @@ } async function withdraw() { + if ($srcChain.id !== mainnetChain.id) { + await switchNetwork(mainnetChain.id); + } + const tx = await withdrawTaikoToken( $signer, TAIKO_L1_ADDRESS, @@ -60,6 +68,10 @@ } async function deposit() { + if ($srcChain.id !== mainnetChain.id) { + await switchNetwork(mainnetChain.id); + } + const tx = await depositTaikoToken( $signer, TAIKO_L1_ADDRESS, diff --git a/packages/pos-dashboard/src/components/StakeForm.svelte/StakeForm.svelte b/packages/pos-dashboard/src/components/StakeForm.svelte/StakeForm.svelte index 9ad1e5ca762..9ed51dbb692 100644 --- a/packages/pos-dashboard/src/components/StakeForm.svelte/StakeForm.svelte +++ b/packages/pos-dashboard/src/components/StakeForm.svelte/StakeForm.svelte @@ -7,6 +7,10 @@ import { successToast } from '../NotificationToast.svelte'; import { pendingTransactions } from '../../store/transaction'; import { getProverRequirements } from '../../utils/getProverRequirements'; + import { switchNetwork } from '../../utils/switchNetwork'; + import { mainnetChain } from '../../chain/chains'; + import { srcChain } from '../../store/chain'; + import { mainnet } from 'wagmi'; let ttkoBalanceInWei: BigNumber = BigNumber.from(0); let amount: string = '0'; let rewardPerGas: number = 0; @@ -42,6 +46,9 @@ } async function submitForm() { + if ($srcChain.id !== mainnetChain.id) { + await switchNetwork(mainnetChain.id); + } const tx = await stake( $signer, PROVER_POOL_ADDRESS, diff --git a/packages/pos-dashboard/src/utils/switchNetwork.ts b/packages/pos-dashboard/src/utils/switchNetwork.ts index 1e531c99598..92954950e73 100644 --- a/packages/pos-dashboard/src/utils/switchNetwork.ts +++ b/packages/pos-dashboard/src/utils/switchNetwork.ts @@ -1,43 +1,5 @@ -import { get } from 'svelte/store'; import { switchNetwork as wagmiSwitchNetwork } from 'wagmi/actions'; -import { srcChain } from '../store/chain'; -import { Deferred } from './Deferred'; - export async function switchNetwork(chainId: number) { - const prevChainId = get(srcChain)?.id; - - if (prevChainId === chainId) return; - await wagmiSwitchNetwork({ chainId }); - - // What are we doing here? we have a watcher waiting for network changes. - // When this happens this watcher is called and takes care of setting - // the signer and chains in the store. We are actually waiting here - // for these stores to change due to some race conditions in the UI. - // There will be a better design around this in alpha-4: fewer stores - // and '$:' tags. They're evil. - const deferred = new Deferred(); - - // This will prevent an unlikely infinite loop - const starting = Date.now(); - const timeout = 5000; // TODO: config? - - const waitForNetworkChange = () => { - const srcChainId = get(srcChain)?.id; - - if (srcChainId && srcChainId !== prevChainId) { - // We have finally set the chain in the store. We're done here. - deferred.resolve(); - } else if (Date.now() > starting + timeout) { - // Wait, what??? - deferred.reject(new Error('timeout switching network')); - } else { - setTimeout(waitForNetworkChange, 300); // TODO: config those 300? - } - }; - - waitForNetworkChange(); - - return deferred.promise; } From 47c6aeec9b3d5120176269442920e95e852530b0 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Thu, 10 Aug 2023 13:05:31 -0700 Subject: [PATCH 2/2] rm logs --- packages/bridge-ui/src/bridge/ERC20Bridge.ts | 2 -- .../bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts | 2 -- packages/pos-dashboard/src/components/Events/History.svelte | 2 -- packages/pos-dashboard/src/components/Tabs/TabPanel.svelte | 1 - 4 files changed, 7 deletions(-) diff --git a/packages/bridge-ui/src/bridge/ERC20Bridge.ts b/packages/bridge-ui/src/bridge/ERC20Bridge.ts index 7ec4da0ae36..c098783fb3c 100644 --- a/packages/bridge-ui/src/bridge/ERC20Bridge.ts +++ b/packages/bridge-ui/src/bridge/ERC20Bridge.ts @@ -59,8 +59,6 @@ export class ERC20Bridge implements Bridge { message.gasLimit = message.gasLimit.add(BigNumber.from(3000000)); } - console.log('isBridgedalreadydeployed', opts.isBridgedTokenAlreadyDeployed); - log('Preparing transaction with message:', message); return { contract, owner, message }; diff --git a/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts b/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts index 7a7bc48605c..add6316154d 100644 --- a/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts +++ b/packages/bridge-ui/src/utils/checkIfTokenIsDeployedCrossChain.ts @@ -23,8 +23,6 @@ export const checkIfTokenIsDeployedCrossChain = async ( ); const tokenAddressOnDestChain = token.addresses[destChain.id]; - console.log('token', token); - console.log('tokenAddressOnDestChain', tokenAddressOnDestChain); if (tokenAddressOnDestChain === '0x00') { // Check if token is already deployed as BridgedERC20 on destination chain diff --git a/packages/pos-dashboard/src/components/Events/History.svelte b/packages/pos-dashboard/src/components/Events/History.svelte index a8ac4b563de..8a2f2fe0fd5 100644 --- a/packages/pos-dashboard/src/components/Events/History.svelte +++ b/packages/pos-dashboard/src/components/Events/History.svelte @@ -28,9 +28,7 @@ if (!allEvents) return []; const start = (page - 1) * pageSize; const end = start + pageSize; - console.log('total items', totalItems); const ret = allEvents.slice(start, end); - console.log(ret); return ret; } diff --git a/packages/pos-dashboard/src/components/Tabs/TabPanel.svelte b/packages/pos-dashboard/src/components/Tabs/TabPanel.svelte index 8a04d4ec81b..b5e68a87f7f 100644 --- a/packages/pos-dashboard/src/components/Tabs/TabPanel.svelte +++ b/packages/pos-dashboard/src/components/Tabs/TabPanel.svelte @@ -13,7 +13,6 @@ activeTab = getContext>(key); } else { activeTab = getContext>(subKey); - console.log('EYY', tab, activeTab); } $: selected = tab === $activeTab;