# Smart Contract

## Storage :&#x20;

### Constants :&#x20;

```solidity
/** @notice Minimum Pledge duration */
uint256 public constant MIN_PLEDGE_DURATION = 1 weeks;
/** @notice Minimum delegation time when pledging */
uint256 public constant MIN_DELEGATION_DURATION = 2 days;
```

### pledges() :&#x20;

```solidity
/** @notice List of all Pledges */
Pledge[] public pledges;
```

### pledgeOwner(uint256) :&#x20;

```solidity
/** @notice Owner of each Pledge (ordered by index in the pledges list) */
mapping(uint256 => address) public pledgeOwner;
```

### onwerPledges(address) :&#x20;

```solidity
/** @notice List of all Pledges for each owner */
mapping(address => uint256[]) public ownerPledges;
```

### pledgeAvailableRewardAmounts(uint256) :&#x20;

```solidity
/** @notice Amount of rewards available for each Pledge */
// sorted by Pledge index
mapping(uint256 => uint256) public pledgeAvailableRewardAmounts;
```

### votingEscrow() :&#x20;

```solidity
/** @notice Address of the votingToken to delegate */
IVotingEscrow public immutable votingEscrow;
```

### delegationBoost() :&#x20;

```solidity
/** @notice Address of the Delegation Boost contract */
IBoostV2 public immutable delegationBoost;
```

### minAmountRewardToken(address) :&#x20;

```solidity
/** @notice Minimum amount of reward per vote for each reward token */
// Also used to whitelist the tokens for rewards
mapping(address => uint256) public minAmountRewardToken;
```

### rewardTokenTotalAmount(address) :&#x20;

```solidity
/** @notice Total amount held in Pledge for the reward amount */
mapping(address => uint256) public rewardTokenTotalAmount;
```

### protocolFeeRatio() :&#x20;

```solidity
/** @notice ratio of fees to pay the protocol (in BPS) */
uint256 public protocolFeeRatio;
```

### chestAddress() :&#x20;

```solidity
/** @notice Address to receive protocol fees */
address public chestAddress;
```

### minVoteDiff() :&#x20;

```solidity
/** @notice Minimum vote difference for a Pledge */
uint256 public minVoteDiff;
```

## Structs :&#x20;

```solidity
struct Pledge{
    // Target amount of veCRV (balance scaled by Boost v2, fetched as adjusted_balance)
    uint256 targetVotes;
    // Price per vote per week, set by the owner
    uint256 rewardPerVotePerWeek;
    // Address to receive the Boosts
    address receiver;
    // Address of the token given as rewards to Boosters
    address rewardToken;
    // Timestamp of end of the Pledge
    uint64 endTimestamp;
    // Set to true if the Pledge is cancelled, or when closed after the endTimestamp
    bool closed;
}
```

## Events :&#x20;

```solidity
    /** @notice Event emitted when a new Pledge is created */
    event NewPledge(
        address indexed creator,
        address indexed receiver,
        address indexed rewardToken,
        uint256 id,
        uint256 targetVotes,
        uint256 rewardPerVotePerWeek,
        uint256 endTimestamp
    );
    /** @notice Event emitted when a Pledge duration is extended */
    event ExtendPledgeDuration(uint256 indexed pledgeId, uint256 oldEndTimestamp, uint256 newEndTimestamp);
    /** @notice Event emitted when a Pledge reward per vote is increased */
    event IncreasePledgeRewardPerVote(uint256 indexed pledgeId, uint256 oldrewardPerVotePerWeek, uint256 newrewardPerVotePerWeek);
    /** @notice Event emitted when a Pledge is closed */
    event ClosePledge(uint256 indexed pledgeId);
    /** @notice Event emitted when rewards are retrieved from a closed Pledge */
    event RetrievedPledgeRewards(uint256 indexed pledgeId, address receiver, uint256 amount);

    /** @notice Event emitted when an user delegate to a Pledge */
    event Pledged(uint256 indexed pledgeId, address indexed user, uint256 amount, uint256 endTimestamp);

    /** @notice Event emitted when a new reward token is added to the list */
    event NewRewardToken(address indexed token, uint256 minRewardPerWeek);
    /** @notice Event emitted when a reward token parameter is updated */
    event UpdateRewardToken(address indexed token, uint256 minRewardPerWeek);
    /** @notice Event emitted when a reward token is removed from the list */
    event RemoveRewardToken(address indexed token);

    /** @notice Event emitted when the address for the Chest is updated */
    event ChestUpdated(address oldChest, address newChest);
    /** @notice Event emitted when the platform fee is updated */
    event PlatformFeeUpdated(uint256 oldFee, uint256 newFee);
    /** @notice Event emitted when the minimum vote difference value is updated */
    event MinVoteDiffUpdated(uint256 oldMinVoteDiff, uint256 newMinVoteDiff);
```

