Carbon's CUSD-Fiat gateway: smart contracts
Smart contract code audited by New Alchemy
To deploy, run:
truffle migrate --network [network]
The gas limit may have to be adjusted in truffle-config.js
.
(Dec 18): Deployment of the entire protocol should not cost more than 2 ETH
Code dependencies need to be flattened into a single *.sol
contract in order for popular block explorers like etherscan.io to verify their bytecode.
Run sol-merger ./contracts/[CONTRACT].sol "./flatten/"
to flatten any contract into the flatten/ directory named [CONTRACT]_merged.sol
To verify contracts created by the Factories, you will need to retrieve the ABI-ecoded constructor arguments that were passed during creation. This is a useful online ABI encoding service
You can also deploy the flattened contract using the Remix IDE
truffle-config currently connects to Ethereum node via websocket provided by our Infura account
provider: function () { return new HDWalletProvider(process.env.MNEMONIC/privateKey, "wss://mainnet.infura.io/ws" + process.env.INFURA_API_KEY_MAIN) },
Update as of November 2018: Interact with CUSD without paying ETH gas fees!
New metatransaction functionality was upgraded in the MetaToken.sol
CUSD implementation contract
CUSD: "CUSD" is a regulated ERC20 token redeemable into any whitelisted token, the initial of which is "WT0" (Whitelisted Token v.0)
MintPermissions: account capable of minting or issuing new CUSD or WT0 tokens to any account
Blacklisted: account barred from interacting with active CUSD tokens
Validator: account capable of setting user permissions/roles including MintPermissions and Blacklisted
CUSD is a Permissioned ERC20 Token whose methods are protected by a Regulator
WhitelistedToken is also a PermissionedToken and is two-way convertible into CUSD`
- The Regulator/CarbonDollar/Whitelisted Proxy Factories can create new CUSD, WT0, and Regulator contracts.
RegulatorProxyFactory.createRegulatorProxy(Regulator.address)
creates a new Regulator instance that uses the same logic as the Regulator Logic contract. For example, RegulatorProxyFactory.createRegulatorProxy
would act as a Regulator that can regulate a Permissioned token. Importantly, since Regulators are ownable proxy contracts, ownership of newly created proxies must be claimed via newRegulator.claimOwnership({ from: newOwner })
.
For convenience, the caller of createRegulatorProxy() is designated a Validator for that Regulator. This can be changed by the Regulator owner.
- Now, we have to do some additional setup steps to ensure that CUSD and WT work properly.
i) CUSD must whitelist WT as an official stablecoin that CUSD is redeemable for
`CUSD.listToken(WT.address, {from:cusdOwner})`
ii) To mint new tokens, the Regulator contracts for WT0 and CUSD (these contracts could be the same) must designate a minter capable of calling mint()
`Regulator.setMinter(minter, {from: validator})`
iii) To set a fee charged upon redeeming CUSD into WT, the CUSD contract owner may call CUSD.setFee(fee)
on the active CUSD contract. Fees can optionally be collected be escrowed by the CUSD contract to pay for transaction fees.
Look at package.json::scripts
to see some possible test suites that we've created to rigorously test our smart contracts. For example, run npm run test-permissioned-token
to unit test PermissionedToken.sol. Note that these tests should be run locally on a local ethereum node, which you can spin up using npm run eth
.
Run npm run test
to run all tests on the local network
Model scripts are provided in ./scripts/
for reading contract stats on Ropsten (or Mainnet with a small tweak) that can be run with npm run stats-ropsten
. npm run test-token-ropsten
will mint, transfer, and burn CUSD on Ropsten for testing purposes.
CarbonDollar (logic) (this is now a MetaToken, which extends CarbonDollar)