Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Lesson 8: Integer Math

In this lesson we're adding a get_dy function, which computes the number of $crvUSD stablecoins received for dx, an input of the collateral token ($CRV).

In the process the lesson highlights some of the intricacies of working with integer arithmetic within smart contracts. A supplemental file TestMath.vy displayed in the video is included in the contracts directory.

Vyper contains additional advanced math functions. For further reading:

INTEGER MATH

Arithmetic in Vyper uses the basic operators from Python. All arithmetic operators utilize safemath by default and revert on overflow.

  • x + y Addition
  • x - y Subtraction
  • -x Unary minus/Negation
  • x * y Multiplication
  • x / y Integer Division
  • x ** y Exponentiation
  • x % y Modulo

DECIMAL TYPES

Vyper supports a decimal variable type that renders as fixed168x10 in the ABI. This tutorial instead follows the convention of shifting 18 decimal places and rounding it off as a uint.