Giter Club home page Giter Club logo

charta's Introduction


'Charta' is the latin word for 'letter or document'. We loosely appropriate this term as a codename for the smart contracts comprising the business logic of Dharma protocol.

Dharma is a protocol for generic tokenized debt issuance and fundraising on blockchains supporting requisite smart contract functionality (i.e. EVM blockchains). This repository contains the core contracts that compromise the business logic for issuing and administering debt crypto-assets on-chain.

We use truffle for deployment, testing, and development, and use Typescript for testing and deployment.

Join us on our chat for any technical or general questions.

Deployed Contracts


Ethereum Mainnet
  • DebtKernel: 0x8ef1351941d0cd8da09d5a4c74f2d64503031a18
  • DebtToken: 0xf7b3fc555c458c46d288ffd049ddbfb09f706df7
  • DebtRegistry: 0x4e0f2b97307ad60b741f993c052733acc1ea5811
  • TokenTransferProxy: 0x2f40766e91aaee4794d3389ac8dc3a4b8fd7ab3e
  • DharmaMultiSigWallet: 0x9445d5ddc2d8a3663ce8cc9fe74009f99b343cfc
  • RepaymentRouter: 0xc1df9b92645cc3b6733992c692a39c34a86fae5f
  • TokenRegistry: 0xd79396ab3bfaaa0d9f6d11f95bb641601d93c0a9
  • SimpleInterestTermsContract: 0xb78a7d1c1d03cf9155cc522097cbc679e15cf9a3
  • CollateralizedSimpleInterestTermsContract: 0x5de2538838b4eb7fa2dbdea09d642b88546e5f20
  • Collateralizer: 0xecc718386176d714dc9e4e35e177396b291499ee
  • PermissionsLib: 0xba0d793fb316d7a457b758e75a57e22ee14bc188
  • ContractRegistry: 0x10512440113cb6cb613be403135876d2e0a42c0b
Kovan Testnet
  • DebtKernel: 0x755e131019e5ab3e213dc269a4020e3e82e06e20
  • DebtToken: 0x12c8615fd55bf6e1f5a298cebdc72e50f838df74
  • DebtRegistry: 0x9662d6cae0e6914a388cb96c1c161cc4d12c3d7a
  • TokenTransferProxy: 0x668beab2e4dfec1d8c0a70fb5e52987cb22c2f1a
  • DharmaMultiSigWallet: 0x5e6d80063af17bf22b6828a7a61693ec37881563
  • RepaymentRouter: 0x0688659d5e36896da7e5d44ebe3e10aa9d2c9968
  • TokenRegistry: 0x6949948d93f3dbe50ec2fe54815fa33bfa284d35
  • SimpleInterestTermsContract: 0x4cad7ad79464628c07227928c851d3bc5ef3da0c
  • CollateralizedSimpleInterestTermsContract: 0x13763cf3eb3b6813fa800d4935725a0504c8eb8f
  • Collateralizer: 0x4b86bbe375577262cb0b3b7893e3de0d11751dd6
  • PermissionsLib: 0x0e7e2aace2ed2565777b420fd181b556971a8cb1
  • ContractRegistry: 0x506acb19a451cc6e2a5c76e65f6b65840406e5f9

Setup


Dependencies

Install dependencies:

yarn install
Testing

Start testrpc:

yarn chain

Run truffle tests:

yarn test

Contract Architecture

A specification of the contracts comprising Dharma protocol's logic can be found in the Dharma wiki.

charta's People

Contributors

chrismin avatar graemecode avatar jdkanani avatar nadavhollander avatar saturnial avatar shivgupt avatar t4sk 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

charta's Issues

Token registry events

Do you plan to have events related to addition or removal of tokens to the Token Registry?
Right now they seem to be represented here:

string[256] public tokenSymbolList;

and I'm not sure what's a good way to be notified of updates to it.
Thank you!

Yarn install: sha3 errors

Error

