Skip to content

Instantly share code, notes, and snippets.

View danlessa's full-sized avatar

Danilo Lessa Bernardineli danlessa

View GitHub Profile
@danlessa
danlessa / neural_governance_tally.py
Created September 18, 2023 20:43
Example implementation of Neural Governance based vote tallying
# 1) Types
# Neuron Governance Types
Weight = callable[[VotingPower], VotingPower]
OracleFunction = callable[[UserUUID, ProjectUUID], VotingPower]
VoteNeuron = tuple[OracleFunction, Weight]
Aggregator = callable[[list[VotingPower]], Voting Power]
UserAction = tuple[str, object]
UserActions = dict[UserUUID, UserAction]
@danlessa
danlessa / neural_governance.py
Created September 18, 2023 20:39
Neural Governance Example
OracleFunction = callable[[UserUUID, ProjectUUID, VotingPower], VotingPower]
WeightingFunction = callable[[VotingPower], VotingPower]
Neuron = tuple[OracleFunction, WeightingFunction]
LayerAggregator = callable[[list[VotingPower]], VotingPower]
NeuronLayer = tuple[dict[str, Neuron], LayerAggregator]
# Attribute Voting Power to a (user, project) tuple
def user_project_vote_power(uid: UserUUID,
pid: ProjectUUID,
neuron_layers: list[NeuronLayer],
@danlessa
danlessa / quorum_delegation.py
Created September 18, 2023 20:31
Example Implementation of Quorum Delegation
def query_user_quorum(user_id: UserUUID,
max_quorum_size: int=5) -> list[UserUUID]:
"""
Retrieves the Actual Quorum for a given delegating user.
Returns `None` if the User is not delegating.
"""
(action, payload) = USER_ACTIONS[user_id]
actual_quorum = None
if action == Action.Delegate:
did:3:kjzl6cwe1jw147ja5vzh9n36sxucppsuab0llr6fpip1dtj21cpywdmxoyqz2nj
@danlessa
danlessa / arbing_amms.py
Last active January 15, 2021 22:25
Arbing AMMs impl
# Based on https://hackmd.io/@markusbkoch/SyfNfQURw
from math import sqrt
def swap(y_1, Y_1, Y_2, sigma):
y_2 = Y_2 * y_1 * (1 - sigma)
y_2 /= Y_1 + 2 * y_1 * (1 - sigma)
return y_2
def arbitrage(x_1, P_x, P_z, rho_1, sigma_x, sigma_z, c, K_x, K_z, g_x, g_z):
@danlessa
danlessa / arbing_amms.py
Created January 15, 2021 21:41
Impl of Arbing AMMs
from math import sqrt
def swap(x_1, P, K, sigma):
X_1 = sqrt(P * K)
X_2 = sqrt(K / P)
y = X_2 * x_1 * (1 - sigma)
y /= X_1 + 2 * x_1 * (1 - sigma)
return y
# Parameters for AMM 1

Keybase proof

I hereby claim:

  • I am danlessa on github.
  • I am danlessa (https://keybase.io/danlessa) on keybase.
  • I have a public key ASDeqKRSXRYCY79cmTtz829Ms0wZ6BbnZS8YRkcY2A2h1Ao

To claim this, I am signing this object:

# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@danlessa
danlessa / atom.gist
Created December 11, 2018 18:15
atom
#