zo-sdk 0.0.51 → 0.1.1

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.
Files changed (201) hide show
  1. package/README.md +272 -20
  2. package/dist/abstract/BaseAPI.cjs +117 -0
  3. package/dist/abstract/BaseAPI.cjs.map +1 -0
  4. package/dist/abstract/BaseAPI.d.cts +131 -0
  5. package/dist/abstract/BaseAPI.d.cts.map +1 -0
  6. package/dist/abstract/BaseAPI.d.mts +131 -0
  7. package/dist/abstract/BaseAPI.d.mts.map +1 -0
  8. package/dist/abstract/BaseAPI.mjs +113 -0
  9. package/dist/abstract/BaseAPI.mjs.map +1 -0
  10. package/dist/abstract/BaseDataAPI.cjs +139 -0
  11. package/dist/abstract/BaseDataAPI.cjs.map +1 -0
  12. package/dist/abstract/BaseDataAPI.d.cts +89 -0
  13. package/dist/abstract/BaseDataAPI.d.cts.map +1 -0
  14. package/dist/abstract/BaseDataAPI.d.mts +89 -0
  15. package/dist/abstract/BaseDataAPI.d.mts.map +1 -0
  16. package/dist/abstract/BaseDataAPI.mjs +135 -0
  17. package/dist/abstract/BaseDataAPI.mjs.map +1 -0
  18. package/dist/abstract/index.cjs +12 -0
  19. package/dist/abstract/index.cjs.map +1 -0
  20. package/dist/abstract/index.d.cts +7 -0
  21. package/dist/abstract/index.d.cts.map +1 -0
  22. package/dist/abstract/index.d.mts +7 -0
  23. package/dist/abstract/index.d.mts.map +1 -0
  24. package/dist/abstract/index.mjs +7 -0
  25. package/dist/abstract/index.mjs.map +1 -0
  26. package/dist/bcs.cjs +42 -0
  27. package/dist/bcs.cjs.map +1 -0
  28. package/dist/bcs.d.cts +91 -0
  29. package/dist/bcs.d.cts.map +1 -0
  30. package/dist/bcs.d.mts +91 -0
  31. package/dist/bcs.d.mts.map +1 -0
  32. package/dist/bcs.mjs +39 -0
  33. package/dist/bcs.mjs.map +1 -0
  34. package/dist/consts/deployments-slp-mainnet.json +710 -0
  35. package/dist/consts/deployments-slp-testnet.json +109 -0
  36. package/dist/consts/deployments-usdz-mainnet.json +180 -0
  37. package/dist/consts/deployments-usdz-testnet.json +98 -0
  38. package/dist/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +278 -42
  39. package/dist/consts/index.cjs +49 -13
  40. package/dist/consts/index.cjs.map +1 -1
  41. package/dist/consts/index.d.cts +81 -11
  42. package/dist/consts/index.d.cts.map +1 -1
  43. package/dist/consts/index.d.mts +81 -11
  44. package/dist/consts/index.d.mts.map +1 -1
  45. package/dist/consts/index.mjs +48 -12
  46. package/dist/consts/index.mjs.map +1 -1
  47. package/dist/consts/price_id_to_object_id.mainnet.json +9 -1
  48. package/dist/factory/SDKFactory.cjs +185 -0
  49. package/dist/factory/SDKFactory.cjs.map +1 -0
  50. package/dist/factory/SDKFactory.d.cts +74 -0
  51. package/dist/factory/SDKFactory.d.cts.map +1 -0
  52. package/dist/factory/SDKFactory.d.mts +74 -0
  53. package/dist/factory/SDKFactory.d.mts.map +1 -0
  54. package/dist/factory/SDKFactory.mjs +179 -0
  55. package/dist/factory/SDKFactory.mjs.map +1 -0
  56. package/dist/implementations/SLPAPI.cjs +829 -0
  57. package/dist/implementations/SLPAPI.cjs.map +1 -0
  58. package/dist/implementations/SLPAPI.d.cts +120 -0
  59. package/dist/implementations/SLPAPI.d.cts.map +1 -0
  60. package/dist/implementations/SLPAPI.d.mts +120 -0
  61. package/dist/implementations/SLPAPI.d.mts.map +1 -0
  62. package/dist/implementations/SLPAPI.mjs +825 -0
  63. package/dist/implementations/SLPAPI.mjs.map +1 -0
  64. package/dist/implementations/SLPDataAPI.cjs +916 -0
  65. package/dist/implementations/SLPDataAPI.cjs.map +1 -0
  66. package/dist/implementations/SLPDataAPI.d.cts +102 -0
  67. package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
  68. package/dist/implementations/SLPDataAPI.d.mts +102 -0
  69. package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
  70. package/dist/implementations/SLPDataAPI.mjs +912 -0
  71. package/dist/implementations/SLPDataAPI.mjs.map +1 -0
  72. package/dist/implementations/USDZAPI.cjs +522 -0
  73. package/dist/implementations/USDZAPI.cjs.map +1 -0
  74. package/dist/implementations/USDZAPI.d.cts +118 -0
  75. package/dist/implementations/USDZAPI.d.cts.map +1 -0
  76. package/dist/implementations/USDZAPI.d.mts +118 -0
  77. package/dist/implementations/USDZAPI.d.mts.map +1 -0
  78. package/dist/implementations/USDZAPI.mjs +518 -0
  79. package/dist/implementations/USDZAPI.mjs.map +1 -0
  80. package/dist/implementations/USDZDataAPI.cjs +697 -0
  81. package/dist/implementations/USDZDataAPI.cjs.map +1 -0
  82. package/dist/implementations/USDZDataAPI.d.cts +86 -0
  83. package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
  84. package/dist/implementations/USDZDataAPI.d.mts +86 -0
  85. package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
  86. package/dist/implementations/USDZDataAPI.mjs +693 -0
  87. package/dist/implementations/USDZDataAPI.mjs.map +1 -0
  88. package/dist/implementations/ZLPAPI.cjs +809 -0
  89. package/dist/implementations/ZLPAPI.cjs.map +1 -0
  90. package/dist/implementations/ZLPAPI.d.cts +121 -0
  91. package/dist/implementations/ZLPAPI.d.cts.map +1 -0
  92. package/dist/implementations/ZLPAPI.d.mts +121 -0
  93. package/dist/implementations/ZLPAPI.d.mts.map +1 -0
  94. package/dist/implementations/ZLPAPI.mjs +805 -0
  95. package/dist/implementations/ZLPAPI.mjs.map +1 -0
  96. package/dist/implementations/ZLPDataAPI.cjs +724 -0
  97. package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
  98. package/dist/implementations/ZLPDataAPI.d.cts +83 -0
  99. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
  100. package/dist/implementations/ZLPDataAPI.d.mts +83 -0
  101. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
  102. package/dist/implementations/ZLPDataAPI.mjs +720 -0
  103. package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
  104. package/dist/implementations/index.cjs +22 -0
  105. package/dist/implementations/index.cjs.map +1 -0
  106. package/dist/implementations/index.d.cts +11 -0
  107. package/dist/implementations/index.d.cts.map +1 -0
  108. package/dist/implementations/index.d.mts +11 -0
  109. package/dist/implementations/index.d.mts.map +1 -0
  110. package/dist/implementations/index.mjs +13 -0
  111. package/dist/implementations/index.mjs.map +1 -0
  112. package/dist/index.cjs +47 -0
  113. package/dist/index.cjs.map +1 -1
  114. package/dist/index.d.cts +45 -0
  115. package/dist/index.d.cts.map +1 -1
  116. package/dist/index.d.mts +45 -0
  117. package/dist/index.d.mts.map +1 -1
  118. package/dist/index.mjs +45 -0
  119. package/dist/index.mjs.map +1 -1
  120. package/dist/interfaces/base.cjs +8 -0
  121. package/dist/interfaces/base.cjs.map +1 -0
  122. package/dist/interfaces/base.d.cts +293 -0
  123. package/dist/interfaces/base.d.cts.map +1 -0
  124. package/dist/interfaces/base.d.mts +293 -0
  125. package/dist/interfaces/base.d.mts.map +1 -0
  126. package/dist/interfaces/base.mjs +6 -0
  127. package/dist/interfaces/base.mjs.map +1 -0
  128. package/dist/interfaces/index.cjs +29 -0
  129. package/dist/interfaces/index.cjs.map +1 -0
  130. package/dist/interfaces/index.d.cts +13 -0
  131. package/dist/interfaces/index.d.cts.map +1 -0
  132. package/dist/interfaces/index.d.mts +13 -0
  133. package/dist/interfaces/index.d.mts.map +1 -0
  134. package/dist/interfaces/index.mjs +13 -0
  135. package/dist/interfaces/index.mjs.map +1 -0
  136. package/dist/interfaces/slp.cjs +9 -0
  137. package/dist/interfaces/slp.cjs.map +1 -0
  138. package/dist/interfaces/slp.d.cts +115 -0
  139. package/dist/interfaces/slp.d.cts.map +1 -0
  140. package/dist/interfaces/slp.d.mts +115 -0
  141. package/dist/interfaces/slp.d.mts.map +1 -0
  142. package/dist/interfaces/slp.mjs +7 -0
  143. package/dist/interfaces/slp.mjs.map +1 -0
  144. package/dist/interfaces/usdz.cjs +7 -0
  145. package/dist/interfaces/usdz.cjs.map +1 -0
  146. package/dist/interfaces/usdz.d.cts +40 -0
  147. package/dist/interfaces/usdz.d.cts.map +1 -0
  148. package/dist/interfaces/usdz.d.mts +40 -0
  149. package/dist/interfaces/usdz.d.mts.map +1 -0
  150. package/dist/interfaces/usdz.mjs +6 -0
  151. package/dist/interfaces/usdz.mjs.map +1 -0
  152. package/dist/interfaces/zlp.cjs +7 -0
  153. package/dist/interfaces/zlp.cjs.map +1 -0
  154. package/dist/interfaces/zlp.d.cts +45 -0
  155. package/dist/interfaces/zlp.d.cts.map +1 -0
  156. package/dist/interfaces/zlp.d.mts +45 -0
  157. package/dist/interfaces/zlp.d.mts.map +1 -0
  158. package/dist/interfaces/zlp.mjs +6 -0
  159. package/dist/interfaces/zlp.mjs.map +1 -0
  160. package/dist/oracle.cjs +7 -35
  161. package/dist/oracle.cjs.map +1 -1
  162. package/dist/oracle.d.cts +3 -4
  163. package/dist/oracle.d.cts.map +1 -1
  164. package/dist/oracle.d.mts +3 -4
  165. package/dist/oracle.d.mts.map +1 -1
  166. package/dist/oracle.mjs +8 -32
  167. package/dist/oracle.mjs.map +1 -1
  168. package/package.json +1 -1
  169. package/src/abstract/BaseAPI.ts +429 -0
  170. package/src/abstract/BaseDataAPI.ts +204 -0
  171. package/src/abstract/index.ts +7 -0
  172. package/src/bcs.ts +45 -0
  173. package/src/consts/deployments-slp-mainnet.json +710 -0
  174. package/src/consts/deployments-slp-testnet.json +109 -0
  175. package/src/consts/deployments-usdz-mainnet.json +180 -0
  176. package/src/consts/deployments-usdz-testnet.json +98 -0
  177. package/src/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +279 -43
  178. package/src/consts/index.ts +143 -41
  179. package/src/consts/price_id_to_object_id.mainnet.json +10 -2
  180. package/src/factory/SDKFactory.ts +282 -0
  181. package/src/implementations/SLPAPI.ts +1207 -0
  182. package/src/implementations/SLPDataAPI.ts +1188 -0
  183. package/src/implementations/USDZAPI.ts +715 -0
  184. package/src/implementations/USDZDataAPI.ts +826 -0
  185. package/src/implementations/ZLPAPI.ts +1130 -0
  186. package/src/implementations/ZLPDataAPI.ts +856 -0
  187. package/src/implementations/index.ts +14 -0
  188. package/src/index.ts +53 -0
  189. package/src/interfaces/base.ts +556 -0
  190. package/src/interfaces/index.ts +45 -0
  191. package/src/interfaces/slp.ts +156 -0
  192. package/src/interfaces/usdz.ts +71 -0
  193. package/src/interfaces/zlp.ts +96 -0
  194. package/src/oracle.ts +12 -42
  195. package/tsconfig.json +4 -2
  196. package/dist/consts/staking/deployments-mainnet.json +0 -12
  197. package/dist/consts/staking/deployments-testnet.json +0 -11
  198. package/src/consts/staking/deployments-mainnet.json +0 -12
  199. package/src/consts/staking/deployments-testnet.json +0 -11
  200. /package/dist/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
  201. /package/src/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
