Skip to content

Commit 4a2b8d4

Browse files
feat(target_chains/sui): use sui sdk v1 (#1802)
* feat: Update SUI SDK import and required functions to new version @mysten/sui πŸš€ * feat: Update SUI SDK import and required functions to new version @mysten/sui πŸš€ * feat: Update SUI SDK import and required functions to new version @mysten/sui πŸš€ * feat: Update SUI SDK import and required functions to new version @mysten/sui πŸš€ * chore: remove old @mysten/sui version and add new version πŸš€ * feat: update Prettier settings to use double quotes πŸš€ * feat: update Prettier settings to use double quotes πŸš€ * feat: update Prettier settings to use double quotes πŸš€ * fix: run pre-commit * chore: remove commented codes * chore: bump versions * chore(target_chains/sui/sdk/js): update readme * chore: remove commented code --------- Co-authored-by: Goraniya Karan <[email protected]>
1 parent 1ea92c9 commit 4a2b8d4

File tree

15 files changed

+493
-718
lines changed

15 files changed

+493
-718
lines changed

β€Žapps/price_pusher/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "7.0.2",
3+
"version": "7.1.0",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -56,7 +56,7 @@
5656
"@coral-xyz/anchor": "^0.30.0",
5757
"@injectivelabs/networks": "^1.14.6",
5858
"@injectivelabs/sdk-ts": "1.10.72",
59-
"@mysten/sui.js": "^0.49.1",
59+
"@mysten/sui": "^1.3.0",
6060
"@pythnetwork/price-service-client": "workspace:*",
6161
"@pythnetwork/price-service-sdk": "workspace:^",
6262
"@pythnetwork/pyth-sdk-solidity": "workspace:*",

β€Žapps/price_pusher/src/sui/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PythPriceListener } from "../pyth-price-listener";
66
import { Controller } from "../controller";
77
import { Options } from "yargs";
88
import { SuiPriceListener, SuiPricePusher } from "./sui";
9-
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
9+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
1010
import pino from "pino";
1111

