@@ -20,8 +20,10 @@ import {
2020 InjectiveExecutor ,
2121} from "@pythnetwork/cosmwasm-deploy-tools" ;
2222import { Network } from "@injectivelabs/networks" ;
23+ import { IotaClient } from "@iota/iota-sdk/client" ;
2324import { SuiClient } from "@mysten/sui/client" ;
24- import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" ;
25+ import { Ed25519Keypair as IotaEd25519Keypair } from "@iota/iota-sdk/keypairs/ed25519" ;
26+ import { Ed25519Keypair as SuiEd25519Keypair } from "@mysten/sui/keypairs/ed25519" ;
2527import { TokenId } from "./token" ;
2628import { BN , Provider , Wallet , WalletUnlocked } from "fuels" ;
2729import { FUEL_ETH_ASSET_ID } from "@pythnetwork/pyth-fuel-js" ;
@@ -38,6 +40,8 @@ import { keyPairFromSeed } from "@ton/crypto";
3840import { PythContract } from "@pythnetwork/pyth-ton-js" ;
3941import * as nearAPI from "near-api-js" ;
4042import * as bs58 from "bs58" ;
43+ import { MIST_PER_SUI } from "@mysten/sui/utils" ;
44+ import { NANOS_PER_IOTA } from "@iota/iota-sdk/utils" ;
4145import * as chains from "viem/chains" ;
4246
4347/**
@@ -337,8 +341,8 @@ export class SuiChain extends Chain {
337341 }
338342
339343 async getAccountAddress ( privateKey : PrivateKey ) : Promise < string > {
340- const keypair = Ed25519Keypair . fromSecretKey (
341- Buffer . from ( privateKey , "hex" )
344+ const keypair = SuiEd25519Keypair . fromSecretKey (
345+ new Uint8Array ( Buffer . from ( privateKey , "hex" ) )
342346 ) ;
343347 return keypair . toSuiAddress ( ) ;
344348 }
@@ -348,7 +352,73 @@ export class SuiChain extends Chain {
348352 const balance = await provider . getBalance ( {
349353 owner : await this . getAccountAddress ( privateKey ) ,
350354 } ) ;
351- return Number ( balance . totalBalance ) / 10 ** 9 ;
355+ return Number ( balance . totalBalance ) / Number ( MIST_PER_SUI ) ;
356+ }
357+ }
358+
359+ export class IotaChain extends Chain {
360+ static type = "IotaChain" ;
361+
362+ constructor (
363+ id : string ,
364+ mainnet : boolean ,
365+ wormholeChainName : string ,
366+ nativeToken : TokenId | undefined ,
367+ public rpcUrl : string
368+ ) {
369+ super ( id , mainnet , wormholeChainName , nativeToken ) ;
370+ }
371+
372+ static fromJson ( parsed : ChainConfig ) : IotaChain {
373+ if ( parsed . type !== IotaChain . type ) throw new Error ( "Invalid type" ) ;
374+ return new IotaChain (
375+ parsed . id ,
376+ parsed . mainnet ,
377+ parsed . wormholeChainName ,
378+ parsed . nativeToken ,
379+ parsed . rpcUrl
380+ ) ;
381+ }
382+
383+ toJson ( ) : KeyValueConfig {
384+ return {
385+ id : this . id ,
386+ wormholeChainName : this . wormholeChainName ,
387+ mainnet : this . mainnet ,
388+ rpcUrl : this . rpcUrl ,
389+ type : IotaChain . type ,
390+ } ;
391+ }
392+
393+ getType ( ) : string {
394+ return IotaChain . type ;
395+ }
396+
397+ /**
398+ * Returns the payload for a governance contract upgrade instruction for contracts deployed on this chain
399+ * @param digest hex string of the 32 byte digest for the new package without the 0x prefix
400+ */
401+ generateGovernanceUpgradePayload ( digest : string ) : Buffer {
402+ return new UpgradeContract256Bit ( this . wormholeChainName , digest ) . encode ( ) ;
403+ }
404+
405+ getProvider ( ) : IotaClient {
406+ return new IotaClient ( { url : this . rpcUrl } ) ;
407+ }
408+
409+ async getAccountAddress ( privateKey : PrivateKey ) : Promise < string > {
410+ const keypair = IotaEd25519Keypair . fromSecretKey (
411+ new Uint8Array ( Buffer . from ( privateKey , "hex" ) )
412+ ) ;
413+ return keypair . toIotaAddress ( ) ;
414+ }
415+
416+ async getAccountBalance ( privateKey : PrivateKey ) : Promise < number > {
417+ const provider = this . getProvider ( ) ;
418+ const balance = await provider . getBalance ( {
419+ owner : await this . getAccountAddress ( privateKey ) ,
420+ } ) ;
421+ return Number ( balance . totalBalance ) / Number ( NANOS_PER_IOTA ) ;
352422 }
353423}
354424
@@ -932,7 +1002,9 @@ export class NearChain extends Chain {
9321002
9331003 async getAccountAddress ( privateKey : PrivateKey ) : Promise < string > {
9341004 return Buffer . from (
935- Ed25519Keypair . fromSecretKey ( Buffer . from ( privateKey , "hex" ) )
1005+ SuiEd25519Keypair . fromSecretKey (
1006+ new Uint8Array ( Buffer . from ( privateKey , "hex" ) )
1007+ )
9361008 . getPublicKey ( )
9371009 . toRawBytes ( )
9381010 ) . toString ( "hex" ) ;
@@ -951,7 +1023,9 @@ export class NearChain extends Chain {
9511023 ) : Promise < nearAPI . Account > {
9521024 const keyStore = new nearAPI . keyStores . InMemoryKeyStore ( ) ;
9531025 if ( typeof senderPrivateKey !== "undefined" ) {
954- const key = bs58 . encode ( Buffer . from ( senderPrivateKey , "hex" ) ) ;
1026+ const key = bs58 . encode (
1027+ new Uint8Array ( Buffer . from ( senderPrivateKey , "hex" ) )
1028+ ) ;
9551029 const keyPair = nearAPI . KeyPair . fromString ( key ) ;
9561030 const address = await this . getAccountAddress ( senderPrivateKey ) ;
9571031 await keyStore . setKey ( this . networkId , address , keyPair ) ;
0 commit comments