Skip to content

Commit

Permalink
Perps Rounding to Mbs instead of Gbs (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell authored Aug 17, 2023
2 parents 7d5969c + 044cdae commit 28b6ee6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x/storage/keeper/msg_server_sign_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (k msgServer) SignContract(goCtx context.Context, msg *types.MsgSignContrac

var end int64
if msg.PayOnce {
s := size.Quo(sdk.NewInt(1_000_000_000)).Int64()
s := size.Quo(sdk.NewInt(1_000_000)).Int64() // round to mbs
if s <= 0 {
s = 1
}
cost := k.GetStorageCost(ctx, s, 720*12*200) // pay for 200 years
cost := k.GetStorageCostKbs(ctx, s*1000, 720*12*200) // pay for 200 years in mbs
deposit, err := sdk.AccAddressFromBech32(k.GetParams(ctx).DepositAccount)
if err != nil {
return nil, err
Expand Down
25 changes: 25 additions & 0 deletions x/storage/keeper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ func (k Keeper) GetProviderUsing(ctx sdk.Context, provider string) int64 {
return space
}

// GetStorageCostKbs calculates storage cost in ujkl
// Uses kilobytes and months to calculate how much user has to pay
func (k Keeper) GetStorageCostKbs(ctx sdk.Context, kbs int64, hours int64) sdk.Int {
pricePerTBPerMonth := sdk.NewDec(k.GetParams(ctx).PricePerTbPerMonth)
quantifiedPricePerTBPerMonth := pricePerTBPerMonth.QuoInt64(3)
pricePerGbPerMonth := quantifiedPricePerTBPerMonth.QuoInt64(1000)
pricePerMbPerMonth := pricePerGbPerMonth.QuoInt64(1000)
pricePerKbPerMonth := pricePerMbPerMonth.QuoInt64(1000)
pricePerKbPerHour := pricePerKbPerMonth.QuoInt64(720)

pricePerHour := pricePerKbPerHour.MulInt64(kbs)

totalCost := pricePerHour.MulInt64(hours)

jklPrice := k.GetJklPrice(ctx)

// TODO: fetch denom unit from bank module
var ujklUnit int64 = 1000000
jklCost := totalCost.Quo(jklPrice)

ujklCost := jklCost.MulInt64(ujklUnit)

return ujklCost.TruncateInt()
}

// GetStorageCost calculates storage cost in ujkl
// Uses gigabytes and months to calculate how much user has to pay
func (k Keeper) GetStorageCost(ctx sdk.Context, gbs int64, hours int64) sdk.Int {
Expand Down

0 comments on commit 28b6ee6

Please sign in to comment.