This documentation provides detailed instructions on how to use and deploy the KolektivoNetworkBadges
smart contract using Foundry.
- Foundry installed
- OpenZeppelin Contracts
The KolektivoNetworkBadges
contract is an ERC1155 token that represents badges in the Kolektivo network. Each badge level requires a certain number of Kolektivo Network Stamps (ERC20 token) to mint. Users must mint badge levels sequentially and cannot mint the same level more than once.
- KolektivoNetworkBadges: ERC1155 token contract for badges.
- KolektivoNetworkStamps: ERC20 token contract representing Kolektivo Network Stamps.
To deploy the KolektivoNetworkBadges
and KolektivoNetworkStamps
contracts, follow these steps:
-
Install Foundry:
If you haven't already installed Foundry, follow the installation instructions here.
-
Prepare the Deployment Script:
Create a
Deploy.sol
script in thescript
folder:// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; import {Script, console} from "forge-std/Script.sol"; import {KolektivoNetworkBadges} from "../src/KolektivoNetworkBadges.sol"; import {KolektivoNetworkStamps} from "../src/KolektivoNetworkStamps.sol"; contract Deploy is Script { function setUp() public {} function run() public { uint256 DECIMALS = 1e18; vm.broadcast(); uint256[] memory points = new uint256[](3); points[0] = 1 * DECIMALS; points[1] = 5 * DECIMALS; points[2] = 10 * DECIMALS; KolektivoNetworkStamps stamps = new KolektivoNetworkStamps( address(this) ); KolektivoNetworkBadges badges = new KolektivoNetworkBadges( address(this), stamps, points ); console.log("Stamps deployed at: ", address(stamps)); console.log("Badges deployed at: ", address(badges)); } }
-
Compile the Contracts:
Compile the contracts using Foundry:
forge build
-
Run the Deployment Script:
Use Foundry to run the deployment script:
forge script script/Deploy.sol --rpc-url <YOUR_RPC_URL> --private-key <YOUR_PRIVATE_KEY> --broadcast
- The
KolektivoNetworkFactory
contract is responsible for deployingKolektivoNetworkBadges
andKolektivoNetworkStamps
contracts. - It stores the addresses of the deployed contracts for later retrieval.
- The
createKolektivoNetworkBadges
function deploys a newKolektivoNetworkBadges
contract and stores its address along with the address of the associated ERC20 contract. - The
createKolektivoNetworkStamps
function deploys a newKolektivoNetworkStamps
contract and stores its address. - The
getBadgesContracts
andgetStampsContracts
functions return the addresses of the deployedKolektivoNetworkBadges
andKolektivoNetworkStamps
contracts respectively.
-
Setup Function:
- Initializes any required setup. Currently, it is empty.
-
Run Function:
- Deploys the
KolektivoNetworkStamps
contract. - Deploys the
KolektivoNetworkBadges
contract with the address of theKolektivoNetworkStamps
contract and the initial points required for each badge level. - Logs the deployed contract addresses.
- Deploys the
-
Constructor:
constructor( address initialOwner, IERC20 kolektivoNetworkPoints, uint256[] memory initialPointsPerTier ) ERC1155("") Ownable(initialOwner) { _setURI("https://kolektivo.network/badges/{id}.json"); _kolektivoNetworkPoints = kolektivoNetworkPoints; _setInitialPointsPerTier(initialPointsPerTier); }
Deploy the contract with the initial owner, the address of the Kolektivo Network Points contract, and an array of initial points required for each tier.
-
setURI(string memory newuri):
Sets the base URI for all token types.
function setURI(string memory newuri) public onlyOwner { _setURI(newuri); }
-
mint(address account, uint256 id):
Mints a new badge token for the specified account, mind the id is the level you want to mint (starts on 1, SO IMPORTANT).
function mint( address account, uint256 id ) public { require(id > 0 && id <= maxBadgeLevel, "Invalid badge level"); require( _kolektivoNetworkPoints.balanceOf(account) >= pointsPerTier[id - 1], "Insufficient points for this badge level" ); require( _lastMintedLevel[account] + 1 == id, "Levels must be minted sequentially" ); _mint(account, id, 1, ""); _lastMintedLevel[account] = id; }
-
setPointsRequired(uint256 level, uint256 points):
Sets the points required for a specific level.
function setPointsRequired( uint256 level, uint256 points ) external onlyOwner { require( level <= maxBadgeLevel + 1, "The level must be the next one in the sequence or lower." ); if (level > 1) { require( points > pointsPerTier[level - 2], "Points must be in ascending order" ); } if (level <= maxBadgeLevel && level < pointsPerTier.length) { require( points < pointsPerTier[level], "Points must be in ascending order" ); } if (level > maxBadgeLevel) { pointsPerTier.push(points); maxBadgeLevel = level; } else { pointsPerTier[level - 1] = points; } }
-
getPointsRequired(uint256 level):
Returns the points required for a specific level.
function getPointsRequired(uint256 level) external view returns (uint256) { require(level > 0 && level <= maxBadgeLevel, "Invalid badge level"); return pointsPerTier[level - 1]; }
-
getLastMintedLevel(address account):
Returns the last badge level minted by the specified account.
function getLastMintedLevel(address account) external view returns (uint256) { return _lastMintedLevel[account]; }
The deployment script (Deploy.sol
) initializes and deploys the KolektivoNetworkStamps
and KolektivoNetworkBadges
contracts.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {KolektivoNetworkBadges} from "../src/KolektivoNetworkBadges.sol";
import {KolektivoNetworkStamps} from "../src/KolektivoNetworkStamps.sol";
contract Deploy is Script {
function setUp() public {}
function run() public {
uint256 DECIMALS = 1e18;
vm.broadcast();
uint256[] memory points = new uint256[](3);
points[0] = 1 * DECIMALS;
points[1] = 5 * DECIMALS;
points[2] = 10 * DECIMALS;
KolektivoNetworkStamps stamps = new KolektivoNetworkStamps(
address(this)
);
KolektivoNetworkBadges badges = new KolektivoNetworkBadges(
address(this),
stamps,
points
);
console.log("Stamps deployed at: ", address(stamps));
console.log("Badges deployed at: ", address(badges));
}
}
-
Setup Function:
- Initializes any required setup. Currently, it is empty.
-
Run Function:
- Deploys the
KolektivoNetworkStamps
contract. - Deploys the
KolektivoNetworkBadges
contract with the address of theKolektivoNetworkStamps
contract and the initial points required for each badge level. - Logs the deployed contract addresses.
- Deploys the
This documentation provides a detailed guide on how to use and deploy the KolektivoNetworkBadges
smart contract using Foundry. Follow the steps outlined to successfully deploy and interact with the contract. If you encounter any issues or have further questions, please refer to the official OpenZeppelin and Foundry documentation or reach out to the Kolektivo network support team.