1
- import { evm , ChainInfo , getContractInstance , getContractAddress , getDependencyAddress } from "../../../helpers" ;
2
- import { deployImplementation , getMintRecipientAddress , getTokenRouterConfiguration , matchingEngineChain , matchingEngineDomain } from "./utils" ;
1
+ import { evm , ChainInfo , getContractInstance , getContractAddress , getDependencyAddress , ecosystemChains , solana } from "../../../helpers" ;
2
+ import { deployImplementation , getMatchingEngineMintRecipientAddress , getTokenRouterConfiguration , matchingEngineChain , matchingEngineDomain } from "./utils" ;
3
3
import { TokenRouter } from "../../../contract-bindings" ;
4
- import { toUniversal } from "@wormhole-foundation/sdk-definitions" ;
4
+ import { UniversalAddress , toUniversal } from "@wormhole-foundation/sdk-definitions" ;
5
+ import { Connection } from "@solana/web3.js" ;
5
6
6
7
evm . runOnEvms ( "upgrade-token-router" , async ( chain , signer , log ) => {
7
8
const currentImplementationAddress = getContractAddress ( "TokenRouterImplementation" , chain . chainId ) ;
8
9
const proxyAddress = getContractAddress ( "TokenRouterProxy" , chain . chainId ) ;
9
10
const proxy = ( await getContractInstance ( "TokenRouter" , proxyAddress , chain ) ) as TokenRouter ;
10
11
const config = await getTokenRouterConfiguration ( chain ) ;
11
12
13
+ // TODO: write a `getChain(chainId: ChainId): ChainInfo` function to replace these lines
14
+ if ( ecosystemChains . solana . networks . length !== 1 ) {
15
+ throw Error ( "Unexpected number of Solana networks." ) ;
16
+ }
17
+ const solanaRpc = ecosystemChains . solana . networks [ 0 ] . rpc ;
18
+
19
+ const solanaConnection = new Connection ( solanaRpc , solana . connectionCommitmentLevel ) ;
20
+ const matchingEngineMintRecipient = toUniversal ( "Solana" , getMatchingEngineMintRecipientAddress ( solanaConnection ) ) ;
21
+
12
22
log ( `Checking immutables for TokenRouter` ) ;
13
- checkImmutables ( proxy , chain ) ;
23
+ checkImmutables ( proxy , chain , matchingEngineMintRecipient ) ;
14
24
15
- const newImplementation = await deployImplementation ( chain , signer , config , log ) ;
25
+ const newImplementation = await deployImplementation ( signer , config , matchingEngineMintRecipient , log ) ;
16
26
17
27
log ( `Upgrading TokenRouter implementation from ${ currentImplementationAddress } to ${ newImplementation . address } ` ) ;
18
-
28
+
19
29
await proxy . upgradeContract ( newImplementation . address ) ;
20
30
} ) ;
21
31
22
- async function checkImmutables ( tokenRouter : TokenRouter , chain : ChainInfo ) {
32
+ async function checkImmutables ( tokenRouter : TokenRouter , chain : ChainInfo , matchingEngineMintRecipient : UniversalAddress ) {
23
33
const [
24
34
token ,
25
35
savedMatchingEngineMintRecipient ,
@@ -34,12 +44,11 @@ async function checkImmutables(tokenRouter: TokenRouter, chain: ChainInfo) {
34
44
tokenRouter . matchingEngineAddress ( ) ,
35
45
] ) ;
36
46
37
- const matchingEngineMintRecipient = toUniversal ( "Solana" , getMintRecipientAddress ( ) ) . toString ( ) ;
38
47
const localMatchingEngineAddress = getContractAddress ( "MatchingEngineProxy" , matchingEngineChain ) ;
39
48
const matchingEngineAddress = toUniversal ( "Solana" , localMatchingEngineAddress ) . toString ( ) ;
40
49
const tokenAddress = getDependencyAddress ( "token" , chain . chainId ) ;
41
50
42
- if ( savedMatchingEngineMintRecipient . toLowerCase ( ) !== matchingEngineMintRecipient . toLowerCase ( ) )
51
+ if ( savedMatchingEngineMintRecipient . toLowerCase ( ) !== matchingEngineMintRecipient . toString ( ) . toLowerCase ( ) )
43
52
throw new Error ( `MatchingEngineMintRecipient is an immutable value and cannot be changed.` ) ;
44
53
45
54
if ( savedMatchingEngineChain !== matchingEngineChain )
0 commit comments