11import { SuiClient } from "@mysten/sui/client" ;
22import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" ;
33import { Transaction } from "@mysten/sui/transactions" ;
4- import type { Request as SubscriptionRequest } from "@pythnetwork/pyth-lazer-sdk" ;
54import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk" ;
65import yargs from "yargs" ;
76import { hideBin } from "yargs/helpers" ;
87
98import { addParseAndVerifyLeEcdsaUpdateCall } from "../src/client.js" ;
109
11- async function getOneLeEcdsaUpdate ( urls : string [ ] , token : string ) {
10+ async function getOneLeEcdsaUpdate ( token : string ) {
1211 const lazer = await PythLazerClient . create ( {
13- urls,
1412 token,
15- numConnections : 1 ,
1613 } ) ;
1714
18- const subscription : SubscriptionRequest = {
19- subscriptionId : 1 ,
20- type : "subscribe" ,
15+ const latestPrice = await lazer . get_latest_price ( {
2116 priceFeedIds : [ 1 ] ,
2217 properties : [ "price" , "bestBidPrice" , "bestAskPrice" , "exponent" ] ,
2318 formats : [ "leEcdsa" ] ,
2419 channel : "fixed_rate@200ms" ,
25- deliveryFormat : "binary" ,
2620 jsonBinaryEncoding : "hex" ,
27- } ;
28-
29- lazer . subscribe ( subscription ) ;
30-
31- return new Promise < Uint8Array > ( ( resolve ) => {
32- lazer . addMessageListener ( ( event ) => {
33- if ( event . type === "binary" && event . value . leEcdsa ) {
34- const buf = event . value . leEcdsa ;
35-
36- // For the purposes of this example, we only need one update.
37- lazer . shutdown ( ) ;
38- resolve ( buf ) ;
39- }
40- } ) ;
4121 } ) ;
22+
23+ return latestPrice ;
4224}
4325
4426async function main ( ) {
@@ -87,10 +69,7 @@ async function main() {
8769 const provider = new SuiClient ( { url : args . fullnodeUrl } ) ;
8870
8971 // Fetch the price update
90- const updateBytes = await getOneLeEcdsaUpdate (
91- args . lazerUrls ,
92- args . lazerToken ,
93- ) ;
72+ const update = await getOneLeEcdsaUpdate ( args . lazerToken ) ;
9473
9574 // Build the Sui transaction
9675 const tx = new Transaction ( ) ;
@@ -100,7 +79,7 @@ async function main() {
10079 tx,
10180 packageId : args . packageId ,
10281 stateObjectId : args . stateObjectId ,
103- updateBytes,
82+ updateBytes : Buffer . from ( update . leEcdsa ?. data ?? "" , "hex" ) ,
10483 } ) ;
10584
10685 // --- You can add more calls to the transaction that consume the parsed update here ---
0 commit comments