Coder Social home page Coder Social logo

klimadao-solidity's Introduction

Summary

This repo contains 6 packages.

@klimadao/app -> app.klimadao.finance, a standalone single-page-app for protocol interactions.

@klimadao/carbon-projects -> A Sanity CMS that contains curated data for Verra projects, deployed to carbon-projects.sanity.studio, and referenced by the Carbonmark frontend and backend. NOTE: Unlike the other packages, this one is not included as an NPM workspace from the root package.json. To work with the CMS you need to run sanity install from inside the carbon-projects folder.

@klimadao/carbon -> data.klimadao.finance site (formerly carbon.klimadao.finance)

@klimadao/lib -> Components and utilities that are shared between packages.

@klimadao/site -> klimadao.finance homepage, content and cms-powered pages.

Requirements

Take note, this repo utilizes newer features from Node, NPM and TypeScript 4.5.

Install dependencies

From the klimadao/ root folder, not from individual packages: npm install

Development

A set of NPM Workspace commands are provided, and can be run from the root folder.

Other scripts you should know about:

  • npm run build-all: build all workspaces.
  • npm run format-all: Format all files with prettier.
  • npm run extract-strings:dev: Extract translation files for the source language "en".

Type Generation

Typescript types for Carbonmark and Carbonmark API are generated via the generate:types script in each respective project.

Regenerate types in any of the following changes:

  1. Models in the API (.model files)
  2. Change to any of the dependant subgraphs (see codegen.constants.ts)
  3. API Version targeted by Carbonmark

Translations

For Developers

This repo uses lingui in combination with translation.io.

We follow these rules:

  • Don't use ids, except for very long strings.
  • Extract the source translation with npm run extract-strings:dev
  • Commit source language files "en" only

For translators

Setup

  • Create an account on translation.io
  • Request access to the project atmosfearful/klimadao in the #content-translation KlimaDAO discord server

Translating

  • Log in translation.io
  • Select the appropriate project klimadao-site or klimadao-app
  • Make sure you select the appropriate language in the top menu
  • Start translating!
  • Select an item to translate in the left column
  • On the bottom right you will notice the source text (in English) and the place to translate the text beneath.
  • You can prefill this by selecting an entry in the Suggestion area above.

Pledge Dashboard

Klima Infinity pledge dashboard is backed by a firebase database. Follow the following to set up your dev environment if you'd like to contribute to the project.

Diagrams

See this page in the wiki of this repo for architecture and other diagrams.

Contributing

The DAO is looking for react/typescript devs as well as experienced Solidity devs! Enjoy a flexible work schedule and work on something truly ambitious and meaningful. Monthly compensation available based on your level of experience and degree of contribution.

If you'd like to just take a ticket or fix a bug, go for it (always better to ask first, though).

If you'd like to become a regular contributor to the DAO, join the KlimaDAO discord and follow the application instructions.

πŸ“šCheck out the contribution & style guide.

klimadao-solidity's People

Contributors

0xaurelius avatar 0xmichalis avatar archimedescrypto avatar chazschmidt avatar cujowolf avatar shimond-klimadao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

klimadao-solidity's Issues

Proper hardhat deploy tester

Rather than running the test suite on a mocked up local testnet, it would be ideal to use a Hardhat tester that mirrors the current state of mainnet for testing

May need additional clarity from @ArchimedesCrypto on how that will work

Bug in retireCarbonSpecific

Hi,there is a bug in retireCarbonSpecific when poolToken and sourceToken is not equal and amountInCarbon is false

    function _prepareRetireSpecific(
        address _sourceToken,
        address _poolToken,
        uint256 _amount,
        bool _amountInCarbon,
        address _retiree
    ) internal returns (uint256, uint256) {
        (
            uint256 sourceAmount,
            uint256 totalCarbon,
            uint256 fee
        ) = _transferSourceTokens(
                _sourceToken,
                _poolToken,
                _amount,
                _amountInCarbon,
                true
            );

        // Get the pool tokens

        if (_sourceToken != _poolToken) {
            // Swap the source to get pool
            if (_amountInCarbon) {
                // Add redemption fee to the total to redeem.
                totalCarbon += _getSpecificCarbonFee(_poolToken, _amount);
                _amount += _getSpecificCarbonFee(_poolToken, _amount);

                // swapTokensForExactTokens
                _swapForExactCarbon(
                    _sourceToken,
                    _poolToken,
                    totalCarbon,
                    sourceAmount,
                    _retiree
                );
            } else {
                // swapExactTokensForTokens
                (_amount, fee) = _swapExactForCarbon(
                    _sourceToken,
                    _poolToken,
                    sourceAmount
                );
            }
        } else {
            _amount = sourceAmount - fee;
        }

        if (!_amountInCarbon) {
            // Calculate the fee and adjust if pool token is provided with false bool
            fee = (_amount * feeAmount) / 1000;
            _amount = totalCarbon - fee;
        }

        return (_amount, fee);
    }

example :

sourceToken : usdc
poolToken : bct
amountInCarbon:false
amount : 10 usdc

we consider 2 usdc equal to 1 bct

in this case _swapExactForCarbon return amount of bct (that is 4.95 bct if feeAmount is 1 %)

then because _amountInCarbon is false the below code also run:

if (!_amountInCarbon) {
    // Calculate the fee and adjust if pool token is provided with false bool
    fee = (_amount * feeAmount) / 1000;
    _amount = totalCarbon - fee;
}

and _amount updated here again with a value greater than the actual value that is 4.95

based on the calculations totalCarbon is 10 and _amount ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍updated to something near to 9.9

in this case the above if must not be executed .

Add automation for RA fee split