1212
export default {

β€Žapps/price_pusher/src/sui/sui.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
import { DurationInSeconds } from "../utils";
88
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
99
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
10-
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
11-
import { TransactionBlock } from "@mysten/sui.js/transactions";
12-
import { SuiClient, SuiObjectRef, PaginatedCoins } from "@mysten/sui.js/client";
10+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
11+
import { Transaction } from "@mysten/sui/transactions";
12+
import { SuiClient, SuiObjectRef, PaginatedCoins } from "@mysten/sui/client";
1313
import { Logger } from "pino";
1414

1515
const GAS_FEE_FOR_SPLIT = 2_000_000_000;
@@ -219,7 +219,7 @@ export class SuiPricePusher implements IPricePusher {
219219
// 3 price feeds per transaction is the optimal number for gas cost.
220220
const priceIdChunks = chunkArray(priceIds, 3);
221221

222-
const txBlocks: TransactionBlock[] = [];
222+
const txBlocks: Transaction[] = [];
223223

224224
await Promise.all(
225225
priceIdChunks.map(async (priceIdChunk) => {
@@ -232,7 +232,7 @@ export class SuiPricePusher implements IPricePusher {
232232
);
233233
}
234234
const vaa = vaas[0];
235-
const tx = new TransactionBlock();
235+
const tx = new Transaction();
236236
await this.pythClient.updatePriceFeeds(
237237
tx,
238238
[Buffer.from(vaa, "base64")],
@@ -246,14 +246,12 @@ export class SuiPricePusher implements IPricePusher {
246246
}
247247

248248
/** Send every transaction in txs in parallel, returning when all transactions have completed. */
249-
private async sendTransactionBlocks(
250-
txs: TransactionBlock[]
251-
): Promise<void[]> {
249+
private async sendTransactionBlocks(txs: Transaction[]): Promise<void[]> {
252250
return Promise.all(txs.map((tx) => this.sendTransactionBlock(tx)));
253251
}
254252

255253
/** Send a single transaction block using a gas coin from the pool. */
256-
private async sendTransactionBlock(tx: TransactionBlock): Promise<void> {
254+
private async sendTransactionBlock(tx: Transaction): Promise<void> {
257255
const gasObject = this.gasPool.shift();
258256
if (gasObject === undefined) {
259257
this.logger.warn("No available gas coin. Skipping push.");
@@ -264,9 +262,9 @@ export class SuiPricePusher implements IPricePusher {
264262
try {
265263
tx.setGasPayment([gasObject]);
266264
tx.setGasBudget(this.gasBudget);
267-
const result = await this.provider.signAndExecuteTransactionBlock({
265+
const result = await this.provider.signAndExecuteTransaction({
268266
signer: this.signer,
269-
transactionBlock: tx,
267+
transaction: tx,
270268
options: {
271269
showEffects: true,
272270
},
@@ -422,20 +420,20 @@ export class SuiPricePusher implements IPricePusher {
422420
gasCoin: SuiObjectRef
423421
): Promise<SuiObjectRef[]> {
424422
// TODO: implement chunking if numGasObjects exceeds MAX_NUM_CREATED_OBJECTS
425-
const tx = new TransactionBlock();
423+
const tx = new Transaction();
426424
const coins = tx.splitCoins(
427425
tx.gas,
428-
Array.from({ length: numGasObjects }, () => tx.pure(splitAmount))
426+
Array.from({ length: numGasObjects }, () => tx.pure.u64(splitAmount))
429427
);
430428

431429
tx.transferObjects(
432430
Array.from({ length: numGasObjects }, (_, i) => coins[i]),
433-
tx.pure(signerAddress)
431+
tx.pure.address(signerAddress)
434432
);
435433
tx.setGasPayment([gasCoin]);
436-
const result = await provider.signAndExecuteTransactionBlock({
434+
const result = await provider.signAndExecuteTransaction({
437435
signer,
438-
transactionBlock: tx,
436+
transaction: tx,
439437
options: { showEffects: true },
440438
});
441439
const error = result?.effects?.status.error;
@@ -474,7 +472,7 @@ export class SuiPricePusher implements IPricePusher {
474472
const lockedAddresses: Set<string> = new Set();
475473
initialLockedAddresses.forEach((value) => lockedAddresses.add(value));
476474
for (let i = 0; i < gasCoinsChunks.length; i++) {
477-
const mergeTx = new TransactionBlock();
475+
const mergeTx = new Transaction();
478476
let coins = gasCoinsChunks[i];
479477
coins = coins.filter((coin) => !lockedAddresses.has(coin.objectId));
480478
if (finalCoin) {
@@ -483,9 +481,9 @@ export class SuiPricePusher implements IPricePusher {
483481
mergeTx.setGasPayment(coins);
484482
let mergeResult;
485483
try {
486-
mergeResult = await provider.signAndExecuteTransactionBlock({
484+
mergeResult = await provider.signAndExecuteTransaction({
487485
signer,
488-
transactionBlock: mergeTx,
486+
transaction: mergeTx,
489487
options: { showEffects: true },
490488
});
491489
} catch (err) {

β€Žcontract_manager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@cosmjs/cosmwasm-stargate": "^0.32.3",
2727
"@cosmjs/stargate": "^0.32.3",
2828
"@injectivelabs/networks": "^1.14.6",
29-
"@mysten/sui.js": "^0.49.1",
29+
"@mysten/sui": "^1.3.0",
3030
"@pythnetwork/client": "^2.21.1",
3131
"@pythnetwork/contract-manager": "workspace:*",
3232
"@pythnetwork/cosmwasm-deploy-tools": "workspace:*",

β€Žcontract_manager/src/chains.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
InjectiveExecutor,
2121
} from "@pythnetwork/cosmwasm-deploy-tools";
2222
import { Network } from "@injectivelabs/networks";
23-
import { SuiClient } from "@mysten/sui.js/client";
24-
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
23+
import { SuiClient } from "@mysten/sui/client";
24+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2525
import { TokenId } from "./token";
2626
import { BN, Provider, Wallet, WalletUnlocked } from "fuels";
2727
import { FUEL_ETH_ASSET_ID } from "@pythnetwork/pyth-fuel-js";

β€Žcontract_manager/src/contracts/sui.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { DataSource } from "@pythnetwork/xc-admin-common";
33
import { WormholeContract } from "./wormhole";
44
import { PriceFeedContract, PrivateKey, TxResult } from "../base";
55
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
6-
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
7-
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
8-
import { TransactionBlock } from "@mysten/sui.js/transactions";
6+
import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
7+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
8+
import { Transaction } from "@mysten/sui/transactions";
99
import { uint8ArrayToBCS } from "@certusone/wormhole-sdk/lib/cjs/sui";
1010

1111
type ObjectId = string;
@@ -148,7 +148,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
148148
* @param keypair used to sign the transaction
149149
*/
150150
async executeMigrateInstruction(vaa: Buffer, keypair: Ed25519Keypair) {
151-
const tx = new TransactionBlock();
151+
const tx = new Transaction();
152152
const packageId = await this.getPythPackageId();
153153
const verificationReceipt = await this.getVaaVerificationReceipt(
154154
tx,
@@ -177,7 +177,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
177177
vaas: Buffer[],
178178
feedIds: string[]
179179
): Promise<TxResult> {
180-
const tx = new TransactionBlock();
180+
const tx = new Transaction();
181181
await this.client.updatePriceFeeds(tx, vaas, feedIds);
182182
const keypair = Ed25519Keypair.fromSecretKey(
183183
Buffer.from(senderPrivateKey, "hex")
@@ -189,7 +189,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
189189
senderPrivateKey: string,
190190
vaas: Buffer[]
191191
): Promise<TxResult> {
192-
const tx = new TransactionBlock();
192+
const tx = new Transaction();
193193
await this.client.createPriceFeed(tx, vaas);
194194
const keypair = Ed25519Keypair.fromSecretKey(
195195
Buffer.from(senderPrivateKey, "hex")
@@ -206,7 +206,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
206206
const keypair = Ed25519Keypair.fromSecretKey(
207207
Buffer.from(senderPrivateKey, "hex")
208208
);
209-
const tx = new TransactionBlock();
209+
const tx = new Transaction();
210210
const packageId = await this.getPythPackageId();
211211
const verificationReceipt = await this.getVaaVerificationReceipt(
212212
tx,
@@ -229,7 +229,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
229229
modules: number[][],
230230
dependencies: string[]
231231
) {
232-
const tx = new TransactionBlock();
232+
const tx = new Transaction();
233233
const packageId = await this.getPythPackageId();
234234
const verificationReceipt = await this.getVaaVerificationReceipt(
235235
tx,
@@ -245,7 +245,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
245245
const [upgradeReceipt] = tx.upgrade({
246246
modules,
247247
dependencies,
248-
packageId: packageId,
248+
package: packageId,
249249
ticket: upgradeTicket,
250250
});
251251

@@ -266,7 +266,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
266266
* @private
267267
*/
268268
async getVaaVerificationReceipt(
269-
tx: TransactionBlock,
269+
tx: Transaction,
270270
packageId: string,
271271
vaa: Buffer
272272
) {
@@ -276,7 +276,7 @@ export class SuiPriceFeedContract extends PriceFeedContract {
276276
target: `${wormholePackageId}::vaa::parse_and_verify`,
277277
arguments: [
278278
tx.object(this.wormholeStateId),
279-
tx.pure(Array.from(vaa)),
279+
tx.pure.arguments(Array.from(vaa)),
280280
tx.object(SUI_CLOCK_OBJECT_ID),
281281
],
282282
});
@@ -295,19 +295,16 @@ export class SuiPriceFeedContract extends PriceFeedContract {
295295
* @param keypair
296296
* @private
297297
*/
298-
private async executeTransaction(
299-
tx: TransactionBlock,
300-
keypair: Ed25519Keypair
301-
) {
298+
private async executeTransaction(tx: Transaction, keypair: Ed25519Keypair) {
302299
const provider = this.getProvider();
303300
tx.setSender(keypair.toSuiAddress());
304301
const dryRun = await provider.dryRunTransactionBlock({
305302
transactionBlock: await tx.build({ client: provider }),
306303
});
307304
tx.setGasBudget(BigInt(dryRun.input.gasData.budget.toString()) * BigInt(2));
308-
return provider.signAndExecuteTransactionBlock({
305+
return provider.signAndExecuteTransaction({
309306
signer: keypair,
310-
transactionBlock: tx,
307+
transaction: tx,
311308
options: {
312309
showEffects: true,
313310
showEvents: true,
@@ -489,7 +486,7 @@ export class SuiWormholeContract extends WormholeContract {
489486
senderPrivateKey: PrivateKey,
490487
vaa: Buffer
491488
): Promise<TxResult> {
492-
const tx = new TransactionBlock();
489+
const tx = new Transaction();
493490
const coreObjectId = this.stateId;
494491
const corePackageId = await this.client.getWormholePackageId();
495492
const [verifiedVaa] = tx.moveCall({
@@ -552,19 +549,16 @@ export class SuiWormholeContract extends WormholeContract {
552549
* @param keypair
553550
* @private
554551
*/
555-
private async executeTransaction(
556-
tx: TransactionBlock,
557-
keypair: Ed25519Keypair
558-
) {
552+
private async executeTransaction(tx: Transaction, keypair: Ed25519Keypair) {
559553
const provider = this.chain.getProvider();
560554
tx.setSender(keypair.toSuiAddress());
561555
const dryRun = await provider.dryRunTransactionBlock({
562556
transactionBlock: await tx.build({ client: provider }),
563557
});
564558
tx.setGasBudget(BigInt(dryRun.input.gasData.budget.toString()) * BigInt(2));
565-
return provider.signAndExecuteTransactionBlock({
559+
return provider.signAndExecuteTransaction({
566560
signer: keypair,
567-
transactionBlock: tx,
561+
transaction: tx,
568562
options: {
569563
showEffects: true,
570564
showEvents: true,

0 commit comments

Comments
Β (0)