Skip to content

deplant/contracts-common

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Common Contracts

This repository stores common contracts made by Deplant.

STD

Library with common functions (only internal and mostly inlined), modifiers, constants, rules and strategies.

Floor & Reserve Gas Management Strategy

Gas Management - abstract contract with internal functions & modifiers for gas management strategy where you always reserve a certain amount of gas on your contract and return all EVERs above this floor to contract's counterparties.

Contract has one virtual function $gasFloor() that you need to override like this:

function $gasFloor() override internal inline view returns (uint128 gasAmount) {
    return DEFAULT_GAS_FLOOR;
}

DEFAULT_GAS_FLOOR is 25000 gas. You can specify your own value for floor. All functions and modifiers will use this gas floor.

Typical usage of modifiers is:

function publishCustomTask() external view internalMsg reserveGas returnAllUnreserved {
 // reserveGas() modifier will reserve gas floor at the beginning
 // returnAllUnreserved() modifier will return all extra gas to sender at the end
}

address _owner;

function publishCustomTask() external view internalMsg reserveGasExactly(25_000) returnAllUnreservedTo(_ownerAddress) {
 // reserveGasExactly(25_000) modifier will reserve 25000 gas as a floor
 // returnAllUnreservedTo(_ownerAddress) modifier will return all extra gas to address variable _owner
}

Ownership

Abstract contracts to help with ownership management.

Math

Math Library contains a lot of useful Solidity math (sorts, averages, price convertations), still, it's not final and not for everyone, so use it as a copy/paste source.

Constants

These are constants that are used by everyone & everywhere:

  • Errors - common exception constants for almost any contract
  • Flags - common flag constants for message transfers & gas reserve

Extensions

Address Type Extension contains various useful functions for extending Address type.

TvmCell Type Extension contains various useful functions for extending TvmCell type.

Releases

No releases published

Packages

No packages published