Custodial System Bootstrap
Grassroots Economics provides a script to quickly deploy all core contracts + a sample Demurrage voucher contract that can be used for training purposes. The default values can be overridden.
Setup
Prerequistes
ge-publish
(https://github.com/grassrootseconomics/ge-publish (opens in a new tab))cast
(https://book.getfoundry.sh/getting-started/installation (opens in a new tab))- Access to an Ethereum node
- Atleast 1 ETH
ℹ️
Some flags have been omitted, refer to both ge-publish and cast "help" for required flags.
Steps
- Publish a token index:
ge-publish p token-index
- Publish a user index:
ge-publish p user-index
- Publish a gas faucet:
ge-publish p faucet
- Publish a period backend for the gas faucet:
ge-publish p period
- Setup the period backend:
# Set the gas faucet as the poker with setPoker(address)
cast send $PERIOD_BACKEND "setPoker(address)" $GAS_FAUCET
# Set the cooldown period after which a user may request for gas again with setPeriod(uint256) [86400=24hrs]
cast send $PERIOD_BACKEND "setPeriod(uint256)" 86400
# Set the balance threshold such that a user can only request for more gas if their balance is less than the threshold at that time
# 0.03 CELO ~= 5 token transfers in the worse network conditions ~= 2 KES [30000000000000000]
cast send $PERIOD_BACKEND "setBalanceThreshold(uint256)" 30000000000000000
- Setup the gas faucet
# Set the top up amount: 0.03 CELO ~= 5 token transfers in the worse network conditions ~= 2 KES [30000000000000000]
cast send $GAS_FAUCET "setAmount(uint256)" 30000000000000000
# Set the period checker pointing it to the period backend
cast send $GAS_FAUCET "setPeriodChecker(address)" $PERIOD_BACKEND
# Set the user index on the gas faucet (This acts as an ACL)
cast send $GAS_FAUCET "setRegistry(address)" $USER_INDEX
# Top up the faucet. This should be done regularly.
cast send --value 10ether $GAS_FAUCET
- Publish a custodial registration proxy
- Remember to reset the system account address after setting up the eth-custodial backend.
# We pass a place holder value i.e your public key as the initial system account address
# We will replace this value later
ge-publish p custodial --faucet $GAS_FAUCET --user-index $USER_INDEX --system-account-address $YOUR_PUBLIC_KEY
- Setup user index
# Add the custodial registration proxy as a writer to the user index
cast send $USER_INDEX "addWriter(address)" $CUSTODIAL_REGISTRATION_PROXY
- Publish a pools index
# A pool index is usually the same as a token index
ge-publish p token-index
- Publish a contracts registry
This is the entry point to discover all other contracts.
ge-publish p registry --identifier AccountIndex --identifier CustodialRegistrationProxy --identifier GasFaucet --identifier TokenIndex --identifier PoolIndex
- Setup the contracts registry
ℹ️
The commented string2bytes32 are fixed. You can use them as your first argument to the set call.
# string to bytes32 identifiers
# cast format-bytes32-string [STRING]
# CustodialRegistrationProxy=0x437573746f6469616c526567697374726174696f6e50726f7879000000000000
# AccountIndex=0x4163636f756e74496e6465780000000000000000000000000000000000000000
# GasFaucet=0x4761734661756365740000000000000000000000000000000000000000000000
# TokenIndex=0x546f6b656e496e64657800000000000000000000000000000000000000000000
# PoolIndex=0x506f6f6c496e6465780000000000000000000000000000000000000000000000
cast send $REGISTRY "set(bytes32,address)" 0x437573746f6469616c526567697374726174696f6e50726f7879000000000000 $CUSTODIAL_REGISTRATION_PROXY
cast send $REGISTRY "set(bytes32,address)" 0x4163636f756e74496e6465780000000000000000000000000000000000000000 $USER_INDEX
cast send $REGISTRY "set(bytes32,address)" 0x546f6b656e496e64657800000000000000000000000000000000000000000000 $TOKEN_INDEX
cast send $REGISTRY "set(bytes32,address)" 0x506f6f6c496e6465780000000000000000000000000000000000000000000000 $POOL_INDEX
cast send $REGISTRY "set(bytes32,address)" 0x4761734661756365740000000000000000000000000000000000000000000000 $GAS_FAUCET
- (Optional) Add a writer to any of the published indexes
# Add a writer to the token index
cast send $TOKEN_INDEX "addWriter(address)" $YOUR_PUBLIC_KEY
- (Optional) Publish some tokens and add them to the tokens index
# Publish a standard ERC20
ge-publish p erc20--name "Kilifi" --symbol "KILIFI"
cast send $TOKEN "mintTo(address,uint256)" $YOUR_PUBLIC_KEY 100000000
cast send $TOKEN_INDEX "add(address)" $TOKEN
- (Optional) To deploy a pool, refer to:
https://software.grassecon.org/smart-contracts/swappool (opens in a new tab)
- Set up custodial registration proxy
ℹ️
The system account can be dumped via the ETH custodial API using the /system endpoint
# Top up the system account
cast send --value 10ether $SYSTEM_ACCOUNT
# Set the new system account on the custodial registration proxy
cast send $CUSTODIAL_REGISTRATION_PROXY "setNewSystemAccount(address)" $SYSTEM_ACCOUNT