Skip to content

Commit

Permalink
feat: take rate, multi-currency (#118)
Browse files Browse the repository at this point in the history
* expose currency to bid engine
  • Loading branch information
boz authored Jun 16, 2023
1 parent 82f5313 commit c2213a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bidengine/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ loop:
price := result.Value().(sdk.DecCoin)
maxPrice := group.GroupSpec.Price()

if maxPrice.GetDenom() != price.GetDenom() {
o.log.Error("Unsupported Denomination", "calculated", price.String(), "max-price", maxPrice.String())
break loop
}

if maxPrice.IsLT(price) {
o.log.Info("Price too high, not bidding", "price", price.String(), "max-price", maxPrice.String())
break loop
Expand Down
3 changes: 1 addition & 2 deletions bidengine/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type BidPricingStrategy interface {
CalculatePrice(ctx context.Context, req Request) (sdk.DecCoin, error)
}

const denom = "uakt"

var (
errAllScalesZero = errors.New("at least one bid price must be a non-zero number")
errNoPriceScaleForStorageClass = errors.New("no pricing configured for storage class")
Expand Down Expand Up @@ -130,6 +128,7 @@ func (fp scalePricing) CalculatePrice(_ context.Context, req Request) (sdk.DecCo
cpuTotal := decimal.NewFromInt(0)
memoryTotal := decimal.NewFromInt(0)
storageTotal := make(Storage)
denom := req.GSpec.Price().Denom

for k := range fp.storageScale {
storageTotal[k] = decimal.NewFromInt(0)
Expand Down
3 changes: 3 additions & 0 deletions bidengine/shellscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ func (ssp shellScriptPricing) CalculatePrice(ctx context.Context, req Request) (
stderrBuf := &bytes.Buffer{}
cmd.Stderr = stderrBuf

denom := req.GSpec.Price().Denom

subprocEnv := os.Environ()
subprocEnv = append(subprocEnv, fmt.Sprintf("AKASH_OWNER=%s", req.Owner))
subprocEnv = append(subprocEnv, fmt.Sprintf("AKASH_DENOM=%s", denom))
cmd.Env = subprocEnv

err = cmd.Run()
Expand Down

0 comments on commit c2213a8

Please sign in to comment.