@@ -20,8 +20,10 @@ import {
20
20
InjectiveExecutor ,
21
21
} from "@pythnetwork/cosmwasm-deploy-tools" ;
22
22
import { Network } from "@injectivelabs/networks" ;
23
+ import { IotaClient } from "@iota/iota-sdk/client" ;
23
24
import { 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" ;
25
27
import { TokenId } from "./token" ;
26
28
import { BN , Provider , Wallet , WalletUnlocked } from "fuels" ;
27
29
import { FUEL_ETH_ASSET_ID } from "@pythnetwork/pyth-fuel-js" ;
@@ -38,6 +40,8 @@ import { keyPairFromSeed } from "@ton/crypto";
38
40
import { PythContract } from "@pythnetwork/pyth-ton-js" ;
39
41
import * as nearAPI from "near-api-js" ;
40
42
import * as bs58 from "bs58" ;
43
+ import { MIST_PER_SUI } from "@mysten/sui/utils" ;
44
+ import { NANOS_PER_IOTA } from "@iota/iota-sdk/utils" ;
41
45
import * as chains from "viem/chains" ;
42
46
43
47
/**
@@ -337,8 +341,8 @@ export class SuiChain extends Chain {
337
341
}
338
342
339
343
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" ) )
342
346
) ;
343
347
return keypair . toSuiAddress ( ) ;
344
348
}
@@ -348,7 +352,73 @@ export class SuiChain extends Chain {
348
352
const balance = await provider . getBalance ( {
349
353
owner : await this . getAccountAddress ( privateKey ) ,
350
354
} ) ;
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 ) ;
352
422
}
353
423
}
354
424
@@ -932,7 +1002,9 @@ export class NearChain extends Chain {
932
1002
933
1003
async getAccountAddress ( privateKey : PrivateKey ) : Promise < string > {
934
1004
return Buffer . from (
935
- Ed25519Keypair . fromSecretKey ( Buffer . from ( privateKey , "hex" ) )
1005
+ SuiEd25519Keypair . fromSecretKey (
1006
+ new Uint8Array ( Buffer . from ( privateKey , "hex" ) )
1007
+ )
936
1008
. getPublicKey ( )
937
1009
. toRawBytes ( )
938
1010
) . toString ( "hex" ) ;
@@ -951,7 +1023,9 @@ export class NearChain extends Chain {
951
1023
) : Promise < nearAPI . Account > {
952
1024
const keyStore = new nearAPI . keyStores . InMemoryKeyStore ( ) ;
953
1025
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
+ ) ;
955
1029
const keyPair = nearAPI . KeyPair . fromString ( key ) ;
956
1030
const address = await this . getAccountAddress ( senderPrivateKey ) ;
957
1031
await keyStore . setKey ( this . networkId , address , keyPair ) ;
0 commit comments