GoodDocs
Search…
Core Contracts & API
This page provides contract addresses for key components of GoodDollar protocol.

Contracts & API

GoodDollar Protocol is deployed on both the Ethereum mainnet and on the Fuse sidechain. Contracts like the GoodReserve are only on Mainnet, and other contracts like the UBIScheme are only on the Fuse sidechain. Certain contracts, such as the DAO and G$ Token contracts, are deployed on both networks.

Core Contracts

GoodDollar G$ ERC-20

The GoodDollar G$ token follows the ERC-20 token standard and also supports ERC-677.

Identity

The identity contract controls addresses that are whitelisted to "Claim" UBI.
    Face Verification GoodDollar currently whitelists users based on a user proving "uniqueness" by signing up with a live and unique face. All image data and details are anonymized in order to allow the user to create a new account in case he is unable to recover his wallet. Facial details are deleted after authenticationPeriod and users are required to perform face verification again every authenticationPeriod days.
    Social Profile Each blockchain address is linked to the user's public profile as created in the wallet. The DID is the node id in the public p2p GunDB database. Mappings from wallet address to DID are held in addrTODID
1
/*
2
* @dev Returns true if given address has been added to whitelist
3
* @param account the address to check
4
* @return a bool indicating weather the address is present in whitelist
5
*/
6
function isWhitelisted(address account) public view returns (bool)
7
8
/*
9
* @dev Function that gives the date the given user was added
10
* @param account The address to check
11
* @return The date the address was added
12
*/
13
function lastAuthenticated(address account) public view returns (uint256)
14
15
/* the number of days an authentication is valid for*/
16
uint256 public authenticationPeriod
17
18
mapping(address => string) public addrToDID;
Copied!

GoodStaking

Supporters / stakers can stake crypto which is then sent to permissionless protocols which earn interest. The FundManager has permissions to collect interest-earned from this contract.
1
/**
2
* @dev Allows a staker to deposit DAI tokens. Notice that `approve` is
3
* needed to be executed before the execution of this method.
4
* Can be executed only when the contract is not paused.
5
* @param _amount The amount of DAI to stake
6
*/
7
function stakeDAI(uint256 _amount) public whenNotPaused
8
9
/**
10
* @dev Withdraws the sender staked DAI.
11
*/
12
function withdrawStake() public
Copied!

GoodReserve

The GoodReserve mints G$ based on the interest transferred from the FundManager. Only the FundManager can trigger minting. The GoodReserve also acts as the GoodDollar liquidity pool and AMM (Automatic Market Maker) and enables methods to buy and sell G$s.
1
/**
2
* @dev Converts `buyWith` tokens to GD tokens and updates the bonding curve params.
3
* `buy` occurs only if the GD return is above the given minimum. It is possible
4
* to buy only with cDAI and when the contract is set to active.
5
* MUST `approve` prior this action to allow this contract to accomplish the
6
* conversion.
7
* @param _buyWith The tokens that should be converted to GD tokens
8
* @param _tokenAmount The amount of `buyWith` tokens that should be converted to GD tokens
9
* @param _minReturn The minimum allowed return in GD tokens
10
* @return (gdReturn) How much GD tokens were transferred
11
*/
12
function buy(ERC20 _buyWith,uint256 _tokenAmount,uint256 _minReturn) public requireActive onlyCDai(_buyWith) returns (uint256)
13
14
/**
15
* @dev Converts GD tokens to `sellTo` tokens and update the bonding curve params.
16
* `sell` occurs only if the token return is above the given minimum. Notice that
17
* there is a contribution amount from the given GD that remains in the reserve.
18
* It is only possible to sell to cDAI and only when the contract is set to
19
* active. MUST make call to G$ `approve` prior to this action to allow this
20
* contract to accomplish the conversion.
21
* @param _sellTo The tokens that will be received after the conversion
22
* @param _gdAmount The amount of GD tokens that should be converted to `_sellTo` tokens
23
* @param _minReturn The minimum allowed `sellTo` tokens return
24
* @return (tokenReturn) How much `sellTo` tokens were transferred
25
*/
26
27
function sell(
28
ERC20 _sellTo,
29
uint256 _gdAmount,
30
uint256 _minReturn
31
) public requireActive onlyCDai(_sellTo) returns (uint256)
32
33
/**
34
* @dev Current price of GD in `token`. currently only cDAI is supported.
35
* @param _token The desired reserve token to have
36
* @return price of GD
37
*/
38
function currentPrice(ERC20 _token) public view returns (uint256)
Copied!

GoodFundManager

Has permissions to collect interest from the GoodStaking contract and permissions to tell GoodReserve to mint. Anyone can trigger the collection and minting process
1
/**
2
* @dev Collects UBI interest in cDai from a given staking contract and transfers
3
* that interest to the reserve contract. Then transfers the gd
4
* received from the reserve contract back to the staking contract and to the
5
* bridge, which locks the funds and then same amount of G$ tokens are minted to the
6
* ubiRecipient address on the sidechain
7
*
8
* @param _staking Contract that implements `collectUBIInterest` and transfer cDai to
9
* a given address. The given address should be the same whitelisted `reserve`
10
* address in the current contract, in case that the given staking contract transfers
11
* the funds to another contract, zero GD tokens will be minted by the reserve contract.
12
* Emits `FundsTransferred` event in case which interest has been passed to the `reserve`
13
*/
14
function transferInterest(StakingContract _staking)
15
public
16
requireActive
17
reserveHasInitialized
18
requireDAOContract(address(_staking))
Copied!

UBIScheme

