Solidity API

X2EarnRewardsPool

_This contract is used by x2Earn apps to reward users that performed sustainable actions. The XAllocationPool contract or other contracts/users can deposit funds into this contract by specifying the app that can access the funds. Admins of x2EarnApps can withdraw funds from the rewards pool, whihch are sent to the team wallet. Reward distributors of a x2Earn app can distribute rewards to users that performed sustainable actions or withdraw funds to the team wallet. The contract is upgradable through the UUPS proxy pattern and UPGRADER_ROLE can authorize the upgrade.

—– Version 2 —– - Added onchain proof and impact tracking —– Version 3 —– - Added VeBetterPassport integration —– Version 4 —– - Updated the X2EarnApps interface to support node endorsement feature —– Version 5 —– - Updated the X2EarnApps interface to support node cooldown functionality_

UPGRADER_ROLE

bytes32 UPGRADER_ROLE

CONTRACTS_ADDRESS_MANAGER_ROLE

bytes32 CONTRACTS_ADDRESS_MANAGER_ROLE

IMPACT_KEY_MANAGER_ROLE

bytes32 IMPACT_KEY_MANAGER_ROLE

constructor

constructor() public

X2EarnRewardsPoolStorage

struct X2EarnRewardsPoolStorage {
  contract IB3TR b3tr;
  contract IX2EarnApps x2EarnApps;
  mapping(bytes32 => uint256) availableFunds;
  mapping(string => uint256) impactKeyIndex;
  string[] allowedImpactKeys;
  contract IVeBetterPassport veBetterPassport;
}

initialize

function initialize(address _admin, address _contractsManagerAdmin, address _upgrader, contract IB3TR _b3tr, contract IX2EarnApps _x2EarnApps) external

initializeV2

function initializeV2(address _impactKeyManager, string[] _initialImpactKeys) external

initializeV3

function initializeV3(address _veBetterPassport) external

onlyRoleOrAdmin

modifier onlyRoleOrAdmin(bytes32 role)

Modifier to check if the user has the required role or is the DEFAULT_ADMIN_ROLE

Parameters

Name Type Description
role bytes32 - the role to check

_authorizeUpgrade

function _authorizeUpgrade(address newImplementation) internal virtual

_Function that should revert when msg.sender is not authorized to upgrade the contract. Called by {upgradeToAndCall}.

Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.

function _authorizeUpgrade(address) internal onlyOwner {}
```_

### deposit

```solidity
function deposit(uint256 amount, bytes32 appId) external returns (bool)

See {IX2EarnRewardsPool-deposit}

withdraw

function withdraw(uint256 amount, bytes32 appId, string reason) external

See {IX2EarnRewardsPool-withdraw}

distributeRewardDeprecated

function distributeRewardDeprecated(bytes32 appId, uint256 amount, address receiver, string proof) external

This function is deprecated and kept for backwards compatibility, will be removed in future versions.

Distribute rewards to a user with a self provided proof.

distributeReward

function distributeReward(bytes32 appId, uint256 amount, address receiver, string) external

the proof argument is unused but kept for backwards compatibility

{IX2EarnRewardsPool-distributeReward}

distributeRewardWithProof

function distributeRewardWithProof(bytes32 appId, uint256 amount, address receiver, string[] proofTypes, string[] proofValues, string[] impactCodes, uint256[] impactValues, string description) external

See {IX2EarnRewardsPool-distributeRewardWithProof}

_distributeReward

function _distributeReward(bytes32 appId, uint256 amount, address receiver) internal

The impact is an array of integers and codes that represent the impact of the action. Each index of the array represents a different impact. The codes are predefined and the values are the impact values. Example: [“carbon”, “water”, “energy”], [100, 200, 300]

See {IX2EarnRewardsPool-distributeReward}

_emitProof

function _emitProof(bytes32 appId, uint256 amount, address receiver, string[] proofTypes, string[] proofValues, string[] impactCodes, uint256[] impactValues, string description) internal

Emits the RewardDistributed event with the provided proofs and impacts.

buildProof

function buildProof(string[] proofTypes, string[] proofValues, string[] impactCodes, uint256[] impactValues, string description) public view virtual returns (string)

see {IX2EarnRewardsPool-buildProof}

_buildProofJson

function _buildProofJson(string[] proofTypes, string[] proofValues) internal pure returns (bytes)

Builds the proof JSON string from the proof data.

Parameters

Name Type Description
proofTypes string[] the proof types
proofValues string[] the proof values

_buildImpactJson

function _buildImpactJson(string[] impactCodes, uint256[] impactValues) internal view returns (bytes)

Builds the impact JSON string from the impact data.

Parameters

Name Type Description
impactCodes string[] the impact codes
impactValues uint256[] the impact values

_isAllowedImpactKey

function _isAllowedImpactKey(string key) internal view returns (bool)

Checks if the key is allowed.

_isValidProofType

function _isValidProofType(string proofType) internal pure returns (bool)

Checks if the proof type is valid.

setX2EarnApps

function setX2EarnApps(contract IX2EarnApps _x2EarnApps) external

Sets the X2EarnApps contract address.

Parameters

Name Type Description
_x2EarnApps contract IX2EarnApps the new X2EarnApps contract

addImpactKey

function addImpactKey(string newKey) external

Adds a new allowed impact key.

Parameters

Name Type Description
newKey string the new key to add

_addImpactKey

function _addImpactKey(string key, struct X2EarnRewardsPool.X2EarnRewardsPoolStorage $) internal

Internal function to add a new allowed impact key.

Parameters

Name Type Description
key string the new key to add
$ struct X2EarnRewardsPool.X2EarnRewardsPoolStorage

removeImpactKey

function removeImpactKey(string keyToRemove) external

Removes an allowed impact key.

Parameters

Name Type Description
keyToRemove string the key to remove

setVeBetterPassport

function setVeBetterPassport(contract IVeBetterPassport _veBetterPassport) external

Sets the VeBetterPassport contract address.

Parameters

Name Type Description
_veBetterPassport contract IVeBetterPassport the new VeBetterPassport contract

availableFunds

function availableFunds(bytes32 appId) external view returns (uint256)

See {IX2EarnRewardsPool-availableFunds}

version

function version() external pure virtual returns (string)

See {IX2EarnRewardsPool-version}

b3tr

function b3tr() external view returns (contract IB3TR)

Retrieves the B3TR token contract.

x2EarnApps

function x2EarnApps() external view returns (contract IX2EarnApps)

Retrieves the X2EarnApps contract.

getAllowedImpactKeys

function getAllowedImpactKeys() external view returns (string[])

Retrieves the allowed impact keys.

veBetterPassport

function veBetterPassport() external view returns (contract IVeBetterPassport)

Retrieves the VeBetterPassport contract.

receive

receive() external payable virtual

Transfers of VET to this contract are not allowed.

fallback

fallback() external payable

Contract does not accept calls/data.

onERC721Received

function onERC721Received(address, address, uint256, bytes) public virtual returns (bytes4)

supported only when safeTransferFrom is used

Transfers of ERC721 tokens to this contract are not allowed.

onERC1155Received

function onERC1155Received(address, address, uint256, uint256, bytes) public virtual returns (bytes4)

Transfers of ERC1155 tokens to this contract are not allowed.

onERC1155BatchReceived

function onERC1155BatchReceived(address, address, uint256[], uint256[], bytes) public virtual returns (bytes4)

Transfers of ERC1155 tokens to this contract are not allowed.