Skip to content

Commit

Permalink
logs operation names before building the transaction payload
Browse files Browse the repository at this point in the history
Signed-off-by: shankar <[email protected]>
  • Loading branch information
shankars99 committed Jan 16, 2025
1 parent f8c5ed0 commit 3822bc5
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 36 deletions.
25 changes: 2 additions & 23 deletions packages/devtools-move/tasks/evm/wire-evm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Contract, ethers } from 'ethers'

import { getDeploymentAddressAndAbi } from '@layerzerolabs/lz-evm-sdk-v2'
import { OAppOmniGraphHardhat } from '@layerzerolabs/toolbox-hardhat'
import { getNetworkForChainId, ChainType } from '@layerzerolabs/lz-definitions'

import { createSetDelegateTransactions } from './wire/setDelegate'
Expand All @@ -28,12 +27,7 @@ import dotenv from 'dotenv'
* @description Handles wiring of EVM contracts with the Aptos OApp
* @dev Creates ethers's populated transactions for the various transaction types (setPeer, setDelegate, setEnforcedOptions, setSendLibrary, setReceiveLibrary, setReceiveLibraryTimeout). It then simulates them on a forked network before executing
*/
export async function createEvmOmniContracts(
args: any,
privateKey: string,
chainType: ChainType = ChainType.EVM,
isWire: boolean = false
) {
export async function createEvmOmniContracts(args: any, privateKey: string, chainType: ChainType = ChainType.EVM) {
const globalConfigPath = path.resolve(path.join(args.rootDir, args.oapp_config))
const connectionsToWire = await getConfigConnectionsFromChainType('from', chainType, globalConfigPath)
const accountConfigs = await getHHAccountConfig(globalConfigPath)
Expand All @@ -48,9 +42,6 @@ export async function createEvmOmniContracts(
* omniContracts contains ethers Contract objects for the OApp and EndpointV2 contracts.
*/
for (const conn of connectionsToWire) {
if (isWire) {
logPathwayHeader(conn)
}
const fromEid = conn.from.eid
const toEid = conn.to.eid.toString()
const fromNetwork = networks[fromEid]
Expand Down Expand Up @@ -119,7 +110,7 @@ export function readPrivateKey(args: any) {
async function wireEvm(args: any) {
const privateKey = readPrivateKey(args)

const omniContracts = await createEvmOmniContracts(args, privateKey, ChainType.EVM, true)
const omniContracts = await createEvmOmniContracts(args, privateKey, ChainType.EVM)
await validateOmniContractsOrTerminate(omniContracts)

// Build a Transaction mapping for each type of transaction. It is further indexed by the eid.
Expand Down Expand Up @@ -167,16 +158,4 @@ async function wireEvm(args: any) {
}
}

function logPathwayHeader(connection: OAppOmniGraphHardhat['connections'][number]) {
const fromNetwork = getNetworkForChainId(connection.from.eid)
const toNetwork = getNetworkForChainId(connection.to.eid)

const pathwayString = `🔄 Building wire transactions for pathway: ${fromNetwork.chainName}-${fromNetwork.env}${toNetwork.chainName}-${toNetwork.env} 🔄`
const borderLine = '━'.repeat(pathwayString.length)

console.log(borderLine)
console.log(pathwayString)
console.log(`${borderLine}\n`)
}

export { wireEvm }
4 changes: 2 additions & 2 deletions packages/devtools-move/tasks/evm/wire/setDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Contract, utils } from 'ethers'

import { diffPrinter } from '../../shared/utils'

import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'

import type { OmniContractMetadataMapping, EidTxMap } from '../utils/types'

Expand All @@ -14,7 +14,7 @@ import type { OmniContractMetadataMapping, EidTxMap } from '../utils/types'
*/
export async function createSetDelegateTransactions(eidDataMapping: OmniContractMetadataMapping): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}

logPathwayHeader('setDelegate')
for (const [eid, { peers, address, contract, configAccount }] of Object.entries(eidDataMapping)) {
const peerToEid = peers[0].eid
const currDelegate = await getDelegate(contract.epv2, address.oapp)
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-move/tasks/evm/wire/setEnforcedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Options,
} from '@layerzerolabs/lz-v2-utilities'

import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'

import { diffPrinter } from '../../shared/utils'

Expand All @@ -26,7 +26,7 @@ export async function createSetEnforcedOptionsTransactions(
eidDataMapping: OmniContractMetadataMapping
): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}

logPathwayHeader('setEnforcedOptions')
for (const [eid, { peers, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
const { eid: peerToEid } = peer
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools-move/tasks/evm/wire/setPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Contract } from 'ethers'

import { diffPrinter } from '../../shared/utils'

import { createDiffMessage, printAlreadySet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, logPathwayHeader } from '../../shared/messageBuilder'
import type { EidTxMap, OmniContractMetadataMapping } from '../utils/types'

/**
Expand All @@ -13,6 +13,7 @@ import type { EidTxMap, OmniContractMetadataMapping } from '../utils/types'
*/
export async function createSetPeerTransactions(eidDataMappings: OmniContractMetadataMapping): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}
logPathwayHeader('setPeer')

for (const [toEid, { peers, contract }] of Object.entries(eidDataMappings)) {
for (const peer of peers) {
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools-move/tasks/evm/wire/setReceiveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { diffPrinter } from '../../shared/utils'
import { buildConfig, decodeConfig, getConfig, setConfig } from '../utils/libraryConfigUtils'

import { parseReceiveLibrary } from './setReceiveLibrary'

import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { buildConfig, decodeConfig, getConfig, setConfig } from '../utils/libraryConfigUtils'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'

import type { OmniContractMetadataMapping, EidTxMap, SetConfigParam } from '../utils/types'

Expand All @@ -14,7 +14,7 @@ export async function createSetReceiveConfigTransactions(
eidDataMapping: OmniContractMetadataMapping
): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}

logPathwayHeader('setReceiveConfig')
for (const [eid, { peers, address, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
const { eid: peerToEid } = peer
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools-move/tasks/evm/wire/setReceiveLibrary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contract, utils, constants } from 'ethers'

import { diffPrinter } from '../../shared/utils'
import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'
import type { OmniContractMetadataMapping, EidTxMap, RecvLibParam, address, eid } from '../utils/types'
import type { OAppEdgeConfig } from '@layerzerolabs/toolbox-hardhat'

Expand All @@ -20,6 +20,7 @@ export async function createSetReceiveLibraryTransactions(
eidDataMapping: OmniContractMetadataMapping
): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}
logPathwayHeader('setReceiveLibrary')

for (const [eid, { peers, address, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contract, utils, constants } from 'ethers'

import { diffPrinter } from '../../shared/utils'
import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'
import type { OmniContractMetadataMapping, EidTxMap, RecvLibraryTimeoutConfig, eid } from '../utils/types'

/**
Expand All @@ -14,6 +14,7 @@ export async function createSetReceiveLibraryTimeoutTransactions(
eidDataMapping: OmniContractMetadataMapping
): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}
logPathwayHeader('setReceiveLibraryTimeout')

for (const [eid, { peers, address, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-move/tasks/evm/wire/setSendConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { buildConfig, decodeConfig, getConfig, setConfig } from '../utils/librar

import { parseSendLibrary } from './setSendLibrary'

import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'

import type { OmniContractMetadataMapping, EidTxMap, SetConfigParam } from '../utils/types'

Expand All @@ -13,7 +13,7 @@ import type { OmniContractMetadataMapping, EidTxMap, SetConfigParam } from '../u
*/
export async function createSetSendConfigTransactions(eidDataMapping: OmniContractMetadataMapping): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}

logPathwayHeader('setSendConfig')
for (const [eid, { peers, address, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
const { eid: peerToEid } = peer
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools-move/tasks/evm/wire/setSendLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { diffPrinter } from '../../shared/utils'

import type { OmniContractMetadataMapping, EidTxMap, address, eid } from '../utils/types'
import type { OAppEdgeConfig } from '@layerzerolabs/toolbox-hardhat'
import { createDiffMessage, printAlreadySet, printNotSet } from '../../shared/messageBuilder'
import { createDiffMessage, printAlreadySet, printNotSet, logPathwayHeader } from '../../shared/messageBuilder'
const error_LZ_DefaultSendLibUnavailable = '0x6c1ccdb5'

/**
Expand All @@ -18,6 +18,7 @@ const error_LZ_DefaultSendLibUnavailable = '0x6c1ccdb5'
*/
export async function createSetSendLibraryTransactions(eidDataMapping: OmniContractMetadataMapping): Promise<EidTxMap> {
const txTypePool: EidTxMap = {}
logPathwayHeader('setSendLibrary')

for (const [eid, { peers, address, contract, configOapp }] of Object.entries(eidDataMapping)) {
for (const peer of peers) {
Expand Down
9 changes: 9 additions & 0 deletions packages/devtools-move/tasks/shared/messageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export function buildTransactionDescription(action: string, fromEid: number, toE

return `${action} from ${fromNetwork.chainName}-${fromNetwork.env}${toNetwork.chainName}-${toNetwork.env}`
}

export function logPathwayHeader(op: string) {
const pathwayString = `🔄 Building ${op} transactions 🔄`
const borderLine = '━'.repeat(pathwayString.length)

console.log(borderLine)
console.log(pathwayString)
console.log(`${borderLine}\n`)
}

0 comments on commit 3822bc5

Please sign in to comment.