-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathsetSendConfig.ts
More file actions
115 lines (95 loc) · 3.45 KB
/
Copy pathsetSendConfig.ts
File metadata and controls
115 lines (95 loc) · 3.45 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Contract, ethers } from 'ethers'
import { createLogger } from '@layerzerolabs/io-devtools'
import { Uln302 } from '@layerzerolabs/protocol-devtools-evm'
const logger = createLogger()
export interface SetSendConfigArgs {
dstEid: number
contractName: string
dvn?: string
executorAddress?: string
}
export interface SetSendConfigParams {
oappAddress: string
sendLibrary: string
dvnAddress: string
executorAddress: string
provider: ethers.providers.Provider
}
// SetConfigParam struct for V2 interface
interface SetConfigParam {
eid: number
configType: number
config: string
}
// Executor configuration
// interface ExecutorConfig {
// maxMessageSize: number
// executorAddress: string
// }
const CONFIG_TYPE_EXECUTOR = 1
const CONFIG_TYPE_ULN = 2
/**
* Send configuration setup
*/
export async function setSendConfig(endpointContract: Contract, params: SetSendConfigParams, args: SetSendConfigArgs) {
const { dstEid, contractName } = args
const { oappAddress, sendLibrary, dvnAddress, executorAddress, provider } = params
logger.info(`\nSetting up executor send configuration for ${contractName}`)
logger.info(` OApp: ${oappAddress}`)
logger.info(` Destination EID: ${dstEid}`)
logger.info(` Send Lib: ${sendLibrary}`)
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: dstEid,
address: sendLibrary,
})
const MAX_MESSAGE_SIZE = 10000
const executorConfig = uln302.encodeExecutorConfig({
maxMessageSize: MAX_MESSAGE_SIZE,
executor: executorAddress,
})
// 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: dstEid,
configType: CONFIG_TYPE_EXECUTOR,
config: executorConfig,
},
{
eid: dstEid,
configType: CONFIG_TYPE_ULN,
config: ulnConfig,
},
]
logger.info(`Setting ULN and Executor config...`)
try {
const tx = await endpointContract.setConfig(oappAddress, sendLibrary, setConfigParams)
const receipt = await tx.wait()
logger.info(`setConfig txHash: ${receipt.transactionHash}`)
logger.info(`\nSend configuration completed successfully!`)
logger.info(` Local OApp ${contractName} → Destination EID ${dstEid}`)
logger.info(` Using SimpleDVNMock: ${dvnAddress}`)
logger.info(` Using SimpleExecutorMock: ${executorAddress}\n`)
return receipt
} catch (error: unknown) {
logger.error(`Error occurred:`, error)
throw error
}
}