Rather than manually swapping collected fees for KLIMA, automate this process by deploying an immutable smart contract that executes the swaps and automate it using Gelato or Chainlink Keeper

  • Write helper contract to handle swaps
  • Add automation to invoke periodically (monthly?)

Update LibToucanCarbon for Puro Credits

Add support for Toucan bridged Puro credits

From KlimaDAO/klimadao#1858 (comment)

PuroToucanCarbonOffsets: https://polygonscan.com/address/0x17179596dd44167743f707F590E34C49caBe4E7D#code
PuroToucanCarbonOffsetsFactory: https://polygonscan.com/address/0xc83dc91b3cd45d65f981c0018b3eb1c43a468381#code

Key difference here is that instead of immediately issuing the retirement, there is a new method requestRetirement that can then either be finalized or reverted. May need some updates to the ERC721 receiver function if the retirement NFT is going to lag behind the on chain request.

Add Coorest Library for handling retirements

Create a LibCorrestCarbon for the use in acquiring and retiring CCO2s through the aggregator. Also update the enum in LibRetire to add Coorest

  • Emits a CarbonRetired event.
  • Since there are no current redemptions or pools set up, should be simple for now.

Upgrade RA v2 to allow for any pool to pool swap through Klima

Currently, in RA V2, we can only swap (s/ws)klima>anything and usdc->anything.
BCT->"any pool token" would also work for small amounts, but not vice versa since we don't have USDC liquidity for any other pool token.

Libswap has default logic which swaps the source token to USDC first if a path is not pre-defined. That's good for non-pool tokens, and works for small amounts for BCT->other as described above.

We should implement a function that checks if (s.isPoolToken[sourceToken]), and swaps to Klima first. This would likely require 5 new mappings in DiamondInit.sol, for the following paths:

s.swap[C.klima()][C.bct()]
s.swap[C.klima()][C.nct()]
s.swap[C.klima()][C.ubo()]
s.swap[C.klima()][C.nbo()]
s.swap[C.klima()][C.mco2()]

[Retirement Aggregator] BCT/USDC removed liquidity is causing failures with USDC->BCT and amountincarbon=false

The aggregator broke for the two cases:

  1. USDC -> BCT.
  2. Amountincarbon = false.

In both cases bct/usdc removed liquidity is causing an error.

It took me a while to figure this one out since my live offsetting contract broke, and Timmy also reached out to me asking for help figuring out the same error "UniswapV2Library: ZERO_ADDRESS".

I'm opening a github issue.

The problem is with this assumption:
In RetireToucanCarbon
image

The same assumption is in the MOSS helper as well, but there's usdc/moss liquidity on quickswap so it's not an issue there

Deploy wsKLIMA

Please deploy a wsKLIMA contract similar to https://github.com/OlympusDAO/olympus-contracts/blob/Version-1.1/contracts/wOHM.sol

Background:

  1. The wrapped version would be better for (german) taxation, since it generates no longer any staking income
  2. The wrapped version of the staked token would allow cross-chain bridging

Logic:

wsKLIMA would be a wrapped version of sKLIMA such that:

  • When you wrap your sKLIMA the amount of wsKLIMA you get is: sKLIMA / index.
  • 50 sKLIMA at the index of 10 gets you 5 wsKLIMA.
  • Upon unwrapping wsKLIMA the amount of OHM you get is: wsKLIMA x index.
  • Example: 5 wsKLIMA with an index of 12, unwraps to 60 sKLIMA
  • Price of 1 wsKLIMA is always approximately = price of 1 KLIMA x Current Index

Retirement aggregator should include retirements not executed by itself

I just came across this tweet and while I have made retirements directly via Toucan, it seems Carbon.fyi cannot recognize those and only looks into the Klima aggregator storage for retirements? Maybe this needs to be fixed directly in carbon.fyi or even better we need a library that sits on top of the Klima aggregator contract and native retirement contracts (Toucan, C3, etc.) to aggregate retirements for end users. This could also be a read function in the Klima aggregator as it sounds like aggregating is something it is meant to do :)

Implement Retirement Aggregator Fee Split

KIP-33 has passed. The RA fee handling logic should have configurable parameters to control the splitting logic for the convenience fee

  • daoFeeShare: indicates what proportion (e.g. 0.8 for 80%) goes to the DAO wallet. Remaining fee goes to the treasury.
  • daoWallet: address where the DAO's share should be sent

We may eventually want to generalize this to support referral fees, but we'll treat that as a future piece of work

[Retirement Agg] Add support for Trident pool swaps

Currently, paying with KLIMA to offset UBO or NBO causes the transaction to revert, since the swap step doesn't support Trident pools.
The user has to go through the additional step of swapping KLIMA for UBO or NBO on Sushi before offsetting, which is not good user experience.

PS
I will open a corresponding frontend issue to disable KLIMA as a source for retiring UBO or NBO for now.

Add a proper test suite

There is an existing PR that ports the existing test suite from Olympus, but it isn't really complete/mergeable: https://github.com/KlimaDAO/klimadao-solidity/pull/4/files

The scope of this ticket is to take that PR, update it, and expand it as follows:

  • Ensure all contracts have some basic tests
    • Retirement aggregator definitely needs tests written
  • Add testing invocation to the GitHub Actions ci.yaml workflow

V2 Aggregator - Toucan retirement with event only

Allow a user to retire Toucan tonnes only emitting the retirement events. Store the details of beneficiary => eventID so that the NFT certificate can be claimed either by the beneficiary or possibly permissionless for them.

Update LibRetire for Coorest

  • Add Coorest to the CarbonBridge enum.
  • Extend the retireReceivedCarbon function to also call the LibCoorestCarbon if CCO2 is provided.

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.