-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathsetReceiveConfig.ts
More file actions
98 lines (81 loc) · 2.99 KB
/
Copy pathsetReceiveConfig.ts
File metadata and controls
98 lines (81 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Contract, ethers } from 'ethers'
import { createLogger } from '@layerzerolabs/io-devtools'
import { Uln302 } from '@layerzerolabs/protocol-devtools-evm'
const logger = createLogger()
export interface SetReceiveConfigArgs {
srcEid: number
contractName: string
}
export interface SetReceiveConfigParams {
oappAddress: string
receiveLibrary: string
dvnAddress: string
executorAddress: string
provider: ethers.providers.Provider
}
// SetConfigParam struct for V2 interface
interface SetConfigParam {
eid: number
configType: number
config: string
}
const CONFIG_TYPE_ULN = 2
/**
* Receive configuration setup
*/
export async function setReceiveConfig(
endpointContract: Contract,
params: SetReceiveConfigParams,
args: SetReceiveConfigArgs
) {
const { srcEid, contractName } = args
const { oappAddress, receiveLibrary, dvnAddress, executorAddress, provider } = params
logger.info(`\nSetting up executor receive configuration for ${contractName}`)
logger.info(` OApp: ${oappAddress}`)
logger.info(` Source EID: ${srcEid}`)
logger.info(` Receive Lib: ${receiveLibrary}`)
logger.info(` DVN: ${dvnAddress}`)
logger.info(` Executor: ${executorAddress}\n`)
// Validate addresses
if (!dvnAddress || dvnAddress === ethers.constants.AddressZero) {
throw new Error(`Invalid DVN address: ${dvnAddress}`)
}
if (!executorAddress || executorAddress === ethers.constants.AddressZero) {
throw new Error(`Invalid executor address: ${executorAddress}`)
}
// Set up ULN SDK
const uln302 = new Uln302(provider as ethers.providers.BaseProvider, {
eid: srcEid,
address: receiveLibrary,
})
// Configure ULN with SimpleDVNMock using V2 interface.
// optionalDVNs: [] explicitly pins "no optional DVNs" (NIL sentinel) for a deterministic mock
// — it does NOT inherit the on-chain default. The threshold is clamped to 0 with no optional
// DVNs, so it is omitted.
const ulnConfig = uln302.encodeUlnConfig({
confirmations: BigInt(1),
requiredDVNs: [dvnAddress],
optionalDVNs: [],
})
const setConfigParams: SetConfigParam[] = [
{
eid: srcEid,
configType: CONFIG_TYPE_ULN,
config: ulnConfig,
},
]
logger.info(`Setting ULN config...`)
try {
const tx = await endpointContract.setConfig(oappAddress, receiveLibrary, setConfigParams)
const receipt = await tx.wait()
logger.info(`setConfig txHash: ${receipt.transactionHash}`)
logger.info(`\nReceive configuration completed successfully!`)
logger.info(` Source EID ${srcEid} → Local OApp ${contractName}`)
logger.info(` Using SimpleDVNMock: ${dvnAddress}`)
logger.info(` Using SimpleExecutorMock: ${executorAddress}\n`)
return receipt
} catch (error: unknown) {
logger.error(`Error occurred:`, error)
throw error
}
}