Skip to content

stablecarbon/fiatgateway_ethcontracts

Repository files navigation

fiat_gateway

Carbon's CUSD-Fiat gateway: smart contracts

node

Smart contract code audited by New Alchemy

Upgradeability

delegatecall proxy pattern

Deployment

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

Contract Verification

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

Connecting to an Ethereum node

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) },

Metatransactions

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

Architecture

Core Token:

CUSD: "CUSD" is a regulated ERC20 token redeemable into any whitelisted token, the initial of which is "WT0" (Whitelisted Token v.0)

Our Regulators can assign accounts Permissions

Token Permissions:

MintPermissions: account capable of minting or issuing new CUSD or WT0 tokens to any account
Blacklisted: account barred from interacting with active CUSD tokens

Regulator Permissions:

Validator: account capable of setting user permissions/roles including MintPermissions and Blacklisted

Architecture Description

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`

Deployment Addresses:

Mainnet (Logic contracts are proxy "implementations", Only the Active contracts can be used):

RegulatorProxyFactory

CarbonDollarProxyFactory

WhitelistedTokenProxyFactory

Regulator (logic)

Regulator (active)

CarbonDollar (logic)

CarbonDollar (active)

WhitelistedToken (logic)

WhitelistedToken (active)

Setting up CUSD token for local

  1. 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.

  1. 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.

Test locally

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

Test deployed contracts on the Ropsten testnet

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.

Ropsten

RegulatorProxyFactory

CarbonDollarProxyFactory

WhitelistedTokenProxyFactory

Regulator (logic)

Regulator (active)

CarbonDollar (logic) (this is now a MetaToken, which extends CarbonDollar)

CarbonDollar (active)

WhitelistedToken (logic)

WhitelistedToken (active)

About

Carbon's Fiat-Backed Currency (smart contracts)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published