Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:hop-protocol/hop into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
shanefontaine committed Dec 10, 2024
2 parents 2b2ea41 + bd0df51 commit 1da60fd
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/explorer-backend/scripts/refresh_pending.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ require('dotenv').config()
const wait = require('wait')

const rateLimitToken = process.env.RATE_LIMIT_TOKEN
const token = process.argv[2] ?? ''
console.log('rateLimitToken set', !!rateLimitToken)
console.log('token', token)

async function main () {
let page = 0
Expand All @@ -11,7 +13,7 @@ async function main () {
if (page === 2) {
break
}
const url0 = `https://explorer-api.hop.exchange/v1/transfers?page=${page}&bonded=pending&rate_limit_token=${rateLimitToken}`
const url0 = `https://explorer-api.hop.exchange/v1/transfers?page=${page}&bonded=pending&rate_limit_token=${rateLimitToken}&token=${token}`
const response0 = await fetch(url0)
const json0 = await response0.json()
const transferIds = json0.data.map(transfer => transfer.transferId)
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/public/commit-transfers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script>window.location.href='../#/commit-transfers'+window.location.search</script>
2 changes: 2 additions & 0 deletions packages/frontend/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Convert = lazy(() => import(/* webpackChunkName: "Convert" */ '#pages/Conv
const Stats = lazy(() => import(/* webpackChunkName: "Stats" */ '#pages/Stats/index.js'))
const Withdraw = lazy(() => import(/* webpackChunkName: "Withdraw" */ '#pages/Withdraw/index.js'))
const Relay = lazy(() => import(/* webpackChunkName: "Relay" */ '#pages/Relay/index.js'))
const CommitTransfers = lazy(() => import(/* webpackChunkName: "CommitTransfers" */ '#pages/CommitTransfers/index.js'))
const Faucet = lazy(() => import(/* webpackChunkName: "Faucet" */ '#pages/Faucet/index.js'))
const Health = lazy(() => import(/* webpackChunkName: "Health" */ '#pages/Health/index.js'))
const Rewards = lazy(() => import(/* webpackChunkName: "Rewards" */ '#pages/Rewards/index.js'))
Expand Down Expand Up @@ -61,6 +62,7 @@ const AppRoutes: FC = () => {
<Route path="/rewards" element={<Rewards />} />
<Route path="/withdraw" element={<Withdraw />} />
<Route path="/relay" element={<Relay />} />
<Route path="/commit-transfers" element={<CommitTransfers />} />
<Route path="/health" element={<Health />} />
<Route path="/faucet" element={<Faucet />} />
<Route path="/claim/*" element={<Claim />} />
Expand Down
227 changes: 227 additions & 0 deletions packages/frontend/src/pages/CommitTransfers/CommitTransfers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import Box from '@mui/material/Box'
import React, { ChangeEvent, FC, useEffect, useState } from 'react'
import Typography from '@mui/material/Typography'
import useQueryParams from '#hooks/useQueryParams.js'
import { Alert } from '#components/Alert/index.js'
import { Button } from '#components/Button/Button.js'
import { formatError } from '#utils/format.js'
import { makeStyles } from '@mui/styles'
import { reactAppNetwork } from '#config/index.js'
import { useApp } from '#contexts/AppContext/index.js'
import { useWeb3Context } from '#contexts/Web3Context.js'
import RaisedSelect from '#components/selects/RaisedSelect.js'
import MenuItem from '@mui/material/MenuItem'
import Link from '@mui/material/Link'
import SelectOption from '#components/selects/SelectOption.js'
import { l2Networks, allNetworks } from '#config/networks.js'
import Network from '#models/Network.js'
import { findNetworkBySlug, findMatchingBridge } from '#utils/index.js'

const useStyles = makeStyles((theme: any) => ({
root: {
maxWidth: '680px',
margin: '0 auto',
},
header: {
marginBottom: '4rem',
textAlign: 'center',
},
form: {
display: 'block',
marginBottom: '4rem',
},
card: {
marginBottom: '4rem',
},
loader: {
marginTop: '2rem',
textAlign: 'center',
},
notice: {
display: 'flex',
alignItems: 'center',
flexDirection: 'column',
},
}))

export const CommitTransfers: FC = () => {
const styles = useStyles()
const { sdk, networks, txConfirm, bridges, selectedBridge, setSelectedBridge } = useApp()
const { checkConnectedNetworkId } = useWeb3Context()
const { queryParams } = useQueryParams()
const [loading, setLoading] = useState<boolean>(false)
const [error, setError] = useState<string>('')
const [success, setSuccess] = useState<string>('')
const [commitInfoMsg, setCommitInfoMsg] = useState<string>('')
const [selectedFromNetwork, setSelectedFromNetwork] = useState<Network>(() => {
try {
const selectedFromNetworkSlug = localStorage.getItem('commitTransfers:selectedFromNetwork')
if (selectedFromNetworkSlug) {
const network = findNetworkBySlug(selectedFromNetworkSlug, l2Networks)
if (network) {
return network
}
}
} catch (err: any) {
}
return l2Networks[0]
})

const [selectedToNetwork, setSelectedToNetwork] = useState<Network>(() => {
try {
const selectedToNetworkSlug = localStorage.getItem('commitTransfers:selectedToNetwork')
if (selectedToNetworkSlug) {
const network = findNetworkBySlug(selectedToNetworkSlug, allNetworks)
if (network) {
return network
}
}
} catch (err: any) {
}
return allNetworks[0]
})

useEffect(() => {
try {
localStorage.setItem('commitTransfers:selectedFromNetwork', selectedFromNetwork?.slug ?? '')
} catch (err: any) {
console.error(err)
}
}, [selectedFromNetwork])

useEffect(() => {
try {
localStorage.setItem('commitTransfers:selectedToNetwork', selectedToNetwork?.slug ?? '')
} catch (err: any) {
console.error(err)
}
}, [selectedToNetwork])

const handleBridgeChange = (event: any) => {
const tokenSymbol = event.target.value as string

const bridge = findMatchingBridge(bridges, tokenSymbol)
if (bridge) {
setSelectedBridge(bridge)
}
}

async function handleSubmit(event: ChangeEvent<any>) {
event.preventDefault()
try {
setLoading(true)
setError('')
setSuccess('')
setCommitInfoMsg('')
await new Promise((resolve, reject) => {
const run = async () => {
console.log('selectedFromNetwork', selectedFromNetwork)
const l2Wallet = await sdk.getSignerOrProvider(selectedFromNetwork.slug)
const token = selectedBridge.getTokenSymbol()
console.log('reactAppNetwork', reactAppNetwork)
console.log('l2Wallet', l2Wallet)
console.log('token', token)
const commitTxHash = '' // for debugging
if (!commitTxHash) {
const bridge = sdk.bridge(token)
const isNetworkConnected = await checkConnectedNetworkId(selectedFromNetwork.networkId)
if (!isNetworkConnected) {
throw new Error('wrong network connected')
}
const tx = await bridge.commitTransfers(selectedFromNetwork.slug, selectedToNetwork.slug)
console.log('commitTxHash', tx.hash)
setCommitInfoMsg(`Commit transfers transaction hash: ${tx.hash}`)
}
setLoading(false)
resolve(null)
}
run().catch(reject)
})
} catch (err: any) {
console.error(err)
setCommitInfoMsg('')
setError(formatError(err))
}
setLoading(false)
}

return (
<Box className={styles.root}>
<Box className={styles.header}>
<Typography variant="h4">Commit Transfers</Typography>
</Box>
<Box mb={4} justifyItems="center" style={{ opacity: 0.7 }}>
<Typography variant="body1">This is to commit the transfer root hash which is necessary for manually withdrawals.</Typography>
</Box>
<form className={styles.form} onSubmit={handleSubmit}>
<Box>

<Box mb={2} display="flex" justifyContent="center">
<Box display="flex" alignItems="center" justifyContent="center">

<RaisedSelect value={selectedBridge?.getTokenSymbol()} onChange={handleBridgeChange}>
{bridges.map(bridge => (
<MenuItem value={bridge.getTokenSymbol()} key={bridge.getTokenSymbol()}>
<SelectOption
value={bridge.getTokenSymbol()}
icon={bridge.getTokenImage()}
label={bridge.getTokenSymbol()}
/>
</MenuItem>
))}
</RaisedSelect>

<Box mr={2}></Box>

<RaisedSelect value={selectedFromNetwork?.slug} onChange={(event: any) => {
const selectedFromNetworkSlug = event.target.value as string
setSelectedFromNetwork(findNetworkBySlug(selectedFromNetworkSlug, l2Networks))
}}>
{l2Networks.map(network => (
<MenuItem value={network.slug} key={network.slug}>
<SelectOption value={network.slug} icon={network.imageUrl} label={network.name} />
</MenuItem>
))}
</RaisedSelect>
<Box ml={2} mr={2}>
<Typography variant="subtitle1">To</Typography>
</Box>

<RaisedSelect value={selectedToNetwork?.slug} onChange={(event: any) => {
const selectedToNetworkSlug = event.target.value as string
setSelectedToNetwork(findNetworkBySlug(selectedToNetworkSlug, allNetworks))
}}>
{allNetworks.map(network => (
<MenuItem value={network.slug} key={network.slug}>
<SelectOption value={network.slug} icon={network.imageUrl} label={network.name} />
</MenuItem>
))}
</RaisedSelect>

</Box>
</Box>

</Box>
<Box>
<Button onClick={handleSubmit} loading={loading} large highlighted>
Commit Transfers
</Button>
</Box>
</form>
<Box className={styles.notice} mb={2}>
<Alert severity="error">{error}</Alert>
</Box>
<Box className={styles.notice} mb={2}>
<Alert severity="success">{success}</Alert>
</Box>
{commitInfoMsg && (
<Box className={styles.notice} mb={2}>
<Alert severity="success">{commitInfoMsg}</Alert>
</Box>
)}
<Box mt={10} display="flex" justifyContent="center" style={{ opacity: 0.7 }}>
<Typography variant="body1">After the transfer root has been committed, the transfer can be relayed using the <Link href="#/relay">Relay page</Link>.</Typography>
</Box>
</Box>
)
}
3 changes: 3 additions & 0 deletions packages/frontend/src/pages/CommitTransfers/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CommitTransfers } from './CommitTransfers.js'

export default CommitTransfers
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/Convert/ConvertContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ const ConvertProvider: FC<{ children: ReactNode }> = ({ children }) => {
useEffect(() => {
const isUSDCe = sourceToken?.symbol === 'hUSDC.e' || destToken?.symbol === 'USDC.e'
if (isUSDCe && destNetwork?.isL1) {
setInfo(<>Notice: The USDC.e bonder was <Link target="_blank" rel="noopener noreferrer" href="https://twitter.com/HopProtocol/status/1765455840700694902">deprecated</Link> on March 20th, 2024. To transfer hUSDC.e to L1, <strong>you will need to wait for the full exit process (7+ days after root commit)</strong> before withdrawing. Please reach out on <Link target="_blank" rel="noopener noreferrer" href="https://discord.gg/PwCF88emV4">Discord</Link> if you have any questions.</>)
setInfo(<>Notice: The USDC.e bonder was <Link target="_blank" rel="noopener noreferrer" href="https://twitter.com/HopProtocol/status/1765455840700694902">deprecated</Link> on March 20th, 2024. To transfer hUSDC.e to L1, <strong>you will need to wait for the full exit process (7+ days after root commit)</strong> before withdrawing. After you have intiated the withdrawal on this page, you must commit the transfer root hash on the <Link href="/#/commit-transfers">Commit Transfers Page</Link> here. Please reach out on <Link target="_blank" rel="noopener noreferrer" href="https://discord.gg/PwCF88emV4">Discord</Link> if you have any questions.</>)
} else {
setInfo(null)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/Relay/Relay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const Relay: FC = () => {
}
const l1Wallet = await sdk.getSignerOrProvider(l1Network.slug)
const l2Wallet = await sdk.getSignerOrProvider(selectedNetwork.slug)
let token = selectedBridge.getTokenSymbol()
const token = selectedBridge.getTokenSymbol()
let subgraphToken = token
if (token === 'USDC.e') {
subgraphToken = 'USDC' // it needs to be USDC for graph lookups for USDC.e
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/Withdraw/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const Withdraw: FC = () => {
if (data) {
const { transactionHash, fromChain, toChain, toChainId, nonceUsed } = data
if (nonceUsed) {
reject(new Error('The withdrawal for this transfer has already been processed'))
reject(new Error('The withdrawal for this transfer has already been processed. The funds should have been received at the destination. No further action is required.'))
return
}
await txConfirm?.show({
Expand Down
9 changes: 8 additions & 1 deletion packages/sdk/src/HopBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,14 @@ export class HopBridge extends Base {
public async commitTransfers (sourceChain: TChain, destinationChain: TChain) {
sourceChain = this.toChainModel(sourceChain)
destinationChain = this.toChainModel(destinationChain)
const l2Bridge = await this.getL2Bridge(sourceChain)
let l2Bridge = await this.getL2Bridge(sourceChain)
if (sourceChain.slug === ChainSlug.Polygon) {
const address = this.getConfigAddresses(this.tokenSymbol, sourceChain)?.l2MessengerProxy
if (address) {
const provider = await this.getSignerOrProvider(sourceChain)
l2Bridge = L2_Bridge__factory.connect(address, provider)
}
}
return l2Bridge.commitTransfers(destinationChain.chainId)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stats-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hop-protocol/stats-worker",
"version": "0.0.19",
"version": "0.0.20",
"description": "Hop Protocol Stats Worker",
"author": "Authereum Labs, Inc.",
"license": "MIT",
Expand Down
7 changes: 6 additions & 1 deletion packages/stats-worker/src/YieldStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ class YieldStats {
break
}
}
if (areAllChainsMissing) {
// Temp fix to handle times when transfers don't occur for more than 24h
const lowTransferCountToken = 'rETH'
if (
areAllChainsMissing &&
token !== lowTransferCountToken
) {
delete yieldData.pools[token]
delete yieldData.optimalYield[token]
if (yieldData.stakingRewards?.[token]) {
Expand Down

0 comments on commit 1da60fd

Please sign in to comment.