Safe, simple, flexible building-blocks for smart-contract systems.
ds-auth
ds-guard
ds-roles
ds-token
ds-vault
ds-cache
ds-value
ds-exec
ds-math
ds-note
ds-proxy
ds-stop
ds-thing
ds-multisig
Safe Arithmetic
DS-Math provides arithmetic functions for the common numerical primitive types
of Solidity. You can safely add, subtract, multiply, and divide uint
numbers
without fear of integer overflow. You can also find the minimum and maximum of
two numbers.
Additionally, this package provides arithmetic functions for new two higher level numerical concepts called wad (18 decimals) and ray (27 decimals). These are used to represent fixed-point decimal numbers.
A wad is a decimal number with 18 digits of precision and a ray is a decimal
number with 27 digits of precision. These functions are necessary to account for
the difference between how integer arithmetic behaves normally, and how decimal
arithmetic should actually work. A brief example using wmul
, which returns the
product of a wad and another number:
1.1 * 2.2 == 2.42
//Regular integer arithmetic adds orders of magnitude:
110 * 220 == 24200
// Wad arithmetic does not add orders of magnitude:
wmul(1.1 ether, 2.2 ether) == 2.42 ether
The standard functions are the uint
set, so their function names are not
prefixed: add
, sub
, mul
, min
, and max
. There is no div
function, as
divide-by-zero checking is built into the Solidity compiler.
The int
functions have an i
prefix: imin
, and imax
.
Wad functions have a w
prefix: wmul
, wdiv
.
Ray functions have a r
prefix: rmul
, rdiv
, rpow
.
add
Return x + y
or an exception in case of uint
overflow.
sub
Return x - y
or an exception in case of uint
overflow.
mul
Return x * y
or an exception in case of uint
overflow.
min
Return the smaller number of x
and y
.
max
Return the larger number of x
and y
.
imin
Return the smaller number of x
and y
.
imax
Return the larger number of x
and y
.
wmul
Multiply two Wads and return a new Wad with the correct level of precision. A Wad is a decimal number with 18 digits of precision that is being represented as an integer.
wdiv
Divide two Wads and return a new Wad with the correct level of precision. A Wad is a decimal number with 18 digits of precision that is being represented as an integer.
rmul
Multiply two Rays and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.
rdiv
Divide two Rays and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.
rpow
Raise a Ray to the n^th power and return a new Ray with the correct level of precision. A Ray is a decimal number with 27 digits of precision that is being represented as an integer.
We believe that the free software movement is the most important cultural predecessor to the modern-day renaissance in decentralized technologies.
To catalyze the growth of this ecosystem, and to empower hackers to participate, we’re building a comprehensive suite of blockchain-oriented developer tools in the spirit of the Unix philosophy.
Dapp is all you need to start developing for Ethereum. It creates new dapps, runs Solidity unit tests, debugs, deploys, launches testnets, and more.
Seth is a handy tool for slicing and dicing transactions, querying the blockchain, converting between data formats, performing remote calls, and other everyday tasks.
Hevm is our own EVM
implementation with a nimble terminal-based Solidity debugger.
It’s used for dapp test
and dapp debug
.
We also maintain Dappsys, an audited collection of smart contract building blocks designed to complement each other. They include;
ds-token
—
a generic EIP-20 coin;
ds-group
—
a multisig;
ds-guard
—
a flexible authority rule;
ds-proxy
—
a transaction proxy; and
ds-cache
—
a store of expiring values.
Using these proven parts lets us focus on the novel features of the systems we develop. We share Dappsys to benefit the smart contract ecosystem.