@@ -0,0 +1,156 @@
1
+ /**
2
+ * SLP-specific interfaces and types
3
+ * Extends base interfaces with SLP-specific implementations for Sudo SDK
4
+ */
5
+
6
+ import { Transaction } from '@mysten/sui/transactions'
7
+ import type {
8
+ IBaseMarketValuationInfo,
9
+ IBaseVaultInfo,
10
+ IBaseSymbolInfo,
11
+ IBaseMarketInfo,
12
+ IBasePositionInfo,
13
+ IBaseOrderInfo,
14
+ IBaseHistory,
15
+ IBaseStakePool,
16
+ IBaseCredential,
17
+ IBaseDataAPI,
18
+ IBaseAPI,
19
+ IBasePositionCapInfo,
20
+ IBaseOrderCapInfo,
21
+ IBaseStaked,
22
+ IBasePositionConfig,
23
+ IBaseFundingFeeModel,
24
+ IBaseReservingFeeModel,
25
+ IBaseRebaseFeeModel
26
+ } from './base'
27
+ import { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
28
+
29
+ // SLP-specific interfaces
30
+ export interface ISLPMarketValuationInfo extends IBaseMarketValuationInfo { }
31
+
32
+ export interface ISLPVaultInfo extends IBaseVaultInfo { }
33
+
34
+ export interface ISLPSymbolInfo extends IBaseSymbolInfo { }
35
+
36
+ export interface ISLPFundingFeeModel extends IBaseFundingFeeModel { }
37
+
38
+ export interface ISLPReservingFeeModel extends IBaseReservingFeeModel { }
39
+
40
+ export interface ISLPRebaseFeeModel extends IBaseRebaseFeeModel { }
41
+
42
+ export interface ISLPMarketInfo extends IBaseMarketInfo { }
43
+
44
+ export interface ISLPPositionInfo extends IBasePositionInfo { }
45
+
46
+ export interface ISLPPositionConfig extends IBasePositionConfig { }
47
+
48
+ export interface ISLPPositionCapInfo extends IBasePositionCapInfo { }
49
+
50
+ export interface ISLPOrderInfo extends IBaseOrderInfo { }
51
+
52
+ export interface ISLPOrderCapInfo extends IBaseOrderCapInfo { }
53
+
54
+ export interface ISLPHistory extends IBaseHistory { }
55
+
56
+ export interface ISLPStaked extends IBaseStaked { }
57
+
58
+ export interface ISLPStakePool extends IBaseStakePool { }
59
+
60
+ export interface ISLPCredential extends IBaseCredential { }
61
+
62
+ // Sudo SDK specific data structures
63
+ export interface ISudoMarket {
64
+ lpSupply: bigint
65
+ lpSupplyWithDecimals: number
66
+ totalValue: number
67
+ apr?: number
68
+ }
69
+
70
+ export interface ISudoVault {
71
+ symbol: string
72
+ liquidity: bigint
73
+ reservedAmount: bigint
74
+ enabled: boolean
75
+ weight: number
76
+ lastUpdate: number
77
+ totalValue: number
78
+ }
79
+
80
+ export interface ISudoSymbol {
81
+ name: string
82
+ openingSize: bigint
83
+ openingAmount: bigint
84
+ fundingRate: number
85
+ long: boolean
86
+ lastUpdate: number
87
+ totalOpenInterest: number
88
+ }
89
+
90
+ export interface ISudoPosition {
91
+ id: string
92
+ owner: string
93
+ symbol: string
94
+ size: bigint
95
+ collateralAmount: bigint
96
+ long: boolean
97
+ lastUpdate: number
98
+ unrealizedPnl: number
99
+ liquidationPrice: number
100
+ }
101
+
102
+ export interface ISudoOrder {
103
+ id: string
104
+ owner: string
105
+ symbol: string
106
+ size: bigint
107
+ triggerPrice: number
108
+ long: boolean
109
+ createdAt: number
110
+ }
111
+
112
+ export interface ISudoHistory {
113
+ owner: string
114
+ txid: string
115
+ id: string
116
+ timestamp: number
117
+ action: string
118
+ symbol: string
119
+ price: number
120
+ size: number
121
+ pnl: number
122
+ fee: number
123
+ }
124
+
125
+ export interface ISudoStaked {
126
+ credentials: ISudoStakeCredential[]
127
+ amount: bigint
128
+ claimable: bigint
129
+ }
130
+
131
+ export interface ISudoStakeCredential {
132
+ id: string
133
+ poolId: string
134
+ amount: bigint
135
+ lockUntil: number
136
+ claimable: bigint
137
+ rewardRate: number
138
+ }
139
+
140
+ // SLP-specific data API interface
141
+ export interface ISLPDataAPI extends IBaseDataAPI {
142
+ // SLP-specific data api methods can be added here
143
+ getCumulativeApr(): Promise<number>
144
+ }
145
+
146
+ // SLP-specific API interface
147
+ export interface ISLPAPI extends IBaseAPI {
148
+ // SLP-specific api methods can be added here
149
+ claimTokenFromSCard(
150
+ token: string,
151
+ coinObjects: string[],
152
+ kioskClient: KioskClient,
153
+ kioskCap: KioskOwnerCap,
154
+ scard: string
155
+ ): Promise<Transaction>
156
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * USDZ-specific interfaces and types
3
+ * Extends base interfaces with USDZ-specific implementations
4
+ */
5
+
6
+ import type {
7
+ IBaseMarketValuationInfo,
8
+ IBaseVaultInfo,
9
+ IBaseSymbolInfo,
10
+ IBaseMarketInfo,
11
+ IBasePositionInfo,
12
+ IBaseOrderInfo,
13
+ IBaseHistory,
14
+ IBaseStakePool,
15
+ IBaseCredential,
16
+ IBaseDataAPI,
17
+ IBaseAPI,
18
+ IBaseFundingFeeModel,
19
+ IBasePositionConfig,
20
+ IBasePositionCapInfo,
21
+ IBaseReservingFeeModel,
22
+ IBaseOrderCapInfo,
23
+ IBaseRebaseFeeModel
24
+ } from './base'
25
+
26
+ // USDZ-specific interfaces
27
+ export interface IUSDZMarketValuationInfo extends IBaseMarketValuationInfo { }
28
+
29
+ export interface IUSDZVaultInfo extends IBaseVaultInfo { }
30
+
31
+ export interface IUSDZReservingFeeModel extends IBaseReservingFeeModel { }
32
+
33
+ export interface IUSDZFundingFeeModel extends IBaseFundingFeeModel { }
34
+
35
+ export interface IUSDZRebaseFeeModel extends IBaseRebaseFeeModel { }
36
+
37
+ export interface IUSDZSymbolInfo extends IBaseSymbolInfo { }
38
+
39
+ export interface IUSDZMarketInfo extends IBaseMarketInfo {
40
+ // USDZ-specific market info fields can be added here
41
+ }
42
+
43
+ export interface IUSDZPositionInfo extends IBasePositionInfo {
44
+ // USDZ-specific position fields can be added here
45
+ }
46
+
47
+ export interface IUSDZPositionConfig extends IBasePositionConfig { }
48
+
49
+ export interface IUSDZPositionCapInfo extends IBasePositionCapInfo { }
50
+
51
+ export interface IUSDZOrderInfo extends IBaseOrderInfo { }
52
+
53
+ export interface IUSDZOrderCapInfo extends IBaseOrderCapInfo { }
54
+
55
+ export interface IUSDZHistory extends IBaseHistory {
56
+ // USDZ-specific history fields can be added here
57
+ }
58
+
59
+ export interface IUSDZStakePool extends IBaseStakePool {
60
+ // USDZ-specific stake pool fields can be added here
61
+ }
62
+
63
+ export interface IUSDZCredential extends IBaseCredential {
64
+ // USDZ-specific credential fields can be added here
65
+ }
66
+
67
+ // USDZ-specific data API interface
68
+ export interface IUSDZDataAPI extends IBaseDataAPI { }
69
+
70
+ // USDZ-specific API interface
71
+ export interface IUSDZAPI extends IBaseAPI { }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * ZLP-specific interfaces and types
3
+ * Extends base interfaces with ZLP-specific implementations
4
+ */
5
+
6
+ import type { Transaction } from '@mysten/sui/transactions'
7
+ import type {
8
+ IBaseMarketValuationInfo,
9
+ IBaseVaultInfo,
10
+ IBaseSymbolInfo,
11
+ IBaseMarketInfo,
12
+ IBasePositionInfo,
13
+ IBaseOrderInfo,
14
+ IBaseHistory,
15
+ IBaseStakePool,
16
+ IBaseCredential,
17
+ IBaseDataAPI,
18
+ IBaseAPI,
19
+ IBaseFundingFeeModel,
20
+ IBasePositionConfig,
21
+ IBasePositionCapInfo,
22
+ IBaseReservingFeeModel,
23
+ IBaseOrderCapInfo,
24
+ IBaseRebaseFeeModel
25
+ } from './base'
26
+
27
+ // ZLP-specific interfaces
28
+ export interface IZLPMarketValuationInfo extends IBaseMarketValuationInfo { }
29
+
30
+ export interface IZLPVaultInfo extends IBaseVaultInfo { }
31
+
32
+ export interface IZLPReservingFeeModel extends IBaseReservingFeeModel { }
33
+
34
+ export interface IZLPFundingFeeModel extends IBaseFundingFeeModel { }
35
+
36
+ export interface IZLPRebaseFeeModel extends IBaseRebaseFeeModel { }
37
+
38
+ export interface IZLPSymbolInfo extends IBaseSymbolInfo { }
39
+
40
+ export interface IZLPMarketInfo extends IBaseMarketInfo {
41
+ // ZLP-specific market info fields can be added here
42
+ }
43
+
44
+ export interface IZLPPositionInfo extends IBasePositionInfo {
45
+ // ZLP-specific position fields can be added here
46
+ }
47
+
48
+ export interface IZLPPositionConfig extends IBasePositionConfig { }
49
+
50
+ export interface IZLPPositionCapInfo extends IBasePositionCapInfo { }
51
+
52
+ export interface IZLPOrderInfo extends IBaseOrderInfo { }
53
+
54
+ export interface IZLPOrderCapInfo extends IBaseOrderCapInfo { }
55
+
56
+ export interface IZLPHistory extends IBaseHistory {
57
+ // ZLP-specific history fields can be added here
58
+ }
59
+
60
+ export interface IZLPStakePool extends IBaseStakePool {
61
+ // ZLP-specific stake pool fields can be added here
62
+ }
63
+
64
+ export interface IZLPCredential extends IBaseCredential {
65
+ // ZLP-specific credential fields can be added here
66
+ }
67
+
68
+ // ZLP-specific data API interface
69
+ export interface IZLPDataAPI extends IBaseDataAPI { }
70
+
71
+ // ZLP-specific API interface
72
+ export interface IZLPAPI extends IBaseAPI {
73
+ adminIssueLootbox(
74
+ coin: string,
75
+ tiers: number[],
76
+ beneficiaries: string[],
77
+ amounts: number[],
78
+ tx: Transaction,
79
+ ): Promise<void>
80
+
81
+ depositToPrizePool(
82
+ coin: string,
83
+ coinObjects: string[],
84
+ amount: number,
85
+ ): Promise<Transaction>
86
+
87
+ withdrawFromPricePool(
88
+ coin: string,
89
+ amount: number
90
+ ): Promise<Transaction>
91
+
92
+ openLootbox(
93
+ coin: string,
94
+ lootbox: string
95
+ ): Promise<Transaction>
96
+ }
package/src/oracle.ts CHANGED
@@ -4,8 +4,7 @@ import type { PriceFeed } from '@pythnetwork/pyth-sui-js'
4
4
  import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js'
5
5
 
6
6
  import type { IConsts } from './consts'
7
- import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, Network } from './consts'
8
- import jsonFile from './consts/price_id_to_object_id.mainnet.json'
7
+ import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, Network, LPToken } from './consts'
9
8
  import { createJsonRpcProvider } from './utils'
