@meteraprotocol/core
Version:
Core functionality and constants for the Metera Protocol
89 lines (84 loc) • 3.01 kB
TypeScript
import * as bignumber_js from 'bignumber.js';
import { BigNumber } from 'bignumber.js';
import { BigRational } from 'big-rational-ts';
type AssetIdentifier = string;
type PortfolioState<AssetAmountType, MtkSupplyType> = {
/** How much (in the unit) of each asset the portfolio has been deposited */
assets: Record<AssetIdentifier, AssetAmountType>;
/** How many MTKs of the portfolio have been minted */
mtkSupply: MtkSupplyType;
};
type Prices = Record<AssetIdentifier, BigRational>;
/** Dictionary with the ratios of how much of each asset there is/should be in a portfolio */
type Weights = Record<AssetIdentifier, BigRational>;
type RationalDict = Record<AssetIdentifier, BigRational>;
/**
* State of the portfolio at the moment of computation
*/
type State = {
/** Percentage multiplied by 100 (e.g. 324 is 3.24%) */
entryFee: BigNumber;
/** Percentage multiplied by 100 (e.g. 324 is 3.24%) */
exitFee: BigNumber;
/** Percentage multiplied by 100 (e.g. 324 is 3.24%) */
platformFee: BigNumber;
/** Lovelace value */
batcherFee: BigNumber;
/** Micro MTK price in lovelace*/
microMtkPrice: BigNumber;
};
type FeeComputation = {
/** Type of interaction */
type: 'mint' | 'burn';
/** How much in lovelace the user wants to mint/burn in MTK */
amount: BigNumber;
/** The state of the portfolio to base the math on */
portfolioState: State;
};
/**
* Computes the next state of the portfolio after an interaction.
* @param prices The prices of the assets in ADA
* @param targetWeights The target weights of the assets in the portfolio
* @param state The current state of the portfolio
* @param adaInput The amount of ADA to be added (if negative removed) to the portfolio
*
* @returns The new state of the portfolio
*/
declare function computeInteraction(prices: Prices, targetWeights: Weights, state: PortfolioState<bigint, bigint>, adaInput: BigRational): PortfolioState<BigRational, BigRational>;
/**
* Computes how much of each fee in the smart contract this interaction contains
*/
declare function computeFees({ portfolioState, amount, type, }: FeeComputation): {
/**
* Batcher fee in lovelace
*/
batcherFee: bignumber_js.BigNumber;
/**
* Platform fee in lovelace
*/
platformFee: bignumber_js.BigNumber;
/**
* User fees in microMTKs
*/
userFee: bignumber_js.BigNumber;
};
declare const MTK_DECIMALS = 6;
declare const FEES: {
readonly entry: {
readonly max: 500n;
readonly min: 1n;
};
readonly exit: {
readonly max: 500n;
readonly min: 1n;
};
readonly batcher: {
readonly max: 4000000n;
readonly min: 1n;
};
readonly platform: {
readonly max: 100n;
readonly min: 1n;
};
};
export { type AssetIdentifier, FEES, type FeeComputation, MTK_DECIMALS, type PortfolioState, type Prices, type RationalDict, type State, type Weights, computeFees, computeInteraction };