@zofai/zo-sdk 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abstract/BaseAPI.cjs +7 -1
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +11 -10
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +11 -10
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +7 -1
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +1 -1
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +1 -1
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/api.cjs +12 -12
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +12 -12
- package/dist/api.mjs.map +1 -1
- package/dist/bcs.d.cts +41 -71
- package/dist/bcs.d.cts.map +1 -1
- package/dist/bcs.d.mts +41 -71
- package/dist/bcs.d.mts.map +1 -1
- package/dist/coins.cjs +74 -0
- package/dist/coins.cjs.map +1 -0
- package/dist/coins.d.cts +37 -0
- package/dist/coins.d.cts.map +1 -0
- package/dist/coins.d.mts +37 -0
- package/dist/coins.d.mts.map +1 -0
- package/dist/coins.mjs +67 -0
- package/dist/coins.mjs.map +1 -0
- package/dist/data.d.cts +6 -6
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts +6 -6
- package/dist/data.d.mts.map +1 -1
- package/dist/factory/SDKFactory.d.cts +1 -1
- package/dist/factory/SDKFactory.d.cts.map +1 -1
- package/dist/factory/SDKFactory.d.mts +1 -1
- package/dist/factory/SDKFactory.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.cjs +192 -100
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +24 -24
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +24 -24
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +192 -100
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +2 -2
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +5 -5
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +5 -5
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +2 -2
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +176 -92
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +22 -22
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +22 -22
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +176 -92
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts +5 -5
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts +5 -5
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +84 -46
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +84 -46
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +192 -100
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +24 -24
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +24 -24
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +192 -100
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +5 -5
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +5 -5
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +26 -22
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +26 -22
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +1 -1
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +1 -1
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/usdz.d.cts +1 -1
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +1 -1
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zbtcvc.d.cts +1 -1
- package/dist/interfaces/zbtcvc.d.cts.map +1 -1
- package/dist/interfaces/zbtcvc.d.mts +1 -1
- package/dist/interfaces/zbtcvc.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +1 -1
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +1 -1
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +27 -22
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +14 -2
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +14 -2
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +27 -22
- package/dist/oracle.mjs.map +1 -1
- package/dist/suiClient.cjs +8 -0
- package/dist/suiClient.cjs.map +1 -0
- package/dist/suiClient.d.cts +8 -0
- package/dist/suiClient.d.cts.map +1 -0
- package/dist/suiClient.d.mts +8 -0
- package/dist/suiClient.d.mts.map +1 -0
- package/dist/suiClient.mjs +2 -0
- package/dist/suiClient.mjs.map +1 -0
- package/dist/utils.cjs +7 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +7 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -4
- package/src/abstract/BaseAPI.ts +11 -9
- package/src/abstract/BaseDataAPI.ts +1 -1
- package/src/api.ts +13 -17
- package/src/coins.ts +116 -0
- package/src/data.ts +1 -1
- package/src/factory/SDKFactory.ts +1 -1
- package/src/implementations/SLPAPI.ts +200 -116
- package/src/implementations/SLPDataAPI.ts +3 -3
- package/src/implementations/USDZAPI.ts +185 -95
- package/src/implementations/USDZDataAPI.ts +1 -1
- package/src/implementations/ZBTCVCAPI.ts +99 -53
- package/src/implementations/ZBTCVCDataAPI.ts +1 -1
- package/src/implementations/ZLPAPI.ts +200 -111
- package/src/implementations/ZLPDataAPI.ts +1 -1
- package/src/index.ts +3 -1
- package/src/interfaces/base.ts +14 -22
- package/src/interfaces/slp.ts +0 -1
- package/src/interfaces/usdz.ts +0 -1
- package/src/interfaces/zbtcvc.ts +0 -1
- package/src/interfaces/zlp.ts +0 -1
- package/src/oracle.ts +70 -30
- package/src/suiClient.ts +11 -0
- package/src/utils.ts +9 -3
- package/tsconfig.json +8 -1
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Implements ZLP-specific data access methods
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { DynamicFieldInfo, SuiClient } from '@mysten/sui/client'
|
|
8
7
|
import type { Transaction } from '@mysten/sui/transactions'
|
|
9
8
|
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
|
|
10
9
|
|
|
@@ -36,6 +35,7 @@ import type {
|
|
|
36
35
|
IZLPSymbolInfo,
|
|
37
36
|
IZLPVaultInfo,
|
|
38
37
|
} from '../interfaces'
|
|
38
|
+
import type { DynamicFieldInfo, SuiClient } from '../suiClient'
|
|
39
39
|
import { joinSymbol, parseSymbolKey, parseValue, suiSymbolToSymbol } from '../utils'
|
|
40
40
|
|
|
41
41
|
interface SwapImpactConfig {
|
package/src/index.ts
CHANGED
|
@@ -20,17 +20,19 @@ export * from './abstract'
|
|
|
20
20
|
export * from './factory/SDKFactory'
|
|
21
21
|
export * from './implementations'
|
|
22
22
|
export * from './interfaces'
|
|
23
|
+
export * from './suiClient'
|
|
23
24
|
|
|
24
25
|
// Export legacy components for backward compatibility
|
|
25
26
|
export * from './api'
|
|
26
27
|
export * from './bcs'
|
|
28
|
+
export * from './coins'
|
|
27
29
|
export * from './consts'
|
|
28
30
|
export * from './data'
|
|
29
31
|
export * from './oracle'
|
|
30
32
|
export * from './utils'
|
|
31
33
|
|
|
32
34
|
// Re-export commonly used types from Sui SDK
|
|
33
|
-
export type { SuiClient } from '
|
|
35
|
+
export type { SuiClient } from './suiClient'
|
|
34
36
|
export type { Transaction } from '@mysten/sui/transactions'
|
|
35
37
|
|
|
36
38
|
/**
|
package/src/interfaces/base.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
|
|
7
|
-
import type { SuiClient } from '@mysten/sui/client'
|
|
8
7
|
import type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions'
|
|
9
8
|
import type { PriceFeed } from '@pythnetwork/pyth-sui-js'
|
|
10
9
|
|
|
11
10
|
import type { IConsts, LPToken, Network } from '../consts'
|
|
11
|
+
import type { IInitOracleTxbResult } from '../oracle'
|
|
12
|
+
import type { SuiClient } from '../suiClient'
|
|
12
13
|
|
|
13
14
|
// Common data interfaces
|
|
14
15
|
export interface IBaseMarketValuationInfo {
|
|
@@ -293,7 +294,12 @@ export interface IBaseDataAPI {
|
|
|
293
294
|
getOraclePrice: (tokenId: string) => Promise<PriceFeed>
|
|
294
295
|
getOraclePrices: (tokens: string[]) => Promise<PriceFeed[]>
|
|
295
296
|
subOraclePrices: (tokens: string[], callback: (price: PriceFeed) => void) => Promise<() => void>
|
|
296
|
-
initOracleTxb: (
|
|
297
|
+
initOracleTxb: (
|
|
298
|
+
tokens: string[],
|
|
299
|
+
tx?: Transaction,
|
|
300
|
+
sponsoredTx?: boolean,
|
|
301
|
+
sponsorOptions?: { sender: string, additionalSuiAmount?: bigint },
|
|
302
|
+
) => Promise<IInitOracleTxbResult>
|
|
297
303
|
|
|
298
304
|
// Utility methods
|
|
299
305
|
validateCache: () => void
|
|
@@ -309,7 +315,6 @@ export interface IBaseAPI {
|
|
|
309
315
|
referralAddress?: string,
|
|
310
316
|
sender?: string,
|
|
311
317
|
sponsoredTx?: boolean,
|
|
312
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
313
318
|
) => Promise<Transaction>
|
|
314
319
|
|
|
315
320
|
withdraw: (
|
|
@@ -318,7 +323,6 @@ export interface IBaseAPI {
|
|
|
318
323
|
amount: number,
|
|
319
324
|
minAmountOut?: number,
|
|
320
325
|
sponsoredTx?: boolean,
|
|
321
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
322
326
|
) => Promise<Transaction>
|
|
323
327
|
|
|
324
328
|
swap: (
|
|
@@ -362,7 +366,6 @@ export interface IBaseAPI {
|
|
|
362
366
|
referralAddress?: string,
|
|
363
367
|
sender?: string,
|
|
364
368
|
sponsoredTx?: boolean,
|
|
365
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
366
369
|
) => Promise<Transaction>
|
|
367
370
|
|
|
368
371
|
// Trading operations
|
|
@@ -384,7 +387,6 @@ export interface IBaseAPI {
|
|
|
384
387
|
sender?: string,
|
|
385
388
|
tx?: Transaction,
|
|
386
389
|
sponsoredTx?: boolean,
|
|
387
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
388
390
|
) => Promise<Transaction>
|
|
389
391
|
|
|
390
392
|
decreasePosition: (
|
|
@@ -403,7 +405,7 @@ export interface IBaseAPI {
|
|
|
403
405
|
relayerFee?: bigint,
|
|
404
406
|
coinObjects?: string[],
|
|
405
407
|
sponsoredTx?: boolean,
|
|
406
|
-
|
|
408
|
+
sender?: string,
|
|
407
409
|
) => Promise<Transaction>
|
|
408
410
|
|
|
409
411
|
decreaseMultiPositions: (
|
|
@@ -425,7 +427,7 @@ export interface IBaseAPI {
|
|
|
425
427
|
}>,
|
|
426
428
|
tx?: Transaction,
|
|
427
429
|
sponsoredTx?: boolean,
|
|
428
|
-
|
|
430
|
+
sender?: string,
|
|
429
431
|
) => Promise<Transaction>
|
|
430
432
|
|
|
431
433
|
openPositionV2?: (
|
|
@@ -446,7 +448,6 @@ export interface IBaseAPI {
|
|
|
446
448
|
referralAddress?: string,
|
|
447
449
|
sender?: string,
|
|
448
450
|
sponsoredTx?: boolean,
|
|
449
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
450
451
|
) => Promise<Transaction>
|
|
451
452
|
|
|
452
453
|
// Trading operations
|
|
@@ -468,7 +469,6 @@ export interface IBaseAPI {
|
|
|
468
469
|
sender?: string,
|
|
469
470
|
tx?: Transaction,
|
|
470
471
|
sponsoredTx?: boolean,
|
|
471
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
472
472
|
) => Promise<Transaction>
|
|
473
473
|
|
|
474
474
|
decreasePositionV2?: (
|
|
@@ -487,7 +487,7 @@ export interface IBaseAPI {
|
|
|
487
487
|
relayerFee?: bigint,
|
|
488
488
|
coinObjects?: string[],
|
|
489
489
|
sponsoredTx?: boolean,
|
|
490
|
-
|
|
490
|
+
sender?: string,
|
|
491
491
|
) => Promise<Transaction>
|
|
492
492
|
|
|
493
493
|
decreaseMultiPositionsV2?: (
|
|
@@ -509,7 +509,7 @@ export interface IBaseAPI {
|
|
|
509
509
|
}>,
|
|
510
510
|
tx?: Transaction,
|
|
511
511
|
sponsoredTx?: boolean,
|
|
512
|
-
|
|
512
|
+
sender?: string,
|
|
513
513
|
feeObjects?: TransactionObjectArgument[],
|
|
514
514
|
) => Promise<Transaction>
|
|
515
515
|
|
|
@@ -521,7 +521,7 @@ export interface IBaseAPI {
|
|
|
521
521
|
coinObjects: string[],
|
|
522
522
|
long: boolean,
|
|
523
523
|
sponsoredTx?: boolean,
|
|
524
|
-
|
|
524
|
+
sender?: string,
|
|
525
525
|
) => Promise<Transaction>
|
|
526
526
|
|
|
527
527
|
redeemFromPosition: (
|
|
@@ -531,7 +531,6 @@ export interface IBaseAPI {
|
|
|
531
531
|
amount: number,
|
|
532
532
|
long: boolean,
|
|
533
533
|
sponsoredTx?: boolean,
|
|
534
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
535
534
|
) => Promise<Transaction>
|
|
536
535
|
|
|
537
536
|
cancelOrder: (
|
|
@@ -621,7 +620,6 @@ export interface IBaseAPI {
|
|
|
621
620
|
referralAddress?: string,
|
|
622
621
|
sender?: string,
|
|
623
622
|
sponsoredTx?: boolean,
|
|
624
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
625
623
|
) => Promise<Transaction>
|
|
626
624
|
|
|
627
625
|
// S Card operations
|
|
@@ -646,7 +644,6 @@ export interface IBaseAPI {
|
|
|
646
644
|
sender?: string,
|
|
647
645
|
tx?: Transaction,
|
|
648
646
|
sponsoredTx?: boolean,
|
|
649
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
650
647
|
) => Promise<Transaction>
|
|
651
648
|
|
|
652
649
|
decreasePositionWithSCard: (
|
|
@@ -668,7 +665,6 @@ export interface IBaseAPI {
|
|
|
668
665
|
relayerFee?: bigint,
|
|
669
666
|
coinObjects?: string[],
|
|
670
667
|
sponsoredTx?: boolean,
|
|
671
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
672
668
|
) => Promise<Transaction>
|
|
673
669
|
|
|
674
670
|
decreaseMultiPositionsWithSCard: (
|
|
@@ -693,7 +689,6 @@ export interface IBaseAPI {
|
|
|
693
689
|
scard: string,
|
|
694
690
|
tx?: Transaction,
|
|
695
691
|
sponsoredTx?: boolean,
|
|
696
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
697
692
|
) => Promise<Transaction>
|
|
698
693
|
|
|
699
694
|
openPositionWithSCardV2?: (
|
|
@@ -717,7 +712,6 @@ export interface IBaseAPI {
|
|
|
717
712
|
referralAddress?: string,
|
|
718
713
|
sender?: string,
|
|
719
714
|
sponsoredTx?: boolean,
|
|
720
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
721
715
|
) => Promise<Transaction>
|
|
722
716
|
|
|
723
717
|
// S Card operations
|
|
@@ -742,7 +736,6 @@ export interface IBaseAPI {
|
|
|
742
736
|
sender?: string,
|
|
743
737
|
tx?: Transaction,
|
|
744
738
|
sponsoredTx?: boolean,
|
|
745
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
746
739
|
) => Promise<Transaction>
|
|
747
740
|
|
|
748
741
|
decreasePositionWithSCardV2?: (
|
|
@@ -764,7 +757,6 @@ export interface IBaseAPI {
|
|
|
764
757
|
relayerFee?: bigint,
|
|
765
758
|
coinObjects?: string[],
|
|
766
759
|
sponsoredTx?: boolean,
|
|
767
|
-
suiCoinObjectsForPythUpdate?: string[],
|
|
768
760
|
) => Promise<Transaction>
|
|
769
761
|
|
|
770
762
|
decreaseMultiPositionsWithSCardV2?: (
|
|
@@ -789,7 +781,7 @@ export interface IBaseAPI {
|
|
|
789
781
|
scard: string,
|
|
790
782
|
tx?: Transaction,
|
|
791
783
|
sponsoredTx?: boolean,
|
|
792
|
-
|
|
784
|
+
sender?: string,
|
|
793
785
|
feeObjects?: TransactionObjectArgument[],
|
|
794
786
|
) => Promise<Transaction>
|
|
795
787
|
|
package/src/interfaces/slp.ts
CHANGED
package/src/interfaces/usdz.ts
CHANGED
package/src/interfaces/zbtcvc.ts
CHANGED
package/src/interfaces/zlp.ts
CHANGED
package/src/oracle.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransactionObjectArgument } from '@mysten/sui/transactions'
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions'
|
|
3
3
|
import type { PriceFeed } from '@pythnetwork/pyth-sui-js'
|
|
4
4
|
import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js'
|
|
5
5
|
|
|
6
|
+
import { resolveSpendableSuiCoin } from './coins'
|
|
6
7
|
import type { IConsts, Network } from './consts'
|
|
7
8
|
import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, getSharedConfig, LPToken } from './consts'
|
|
9
|
+
import type { SuiClient } from './suiClient'
|
|
8
10
|
import { createJsonRpcProvider } from './utils'
|
|
9
11
|
|
|
12
|
+
export interface IInitOracleSponsorOptions {
|
|
13
|
+
sender: string
|
|
14
|
+
/** SUI (MIST) needed beyond Pyth update fees, e.g. SUI collateral deposit + relayer fee. */
|
|
15
|
+
additionalSuiAmount?: bigint
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IInitOracleTxbResult {
|
|
19
|
+
tx: Transaction
|
|
20
|
+
/** Remaining SUI coin after Pyth fee splits; present when sponsored and SUI was resolved. */
|
|
21
|
+
suiCoinObject?: TransactionObjectArgument
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
export class OracleAPI {
|
|
11
25
|
network: Network
|
|
12
26
|
consts: IConsts
|
|
@@ -33,7 +47,11 @@ export class OracleAPI {
|
|
|
33
47
|
this.PythFeederToPriceId = getPythFeederToPriceId(network)
|
|
34
48
|
this.PythFeederToId = getPythFeederToId(network)
|
|
35
49
|
this.provider = provider || createJsonRpcProvider(network)
|
|
36
|
-
this.client = new SuiPythClient(
|
|
50
|
+
this.client = new SuiPythClient(
|
|
51
|
+
this.provider as ConstructorParameters<typeof SuiPythClient>[0],
|
|
52
|
+
this.consts.pythFeeder.state,
|
|
53
|
+
this.consts.pythFeeder.wormhole.state,
|
|
54
|
+
)
|
|
37
55
|
}
|
|
38
56
|
|
|
39
57
|
validateCache() {
|
|
@@ -90,39 +108,47 @@ export class OracleAPI {
|
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
async
|
|
94
|
-
tokens: string[],
|
|
95
|
-
tx?: Transaction,
|
|
96
|
-
sponsoredTx?: boolean,
|
|
97
|
-
suiCoinObject?: any,
|
|
98
|
-
) {
|
|
99
|
-
let tx_ = tx
|
|
100
|
-
if (!tx_) {
|
|
101
|
-
tx_ = new Transaction()
|
|
102
|
-
}
|
|
103
|
-
// Remove redundant tokens first
|
|
111
|
+
async getStalePriceFeedIds(tokens: string[]): Promise<string[]> {
|
|
104
112
|
const uniqueTokens = Array.from(new Set(tokens))
|
|
105
|
-
|
|
106
|
-
const connection = new SuiPriceServiceConnection(this.connectionURL, {
|
|
107
|
-
priceFeedRequestConfig: {
|
|
108
|
-
binary: true,
|
|
109
|
-
},
|
|
110
|
-
})
|
|
111
113
|
let pythObjectIds = uniqueTokens.map(token => this.consts.pythFeeder.feeder[token])
|
|
112
|
-
// remove dupe object ids. If any of the object ids are duplicates the call will fail
|
|
113
114
|
pythObjectIds = [...new Set(pythObjectIds)].filter(Boolean)
|
|
114
|
-
|
|
115
|
+
|
|
116
|
+
const objects = await this.provider.multiGetObjects({
|
|
115
117
|
ids: pythObjectIds,
|
|
116
|
-
options: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
options: { showContent: true },
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
return objects.map(pythObject => [
|
|
120
122
|
Number.parseInt((pythObject.data?.content as any).fields.price_info.fields.arrival_time || 0, 10) - Date.now() / 1000,
|
|
121
123
|
pythObject.data?.objectId,
|
|
122
124
|
]).filter((x: any) => Math.abs(x[0]) >= 0).map(x => x[1] as string)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async initOracleTxb(
|
|
128
|
+
tokens: string[],
|
|
129
|
+
tx?: Transaction,
|
|
130
|
+
sponsoredTx?: boolean,
|
|
131
|
+
sponsorOptions?: IInitOracleSponsorOptions,
|
|
132
|
+
): Promise<IInitOracleTxbResult> {
|
|
133
|
+
const tx_ = tx ?? new Transaction()
|
|
134
|
+
|
|
135
|
+
const connection = new SuiPriceServiceConnection(this.connectionURL, {
|
|
136
|
+
priceFeedRequestConfig: { binary: true },
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const needUpdateObjectIds = await this.getStalePriceFeedIds(tokens)
|
|
123
140
|
|
|
124
141
|
if (needUpdateObjectIds.length === 0) {
|
|
125
|
-
|
|
142
|
+
if (sponsoredTx && sponsorOptions && (sponsorOptions.additionalSuiAmount ?? 0n) > 0n) {
|
|
143
|
+
const suiCoinObject = await resolveSpendableSuiCoin(
|
|
144
|
+
tx_,
|
|
145
|
+
this.provider,
|
|
146
|
+
sponsorOptions.sender,
|
|
147
|
+
sponsorOptions.additionalSuiAmount!,
|
|
148
|
+
)
|
|
149
|
+
return { tx: tx_, suiCoinObject }
|
|
150
|
+
}
|
|
151
|
+
return { tx: tx_ }
|
|
126
152
|
}
|
|
127
153
|
|
|
128
154
|
const priceFeedIds = needUpdateObjectIds
|
|
@@ -133,18 +159,32 @@ export class OracleAPI {
|
|
|
133
159
|
const priceUpdateData = await connection.getPriceFeedsUpdateData(priceFeedIds)
|
|
134
160
|
|
|
135
161
|
if (sponsoredTx) {
|
|
162
|
+
if (!sponsorOptions?.sender) {
|
|
163
|
+
throw new Error('sender is required for sponsored transactions that update Pyth price feeds')
|
|
164
|
+
}
|
|
165
|
+
|
|
136
166
|
const baseUpdateFee = await this.getBaseUpdateFee()
|
|
167
|
+
const pythCost = BigInt(baseUpdateFee) * BigInt(priceFeedIds.length)
|
|
168
|
+
const totalSui = pythCost + (sponsorOptions.additionalSuiAmount ?? 0n)
|
|
169
|
+
|
|
170
|
+
const suiCoinObject = await resolveSpendableSuiCoin(
|
|
171
|
+
tx_,
|
|
172
|
+
this.provider,
|
|
173
|
+
sponsorOptions.sender,
|
|
174
|
+
totalSui,
|
|
175
|
+
)
|
|
176
|
+
|
|
137
177
|
const pythUpdateCoins = tx_.splitCoins(
|
|
138
178
|
suiCoinObject,
|
|
139
179
|
priceFeedIds.map(() => tx_.pure.u64(baseUpdateFee)),
|
|
140
180
|
)
|
|
141
181
|
await this.client.updatePriceFeedsWithCoins(tx_, priceUpdateData, priceFeedIds, pythUpdateCoins)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await this.client.updatePriceFeeds(tx_, priceUpdateData, priceFeedIds)
|
|
182
|
+
|
|
183
|
+
return { tx: tx_, suiCoinObject }
|
|
145
184
|
}
|
|
146
185
|
|
|
147
|
-
|
|
186
|
+
await this.client.updatePriceFeeds(tx_, priceUpdateData, priceFeedIds)
|
|
187
|
+
return { tx: tx_ }
|
|
148
188
|
}
|
|
149
189
|
|
|
150
190
|
async getBaseUpdateFee(): Promise<number> {
|
package/src/suiClient.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sui v2 client re-exports.
|
|
3
|
+
* SuiJsonRpcClient is the JSON-RPC replacement for the removed SuiClient.
|
|
4
|
+
*/
|
|
5
|
+
export type { ClientWithCoreApi } from '@mysten/sui/client'
|
|
6
|
+
export type { DynamicFieldInfo, SuiJsonRpcClient as SuiClient } from '@mysten/sui/jsonRpc'
|
|
7
|
+
export {
|
|
8
|
+
getJsonRpcFullnodeUrl,
|
|
9
|
+
JsonRpcHTTPTransport,
|
|
10
|
+
SuiJsonRpcClient,
|
|
11
|
+
} from '@mysten/sui/jsonRpc'
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SuiClientTypes } from '@mysten/sui/client'
|
|
2
|
+
import { JsonRpcHTTPTransport, SuiJsonRpcClient } from '@mysten/sui/jsonRpc'
|
|
2
3
|
|
|
3
4
|
import type { IConsts } from './consts'
|
|
4
5
|
import { Network } from './consts'
|
|
5
6
|
|
|
7
|
+
function toSuiNetwork(network: Network): SuiClientTypes.Network {
|
|
8
|
+
return network
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export function createJsonRpcProvider(network: Network) {
|
|
7
12
|
let url = ''
|
|
8
13
|
switch (network) {
|
|
@@ -23,8 +28,9 @@ export function createJsonRpcProvider(network: Network) {
|
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
return new
|
|
27
|
-
transport: new
|
|
31
|
+
return new SuiJsonRpcClient({
|
|
32
|
+
transport: new JsonRpcHTTPTransport({ url }),
|
|
33
|
+
network: toSuiNetwork(network),
|
|
28
34
|
})
|
|
29
35
|
}
|
|
30
36
|
|
package/tsconfig.json
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2020",
|
|
4
4
|
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@mysten/sui/transactions": ["node_modules/@mysten/sui/dist/transactions/index.d.mts"],
|
|
9
|
+
"@mysten/sui/utils": ["node_modules/@mysten/sui/dist/utils/index.d.mts"],
|
|
10
|
+
"@mysten/sui/jsonRpc": ["node_modules/@mysten/sui/dist/jsonRpc/index.d.mts"],
|
|
11
|
+
"@mysten/sui/client": ["node_modules/@mysten/sui/dist/client/index.d.mts"]
|
|
12
|
+
},
|
|
6
13
|
"esModuleInterop": true,
|
|
7
14
|
"forceConsistentCasingInFileNames": true,
|
|
8
15
|
"strict": true,
|