icdevsorg / axon

DAO in a box
https://icdevs.org/
Other
12 stars 8 forks source link
dao internet-computer motoko

The function of the axon is to transmit information to different neurons - Wikipedia


Axon is a multi-user, multi-neuron management canister.

This repo is a fork of the original Axon project, created and sponsored by ICDevs.org.

Overview

Admins

Only Admins can create new Axons. The Admin role can be granted to or removed from principals only by the Master Admin. The Master Admin is the principle that deploys the parent Axon dapp canister.

You may want to add your wallet principal:

dfx canister --network ic call Axon add_admin '(principal "k3gvh-4fgvt-etjfk-dfpfc-we5bp-cguw5-6rrao-65iwb-ttim7-tt3bc-6qe")'

Deploying Axon dapp

(Principal of deploying identity becomes Master Admin)

Deploy an Axon dapp :

cd src/axon-ui

Follow the instructions to add the Psycadelic context as a github package registry: https://github.com/Psychedelic/plug-inpage-provider#-installation

npm i npm run build

```sh
npm run export
cd ../..
dfx deploy --network ic

Deploying a child Axon

(must be an Admin)

Deploy an Axon canister:

dfx deploy Axon --argument 'record {owner= (principal "your-principal-here"); visibility= variant{Public}}'

Testing locally

(Principal of deploying identity becomes Master Admin)

Deploy an Axon dapp :

cd src/axon-ui

Follow the instructions to add the Psycadelic context as a github package registry: https://github.com/Psychedelic/plug-inpage-provider#-installation

npm i npm run build_local

```sh
npm run export_local
cd ../..
dfx deploy --network local

Currently, canisters cannot control neurons. It is only possible to add the Axon canister as a hot key for neurons, so only commands like Follow and RegisterVote will succeed.

Documentation for Axon.mo

Public queries

is_admin(p: Principal): async Bool

Checks if the specified principal is an admin on the axon head canister.

Parameters

Returns

get_admins(): async Array<Principal>

Returns a list of all the admins.

Returns

count(): async Nat

Retrieves the number of axons.

Returns

topAxons(): async Array<AxonPublic>

Retrieves the top axons based on their total stake.

Returns

axonById(id: Nat): async AxonPublic

Retrieves the public information of an axon by ID.

Parameters

Returns

axonByWallet(id: Principal): async ?AxonPublic

Retrieves the public information of an axon by wallet address. You can use this if you know your Axon Proxy and want to find the axon id that controls that proxy.

Parameters

Returns

axonStatusById(id: Nat): async CanisterStatusResult

Retrieves the status of an axon by ID.

Parameters

Returns

getNeuronIds(id: Nat): async Array<Nat64>

Retrieves the neuron IDs associated with an axon.

Parameters

Returns

balanceOf(id: Nat, principal: ?Principal): async Nat

Retrieves the balance for a principal on a given axon for a specific principal or caller.

Parameters

Returns

ledger(id: Nat): async Array<LedgerEntry>

Retrieves the ledger entries of an axon by ID.

Parameters

Returns

myAxons(): async Array<AxonPublic>

Retrieves the axons where the caller has a non-zero balance.

Returns

getNeurons(id: Nat): async NeuronsResult

Retrieves the neurons associated with an axon.

Parameters

Returns

getProposalById(axonId: Nat, proposalId: Nat): async Result<AxonProposalPublic>

Retrieves a single proposal by ID.

Parameters

Returns

getActiveProposals(id: Nat): async ProposalResult

Retrieves all active proposals of an axon.

Parameters

Returns

getAllProposals(id: Nat, before: ?Nat): async ProposalResult

Retrieves the last 100 proposals of an axon, optionally before the specified ID.

Parameters

Returns

getMotionProposals(id: Nat): async ProposalResult

Retrieves all motion proposals of an axon.

Parameters

Returns

Public Updates

add_admin(p: Principal): async void

Adds the specified principal as an admin.

Parameters

cycles(): async Nat

Retrieves the current balance of cycles.

Returns

updateSettings(canisterId: Principal, manager: Principal): async void

Updates the controller of an axon. This is needed for deletion purposes.

Parameters

update_master(p: Principal): async void

Changes the master.

Parameters

remove_admin(p: Principal): async void

Removes the specified principal as an admin.

Parameters

private _mint(caller: Principal, axonId: Nat, p: Principal, a: Nat): async* Result<AxonCommandExecution>

Mints a specified amount of tokens for a recipient. Creates the equivalent of an mint proposal and executes it. You must have a minting privileges. A message will be sent to the proxy wallet to actually mint the tokens and then the proxy will update the balance on the Axon head.

Parameters

Returns

