Alcor
Search…
Contract Tables
Alcor contract tables structure for contracts communication.

Markets

1
struct[[eosio::table]] market {
2
uint64_t id;
3
4
extended_symbol base_token;
5
extended_symbol quote_token;
6
7
asset min_buy;
8
asset min_sell;
9
10
bool frozen = false;
11
12
uint8_t fee = 0;
13
14
uint64_t primary_key() const { return id; }
15
checksum256 get_secondary_1() const {
16
return make256key(
17
quote_token.get_contract().value,
18
quote_token.get_symbol().code().raw(),
19
base_token.get_contract().value,
20
base_token.get_symbol().code().raw()
21
);
22
}
23
24
string get_market_symbol() const {
25
return quote_token.get_symbol().code().to_string() + "/" + base_token.get_symbol().code().to_string();
26
}
27
};
28
29
typedef eosio::multi_index<"markets"_n, market,
30
indexed_by<"bytokens"_n, const_mem_fun<market, checksum256, &market::get_secondary_1 >
31
> > markets_index;
32
33
34
// Helper function for market 256 id
35
36
uint128_t make128key(uint64_t a, uint64_t b) {
37
uint128_t aa = a;
38
uint128_t bb = b;
39
return (aa << 64) + bb;
40
}
41
42
checksum256 make256key(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
43
if (make128key(a, b) < make128key(c, d))
44
return checksum256::make_from_word_sequence < uint64_t > (a, b, c, d);
45
else
46
return checksum256::make_from_word_sequence < uint64_t > (c, d, a, b);
47
}
Copied!

Order

in contract it's two same structure tables: buyorder and sellorder
1
struct [[eosio::table]] sellorder {
2
uint64_t id;
3
name account;
4
asset bid;
5
asset ask;
6
uint128_t unit_price;
7
uint32_t timestamp;
8
9
uint64_t primary_key() const { return id; }
10
uint64_t get_account() const { return account.value; }
11
};
12
13
typedef eosio::multi_index< "buyorder"_n, buyorder,
14
indexed_by<"byprice"_n, const_mem_fun<buyorder, uint128_t, &buyorder::get_price> >,
15
indexed_by<"byaccount"_n, const_mem_fun<buyorder, uint64_t, &buyorder::get_account> >
16
> buyorders_t;
17
18
Copied!

Swap liquidity pool Pairs table

1
struct[[eosio::table]] pairs_struct {
2
uint64_t id;
3
4
asset supply;
5
extended_asset pool1;
6
extended_asset pool2;
7
8
int fee;
9
name fee_contract;
10
11
uint64_t primary_key() const {
12
return id;
13
}
14
15
checksum256 secondary_key() const {
16
return make256key( // this function can be find in markets table example above.
17
pool1.contract.value, pool1.quantity.symbol.code().raw(),
18
pool2.contract.value, pool2.quantity.symbol.code().raw()
19
);
20
}
21
};
22
23
typedef eosio::multi_index< "pairs"_n, pairs_struct,
24
indexed_by<"extended"_n, const_mem_fun<pairs_struct, checksum256,
25
&pairs_struct::secondary_key>> > pairs_index;
Copied!
Last modified 3mo ago
Copy link
Contents