tg4-mixer

Crates.iotg4-mixer
lib.rstg4-mixer
version0.17.1
sourcesrc
created_at2022-01-17 15:19:12.278793
updated_at2023-01-26 12:21:36.510898
descriptionTG4 implementation that combines two different groups with a merge function
homepagehttps://tgrade.finance
repositoryhttps://github.com/confio/poe-contracts
max_upload_size
id515625
size126,634
Developers (github:confio:developers)

documentation

README

TG4 Mixer

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.

Init

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,
}

Mixing Function

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.

Updates

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.

Benchmarking

cd contracts/tg4-mixer
cargo bench --features benches
Commit count: 698

cargo fmt