Skip to content

Commit d31cefb

Browse files
author
Dev Kalra
authored
feat(contract_manager): separate store for wormhole (#1493)
* rename wormhole contract as per other names * store for wormhole * fix var name * rename var * rename contract based on other namings * add yaml for aptos and cosmwasm
1 parent 48a5faf commit d31cefb

File tree

14 files changed

+490
-31
lines changed

14 files changed

+490
-31
lines changed

contract_manager/scripts/check_proposal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
EvmEntropyContract,
2424
EvmPriceFeedContract,
2525
getCodeDigestWithoutAddress,
26-
WormholeEvmContract,
26+
EvmWormholeContract,
2727
} from "../src/contracts/evm";
2828
import Web3 from "web3";
2929

@@ -73,7 +73,7 @@ async function main() {
7373
instruction.governanceAction.targetChainId
7474
) {
7575
const address = instruction.governanceAction.address;
76-
const contract = new WormholeEvmContract(chain, address);
76+
const contract = new EvmWormholeContract(chain, address);
7777
const currentIndex = await contract.getCurrentGuardianSetIndex();
7878
const guardianSet = await contract.getGuardianSet();
7979

contract_manager/scripts/deploy_evm_entropy_contracts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PrivateKey,
1111
toDeploymentType,
1212
toPrivateKey,
13-
WormholeEvmContract,
13+
EvmWormholeContract,
1414
} from "../src";
1515
import {
1616
COMMON_DEPLOY_OPTIONS,
@@ -200,7 +200,7 @@ async function main() {
200200
saveContract: argv.saveContract,
201201
wormholeAddr,
202202
};
203-
const wormholeContract = new WormholeEvmContract(
203+
const wormholeContract = new EvmWormholeContract(
204204
chain,
205205
deploymentConfig.wormholeAddr
206206
);

contract_manager/scripts/deploy_evm_pricefeed_contracts.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
PrivateKey,
1010
toDeploymentType,
1111
toPrivateKey,
12-
WormholeEvmContract,
12+
EvmWormholeContract,
1313
} from "../src";
1414
import {
1515
COMMON_DEPLOY_OPTIONS,
@@ -98,15 +98,12 @@ async function deployWormholeReceiverContracts(
9898
[receiverSetupAddr, initData]
9999
);
100100

101-
const wormholeEvmContract = new WormholeEvmContract(
102-
chain,
103-
wormholeReceiverAddr
104-
);
101+
const wormholeContract = new EvmWormholeContract(chain, wormholeReceiverAddr);
105102

106103
if (config.type === "stable") {
107104
console.log(`Syncing mainnet guardian sets for ${chain.getId()}...`);
108105
// TODO: Add a way to pass gas configs to this
109-
await wormholeEvmContract.syncMainnetGuardianSets(config.privateKey);
106+
await wormholeContract.syncMainnetGuardianSets(config.privateKey);
110107
console.log(`✅ Synced mainnet guardian sets for ${chain.getId()}`);
111108
}
112109

contract_manager/src/contracts/aptos.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,39 @@ type GuardianSet = {
1717
index: { number: string };
1818
};
1919

20-
export class WormholeAptosContract extends WormholeContract {
20+
export class AptosWormholeContract extends WormholeContract {
21+
static type = "AptosWormholeContract";
22+
23+
getId(): string {
24+
return `${this.chain.getId()}_${this.address}`;
25+
}
26+
27+
getType(): string {
28+
return AptosWormholeContract.type;
29+
}
30+
31+
toJson() {
32+
return {
33+
chain: this.chain.getId(),
34+
address: this.address,
35+
type: AptosWormholeContract.type,
36+
};
37+
}
38+
39+
static fromJson(
40+
chain: Chain,
41+
parsed: {
42+
type: string;
43+
address: string;
44+
}
45+
): AptosWormholeContract {
46+
if (parsed.type !== AptosWormholeContract.type)
47+
throw new Error("Invalid type");
48+
if (!(chain instanceof AptosChain))
49+
throw new Error(`Wrong chain type ${chain}`);
50+
return new AptosWormholeContract(chain, parsed.address);
51+
}
52+
2153
constructor(public chain: AptosChain, public address: string) {
2254
super();
2355
}
@@ -124,8 +156,8 @@ export class AptosPriceFeedContract extends PriceFeedContract {
124156
return this.chain.sendTransaction(senderPrivateKey, txPayload);
125157
}
126158

127-
public getWormholeContract(): WormholeAptosContract {
128-
return new WormholeAptosContract(this.chain, this.wormholeStateId);
159+
public getWormholeContract(): AptosWormholeContract {
160+
return new AptosWormholeContract(this.chain, this.wormholeStateId);
129161
}
130162

131163
async executeUpdatePriceFeed(

contract_manager/src/contracts/cosmwasm.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,36 @@ export interface DeploymentConfig {
3838
fee: { amount: string; denom: string };
3939
}
4040

41-
export class WormholeCosmWasmContract extends WormholeContract {
41+
export class CosmWasmWormholeContract extends WormholeContract {
42+
static type = "CosmWasmWormholeContract";
43+
44+
getId(): string {
45+
return `${this.chain.getId()}_${this.address}`;
46+
}
47+
48+
getType(): string {
49+
return CosmWasmWormholeContract.type;
50+
}
51+
52+
toJson() {
53+
return {
54+
chain: this.chain.getId(),
55+
address: this.address,
56+
type: CosmWasmWormholeContract.type,
57+
};
58+
}
59+
60+
static fromJson(
61+
chain: Chain,
62+
parsed: { type: string; address: string }
63+
): CosmWasmWormholeContract {
64+
if (parsed.type !== CosmWasmWormholeContract.type)
65+
throw new Error("Invalid type");
66+
if (!(chain instanceof CosmWasmChain))
67+
throw new Error(`Wrong chain type ${chain}`);
68+
return new CosmWasmWormholeContract(chain, parsed.address);
69+
}
70+
4271
constructor(public chain: CosmWasmChain, public address: string) {
4372
super();
4473
}
@@ -310,10 +339,10 @@ export class CosmWasmPriceFeedContract extends PriceFeedContract {
310339
return { id: result.txHash, info: result };
311340
}
312341

313-
async getWormholeContract(): Promise<WormholeCosmWasmContract> {
342+
async getWormholeContract(): Promise<CosmWasmWormholeContract> {
314343
const config = await this.getConfig();
315344
const wormholeAddress = config.config_v1.wormhole_contract;
316-
return new WormholeCosmWasmContract(this.chain, wormholeAddress);
345+
return new CosmWasmWormholeContract(this.chain, wormholeAddress);
317346
}
318347

319348
async getUpdateFee(msgs: string[]): Promise<Coin> {

contract_manager/src/contracts/evm.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,37 @@ export async function getCodeDigestWithoutAddress(
390390
return Web3.utils.keccak256(strippedCode);
391391
}
392392

393-
export class WormholeEvmContract extends WormholeContract {
393+
export class EvmWormholeContract extends WormholeContract {
394+
static type = "EvmWormholeContract";
395+
396+
getId(): string {
397+
return `${this.chain.getId()}_${this.address}`;
398+
}
399+
400+
getChain(): EvmChain {
401+
return this.chain;
402+
}
403+
404+
getType(): string {
405+
return EvmWormholeContract.type;
406+
}
407+
408+
async getVersion(): Promise<string> {
409+
const contract = this.getContract();
410+
return contract.methods.version().call();
411+
}
412+
413+
static fromJson(
414+
chain: Chain,
415+
parsed: { type: string; address: string }
416+
): EvmWormholeContract {
417+
if (parsed.type !== EvmWormholeContract.type)
418+
throw new Error("Invalid type");
419+
if (!(chain instanceof EvmChain))
420+
throw new Error(`Wrong chain type ${chain}`);
421+
return new EvmWormholeContract(chain, parsed.address);
422+
}
423+
394424
constructor(public chain: EvmChain, public address: string) {
395425
super();
396426
}
@@ -436,6 +466,14 @@ export class WormholeEvmContract extends WormholeContract {
436466
);
437467
return { id: result.transactionHash, info: result };
438468
}
469+
470+
toJson() {
471+
return {
472+
chain: this.chain.getId(),
473+
address: this.address,
474+
type: EvmWormholeContract.type,
475+
};
476+
}
439477
}
440478

441479
interface EntropyProviderInfo {
@@ -651,13 +689,13 @@ export class EvmExecutorContract {
651689
return `${this.chain.getId()}_${this.address}`;
652690
}
653691

654-
async getWormholeContract(): Promise<WormholeEvmContract> {
692+
async getWormholeContract(): Promise<EvmWormholeContract> {
655693
const web3 = new Web3(this.chain.getRpcUrl());
656694
//Unfortunately, there is no public method to get the wormhole address
657695
//Found 251 by using `forge build --extra-output storageLayout` and finding the slot for the wormhole variable.
658696
let address = await web3.eth.getStorageAt(this.address, 251);
659697
address = "0x" + address.slice(26);
660-
return new WormholeEvmContract(this.chain, address);
698+
return new EvmWormholeContract(this.chain, address);
661699
}
662700

663701
getContract() {
@@ -822,10 +860,10 @@ export class EvmPriceFeedContract extends PriceFeedContract {
822860
/**
823861
* Returns the wormhole contract which is being used for VAA verification
824862
*/
825-
async getWormholeContract(): Promise<WormholeEvmContract> {
863+
async getWormholeContract(): Promise<EvmWormholeContract> {
826864
const pythContract = this.getContract();
827865
const address = await pythContract.methods.wormhole().call();
828-
return new WormholeEvmContract(this.chain, address);
866+
return new EvmWormholeContract(this.chain, address);
829867
}
830868

831869
async getBaseUpdateFee() {

contract_manager/src/contracts/wormhole.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { PrivateKey, TxResult } from "../base";
1+
import { PrivateKey, Storable, TxResult } from "../base";
22

3-
export abstract class WormholeContract {
3+
export abstract class WormholeContract extends Storable {
44
abstract getCurrentGuardianSetIndex(): Promise<number>;
55

66
/**

contract_manager/src/shell.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ repl.evalCode(
88
"import { loadHotWallet, Vault } from './src/governance';" +
99
"import { SuiChain, CosmWasmChain, AptosChain, EvmChain } from './src/chains';" +
1010
"import { SuiPriceFeedContract } from './src/contracts/sui';" +
11-
"import { WormholeCosmWasmContract, CosmWasmPriceFeedContract } from './src/contracts/cosmwasm';" +
12-
"import { WormholeEvmContract, EvmPriceFeedContract } from './src/contracts/evm';" +
13-
"import { WormholeAptosContract, AptosPriceFeedContract } from './src/contracts/aptos';" +
11+
"import { CosmWasmWormholeContract, CosmWasmPriceFeedContract } from './src/contracts/cosmwasm';" +
12+
"import { EvmWormholeContract, EvmPriceFeedContract } from './src/contracts/evm';" +
13+
"import { AptosWormholeContract, AptosPriceFeedContract } from './src/contracts/aptos';" +
1414
"import { DefaultStore } from './src/store';" +
1515
"import { toPrivateKey } from './src/base';" +
1616
"DefaultStore"

contract_manager/src/store.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import {
88
} from "./chains";
99
import {
1010
AptosPriceFeedContract,
11+
AptosWormholeContract,
1112
CosmWasmPriceFeedContract,
13+
CosmWasmWormholeContract,
1214
EvmEntropyContract,
1315
EvmPriceFeedContract,
16+
EvmWormholeContract,
1417
SuiPriceFeedContract,
18+
WormholeContract,
1519
} from "./contracts";
1620
import { Token } from "./token";
1721
import { PriceFeedContract, Storable } from "./base";
@@ -23,6 +27,7 @@ export class Store {
2327
public chains: Record<string, Chain> = { global: new GlobalChain() };
2428
public contracts: Record<string, PriceFeedContract> = {};
2529
public entropy_contracts: Record<string, EvmEntropyContract> = {};
30+
public wormhole_contracts: Record<string, WormholeContract> = {};
2631
public tokens: Record<string, Token> = {};
2732
public vaults: Record<string, Vault> = {};
2833

@@ -81,6 +86,7 @@ export class Store {
8186
const contractsByType: Record<string, Storable[]> = {};
8287
const contracts: Storable[] = Object.values(this.contracts);
8388
contracts.push(...Object.values(this.entropy_contracts));
89+
contracts.push(...Object.values(this.wormhole_contracts));
8490
for (const contract of contracts) {
8591
if (!contractsByType[contract.getType()]) {
8692
contractsByType[contract.getType()] = [];
@@ -114,10 +120,13 @@ export class Store {
114120
loadAllContracts() {
115121
const allContractClasses = {
116122
[CosmWasmPriceFeedContract.type]: CosmWasmPriceFeedContract,
123+
[CosmWasmWormholeContract.type]: CosmWasmWormholeContract,
117124
[SuiPriceFeedContract.type]: SuiPriceFeedContract,
118125
[EvmPriceFeedContract.type]: EvmPriceFeedContract,
119126
[AptosPriceFeedContract.type]: AptosPriceFeedContract,
127+
[AptosWormholeContract.type]: AptosWormholeContract,
120128
[EvmEntropyContract.type]: EvmEntropyContract,
129+
[EvmWormholeContract.type]: EvmWormholeContract,
121130
};
122131
this.getYamlFiles(`${this.path}/contracts/`).forEach((yamlFile) => {
123132
const parsedArray = parse(readFileSync(yamlFile, "utf-8"));
@@ -132,13 +141,16 @@ export class Store {
132141
);
133142
if (
134143
this.contracts[chainContract.getId()] ||
135-
this.entropy_contracts[chainContract.getId()]
144+
this.entropy_contracts[chainContract.getId()] ||
145+
this.wormhole_contracts[chainContract.getId()]
136146
)
137147
throw new Error(
138148
`Multiple contracts with id ${chainContract.getId()} found`
139149
);
140150
if (chainContract instanceof EvmEntropyContract) {
141151
this.entropy_contracts[chainContract.getId()] = chainContract;
152+
} else if (chainContract instanceof WormholeContract) {
153+
this.wormhole_contracts[chainContract.getId()] = chainContract;
142154
} else {
143155
this.contracts[chainContract.getId()] = chainContract;
144156
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- chain: aptos_mainnet
2+
address: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625"
3+
type: AptosWormholeContract
4+
- chain: aptos_testnet
5+
address: "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625"
6+
type: AptosWormholeContract
7+
- chain: movement_move_devnet
8+
address: "0x9236893d6444b208b7e0b3e8d4be4ace90b6d17817ab7d1584e46a33ef5c50c9"
9+
type: AptosWormholeContract

0 commit comments

Comments
 (0)