Files
aitbc/packages/solidity/aitbc-token/contracts/AIToken.sol
aitbc 625c1b7812
Some checks failed
Integration Tests / test-service-integration (push) Successful in 2m16s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 25s
Package Tests / Python package - aitbc-core (push) Successful in 22s
Package Tests / Python package - aitbc-crypto (push) Successful in 14s
Package Tests / Python package - aitbc-sdk (push) Successful in 18s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 6s
Package Tests / JavaScript package - aitbc-token (push) Successful in 21s
Production Tests / Production Integration Tests (push) Failing after 10s
Python Tests / test-python (push) Failing after 2m41s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 16s
Smart Contract Tests / lint-solidity (push) Successful in 12s
ci: clean up CI workflows and fix package dependencies
- Simplified npm install commands in CI workflows by removing fallback logic
- Added aitbc-crypto local dependency installation for aitbc-sdk in package-tests.yml
- Removed aitbc-token specific Hardhat dependency workarounds from package-tests.yml
- Fixed bare except clause in agent_daemon.py to catch specific json.JSONDecodeError
- Moved aitbc-crypto from poetry.dependencies to standard dependencies in aitbc-sdk
- Fixed MyPy type errors in receip
2026-04-19 19:24:09 +02:00

77 lines
2.6 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
/// @title AIToken
/// @notice ERC20 token that mints units for providers based on attested compute receipts
contract AIToken is ERC20, AccessControl {
using ECDSA for bytes32;
using MessageHashUtils for bytes32;
bytes32 public constant COORDINATOR_ROLE = keccak256("COORDINATOR_ROLE");
bytes32 public constant ATTESTOR_ROLE = keccak256("ATTESTOR_ROLE");
/// @notice Tracks consumed receipt hashes to prevent replay
mapping(bytes32 => bool) public consumedReceipts;
event ReceiptConsumed(
bytes32 indexed receiptHash,
address indexed provider,
uint256 units,
address indexed attestor
);
constructor(address admin) ERC20("AIToken", "AIT") {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
/// @notice Mint tokens for a provider when coordinator submits a valid attested receipt
/// @param provider Address of the compute provider receiving minted tokens
/// @param units Amount of tokens to mint
/// @param receiptHash Unique hash representing the off-chain receipt
/// @param signature Coordinator-attested signature authorizing the mint
function mintWithReceipt(
address provider,
uint256 units,
bytes32 receiptHash,
bytes calldata signature
) external onlyRole(COORDINATOR_ROLE) {
require(provider != address(0), "invalid provider");
require(units > 0, "invalid units");
require(!consumedReceipts[receiptHash], "receipt already consumed");
bytes32 digest = _mintDigest(provider, units, receiptHash);
address attestor = digest.recover(signature);
require(hasRole(ATTESTOR_ROLE, attestor), "invalid attestor signature");
consumedReceipts[receiptHash] = true;
_mint(provider, units);
emit ReceiptConsumed(receiptHash, provider, units, attestor);
}
/// @notice Helper to compute the signed digest required for minting
function mintDigest(
address provider,
uint256 units,
bytes32 receiptHash
) external view returns (bytes32) {
return _mintDigest(provider, units, receiptHash);
}
function _mintDigest(
address provider,
uint256 units,
bytes32 receiptHash
) internal view returns (bytes32) {
bytes32 structHash = keccak256(
abi.encode(block.chainid, address(this), provider, units, receiptHash)
);
return structHash.toEthSignedMessageHash();
}
}