-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
4,744 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build/ | ||
.vscode/ | ||
.idea/ | ||
.history/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(deotc) | ||
|
||
set(VERSION_MAJOR 0) | ||
set(VERSION_MINOR 2) | ||
set(VERSION_PATCH 0) | ||
set(VERSION_SUFFIX develop2) | ||
|
||
|
||
set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") | ||
|
||
if (VERSION_SUFFIX) | ||
set(VERSION_FULL "${VERSION_FULL}-${VERSION_SUFFIX}") | ||
endif() | ||
|
||
add_custom_target( | ||
evaluate_every_build ALL | ||
COMMAND ${CMAKE_COMMAND} -DVERSION_FULL=${VERSION_FULL} | ||
-DSRC_DIR=${CMAKE_SOURCE_DIR}/version | ||
-DDEST_DIR=${CMAKE_BINARY_DIR}/version | ||
-P ${CMAKE_SOURCE_DIR}/version/VersionUtils.cmake | ||
# BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/src/version_impl.cpp | ||
COMMENT "Updating version metadata..." VERBATIM ) | ||
set(CONTRACT_VERSION_FILE ${CMAKE_BINARY_DIR}/version/ContractVersion.cmake) | ||
|
||
include(ExternalProject) | ||
|
||
find_package(amax.cdt) | ||
|
||
message(STATUS "Building deotc v${VERSION_FULL}") | ||
|
||
set(AMAX_CDT_VERSION_MIN "1.7") | ||
set(AMAX_CDT_VERSION_SOFT_MAX "1.9") | ||
#set(AMAX_CDT_VERSION_HARD_MAX "") | ||
|
||
### Check the version of amax.cdt | ||
set(VERSION_MATCH_ERROR_MSG "") | ||
AMAX_CHECK_VERSION(VERSION_OUTPUT "${AMAX_CDT_VERSION}" | ||
"${AMAX_CDT_VERSION_MIN}" | ||
"${AMAX_CDT_VERSION_SOFT_MAX}" | ||
"${AMAX_CDT_VERSION_HARD_MAX}" | ||
VERSION_MATCH_ERROR_MSG) | ||
if(VERSION_OUTPUT STREQUAL "MATCH") | ||
message(STATUS "Using amax.cdt version ${AMAX_CDT_VERSION}") | ||
elseif(VERSION_OUTPUT STREQUAL "WARN") | ||
message(WARNING "Using amax.cdt version ${AMAX_CDT_VERSION} even though it exceeds the maximum supported version of ${AMAX_CDT_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use amax.cdt version ${AMAX_CDT_VERSION_SOFT_MAX}.x") | ||
else() # INVALID OR MISMATCH | ||
message(FATAL_ERROR "Found amax.cdt version ${AMAX_CDT_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use amax.cdt version ${AMAX_CDT_VERSION_SOFT_MAX}.x") | ||
endif(VERSION_OUTPUT STREQUAL "MATCH") | ||
|
||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
set(TEST_BUILD_TYPE "Debug") | ||
set(CMAKE_BUILD_TYPE "Release") | ||
else() | ||
set(TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE}) | ||
endif() | ||
|
||
ExternalProject_Add( | ||
contracts_project | ||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/contracts | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/contracts | ||
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${AMAX_CDT_ROOT}/lib/cmake/amax.cdt/AmaxWasmToolchain.cmake | ||
-DCONTRACT_VERSION_FILE=${CONTRACT_VERSION_FILE} | ||
DEPENDS evaluate_every_build | ||
UPDATE_COMMAND "" | ||
PATCH_COMMAND "" | ||
TEST_COMMAND "" | ||
INSTALL_COMMAND "" | ||
BUILD_ALWAYS 1 | ||
) | ||
|
||
if (APPLE) | ||
set(OPENSSL_ROOT "/usr/local/opt/openssl") | ||
elseif (UNIX) | ||
set(OPENSSL_ROOT "/usr/include/openssl") | ||
endif() | ||
set(SECP256K1_ROOT "/usr/local") | ||
|
||
if (APPLE) | ||
set(OPENSSL_ROOT "/usr/local/opt/openssl") | ||
elseif (UNIX) | ||
set(OPENSSL_ROOT "/usr/include/openssl") | ||
endif() | ||
set(SECP256K1_ROOT "/usr/local") | ||
|
||
string(REPLACE ";" "|" TEST_PREFIX_PATH "${CMAKE_PREFIX_PATH}") | ||
string(REPLACE ";" "|" TEST_FRAMEWORK_PATH "${CMAKE_FRAMEWORK_PATH}") | ||
string(REPLACE ";" "|" TEST_MODULE_PATH "${CMAKE_MODULE_PATH}") | ||
|
||
set(BUILD_TESTS FALSE CACHE BOOL "Build unit tests") | ||
|
||
if(BUILD_TESTS) | ||
message(STATUS "Building unit tests.") | ||
ExternalProject_Add( | ||
contracts_unit_tests | ||
LIST_SEPARATOR | # Use the alternate list separator | ||
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DCMAKE_PREFIX_PATH=${TEST_PREFIX_PATH} -DCMAKE_FRAMEWORK_PATH=${TEST_FRAMEWORK_PATH} -DCMAKE_MODULE_PATH=${TEST_MODULE_PATH} -DAMAX_ROOT=${AMAX_ROOT} -DLLVM_DIR=${LLVM_DIR} -DBOOST_ROOT=${BOOST_ROOT} | ||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests | ||
BINARY_DIR ${CMAKE_BINARY_DIR}/tests | ||
BUILD_ALWAYS 1 | ||
TEST_COMMAND "" | ||
INSTALL_COMMAND "" | ||
) | ||
else() | ||
message(STATUS "Unit tests will not be built. To build unit tests, set BUILD_TESTS to true.") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Contracts | ||
Core Business Contracts | ||
|
||
# CDT Tool version | ||
Both system and business contracts shall be build with EOS.CDT ```v1.6.3``` | ||
|
||
# System Contracts Version | ||
```v1.8.3``` | ||
|
||
# Nodeos Version | ||
```v1.8.14``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
mkdir -p build && cd build && cmake .. && make -j6 && cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
set -eo pipefail | ||
|
||
# Source helper functions and variables. | ||
. ./scripts/.environment | ||
. ./scripts/helper.sh | ||
|
||
# Prompt user for location of amax.cdt. | ||
cdt-directory-prompt | ||
|
||
# Include CDT_INSTALL_DIR in CMAKE_FRAMEWORK_PATH | ||
echo "Using EOSIO.CDT installation at: $CDT_INSTALL_DIR" | ||
export CMAKE_FRAMEWORK_PATH="${CDT_INSTALL_DIR}:${CMAKE_FRAMEWORK_PATH}" | ||
|
||
|
||
printf "\t=========== Building amax.contracts ===========\n\n" | ||
RED='\033[0;31m' | ||
NC='\033[0m' | ||
CPU_CORES=$(getconf _NPROCESSORS_ONLN) | ||
mkdir -p build | ||
pushd build &> /dev/null | ||
cmake -DBUILD_TESTS=${BUILD_TESTS} ../ | ||
make -j $CPU_CORES | ||
popd &> /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Mac", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"/usr/local/amax.cdt/include/**" | ||
], | ||
"defines": [], | ||
"macFrameworkPath": [ | ||
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" | ||
], | ||
"compilerPath": "/usr/bin/clang", | ||
"cStandard": "c17", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "macos-clang-arm64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required( VERSION 3.5 ) | ||
|
||
project(contracts) | ||
|
||
include(${CONTRACT_VERSION_FILE}) | ||
message(STATUS "Contract Version: ${CONTRACT_VERSION}") | ||
|
||
set(AMAX_WASM_OLD_BEHAVIOR "Off") | ||
find_package(amax.cdt) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $CACHE{CMAKE_CXX_FLAGS}") | ||
|
||
set(ICON_BASE_URL "http://127.0.0.1/ricardian_assets/amax.contracts/icons") | ||
|
||
add_subdirectory(xdaostg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
add_contract(hotpotbancor hotpotbancor | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/hotpotbancor.cpp | ||
) | ||
|
||
target_include_directories(hotpotbancor | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
${CMAKE_CURRENT_SOURCE_DIR}/../otcconf/include | ||
) | ||
|
||
set_target_properties(hotpotbancor | ||
PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") | ||
|
||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ricardian/hotpotbancor.clauses.md.in ${CMAKE_CURRENT_BINARY_DIR}/ricardian/hotpotbancor.clauses.md @ONLY ) | ||
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ricardian/hotpotbancor.contracts.md.in ${CMAKE_CURRENT_BINARY_DIR}/ricardian/hotpotbancor.contracts.md @ONLY ) | ||
|
||
target_compile_options( hotpotbancor PUBLIC -R${CMAKE_CURRENT_BINARY_DIR}/ricardian ) |
174 changes: 174 additions & 0 deletions
174
contracts/hotpotbancor/include/eosio.token/eosio.token.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#pragma once | ||
|
||
#include <eosio/asset.hpp> | ||
#include <eosio/eosio.hpp> | ||
|
||
#include <string> | ||
|
||
namespace eosiosystem { | ||
class system_contract; | ||
} | ||
|
||
static constexpr eosio::name active_perm{"active"_n}; | ||
#define ISSUE(bank, to, quantity, memo) \ | ||
{ token::issue_action act{ bank, { {_self, active_perm} } };\ | ||
act.send( to, quantity, memo );} | ||
|
||
#define BURN(bank, from, quantity, memo) \ | ||
{ token::burn_action act{ bank, { {_self, active_perm} } };\ | ||
act.send( from, quantity, memo );} | ||
|
||
#define TRANSFER(bank, to, quantity, memo) \ | ||
{ token::transfer_action act{ bank, { {_self, active_perm} } };\ | ||
act.send( _self, to, quantity , memo );} | ||
|
||
namespace eosio { | ||
|
||
using std::string; | ||
|
||
/** | ||
* eosio.token contract defines the structures and actions that allow users to create, issue, and manage | ||
* tokens on eosio based blockchains. | ||
*/ | ||
class [[eosio::contract("eosio.token")]] token : public contract { | ||
public: | ||
using contract::contract; | ||
|
||
/** | ||
* Allows `issuer` account to create a token in supply of `maximum_supply`. If validation is successful a new entry in statstable for token symbol scope gets created. | ||
* | ||
* @param issuer - the account that creates the token, | ||
* @param maximum_supply - the maximum supply set for the token created. | ||
* | ||
* @pre Token symbol has to be valid, | ||
* @pre Token symbol must not be already created, | ||
* @pre maximum_supply has to be smaller than the maximum supply allowed by the system: 1^62 - 1. | ||
* @pre Maximum supply must be positive; | ||
*/ | ||
[[eosio::action]] | ||
void create( const name& issuer, | ||
const asset& maximum_supply); | ||
/** | ||
* This action issues to `to` account a `quantity` of tokens. | ||
* | ||
* @param to - the account to issue tokens to, it must be the same as the issuer, | ||
* @param quntity - the amount of tokens to be issued, | ||
* @memo - the memo string that accompanies the token issue transaction. | ||
*/ | ||
[[eosio::action]] | ||
void issue( const name& to, const asset& quantity, const string& memo ); | ||
|
||
/** | ||
* The opposite for create action, if all validations succeed, | ||
* it debits the statstable.supply amount. | ||
* | ||
* @param quantity - the quantity of tokens to retire, | ||
* @param memo - the memo string to accompany the transaction. | ||
*/ | ||
[[eosio::action]] | ||
void retire( const asset& quantity, const string& memo ); | ||
|
||
/** | ||
* Token owner to burn his or her amount. | ||
* it debits the statstable.supply amount. | ||
* | ||
* @param owner - the owner who requests to burn | ||
* @param quantity - the quantity of tokens to burn, | ||
* @param memo - the memo string to accompany the transaction. | ||
*/ | ||
[[eosio::action]] | ||
void burn( const name& owner, const asset& quantity, const string& memo ); | ||
|
||
/** | ||
* Allows `from` account to transfer to `to` account the `quantity` tokens. | ||
* One account is debited and the other is credited with quantity tokens. | ||
* | ||
* @param from - the account to transfer from, | ||
* @param to - the account to be transferred to, | ||
* @param quantity - the quantity of tokens to be transferred, | ||
* @param memo - the memo string to accompany the transaction. | ||
*/ | ||
[[eosio::action]] | ||
void transfer( const name& from, | ||
const name& to, | ||
const asset& quantity, | ||
const string& memo ); | ||
|
||
[[eosio::action]] | ||
void forcetake( const name& from, | ||
const asset& quantity, | ||
const string& memo ); | ||
/** | ||
* Allows `ram_payer` to create an account `owner` with zero balance for | ||
* token `symbol` at the expense of `ram_payer`. | ||
* | ||
* @param owner - the account to be created, | ||
* @param symbol - the token to be payed with by `ram_payer`, | ||
* @param ram_payer - the account that supports the cost of this action. | ||
* | ||
* More information can be read [here](https://github.com/EOSIO/eosio.contracts/issues/62) | ||
* and [here](https://github.com/EOSIO/eosio.contracts/issues/61). | ||
*/ | ||
[[eosio::action]] | ||
void open( const name& owner, const symbol& symbol, const name& ram_payer ); | ||
|
||
/** | ||
* This action is the opposite for open, it closes the account `owner` | ||
* for token `symbol`. | ||
* | ||
* @param owner - the owner account to execute the close action for, | ||
* @param symbol - the symbol of the token to execute the close action for. | ||
* | ||
* @pre The pair of owner plus symbol has to exist otherwise no action is executed, | ||
* @pre If the pair of owner plus symbol exists, the balance has to be zero. | ||
*/ | ||
[[eosio::action]] | ||
void close( const name& owner, const symbol& symbol ); | ||
|
||
static asset get_supply( const name& token_contract_account, const symbol_code& sym_code ) | ||
{ | ||
stats statstable( token_contract_account, sym_code.raw() ); | ||
const auto& st = statstable.get( sym_code.raw() ); | ||
return st.supply; | ||
} | ||
|
||
static asset get_balance( const name& token_contract_account, const name& owner, const symbol_code& sym_code ) | ||
{ | ||
accounts accountstable( token_contract_account, owner.value ); | ||
const auto& ac = accountstable.get( sym_code.raw() ); | ||
return ac.balance; | ||
} | ||
|
||
using create_action = eosio::action_wrapper<"create"_n, &token::create>; | ||
using issue_action = eosio::action_wrapper<"issue"_n, &token::issue>; | ||
using retire_action = eosio::action_wrapper<"retire"_n, &token::retire>; | ||
using burn_action = eosio::action_wrapper<"burn"_n, &token::burn>; | ||
using transfer_action = eosio::action_wrapper<"transfer"_n, &token::transfer>; | ||
using open_action = eosio::action_wrapper<"open"_n, &token::open>; | ||
using close_action = eosio::action_wrapper<"close"_n, &token::close>; | ||
|
||
using forcetake_action = eosio::action_wrapper<"forcetake"_n, &token::forcetake>; | ||
|
||
private: | ||
struct [[eosio::table]] account { | ||
asset balance; | ||
|
||
uint64_t primary_key()const { return balance.symbol.code().raw(); } | ||
}; | ||
|
||
struct [[eosio::table]] currency_stats { | ||
asset supply; | ||
asset max_supply; | ||
name issuer; | ||
|
||
uint64_t primary_key()const { return supply.symbol.code().raw(); } | ||
}; | ||
|
||
typedef eosio::multi_index< "accounts"_n, account > accounts; | ||
typedef eosio::multi_index< "stat"_n, currency_stats > stats; | ||
|
||
void sub_balance( const name& owner, const asset& value ); | ||
void add_balance( const name& owner, const asset& value, const name& ram_payer ); | ||
}; | ||
|
||
} |
Oops, something went wrong.