web/website/node/spice-policy.mjs

6 lines
657 B
JavaScript

export const SPICE_POLICY=Object.freeze({version:1,guild:1995,smuggler:1500,levyBasisPoints:121});
export function spiceQuote(channel,amount,policy=SPICE_POLICY){
if(!['guild','smuggler'].includes(channel)||!Number.isInteger(amount)||amount<1||amount>21312||!Number.isSafeInteger(policy[channel])||policy[channel]<1||!Number.isInteger(policy.levyBasisPoints)||policy.levyBasisPoints<0||policy.levyBasisPoints>10000)throw Error('Choose between 1 and 21312 spice.');
const gross=policy[channel]*amount,tax=Math.round(gross*policy.levyBasisPoints/10000);
return {channel,amount,unitMinor:policy[channel],grossMinor:gross,taxMinor:tax,netMinor:gross-tax};
}