Code Monkey home page Code Monkey logo

circles-contracts-v2's Introduction

Circles Protocol

Introducing Circles Protocol v2

We're excited to be working on Circles Protocol v2, where we focus on making things better for everyone who uses and builds on Circles. Learning from our journey since Circles began, we've tackled the challenges we faced in the early days.

In Circles v2, we make it easier and more inviting for users and developers to engage with Circles. Our goal is to foster an ecosystem of products and experiences building on Circles. We've also been busy updating our technology, using the latest in cryptography to enhance performance, scalability, and to bring a new level of privacy to the Circles experience.

Why build Circles ?

Our standard money system is based on debt, primarily from banks. Repaying this debt requires more than the initial amount due to interest, ensuring a consistent return of funds to these financial institutions. This system indirectly encourages anticipating future economic growth, which can increase our demand on the planet's resources.

In Circles UBI, we introduce "Time Circles" (TiC), a money system backed by the equal passage of time for all people. Every hour, each individual can seamlessly add one TiC to their account, unconditionally. To ensure TiC remains a meaningful measure of value, we implement a decay mechanism: tokens diminish in value over time. This equilibrium between token creation and decay ensures a stable balance for everyone, today and for future generations.

Understanding "Time Circles" also means recognizing what they are not. While this brief overview may not capture the full depth of the discussion, let's set a clear foundation from the outset.

Time Circles is not a panacea for all economic challenges, but it is essential to understand its intended purpose. TiC isn't a promise of a universal standard of living across diverse regions. Instead, it's a commitment that no person should be completely without financial means. Think of TC as a baseline currency available to all.

Time Circles encourages circular spending. Its true worth will be determined by the quality and range of goods and services available for TiC. While other currencies may prioritize store-of-value, TiC complements this financial landscape, emphasizing circulation and utility.

Lastly, two crucial parameters underpin the TiC system. The first parameter straightforwardly defines the unit: one token for every human, every hour. The second parameter establishes the decay rate of TiC. With a vision for sustainability across generations, our approach is retrospective: taking an optimistic human lifespan of 80 years as a benchmark, a token minted today should, after those 80 years, carry negligible value.

Specifications

🐉 warning: here be dragons. This repository is under construction and neither functionally complete or externally reviewed. It is shared publicly to enable early discussion, but should not be considered ready for use.

For questions, contact maintainer: Ben [email protected]

Setting up development environment

This Solidity project uses Foundry as a toolkit. If you don't have Foundry installed yet, see instructions below

Using Foundry to build the contracts

  1. First, you'll need to clone the repository to your local machine:
    git clone https://github.com/CirclesUBI/circles-contracts-v2
    cd circles-contracts-v2

Compiling the contracts

  1. To compile the contracts, use the following command:

    forge build

    Upon successful compilation, you'll find the generated artifacts (like ABI and bytecode) in the specified output directory, by default out/.

  2. To format the code, you can run:

    forge fmt

    or only check the correct formatting without changing the code:

    forge fmt --check

Testing the contracts

  1. To test the contracts, use the following command:
    forge test
    or to report on gas usage:
    forge test --gas-report
  2. To create a snapshot file to disk of each test's gas usage, use:
    forge snapshot

Deploying the contracts

Chiado

To deploy the contracts to the Chiado testnet, run ./chiadoDeploy.sh and supply a private key and API keys in .env file in the root directory (copy .env.example and set private information):

./script/deployments/chiadoDeploy.sh

Foundry as toolkit

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

You can find the installation guide for Foundry in their book.getfoundry.sh - Getting started

Here we re-iterate the most important steps to get you started.

  1. You can install precompiled binaries with their toolchain installer:
    curl -L https://foundry.paradigm.xyz | bash
    and follow the instructions in the terminal. To instead build from source, see their getting started guide.

circles-contracts-v2's People

Contributors

benjaminbollen avatar jaensen avatar koeppelmann avatar

Forkers

shorn-gnosis

circles-contracts-v2's Issues

Implement infinite scroll for the List component

As a user I want to be able to scroll through e.g. all my historic transactions. Currently only a fixed number (25) of items is displayed and I'm not able to see older items.

