Skip to content

Commit

Permalink
[sui-sdk] Sui sdk improvements (#1065)
Browse files Browse the repository at this point in the history
* Split all coins in 1 transaction

* Use buffer library instead of built-in Buffer
  • Loading branch information
m30m authored Sep 25, 2023
1 parent 24f582c commit 940c203
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion target_chains/sui/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const OPTIONS = {
},
endpoint: {
type: "string",
desc: "Price service endpoint to use, defaults to https://xc-mainnet.pyth.network for mainnet and https://xc-testnet.pyth.network for testnet",
desc: "Price service endpoint to use, defaults to https://hermes.pyth.network for mainnet and https://hermes-beta.pyth.network for testnet",
},
"feed-id": {
type: "array",
Expand Down
2 changes: 1 addition & 1 deletion target_chains/sui/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-sui-js",
"version": "1.2.0",
"version": "1.2.1",
"description": "Pyth Network Sui Utilities",
"homepage": "https://pyth.network",
"author": {
Expand Down
13 changes: 9 additions & 4 deletions target_chains/sui/sdk/js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TransactionBlock,
} from "@mysten/sui.js";
import { HexString } from "@pythnetwork/price-service-client";
import { Buffer } from "buffer";

const MAX_ARGUMENT_SIZE = 16 * 1024;

Expand Down Expand Up @@ -155,6 +156,12 @@ export class SuiPythClient {
}

const priceInfoObjects: ObjectId[] = [];
const baseUpdateFee = await this.getBaseUpdateFee();
const coins = tx.splitCoins(
tx.gas,
feedIds.map(() => tx.pure(baseUpdateFee))
);
let coinId = 0;
for (const feedId of feedIds) {
const priceInfoObjectId = await this.getPriceFeedObjectId(feedId);
if (!priceInfoObjectId) {
Expand All @@ -163,19 +170,17 @@ export class SuiPythClient {
);
}
priceInfoObjects.push(priceInfoObjectId);
const coin = tx.splitCoins(tx.gas, [
tx.pure(await this.getBaseUpdateFee()),
]);
[priceUpdatesHotPotato] = tx.moveCall({
target: `${packageId}::pyth::update_single_price_feed`,
arguments: [
tx.object(this.pythStateId),
priceUpdatesHotPotato,
tx.object(priceInfoObjectId),
coin,
coins[coinId],
tx.object(SUI_CLOCK_OBJECT_ID),
],
});
coinId++;
}
tx.moveCall({
target: `${packageId}::hot_potato_vector::destroy`,
Expand Down
2 changes: 1 addition & 1 deletion target_chains/sui/sdk/js/src/examples/SuiRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RawSigner,
TransactionBlock,
} from "@mysten/sui.js";

import { Buffer } from "buffer";
import { SuiPythClient } from "../client";
import { SuiPriceServiceConnection } from "../index";

Expand Down

0 comments on commit 940c203

Please sign in to comment.