Verified contractExactMIT
AdvanceManager
Address0x3819ddce79b484a73f01bfd5fb6c157c665b2e43
- Balance
0 ETH
- Transactions
8
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,463,384
- Creation transaction
- 0xccdab25781…b245ff8493
contracts/src/AdvanceManager.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice Groth16 verifier generated by snarkjs from circuits/advance_eligibility.circom.
/// Public signals: [commitment, advanceCents, monthlyRate, artist, requestId].
interface IGroth16Verifier {
function verifyProof(
uint256[2] calldata pA,
uint256[2][2] calldata pB,
uint256[2] calldata pC,
uint256[5] calldata pubSignals
) external view returns (bool);
}
/// @title AdvanceManager
/// @notice Approves royalty advance requests that come with a valid zero-knowledge proof that the
/// artist's private valuation (NPV of 24 months of forecast royalties at `monthlyRate`)
/// covers the requested advance. Only the proof and the public values reach the chain.
/// @dev MVP: the approval is recorded and an event is emitted. No tokens are transferred.
contract AdvanceManager {
struct Approval {
address artist;
uint64 approvedAt;
uint256 advanceCents;
uint256 monthlyRate;
uint256 commitment;
}
/// @notice Fixed-point scale of `monthlyRate` (10_000 = 1% per month).
uint256 public constant RATE_SCALE = 1_000_000;
/// @notice Forecast length the circuit is compiled for.
uint256 public constant HORIZON_MONTHS = 24;
IGroth16Verifier public immutable verifier;
address public owner;
/// @notice Lowest discount rate the lender accepts. Stops an artist from proving with r = 0.
uint256 public minMonthlyRate;
uint256 public approvalCount;
mapping(uint256 requestId => Approval) private approvals;
event AdvanceApproved(
uint256 indexed requestId,
address indexed artist,
uint256 advanceCents,
uint256 monthlyRate,
uint256 commitment
);
event MinMonthlyRateChanged(uint256 previousRate, uint256 newRate);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
error InvalidProof();
error RequestAlreadyUsed(uint256 requestId);
error RateBelowMinimum(uint256 rate, uint256 minimum);
error RateTooHigh(uint256 rate);
error ZeroAddress();
error ZeroAdvance();
error NotOwner();
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
constructor(IGroth16Verifier verifier_, uint256 minMonthlyRate_) {
if (address(verifier_) == address(0)) revert ZeroAddress();
if (minMonthlyRate_ > RATE_SCALE) revert RateTooHigh(minMonthlyRate_);
verifier = verifier_;
owner = msg.sender;
minMonthlyRate = minMonthlyRate_;
emit OwnershipTransferred(address(0), msg.sender);
emit MinMonthlyRateChanged(0, minMonthlyRate_);
}
/// @notice Submit an advance request with its proof. Anyone may submit (for example a relayer):
/// the proof is bound to `artist`, so the approval can only ever be recorded for that wallet.
/// @param artist wallet the proof was made for
/// @param advanceCents requested advance in US cents
/// @param monthlyRate discount rate used in the proof, scaled by RATE_SCALE
/// @param requestId unique request id; each id can be approved once
/// @param commitment Poseidon hash of the private figures (output of the circuit)
function submitAdvance(
address artist,
uint256 advanceCents,
uint256 monthlyRate,
uint256 requestId,
uint256 commitment,
uint256[2] calldata pA,
uint256[2][2] calldata pB,
uint256[2] calldata pC
) external {
if (artist == address(0)) revert ZeroAddress();
if (advanceCents == 0) revert ZeroAdvance();
if (approvals[requestId].artist != address(0)) revert RequestAlreadyUsed(requestId);
if (monthlyRate < minMonthlyRate) revert RateBelowMinimum(monthlyRate, minMonthlyRate);
uint256[5] memory pubSignals = [commitment, advanceCents, monthlyRate, uint256(uint160(artist)), requestId];
if (!verifier.verifyProof(pA, pB, pC, pubSignals)) revert InvalidProof();
approvals[requestId] = Approval({
artist: artist,
approvedAt: uint64(block.timestamp),
advanceCents: advanceCents,
monthlyRate: monthlyRate,
commitment: commitment
});
approvalCount += 1;
emit AdvanceApproved(requestId, artist, advanceCents, monthlyRate, commitment);
}
function getApproval(uint256 requestId) external view returns (Approval memory) {
return approvals[requestId];
}
function isApproved(uint256 requestId) external view returns (bool) {
return approvals[requestId].artist != address(0);
}
function setMinMonthlyRate(uint256 newRate) external onlyOwner {
if (newRate > RATE_SCALE) revert RateTooHigh(newRate);
emit MinMonthlyRateChanged(minMonthlyRate, newRate);
minMonthlyRate = newRate;
}
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.