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
45 changes: 43 additions & 2 deletions packages/hyperliquid-composer/src/commands/link-evm-core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createModuleLogger, setDefaultLogLevel } from '@layerzerolabs/io-devtools'
import inquirer from 'inquirer'

import { getCoreSpotDeployment, writeUpdatedCoreSpotDeployment } from '@/io/parser'
import {
getCoreSpotDeployment,
getERC20abi,
writeNativeSpotConnected,
writeUpdatedCoreSpotDeployment,
} from '@/io/parser'
import { getHyperliquidSigner } from '@/signer'
import { setRequestEvmContract, setFinalizeEvmContract } from '@/operations'
import { LOGGER_MODULES } from '@/types/cli-constants'
Expand Down Expand Up @@ -48,13 +53,49 @@ export async function requestEvmContract(args: RequestEvmContractArgs): Promise<

logger.verbose(`txData: \n ${JSON.stringify(txData, null, 2)}`)

const rpcUrl = isTestnet ? RPC_URLS.TESTNET : RPC_URLS.MAINNET
try {
const provider = new ethers.providers.JsonRpcProvider({ url: rpcUrl, skipFetchSetup: true })
const tokenAbi = await getERC20abi()
const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, provider)
const onChainDecimals = Number(await tokenContract.decimals())
const weiDecimals = coreSpotDeployment.coreSpot.weiDecimals
const expectedWeiDiff = onChainDecimals - weiDecimals

if (txData.weiDiff !== expectedWeiDiff) {
logger.warn(`WARNING: txData.weiDiff (${txData.weiDiff}) does not match on-chain calculation`)
logger.warn(` ERC20 decimals (on-chain): ${onChainDecimals}`)
logger.warn(` HyperCore weiDecimals: ${weiDecimals}`)
logger.warn(` Expected evmExtraWeiDecimals: ${expectedWeiDiff}`)
logger.warn(` Stored evmExtraWeiDecimals: ${txData.weiDiff}`)

const { useCorrectValue } = await inquirer.prompt([
{
type: 'confirm',
name: 'useCorrectValue',
message: `Use on-chain derived value (${expectedWeiDiff}) instead of stored value (${txData.weiDiff})?`,
default: true,
},
])

if (useCorrectValue) {
txData.weiDiff = expectedWeiDiff
writeNativeSpotConnected(hyperAssetIndex, isTestnet, txData.connected, txData.weiDiff, logger)
logger.info(`Updated weiDiff to ${expectedWeiDiff} in deployment file`)
}
}
} catch (error) {
logger.warn(`Failed to fetch on-chain decimals: ${error instanceof Error ? error.message : error}`)
logger.warn(`Proceeding with stored txData.weiDiff (${txData.weiDiff}) without on-chain validation`)
}

const hyperAssetIndexInt = parseInt(hyperAssetIndex)

const { executeTx } = await inquirer.prompt([
{
type: 'confirm',
name: 'executeTx',
message: `Trying to populate a request to connect HyperCore-EVM ${hyperAssetIndex} to ${tokenAddress}. This should be sent by the Spot Deployer and before finalizeEvmContract is executed. Do you want to execute the transaction?`,
message: `Connect HyperCore-EVM ${hyperAssetIndex} to ${tokenAddress} with evmExtraWeiDecimals=${txData.weiDiff}. This value is IRREVERSIBLE after finalization. Continue?`,
default: false,
},
])
Expand Down
9 changes: 8 additions & 1 deletion packages/hyperliquid-composer/src/io/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ export function writeUpdatedCoreSpotDeployment(
const fullPath = getFullPath(index.toString(), isTestnet)

const spot = getCoreSpotDeployment(index, isTestnet, logger)

if (txData.weiDiff == null) {
throw new Error(
'weiDiff is not set in txData. Run core-spot-deployment create first to calculate the correct value.'
)
}

spot.coreSpot.evmContract = {
address: tokenAddress,
evm_extra_wei_decimals: txData.weiDiff ?? 0,
evm_extra_wei_decimals: txData.weiDiff,
}
spot.coreSpot.fullName = tokenFullName
spot.txData.txHash = txData.txHash
Expand Down