## View Methods :&#x20;

### nextPledgeIndex() :&#x20;

```solidity
/**
* @notice Amount of Pledges listed in this contract
* @return uint256: Amount of Pledges listed in this contract
*/
function nextPledgeIndex() public view returns(uint256);
```

###

### getUserPledges() :&#x20;

```solidity
/**
* @notice Get all Pledges created by the user
* @param user Address of the user
* @return uint256[]: List of Pledges IDs
*/
function getUserPledges(address user) external view returns(uint256[] memory);
```

### getAllPledges() :&#x20;

```solidity
/**
* @notice Get all the Pledges
* @return Pledge[]: List of Pledge structs
*/
function getAllPledges() external view returns(Pledge[] memory);
```

##

## State-changing Methods :&#x20;

### pledge() :&#x20;

```solidity
/**
* @notice Delegates boost to a given Pledge & receive rewards
* @param pledgeId Pledge to delegate to
* @param amount Amount to delegate
* @param endTimestamp End of delegation
*/
function pledge(uint256 pledgeId, uint256 amount, uint256 endTimestamp) external;
```

### pledgePercent() :&#x20;

```solidity
/**
* @notice Delegates boost (using a percentage of the balance) to a given Pledge & receive rewards
* @param pledgeId Pledge to delegate to
* @param percent Percent of balance to delegate
* @param endTimestamp End of delegation
*/
function pledgePercent(uint256 pledgeId, uint256 percent, uint256 endTimestamp) external;
```

### createPledge() :&#x20;

```solidity
/**
* @notice Creates a new Pledge
* @param receiver Address to receive the boost delegation
* @param rewardToken Address of the token distributed as reward
* @param targetVotes Maximum target of votes to have (own balance + delegation) for the receiver
* @param rewardPerVotePerWeek Amount of reward given for each vote delegation (per week)
* @param endTimestamp End of the Pledge
* @param maxTotalRewardAmount Maximum total reward amount allowed to be pulled by this contract
* @return uint256: Newly created Pledge ID
*/ 
function createPledge(
    address receiver,
    address rewardToken,
    uint256 targetVotes,
    uint256 rewardPerVotePerWeek, // reward/veToken/week
    uint256 endTimestamp,
    uint256 maxTotalRewardAmount
) external returns(uint256);
```

### extendPledge() :&#x20;

```solidity
/**
* @notice Extends the Pledge duration
* @param pledgeId ID of the Pledge
* @param newEndTimestamp New end of the Pledge
* @param maxTotalRewardAmount Maximum added total reward amount allowed to be pulled by this contract
*/
function extendPledge(
    uint256 pledgeId,
    uint256 newEndTimestamp,
    uint256 maxTotalRewardAmount
) external;
```

### increasePledgeRewardPerVote() :&#x20;

```solidity
/**
* @notice Increases the Pledge reward per vote delegated
* @param pledgeId ID of the Pledge
* @param newRewardPerVotePerWeek New amount of reward given for each vote delegation (per week)
* @param maxTotalRewardAmount Maximum added total reward amount allowed to be pulled by this contract
*/
function increasePledgeRewardPerVote(
    uint256 pledgeId,
    uint256 newRewardPerVotePerWeek,
     uint256 maxTotalRewardAmount
) external;
```

### closePledge() :&#x20;

```solidity
/**
* @notice Closes a Pledge and retrieves all non-distributed rewards from a Pledge
* @param pledgeId ID of the Pledge to close
* @param receiver Address to receive the remaining rewards
*/
function closePledge(uint256 pledgeId, address receiver) external;
```

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.paladin.vote/warden-pledge/smart-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
