Skip to main content

Pricing

Github: packages/nftanvil_canisters/mo/type/nft_interface.mo

import Nft "mo:anvil/type/nft_interface"
module {
...

public module Pricing = {
// WARNING: Has to mirror calculations in pricing.js
public let QUALITY_PRICE : Nat64 = 1000; // max quality price per min
public let STORAGE_KB_PER_MIN : Nat64 = 8; // prices are in cycles
public let AVG_MESSAGE_COST : Nat64 = 4000000; // prices are in cycles
public let FULLY_CHARGED_MINUTES : Nat64 = 8409600; //(16 * 365 * 24 * 60) 16 years
public let FULLY_CHARGED_MESSAGES : Nat64 = 5840; // 1 message per day

public func priceStorage({
custom:?CustomData;
content:?Content;
thumb:Content;
quality:Quality;
ttl: ?Nat32;
}) : Nat64 { // half goes to rechare pool paid to IC the other half goes to NFTAnvil community pool
let cost_per_min = Pricing.STORAGE_KB_PER_MIN * 100 // cost for nft metadata stored in the cluster
+ OptPrice(custom, CustomData.price)
+ OptPrice(content, Content.price)
+ Content.price(thumb)
+ Quality.price(quality);

switch(ttl) {
case (null) {
cost_per_min * Pricing.FULLY_CHARGED_MINUTES * 2
};
case (?t) {
cost_per_min * Nat64.fromNat(Nat32.toNat(t)) * 2
}
}
};

public func priceOps({ // half goes to rechare pool paid to IC the other half goes to NFTAnvil community pool
ttl:?Nat32
}) : Nat64 {

switch(ttl) {
case (null) {
Pricing.FULLY_CHARGED_MESSAGES * Pricing.AVG_MESSAGE_COST * 2
};

case (?t) {
(Nat64.fromNat(Nat32.toNat(t)) * Pricing.AVG_MESSAGE_COST / 60 / 24 // 1 message a day
+ Pricing.AVG_MESSAGE_COST * 100) * 2 // minimum 100 messages
}
}
};

};

public func OptPrice<A>(v:?A, f: (A) -> Nat64) : Nat64 {
switch(v) { case (?z) f(z); case(null) 0 }
};

public func OptValid<A>(v:?A, f: (A) -> Bool) : Bool {
switch(v) { case (?z) f(z); case(null) true }
};

public type Price = {
amount : Nat64;
marketplace : ?{
address : AccountIdentifier;
share : Share
};
};

public module Price = {
public func NotForSale() : Price {
{
amount = 0;
marketplace = null;
// affiliate = null;
}
};

public func hash(x: Price) : [Nat8] {
_Array.concat<Nat8>(
Blob_.nat64ToBytes(x.amount),
switch(x.marketplace) {
case (?{address; share}) {
_Array.concat<Nat8>(
Blob.toArray(address),
Blob_.nat16ToBytes(share)
)
};
case (null) {
[]
}
}
)
};
};

...
}