Skip to content

Commit 736a202

Browse files
ali-behjatim30m
andauthored
chore(target_chains/sui): update sui js packages (#1340)
* chore(target_chains/sui): update sui js packages * chore: bump version --------- Co-authored-by: Amin Moghaddam <[email protected]>
1 parent f9de543 commit 736a202

File tree

12 files changed

+2095
-3164
lines changed

12 files changed

+2095
-3164
lines changed

contract_manager/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"@certusone/wormhole-sdk": "^0.9.8",
2525
"@injectivelabs/networks": "1.0.68",
26-
"@mysten/sui.js": "^0.37.1",
26+
"@mysten/sui.js": "^0.49.1",
2727
"@pythnetwork/cosmwasm-deploy-tools": "*",
2828
"@pythnetwork/entropy-sdk-solidity": "*",
2929
"@pythnetwork/price-service-client": "*",
@@ -32,7 +32,7 @@
3232
"aptos": "^1.5.0",
3333
"bs58": "^5.0.0",
3434
"ts-node": "^10.9.1",
35-
"typescript": "^4.9.3"
35+
"typescript": "^5.3.3"
3636
},
3737
"devDependencies": {
3838
"prettier": "^2.6.2",

contract_manager/src/chains.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ import {
2020
InjectiveExecutor,
2121
} from "@pythnetwork/cosmwasm-deploy-tools";
2222
import { Network } from "@injectivelabs/networks";
23-
import {
24-
Connection,
25-
Ed25519Keypair,
26-
JsonRpcProvider,
27-
RawSigner,
28-
} from "@mysten/sui.js";
23+
import { SuiClient } from "@mysten/sui.js/client";
24+
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
2925

3026
export type ChainConfig = Record<string, string> & {
3127
mainnet: boolean;
@@ -290,17 +286,15 @@ export class SuiChain extends Chain {
290286
).encode();
291287
}
292288

293-
getProvider(): JsonRpcProvider {
294-
return new JsonRpcProvider(new Connection({ fullnode: this.rpcUrl }));
289+
getProvider(): SuiClient {
290+
return new SuiClient({ url: this.rpcUrl });
295291
}
296292

297293
async getAccountAddress(privateKey: PrivateKey): Promise<string> {
298-
const provider = this.getProvider();
299294
const keypair = Ed25519Keypair.fromSecretKey(
300295
Buffer.from(privateKey, "hex")
301296
);
302-
const wallet = new RawSigner(keypair, provider);
303-
return await wallet.getAddress();
297+
return keypair.toSuiAddress();
304298
}
305299

306300
async getAccountBalance(privateKey: PrivateKey): Promise<number> {

contract_manager/src/contracts/sui.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import {
2-
Ed25519Keypair,
3-
ObjectId,
4-
RawSigner,
5-
SUI_CLOCK_OBJECT_ID,
6-
TransactionBlock,
7-
} from "@mysten/sui.js";
81
import { Chain, SuiChain } from "../chains";
92
import { DataSource } from "xc_admin_common";
103
import { PriceFeedContract, PrivateKey, TxResult } from "../base";
114
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
5+
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
6+
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
7+
import { TransactionBlock } from "@mysten/sui.js/transactions";
8+
9+
type ObjectId = string;
1210

1311
export class SuiPriceFeedContract extends PriceFeedContract {
1412
static type = "SuiPriceFeedContract";
@@ -96,13 +94,6 @@ export class SuiPriceFeedContract extends PriceFeedContract {
9694
timestamp: string;
9795
};
9896
}) {
99-
const packageId = await this.getPythPackageId();
100-
const expectedType = `${packageId}::price::Price`;
101-
if (priceInfo.type !== expectedType) {
102-
throw new Error(
103-
`Price type mismatch, expected ${expectedType} but found ${priceInfo.type}`
104-
);
105-
}
10697
let expo = priceInfo.fields.expo.fields.magnitude;
10798
if (priceInfo.fields.expo.fields.negative) expo = "-" + expo;
10899
let price = priceInfo.fields.price.fields.magnitude;
@@ -135,10 +126,14 @@ export class SuiPriceFeedContract extends PriceFeedContract {
135126
}
136127
return {
137128
emaPrice: await this.parsePrice(
129+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
130+
// @ts-ignore
138131
priceInfo.data.content.fields.price_info.fields.price_feed.fields
139132
.ema_price
140133
),
141134
price: await this.parsePrice(
135+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
136+
// @ts-ignore
142137
priceInfo.data.content.fields.price_info.fields.price_feed.fields.price
143138
),
144139
};
@@ -303,21 +298,25 @@ export class SuiPriceFeedContract extends PriceFeedContract {
303298
keypair: Ed25519Keypair
304299
) {
305300
const provider = this.getProvider();
306-
const txBlock = {
301+
tx.setSender(keypair.toSuiAddress());
302+
const dryRun = await provider.dryRunTransactionBlock({
303+
transactionBlock: await tx.build({ client: provider }),
304+
});
305+
tx.setGasBudget(BigInt(dryRun.input.gasData.budget.toString()) * BigInt(2));
306+
return provider.signAndExecuteTransactionBlock({
307+
signer: keypair,
307308
transactionBlock: tx,
308309
options: {
309310
showEffects: true,
310311
showEvents: true,
311312
},
312-
};
313-
const wallet = new RawSigner(keypair, provider);
314-
const gasCost = await wallet.getGasCostEstimation(txBlock);
315-
tx.setGasBudget(gasCost * BigInt(2));
316-
return wallet.signAndExecuteTransactionBlock(txBlock);
313+
});
317314
}
318315

319316
async getValidTimePeriod() {
320317
const fields = await this.getStateFields();
318+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
319+
// @ts-ignore
321320
return Number(fields.stale_price_threshold);
322321
}
323322

@@ -338,6 +337,8 @@ export class SuiPriceFeedContract extends PriceFeedContract {
338337
if (result.data.content.dataType !== "moveObject") {
339338
throw new Error("Data Sources type mismatch");
340339
}
340+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
341+
// @ts-ignore
341342
return result.data.content.fields.value.fields.keys.map(
342343
({
343344
fields,
@@ -359,6 +360,8 @@ export class SuiPriceFeedContract extends PriceFeedContract {
359360

360361
async getGovernanceDataSource(): Promise<DataSource> {
361362
const fields = await this.getStateFields();
363+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
364+
// @ts-ignore
362365
const governanceFields = fields.governance_data_source.fields;
363366
const chainId = governanceFields.emitter_chain;
364367
const emitterAddress =
@@ -371,11 +374,15 @@ export class SuiPriceFeedContract extends PriceFeedContract {
371374

372375
async getBaseUpdateFee() {
373376
const fields = await this.getStateFields();
377+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
378+
// @ts-ignore
374379
return { amount: fields.base_update_fee };
375380
}
376381

377382
async getLastExecutedGovernanceSequence() {
378383
const fields = await this.getStateFields();
384+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
385+
// @ts-ignore
379386
return Number(fields.last_executed_governance_sequence);
380387
}
381388

contract_manager/store/contracts/SuiPriceFeedContracts.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
- chain: sui_mainnet
2-
stateId: "0xf9ff3ef935ef6cdfb659a203bf2754cebeb63346e29114a535ea6f41315e5a3f"
3-
wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
4-
type: SuiPriceFeedContract
51
- chain: sui_mainnet
62
stateId: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8"
73
wormholeStateId: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
84
type: SuiPriceFeedContract
9-
- chain: sui_testnet
10-
stateId: "0xb3142a723792001caafc601b7c6fe38f09f3684e360b56d8d90fc574e71e75f3"
11-
wormholeStateId: "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"
12-
type: SuiPriceFeedContract
135
- chain: sui_testnet
146
stateId: "0x2d82612a354f0b7e52809fc2845642911c7190404620cec8688f68808f8800d8"
157
wormholeStateId: "0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02"

0 commit comments

Comments
 (0)