1
1
import chalk from 'chalk' ;
2
- import { LoggerFn , ValueDiff , getEnv } from '.' ;
3
- import { ChainId } from "@wormhole-foundation/sdk-base" ;
4
- import { RouterEndpointConfig } from '../config/config-types' ;
5
- import { UniversalAddress } from '@wormhole-foundation/sdk-definitions' ;
2
+ import { ChainInfo , LoggerFn , ValueDiff } from '.' ;
6
3
7
4
export const someoneIsDifferent = ( values : ValueDiff [ ] ) => values . some ( ( value ) => value . onChain . toString ( ) !== value . offChain . toString ( ) && Number ( value . onChain ) !== Number ( value . offChain ) ) ;
8
5
@@ -13,124 +10,66 @@ export function logComparision(name: string, diffValues: any, log: LoggerFn) {
13
10
return ;
14
11
15
12
// If the on chain value is not present or it is zero value, log it as an addition
16
- if ( ! diffValues . onChain || Number ( diffValues . onChain ) === 0 ) {
13
+ if ( ! diffValues . onChain || Number ( diffValues . onChain ) === 0 )
17
14
log ( chalk . green ( `+ ${ name } : ${ diffValues . offChain } ` ) ) ;
18
- }
19
15
20
16
// If the off chain value is not present or it is zero value, log it as a removal
21
- else if ( ! diffValues . offChain || Number ( diffValues . offChain ) === 0 ) {
17
+ else if ( ! diffValues . offChain || Number ( diffValues . offChain ) === 0 )
22
18
log ( chalk . red ( `- ${ name } : ${ diffValues . onChain } ` ) ) ;
23
- }
24
19
25
20
// If both values are present and they are different, log it as a change
26
- else {
21
+ else
27
22
log ( chalk . yellow ( `~ ${ name } : ` ) + chalk . red ( `${ diffValues . onChain } ` ) + ' -> ' + chalk . green ( `${ diffValues . offChain } ` ) ) ;
28
- }
29
23
}
30
24
31
25
// Assuming that we'll only have two types of addresses: Ethereum and Solana
32
26
export function getAddressType ( address : string ) : 'hex' | 'base58' {
33
27
const ETHEREUM_ADDRESS_LENGTH = 40 ;
34
28
const addressLength = address . length - ( address . startsWith ( "0x" ) ? 2 : 0 ) ;
35
29
36
- // TODO: check lenght of solana addresses
37
30
if ( address . length < ETHEREUM_ADDRESS_LENGTH )
38
31
throw new Error ( `Invalid address length: ${ address } ` ) ;
39
32
40
33
return addressLength === ETHEREUM_ADDRESS_LENGTH ? 'hex' : 'base58' ;
41
34
}
42
35
43
- // Router endpoint helpers
44
-
45
- export function getRouterEndpointDifferences ( onChainRouterEndpoints : RouterEndpointConfig [ ] , offChainRouterEndpoints : RouterEndpointConfig [ ] ) {
46
- const routerEndpointsDifferences = [ ] ;
47
- let onChainIndex = 0 ;
48
- let offChainIndex = 0 ;
49
-
50
- onChainRouterEndpoints = onChainRouterEndpoints . sort ( ( a , b ) => a . wormholeChainId - b . wormholeChainId ) ;
51
- offChainRouterEndpoints = offChainRouterEndpoints . sort ( ( a , b ) => a . wormholeChainId - b . wormholeChainId ) ;
52
-
53
- while ( true ) {
54
- const onChainEndpoint = onChainRouterEndpoints [ onChainIndex ] ;
55
- const offChainEndpoint = offChainRouterEndpoints [ offChainIndex ] ;
56
-
57
- // If we've reached the end of both arrays, we're done
58
- if ( ! onChainEndpoint && ! offChainEndpoint ) {
59
- break ;
60
- }
61
-
62
- // If we've reached the end of offChainEndpoints, add the remaining onChainEndpoints
63
- // or if the onChainEndpoint is less than the offChainEndpoint, add the onChainEndpoint
64
- if ( ! offChainEndpoint || onChainEndpoint ?. wormholeChainId < offChainEndpoint ?. wormholeChainId ) {
65
- routerEndpointsDifferences . push (
66
- routerEndpointConfig ( onChainEndpoint . wormholeChainId , onChainEndpoint , { } )
67
- ) ;
68
- onChainIndex ++ ;
69
- continue ;
70
- }
71
-
72
- // If we've reached the end of onChainEndpoints, add the remaining offChainEndpoints
73
- // or if the offChainEndpoint is less than the onChainEndpoint, add the offChainEndpoint
74
- if ( ! onChainEndpoint || onChainEndpoint ?. wormholeChainId > offChainEndpoint ?. wormholeChainId ) {
75
- routerEndpointsDifferences . push (
76
- routerEndpointConfig ( offChainEndpoint . wormholeChainId , { } , offChainEndpoint )
77
- ) ;
78
- offChainIndex ++ ;
79
- continue ;
80
- }
81
-
82
- routerEndpointsDifferences . push (
83
- routerEndpointConfig ( onChainEndpoint . wormholeChainId , onChainEndpoint , offChainEndpoint )
84
- ) ;
85
-
86
- onChainIndex ++ ;
87
- offChainIndex ++ ;
36
+ export function flattenObject ( obj : Record < string , any > , parentKey = '' , result : Record < string , any > = { } ) {
37
+ for ( let key in obj ) {
38
+ if ( obj . hasOwnProperty ( key ) ) {
39
+ let newKey = parentKey ? `${ parentKey } -${ key } ` : key ;
40
+
41
+ if ( typeof obj [ key ] === 'object' && obj [ key ] !== null && ! Array . isArray ( obj [ key ] ) ) {
42
+ flattenObject ( obj [ key ] , newKey , result ) ;
43
+ } else {
44
+ result [ newKey ] = obj [ key ] ;
45
+ }
46
+ }
88
47
}
89
-
90
- return routerEndpointsDifferences ;
91
- }
92
-
93
- const routerEndpointConfig = ( wormholeChainId : ChainId , onChain : Partial < RouterEndpointConfig > , offChain : Partial < RouterEndpointConfig > ) => ( {
94
- wormholeChainId,
95
- router : {
96
- onChain : onChain ?. endpoint ?. router ,
97
- offChain : offChain ?. endpoint ?. router
98
- } ,
99
- mintRecipient : {
100
- onChain : onChain ?. endpoint ?. mintRecipient ,
101
- offChain : offChain ?. endpoint ?. mintRecipient
102
- } ,
103
- circleDomain : {
104
- onChain : onChain ?. circleDomain ,
105
- offChain : offChain ?. circleDomain
106
- }
107
- } ) ;
108
-
109
- export function getFormattedEndpoint ( router : string , mintRecipient : string ) {
110
- const routerAddresType = getAddressType ( router ) ;
111
- const mintRecipientAddressType = getAddressType ( mintRecipient ) ;
112
-
113
- return {
114
- router : ( new UniversalAddress ( router , routerAddresType ) ) . toString ( ) ,
115
- mintRecipient : ( new UniversalAddress ( mintRecipient , mintRecipientAddressType ) ) . toString ( )
116
- } ;
48
+ return result ;
117
49
}
118
50
119
51
/// Verify bytecode helper
120
52
121
53
export function getVerifyCommand (
54
+ chain : ChainInfo ,
122
55
contractName : string ,
123
56
contractPath : string ,
124
57
contractAddress : string ,
125
58
constructorSignature : string ,
126
59
constructorArgs : any [ ] ,
127
- EvmChainId : number
60
+ verifier : string ,
61
+ apiKey ?: string
128
62
) : string {
129
- const ETHERSCAN_API_KEY = getEnv ( "ETHERSCAN_API_KEY" ) ;
130
- return `
63
+ if ( chain . externalId === undefined )
64
+ throw new Error ( `Chain ${ chain . chainId } does not have an external ID` ) ;
65
+
66
+ let command = `
131
67
forge verify-contract ${ contractAddress } ${ contractPath } :${ contractName } \
68
+ --verifier ${ verifier } \
132
69
--watch --constructor-args $(cast abi-encode "${ constructorSignature } " "${ constructorArgs . join ( '" "' ) } ") \
133
- --chain-id ${ EvmChainId } \
134
- --etherscan-api-key ${ ETHERSCAN_API_KEY } \
70
+ --chain-id ${ chain . externalId } \
71
+ ${ apiKey === undefined || apiKey === "" ? '' : ` --etherscan-api-key ${ apiKey } ` }
135
72
` ;
73
+
74
+ return command ;
136
75
}
0 commit comments