Skip to content

Commit a7d133d

Browse files
m30mali-behjati
andauthored
[cosmwasm] CosmWasm integration with contract manager (#1025)
* Integrate with contract manager for wormhole script * Remove deprecated scripts and more integration with contract manager * Remove cosmwasm tools store These configs are now held in the contract manager * Update docs on cosmwasm * Split cosmwasm package into 2 for fixing dependency issues * Fix cosmwasm README.md Co-authored-by: Ali Behjati <[email protected]>
1 parent cf78791 commit a7d133d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+588
-2488
lines changed

contract_manager/src/contracts/cosmwasm.ts

Lines changed: 20 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import { readFileSync } from "fs";
33
import {
44
ContractInfoResponse,
55
CosmwasmQuerier,
6-
DeploymentType,
7-
getPythConfig,
86
Price,
97
PythWrapperExecutor,
108
PythWrapperQuerier,
119
} from "@pythnetwork/cosmwasm-deploy-tools";
1210
import { Coin } from "@cosmjs/stargate";
13-
import { CHAINS, DataSource } from "xc_admin_common";
11+
import { DataSource } from "xc_admin_common";
1412
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
15-
import { Contract, PrivateKey, TxResult } from "../base";
13+
import {
14+
Contract,
15+
getDefaultDeploymentConfig,
16+
PrivateKey,
17+
TxResult,
18+
} from "../base";
1619
import { WormholeContract } from "./wormhole";
1720

1821
/**
@@ -85,7 +88,7 @@ export class CosmWasmContract extends Contract {
8588
async getDataSources(): Promise<DataSource[]> {
8689
const config = await this.getConfig();
8790
return config.config_v1.data_sources.map(
88-
({ emitter, chain_id }: { emitter: string; chain_id: string }) => {
91+
({ emitter, chain_id }: WormholeSource) => {
8992
return {
9093
emitterChain: Number(chain_id),
9194
emitterAddress: Buffer.from(emitter, "base64").toString("hex"),
@@ -124,19 +127,6 @@ export class CosmWasmContract extends Contract {
124127
return CosmWasmContract.type;
125128
}
126129

127-
static getDeploymentConfig(
128-
chain: CosmWasmChain,
129-
deploymentType: DeploymentType,
130-
wormholeContract: string
131-
): DeploymentConfig {
132-
return getPythConfig({
133-
feeDenom: chain.feeDenom,
134-
wormholeChainId: CHAINS[chain.wormholeChainName],
135-
wormholeContract,
136-
deploymentType: deploymentType,
137-
});
138-
}
139-
140130
/**
141131
* Stores the wasm code on the specified chain using the provided private key as the signer
142132
* You can find the wasm artifacts from the repo releases
@@ -180,28 +170,6 @@ export class CosmWasmContract extends Contract {
180170
return new CosmWasmContract(chain, result.contractAddr);
181171
}
182172

183-
/**
184-
* Uploads the wasm code and initializes a new contract to the specified chain.
185-
* Use this method if you are deploying to a new chain, or you want a fresh contract in
186-
* a testnet environment. Uses the default deployment configurations for governance, data sources,
187-
* valid time period, etc. You can manually run the storeCode and initialize methods if you want
188-
* more control over the deployment process.
189-
* @param chain
190-
* @param wormholeContract
191-
* @param privateKey private key to use for signing the transaction in hex format without 0x prefix
192-
* @param wasmPath
193-
*/
194-
static async deploy(
195-
chain: CosmWasmChain,
196-
wormholeContract: string,
197-
privateKey: PrivateKey,
198-
wasmPath: string
199-
): Promise<CosmWasmContract> {
200-
const config = this.getDeploymentConfig(chain, "beta", wormholeContract);
201-
const { codeId } = await this.storeCode(chain, privateKey, wasmPath);
202-
return this.initialize(chain, codeId, config, privateKey);
203-
}
204-
205173
getId(): string {
206174
return `${this.chain.getId()}_${this.address}`;
207175
}
@@ -247,9 +215,6 @@ export class CosmWasmContract extends Contract {
247215
return Number(config.config_v1.governance_sequence_number);
248216
}
249217

250-
// TODO: function for upgrading the contract
251-
// TODO: Cleanup and more strict linter to convert let to const
252-
253218
private parsePrice(priceInfo: Price) {
254219
return {
255220
conf: priceInfo.conf.toString(),
@@ -295,31 +260,20 @@ export class CosmWasmContract extends Contract {
295260

296261
async getDeploymentType(): Promise<string> {
297262
const config = await this.getConfig();
298-
const wormholeContract = config.config_v1.wormhole_contract;
299-
const stableConfig = getPythConfig({
300-
feeDenom: this.chain.feeDenom,
301-
wormholeChainId: CHAINS[this.chain.getId() as keyof typeof CHAINS],
302-
wormholeContract,
303-
deploymentType: "stable",
304-
});
305-
const betaConfig = getPythConfig({
306-
feeDenom: this.chain.feeDenom,
307-
wormholeChainId: CHAINS[this.chain.getId() as keyof typeof CHAINS],
308-
wormholeContract,
309-
deploymentType: "beta",
310-
});
311-
if (
312-
this.equalDataSources(
313-
config.config_v1.data_sources,
314-
stableConfig.data_sources
315-
)
316-
)
263+
const convertDataSource = (source: DataSource) => {
264+
return {
265+
emitter: Buffer.from(source.emitterAddress, "hex").toString("base64"),
266+
chain_id: source.emitterChain,
267+
};
268+
};
269+
const stableDataSources =
270+
getDefaultDeploymentConfig("stable").dataSources.map(convertDataSource);
271+
const betaDataSources =
272+
getDefaultDeploymentConfig("beta").dataSources.map(convertDataSource);
273+
if (this.equalDataSources(config.config_v1.data_sources, stableDataSources))
317274
return "stable";
318275
else if (
319-
this.equalDataSources(
320-
config.config_v1.data_sources,
321-
betaConfig.data_sources
322-
)
276+
this.equalDataSources(config.config_v1.data_sources, betaDataSources)
323277
)
324278
return "beta";
325279
else return "unknown";

contract_manager/store/contracts/SuiContracts.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
stateId: "0xf9ff3ef935ef6cdfb659a203bf2754cebeb63346e29114a535ea6f41315e5a3f"
33
wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
44
type: SuiContract
5+
- chain: sui_mainnet
6+
stateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
7+
wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
8+
type: SuiContract
59
- chain: sui_testnet
610
stateId: "0xb3142a723792001caafc601b7c6fe38f09f3684e360b56d8d90fc574e71e75f3"
711
wormholeStateId: "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"
812
type: SuiContract
913
- chain: sui_testnet
10-
stateId: "0xe8c2ddcd5b10e8ed98e53b12fcf8f0f6fd9315f810ae61fa4001858851f21c88"
14+
stateId: "0x2d82612a354f0b7e52809fc2845642911c7190404620cec8688f68808f8800d8"
1115
wormholeStateId: "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"
1216
type: SuiContract

0 commit comments

Comments
 (0)