• review

  • AAVEGOTCHI FAUCET Review

    • ownerOf
    • getApproved
    • isApprovedForAll

    write a contract that acts as a disseminator allows specific addresses to mint a certificate. The predefined certs are already uploaded to ipfs(pinata). there is a supposed connection between user⇒id⇒ipfs

    JobsInCrypto - twitter

    Assignment: https://github.com/jebitok-dev/autoyieldfarms/blob/main/contracts/UserYieldFarming.sol

    • [ ] AutoyieldFarms
    • Reviewing the AutoyieldFarm Contract, the contract is written using the solidity version that is greater or equal 0.4.0. It uses the SafeMath Library like the one by OpenZeppelin to help with arithmetic computations.
    • the safemath library is defined within the contract(not imported). The library has:
      • add function that requires at least the output of the sum of a & b will be greater than either a or b meaning its sum of whole numbers.
      • subtract function that allows the use of minus operator and subtract function for unsigned integers that can allow signed integer that is greater than the other to subtract the other.
      • multiplication function that checks that if one number is equal to zero if multiplied returns zero and if multiplication of two equal numbers its division returns value equals to either of them
      • division function that checks division of two numbers and reverts any division of a number with zero. Also has a division function that requires that a number is greater than zero else gives an error message so division.
      • modulo function that uses the % operator returns the remainder of diving two unsigned integers and reverts operations that divide integer with zero which leaves gas unused ensuring divisor isn’t equal to zero
      • min function that uses a ternary operator to check if the variables are equal or else than the other and pass a condition.
      • square-root function which is a Babylonian method that checks some conditions then performs square-root of the given variables
    • the contract uses the IBEP20 Contract Interface which consists of:
      • totalSupply function that returns the amount of tokens that exists i.e uint256
      • decimals function that returns the tokens in decimals i.e uint8
      • symbol function that returns the symbol of the token
      • name function that returns the name of the token
      • getOwner function that returns the address of the token owner
      • balance function that returns the number of tokens owned by the address owner
      • transfer function that facilities the transaction of moving tokens it passes the recipient's address and the amount to be transferred
      • allowance function that passes the address of owner and the address spender allowed to spend on behalf of owner’s address. The value of the address changes when approve/transfer from functions are called
      • approve function which passes the address of spender and the amount to allowance to be spent and returns a bool which could be approval allowed or denied
      • transferFrom function that passes the addresses of sender and recipient and the amount of token and also returns a bool
      • Transfer event which stores the indexed address of transferFrom(sender), indexed address of transferTo(receiver) and the value of transaction passed in a transaction. this is emmited when transferring tokens
      • Approval event which stores the indexed address of owner and that of spender and value that are passed in allowance transaction. Its emmited when approve function is called and passes
    • Address Library that has:
      • isContract function which is a hashing function that passes the address of the account and returns a boolean. The account is hashed into accountHash which is of bytes32 of 64 char and is prefixed with 0x i.e hexadecimal string. and also an account that has not been generated is a codehash and to generate a new account it uses assembly. The generated address is ensured that it is not equal to the one that was hashed using keccak256 and is not the uncreated one
      • sendValue function that passes the address of the recipient which is payable(reduce gas fees) and the amount to be sent. It has a require statement that ensures that the account balance is greater or equal to the amount to be sent. It returns a bool that either transaction was successful or it was reverted either by the recipient or failed
        • functionCall function that passes the address of the target and the data in memory(just used within the contract) and returns memory data i.e notifies when low-level calls fail. (could be an internal method defined to be used in another function)
        • functionCall function that passes the address of the target, data in memory, and the error message is an internal function and returns the memory data i.e it uses the functionCallWithValue method which is a method that was defined with this contract library that still passes the target address, data, value, and the error message or the low-level call failing
        • functionCallWithValue function which passes the address of the target, memory data, value, and error message, it requires that the address balance is greater than the value else sends an error message else returns a method which is a function i.e _functionCallWithValue which passes the target, data, value and error message
        • _functionCallWithValue requires that the target’s address is not hashed or uncreated account else pass an error message that it's not a contract address then it passes a bool and memory data it will make a low-level call i.e the value in Wei and the data if it's successful it emits the call else if the unsuccessful checks reason(balance) and reverts the transaction using memory through assembly
  • uses SafeBEP20 library that uses the SafeMath and Address Library defined within this contract. It has:

    • safeTransfer function that passes an IBEP20 token, address of the receiver, and the value which is an internal function it uses _callOptionalReturn method (define as a function within this library that is re-used in all the functions it passes the token, data in memory and data its a private function that defines the return data which is the token address then functionCall is called to check its requirements to determine if the low-level call passes or not, to pass data) which passes the token, abi.encodewithselector that passes data variables i.e event token transferfrom selector, the address of the sender, address of the receiver and the value
    • safeApprove function with passes the IEP20 Token, address of spender and the value its an internal function that requires that the value is equal to zero or the token allowance balance of address of the spender from is equal to zero or send a message that SafeBEP20 is only approved for non-zero to non-zero allowance then calls the _callOptionalReturn method that passes the token and abi.encodeWithSelector that passes variables the event that token approve selector, address pf spender and the value
    • safeIncreaseAllowance that passes that IBEP token, address of spender, and the value is an internal function that defines newAllowance which is token allowance which is assigned address and a spender whom a given value is added to them. It uses the _callOptionalReturn method that stores the token, abi.encodeWithSelector that is feed data variables token approve selector, the spender and the newAllowance to increase
    • safeDecreaseAllowance function which unlike the safeIncreaseAllowance function passes the parameters and uses the same method but decreases the allowance using the given value.
  • Context Contract that has:

    • an empty constructor that prevents people from mistakenly deploying contract instance used for inheritance
    • _msgSender function that returns a payable address and return statement is a low-level call msg.sender
    • _msgData function that returns memory in bytes and return statement is a low-level call msg.data
  • Ownable Contract that is a Context Contract. It

    • declares an owner’s address which is private
    • declares an event OwnershipTransferred which has indexed parameters: previous owners and the new owner
    • it declares constructor function which is internal that has an address of the sender that’ll facilitate owner level call and its assigned to the owner and will emit OwnershipTransferred event of the index address & low-level call
    • owner function that returns an address i.e _owner by address
    • a modifier OnlyOwner that requires that only the owner that is equivalent to msg.sender can only call this contract
    • renounceOwnership function that can only be accessed by the current owner and emits the OwnershipTransferred event that was declared that has parameters indexed owner & address so the owner will be equivalent to given indexed address if ownership is renounced
    • transferOwnership function that passes the address of newOwner whom ownership is transferred to and this call only called by the owner and it transferOwnership to the new owner using _tranferOwnership method defined within this contract as a function it requires that newOwner is equal to the index zero address then emits the ownershipTransferred event which transfers ownership to newOwner then reassigns ownership from owner to newOwner
  • BEP20 Contract which is a Context, IBEP20, and Ownable Contract it uses the Safemath and Address Libraries. It has:

    • mapping that maps the address to uint256
    • mapping that maps the address to another nested mapping
    • declares variables that will be used in the contract i.e total supply, name, symbol, and decimals
    • defines constructor function that passes name stored in memory and string stored in memory that reassigns _name to name, _symbol to symbol, and _decimal to the given number of decimal (18).
    • getOwner function that’s an external function that returns an address and return statement is an owner
    • name function that returns a string and return statement is the name of the token
    • decimals function whose return statement is the decimals
    • symbol function that returns a string i.e string
    • totalSupply function that returns the totalSupply of the token
    • balanceOf function that passes the address of a given account and returns that balance of the account
    • transfer function that passes the address of the recipient and the amount to be transferred and returns a bool to be called it requires that its no a zero address and the amount will be transferred to the given address by the user or the transaction will fail(true/false...if it meets requirements)
    • allowance function that passes the address of the owner and that of the spender and returns an allowance that the owner can transfer/allow to the spender
    • approve function that passes the address of spender and the amount it returns a bool(true/false) and can approve the low-level call of sending spender given amount of allowance after checking that it's not a zero-address
    • TransferFrom function that has the address of the sender, the address of the recipient, and the given amount that returns a boolean(true/false). _transfer method takes the sender’s address, recipient's address, and the amount whereas the _approve takes the sender’s address, the low-level call msg.sender(requires owner) and the allowances to be transferred to spender hence subtracting from the Owner’s amount of tokens
    • decreaseAllowancefunction that passes the spender’s address and subtractedValue and the _approve method that executes low-level call, spender’s address, and the allowance from the owner to the spender then using sub-method from Safemath to subtract value from the owner. If the address is non-zero and the balance meets the condition it will return a true else false
    • mint function that passes the amount to be minted and returns a bool. It uses the _mint method whose tokens are assigned to the owner with a given amount of tokens out of the mint
    • _transfer function that is defined and used in other functions within this contract its an internal function that passes the address of the sender and that of the recipient and the amount it requires that sender’s and recipient's addresses should not the zero index address. balance of the sender is equal to the amount subtracted by the allowance amount and the recipient's balance is equal to the actual balance added to the allowance from the sender
    • _mint function that is also used in the other functions within this contract passes the address of the account and the amount it also requires that the account should not be a zero-indexed address. The total supply is equal to the totalSupply plus the amount from the mint and the account balance equals the actual balance plus the amount added from the mint. This mint emits the Transfer method to the given zero index address, the account, and the given amount
    • _burn function that passes the account address and the amount it requires that the address of the account isn’t zero-indexed. The balance of the account is equal to the balance of the account subtracted by the amount from the burn and the total supply is equal to the total supply minus the amount as a result of a burn. This emits the transfer method who variables are the account, zero-indexed address and amount
    • _approve function that passes the address of the owner and that of spender and amount it requires that owner’s and recipient addresses are not zero-index addresses. The amount is equal to the allowance that the owner approves for a spender. This emits the Approval method that
    • _burnFrom function that passes the address of the account that contract will burn from, and the amount. _burn takes the account and amount and _approve takes account, the owner and the subtracts the allowance that the owner then burns the amount that exceeds the this. This function is used in the burn function
  • Contract RigelToken is a BEP20 Token and it's a governance token. It has:

    • mint function that passes the address of which token is minted and the amount this can only be called by the owner. _mint emit the amount to a given address and _moveDelegates passes index zero address(first), amount and adds it to delegates record
    • mapping of address to address on delegates
    • checkpoint struct that marks the fromBlock and the votes
    • mapping address to another mapping and records them on checkpoints
    • mapping address to uint32 and records ut on numCheckpoints
    • Domain Typehashing constant: EIP712Domain of name, chainId, verifying contract using Keccak256
    • Delegation Typehashing constant: EIP712Delegation of delegatee, nonce, expirity
    • mapping address to unit to record on nonces
    • event DelegateChanged that stores indexed delegator address, indexed address of fromDelegate and indexed address of toDelegate . It’s emitted when the account changes its delegate
    • event DelegateVotesChanged which stores the indexed address of the delegate, previous balance, and new balance. Emitted when account balance changes
    • delegates function that passes the address of delegator and returns an address of the delegator from _delegates record
    • delegate function that passes the address of delegated and has return statement _delegate with the msg.sender(the owner who’ll vote) and the delegatee(the address that delegates votes)
    • delegateBySig function that passes the address of delegatee, nonce, expiry, v, r, and s. This function has: (encode data in EIP712)
    • getCurrentVotes function that passes address of the account and returns uint256 value. Has nCheckPoints that checks the votes of the account. and return statement with terniray operator with condition if nCheckPoint is greater than 0 it will return the checkpoints of the account multiplied by the number of checks minus one multiplied by the votes else return zero
    • getPriorVotes functions that passes the account’s address and the blocknumber which returns a uint256 value. it:
    • _delegate function used in other function within this contract passes the address of the delegator and address of delegatee.
    • _moveDelegates functions that passes address of srcRep, address of dstRep and amount. If the srcRep is not equal and amount is greater than zero
    • _writeCheckPoint functions which passes the address of delagatee, nCheckpoints, oldVotes, newVotes.
    • safe32 function that passes n, errorMessage string stored in memory and returns a uint32 value it requires that the value of n is less than two power of 32 else returns an errormessage and the return statement is value of n in uint32
    • getChainId functions returns a uint value. It has chainID and uses assembly() to the get chainId (latest versions of solidity avoids the use of assembly for the chainID it uses block.chainid)
    // assembly was also used in the previous version of UniswapV2ERC20 
    // block.chainid wasn't yet implemented in solidity 
    uint chainId;
    assembly {
        chainId := chainid
    }
    
  • MaterChef Contract which is Ownable. It uses SafeMath and safeBEP20. It has:

  • deposit function that passes the _pid and the _amount:

  • withdraw function that passes _pid and _amount and it requires that _pid is not equal to zero else returns an error message. The poolinfo is stored in the pool with the details of the specified id the userinfo is stored in the user with the user info of the given pid of the owner. It requires that the user’s amount should be greater than or equal to _maount else returns withdrawal error.

  • emergencyTransfer function passes the _pid: the Poolinfo is stored as pool and has poolinfo of given pid whereas userinfo is stored as a user with the userinfo of given pid of the respective owner

  • safeRigelTransfer function that passes address _to ad the given ammout its used in another functions with this contract the rigelBalance is equal to the balance of rigel of this address

  • dev function passes the _devaddr and the percentage it requires that the owner is equal to the devAdddr and the devaadr is reassigned to _devaddr then devPercentage equals to percentage

  • safeRigelWithdraw functions that passes the address to and the amount and can only be called by the owner. The rigelBalance equals to the balance of Rigel in a given address if the _amount to be withdrawn is greater than the rigelbalance is traffered to the owner else user gets transfer of exact amount they specified