Holds all the G$s that were transferred via bridge from the FundManager. The pool of G$s is divided equally by the amount of current active users, and distributed every day. Each active user can then "claim" his quota. If a user fails to claim his quota it becomes part of the next day's pool of G$ to be distributed as basic income.
1
/**
2
* @dev Checks the amount which the sender address is eligible to claim for,
3
* regardless if they have been whitelisted or not.
4
* @return The amount of GD tokens the address can claim.
5
*/
6
function checkEntitlement() public view requireActive returns (uint256)
7
8
/**
9
* @dev Function for claiming UBI. Requires contract to be active and claimer to be whitelisted.
10
* Calls distributionFormula, calculats the amount the caller can claim, and transfers the amount
11
* to the caller. Emits the address of caller and amount claimed.
12
* @return A bool indicating if UBI was claimed
13
*/
14
function claim() public requireActive onlyWhitelisted returns (bool)
15
16
/**
17
* @dev In order to update users from active to inactive, we give out incentive to people
18
* to update the status of inactive users, this action is called "Fishing". Anyone can
19
* send a tx to the contract to mark inactive users. The "fisherman" receives a reward
20
* equal to the daily UBI (ie instead of the “fished” user). User that “last claimed” > 14
21
* can be "fished" and made inactive (reduces active users count by one). Requires
22
* contract to be active.
23
* @param _account to fish
24
* @return A bool indicating if UBI was fished
25
*/
26
function fish(address _account) public requireActive returns (bool)
27
28
/**
29
* @dev executes `fish` with multiple addresses. emits the number of users from the given
30
* array who actually been tried being fished.
31
* @param _accounts to fish
32
* @return A bool indicating if all the UBIs were fished
33
*/
34
function fishMulti(address[] memory _accounts)
Copied!

OneTimePayments

Payments on the GoodDollar wallet are done via payment links. G$s are held in escrow and the recipient can retrieve the funds if he has the key. While the money is in escrow the sender can choose to cancel the payment and retrieve the funds. Based on Celo's payments contract.
1
/*
2
* @dev ERC677 on token transfer function. When transferAndCall is called on this contract,
3
* this function is called, depositing the payment amount under the hash of the given bytes.
4
* Reverts if hash is already in use. Can only be called by token contract.
5
* @param sender the address of the sender
6
* @param value the amount to deposit
7
* @param data The given paymentId which should be a fresh public key
8
*/
9
10
to deposit a payment to a one time payment address call:
11
GoodDollar.transferAndCall(value,data) this will trigger OneTimePayments onTokenTransfer
12
13
/* @dev Withdrawal function.
14
* allows the sender that proves ownership of paymentId to withdraw
15
* @param paymentId the address of the public key that the
16
* rightful receiver of the payment knows the private key to
17
* @param signature the signature of a the message containing the msg.sender address signed
18
* with the private key.
19
*/
20
function withdraw(address paymentId, bytes memory signature) public onlyRegistered
21
22
/* @dev Cancel function
23
* allows only creator of payment to cancel
24
* @param paymentId The paymentId of the payment to cancelæ
25
*/
26
function cancel(address paymentId) public
Copied!

DonationsStaking

Any ETH/DAI sent to this contract address is donated to the GoodDollar DAO and will generate interest to fund UBI. The funds are periodically staked in the GoodStaking contract by calling the stakeDonationsmethod.
1
uint256 public totalETHDonated;
2
uint256 public totalDAIDonated;
3
4
event DonationStaked(
5
address caller,
6
uint256 stakedDAI,
7
uint256 ethDonated,
8
uint256 daiDonated
9
);
10
11
/**
12
* @dev stake available funds. It
13
* take balance in eth and buy DAI from uniswap then stake outstanding DAI balance.
14
* anyone can call this.
15
* @param _minDAIAmount enforce expected return from uniswap when converting eth balance to DAI
16
*/
17
function stakeDonations(uint256 _minDAIAmount) public payable isActive {
18
uint256 daiDonated = DAI.balanceOf(address(this));
19
uint256 ethDonated = _buyDAI(_minDAIAmount);
20
21
uint256 daiBalance = DAI.balanceOf(address(this));
22
require(daiBalance > 0, "no DAI to stake");
23
24
stakingContract.stakeDAI(daiBalance);
25
totalETHDonated += ethDonated;
26
totalDAIDonated += daiDonated;
27
emit DonationStaked(msg.sender, daiBalance, ethDonated, daiDonated);
28
}
29
30
/**
31
* @dev total DAI value staked
32
* @return DAI value staked
33
*/
34
function totalStaked() public view returns (uint256) {
35
Staking.Staker memory staker = stakingContract.stakers(address(this));
36
return staker.stakedDAI;
37
}
Copied!

GoodMarketMaker

Helper contract for the GoodReserve.

ContributionCalculation

Helper contract for calculating the exit contribution (ie when selling G$ back to the reserve)

FirstClaimPool

Helper contract for UBIScheme. Manually funded by the Foundation to give 1G$ for "inactive" users when they claim. Since a new user (inactive) becomes active and eligible to claim UBI only in the next UBI epoch. So for new users not go empty handed on their first claim we give out a 1G$.

AdminWallet

Helper contract for our backend servers to whitelist users and to fill their Fuse network gas.

Token Bridge Contracts

Bridge contracts were developed by Fuse.
Note: for regular users it is recommended to use FuseSwap Bridge in order to avoid losing your tokens (help). FuseSwap Bridge: Mainnet -> Fuse | Fuse -> Mainnet.
Contract
Mainnet
Fuse
Source Code

DAO Contracts

DAO contracts were developed by DAOStack
Last modified 14d ago