mint(axonId: Nat, p: Principal, a: Nat): async Result<AxonCommandExecution>

Mints a specified amount of tokens for a recipient. Must be the minting canister or principal

Parameters

Returns

mint_batch(request: Array<[Nat, Principal, Nat]>): async Array<[(Nat, Principal, Nat), Result<AxonCommandExecution>]>

Mints a batch of tokens for multiple recipients.

Parameters

Returns

burn(axonId: Nat, p: Principal, a: Nat): async Result<AxonCommandExecution>

Burns a specified amount of tokens owned by a recipient. Burns must be allowed. A message will be sent to the proxy to burn the tokens. Balance will be updated by the proxy wallet if the burn is allowed.

Parameters

Returns

burn_batch(request: Array<[Nat, Principal, Nat]>): async Array<[(Nat, Principal, Nat), Result<AxonCommandExecution>]>

Burns a batch of tokens owned by multiple recipients.

Parameters

Returns

upgradeProxy(): async Array<Result<Bool, Text>>

Upgrades a proxy to the new actor type. This should be called once for each upgrade to upgrade all the proxy canisters one by one to the new actor.

Returns

wallet_receive(): async Nat

Accepts cycles to the wallet.

Returns

recycle_cycles(axonId: Nat, floor: Nat): async Nat

Accepts cycles and recycles them for an axon.

Parameters

Returns

transfer(id: Nat, dest: Principal, amount: Nat): async Result<()>

Transfers tokens from one axon to another.

Parameters

Returns

create(init: Initialization): async Result<AxonPublic>

Creates a new axon.

Parameters

Returns

propose(request: NewProposal): async Result<AxonProposalPublic>

Submits a new proposal for an axon.

Parameters

Returns

vote(request: VoteRequest): async Result<()>

Votes on an active proposal.

Parameters

Returns

cancel(axonId: Nat, proposalId: Nat): async Result<AxonProposalPublic>

Cancels an active proposal created by the caller.

Parameters

Returns

execute(axonId: Nat, proposalId: Nat): async Result<AxonProposalPublic>

Queues a proposal for execution.

Parameters

Returns

sync(id: Nat): async NeuronsResult

Calls list_neurons() and saves the list of neurons controlled by the axon's proxy.

Parameters

Returns

refreshBalances(axonId: Nat, accounts: Array<{account: Principal, balance: Nat}>): async [Result<Bool>]

Refreshes the balances of the specified accounts in the axon's ledger. This can only be called by the proxy wallet and is used to keep the axon head in sync with the proxy.

Parameters

accounts(type:Array<{account: Principal, balance: Nat}>`): The accounts and their updated balances.

Returns

cleanup(axonId: Nat): async Result<()>

Updates the proposal statuses and moves them from active to all if needed. Called by the sync function.

Parameters

Returns

private _doExecute(axonId: Nat, proposal: AxonProposal): async AxonProposalPublic

Executes an accepted proposal.

Parameters

Returns

Helper Functions

tokenTransfersAllowed(id: Nat): Bool

Returns true if the policy of an axon allows token transfers by members.

isAuthed(principal: Principal, ledger: Ledger): Bool

Returns true if the principal holds a balance in the ledger or if it's this canister.

neuronIdsFromInfos(id: Nat): Array<Nat64>

Returns the neuron IDs from the stored neuron infos.

getAxonPublic(axon: AxonFull): AxonPublic

Returns the public information of the axon with its own balance.

secsToNanos(s: Int): Int

Converts seconds to nanoseconds.

clamp(n: Int, lower: Int, upper: Int): Int

Clamps a number within a specified range.

makeError(e: Error): Error

Creates an error object from an error.

Documentation for Proxy.mo (The wallet canister)

The Proxy wallet contract is responsible for managing an ICRC1 token implementation and providing various functionalities for interacting with the token. If also allows the users to make requests for call_raw calls so that the Axon Proxy Wallet can call other services.

Public Functions

metrics(): {axon: Principal, archive: Principal}

Retrieves the metrics of the Proxy wallet contract.

recycle_cycles(caller: Principal, floor: Nat): Nat

Recycles cycles from the Proxy wallet contract.

list_neurons(): GT.ListNeuronsResponse

Calls the list_neurons() function and saves the list of neurons that this canister controls.

manage_neuron(args: GT.ManageNeuron): GT.ManageNeuronResponse

Manages a neuron by calling the manage_neuron() function.

call_raw(canister: Principal, functionName: Text, argumentBinary: Blob, cycles: Nat): Result.Result<Blob, Text>

Calls a canister function with raw parameters.

ICRC1 Token

Management Functions

Release Notes

v2.1.2

v2.1.1

v2.1.0

v2.0.3

v2.0.2

v2.0.1