Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions contract_manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/stargate": "^0.32.3",
"@injectivelabs/networks": "^1.14.6",
"@iota/iota-sdk": "^0.5.0",
"@mysten/sui": "^1.3.0",
"@pythnetwork/client": "catalog:",
"@pythnetwork/cosmwasm-deploy-tools": "workspace:*",
Expand All @@ -36,6 +37,7 @@
"@pythnetwork/pyth-sdk-solidity": "workspace:^",
"@pythnetwork/pyth-starknet-js": "^0.2.1",
"@pythnetwork/pyth-sui-js": "workspace:*",
"@pythnetwork/pyth-iota-js": "workspace:*",
"@pythnetwork/pyth-ton": "workspace:*",
"@pythnetwork/pyth-ton-js": "workspace:*",
"@pythnetwork/solana-utils": "workspace:^",
Expand Down
2 changes: 2 additions & 0 deletions contract_manager/scripts/sync_wormhole_guardian_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CosmWasmPriceFeedContract,
DefaultStore,
EvmPriceFeedContract,
IotaWormholeContract,
SuiWormholeContract,
toPrivateKey,
} from "../src";
Expand Down Expand Up @@ -32,6 +33,7 @@ async function main() {
for (const contract of Object.values(DefaultStore.wormhole_contracts)) {
if (
contract instanceof SuiWormholeContract ||
contract instanceof IotaWormholeContract ||
contract instanceof AptosWormholeContract
) {
if (chains && !chains.includes(contract.getChain().getId())) {
Expand Down
86 changes: 80 additions & 6 deletions contract_manager/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
InjectiveExecutor,
} from "@pythnetwork/cosmwasm-deploy-tools";
import { Network } from "@injectivelabs/networks";
import { IotaClient } from "@iota/iota-sdk/client";
import { SuiClient } from "@mysten/sui/client";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { Ed25519Keypair as IotaEd25519Keypair } from "@iota/iota-sdk/keypairs/ed25519";
import { Ed25519Keypair as SuiEd25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { TokenId } from "./token";
import { BN, Provider, Wallet, WalletUnlocked } from "fuels";
import { FUEL_ETH_ASSET_ID } from "@pythnetwork/pyth-fuel-js";
Expand All @@ -38,6 +40,8 @@
import { PythContract } from "@pythnetwork/pyth-ton-js";
import * as nearAPI from "near-api-js";
import * as bs58 from "bs58";
import { MIST_PER_SUI } from "@mysten/sui/utils";
import { NANOS_PER_IOTA } from "@iota/iota-sdk/utils";

/**
* Returns the chain rpc url with any environment variables replaced or throws an error if any are missing
Expand Down Expand Up @@ -174,11 +178,11 @@
);
}

async getAccountAddress(_privateKey: PrivateKey): Promise<string> {

Check warning on line 181 in contract_manager/src/chains.ts

View workflow job for this annotation

GitHub Actions / test

'_privateKey' is defined but never used
throw new Error("Can not get account for GlobalChain.");
}

async getAccountBalance(_privateKey: PrivateKey): Promise<number> {

Check warning on line 185 in contract_manager/src/chains.ts

View workflow job for this annotation

GitHub Actions / test

'_privateKey' is defined but never used
throw new Error("Can not get account balance for GlobalChain.");
}

Expand Down Expand Up @@ -334,8 +338,8 @@
}

async getAccountAddress(privateKey: PrivateKey): Promise<string> {
const keypair = Ed25519Keypair.fromSecretKey(
Buffer.from(privateKey, "hex")
const keypair = SuiEd25519Keypair.fromSecretKey(
new Uint8Array(Buffer.from(privateKey, "hex"))
);
return keypair.toSuiAddress();
}
Expand All @@ -345,7 +349,73 @@
const balance = await provider.getBalance({
owner: await this.getAccountAddress(privateKey),
});
return Number(balance.totalBalance) / 10 ** 9;
return Number(balance.totalBalance) / Number(MIST_PER_SUI);
}
}

export class IotaChain extends Chain {
static type = "IotaChain";

constructor(
id: string,
mainnet: boolean,
wormholeChainName: string,
nativeToken: TokenId | undefined,
public rpcUrl: string
) {
super(id, mainnet, wormholeChainName, nativeToken);
}

static fromJson(parsed: ChainConfig): IotaChain {
if (parsed.type !== IotaChain.type) throw new Error("Invalid type");
return new IotaChain(
parsed.id,
parsed.mainnet,
parsed.wormholeChainName,
parsed.nativeToken,
parsed.rpcUrl
);
}

toJson(): KeyValueConfig {
return {
id: this.id,
wormholeChainName: this.wormholeChainName,
mainnet: this.mainnet,
rpcUrl: this.rpcUrl,
type: IotaChain.type,
};
}

getType(): string {
return IotaChain.type;
}

/**
* Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
* @param digest hex string of the 32 byte digest for the new package without the 0x prefix
*/
generateGovernanceUpgradePayload(digest: string): Buffer {
return new UpgradeContract256Bit(this.wormholeChainName, digest).encode();
}

getProvider(): IotaClient {
return new IotaClient({ url: this.rpcUrl });
}

async getAccountAddress(privateKey: PrivateKey): Promise<string> {
const keypair = IotaEd25519Keypair.fromSecretKey(
new Uint8Array(Buffer.from(privateKey, "hex"))
);
return keypair.toIotaAddress();
}

async getAccountBalance(privateKey: PrivateKey): Promise<number> {
const provider = this.getProvider();
const balance = await provider.getBalance({
owner: await this.getAccountAddress(privateKey),
});
return Number(balance.totalBalance) / Number(NANOS_PER_IOTA);
}
}

Expand Down Expand Up @@ -439,7 +509,7 @@
}

async estiamteAndSendTransaction(
transactionObject: any,

Check warning on line 512 in contract_manager/src/chains.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
txParams: { from?: string; value?: string }
) {
const GAS_ESTIMATE_MULTIPLIER = 2;
Expand Down Expand Up @@ -913,7 +983,9 @@

async getAccountAddress(privateKey: PrivateKey): Promise<string> {
return Buffer.from(
Ed25519Keypair.fromSecretKey(Buffer.from(privateKey, "hex"))
SuiEd25519Keypair.fromSecretKey(
new Uint8Array(Buffer.from(privateKey, "hex"))
)
.getPublicKey()
.toRawBytes()
).toString("hex");
Expand All @@ -932,7 +1004,9 @@
): Promise<nearAPI.Account> {
const keyStore = new nearAPI.keyStores.InMemoryKeyStore();
if (typeof senderPrivateKey !== "undefined") {
const key = bs58.encode(Buffer.from(senderPrivateKey, "hex"));
const key = bs58.encode(
new Uint8Array(Buffer.from(senderPrivateKey, "hex"))
);
const keyPair = nearAPI.KeyPair.fromString(key);
const address = await this.getAccountAddress(senderPrivateKey);
await keyStore.setKey(this.networkId, address, keyPair);
Expand Down
1 change: 1 addition & 0 deletions contract_manager/src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./cosmwasm";
export * from "./evm";
export * from "./fuel";
export * from "./sui";
export * from "./iota";
export * from "./wormhole";
export * from "./evm_abis";
export * from "./ton";
Loading
Loading