RepoTokenLinkedList.sol#RepoTokenLinkedList
Inherits: Initializable, UUPSUpgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable, RepoTokenLinkedListStorageV1
A marketplace for trading repo tokens
Implements upgradeable patterns and various security features
State Variables
TERM_CONTROLLER
ITermController public immutable TERM_CONTROLLER;
REPO_TOKEN_LINKED_LIST_EVENT_EMITTER
RepoTokenLinkedListEventEmitter public immutable REPO_TOKEN_LINKED_LIST_EVENT_EMITTER;
ADMIN_ROLE
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
DEVOPS_ROLE
bytes32 public constant DEVOPS_ROLE = keccak256("DEVOPS_ROLE");
RATE_PRECISION
uint256 public constant RATE_PRECISION = 1e18;
MAX_MARKUP
uint256 public constant MAX_MARKUP = 2e16;
REDEMPTION_VALUE_PRECISION
uint256 public constant REDEMPTION_VALUE_PRECISION = 1e18;
THREESIXTY_DAYCOUNT_SECONDS
uint256 public constant THREESIXTY_DAYCOUNT_SECONDS = 360 days;
USDC
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
WETH
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
Functions
constructor
Contract constructor
constructor(address termController, address repoTokenLinkedListEventEmitter);
Parameters
termController
address
Address of the term controller contract
repoTokenLinkedListEventEmitter
address
Address of the event emitter contract
initialize
Initializes the contract with admin and devops roles
Sets up roles and initializes the contract using OpenZeppelin's upgradeable pattern
See: https://docs.openzeppelin.com/contracts/4.x/upgradeable
function initialize(address discountRateAdapter_, address adminWallet_, address devopsWallet_) external initializer;
Parameters
discountRateAdapter_
address
The address of the discount rate oracle
adminWallet_
address
The address to be granted the admin role
devopsWallet_
address
The address to be granted the devops role
onlyValidatedRepoToken
Modifier to check if a repo token is valid
modifier onlyValidatedRepoToken(address repoToken);
setRepoTokenBlacklist
Sets the blacklist status for a repo token
function setRepoTokenBlacklist(address repoToken, bool blacklisted) external onlyRole(ADMIN_ROLE);
Parameters
repoToken
address
The address of the repo token
blacklisted
bool
The blacklist status to set
setDiscountRateAdapter
Sets a new discount rate adapter
function setDiscountRateAdapter(address newAdapter) external onlyRole(ADMIN_ROLE);
Parameters
newAdapter
address
The address of the new discount rate adapter
setDiscountRateMarkup
Sets a new value for the discount rate markup
Only callable by accounts with the ADMIN_ROLE
function setDiscountRateMarkup(uint256 newMarkup) external onlyRole(ADMIN_ROLE);
Parameters
newMarkup
uint256
The new markup value to set
manageMinimumListing
function manageMinimumListing(address token, uint256 amount) external onlyRole(ADMIN_ROLE);
pause
Pauses the contract
function pause() external onlyRole(ADMIN_ROLE);
unpause
Unpauses the contract
function unpause() external onlyRole(ADMIN_ROLE);
createListing
Creates a new listing for a repo token
function createListing(address repoToken, uint256 amount)
external
nonReentrant
whenNotPaused
onlyValidatedRepoToken(repoToken);
Parameters
repoToken
address
The address of the repo token to list
amount
uint256
The amount of tokens to list
purchase
Allows a user to purchase repo tokens
function purchase(uint256 desiredAmount, address repoToken)
external
nonReentrant
whenNotPaused
onlyValidatedRepoToken(repoToken);
Parameters
desiredAmount
uint256
The amount of tokens to purchase
repoToken
address
The address of the repo token to purchase
swapExactPurchaseForRepo
Allows a user to purchase repo tokens
function swapExactPurchaseForRepo(uint256 purchaseTokenAmount, address repoToken)
external
nonReentrant
whenNotPaused
onlyValidatedRepoToken(repoToken);
Parameters
purchaseTokenAmount
uint256
The amount of purchase tokens to spend in purchase
repoToken
address
The address of the repo token to purchase
_purchase
Internal function to handle the purchase logic
function _purchase(address repoToken, address purchaseToken, uint256 desiredAmount, uint256 pricePerToken) private;
Parameters
repoToken
address
The address of the repo token to purchase
purchaseToken
address
The address of the token used for purchase
desiredAmount
uint256
The amount of tokens to purchase
pricePerToken
uint256
The price per token
_emitAndTransfer
function _emitAndTransfer(
uint256 currentListing,
address purchaseToken,
address seller,
address token,
uint256 purchaseAmount,
uint256 cost
) private;
cancelListing
Allows a seller to cancel their listing
function cancelListing(uint256 listingId, bool skipRedeem) public nonReentrant whenNotPaused;
Parameters
listingId
uint256
The ID of the listing to cancel
skipRedeem
bool
Whether to skip the redeem process
batchCancelListings
Repotokens can be redeemed by anyone on behalf of any third-party
function batchCancelListings(uint256[] calldata listingIds, bool skipRedeem) external;
removeListing
Internal function to remove a listing
function removeListing(address repoToken, uint256 listingId) internal;
Parameters
repoToken
address
The address of the repo token
listingId
uint256
The ID of the listing to remove
getListing
Retrieves the details of a listing
function getListing(uint256 listingId) external view returns (address seller, address token, uint256 amount);
Parameters
listingId
uint256
The ID of the listing to retrieve
Returns
seller
address
The address of the seller
token
address
The address of the token being sold
amount
uint256
The amount of tokens being sold
getTotalListings
Gets the total number of active listings
function getTotalListings(address repoToken) external view returns (uint256);
Parameters
repoToken
address
The address of the repo token
Returns
<none>
uint256
The total number of listings
isRepoTokenValid
Checks if a repo token is valid
function isRepoTokenValid(address repoToken) public view returns (bool);
Parameters
repoToken
address
The address of the repo token to check
Returns
<none>
bool
bool indicating if the repo token is valid
_authorizeUpgrade
Ensures only authorized addresses can upgrade the contract
Overrides the UUPSUpgradeable _authorizeUpgrade function to include role checks.
required override by the OpenZeppelin UUPS module
function _authorizeUpgrade(address) internal view override onlyRole(DEVOPS_ROLE);
Parameters
<none>
address
Last updated