Bug Bounty Management
The OtaconBountyRegistry smart contract manages bug bounties, staking of collectibles, and distribution of rewards in the Otacon ecosystem. This documentation provides a comprehensive breakdown of all contract functions, including explanations, TypeScript examples (using ethers.js), and simulations to showcase their usage.
1. Contract Initialization
The contract is initialized with important parameters and sets up immutable variables.
Parameters:
otaconToken
: The Otacon ERC20 token.swapRouter
: Uniswap V3 router for token swaps.WETH9
: Wrapped ETH token address.
Ownership: The deployer becomes the contract owner.
2. Modifiers
onlyBountyOwner(uint256 bountyId)
: Restricts function access to the owner of the bounty.
3. Collectible Management Functions
a. setProofCollectibleContract
setProofCollectibleContract
Description: Sets the contract address for the ProofCollectible.
Parameters:
tokenAddress
: Address of the ProofCollectible contract.
TypeScript Example:
Simulation:
Owner calls
setProofCollectibleContract
with the ProofCollectible contract address.The contract updates the
proofCollectible
state variable.
b. setSnippetCollectibleContract
setSnippetCollectibleContract
Description: Sets the contract address for the SnippetCollectible (ERC721).
TypeScript Example:
Simulation:
Owner calls
setSnippetCollectibleContract
with the SnippetCollectible contract address.The contract updates the
snippetCollectible
state variable.
c. setBountyPassCollectibleContract
setBountyPassCollectibleContract
Description: Sets the contract address for the BountyPassCollectible (ERC1155).
TypeScript Example:
Simulation:
Owner calls
setBountyPassCollectibleContract
with the BountyPassCollectible contract address.The contract updates the
bountyPassCollectible
state variable.
d. setMultiplierCollectible
setMultiplierCollectible
Description: Sets the multiplier collectible information for a specific tier.
Parameters:
tier
: Enum value representing the multiplier tier (S, A, B, C, D, F).tokenAddress
: Address of the MultiplierCollectible contract.multiplierValue
: The value of the multiplier (e.g.,2e18
for 2x).collectibleType
: Token ID representing the tier in the ERC1155 contract.
TypeScript Example:
Simulation:
Owner sets up multiplier collectibles for each tier with appropriate values.
The contract stores these configurations for use in staking and reward calculations.
4. Validator Management Functions
a. addValidator
addValidator
Description: Adds a validator to a bounty.
Access Control: Can be called by the bounty owner or the contract owner.
TypeScript Example:
Simulation:
Bounty Owner or Contract Owner adds a validator to a specific bounty.
The validator is added to the
validators
mapping andvalidatorList
array.
b. removeValidator
removeValidator
Description: Removes a validator from a bounty.
TypeScript Example:
Simulation:
Bounty Owner or Contract Owner removes a validator from a specific bounty.
The validator is removed from the
validators
mapping andvalidatorList
array.
5. Bounty Management Functions
a. startBounty
startBounty
Description: Starts a new bounty program with specified parameters and handles the creation fee.
Parameters:
params
: Struct containing bounty details.targetContract
: Address of the contract under scrutiny.rewards
: Array of rewards per severity level.rewardToken
: ERC20 token used for rewards.requireSnippet
: Whether a code snippet is required.targetNetwork
: Network identifier.targetEnvironment
: Environment identifier.validators
: Initial list of validators.
useOtaconToken
: Whether to pay the fee with Otacon tokens.useETH
: Whether to pay the fee with ETH.bountyPassTokenId
: Token ID of the Bounty Pass collectible (if not using Otacon or ETH).
TypeScript Example:
Simulation:
Scenario 1: Using Otacon Token
User approves
otaconFee
amount of Otacon tokens to the contract.Calls
startBounty
withuseOtaconToken = true
.The contract deducts the
otaconFee
from the user's balance.Bounty is created and stored in the contract.
Scenario 2: Using ETH
User sends a transaction with
value = ethFee
.Calls
startBounty
withuseETH = true
.The contract uses half of the ETH for an Otacon token buyback via Uniswap V3.
Bounty is created and stored in the contract.
Scenario 3: Using Bounty Pass Collectible
User must own a Bounty Pass collectible.
Calls
startBounty
withbountyPassTokenId
of the collectible they own.The contract transfers and burns the Bounty Pass collectible.
Bounty is created and stored in the contract.
b. stopBounty
stopBounty
Description: Stops an active bounty.
TypeScript Example:
Simulation:
Bounty Owner calls
stopBounty
.The bounty's
isActive
state is set tofalse
.
c. setBountyReward
setBountyReward
Description: Sets the reward for a specific severity level in a bounty.
TypeScript Example:
Simulation:
Bounty Owner updates the reward amounts for specific severity levels.
d. setProtocolFeePercentage
setProtocolFeePercentage
Description: Sets the protocol fee percentage.
TypeScript Example:
Simulation:
Contract Owner adjusts the protocol fee percentage used in reward calculations.
6. Staking Functions
a. stakeProofCollectible
stakeProofCollectible
Description: Stake a ProofCollectible (ERC721) to a bounty.
TypeScript Example:
Simulation:
User approves the ProofCollectible for transfer.
Calls
stakeProofCollectible
with the bounty ID and collectible ID.The contract transfers the ProofCollectible from the user to itself.
Records the staked collectible in
stakedProofs
.
b. unstakeProofCollectible
unstakeProofCollectible
Description: Unstake a ProofCollectible from a bounty.
TypeScript Example:
Simulation:
User calls
unstakeProofCollectible
.The contract transfers the ProofCollectible back to the user.
Removes the collectible from
stakedProofs
.
c. stakeSnippetCollectible
stakeSnippetCollectible
Description: Stake a SnippetCollectible (ERC721) to a bounty.
TypeScript Example:
Simulation:
User approves and stakes a SnippetCollectible to the bounty.
The contract records the staked snippet in
stakedSnippets
.
d. unstakeSnippetCollectible
unstakeSnippetCollectible
Description: Unstake a SnippetCollectible from a bounty.
TypeScript Example:
Simulation:
User calls
unstakeSnippetCollectible
.The contract transfers the SnippetCollectible back to the user.
Removes the collectible from
stakedSnippets
.
e. stakeMultiplierCollectible
stakeMultiplierCollectible
Description: Stake a MultiplierCollectible (ERC1155) to a bounty.
TypeScript Example:
Simulation:
User approves the MultiplierCollectible for transfer.
Calls
stakeMultiplierCollectible
with the bounty ID, tier, and amount.The contract transfers the specified amount of multiplier collectibles from the user to itself.
Records the staked multipliers in
stakedMultipliers
.
f. unstakeMultiplierCollectible
unstakeMultiplierCollectible
Description: Unstake MultiplierCollectibles from a bounty.
TypeScript Example:
Simulation:
User calls
unstakeMultiplierCollectible
.The contract transfers the specified amount of multiplier collectibles back to the user.
Updates the
stakedMultipliers
andtotalMultiplierValueStaked
.
7. Validation and Reward Functions
a. validateProof
validateProof
Description: Validates a proof collectible, rewarding the bounty hunter and accumulating protocol fees.
TypeScript Example:
Simulation:
Validator calls
validateProof
.The contract checks that the validator is authorized and the proof is staked.
Calculates the reward amounts:
Total Reward: From
bounty.rewards[severity]
.Protocol Fee:
rewardAmount * protocolFeePercentage / 100
.Hunter Reward:
rewardAmount - protocolFee
.
Transfers the hunter reward to the bounty hunter.
Updates
totalProtocolBountyReward
andtotalUnclaimedProtocolRewards
.Burns the proof collectible.
b. claimBountyShare
claimBountyShare
Description: Allows a staker to claim their share of the protocol bounty rewards.
TypeScript Example:
Simulation:
User must have staked a proof and a multiplier.
Calls
claimBountyShare
.The contract calculates the user's share based on their staked multiplier.
Applies a maximum cap (cannot exceed half of the total protocol bounty reward).
Burns the staked multiplier collectibles.
Transfers the calculated share to the user.
c. claimProtocolBountyShare
claimProtocolBountyShare
Description: Allows the protocol owner to claim its share of the protocol bounty rewards.
TypeScript Example:
Simulation:
Contract Owner calls
claimProtocolBountyShare
.The contract calculates the remaining protocol share (cannot exceed half of the total protocol bounty reward).
Transfers the protocol share to the owner.
8. Administrative Functions
a. setFee
setFee
Description: Sets the Otacon or ETH fee for bounty creation.
Parameters:
feeType
: Either"Otacon"
or"ETH"
.fee
: The new fee amount.
TypeScript Example:
Simulation:
Contract Owner adjusts the fee amounts for bounty creation.
b. claimRevenue
claimRevenue
Description: Withdraws accumulated bounty creation fees (Otacon tokens and ETH) to the owner.
TypeScript Example:
Simulation:
Contract Owner calls
claimRevenue
.The contract transfers all Otacon tokens and ETH held as fees to the owner.
c. getBounty
getBounty
Description: Returns all bounty information for a given bounty ID.
TypeScript Example:
Simulation:
User calls
getBounty
to retrieve bounty details.
9. ERC165 and Receiver Functions
supportsInterface
: Indicates support for ERC1155Receiver and ERC721Receiver interfaces.
ERC1155Receiver Functions
onERC1155Received
: Handles receipt of single ERC1155 token type.onERC1155BatchReceived
: Handles receipt of multiple ERC1155 token types.
ERC721Receiver Function
onERC721Received
: Handles receipt of ERC721 tokens.
Note: These functions are called automatically during token transfers to the contract and do not require manual interaction in TypeScript.
10. Fallback Functions
receive
: Allows the contract to receive ETH.fallback
: Fallback function to handle unexpected calls.
Last updated