Tasks:

  • Change the List to accept a query: CirclesQuery<T> parameter instead of a rows: RowItem[] array. Keep the rows array around locally but don't expose it as component parameter.
  • Execute the query and add the results from the query.currentPage.results property to the rows array.
  • Render the list in a way, that it contains a page-end marker element at the end of the list.

    Pseudo code:
    {#each row in rows}
    <!— Row component here -->
    {/each}
    <!— page-end marker here -->

    Whenever the page-end marker is scrolled into the view, call query.queryNextPage() and append the results of the next page to the rows.

Acceptance:

  • All lists in the application offer endless scrolling
    • /contacts
    • /dashboard
    • /groups
    • /invitations

Wrap/unwrap ERC20

As a developer I want to use the SDK to allow my users to wrap their personal Circles tokens into ERC20 tokens so that they can use it in e.g. DeFi scenarios.

Contracts review

v2 contracts reviewed and audited by (at least) one other person.

  • intro call with Ben and Côme du Crest (Gnosis internal review)
  • @benjamin.bollen to reach out to ChrisEth to request review

[epic] Contract Reviews

  • internal contracts review
  • bring v2 (contracts and SDK) to hackers to gather feedback
  • #27
  • address findings from dev community feedback

Pathfinder speed-up potential

We identified some changes that would improve the pathfinding speed. This issue collects the different ideas for discussion and triage.

Note: Many user-facing flows (e.g. transfer Circles) require to call the pathfinder twice. First to determine the max. flow and then again to calculate the flow for the actual transfer value.

Known potential:

  1. CRC-290
  2. Don't use the full 20 byte address to address nodes in the graph. Instead assign a numeric index to each address and use that instead.
  3. Do partial graph updates instead of re-loading the whole graph at any new block. This will free up resources to do actual pathfinding.

Acceptance:

  • Ideas brainstormed and discussed
  • Specific issues for implementation are written

Outlook: Long term, the pathfinder should be part of the "Circles Node", support batching and competing algorithms.

Groups policies for growth initiatives

TODO:

  • specify (and document) the design of the most important (3) groups that we want to have for launch:
    • kyc’d gnosis pay user - if you are a pay user, you should be able to join this group
    • poap holder - possibly linking poaps to your circles account … (features to tbd)
    • trusted members group - based on a trust score that the “trust rating algo” (not yet built) calculates for every circles user.
  • decide on (and document) how to mint group tokens (direct mint or via path) - probably just at the group level

Index safe events / show owners of org

As a Circles user I want to know who's the owner of an organization account. In the Circles protocol, organizations are traditionally Safes with other (human) avatars as owners.

Particularly interesting events for this use case are:

  • AddedOwner
  • RemovedOwner
  • ChangedThreshold

Alternatives:

  • Instead of indexing these events for all safe deployments in the circles plug-in, we could use the safe transaction service. There is prior art in the Metri wallet.
  • Don't index at all but query via rpc.

Acceptance:

  • Alternatives are evaluated
  • I can query the ownership and threshold information for every safe account registered with Circles from the SDK

Follow up:

  • Add the query to the SDK's data package

Feed the pathfinder with Nethermind plug-in data

As a protocol developer I want to feed the pathfinder with data from the circles-nethermind-plugin. Currently it uses data from the blockchain-indexer which is deprecated. The pathfinder is the last component that uses the indexer via the pathfinder-updater and the indexer can be shut down once the transition is complete.

Acceptance:

  • The pathfinder gets its data either from the nethermind plugin

Follow-up:

  • Install the new pathfinder and/or pathfinder2-updater in production

address findings from report

  • Attacker can steal tokens from user who opted out consented flow
    • #28 change group mint over path to be minted in group address itself
    • not adopted patch because overreaching: consider restricting operator to only authorized operators for all touched vertices
    • #30 remove opt-out from consented flow
    • acknowledging that upon trusting a group the user is aware that it is the group mint policy that determines whether other people can maximally mint over the user's collateral into the group; or what conditions are enforced
  • improve events for wallet UX
    • work within compile size constraint to add event StreamCompleted which is the effective ERC1155:TransferBatch event for each effective batch that is completed in a flow matrix representing a batch of transfer intents as one path transfer
    • replace event DiscountCost with standard ERC1155:TransferSingle(_burner, 0x00, burnAmount) so that standard ERC1155 indexing tracks the correct balances (without specific indexing knowledge of Demurrage "DiscountCost"). Unfortunately we cannot emit both events because of compile size constraints on Hub.sol
    • add events for Group Creation, Mint and Redemption
    • #31 see PR for Patch 03
  • closed paths constraints can be by-passed, remove it
    • the intention was that an operator can unscatter the distribution of Circles by using closed paths to return Circles to their center where they maximise liquidity. This constraint attempted to block arbitrary moving around of Circles, when a path was "closed" ie. had no explicit senders and receivers; but indeed this constraint is trivially bypassed, so we can remove this constraint.
    • see #32 for code patch
  • Base58Converter will fail if alphabet is updated
  • Public function in Proxy
    • remark: this code is copied from the audited SAFE proxy
    • I have considered EIP1967: reconsider
      • first Gnosis has an older established standard, being part of the Gnosis ecosystem I see no reason not to follow this standard; also SAFE itself has not adopted EIP1967
      • EIP1967 beyond the storage slot "improvement" which is as arbitrary as the first slot (though modern compiler protected), it specifically spends a lot of effort on upgradability and beacon upgradability, which is explicitly not desired. It is not addressed in the EIP how to handle non-upgradable contracts
    • consider code improvements
      • making the storage slot internal is a valid remark and indeed in later versions of SAFE proxy contract this same correction has been adopted; I adopted the changes of SAFE, but your comment that the check for the masterCopy() call is redundant is not true, so I have not adopted that.
    • I have additionally made the proxy not payable as it never needs to receive xDAI in Circles
    • see #33
  • Optimisations and miscellaneous
    • Contract is not IContract
      • Solidity compiler will return non-linear dependency error if adopted (I have fought many times to try to get this, but if you have a solution, please tell me)
    • Additonal SSTORE/SLOAD
      • evaluated and applied, see #35
    • Unnecessary re-assignment of values
      • consider applying: while I am pretty certain we never call _update with an empty initialisation of the arrays, this is adapted from the original OpenZeppelin ERC1155 implementation; of course, as a framework they may want to be extra careful as some may use their implementation wrong, so our situation is slightly different. Nonetheless, I feel this is too small an optimisation to venture into more dangerous territory. I would advocate to let this be as it is.
    • Update Math64x64 library
      • updated from explicit copy in 2021 to gitmodule dependency on v3.2 (2023) see #36
  • Viewing issuance calculation for groups returns non-zero value, despite actually minting is blocked as designed.
    • add check to return zero for groups and orgs available issuance.
    • see #34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.