10
9
 
11
10
  export class OracleAPI {
@@ -24,9 +23,10 @@ export class OracleAPI {
24
23
  provider: SuiClient | null,
25
24
  // todo 需要从配置文件中获取
26
25
  connectionURL: string,
26
+ lpToken: LPToken = LPToken.ZLP,
27
27
  ) {
28
28
  this.network = network
29
- this.consts = getConsts(network)
29
+ this.consts = getConsts(network, lpToken)
30
30
  this.connectionURL = connectionURL
31
31
  this.PythFeederToPriceId = getPythFeederToPriceId(network)
32
32
  this.PythFeederToId = getPythFeederToId(network)
@@ -43,7 +43,7 @@ export class OracleAPI {
43
43
  }
44
44
  }
45
45
 
46
- async getOraclePrice(tokenId: string) {
46
+ async getOraclePrice(tokenId: string): Promise<PriceFeed> {
47
47
  this.validateCache()
48
48
  if (this.priceCache[tokenId]) {
49
49
  return this.priceCache[tokenId]
@@ -56,7 +56,7 @@ export class OracleAPI {
56
56
  return res[0]
57
57
  }
58
58
 
59
- async getOraclePrices(tokens: string[]) {
59
+ async getOraclePrices(tokens: string[]): Promise<PriceFeed[]> {
60
60
  const connection = new SuiPriceServiceConnection(this.connectionURL, {
61
61
  priceFeedRequestConfig: {
62
62
  binary: true,
@@ -65,11 +65,11 @@ export class OracleAPI {
65
65
  const pythObjectIds = tokens.map(token => this.consts.pythFeeder.feeder[token])
66
66
  const priceFeedIds = pythObjectIds.map(pythObjectId => `0x${this.PythFeederToPriceId[pythObjectId]}`)
67
67
  const price = await connection.getLatestPriceFeeds(priceFeedIds)
68
- return price
68
+ return price || []
69
69
  }
70
70
 
71
71
  // memory leak
72
- async subOraclePrices(tokens: string[], callback: (price: PriceFeed) => void) {
72
+ async subOraclePrices(tokens: string[], callback: (price: PriceFeed) => void): Promise<() => void> {
73
73
  const connection = new SuiPriceServiceConnection(this.connectionURL, {
74
74
  priceFeedRequestConfig: {
75
75
  binary: true,
@@ -88,20 +88,22 @@ export class OracleAPI {
88
88
  }
89
89
  }
90
90
 
91
- async initOracleTxb(tokens: string[], tx?: Transaction) {
91
+ async initOracleTxb(tokens: string[], tx?: Transaction): Promise<Transaction> {
92
92
  let tx_ = tx
93
93
  if (!tx_) {
94
94
  tx_ = new Transaction()
95
95
  }
96
96
  // Remove redundant tokens first
97
- const uniqueTokens = [...new Set(tokens)]
97
+ const uniqueTokens = Array.from(new Set(tokens))
98
98
 
99
99
  const connection = new SuiPriceServiceConnection(this.connectionURL, {
100
100
  priceFeedRequestConfig: {
101
101
  binary: true,
102
102
  },
103
103
  })
104
- const pythObjectIds = uniqueTokens.map(token => this.consts.pythFeeder.feeder[token])
104
+ let pythObjectIds = uniqueTokens.map(token => this.consts.pythFeeder.feeder[token])
105
+ // remove dupe object ids. If any of the object ids are duplicates the call will fail
106
+ pythObjectIds = [...new Set(pythObjectIds)].filter(Boolean)
105
107
  const needUpdateObjectIds = (await this.provider.multiGetObjects({
106
108
  ids: pythObjectIds,
107
109
  options: {
@@ -127,35 +129,3 @@ export class OracleAPI {
127
129
  return tx_
128
130
  }
129
131
  }
130
-
131
- export async function generatePriceIdToObjectIdJson() {
132
- const provider = createJsonRpcProvider(Network.MAINNET)
133
- const wormholeStateId = '0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c'
134
- const pythStateId = '0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8'
135
- const client = new SuiPythClient(provider, pythStateId, wormholeStateId)
136
- const ret: any = {}
137
-
138
- const entries = Object.keys(jsonFile)
139
-
140
- // 使用 Promise.all 并行处理所有请求
141
- await Promise.all(
142
- entries.map(async (key) => {
143
- try {
144
- const pythObjectId = await client.getPriceFeedObjectId(key)
145
- if (pythObjectId) {
146
- ret[key] = pythObjectId
147
- }
148
- else {
149
- console.warn(`Failed to get pythObjectId for key: ${key}`)
150
- }
151
- }
152
- catch (error) {
153
- console.error(`Error getting pythObjectId for key ${key}:`, error)
154
- }
155
- }),
156
- )
157
-
158
- return ret
159
- }
160
-
161
- // generatePriceIdToObjectIdJson()
package/tsconfig.json CHANGED
@@ -13,8 +13,10 @@
13
13
  "outDir": "./dist",
14
14
  "rootDir": "./src",
15
15
  "lib": ["ES2020", "DOM"],
16
- "resolveJsonModule": true
16
+ "resolveJsonModule": true,
17
+ "downlevelIteration": true,
18
+ "allowSyntheticDefaultImports": true
17
19
  },
18
20
  "include": ["src/**/*"],
19
21
  "exclude": ["node_modules", "dist", "**/*.test.ts"]
20
- }
22
+ }
@@ -1,12 +0,0 @@
1
- {
2
- "zo_staking": {
3
- "package": "",
4
- "upgrade_cap": "",
5
- "admin_cap": "",
6
- "pool": "",
7
- "pools": [""]
8
- },
9
- "coin_modules": {
10
- "sui": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
11
- }
12
- }
@@ -1,11 +0,0 @@
1
- {
2
- "zo_staking": {
3
- "package": "",
4
- "upgrade_cap": "",
5
- "admin_cap": "",
6
- "pool": ""
7
- },
8
- "coin_modules": {
9
- "sui": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
10
- }
11
- }
@@ -1,12 +0,0 @@
1
- {
2
- "zo_staking": {
3
- "package": "",
4
- "upgrade_cap": "",
5
- "admin_cap": "",
6
- "pool": "",
7
- "pools": [""]
8
- },
9
- "coin_modules": {
10
- "sui": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
11
- }
12
- }
@@ -1,11 +0,0 @@
1
- {
2
- "zo_staking": {
3
- "package": "",
4
- "upgrade_cap": "",
5
- "admin_cap": "",
6
- "pool": ""
7
- },
8
- "coin_modules": {
9
- "sui": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
10
- }
11
- }