@@ -99,29 +99,29 @@ export const msToRent: Readable<number> = derived(activeBlockchain, ($activeBloc
99
99
100
100
//price per ms
101
101
export const cpuPowerupPrice = derived (
102
- [ msToRent , sampleUsage , statePowerUp , info ] ,
103
- ( [ $msToRent , $sampleUsage , $statePowerUp , $info ] ) => {
102
+ [ activeBlockchain , msToRent , sampleUsage , statePowerUp , info ] ,
103
+ ( [ $activeBlockchain , $ msToRent, $sampleUsage , $statePowerUp , $info ] ) => {
104
104
if ( $msToRent && $sampleUsage && $statePowerUp ) {
105
105
return Asset . from (
106
106
$statePowerUp . cpu . price_per_ms ( $sampleUsage , $msToRent , $info ) ,
107
- '4,EOS'
107
+ $activeBlockchain . coreTokenSymbol
108
108
)
109
109
}
110
- return Asset . from ( 0 , '4,EOS' )
110
+ return Asset . from ( 0 , $activeBlockchain . coreTokenSymbol )
111
111
}
112
112
)
113
113
114
114
// price per kb
115
115
export const netPowerupPrice = derived (
116
- [ sampleUsage , statePowerUp , info ] ,
117
- ( [ $sampleUsage , $statePowerUp , $info ] ) => {
116
+ [ activeBlockchain , sampleUsage , statePowerUp , info ] ,
117
+ ( [ $activeBlockchain , $ sampleUsage, $statePowerUp , $info ] ) => {
118
118
if ( $sampleUsage && $statePowerUp ) {
119
119
return Asset . from (
120
120
$statePowerUp . net . price_per_kb ( $sampleUsage , 1 , $info ) ,
121
- '4,EOS'
121
+ $activeBlockchain . coreTokenSymbol
122
122
)
123
123
}
124
- return Asset . from ( 0 , '4,EOS' )
124
+ return Asset . from ( 0 , $activeBlockchain . coreTokenSymbol )
125
125
}
126
126
)
127
127
@@ -182,31 +182,38 @@ export const stateREX: Readable<REXState | undefined> = derived(
182
182
183
183
// The price of CPU in the REX system
184
184
export const cpuRexPrice = derived (
185
- [ msToRent , sampleUsage , stateREX ] ,
186
- ( [ $msToRent , $sampleUsage , $stateREX ] ) => {
185
+ [ activeBlockchain , msToRent , sampleUsage , stateREX ] ,
186
+ ( [ $activeBlockchain , $ msToRent, $sampleUsage , $stateREX ] ) => {
187
187
if ( $msToRent && $sampleUsage && $stateREX ) {
188
- return Asset . from ( $stateREX . price_per ( $sampleUsage , $msToRent * 30000 ) , '4,EOS' )
188
+ const price = $stateREX . price_per ( $sampleUsage , $msToRent * 30000 ) ;
189
+ const coreTokenSymbol = $activeBlockchain . coreTokenSymbol
190
+ return compatPriceWithPrecision ( price , coreTokenSymbol )
189
191
}
190
- return Asset . from ( 0 , '4,EOS' )
192
+ return Asset . from ( 0 , $activeBlockchain . coreTokenSymbol )
191
193
}
192
194
)
193
195
194
196
// The price of Net in the REX system
195
197
export const netRexPrice = derived (
196
- [ sampleUsage , stateREX ] ,
197
- ( [ $sampleUsage , $stateREX ] ) => {
198
+ [ activeBlockchain , sampleUsage , stateREX ] ,
199
+ ( [ $activeBlockchain , $ sampleUsage, $stateREX ] ) => {
198
200
if ( $sampleUsage && $stateREX ) {
199
- const price = calculateNetRexPrice ( $stateREX , $sampleUsage , 30000 ) ;
200
- let precision = 4 ;
201
- if ( price > 0 && price < 0.0001 ) {
202
- precision = Number ( price . toExponential ( ) . split ( '-' ) [ 1 ] )
203
- }
204
- return Asset . from ( price , `${ precision } ,EOS` )
201
+ const price = calculateNetRexPrice ( $stateREX , $sampleUsage , 30000 )
202
+ const coreTokenSymbol = $activeBlockchain . coreTokenSymbol
203
+ return compatPriceWithPrecision ( price , coreTokenSymbol )
205
204
}
206
- return Asset . from ( 0 , '4,EOS' )
205
+ return Asset . from ( 0 , $activeBlockchain . coreTokenSymbol )
207
206
}
208
207
)
209
208
209
+ function compatPriceWithPrecision ( price : number , coreTokenSymbol : Asset . Symbol ) {
210
+ let precision = coreTokenSymbol . precision ;
211
+ if ( price > 0 && price < 1 / Math . pow ( 10 , precision ) ) {
212
+ precision = Number ( price . toExponential ( ) . split ( '-' ) [ 1 ] )
213
+ }
214
+ return Asset . from ( price , `${ precision } ,${ coreTokenSymbol . name } ` )
215
+ }
216
+
210
217
function calculateNetRexPrice ( stateRex : REXState , sample : SampleUsage , unit = 1000 ) : number {
211
218
// Sample token units
212
219
const tokens = Asset . fromUnits ( 10000 , stateRex . symbol )
0 commit comments