Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
Include max_amount limits on deposit
Browse files Browse the repository at this point in the history
- Remove Defibox Oracle
- validate `max_amount`
- improve `min_amount` to validate full amount and not only the single deposit
- remove extra tables `transfers`, `status` & `chains` (can be replaced with Substreams)
- Add `-d DEBUG` flag to makefile
  • Loading branch information
DenisCarriere committed Oct 12, 2023
1 parent e28fabc commit c451031
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 392 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ all:

.PHONY: build
build:
cdt-cpp work.pomelo.cpp -I include
cdt-cpp work.pomelo.cpp -I include -D DEBUG

28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,17 @@ $ ./test.sh

- `{symbol} sym` - (primary key) symbol
- `{name} contract` - token contract
- `{uint64_t} min_amount` - min amount required when donating
- `{uint64_t} oracle_id` - Defibox Oracle ID
- `{uint64_t} min_amount` - min amount required per bounty
- `{uint64_t} max_amount` - max amount required per bounty

### example

```json
{
"sym": "4,USDT",
"contract": "tethertether",
"min_amount": 10000,
"oracle_id": 1
"min_amount": 50000,
"max_amount": 5000000
}
```

Expand Down Expand Up @@ -287,10 +287,10 @@ $ ./test.sh

### params

- `{name} status` - contract status: ok/testing/disabled
- `{uint64_t} fee` - platform fee (bips - 1/100 1%)
- `{name} login_contract` - EOSN Login contract
- `{name} fee_account` - fee account
- `{name} [status]` - contract status: ok/testing/disabled
- `{uint64_t} [fee]` - platform fee (bips - 1/100 1%)
- `{name} [login_contract]` - EOSN Login contract
- `{name} [fee_account]` - fee account
- `{set<name>} metadata_keys` - allowed metadata keys

### example
Expand All @@ -309,13 +309,13 @@ Set token as supported asset

- `{symbol} sym` - (primary key) symbol
- `{name} contract` - token contract
- `{uint64_t} min_amount` - min amount required when donating
- `{uint64_t} oracle_id` - Defibox oracle ID
- `{uint64_t} min_amount` - min amount required per bounty
- `{uint64_t} max_amount` - max amount required per bounty

### example

```bash
$ cleos push action work.pomelo token '["4,USDT", "tethertether", 10000, 1]' -p work.pomelo
$ cleos push action work.pomelo token '["4,USDT", "tethertether", 50000, 5000000]' -p work.pomelo
```

## ACTION `deltoken`
Expand All @@ -331,7 +331,7 @@ Delete token from supported assets
### example

```bash
$ cleos push action work.pomelo deltoken '["EOS"]' -p work.pomelo
$ cleos push action work.pomelo deltoken '["USDT"]' -p work.pomelo
```

## ACTION `create`
Expand All @@ -344,7 +344,7 @@ Create bounty

- `{name} author_user_id` - author (EOSN Login ID)
- `{name} bount_id` - bounty ID
- `{symbol_code} accepted_token` - accepted deposit token (ex: `"EOS"`)
- `{symbol_code} accepted_token` - accepted deposit token (ex: `"USDT"`)
- `{optional<name>} bounty_type` - bounty type (default = traditional)

### Example
Expand All @@ -368,7 +368,7 @@ Add/remove metadata. If key == "" - remove.
### example

```bash
$ cleos push action work.pomelo setmetadata '[bounty1, url, "https://github.com/pomelo-io"]' -p author.eosn
$ cleos push action work.pomelo setmetadata '[bounty1, url, "https://github.com/pomelo-io/pomelo-rest-api/issues/735"]' -p author.eosn
```

## ACTION `setstate`
Expand Down
99 changes: 0 additions & 99 deletions include/oracle.defi/oracle.defi.abi

This file was deleted.

23 changes: 0 additions & 23 deletions include/oracle.defi/oracle.defi.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions include/oracle.defi/oracle.defi.hpp

This file was deleted.

