Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions contract_manager/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"author": "",
"dependencies": {
"@certusone/wormhole-sdk": "^0.9.8",
"@coral-xyz/anchor": "^0.29.0",
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/stargate": "^0.32.3",
Expand Down Expand Up @@ -31,7 +30,9 @@
"@ton/crypto": "^3.3.0",
"@ton/ton": "^15.1.0",
"@types/yargs": "catalog:",
"@wormhole-foundation/sdk-solana-core": "^4.18.0",
"@wormhole-foundation/sdk-base": "^4.19.0",
"@wormhole-foundation/sdk-definitions": "^4.19.0",
"@wormhole-foundation/sdk-solana-core": "^4.19.0",
"aptos": "^1.5.0",
"axios": "^0.24.0",
"bs58": "^5.0.0",
Expand Down Expand Up @@ -241,16 +242,6 @@
"types": "./dist/cjs/node/utils/governance.d.ts"
}
},
"./node/utils/preserve-native-fetch": {
"import": {
"default": "./dist/esm/node/utils/preserve-native-fetch.mjs",
"types": "./dist/esm/node/utils/preserve-native-fetch.d.ts"
},
"require": {
"default": "./dist/cjs/node/utils/preserve-native-fetch.cjs",
"types": "./dist/cjs/node/utils/preserve-native-fetch.d.ts"
}
},
"./node/utils/shell": {
"import": {
"default": "./dist/esm/node/utils/shell.mjs",
Expand Down
25 changes: 12 additions & 13 deletions contract_manager/scripts/execute_vaas.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-floating-promises */

/* eslint-disable unicorn/prefer-top-level-await */

/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable no-console */

import { parseVaa } from "@certusone/wormhole-sdk";
/** biome-ignore-all lint/suspicious/noConsole: CLI script */
import { decodeGovernancePayload } from "@pythnetwork/xc-admin-common";
import { deserialize } from "@wormhole-foundation/sdk-definitions";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { toPrivateKey } from "../src/core/base";
Expand Down Expand Up @@ -61,7 +54,12 @@ async function main() {
"mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj"
]
: DefaultStore.vaults.devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3;
console.log("Executing VAAs for vault", vault?.getId());

if (!vault) {
throw new Error(`Could not retrieve vault '${argv.vault}'`);
}

console.log("Executing VAAs for vault", vault.getId());
console.log(
"Executing VAAs for emitter",
// eslint-disable-next-line unicorn/no-await-expression-member
Expand Down Expand Up @@ -93,12 +91,13 @@ async function main() {
seqNumber++
) {
const submittedWormholeMessage = new SubmittedWormholeMessage(
await vault!.getEmitter(),
await vault.getEmitter(),
seqNumber,
vault!.cluster,
vault.cluster,
);
const vaa = await submittedWormholeMessage.fetchVaa();
const decodedAction = decodeGovernancePayload(parseVaa(vaa).payload);
const { payload } = deserialize("Uint8Array", new Uint8Array(vaa));
const decodedAction = decodeGovernancePayload(Buffer.from(payload));
if (!decodedAction) {
console.log("Skipping unknown action for vaa", seqNumber);
continue;
Expand Down
5 changes: 3 additions & 2 deletions contract_manager/scripts/manage_cardano_governance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** biome-ignore-all lint/suspicious/noConsole: this is a CLI script */

import { parseVaa } from "@certusone/wormhole-sdk";
import type { Wallet } from "@coral-xyz/anchor";
import type { PythCluster } from "@pythnetwork/client";
import {
Expand All @@ -9,6 +8,7 @@ import {
UpgradeCardanoSpendScript,
UpgradeCardanoWithdrawScript,
} from "@pythnetwork/xc-admin-common";
import { deserialize } from "@wormhole-foundation/sdk-definitions";
import type { Options } from "yargs";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
Expand Down Expand Up @@ -287,7 +287,8 @@ parser.command(
process.stderr.write(`Sequence ${seq}: not found, skipping\n`);
continue;
}
const action = decodeGovernancePayload(parseVaa(vaa).payload);
const { payload } = deserialize("Uint8Array", new Uint8Array(vaa));
const action = decodeGovernancePayload(Buffer.from(payload));
if (!action || action.targetChainId !== chain) {
process.stderr.write(
`Sequence ${seq}: could not decode as action for this chain, skipping\n`,
Expand Down
24 changes: 14 additions & 10 deletions contract_manager/scripts/sync_governance_vaas.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable unicorn/no-await-expression-member */
import { parseVaa } from "@certusone/wormhole-sdk";
/** biome-ignore-all lint/suspicious/noConsole: CLI script */
import { decodeGovernancePayload } from "@pythnetwork/xc-admin-common";
import { deserialize } from "@wormhole-foundation/sdk-definitions";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

Expand Down Expand Up @@ -44,9 +42,17 @@ async function main() {
const mainnetVault =
DefaultStore.vaults[
"mainnet-beta_FVQyHcooAtThJ83XFrNnv74BcinbRH3bRmfFamAHBfuj"
]!;
];
if (!mainnetVault) {
throw new Error("could not find mainnet vault");
}

const devnetVault =
DefaultStore.vaults.devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3!;
DefaultStore.vaults.devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3;
if (!devnetVault) {
throw new Error("could not find devnet vault");
}

let matchedVault: Vault;
if (
(await devnetVault.getEmitter()).toBuffer().toString("hex") ===
Expand All @@ -73,7 +79,6 @@ async function main() {
}
console.log("Starting from sequence number", lastExecuted);

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
const submittedWormholeMessage = new SubmittedWormholeMessage(
await matchedVault.getEmitter(),
Expand All @@ -88,8 +93,8 @@ async function main() {
console.log("no vaa found for sequence", lastExecuted + 1);
break;
}
const parsedVaa = parseVaa(vaa);
const action = decodeGovernancePayload(parsedVaa.payload);
const { payload } = deserialize("Uint8Array", new Uint8Array(vaa));
const action = decodeGovernancePayload(Buffer.from(payload));
if (!action) {
console.log("can not decode vaa, skipping");
} else if (
Expand All @@ -112,5 +117,4 @@ async function main() {
}
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises, unicorn/prefer-top-level-await
main();
37 changes: 12 additions & 25 deletions contract_manager/src/core/contracts/iota.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-base-to-string */
import { uint8ArrayToBCS } from "@certusone/wormhole-sdk/lib/cjs/sui";
import { bcs } from "@iota/iota-sdk/bcs";

const uint8ArrayToBCS = (arr: Uint8Array): Uint8Array =>
bcs.vector(bcs.u8()).serialize(arr).toBytes();

import { Ed25519Keypair } from "@iota/iota-sdk/keypairs/ed25519";
import { Transaction } from "@iota/iota-sdk/transactions";
import { IOTA_CLOCK_OBJECT_ID } from "@iota/iota-sdk/utils";
Expand Down Expand Up @@ -84,7 +79,7 @@ export class IotaPriceFeedContract extends PriceFeedContract {
* @param objectId - the object id to get
*/
async getPackageId(objectId: ObjectId): Promise<ObjectId> {
return this.client.getPackageId(objectId);
return await this.client.getPackageId(objectId);
}

async getPythPackageId(): Promise<ObjectId> {
Expand All @@ -99,7 +94,7 @@ export class IotaPriceFeedContract extends PriceFeedContract {
return `${this.chain.getId()}_${this.stateId}`;
}

private async parsePrice(priceInfo: {
private parsePrice(priceInfo: {
type: string;
fields: {
expo: { fields: { magnitude: string; negative: boolean } };
Expand Down Expand Up @@ -139,14 +134,12 @@ export class IotaPriceFeedContract extends PriceFeedContract {
);
}
return {
emaPrice: await this.parsePrice(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
emaPrice: this.parsePrice(
// @ts-ignore
priceInfo.data.content.fields.price_info.fields.price_feed.fields
.ema_price,
),
price: await this.parsePrice(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
price: this.parsePrice(
// @ts-ignore
priceInfo.data.content.fields.price_info.fields.price_feed.fields.price,
),
Expand Down Expand Up @@ -176,7 +169,7 @@ export class IotaPriceFeedContract extends PriceFeedContract {
return this.executeTransaction(tx, keypair);
}

async executeUpdatePriceFeed(): Promise<TxResult> {
executeUpdatePriceFeed(): Promise<TxResult> {
// We need the feed ids to be able to execute the transaction
// it may be possible to get them from the VAA but in batch transactions,
// it is also possible to hava fewer feeds that user wants to update compared to
Expand Down Expand Up @@ -324,7 +317,6 @@ export class IotaPriceFeedContract extends PriceFeedContract {

async getValidTimePeriod() {
const fields = await this.getStateFields();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return Number(fields.stale_price_threshold);
}
Expand All @@ -346,7 +338,6 @@ export class IotaPriceFeedContract extends PriceFeedContract {
if (result.data.content.dataType !== "moveObject") {
throw new Error("Data Sources type mismatch");
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return result.data.content.fields.value.fields.keys.map(
({
Expand All @@ -369,7 +360,6 @@ export class IotaPriceFeedContract extends PriceFeedContract {

async getGovernanceDataSource(): Promise<DataSource> {
const fields = await this.getStateFields();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const governanceFields = fields.governance_data_source.fields;
const chainId = governanceFields.emitter_chain;
Expand All @@ -383,14 +373,12 @@ export class IotaPriceFeedContract extends PriceFeedContract {

async getBaseUpdateFee() {
const fields = await this.getStateFields();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return { amount: fields.base_update_fee };
}

async getLastExecutedGovernanceSequence() {
const fields = await this.getStateFields();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return Number(fields.last_executed_governance_sequence);
}
Expand Down Expand Up @@ -471,8 +459,8 @@ export class IotaWormholeContract extends WormholeContract {
// via a Iota transaction due to the linear nature of the language, this is
// enforced at the TransactionBlock level by only allowing you to receive
// receipts.
async getChainId(): Promise<number> {
return this.chain.getWormholeChainId();
getChainId(): Promise<number> {
return Promise.resolve(this.chain.getWormholeChainId());
}

// NOTE: There's no way to getChain() on the main interface, should update
Expand Down Expand Up @@ -532,7 +520,6 @@ export class IotaWormholeContract extends WormholeContract {
return { id: result.digest, info: result };
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async getStateFields(): Promise<any> {
const provider = this.chain.getProvider();
const result = await provider.getObject({
Expand Down
Loading