1
- import {
2
- Ed25519Keypair ,
3
- ObjectId ,
4
- RawSigner ,
5
- SUI_CLOCK_OBJECT_ID ,
6
- TransactionBlock ,
7
- } from "@mysten/sui.js" ;
8
1
import { Chain , SuiChain } from "../chains" ;
9
2
import { DataSource } from "xc_admin_common" ;
10
3
import { PriceFeedContract , PrivateKey , TxResult } from "../base" ;
11
4
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 ;
12
10
13
11
export class SuiPriceFeedContract extends PriceFeedContract {
14
12
static type = "SuiPriceFeedContract" ;
@@ -96,13 +94,6 @@ export class SuiPriceFeedContract extends PriceFeedContract {
96
94
timestamp : string ;
97
95
} ;
98
96
} ) {
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
- }
106
97
let expo = priceInfo . fields . expo . fields . magnitude ;
107
98
if ( priceInfo . fields . expo . fields . negative ) expo = "-" + expo ;
108
99
let price = priceInfo . fields . price . fields . magnitude ;
@@ -135,10 +126,14 @@ export class SuiPriceFeedContract extends PriceFeedContract {
135
126
}
136
127
return {
137
128
emaPrice : await this . parsePrice (
129
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
130
+ // @ts -ignore
138
131
priceInfo . data . content . fields . price_info . fields . price_feed . fields
139
132
. ema_price
140
133
) ,
141
134
price : await this . parsePrice (
135
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
136
+ // @ts -ignore
142
137
priceInfo . data . content . fields . price_info . fields . price_feed . fields . price
143
138
) ,
144
139
} ;
@@ -303,21 +298,25 @@ export class SuiPriceFeedContract extends PriceFeedContract {
303
298
keypair : Ed25519Keypair
304
299
) {
305
300
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 ,
307
308
transactionBlock : tx ,
308
309
options : {
309
310
showEffects : true ,
310
311
showEvents : true ,
311
312
} ,
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
+ } ) ;
317
314
}
318
315
319
316
async getValidTimePeriod ( ) {
320
317
const fields = await this . getStateFields ( ) ;
318
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
319
+ // @ts -ignore
321
320
return Number ( fields . stale_price_threshold ) ;
322
321
}
323
322
@@ -338,6 +337,8 @@ export class SuiPriceFeedContract extends PriceFeedContract {
338
337
if ( result . data . content . dataType !== "moveObject" ) {
339
338
throw new Error ( "Data Sources type mismatch" ) ;
340
339
}
340
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
341
+ // @ts -ignore
341
342
return result . data . content . fields . value . fields . keys . map (
342
343
( {
343
344
fields,
@@ -359,6 +360,8 @@ export class SuiPriceFeedContract extends PriceFeedContract {
359
360
360
361
async getGovernanceDataSource ( ) : Promise < DataSource > {
361
362
const fields = await this . getStateFields ( ) ;
363
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
364
+ // @ts -ignore
362
365
const governanceFields = fields . governance_data_source . fields ;
363
366
const chainId = governanceFields . emitter_chain ;
364
367
const emitterAddress =
@@ -371,11 +374,15 @@ export class SuiPriceFeedContract extends PriceFeedContract {
371
374
372
375
async getBaseUpdateFee ( ) {
373
376
const fields = await this . getStateFields ( ) ;
377
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
378
+ // @ts -ignore
374
379
return { amount : fields . base_update_fee } ;
375
380
}
376
381
377
382
async getLastExecutedGovernanceSequence ( ) {
378
383
const fields = await this . getStateFields ( ) ;
384
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
385
+ // @ts -ignore
379
386
return Number ( fields . last_executed_governance_sequence ) ;
380
387
}
381
388
0 commit comments