@polymarket/amm-maths
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,3 +0,3 @@ | ||
export { calcPoolTokens, calcAddFundingSendAmounts, calcDepositedTokens, calcRemoveFundingSendAmounts, calcDistributionHint, calcInitialFundingSendAmounts, } from "./liquidity"; | ||
export { calcPoolTokens, calcAddFundingSendAmounts, calcDepositedTokens, calcRemoveFundingSendAmounts, calcDistributionHint, calcInitialFundingSendAmounts, calcPoolBalancesAfterAddFunding, } from "./liquidity"; | ||
export { calcPrice } from "./price"; | ||
export { computeBalanceAfterSharePurchase, computeBalanceAfterShareSale, calcBuyAmountInShares, calcSellAmountInCollateral, } from "./trading"; |
@@ -10,2 +10,3 @@ "use strict"; | ||
Object.defineProperty(exports, "calcInitialFundingSendAmounts", { enumerable: true, get: function () { return liquidity_1.calcInitialFundingSendAmounts; } }); | ||
Object.defineProperty(exports, "calcPoolBalancesAfterAddFunding", { enumerable: true, get: function () { return liquidity_1.calcPoolBalancesAfterAddFunding; } }); | ||
var price_1 = require("./price"); | ||
@@ -12,0 +13,0 @@ Object.defineProperty(exports, "calcPrice", { enumerable: true, get: function () { return price_1.calcPrice; } }); |
import { BigNumber } from "@ethersproject/bignumber"; | ||
/** | ||
* Compute the number of outcomes that will be sent to the user by the Market Maker | ||
* after adding `addedFunds` of collateral. | ||
* Compute the numbers of outcome tokens that will be sent to the user by the market maker after adding `addedFunds` of collateral. | ||
* @param addedFunds - the amount of collateral being added to the market maker as liquidity | ||
* @param poolBalances - the market maker's balances of outcome tokens | ||
* @param poolShareSupply - the total supply of liquidity pool tokens | ||
*/ | ||
export declare const calcAddFundingSendAmounts: (addedFunds: BigNumber, poolBalances: BigNumber[], poolShareSupply: BigNumber) => BigNumber[] | null; | ||
export declare const calcAddFundingSendAmounts: (addedFunds: BigNumber, poolBalances: BigNumber[]) => BigNumber[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calcAddFundingSendAmounts = void 0; | ||
var calcAddFundingDepositedAmounts_1 = require("./calcAddFundingDepositedAmounts"); | ||
/** | ||
* Compute the number of outcomes that will be sent to the user by the Market Maker | ||
* after adding `addedFunds` of collateral. | ||
* Compute the numbers of outcome tokens that will be sent to the user by the market maker after adding `addedFunds` of collateral. | ||
* @param addedFunds - the amount of collateral being added to the market maker as liquidity | ||
* @param poolBalances - the market maker's balances of outcome tokens | ||
* @param poolShareSupply - the total supply of liquidity pool tokens | ||
*/ | ||
exports.calcAddFundingSendAmounts = function (addedFunds, poolBalances, poolShareSupply) { | ||
if (poolShareSupply.eq(0)) { | ||
return null; | ||
} | ||
var poolWeight = poolBalances.reduce(function (a, b) { return (a.gt(b) ? a : b); }); | ||
var sendAmounts = poolBalances.map(function (h) { | ||
var remaining = addedFunds.mul(h).div(poolWeight); | ||
return addedFunds.sub(remaining); | ||
}); | ||
exports.calcAddFundingSendAmounts = function (addedFunds, poolBalances) { | ||
var depositAmounts = calcAddFundingDepositedAmounts_1.calcAddFundingDepositedAmounts(addedFunds, poolBalances); | ||
var sendAmounts = depositAmounts.map(function (depositAmount) { return addedFunds.sub(depositAmount); }); | ||
return sendAmounts; | ||
}; |
import { BigNumber } from "@ethersproject/bignumber"; | ||
/** | ||
* Compute the number of outcomes that will be sent to the user by the Market Maker | ||
* after funding it for the first time with `addedFunds` of collateral. | ||
* Compute the number of outcome tokens that will be sent to the user by the market maker after funding it for the first time with `addedFunds` of collateral. | ||
* @dev The distribution hint plays the role of the pool's balances so we can just forward this to calcAddFundingSendAmounts | ||
* @param addedFunds - the amount of collateral being added to the market maker as liquidity | ||
@@ -6,0 +6,0 @@ * @param distributionHint - a distribution hint as calculated by `calcDistributionHint` |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calcInitialFundingSendAmounts = void 0; | ||
var calcAddFundingSendAmounts_1 = require("./calcAddFundingSendAmounts"); | ||
/** | ||
* Compute the number of outcomes that will be sent to the user by the Market Maker | ||
* after funding it for the first time with `addedFunds` of collateral. | ||
* Compute the number of outcome tokens that will be sent to the user by the market maker after funding it for the first time with `addedFunds` of collateral. | ||
* @dev The distribution hint plays the role of the pool's balances so we can just forward this to calcAddFundingSendAmounts | ||
* @param addedFunds - the amount of collateral being added to the market maker as liquidity | ||
@@ -11,5 +12,3 @@ * @param distributionHint - a distribution hint as calculated by `calcDistributionHint` | ||
exports.calcInitialFundingSendAmounts = function (addedFunds, distributionHint) { | ||
var maxHint = distributionHint.reduce(function (a, b) { return (a.gt(b) ? a : b); }); | ||
var sendAmounts = distributionHint.map(function (hint) { return addedFunds.sub(addedFunds.mul(hint).div(maxHint)); }); | ||
return sendAmounts; | ||
return calcAddFundingSendAmounts_1.calcAddFundingSendAmounts(addedFunds, distributionHint); | ||
}; |
@@ -7,1 +7,2 @@ export { calcAddFundingSendAmounts } from "./calcAddFundingSendAmounts"; | ||
export { calcRemoveFundingSendAmounts } from "./calcRemoveFundingSendAmounts"; | ||
export { calcPoolBalancesAfterAddFunding } from "./calcPoolBalancesAfterAddFunding"; |
@@ -15,1 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "calcRemoveFundingSendAmounts", { enumerable: true, get: function () { return calcRemoveFundingSendAmounts_1.calcRemoveFundingSendAmounts; } }); | ||
var calcPoolBalancesAfterAddFunding_1 = require("./calcPoolBalancesAfterAddFunding"); | ||
Object.defineProperty(exports, "calcPoolBalancesAfterAddFunding", { enumerable: true, get: function () { return calcPoolBalancesAfterAddFunding_1.calcPoolBalancesAfterAddFunding; } }); |
@@ -26,3 +26,6 @@ "use strict"; | ||
if (scale === void 0) { scale = 10000; } | ||
return bignumber_1.BigNumber.from(a).mul(scale).div(b).toNumber() / scale; | ||
return (bignumber_1.BigNumber.from(a) | ||
.mul(scale) | ||
.div(b) | ||
.toNumber() / scale); | ||
}; | ||
@@ -29,0 +32,0 @@ /** |
{ | ||
"name": "@polymarket/amm-maths", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Utility package to store common maths for interacting with Conditional Tokens AMMs", | ||
@@ -36,4 +36,5 @@ "repository": "https://github.com/TokenUnion/amm-maths.git", | ||
"@types/big.js": "^6.0.0", | ||
"@types/jest": "^26.0.20", | ||
"eslint": "6.x", | ||
"eslint-config-airbnb-typescript-prettier": "^3.1.0", | ||
"eslint-config-airbnb-base-typescript-prettier": "^4.1.0", | ||
"jest": "^26.6.3", | ||
@@ -58,3 +59,3 @@ "lint-staged": "^10.2.7", | ||
"clean": "shx rm -rf ./lib", | ||
"lint": "eslint --config ./.eslintrc.js --ignore-path ./.eslintignore ./src/**/*", | ||
"lint": "eslint --config ./.eslintrc.js --ignore-path ./.eslintignore ./src/**/*.ts", | ||
"test": "jest", | ||
@@ -61,0 +62,0 @@ "prepack": "yarn clean && yarn test && yarn build" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39286
46
580
12
1