Crates.io | tg4-mixer |
lib.rs | tg4-mixer |
version | 0.17.1 |
source | src |
created_at | 2022-01-17 15:19:12.278793 |
updated_at | 2023-01-26 12:21:36.510898 |
description | TG4 implementation that combines two different groups with a merge function |
homepage | https://tgrade.finance |
repository | https://github.com/confio/poe-contracts |
max_upload_size | |
id | 515625 |
size | 126,634 |
This mixes two tg4 contracts.
On init, you pass addresses to two tg4 contracts, and this one will
register a listening hook on both. Following that, it will query both
for their current state and use a mixing function to calculate the combined value.
(We currently implement/optimized it with the assumption that None
points in
either upstream group means a None
points in this group)
Every time one of the upstream contracts changes, it will use the mixing function again to recalculate the combined points of the affected addresses.
Apart from tg4, both upstream contracts need to implement the slashing API.
To create it, you must pass in the two groups you want to listen to. We must be pre-authorized to self-register as a hook listener on both of them.
pub struct InitMsg {
pub left_group: String,
pub right_group: String,
}
As mentioned above, we optimize for the case where None
on either
contract leads to None
in the combined group. This is especially used
for the initialization.
A number of mixing functions are implemented:
GeometricMean
. A simple geometric mean of left
and right
.Sigmoid
. A sigmoid-like function like the one discussed in the PoE whitepaper.SigmoidSqrt
. A variant of the above, with a p = 0.5
, and implemented using GeometricSigmoid
.AlgebraicSigmoid
. An algebraic sigmoid modelled after Sigmoid
.Basic messages, queries, and hooks are defined by the tg4 spec. Please refer to it for more info.
We just add ExecuteMsg::MemberChangedHook
to listen for changes on the
upstream contracts.
cd contracts/tg4-mixer
cargo bench --features benches