Skip to content

Commit

Permalink
Fix/review contracts 398 (#403)
Browse files Browse the repository at this point in the history
* fix(env): use right endpoint

* fix(readme): use right url

* fix(contracts): admin now can approve payment after expiration and use XPR price from API

* fix(hapi): query XPR price directly instead of BTC

* chore(vscode): add cpp properties for Linux

* chore(contracts): install dependecies

* chore(vscode): add needed configuration
  • Loading branch information
Torresmorah committed Feb 13, 2023
1 parent 1aa6ffc commit 56919d8
Show file tree
Hide file tree
Showing 12 changed files with 3,079 additions and 309 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# contracts
CONTRACTS_NETWORK_API=https://proton-testnet.eosio.cr
CONTRACTS_NETWORK_API=https://proton-testnet.edenia.cloud
CONTRACTS_AFFILIATE_ACCOUNT=affiliate
CONTRACTS_AFFILIATE_PASSWORD=PW...
CONTRACTS_AFFILIATE_ACTIVE_PUBLIC_KEY=EOS...
Expand Down Expand Up @@ -27,7 +27,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090
# hapi
HAPI_SERVER_PORT=9090
HAPI_SERVER_ADDRESS=hapi
HAPI_NETWORK_API=https://proton-testnet.eosio.cr
HAPI_NETWORK_API=https://proton-testnet.edenia.cloud
HAPI_NETWORK_CHAIN_ID=71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd
HAPI_NETWORK_WALLET=http://wallet:9999
HAPI_HASURA_URL=http://hasura:8080/v1/graphql
Expand Down Expand Up @@ -56,7 +56,7 @@ REACT_APP_CHAIN_LOGO=https://test.earnproton.com/proton.png
REACT_APP_FOOTER_LINKS=[]
REACT_APP_UAL_APP_NAME=Proton Affiliate Program
REACT_APP_UAL_API_PROTOCOL=https
REACT_APP_UAL_API_HOST=proton-testnet.eosio.cr
REACT_APP_UAL_API_HOST=proton-testnet.edenia.cloud
REACT_APP_UAL_API_PORT=443
REACT_APP_UAL_CHAIN_ID=71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd
REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql
Expand Down
74 changes: 50 additions & 24 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/contracts/**",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/eosiolib/contracts/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/eosiolib/core/**"
],
"defines": ["uint128_t=__uint128_t", "int128_t=__int128_t"],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64",
"compilerArgs": [],
"browse": {
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/contracts/**",
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/eosiolib/contracts/**",
"/usr/local/opt/eosio.cdt/opt/eosio.cdt/include/eosiolib/core/**"
],
"defines": [
"uint128_t=__uint128_t",
"int128_t=__int128_t"
],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64",
"compilerArgs": [],
"browse": {
"limitSymbolsToIncludedHeaders": true
}
},
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/contracts/**",
"/usr/opt/eosio.cdt/1.8.1/include/**",
"/usr/opt/eosio.cdt/1.8.1/include/eosiolib/contracts/**",
"/usr/opt/eosio.cdt/1.8.1/include/eosiolib/core/**",
"/usr/opt/eosio.cdt/1.8.1/include/eosiolib/contracts/eosio/**"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
},
"compilerPath": "/usr/bin/clang-cpp-9"
}
],
"version": 4
}
12 changes: 9 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
"**/.pnp.*": true
},
"prettier.prettierPath": "./webapp/.yarn/sdks/prettier/index.js",
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"cSpell.enabled": true,
"cSpell.enableFiletypes": [
"markdown"
]
"cSpell.enableFiletypes": ["markdown"],
"[cpp]": {
"editor.defaultFormatter": "ms-vscode.cpptools",
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Within this repository you will find the following directories and files:

### EOSIO Blockchain Integration

This project is being developed on the [Proton Testnet](https://proton-testnet.eosio.online/) using the [`affiliate`](https://proton-test.bloks.io/account/affiliate) smart contract account. The backend service is currently using [EOS Costa Rica's testnet API Node](https://proton-testnet.eosio.cr/v1/chain/get_info)
This project is being developed on the [Proton Testnet](https://proton-testnet.antelope.tools/) using the [`affiliate`](https://testnet.protonscan.io/account/affiliate) smart contract account. The backend service is currently using [EOS Costa Rica's testnet API Node](https://proton-testnet.edenia.cloud/v1/chain/get_info)

We use the [EOS JS](https://github.com/EOSIO/eosjs) javascript API for integration with EOSIO-based blockchain networks using EOSIO RPC API.

Expand Down
6 changes: 3 additions & 3 deletions contracts/affiliate/affiliate.abi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.1",
"version": "eosio::abi/1.2",
"types": [],
"structs": [
{
Expand Down Expand Up @@ -226,7 +226,7 @@
"base": "",
"fields": [
{
"name": "btc_usdt",
"name": "xpr_usdt",
"type": "float64"
}
]
Expand Down Expand Up @@ -415,7 +415,7 @@
{
"name": "payref",
"type": "payref",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Pay referral\nsummary: This action pays the reward amount for a valid referral (status PENDING_PAYMENT and not expired).\nicon: https://earnproton.com/icons/approve.png\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Pay referral\nsummary: This action pays the reward amount for a valid referral (status PENDING_PAYMENT).\nicon: https://earnproton.com/icons/approve.png\n---"
},
{
"name": "rejectref",
Expand Down
Binary file modified contracts/affiliate/affiliate.wasm
Binary file not shown.
6 changes: 2 additions & 4 deletions contracts/affiliate/include/affiliate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CONTRACT affiliate : public contract {
* Pay referral.
*
* This action pay the reward amount for a valid referral
* (status PENDING_PAYMENT and not expired)
* (status PENDING_PAYMENT)
*
* @param admin - The name of the admin approving the referral
* @param invitee - The name of the invitee in the referral
Expand Down Expand Up @@ -170,7 +170,7 @@ CONTRACT affiliate : public contract {
*
* @return no return value.
*/
ACTION setrate(double btc_usdt);
ACTION setrate(double xpr_usdt);

/**
* Clear referrals
Expand Down Expand Up @@ -209,8 +209,6 @@ CONTRACT affiliate : public contract {
ACTION clear();

bool has_valid_kyc(name account);

double get_current_exchange_rate (double btc_usdt);

enum user_roles : uint8_t {
ADMIN = 1,
Expand Down
2 changes: 1 addition & 1 deletion contracts/affiliate/ricardian/affiliate.contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ icon: https://earnproton.com/icons/approve.png
---
spec_version: 0.1.0
title: Pay referral
summary: This action pays the reward amount for a valid referral (status PENDING_PAYMENT and not expired).
summary: This action pays the reward amount for a valid referral (status PENDING_PAYMENT).
icon: https://earnproton.com/icons/approve.png
---

Expand Down
33 changes: 4 additions & 29 deletions contracts/affiliate/src/affiliate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ ACTION affiliate::payref(name admin, name invitee) {
auto _referral = _referrals.find(invitee.value);
check(_referral != _referrals.end(), "referral with invitee " + invitee.to_string() + " does not exist");
check(_referral->status == referral_status::PENDING_PAYMENT, "invalid status for invitee " + invitee.to_string() + " referral");
check(_referral->expires_on > current_time_point(), "referral already expired for invitee " + invitee.to_string());

params_table _params(get_self(), get_self().value);
auto params_data = _params.get_or_create(get_self());
Expand Down Expand Up @@ -250,16 +249,15 @@ ACTION affiliate::setparams(name payer, double rate, double usd_reward_amount, u
_params.set(data, get_self());
}

ACTION affiliate::setrate(double btc_usdt) {
ACTION affiliate::setrate(double xpr_usdt) {
require_auth(get_self());

double rate = get_current_exchange_rate(btc_usdt);
check(rate > 0, "Invalid rate");
check(xpr_usdt > 0, "Invalid rate");

params_table _params(get_self(), get_self().value);
auto data = _params.get_or_create(get_self());
data.rate = rate;
data.asset_reward_amount = asset((data.usd_reward_amount / rate) * 10000, symbol("XPR", 4));
data.rate = xpr_usdt;
data.asset_reward_amount = asset((data.usd_reward_amount / xpr_usdt) * 10000, symbol("XPR", 4));
_params.set(data, get_self());
}

Expand Down Expand Up @@ -337,26 +335,3 @@ bool affiliate::has_valid_kyc (name account) {

return _userinfo->kyc.size() > 0;
}

double affiliate::get_current_exchange_rate (double btc_usdt) {
feeds_table _feedstable(name("oracles"), name("oracles").value);
data_table _data_table(name("oracles"), name("oracles").value);
uint64_t xpr_btc_index;

for (auto it = _feedstable.begin(); it != _feedstable.end(); it++)
{
if (it->name == "XPR/BTC") {
xpr_btc_index = it->index;
break;
}
}

auto xpr_btc_fee = _data_table.find(xpr_btc_index);

if (xpr_btc_fee == _data_table.end()) {
return 0;
}

return xpr_btc_fee->aggregate.d_double.value() * btc_usdt;
}

Loading

0 comments on commit 56919d8

Please sign in to comment.