Binary file removed include/oracle.defi/oracle.defi.wasm
Binary file not shown.
8 changes: 2 additions & 6 deletions src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ void pomelo::cleartable( const name table_name, const optional<name> scope, cons
const uint64_t value = scope ? scope->value : get_self().value;

// tables
pomelo::transfers_table _transfers( get_self(), value );
pomelo::bounties_table _bounties( get_self(), value );
pomelo::configs_table _configs( get_self(), value );
pomelo::tokens_table _tokens( get_self(), value );
pomelo::status_table _status( get_self(), value );
pomelo::configs_table _configs( get_self(), value );

if (table_name == "transfers"_n) clear_table( _transfers, rows_to_clear );
else if (table_name == "bounties"_n) clear_table( _bounties, rows_to_clear );
if (table_name == "bounties"_n) clear_table( _bounties, rows_to_clear );
else if (table_name == "tokens"_n) clear_table( _tokens, rows_to_clear );
else if (table_name == "configs"_n) _configs.remove();
else if (table_name == "status"_n) _status.remove();
else check(false, "pomelo::cleartable: [table_name] unknown table to clear" );
}
7 changes: 0 additions & 7 deletions src/getters.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <oracle.defi/oracle.defi.hpp>
#include <eosio/transaction.hpp>
#include <eosio/crypto.hpp>
#include <utils/utils.hpp>
Expand Down Expand Up @@ -63,12 +62,6 @@ bool pomelo::is_token_enabled( const symbol_code symcode )
return itr != _tokens.end();
}

double pomelo::calculate_value( const extended_asset ext_quantity )
{
const auto& token = get_token( ext_quantity );
return defi::oracle::get_value( ext_quantity, token.oracle_id );
}

name pomelo::get_user_id( const name account )
{
const name login_contract = get_configs().login_contract;
Expand Down
35 changes: 9 additions & 26 deletions src/notifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ void pomelo::deposit_bounty( const name bounty_id, const name user_id, const nam

const asset quantity = ext_quantity.quantity;
const symbol_code symcode = quantity.symbol.code();
const int64_t min_amount = get_token( ext_quantity ).min_amount;
const auto token = get_token( ext_quantity );
const int64_t min_amount = token.min_amount;
const int64_t max_amount = token.max_amount;
const name funder_user_id = user_id.value ? user_id : bounty->author_user_id; //if no user id specified - assume it came from the author

// validate incoming transfer
check( quantity.amount >= min_amount, "pomelo::deposit_bounty: [quantity=" + ext_quantity.quantity.to_string() + "] is less than [tokens.min_amount=" + to_string( min_amount ) + "]");

// TO-DO: bounty can only deposit when state == "pending/open/started"
check( STATUS_DEPOSIT_TYPES.find(bounty->status) != STATUS_DEPOSIT_TYPES.end(), "pomelo::deposit_bounty: bounty not available for funding");

Expand All @@ -45,7 +44,7 @@ void pomelo::deposit_bounty( const name bounty_id, const name user_id, const nam
// calculate fee
const extended_asset fee = calculate_fee( ext_quantity );
const extended_asset amount = ext_quantity - fee;
double value = calculate_value( amount );
const double value = utils::asset_to_double(amount.quantity);
print("\n", amount, " == ", value);

// update bounty deposit
Expand All @@ -55,29 +54,13 @@ void pomelo::deposit_bounty( const name bounty_id, const name user_id, const nam
row.amount += amount;
row.fee += fee;
row.updated_at = current_time_point();
});

// save for logging purposes
save_transfer( bounty_id, funder_user_id, from, get_self(), amount, fee.quantity, memo, value );
// validate deposit min & max amounts
const int64_t total = row.amount.quantity.amount;
check( total >= min_amount, "pomelo::deposit_bounty: [quantity=" + ext_quantity.quantity.to_string() + "] is less than [tokens.min_amount=" + to_string( min_amount ) + "]");
check( total <= max_amount, "pomelo::deposit_bounty: [quantity=" + ext_quantity.quantity.to_string() + "] is greater than [tokens.max_amount=" + to_string( max_amount ) + "]");
});

pomelo::depositlog_action depositlog( get_self(), { get_self(), "active"_n });
depositlog.send( bounty_id, funder_user_id, from, amount, fee.quantity, value, memo );
}

void pomelo::save_transfer( const name bounty_id, const name funder_user_id, const name from, const name to, const extended_asset ext_quantity, const asset fee, const string& memo, const double value )
{
pomelo::transfers_table _transfers( get_self(), get_self().value );
_transfers.emplace( get_self(), [&]( auto & row ) {
row.transfer_id = _transfers.available_primary_key();
row.bounty_id = bounty_id;
row.funder_user_id = funder_user_id;
row.from = from;
row.to = to;
row.ext_quantity = ext_quantity;
row.fee = fee;
row.memo = memo;
row.value = value;
row.trx_id = get_trx_id();
row.created_at = current_time_point();
});
}
Loading

0 comments on commit c451031

Please sign in to comment.