Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Remove sqrtOfTokens (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
HardlyDifficult authored and mergify[bot] committed Nov 6, 2019
1 parent 4f483c9 commit 3072b11
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 35 deletions.
18 changes: 0 additions & 18 deletions contracts/math/Sqrt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@ library Sqrt
/// @notice The max possible value
uint256 constant MAX_UINT = 2**256 - 1;

/**
* @notice Calculates sqrt(x/(10^18)^2)*10^18 with 10 decimals of precision.
* @dev Assumes 18 decimals (standard for tokens). 10 decimals of precision was choosen to
* be on-par with the Vyper implementation.
* Returns 0 when x < 10^26.
*/
function sqrtOfTokens(
uint x
) public pure
returns (uint y)
{
// Shift by 18 decimals squared, and leave 10 decimals for sqrt precision
y = x / 10**(18 + 18 - 10);
y = sqrt(y);
// Adjust for sqrt(10^10) (5) and *10^18
y = y.mul(10**(18-5));
}

// Source: https://github.com/ethereum/dapp-bin/pull/50
function sqrt(
uint x
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hardlydifficult-ethereum-contracts",
"version": "0.6.6",
"version": "0.6.7",
"description": "A collection of reusable contracts and Javascript helpers for Ethereum.",
"scripts": {
"build": "npm run compile",
Expand Down
16 changes: 0 additions & 16 deletions test/math/sqrtNumbersArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,6 @@ contract("math / sqrtNumbersArray", () => {

for (let i = numbers.length - 1; i >= 0; i--) {
const x = numbers[i];
let sqrtOfTokensResult = new BigNumber(x)
.div(new BigNumber(10).pow(8))
.dp(0) // we expect to lose 8 decimals before the sqrt
.div(new BigNumber(10).pow(36 - 8))
.sqrt()
.times(new BigNumber(10).pow(18));

it(`sqrtOfTokens(${x.toFixed()}) ~= ${sqrtOfTokensResult.toExponential(
2
)})`, async () => {
sqrtOfTokensResult = sqrtOfTokensResult.dp(0);
const contractRes = new BigNumber(
await contract.sqrtOfTokens(x.toFixed())
);
checkBounds(sqrtOfTokensResult, contractRes, true);
});

let sqrtResult = new BigNumber(x).sqrt();
it(`sqrt(${x.toFixed()}) ~= ${sqrtResult.toExponential(2)}`, async () => {
Expand Down

0 comments on commit 3072b11

Please sign in to comment.