yarn install v1.9.4 [1/4] Resolving packages... [2/4] Fetching packages... info [email protected]: The platform "linux" is incompatible with this module. info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... [4/4] Building fresh packages... [1/6] ⢀ sha3 [2/6] ⠠ secp256k1 [3/6] ⠠ keccak [-/6] ⠠ waiting... error /home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3: Command failed. Exit code: 1 Command: node-gyp rebuild Arguments: Directory: /home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3 Output: gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | linux | x64 gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR gyp info spawn /usr/bin/python2 gyp info spawn args [ '/home/ubuntu/.nvm/versions/node/v10.8.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/home/ubuntu/.nvm/versions/node/v10.8.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/ubuntu/.node-gyp/10.8.0/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/ubuntu/.node-gyp/10.8.0', gyp info spawn args '-Dnode_gyp_dir=/home/ubuntu/.nvm/versions/node/v10.8.0/lib/node_modules/npm/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/ubuntu/.node-gyp/10.8.0/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' ] gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] make: Entering directory '/home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3/build' CXX(target) Release/obj.target/sha3/src/addon.o In file included from ../src/addon.cpp:4:0: ../../nan/nan.h: In function ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’: ../../nan/nan.h:840:60: warning: ‘v8::Local<v8::Value> node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations] v8::Isolate::GetCurrent(), target, func, argc, argv); ^ In file included from ../src/addon.cpp:1:0: /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:172:50: note: declared here NODE_EXTERN v8::Local<v8::Value> MakeCallback( ^ /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:88:42: note: in definition of macro ‘NODE_DEPRECATED’ __attribute__((deprecated(message))) declarator ^~~~~~~~~~ In file included from ../src/addon.cpp:4:0: ../../nan/nan.h: In function ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::String>, int, v8::Local<v8::Value>*)’: ../../nan/nan.h:855:62: warning: ‘v8::Local<v8::Value> node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::String>, int, v8::Local<v8::Value>*)’ is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations] v8::Isolate::GetCurrent(), target, symbol, argc, argv); ^ In file included from ../src/addon.cpp:1:0: /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:165:50: note: declared here NODE_EXTERN v8::Local<v8::Value> MakeCallback( ^ /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:88:42: note: in definition of macro ‘NODE_DEPRECATED’ __attribute__((deprecated(message))) declarator ^~~~~~~~~~ In file included from ../src/addon.cpp:4:0: ../../nan/nan.h: In function ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)’: ../../nan/nan.h:870:62: warning: ‘v8::Local<v8::Value> node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, const char*, int, v8::Local<v8::Value>*)’ is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations] v8::Isolate::GetCurrent(), target, method, argc, argv); ^ In file included from ../src/addon.cpp:1:0: /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:158:50: note: declared here NODE_EXTERN v8::Local<v8::Value> MakeCallback( ^ /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:88:42: note: in definition of macro ‘NODE_DEPRECATED’ __attribute__((deprecated(message))) declarator ^~~~~~~~~~ In file included from ../src/addon.cpp:4:0: ../../nan/nan.h: In member function ‘v8::Local<v8::Value> Nan::Callback::Call_(v8::Isolate*, v8::Local<v8::Object>, int, v8::Local<v8::Value>*) const’: ../../nan/nan.h:1484:5: warning: ‘v8::Local<v8::Value> node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated: Use MakeCallback(..., async_context) [-Wdeprecated-declarations] )); ^ In file included from ../src/addon.cpp:1:0: /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:172:50: note: declared here NODE_EXTERN v8::Local<v8::Value> MakeCallback( ^ /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:88:42: note: in definition of macro ‘NODE_DEPRECATED’ __attribute__((deprecated(message))) declarator ^~~~~~~~~~ ../src/addon.cpp: In static member function ‘static Nan::NAN_METHOD_RETURN_TYPE SHA3Hash::New(Nan::NAN_METHOD_ARGS_TYPE)’: ../src/addon.cpp:59:58: error: no matching function for call to ‘v8::Function::NewInstance(const int&, v8::Local<v8::Value> [1])’ info.GetReturnValue().Set(cons->NewInstance(argc, argv)); ^ In file included from /home/ubuntu/.node-gyp/10.8.0/include/node/node.h:63:0, from ../src/addon.cpp:1: /home/ubuntu/.node-gyp/10.8.0/include/node/v8.h:3953:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>, int, v8::Local<v8::Value>*) const V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( ^~~~~~~~~~~ /home/ubuntu/.node-gyp/10.8.0/include/node/v8.h:3953:44: note: candidate expects 3 arguments, 2 provided /home/ubuntu/.node-gyp/10.8.0/include/node/v8.h:3956:44: note: candidate: v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance( ^~~~~~~~~~~ /home/ubuntu/.node-gyp/10.8.0/include/node/v8.h:3956:44: note: candidate expects 1 argument, 2 provided sha3.target.mk:105: recipe for target 'Release/obj.target/sha3/src/addon.o' failed make: Leaving directory '/home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3/build' make: *** [Release/obj.target/sha3/src/addon.o] Error 1 gyp ERR! build error gyp ERR! stack Error: make failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/home/ubuntu/.nvm/versions/node/v10.8.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23) gyp ERR! stack at ChildProcess.emit (events.js:182:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12) gyp ERR! System Linux 4.4.0-1066-aws gyp ERR! command "/home/ubuntu/.nvm/versions/node/v10.8.0/bin/node" "/home/ubuntu/.nvm/versions/node/v10.8.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/ubuntu/Lendflo-Commodo/charta/node_modules/sha3

Diagnosed Problem

Not sure :/

Solution

Remove both yarn.lock and package-lock.json from the home repo. Then yarn install

FR: Collateralized Base Contract for Terms Contracts

Feature Request:

Create a generic base contract under the contracts/examples/ folder for holding tokens of different types as collateral in a Dharma terms contract that inherits from the contract. In the ideal case, I'd love to see a Collateralized.sol file with usage akin to OpenZeppelin's Owned.sol or Pausable.sol, i.e.

import "charta/contracts/examples/Collateralized.sol";
import "charta/contracts/Terms.sol";

contract CompoundInterestTermsContract is TermsContract, Collateralized {

...

}

Specification:

The flow for collateralizing an asset should be as follows:

  1. User grants transferFrom allowance for desired collateral amount on desired collateral token to the TermsContract that inherits from Collateralized.sol (using the ERC20 approve method)
  2. User calls collateralize(bytes32 issuanceCommitmentHash, address token, uint amount, uint lockupPeriodEndBlockNumber). Terms contract then transfers itself the desired collateral, and records all relevant information (including the user-defined lockupPeriodEndBlockNumber) as associated with the given issuanceCommitmentHash.

After an asset has been collateralized one of the following can happen:

  • When block.number > lockupPeriodEndBlockNumber, any user can call returnCollateral, and the contract will transfer the debtor back the collateral (if it hasn't already been seized)
  • When, at any time, getExpectedRepaymentValue() > getValueRepaid() on the TermsContract that inherits from Collateralized.sol, any user can call seizeCollateral, and the contract will transfer the collateral to the debt agreement's beneficiary.

Acceptance Criteria

  • Is the contract clean, well-documented, and generic?
  • Is a thorough test harness present (both unit and integration tests)?

RFC: Extract Collateralized from Inheritance Hierarchy

Overview

Here we propose extracting collateralized from the inheritance hierarchy, to avoid multiple-inheritance downstream. The extracted functions will exist in its own contract with storage.

Rationale

Multiple inheritance in Solidity can cause bugs if the programmer is not cautious (c.f. https://pdaian.com/blog/solidity-anti-patterns-fun-with-inheritance-dag-abuse.) Charta should avoid any patterns that allows users to create contracts with bugs due to a slight oversight - such as misunderstanding c3 linearization in Solidity.

Alternatives

  • Keep the current implementation, using multiple inheritance, which will allow us to ship faster, but could be problematic down the line.
  • Implement the collateralization functionality as a library.

Engineering Implementation

  • Create a contract Collateralizer.sol that implements the following public functions
    • registerTermStart
      • Only called by debt kernel; called upon debt agreement’s issuance
      • Checks necessary preconditions, such as token balances
      • Pulls collateral from the debtor to the custodian
      • Emits an event that the collateral has been secured
    • returnCollateral
      • Returns collateral to the original debtor, iff debt terms has lapsed and expected repayment has been made.
      • Emits an event that the collateral has been returned
    • SeizeCollateral
      • Takes collateral from the debt agreement and transfers it to the beneficiary who owns the debt
      • Emits an event that the collateral has been seized
    • Uses the following storage
      • debtKernalAddress (for validating that only the debt kernel can call certain functions)
      • debtRegistry, tokenRegistry
      • agreementToCollateralizer, a mapping of the agreement id to the address of the collateralizer

[tutorial-1 bug] how can I call contract in private development chain?

After running by command in tutorial-1, I get this error in Chrome. I have deployed the Dharma contract in my private chain to address list in /artifacts/.

dharma.umd.js:170037 Uncaught (in promise) Error: Unable to find address for contract TokenRegistry on network with id 70
    at Function.<anonymous> (dharma.umd.js:170037)
    at step (dharma.umd.js:169709)
    at Object.next (dharma.umd.js:169690)
    at fulfilled (dharma.umd.js:169681)
(anonymous) @ dharma.umd.js:170037
step @ dharma.umd.js:169709
(anonymous) @ dharma.umd.js:169690
fulfilled @ dharma.umd.js:169681
Promise.then (async)
step @ App.css?d973:26
(anonymous) @ App.css?d973:26
Promise.then (async)
step @ App.css?d973:26
(anonymous) @ App.css?d973:26
(anonymous) @ App.css?d973:26
createDebtOrder @ App.jsx:72
handleSubmit @ RequestLoanForm.jsx:37
callCallback @ react-dom.development.js:100
invokeGuardedCallbackDev @ react-dom.development.js:138
invokeGuardedCallback @ react-dom.development.js:187
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:201
executeDispatch @ react-dom.development.js:461
executeDispatchesInOrder @ react-dom.development.js:483
executeDispatchesAndRelease @ react-dom.development.js:581
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:592
forEachAccumulated @ react-dom.development.js:562
runEventsInBatch @ react-dom.development.js:723
runExtractedEventsInBatch @ react-dom.development.js:732
handleTopLevel @ react-dom.development.js:4476
batchedUpdates$1 @ react-dom.development.js:16659
batchedUpdates @ react-dom.development.js:2131
dispatchEvent @ react-dom.development.js:4555
interactiveUpdates$1 @ react-dom.development.js:16714
interactiveUpdates @ react-dom.development.js:2150
dispatchInteractiveEvent @ react-dom.development.js:4532

I found the address in @dharmaprotocol/dharma.js/dist/dharma.umd.js

"70": {
            "events": {
                "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0": {
                    "anonymous": false,
                    "inputs": [
                        {
                            "indexed": true,
                            "name": "previousOwner",
                            "type": "address"
                        },
                        {
                            "indexed": true,
                            "name": "newOwner",
                            "type": "address"
                        }
                    ],
                    "name": "OwnershipTransferred",
                    "type": "event"
                }
            },
            "links": {},
            "address": "0xf21ef0271ebcbd144616c43b90dc578665264a2c"
        }

and in truffle console

truffle(development)> TokenRegistry.address
'0xf21ef0271ebcbd144616c43b90dc578665264a2c'

Plz give me some insight for this question, thx a lot.

Borrower/Debtor address

Hi Team
What is the recommended way to derive the borrower address for any given debt order? It doesn't seem to be present in any of the contracts' events, or query'able via the subgraph. Am I missing something?

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.