Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|
7129413 | 60 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
SortedTroves
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "./Interfaces/ISortedTroves.sol"; import "./Interfaces/IAddressesRegistry.sol"; import "./Interfaces/ITroveManager.sol"; import "./Interfaces/IBorrowerOperations.sol"; // ID of head & tail of the list. Callers should stop iterating with `getNext()` / `getPrev()` // when encountering this node ID. uint256 constant ROOT_NODE_ID = 0; /* * A sorted doubly linked list with nodes sorted in descending order. * * Nodes map to active Troves in the system - the ID property is the address of a Trove owner. * Nodes are ordered according to the borrower's chosen annual interest rate. * * The list optionally accepts insert position hints. * * The annual interest rate is stored on the Trove struct in TroveManager, not directly on the Node. * * A node need only be re-inserted when the borrower adjusts their interest rate. Interest rate order is preserved * under all other system operations. * * The list is a modification of the following audited SortedDoublyLinkedList: * https://github.com/livepeer/protocol/blob/master/contracts/libraries/SortedDoublyLL.sol * * Changes made in the Bold implementation: * * - Keys have been removed from nodes * * - Ordering checks for insertion are performed by comparing an interest rate argument to the Trove's current interest rate. * * - Public functions with parameters have been made internal to save gas, and given an external wrapper function for external access */ contract SortedTroves is ISortedTroves { string public constant NAME = "SortedTroves"; // Constants used for documentation purposes uint256 constant UNINITIALIZED_ID = 0; uint256 constant BAD_HINT = 0; event TroveManagerAddressChanged(address _troveManagerAddress); event BorrowerOperationsAddressChanged(address _borrowerOperationsAddress); address public immutable borrowerOperationsAddress; ITroveManager public immutable troveManager; // Information for a node in the list struct Node { uint256 nextId; // Id of next node (smaller interest rate) in the list uint256 prevId; // Id of previous node (larger interest rate) in the list BatchId batchId; // Id of this node's batch manager, or zero in case of non-batched nodes bool exists; } struct Batch { uint256 head; uint256 tail; } struct Position { uint256 prevId; uint256 nextId; } // Current size of the list uint256 public size; // Stores the forward and reverse links of each node in the list. // nodes[ROOT_NODE_ID] holds the head and tail of the list. This avoids the need for special // handling when inserting into or removing from a terminal position (head or tail), inserting // into an empty list or removing the element of a singleton list. mapping(uint256 => Node) public nodes; // Lookup batches by the address of their manager mapping(BatchId => Batch) public batches; constructor(IAddressesRegistry _addressesRegistry) { // Technically, this is not needed as long as ROOT_NODE_ID is 0, but it doesn't hurt nodes[ROOT_NODE_ID].nextId = ROOT_NODE_ID; nodes[ROOT_NODE_ID].prevId = ROOT_NODE_ID; troveManager = ITroveManager(_addressesRegistry.troveManager()); borrowerOperationsAddress = address(_addressesRegistry.borrowerOperations()); emit TroveManagerAddressChanged(address(troveManager)); emit BorrowerOperationsAddressChanged(borrowerOperationsAddress); } // Insert an entire list slice (such as a batch of Troves sharing the same interest rate) // between adjacent nodes `_prevId` and `_nextId`. // Can be used to insert a single node by passing its ID as both `_sliceHead` and `_sliceTail`. function _insertSliceIntoVerifiedPosition(uint256 _sliceHead, uint256 _sliceTail, uint256 _prevId, uint256 _nextId) internal { nodes[_prevId].nextId = _sliceHead; nodes[_sliceHead].prevId = _prevId; nodes[_sliceTail].nextId = _nextId; nodes[_nextId].prevId = _sliceTail; } function _insertSlice( ITroveManager _troveManager, uint256 _sliceHead, uint256 _sliceTail, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) internal { if (!_validInsertPosition(_troveManager, _annualInterestRate, _prevId, _nextId)) { // Sender's hint was not a valid insert position // Use sender's hint to find a valid insert position (_prevId, _nextId) = _findInsertPosition(_troveManager, _annualInterestRate, _prevId, _nextId); } _insertSliceIntoVerifiedPosition(_sliceHead, _sliceTail, _prevId, _nextId); } /* * @dev Add a Trove to the list * @param _id Trove's id * @param _annualInterestRate Trove's annual interest rate * @param _prevId Id of previous Trove for the insert position * @param _nextId Id of next Trove for the insert position */ function insert(uint256 _id, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external override { _requireCallerIsBorrowerOperations(); require(!contains(_id), "SortedTroves: List already contains the node"); require(_id != ROOT_NODE_ID, "SortedTroves: _id cannot be the root node's ID"); _insertSlice(troveManager, _id, _id, _annualInterestRate, _prevId, _nextId); nodes[_id].exists = true; ++size; } // Remove the entire slice between `_sliceHead` and `_sliceTail` from the list while keeping // the removed nodes connected to each other, such that they can be reinserted into a different // position with `_insertSlice()`. // Can be used to remove a single node by passing its ID as both `_sliceHead` and `_sliceTail`. function _removeSlice(uint256 _sliceHead, uint256 _sliceTail) internal { nodes[nodes[_sliceHead].prevId].nextId = nodes[_sliceTail].nextId; nodes[nodes[_sliceTail].nextId].prevId = nodes[_sliceHead].prevId; } /* * @dev Remove a non-batched Trove from the list * @param _id Trove's id */ function remove(uint256 _id) external override { _requireCallerIsBOorTM(); require(contains(_id), "SortedTroves: List does not contain the id"); require(!isBatchedNode(_id), "SortedTroves: Must use removeFromBatch() to remove batched node"); _removeSlice(_id, _id); delete nodes[_id]; --size; } function _reInsertSlice( ITroveManager _troveManager, uint256 _sliceHead, uint256 _sliceTail, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) internal { if (!_validInsertPosition(_troveManager, _annualInterestRate, _prevId, _nextId)) { // Sender's hint was not a valid insert position // Use sender's hint to find a valid insert position (_prevId, _nextId) = _findInsertPosition(_troveManager, _annualInterestRate, _prevId, _nextId); } // Check that the new insert position isn't the same as the existing one if (_nextId != _sliceHead && _prevId != _sliceTail) { _removeSlice(_sliceHead, _sliceTail); _insertSliceIntoVerifiedPosition(_sliceHead, _sliceTail, _prevId, _nextId); } } /* * @dev Re-insert a non-batched Trove at a new position, based on its new annual interest rate * @param _id Trove's id * @param _newAnnualInterestRate Trove's new annual interest rate * @param _prevId Id of previous Trove for the new insert position * @param _nextId Id of next Trove for the new insert position */ function reInsert(uint256 _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external override { _requireCallerIsBorrowerOperations(); require(contains(_id), "SortedTroves: List does not contain the id"); require(!isBatchedNode(_id), "SortedTroves: Must not reInsert() batched node"); _reInsertSlice(troveManager, _id, _id, _newAnnualInterestRate, _prevId, _nextId); } /* * @dev Add a Trove to a Batch within the list * @param _troveId Trove's id * @param _batchId Batch's id * @param _annualInterestRate Batch's annual interest rate * @param _prevId Id of previous Trove for the insert position, in case the Batch is empty * @param _nextId Id of next Trove for the insert position, in case the Batch is empty */ function insertIntoBatch( uint256 _troveId, BatchId _batchId, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) external override { _requireCallerIsBorrowerOperations(); require(!contains(_troveId), "SortedTroves: List already contains the node"); require(_troveId != ROOT_NODE_ID, "SortedTroves: _troveId cannot be the root node's ID"); require(_batchId.isNotZero(), "SortedTroves: _batchId cannot be zero"); uint256 batchTail = batches[_batchId].tail; if (batchTail == UNINITIALIZED_ID) { _insertSlice(troveManager, _troveId, _troveId, _annualInterestRate, _prevId, _nextId); // Initialize the batch by setting both its head & tail to its singular node batches[_batchId].head = _troveId; // (Tail will be set outside the "if") } else { _insertSliceIntoVerifiedPosition(_troveId, _troveId, batchTail, nodes[batchTail].nextId); } batches[_batchId].tail = _troveId; nodes[_troveId].batchId = _batchId; nodes[_troveId].exists = true; ++size; } /* * @dev Remove a batched Trove from the list * @param _id Trove's id */ function removeFromBatch(uint256 _id) external override { _requireCallerIsBOorTM(); BatchId batchId = nodes[_id].batchId; // batchId.isNotZero() implies that the list contains the node require(batchId.isNotZero(), "SortedTroves: Must use remove() to remove non-batched node"); Batch memory batch = batches[batchId]; if (batch.head == _id && batch.tail == _id) { // Remove singleton batch delete batches[batchId]; } else if (batch.head == _id) { batches[batchId].head = nodes[_id].nextId; } else if (batch.tail == _id) { batches[batchId].tail = nodes[_id].prevId; } _removeSlice(_id, _id); delete nodes[_id]; --size; } /* * @dev Re-insert an entire Batch of Troves at a new position, based on their new annual interest rate * @param _id Batch's id * @param _newAnnualInterestRate Trove's new annual interest rate * @param _prevId Id of previous Trove for the new insert position * @param _nextId Id of next Trove for the new insert position */ function reInsertBatch(BatchId _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external override { Batch memory batch = batches[_id]; _requireCallerIsBorrowerOperations(); require(batch.head != UNINITIALIZED_ID, "SortedTroves: List does not contain the batch"); _reInsertSlice(troveManager, batch.head, batch.tail, _newAnnualInterestRate, _prevId, _nextId); } /* * @dev Checks if the list contains a node */ function contains(uint256 _id) public view override returns (bool) { return nodes[_id].exists; } /* * @dev Checks whether the node is part of a batch */ function isBatchedNode(uint256 _id) public view override returns (bool) { return nodes[_id].batchId.isNotZero(); } function isEmptyBatch(BatchId _id) external view override returns (bool) { return batches[_id].head == UNINITIALIZED_ID; } /* * @dev Checks if the list is empty */ function isEmpty() external view override returns (bool) { return size == 0; } /* * @dev Returns the current size of the list */ function getSize() external view override returns (uint256) { return size; } /* * @dev Returns the first node in the list (node with the largest annual interest rate) */ function getFirst() external view override returns (uint256) { return nodes[ROOT_NODE_ID].nextId; } /* * @dev Returns the last node in the list (node with the smallest annual interest rate) */ function getLast() external view override returns (uint256) { return nodes[ROOT_NODE_ID].prevId; } /* * @dev Returns the next node (with a smaller interest rate) in the list for a given node * @param _id Node's id */ function getNext(uint256 _id) external view override returns (uint256) { return nodes[_id].nextId; } /* * @dev Returns the previous node (with a larger interest rate) in the list for a given node * @param _id Node's id */ function getPrev(uint256 _id) external view override returns (uint256) { return nodes[_id].prevId; } /* * @dev Check if a pair of nodes is a valid insertion point for a new node with the given interest rate * @param _annualInterestRate Node's annual interest rate * @param _prevId Id of previous node for the insert position * @param _nextId Id of next node for the insert position */ function validInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external view override returns (bool) { return _validInsertPosition(troveManager, _annualInterestRate, _prevId, _nextId); } function _validInsertPosition( ITroveManager _troveManager, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) internal view returns (bool) { BatchId prevBatchId = nodes[_prevId].batchId; // `(_prevId, _nextId)` is a valid insert position if: return // they are adjacent nodes ( nodes[_prevId].nextId == _nextId && nodes[_nextId].prevId == _prevId // they aren't part of the same batch && (prevBatchId != nodes[_nextId].batchId || prevBatchId.isZero()) // `_annualInterestRate` falls between the two nodes' interest rates && (_prevId == ROOT_NODE_ID || _troveManager.getTroveAnnualInterestRate(_prevId) >= _annualInterestRate) && (_nextId == ROOT_NODE_ID || _annualInterestRate > _troveManager.getTroveAnnualInterestRate(_nextId)) ); } function _skipToBatchTail(uint256 _id) internal view returns (uint256) { BatchId batchId = nodes[_id].batchId; return batchId.isNotZero() ? batches[batchId].tail : _id; } function _skipToBatchHead(uint256 _id) internal view returns (uint256) { BatchId batchId = nodes[_id].batchId; return batchId.isNotZero() ? batches[batchId].head : _id; } function _descendOne(ITroveManager _troveManager, uint256 _annualInterestRate, Position memory _pos) internal view returns (bool found) { if (_pos.nextId == ROOT_NODE_ID || _annualInterestRate > _troveManager.getTroveAnnualInterestRate(_pos.nextId)) { found = true; } else { _pos.prevId = _skipToBatchTail(_pos.nextId); _pos.nextId = nodes[_pos.prevId].nextId; } } function _ascendOne(ITroveManager _troveManager, uint256 _annualInterestRate, Position memory _pos) internal view returns (bool found) { if (_pos.prevId == ROOT_NODE_ID || _troveManager.getTroveAnnualInterestRate(_pos.prevId) >= _annualInterestRate) { found = true; } else { _pos.nextId = _skipToBatchHead(_pos.prevId); _pos.prevId = nodes[_pos.nextId].prevId; } } /* * @dev Descend the list (larger interest rates to smaller interest rates) to find a valid insert position * @param _troveManager TroveManager contract, passed in as param to save SLOAD’s * @param _annualInterestRate Node's annual interest rate * @param _startId Id of node to start descending the list from */ function _descendList(ITroveManager _troveManager, uint256 _annualInterestRate, uint256 _startId) internal view returns (uint256, uint256) { Position memory pos = Position(_startId, nodes[_startId].nextId); while (!_descendOne(_troveManager, _annualInterestRate, pos)) {} return (pos.prevId, pos.nextId); } /* * @dev Ascend the list (smaller interest rates to larger interest rates) to find a valid insert position * @param _troveManager TroveManager contract, passed in as param to save SLOAD’s * @param _annualInterestRate Node's annual interest rate * @param _startId Id of node to start ascending the list from */ function _ascendList(ITroveManager _troveManager, uint256 _annualInterestRate, uint256 _startId) internal view returns (uint256, uint256) { Position memory pos = Position(nodes[_startId].prevId, _startId); while (!_ascendOne(_troveManager, _annualInterestRate, pos)) {} return (pos.prevId, pos.nextId); } function _descendAndAscendList( ITroveManager _troveManager, uint256 _annualInterestRate, uint256 _descentStartId, uint256 _ascentStartId ) internal view returns (uint256 prevId, uint256 nextId) { Position memory descentPos = Position(_descentStartId, nodes[_descentStartId].nextId); Position memory ascentPos = Position(nodes[_ascentStartId].prevId, _ascentStartId); for (;;) { if (_descendOne(_troveManager, _annualInterestRate, descentPos)) { return (descentPos.prevId, descentPos.nextId); } if (_ascendOne(_troveManager, _annualInterestRate, ascentPos)) { return (ascentPos.prevId, ascentPos.nextId); } } assert(false); // Should not reach } /* * @dev Find the insert position for a new node with the given interest rate * @param _annualInterestRate Node's annual interest rate * @param _prevId Id of previous node for the insert position * @param _nextId Id of next node for the insert position */ function findInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external view override returns (uint256, uint256) { return _findInsertPosition(troveManager, _annualInterestRate, _prevId, _nextId); } // This function is optimized under the assumption that only one of the original neighbours has been (re)moved. // In other words, we assume that the correct position can be found close to one of the two. // Nevertheless, the function will always find the correct position, regardless of hints or interference. function _findInsertPosition( ITroveManager _troveManager, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) internal view returns (uint256, uint256) { if (_prevId == ROOT_NODE_ID) { // The original correct position was found before the head of the list. // Assuming minimal interference, the new correct position is still close to the head. return _descendList(_troveManager, _annualInterestRate, ROOT_NODE_ID); } else { if (!contains(_prevId) || _troveManager.getTroveAnnualInterestRate(_prevId) < _annualInterestRate) { // `prevId` does not exist anymore or now has a smaller interest rate than the given interest rate _prevId = BAD_HINT; } } if (_nextId == ROOT_NODE_ID) { // The original correct position was found after the tail of the list. // Assuming minimal interference, the new correct position is still close to the tail. return _ascendList(_troveManager, _annualInterestRate, ROOT_NODE_ID); } else { if (!contains(_nextId) || _annualInterestRate <= _troveManager.getTroveAnnualInterestRate(_nextId)) { // `nextId` does not exist anymore or now has a larger interest rate than the given interest rate _nextId = BAD_HINT; } } if (_prevId == BAD_HINT && _nextId == BAD_HINT) { // Both original neighbours have been moved or removed. // We default to descending the list, starting from the head. return _descendList(_troveManager, _annualInterestRate, ROOT_NODE_ID); } else if (_prevId == BAD_HINT) { // No `prevId` for hint - ascend list starting from `nextId` return _ascendList(_troveManager, _annualInterestRate, _skipToBatchHead(_nextId)); } else if (_nextId == BAD_HINT) { // No `nextId` for hint - descend list starting from `prevId` return _descendList(_troveManager, _annualInterestRate, _skipToBatchTail(_prevId)); } else { // The correct position is still somewhere between the 2 hints, so it's not obvious // which of the 2 has been moved (assuming only one of them has been). // We simultaneously descend & ascend in the hope that one of them is very close. return _descendAndAscendList( _troveManager, _annualInterestRate, _skipToBatchTail(_prevId), _skipToBatchHead(_nextId) ); } } // --- 'require' functions --- function _requireCallerIsBOorTM() internal view { require( msg.sender == borrowerOperationsAddress || msg.sender == address(troveManager), "SortedTroves: Caller is not BorrowerOperations nor TroveManager" ); } function _requireCallerIsBorrowerOperations() internal view { require(msg.sender == borrowerOperationsAddress, "SortedTroves: Caller is not BorrowerOperations"); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ITroveManager.sol"; import {BatchId, BATCH_ID_ZERO} from "../Types/BatchId.sol"; interface ISortedTroves { // -- Mutating functions (permissioned) -- function insert(uint256 _id, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external; function insertIntoBatch( uint256 _troveId, BatchId _batchId, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId ) external; function remove(uint256 _id) external; function removeFromBatch(uint256 _id) external; function reInsert(uint256 _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external; function reInsertBatch(BatchId _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external; // -- View functions -- function contains(uint256 _id) external view returns (bool); function isBatchedNode(uint256 _id) external view returns (bool); function isEmptyBatch(BatchId _id) external view returns (bool); function isEmpty() external view returns (bool); function getSize() external view returns (uint256); function getFirst() external view returns (uint256); function getLast() external view returns (uint256); function getNext(uint256 _id) external view returns (uint256); function getPrev(uint256 _id) external view returns (uint256); function validInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external view returns (bool); function findInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external view returns (uint256, uint256); // Public state variable getters function borrowerOperationsAddress() external view returns (address); function troveManager() external view returns (ITroveManager); function size() external view returns (uint256); function nodes(uint256 _id) external view returns (uint256 nextId, uint256 prevId, BatchId batchId, bool exists); function batches(BatchId _id) external view returns (uint256 head, uint256 tail); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IActivePool.sol"; import "./IBoldToken.sol"; import "./IBorrowerOperations.sol"; import "./ICollSurplusPool.sol"; import "./IDefaultPool.sol"; import "./IHintHelpers.sol"; import "./IMultiTroveGetter.sol"; import "./ISortedTroves.sol"; import "./IStabilityPool.sol"; import "./ITroveManager.sol"; import "./ITroveNFT.sol"; import {IMetadataNFT} from "../NFTMetadata/MetadataNFT.sol"; import "./ICollateralRegistry.sol"; import "./IInterestRouter.sol"; import "./IPriceFeed.sol"; interface IAddressesRegistry { struct AddressVars { IERC20Metadata collToken; IBorrowerOperations borrowerOperations; ITroveManager troveManager; ITroveNFT troveNFT; IMetadataNFT metadataNFT; IStabilityPool stabilityPool; IPriceFeed priceFeed; IActivePool activePool; IDefaultPool defaultPool; address gasPoolAddress; ICollSurplusPool collSurplusPool; ISortedTroves sortedTroves; IInterestRouter interestRouter; IHintHelpers hintHelpers; IMultiTroveGetter multiTroveGetter; ICollateralRegistry collateralRegistry; IBoldToken boldToken; IWETH WETH; } function CCR() external returns (uint256); function SCR() external returns (uint256); function MCR() external returns (uint256); function LIQUIDATION_PENALTY_SP() external returns (uint256); function LIQUIDATION_PENALTY_REDISTRIBUTION() external returns (uint256); function collToken() external view returns (IERC20Metadata); function borrowerOperations() external view returns (IBorrowerOperations); function troveManager() external view returns (ITroveManager); function troveNFT() external view returns (ITroveNFT); function metadataNFT() external view returns (IMetadataNFT); function stabilityPool() external view returns (IStabilityPool); function priceFeed() external view returns (IPriceFeed); function activePool() external view returns (IActivePool); function defaultPool() external view returns (IDefaultPool); function gasPoolAddress() external view returns (address); function collSurplusPool() external view returns (ICollSurplusPool); function sortedTroves() external view returns (ISortedTroves); function interestRouter() external view returns (IInterestRouter); function hintHelpers() external view returns (IHintHelpers); function multiTroveGetter() external view returns (IMultiTroveGetter); function collateralRegistry() external view returns (ICollateralRegistry); function boldToken() external view returns (IBoldToken); function WETH() external returns (IWETH); function setAddresses(AddressVars memory _vars) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ILiquityBase.sol"; import "./ITroveNFT.sol"; import "./IBorrowerOperations.sol"; import "./IStabilityPool.sol"; import "./IBoldToken.sol"; import "./ISortedTroves.sol"; import "../Types/LatestTroveData.sol"; import "../Types/LatestBatchData.sol"; // Common interface for the Trove Manager. interface ITroveManager is ILiquityBase { enum Status { nonExistent, active, closedByOwner, closedByLiquidation, zombie } function shutdownTime() external view returns (uint256); function troveNFT() external view returns (ITroveNFT); function stabilityPool() external view returns (IStabilityPool); //function boldToken() external view returns (IBoldToken); function sortedTroves() external view returns (ISortedTroves); function borrowerOperations() external view returns (IBorrowerOperations); function Troves(uint256 _id) external view returns ( uint256 debt, uint256 coll, uint256 stake, Status status, uint64 arrayIndex, uint64 lastDebtUpdateTime, uint64 lastInterestRateAdjTime, uint256 annualInterestRate, address interestBatchManager, uint256 batchDebtShares ); function rewardSnapshots(uint256 _id) external view returns (uint256 coll, uint256 boldDebt); function getTroveIdsCount() external view returns (uint256); function getTroveFromTroveIdsArray(uint256 _index) external view returns (uint256); function getCurrentICR(uint256 _troveId, uint256 _price) external view returns (uint256); function lastZombieTroveId() external view returns (uint256); function batchLiquidateTroves(uint256[] calldata _troveArray) external; function redeemCollateral( address _sender, uint256 _boldAmount, uint256 _price, uint256 _redemptionRate, uint256 _maxIterations ) external returns (uint256 _redemeedAmount); function shutdown() external; function urgentRedemption(uint256 _boldAmount, uint256[] calldata _troveIds, uint256 _minCollateral) external; function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool); function getLatestTroveData(uint256 _troveId) external view returns (LatestTroveData memory); function getTroveAnnualInterestRate(uint256 _troveId) external view returns (uint256); function getTroveStatus(uint256 _troveId) external view returns (Status); function getLatestBatchData(address _batchAddress) external view returns (LatestBatchData memory); // -- permissioned functions called by BorrowerOperations function onOpenTrove(address _owner, uint256 _troveId, TroveChange memory _troveChange, uint256 _annualInterestRate) external; function onOpenTroveAndJoinBatch( address _owner, uint256 _troveId, TroveChange memory _troveChange, address _batchAddress, uint256 _batchColl, uint256 _batchDebt ) external; // Called from `adjustZombieTrove()` function setTroveStatusToActive(uint256 _troveId) external; function onAdjustTroveInterestRate( uint256 _troveId, uint256 _newColl, uint256 _newDebt, uint256 _newAnnualInterestRate, TroveChange calldata _troveChange ) external; function onAdjustTrove(uint256 _troveId, uint256 _newColl, uint256 _newDebt, TroveChange calldata _troveChange) external; function onAdjustTroveInsideBatch( uint256 _troveId, uint256 _newTroveColl, uint256 _newTroveDebt, TroveChange memory _troveChange, address _batchAddress, uint256 _newBatchColl, uint256 _newBatchDebt ) external; function onApplyTroveInterest( uint256 _troveId, uint256 _newTroveColl, uint256 _newTroveDebt, address _batchAddress, uint256 _newBatchColl, uint256 _newBatchDebt, TroveChange calldata _troveChange ) external; function onCloseTrove( uint256 _troveId, TroveChange memory _troveChange, // decrease vars: entire, with interest, batch fee and redistribution address _batchAddress, uint256 _newBatchColl, uint256 _newBatchDebt // entire, with interest and batch fee ) external; // -- batches -- function onRegisterBatchManager(address _batchAddress, uint256 _annualInterestRate, uint256 _annualFee) external; function onLowerBatchManagerAnnualFee( address _batchAddress, uint256 _newColl, uint256 _newDebt, uint256 _newAnnualManagementFee ) external; function onSetBatchManagerAnnualInterestRate( address _batchAddress, uint256 _newColl, uint256 _newDebt, uint256 _newAnnualInterestRate, uint256 _upfrontFee // needed by BatchUpdated event ) external; struct OnSetInterestBatchManagerParams { uint256 troveId; uint256 troveColl; // entire, with redistribution uint256 troveDebt; // entire, with interest, batch fee and redistribution TroveChange troveChange; address newBatchAddress; uint256 newBatchColl; // updated collateral for new batch manager uint256 newBatchDebt; // updated debt for new batch manager } function onSetInterestBatchManager(OnSetInterestBatchManagerParams calldata _params) external; function onRemoveFromBatch( uint256 _troveId, uint256 _newTroveColl, // entire, with redistribution uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution TroveChange memory _troveChange, address _batchAddress, uint256 _newBatchColl, uint256 _newBatchDebt, // entire, with interest and batch fee uint256 _newAnnualInterestRate ) external; // -- end of permissioned functions -- }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ILiquityBase.sol"; import "./IAddRemoveManagers.sol"; import "./IBoldToken.sol"; import "./IPriceFeed.sol"; import "./ISortedTroves.sol"; import "./ITroveManager.sol"; import "./IWETH.sol"; // Common interface for the Borrower Operations. interface IBorrowerOperations is ILiquityBase, IAddRemoveManagers { function CCR() external view returns (uint256); function MCR() external view returns (uint256); function SCR() external view returns (uint256); function openTrove( address _owner, uint256 _ownerIndex, uint256 _ETHAmount, uint256 _boldAmount, uint256 _upperHint, uint256 _lowerHint, uint256 _annualInterestRate, uint256 _maxUpfrontFee, address _addManager, address _removeManager, address _receiver ) external returns (uint256); struct OpenTroveAndJoinInterestBatchManagerParams { address owner; uint256 ownerIndex; uint256 collAmount; uint256 boldAmount; uint256 upperHint; uint256 lowerHint; address interestBatchManager; uint256 maxUpfrontFee; address addManager; address removeManager; address receiver; } function openTroveAndJoinInterestBatchManager(OpenTroveAndJoinInterestBatchManagerParams calldata _params) external returns (uint256); function addColl(uint256 _troveId, uint256 _ETHAmount) external; function withdrawColl(uint256 _troveId, uint256 _amount) external; function withdrawBold(uint256 _troveId, uint256 _amount, uint256 _maxUpfrontFee) external; function repayBold(uint256 _troveId, uint256 _amount) external; function closeTrove(uint256 _troveId) external; function adjustTrove( uint256 _troveId, uint256 _collChange, bool _isCollIncrease, uint256 _debtChange, bool isDebtIncrease, uint256 _maxUpfrontFee ) external; function adjustZombieTrove( uint256 _troveId, uint256 _collChange, bool _isCollIncrease, uint256 _boldChange, bool _isDebtIncrease, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee ) external; function adjustTroveInterestRate( uint256 _troveId, uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee ) external; function applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint) external; function onLiquidateTrove(uint256 _troveId) external; function claimCollateral() external; function hasBeenShutDown() external view returns (bool); function shutdown() external; function shutdownFromOracleFailure() external; function checkBatchManagerExists(address _batchMananger) external view returns (bool); // -- individual delegation -- struct InterestIndividualDelegate { address account; uint128 minInterestRate; uint128 maxInterestRate; uint256 minInterestRateChangePeriod; } function getInterestIndividualDelegateOf(uint256 _troveId) external view returns (InterestIndividualDelegate memory); function setInterestIndividualDelegate( uint256 _troveId, address _delegate, uint128 _minInterestRate, uint128 _maxInterestRate, // only needed if trove was previously in a batch: uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee, uint256 _minInterestRateChangePeriod ) external; function removeInterestIndividualDelegate(uint256 _troveId) external; // -- batches -- struct InterestBatchManager { uint128 minInterestRate; uint128 maxInterestRate; uint256 minInterestRateChangePeriod; } function registerBatchManager( uint128 minInterestRate, uint128 maxInterestRate, uint128 currentInterestRate, uint128 fee, uint128 minInterestRateChangePeriod ) external; function lowerBatchManagementFee(uint256 _newAnnualFee) external; function setBatchManagerAnnualInterestRate( uint128 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee ) external; function interestBatchManagerOf(uint256 _troveId) external view returns (address); function getInterestBatchManager(address _account) external view returns (InterestBatchManager memory); function setInterestBatchManager( uint256 _troveId, address _newBatchManager, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee ) external; function removeFromBatch( uint256 _troveId, uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee ) external; function switchBatchManager( uint256 _troveId, uint256 _removeUpperHint, uint256 _removeLowerHint, address _newBatchManager, uint256 _addUpperHint, uint256 _addLowerHint, uint256 _maxUpfrontFee ) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; type BatchId is address; using {equals as ==, notEquals as !=, isZero, isNotZero} for BatchId global; function equals(BatchId a, BatchId b) pure returns (bool) { return BatchId.unwrap(a) == BatchId.unwrap(b); } function notEquals(BatchId a, BatchId b) pure returns (bool) { return !(a == b); } function isZero(BatchId x) pure returns (bool) { return x == BATCH_ID_ZERO; } function isNotZero(BatchId x) pure returns (bool) { return !x.isZero(); } BatchId constant BATCH_ID_ZERO = BatchId.wrap(address(0));
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IInterestRouter.sol"; import "./IBoldRewardsReceiver.sol"; import "../Types/TroveChange.sol"; interface IActivePool { function defaultPoolAddress() external view returns (address); function borrowerOperationsAddress() external view returns (address); function troveManagerAddress() external view returns (address); function interestRouter() external view returns (IInterestRouter); // We avoid IStabilityPool here in order to prevent creating a dependency cycle that would break flattening function stabilityPool() external view returns (IBoldRewardsReceiver); function getCollBalance() external view returns (uint256); function getBoldDebt() external view returns (uint256); function lastAggUpdateTime() external view returns (uint256); function aggRecordedDebt() external view returns (uint256); function aggWeightedDebtSum() external view returns (uint256); function aggBatchManagementFees() external view returns (uint256); function aggWeightedBatchManagementFeeSum() external view returns (uint256); function calcPendingAggInterest() external view returns (uint256); function calcPendingSPYield() external view returns (uint256); function calcPendingAggBatchManagementFee() external view returns (uint256); function getNewApproxAvgInterestRateFromTroveChange(TroveChange calldata _troveChange) external view returns (uint256); function mintAggInterest() external; function mintAggInterestAndAccountForTroveChange(TroveChange calldata _troveChange, address _batchManager) external; function mintBatchManagementFeeAndAccountForChange(TroveChange calldata _troveChange, address _batchAddress) external; function setShutdownFlag() external; function hasBeenShutDown() external view returns (bool); function shutdownTime() external view returns (uint256); function sendColl(address _account, uint256 _amount) external; function sendCollToDefaultPool(uint256 _amount) external; function receiveColl(uint256 _amount) external; function accountForReceivedColl(uint256 _amount) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol"; import "openzeppelin-contracts/contracts/interfaces/IERC5267.sol"; interface IBoldToken is IERC20Metadata, IERC20Permit, IERC5267 { function setBranchAddresses( address _troveManagerAddress, address _stabilityPoolAddress, address _borrowerOperationsAddress, address _activePoolAddress ) external; function setCollateralRegistry(address _collateralRegistryAddress) external; function mint(address _account, uint256 _amount) external; function burn(address _account, uint256 _amount) external; function sendToPool(address _sender, address poolAddress, uint256 _amount) external; function returnFromPool(address poolAddress, address user, uint256 _amount) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ICollSurplusPool { function getCollBalance() external view returns (uint256); function getCollateral(address _account) external view returns (uint256); function accountSurplus(address _account, uint256 _amount) external; function claimColl(address _account) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IDefaultPool { function troveManagerAddress() external view returns (address); function activePoolAddress() external view returns (address); // --- Functions --- function getCollBalance() external view returns (uint256); function getBoldDebt() external view returns (uint256); function sendCollToActivePool(uint256 _amount) external; function receiveColl(uint256 _amount) external; function increaseBoldDebt(uint256 _amount) external; function decreaseBoldDebt(uint256 _amount) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IHintHelpers { function getApproxHint(uint256 _collIndex, uint256 _interestRate, uint256 _numTrials, uint256 _inputRandomSeed) external view returns (uint256 hintId, uint256 diff, uint256 latestRandomSeed); function predictOpenTroveUpfrontFee(uint256 _collIndex, uint256 _borrowedAmount, uint256 _interestRate) external view returns (uint256); function predictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate) external view returns (uint256); function forcePredictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate) external view returns (uint256); function predictAdjustTroveUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _debtIncrease) external view returns (uint256); function predictAdjustBatchInterestRateUpfrontFee( uint256 _collIndex, address _batchAddress, uint256 _newInterestRate ) external view returns (uint256); function predictJoinBatchInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, address _batchAddress) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IMultiTroveGetter { struct CombinedTroveData { uint256 id; uint256 debt; uint256 coll; uint256 stake; uint256 annualInterestRate; uint256 lastDebtUpdateTime; uint256 lastInterestRateAdjTime; address interestBatchManager; uint256 batchDebtShares; uint256 batchCollShares; uint256 snapshotETH; uint256 snapshotBoldDebt; } struct DebtPerInterestRate { address interestBatchManager; uint256 interestRate; uint256 debt; } function getMultipleSortedTroves(uint256 _collIndex, int256 _startIdx, uint256 _count) external view returns (CombinedTroveData[] memory _troves); function getDebtPerInterestRateAscending(uint256 _collIndex, uint256 _startId, uint256 _maxIterations) external view returns (DebtPerInterestRate[] memory, uint256 currId); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IActivePool.sol"; import "./ILiquityBase.sol"; import "./IBoldToken.sol"; import "./ITroveManager.sol"; import "./IBoldRewardsReceiver.sol"; /* * The Stability Pool holds Bold tokens deposited by Stability Pool depositors. * * When a trove is liquidated, then depending on system conditions, some of its Bold debt gets offset with * Bold in the Stability Pool: that is, the offset debt evaporates, and an equal amount of Bold tokens in the Stability Pool is burned. * * Thus, a liquidation causes each depositor to receive a Bold loss, in proportion to their deposit as a share of total deposits. * They also receive an Coll gain, as the collateral of the liquidated trove is distributed among Stability depositors, * in the same proportion. * * When a liquidation occurs, it depletes every deposit by the same fraction: for example, a liquidation that depletes 40% * of the total Bold in the Stability Pool, depletes 40% of each deposit. * * A deposit that has experienced a series of liquidations is termed a "compounded deposit": each liquidation depletes the deposit, * multiplying it by some factor in range ]0,1[ * * Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / Coll gain derivations: * https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf * */ interface IStabilityPool is ILiquityBase, IBoldRewardsReceiver { function boldToken() external view returns (IBoldToken); function troveManager() external view returns (ITroveManager); /* provideToSP(): * - Calculates depositor's Coll gain * - Calculates the compounded deposit * - Increases deposit, and takes new snapshots of accumulators P and S * - Sends depositor's accumulated Coll gains to depositor */ function provideToSP(uint256 _amount, bool _doClaim) external; /* withdrawFromSP(): * - Calculates depositor's Coll gain * - Calculates the compounded deposit * - Sends the requested BOLD withdrawal to depositor * - (If _amount > userDeposit, the user withdraws all of their compounded deposit) * - Decreases deposit by withdrawn amount and takes new snapshots of accumulators P and S */ function withdrawFromSP(uint256 _amount, bool doClaim) external; function claimAllCollGains() external; /* * Initial checks: * - Caller is TroveManager * --- * Cancels out the specified debt against the Bold contained in the Stability Pool (as far as possible) * and transfers the Trove's collateral from ActivePool to StabilityPool. * Only called by liquidation functions in the TroveManager. */ function offset(uint256 _debt, uint256 _coll) external; function deposits(address _depositor) external view returns (uint256 initialValue); function stashedColl(address _depositor) external view returns (uint256); /* * Returns the total amount of Coll held by the pool, accounted in an internal variable instead of `balance`, * to exclude edge cases like Coll received from a self-destruct. */ function getCollBalance() external view returns (uint256); /* * Returns Bold held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset. */ function getTotalBoldDeposits() external view returns (uint256); function getYieldGainsOwed() external view returns (uint256); function getYieldGainsPending() external view returns (uint256); /* * Calculates the Coll gain earned by the deposit since its last snapshots were taken. */ function getDepositorCollGain(address _depositor) external view returns (uint256); /* * Calculates the BOLD yield gain earned by the deposit since its last snapshots were taken. */ function getDepositorYieldGain(address _depositor) external view returns (uint256); /* * Calculates what `getDepositorYieldGain` will be if interest is minted now. */ function getDepositorYieldGainWithPending(address _depositor) external view returns (uint256); /* * Return the user's compounded deposit. */ function getCompoundedBoldDeposit(address _depositor) external view returns (uint256); function epochToScaleToS(uint128 _epoch, uint128 _scale) external view returns (uint256); function epochToScaleToB(uint128 _epoch, uint128 _scale) external view returns (uint256); function P() external view returns (uint256); function currentScale() external view returns (uint128); function currentEpoch() external view returns (uint128); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol"; import "./ITroveManager.sol"; interface ITroveNFT is IERC721Metadata { function mint(address _owner, uint256 _troveId) external; function burn(uint256 _troveId) external; }
//SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "lib/Solady/src/utils/SSTORE2.sol"; import "./utils/JSON.sol"; import "./utils/baseSVG.sol"; import "./utils/bauhaus.sol"; import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {ITroveManager} from "src/Interfaces/ITroveManager.sol"; interface IMetadataNFT { struct TroveData { uint256 _tokenId; address _owner; address _collToken; address _boldToken; uint256 _collAmount; uint256 _debtAmount; uint256 _interestRate; ITroveManager.Status _status; } function uri(TroveData memory _troveData) external view returns (string memory); } contract MetadataNFT is IMetadataNFT { FixedAssetReader public immutable assetReader; string public constant name = "Liquity V2 Trove"; string public constant description = "Liquity V2 Trove position"; constructor(FixedAssetReader _assetReader) { assetReader = _assetReader; } function uri(TroveData memory _troveData) public view returns (string memory) { string memory attr = attributes(_troveData); return json.formattedMetadata(name, description, renderSVGImage(_troveData), attr); } function renderSVGImage(TroveData memory _troveData) internal view returns (string memory) { return svg._svg( baseSVG._svgProps(), string.concat( baseSVG._baseElements(assetReader), bauhaus._bauhaus(IERC20Metadata(_troveData._collToken).symbol(), _troveData._tokenId), dynamicTextComponents(_troveData) ) ); } function attributes(TroveData memory _troveData) public pure returns (string memory) { //include: collateral token address, collateral amount, debt token address, debt amount, interest rate, status return string.concat( '[{"trait_type": "Collateral Token", "value": "', LibString.toHexString(_troveData._collToken), '"}, {"trait_type": "Collateral Amount", "value": "', LibString.toString(_troveData._collAmount), '"}, {"trait_type": "Debt Token", "value": "', LibString.toHexString(_troveData._boldToken), '"}, {"trait_type": "Debt Amount", "value": "', LibString.toString(_troveData._debtAmount), '"}, {"trait_type": "Interest Rate", "value": "', LibString.toString(_troveData._interestRate), '"}, {"trait_type": "Status", "value": "', _status2Str(_troveData._status), '"} ]' ); } function dynamicTextComponents(TroveData memory _troveData) public view returns (string memory) { string memory id = LibString.toHexString(_troveData._tokenId); id = string.concat(LibString.slice(id, 0, 6), "...", LibString.slice(id, 38, 42)); return string.concat( baseSVG._formattedIdEl(id), baseSVG._formattedAddressEl(_troveData._owner), baseSVG._collLogo(IERC20Metadata(_troveData._collToken).symbol(), assetReader), baseSVG._statusEl(_status2Str(_troveData._status)), baseSVG._dynamicTextEls(_troveData._debtAmount, _troveData._collAmount, _troveData._interestRate) ); } function _status2Str(ITroveManager.Status status) internal pure returns (string memory) { if (status == ITroveManager.Status.active) return "Active"; if (status == ITroveManager.Status.closedByOwner) return "Closed"; if (status == ITroveManager.Status.closedByLiquidation) return "Liquidated"; if (status == ITroveManager.Status.zombie) return "Below Min Debt"; return ""; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "./IBoldToken.sol"; import "./ITroveManager.sol"; interface ICollateralRegistry { function baseRate() external view returns (uint256); function lastFeeOperationTime() external view returns (uint256); function redeemCollateral(uint256 _boldamount, uint256 _maxIterations, uint256 _maxFeePercentage) external; // getters function totalCollaterals() external view returns (uint256); function getToken(uint256 _index) external view returns (IERC20Metadata); function getTroveManager(uint256 _index) external view returns (ITroveManager); function boldToken() external view returns (IBoldToken); function getRedemptionRate() external view returns (uint256); function getRedemptionRateWithDecay() external view returns (uint256); function getRedemptionRateForRedeemedAmount(uint256 _redeemAmount) external view returns (uint256); function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view returns (uint256); function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IInterestRouter { // Currently the Interest Router doesn’t need any specific function }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IPriceFeed { function fetchPrice() external returns (uint256, bool); function fetchRedemptionPrice() external returns (uint256, bool); function lastGoodPrice() external view returns (uint256); function setAddresses(address _borrowerOperationsAddress) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IActivePool.sol"; import "./IDefaultPool.sol"; import "./IPriceFeed.sol"; interface ILiquityBase { function activePool() external view returns (IActivePool); function getEntireSystemDebt() external view returns (uint256); function getEntireSystemColl() external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; struct LatestTroveData { uint256 entireDebt; uint256 entireColl; uint256 redistBoldDebtGain; uint256 redistCollGain; uint256 accruedInterest; uint256 recordedDebt; uint256 annualInterestRate; uint256 weightedRecordedDebt; uint256 accruedBatchManagementFee; uint256 lastInterestRateAdjTime; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; struct LatestBatchData { uint256 entireDebtWithoutRedistribution; uint256 entireCollWithoutRedistribution; uint256 accruedInterest; uint256 recordedDebt; uint256 annualInterestRate; uint256 weightedRecordedDebt; uint256 annualManagementFee; uint256 accruedManagementFee; uint256 weightedRecordedBatchManagementFee; uint256 lastDebtUpdateTime; uint256 lastInterestRateAdjTime; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IAddRemoveManagers { function setAddManager(uint256 _troveId, address _manager) external; function setRemoveManager(uint256 _troveId, address _manager) external; function setRemoveManagerWithReceiver(uint256 _troveId, address _manager, address _receiver) external; function addManagerOf(uint256 _troveId) external view returns (address); function removeManagerReceiverOf(uint256 _troveId) external view returns (address, address); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IWETH is IERC20Metadata { function deposit() external payable; function withdraw(uint256 wad) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IBoldRewardsReceiver { function triggerBoldRewards(uint256 _boldYield) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.24; struct TroveChange { uint256 appliedRedistBoldDebtGain; uint256 appliedRedistCollGain; uint256 collIncrease; uint256 collDecrease; uint256 debtIncrease; uint256 debtDecrease; uint256 newWeightedRecordedDebt; uint256 oldWeightedRecordedDebt; uint256 upfrontFee; uint256 batchAccruedManagementFee; uint256 newWeightedRecordedBatchManagementFee; uint256 oldWeightedRecordedBatchManagementFee; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.0; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Read and write to persistent storage at a fraction of the cost. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SSTORE2.sol) /// @author Saw-mon-and-Natalie (https://github.com/Saw-mon-and-Natalie) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol) /// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol) /// @author Modified from SSTORE3 (https://github.com/Philogy/sstore3) library SSTORE2 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The proxy initialization code. uint256 private constant _CREATE3_PROXY_INITCODE = 0x67363d3d37363d34f03d5260086018f3; /// @dev Hash of the `_CREATE3_PROXY_INITCODE`. /// Equivalent to `keccak256(abi.encodePacked(hex"67363d3d37363d34f03d5260086018f3"))`. bytes32 internal constant CREATE3_PROXY_INITCODE_HASH = 0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Unable to deploy the storage contract. error DeploymentFailed(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* WRITE LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Writes `data` into the bytecode of a storage contract and returns its address. function write(bytes memory data) internal returns (address pointer) { /// @solidity memory-safe-assembly assembly { let n := mload(data) // Let `l` be `n + 1`. +1 as we prefix a STOP opcode. /** * ---------------------------------------------------+ * Opcode | Mnemonic | Stack | Memory | * ---------------------------------------------------| * 61 l | PUSH2 l | l | | * 80 | DUP1 | l l | | * 60 0xa | PUSH1 0xa | 0xa l l | | * 3D | RETURNDATASIZE | 0 0xa l l | | * 39 | CODECOPY | l | [0..l): code | * 3D | RETURNDATASIZE | 0 l | [0..l): code | * F3 | RETURN | | [0..l): code | * 00 | STOP | | | * ---------------------------------------------------+ * @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called. * Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16. */ // Do a out-of-gas revert if `n + 1` is more than 2 bytes. mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n))) // Deploy a new contract with the generated creation code. pointer := create(0, add(data, 0x15), add(n, 0xb)) if iszero(pointer) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(data, n) // Restore the length of `data`. } } /// @dev Writes `data` into the bytecode of a storage contract with `salt` /// and returns its normal CREATE2 deterministic address. function writeCounterfactual(bytes memory data, bytes32 salt) internal returns (address pointer) { /// @solidity memory-safe-assembly assembly { let n := mload(data) // Do a out-of-gas revert if `n + 1` is more than 2 bytes. mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n))) // Deploy a new contract with the generated creation code. pointer := create2(0, add(data, 0x15), add(n, 0xb), salt) if iszero(pointer) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(data, n) // Restore the length of `data`. } } /// @dev Writes `data` into the bytecode of a storage contract and returns its address. /// This uses the so-called "CREATE3" workflow, /// which means that `pointer` is agnostic to `data, and only depends on `salt`. function writeDeterministic(bytes memory data, bytes32 salt) internal returns (address pointer) { /// @solidity memory-safe-assembly assembly { let n := mload(data) mstore(0x00, _CREATE3_PROXY_INITCODE) // Store the `_PROXY_INITCODE`. let proxy := create2(0, 0x10, 0x10, salt) if iszero(proxy) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(0x14, proxy) // Store the proxy's address. // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01). // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex). mstore(0x00, 0xd694) mstore8(0x34, 0x01) // Nonce of the proxy contract (1). pointer := keccak256(0x1e, 0x17) // Do a out-of-gas revert if `n + 1` is more than 2 bytes. mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n))) if iszero( mul( // The arguments of `mul` are evaluated last to first. extcodesize(pointer), call(gas(), proxy, 0, add(data, 0x15), add(n, 0xb), codesize(), 0x00) ) ) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. revert(0x1c, 0x04) } mstore(data, n) // Restore the length of `data`. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ADDRESS CALCULATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the initialization code hash of the storage contract for `data`. /// Used for mining vanity addresses with create2crunch. function initCodeHash(bytes memory data) internal pure returns (bytes32 hash) { /// @solidity memory-safe-assembly assembly { let n := mload(data) // Do a out-of-gas revert if `n + 1` is more than 2 bytes. returndatacopy(returndatasize(), returndatasize(), gt(n, 0xfffe)) mstore(data, add(0x61000180600a3d393df300, shl(0x40, n))) hash := keccak256(add(data, 0x15), add(n, 0xb)) mstore(data, n) // Restore the length of `data`. } } /// @dev Equivalent to `predictCounterfactualAddress(data, salt, address(this))` function predictCounterfactualAddress(bytes memory data, bytes32 salt) internal view returns (address pointer) { pointer = predictCounterfactualAddress(data, salt, address(this)); } /// @dev Returns the CREATE2 address of the storage contract for `data` /// deployed with `salt` by `deployer`. /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly. function predictCounterfactualAddress(bytes memory data, bytes32 salt, address deployer) internal pure returns (address predicted) { bytes32 hash = initCodeHash(data); /// @solidity memory-safe-assembly assembly { // Compute and store the bytecode hash. mstore8(0x00, 0xff) // Write the prefix. mstore(0x35, hash) mstore(0x01, shl(96, deployer)) mstore(0x15, salt) predicted := keccak256(0x00, 0x55) // Restore the part of the free memory pointer that has been overwritten. mstore(0x35, 0) } } /// @dev Equivalent to `predictDeterministicAddress(salt, address(this))`. function predictDeterministicAddress(bytes32 salt) internal view returns (address pointer) { pointer = predictDeterministicAddress(salt, address(this)); } /// @dev Returns the "CREATE3" deterministic address for `salt` with `deployer`. function predictDeterministicAddress(bytes32 salt, address deployer) internal pure returns (address pointer) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, deployer) // Store `deployer`. mstore8(0x0b, 0xff) // Store the prefix. mstore(0x20, salt) // Store the salt. mstore(0x40, CREATE3_PROXY_INITCODE_HASH) // Store the bytecode hash. mstore(0x14, keccak256(0x0b, 0x55)) // Store the proxy's address. mstore(0x40, m) // Restore the free memory pointer. // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01). // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex). mstore(0x00, 0xd694) mstore8(0x34, 0x01) // Nonce of the proxy contract (1). pointer := keccak256(0x1e, 0x17) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* READ LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to `read(pointer, 0, 2 ** 256 - 1)`. function read(address pointer) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { data := mload(0x40) let n := and(sub(extcodesize(pointer), 0x01), 0xffffffffff) extcodecopy(pointer, add(data, 0x1f), 0x00, add(n, 0x21)) mstore(data, n) // Store the length. mstore(0x40, add(n, add(data, 0x40))) // Allocate memory. } } /// @dev Equivalent to `read(pointer, start, 2 ** 256 - 1)`. function read(address pointer, uint256 start) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { data := mload(0x40) let n := and(sub(extcodesize(pointer), 0x01), 0xffffffffff) extcodecopy(pointer, add(data, 0x1f), start, add(n, 0x21)) mstore(data, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(data, add(0x40, mload(data)))) // Allocate memory. } } /// @dev Returns a slice of the data on `pointer` from `start` to `end`. /// `start` and `end` will be clamped to the range `[0, args.length]`. /// The `pointer` MUST be deployed via the SSTORE2 write functions. /// Otherwise, the behavior is undefined. /// Out-of-gas reverts if `pointer` does not have any code. function read(address pointer, uint256 start, uint256 end) internal view returns (bytes memory data) { /// @solidity memory-safe-assembly assembly { data := mload(0x40) if iszero(lt(end, 0xffff)) { end := 0xffff } let d := mul(sub(end, start), lt(start, end)) extcodecopy(pointer, add(data, 0x1f), start, add(d, 0x01)) if iszero(and(0xff, mload(add(data, d)))) { let n := sub(extcodesize(pointer), 0x01) returndatacopy(returndatasize(), returndatasize(), shr(64, n)) d := mul(gt(n, start), sub(d, mul(gt(end, n), sub(end, n)))) } mstore(data, d) // Store the length. mstore(add(add(data, 0x20), d), 0) // Zeroize the slot after the bytes. mstore(0x40, add(add(data, 0x40), d)) // Allocate memory. } } }
//SPDX-License-Identifier: MIT pragma solidity ^0.8.12; // JSON utilities for base64 encoded ERC721 JSON metadata scheme library json { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @dev JSON requires that double quotes be escaped or JSONs will not build correctly /// string.concat also requires an escape, use \\" or the constant DOUBLE_QUOTES to represent " in JSON ///////////////////////////////////////////////////////////////////////////////////////////////////////////// string constant DOUBLE_QUOTES = '\\"'; function formattedMetadata( string memory name, string memory description, string memory svgImg, string memory attributes ) internal pure returns (string memory) { return string.concat( "data:application/json;base64,", encode( bytes( string.concat( "{", _prop("name", name), _prop("description", description), _xmlImage(svgImg), ',"attributes":', attributes, "}" ) ) ) ); } function _xmlImage(string memory _svgImg) internal pure returns (string memory) { return _prop("image", string.concat("data:image/svg+xml;base64,", encode(bytes(_svgImg))), true); } function _prop(string memory _key, string memory _val) internal pure returns (string memory) { return string.concat('"', _key, '": ', '"', _val, '", '); } function _prop(string memory _key, string memory _val, bool last) internal pure returns (string memory) { if (last) { return string.concat('"', _key, '": ', '"', _val, '"'); } else { return string.concat('"', _key, '": ', '"', _val, '", '); } } function _object(string memory _key, string memory _val) internal pure returns (string memory) { return string.concat('"', _key, '": ', "{", _val, "}"); } /** * taken from Openzeppelin * @dev Base64 Encoding/Decoding Table */ string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /** * @dev Converts a `bytes` to its Bytes64 `string` representation. */ function encode(bytes memory data) internal pure returns (string memory) { /** * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol */ if (data.length == 0) return ""; // Loads the table into memory string memory table = _TABLE; // Encoding takes 3 bytes chunks of binary data from `bytes` data parameter // and split into 4 numbers of 6 bits. // The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up // - `data.length + 2` -> Round up // - `/ 3` -> Number of 3-bytes chunks // - `4 *` -> 4 characters for each chunk string memory result = new string(4 * ((data.length + 2) / 3)); assembly { // Prepare the lookup table (skip the first "length" byte) let tablePtr := add(table, 1) // Prepare result pointer, jump over length let resultPtr := add(result, 32) // Run over the input, 3 bytes at a time for { let dataPtr := data let endPtr := add(data, mload(data)) } lt(dataPtr, endPtr) {} { // Advance 3 bytes dataPtr := add(dataPtr, 3) let input := mload(dataPtr) // To write each character, shift the 3 bytes (18 bits) chunk // 4 times in blocks of 6 bits for each character (18, 12, 6, 0) // and apply logical AND with 0x3F which is the number of // the previous character in the ASCII table prior to the Base64 Table // The result is then added to the table to get the character to write, // and finally write it in the result pointer but with a left shift // of 256 (1 byte) - 8 (1 ASCII char) = 248 bits mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F)))) resultPtr := add(resultPtr, 1) // Advance mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F)))) resultPtr := add(resultPtr, 1) // Advance } // When data `bytes` is not exactly 3 bytes long // it is padded with `=` characters at the end switch mod(mload(data), 3) case 1 { mstore8(sub(resultPtr, 1), 0x3d) mstore8(sub(resultPtr, 2), 0x3d) } case 2 { mstore8(sub(resultPtr, 1), 0x3d) } } return result; } }
//SPDX-License-Identifier: MIT pragma solidity 0.8.24; import {svg} from "./SVG.sol"; import {utils, LibString, numUtils} from "./Utils.sol"; import "./FixedAssets.sol"; library baseSVG { string constant GEIST = 'style="font-family: Geist" '; string constant DARK_BLUE = "#121B44"; string constant STOIC_WHITE = "#DEE4FB"; function _svgProps() internal pure returns (string memory) { return string.concat( svg.prop("width", "300"), svg.prop("height", "484"), svg.prop("viewBox", "0 0 300 484"), svg.prop("style", "background:none") ); } function _baseElements(FixedAssetReader _assetReader) internal view returns (string memory) { return string.concat( svg.rect( string.concat( svg.prop("fill", DARK_BLUE), svg.prop("rx", "8"), svg.prop("width", "300"), svg.prop("height", "484") ) ), _styles(_assetReader), _leverageLogo(), _boldLogo(_assetReader), _staticTextEls() ); } function _styles(FixedAssetReader _assetReader) private view returns (string memory) { return svg.el( "style", utils.NULL, string.concat( '@font-face { font-family: "Geist"; src: url("data:font/woff2;utf-8;base64,', _assetReader.readAsset(bytes4(keccak256("geist"))), '"); }' ) ); } function _leverageLogo() internal pure returns (string memory) { return string.concat( svg.path( "M20.2 31.2C19.1 32.4 17.6 33 16 33L16 21C17.6 21 19.1 21.6 20.2 22.7C21.4 23.9 22 25.4 22 27C22 28.6 21.4 30.1 20.2 31.2Z", svg.prop("fill", STOIC_WHITE) ), svg.path( "M22 27C22 25.4 22.6 23.9 23.8 22.7C25 21.6 26.4 21 28 21V33C26.4 33 25 32.4 24 31.2C22.6 30.1 22 28.6 22 27Z", svg.prop("fill", STOIC_WHITE) ) ); } function _boldLogo(FixedAssetReader _assetReader) internal view returns (string memory) { return svg.el( "image", string.concat( svg.prop("x", "264"), svg.prop("y", "373.5"), svg.prop("width", "20"), svg.prop("height", "20"), svg.prop( "href", string.concat("data:image/svg+xml;base64,", _assetReader.readAsset(bytes4(keccak256("BOLD")))) ) ) ); } function _staticTextEls() internal pure returns (string memory) { return string.concat( svg.text( string.concat( GEIST, svg.prop("x", "16"), svg.prop("y", "358"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), "Collateral" ), svg.text( string.concat( GEIST, svg.prop("x", "16"), svg.prop("y", "389"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), "Debt" ), svg.text( string.concat( GEIST, svg.prop("x", "16"), svg.prop("y", "420"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), "Interest Rate" ), svg.text( string.concat( GEIST, svg.prop("x", "265"), svg.prop("y", "422"), svg.prop("font-size", "20"), svg.prop("fill", "white") ), "%" ), svg.text( string.concat( GEIST, svg.prop("x", "16"), svg.prop("y", "462"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), "Owner" ) ); } function _formattedDynamicEl(string memory _value, uint256 _x, uint256 _y) internal pure returns (string memory) { return svg.text( string.concat( GEIST, svg.prop("text-anchor", "end"), svg.prop("x", LibString.toString(_x)), svg.prop("y", LibString.toString(_y)), svg.prop("font-size", "20"), svg.prop("fill", "white") ), _value ); } function _formattedIdEl(string memory _id) internal pure returns (string memory) { return svg.text( string.concat( GEIST, svg.prop("text-anchor", "end"), svg.prop("x", "284"), svg.prop("y", "33"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), _id ); } function _formattedAddressEl(address _address) internal pure returns (string memory) { return svg.text( string.concat( GEIST, svg.prop("text-anchor", "end"), svg.prop("x", "284"), svg.prop("y", "462"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), string.concat( LibString.slice(LibString.toHexStringChecksummed(_address), 0, 6), "...", LibString.slice(LibString.toHexStringChecksummed(_address), 38, 42) ) ); } function _collLogo(string memory _collName, FixedAssetReader _assetReader) internal view returns (string memory) { return svg.el( "image", string.concat( svg.prop("x", "264"), svg.prop("y", "342.5"), svg.prop("width", "20"), svg.prop("height", "20"), svg.prop( "href", string.concat( "data:image/svg+xml;base64,", _assetReader.readAsset(bytes4(keccak256(bytes(_collName)))) ) ) ) ); } function _statusEl(string memory _status) internal pure returns (string memory) { return svg.text( string.concat( GEIST, svg.prop("x", "40"), svg.prop("y", "33"), svg.prop("font-size", "14"), svg.prop("fill", "white") ), _status ); } function _dynamicTextEls(uint256 _debt, uint256 _coll, uint256 _annualInterestRate) internal pure returns (string memory) { return string.concat( _formattedDynamicEl(numUtils.toLocaleString(_coll, 18, 4), 256, 360), _formattedDynamicEl(numUtils.toLocaleString(_debt, 18, 2), 256, 391), _formattedDynamicEl(numUtils.toLocaleString(_annualInterestRate, 16, 2), 256, 422) ); } }
//SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "./SVG.sol"; library bauhaus { string constant GOLDEN = "#F5D93A"; string constant CORAL = "#FB7C59"; string constant GREEN = "#63D77D"; string constant CYAN = "#95CBF3"; string constant BLUE = "#405AE5"; string constant DARK_BLUE = "#121B44"; string constant BROWN = "#D99664"; enum colorCode { GOLDEN, CORAL, GREEN, CYAN, BLUE, DARK_BLUE, BROWN } function _bauhaus(string memory _collName, uint256 _troveId) internal pure returns (string memory) { bytes32 collSig = keccak256(bytes(_collName)); uint256 variant = _troveId % 4; if (collSig == keccak256("WETH")) { return _img1(variant); } else if (collSig == keccak256("wstETH")) { return _img2(variant); } else { // assume rETH return _img3(variant); } } function _colorCode2Hex(colorCode _color) private pure returns (string memory) { if (_color == colorCode.GOLDEN) { return GOLDEN; } else if (_color == colorCode.CORAL) { return CORAL; } else if (_color == colorCode.GREEN) { return GREEN; } else if (_color == colorCode.CYAN) { return CYAN; } else if (_color == colorCode.BLUE) { return BLUE; } else if (_color == colorCode.DARK_BLUE) { return DARK_BLUE; } else { return BROWN; } } struct COLORS { colorCode rect1; colorCode rect2; colorCode rect3; colorCode rect4; colorCode rect5; colorCode poly; colorCode circle1; colorCode circle2; colorCode circle3; } function _colors1(uint256 _variant) internal pure returns (COLORS memory) { if (_variant == 0) { return COLORS( colorCode.BLUE, // rect1 colorCode.GOLDEN, // rect2 colorCode.GOLDEN, // rect3 colorCode.BROWN, // rect4 colorCode.CORAL, // rect5 colorCode.CYAN, // poly colorCode.GREEN, // circle1 colorCode.DARK_BLUE, // circle2 colorCode.GOLDEN // circle3 ); } else if (_variant == 1) { return COLORS( colorCode.GREEN, // rect1 colorCode.BLUE, // rect2 colorCode.GOLDEN, // rect3 colorCode.BROWN, // rect4 colorCode.GOLDEN, // rect5 colorCode.CORAL, // poly colorCode.BLUE, // circle1 colorCode.DARK_BLUE, // circle2 colorCode.BLUE // circle3 ); } else if (_variant == 2) { return COLORS( colorCode.BLUE, // rect1 colorCode.GOLDEN, // rect2 colorCode.CYAN, // rect3 colorCode.GOLDEN, // rect4 colorCode.BROWN, // rect5 colorCode.GREEN, // poly colorCode.CORAL, // circle1 colorCode.DARK_BLUE, // circle2 colorCode.BROWN // circle3 ); } else { return COLORS( colorCode.CYAN, // rect1 colorCode.BLUE, // rect2 colorCode.BLUE, // rect3 colorCode.BROWN, // rect4 colorCode.BLUE, // rect5 colorCode.GREEN, // poly colorCode.GOLDEN, // circle1 colorCode.DARK_BLUE, // circle2 colorCode.BLUE // circle3 ); } } function _img1(uint256 _variant) internal pure returns (string memory) { COLORS memory colors = _colors1(_variant); return string.concat(_rects1(colors), _polygons1(colors), _circles1(colors)); } function _rects1(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //background svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "55"), svg.prop("width", "268"), svg.prop("height", "268"), svg.prop("fill", DARK_BLUE) ) ), // large right rect | rect1 svg.rect( string.concat( svg.prop("x", "128"), svg.prop("y", "55"), svg.prop("width", "156"), svg.prop("height", "268"), svg.prop("fill", _colorCode2Hex(_colors.rect1)) ) ), // small upper right rect | rect2 svg.rect( string.concat( svg.prop("x", "228"), svg.prop("y", "55"), svg.prop("width", "56"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect2)) ) ), // large central left rect | rect3 svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "111"), svg.prop("width", "134"), svg.prop("height", "156"), svg.prop("fill", _colorCode2Hex(_colors.rect3)) ) ), // small lower left rect | rect4 svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "267"), svg.prop("width", "112"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect4)) ) ), // small lower right rect | rect5 svg.rect( string.concat( svg.prop("x", "228"), svg.prop("y", "267"), svg.prop("width", "56"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect5)) ) ) ); } function _polygons1(COLORS memory _colors) internal pure returns (string memory) { return string.concat( // left triangle | poly1 svg.polygon( string.concat(svg.prop("points", "16,55 72,55 16,111"), svg.prop("fill", _colorCode2Hex(_colors.poly))) ), // right triangle | poly2 svg.polygon( string.concat(svg.prop("points", "72,55 128,55 72,111"), svg.prop("fill", _colorCode2Hex(_colors.poly))) ) ); } function _circles1(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //large central circle | circle1 svg.circle( string.concat( svg.prop("cx", "150"), svg.prop("cy", "189"), svg.prop("r", "78"), svg.prop("fill", _colorCode2Hex(_colors.circle1)) ) ), //small right circle | circle2 svg.circle( string.concat( svg.prop("cx", "228"), svg.prop("cy", "295"), svg.prop("r", "28"), svg.prop("fill", _colorCode2Hex(_colors.circle2)) ) ), //small right half circle | circle3 svg.path( "M228 267C220.574 267 213.452 269.95 208.201 275.201C202.95 280.452 200 287.574 200 295C200 302.426 202.95 309.548 208.201 314.799C213.452 320.05 220.574 323 228 323L228 267Z", svg.prop("fill", _colorCode2Hex(_colors.circle3)) ) ); } function _colors2(uint256 _variant) internal pure returns (COLORS memory) { if (_variant == 0) { return COLORS( colorCode.BROWN, // rect1 colorCode.GOLDEN, // rect2 colorCode.BLUE, // rect3 colorCode.GREEN, // rect4 colorCode.CORAL, // rect5 colorCode.GOLDEN, // unused colorCode.GOLDEN, // circle1 colorCode.CYAN, // circle2 colorCode.GREEN // circle3 ); } else if (_variant == 1) { return COLORS( colorCode.GREEN, // rect1 colorCode.BROWN, // rect2 colorCode.GOLDEN, // rect3 colorCode.BLUE, // rect4 colorCode.CYAN, // rect5 colorCode.GOLDEN, // unused colorCode.GREEN, // circle1 colorCode.CORAL, // circle2 colorCode.BLUE // circle3 ); } else if (_variant == 2) { return COLORS( colorCode.BLUE, // rect1 colorCode.GOLDEN, // rect2 colorCode.GREEN, // rect3 colorCode.BLUE, // rect4 colorCode.CORAL, // rect5 colorCode.GOLDEN, // unused colorCode.CYAN, // circle1 colorCode.BROWN, // circle2 colorCode.BROWN // circle3 ); } else { return COLORS( colorCode.GOLDEN, // rect1 colorCode.GREEN, // rect2 colorCode.BLUE, // rect3 colorCode.GOLDEN, // rect4 colorCode.BROWN, // rect5 colorCode.GOLDEN, // unused colorCode.BROWN, // circle1 colorCode.CYAN, // circle2 colorCode.CORAL // circle3 ); } } function _img2(uint256 _variant) internal pure returns (string memory) { COLORS memory colors = _colors2(_variant); return string.concat(_rects2(colors), _circles2(colors)); } function _rects2(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //background svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "55"), svg.prop("width", "268"), svg.prop("height", "268"), svg.prop("fill", DARK_BLUE) ) ), // large upper right rect | rect1 svg.rect( string.concat( svg.prop("x", "128"), svg.prop("y", "55"), svg.prop("width", "156"), svg.prop("height", "156"), svg.prop("fill", _colorCode2Hex(_colors.rect1)) ) ), // large central left rect | rect2 svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "111"), svg.prop("width", "134"), svg.prop("height", "100"), svg.prop("fill", _colorCode2Hex(_colors.rect2)) ) ), // large lower left rect | rect3 svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "211"), svg.prop("width", "212"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect3)) ) ), // small lower central rect | rect4 svg.rect( string.concat( svg.prop("x", "72"), svg.prop("y", "267"), svg.prop("width", "78"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect4)) ) ), // small lower right rect | rect5 svg.rect( string.concat( svg.prop("x", "150"), svg.prop("y", "267"), svg.prop("width", "134"), svg.prop("height", "56"), svg.prop("fill", _colorCode2Hex(_colors.rect5)) ) ) ); } function _circles2(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //lower left circle | circle1 svg.circle( string.concat( svg.prop("cx", "44"), svg.prop("cy", "295"), svg.prop("r", "28"), svg.prop("fill", _colorCode2Hex(_colors.circle1)) ) ), //upper left half circle | circle2 svg.path( "M16 55C16 62.4 17.4 69.6 20.3 76.4C23.1 83.2 27.2 89.4 32.4 94.6C37.6 99.8 43.8 103.9 50.6 106.7C57.4 109.6 64.6 111 72 111C79.4 111 86.6 109.6 93.4 106.7C100.2 103.9 106.4 99.8 111.6 94.6C116.8 89.4 120.9 83.2 123.7 76.4C126.6 69.6 128 62.4 128 55L16 55Z", svg.prop("fill", _colorCode2Hex(_colors.circle2)) ), //central right half circle | circle3 svg.path( "M284 211C284 190.3 275.8 170.5 261.2 155.8C246.5 141.2 226.7 133 206 133C185.3 133 165.5 141.2 150.9 155.86C136.2 170.5 128 190.3 128 211L284 211Z", svg.prop("fill", _colorCode2Hex(_colors.circle3)) ) ); } function _colors3(uint256 _variant) internal pure returns (COLORS memory) { if (_variant == 0) { return COLORS( colorCode.BLUE, // rect1 colorCode.CORAL, // rect2 colorCode.BLUE, // rect3 colorCode.GREEN, // rect4 colorCode.GOLDEN, // unused colorCode.GOLDEN, // unused colorCode.GOLDEN, // circle1 colorCode.CYAN, // circle2 colorCode.GOLDEN // circle3 ); } else if (_variant == 1) { return COLORS( colorCode.CORAL, // rect1 colorCode.GREEN, // rect2 colorCode.BROWN, // rect3 colorCode.GOLDEN, // rect4 colorCode.GOLDEN, // unused colorCode.GOLDEN, // unused colorCode.BLUE, // circle1 colorCode.BLUE, // circle2 colorCode.CYAN // circle3 ); } else if (_variant == 2) { return COLORS( colorCode.CORAL, // rect1 colorCode.CYAN, // rect2 colorCode.CORAL, // rect3 colorCode.GOLDEN, // rect4 colorCode.GOLDEN, // unused colorCode.GOLDEN, // unused colorCode.GREEN, // circle1 colorCode.BLUE, // circle2 colorCode.GREEN // circle3 ); } else { return COLORS( colorCode.GOLDEN, // rect1 colorCode.CORAL, // rect2 colorCode.GREEN, // rect3 colorCode.BLUE, // rect4 colorCode.GOLDEN, // unused colorCode.GOLDEN, // unused colorCode.BROWN, // circle1 colorCode.BLUE, // circle2 colorCode.GREEN // circle3 ); } } function _img3(uint256 _variant) internal pure returns (string memory) { COLORS memory colors = _colors3(_variant); return string.concat(_rects3(colors), _circles3(colors)); } function _rects3(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //background svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "55"), svg.prop("width", "268"), svg.prop("height", "268"), svg.prop("fill", DARK_BLUE) ) ), // lower left rect | rect1 svg.rect( string.concat( svg.prop("x", "16"), svg.prop("y", "205"), svg.prop("width", "75"), svg.prop("height", "118"), svg.prop("fill", _colorCode2Hex(_colors.rect1)) ) ), // central rect | rect2 svg.rect( string.concat( svg.prop("x", "91"), svg.prop("y", "205"), svg.prop("width", "136"), svg.prop("height", "59"), svg.prop("fill", _colorCode2Hex(_colors.rect2)) ) ), // central right rect | rect3 svg.rect( string.concat( svg.prop("x", "166"), svg.prop("y", "180"), svg.prop("width", "118"), svg.prop("height", "25"), svg.prop("fill", _colorCode2Hex(_colors.rect3)) ) ), // upper right rect | rect4 svg.rect( string.concat( svg.prop("x", "166"), svg.prop("y", "55"), svg.prop("width", "118"), svg.prop("height", "126"), svg.prop("fill", _colorCode2Hex(_colors.rect4)) ) ) ); } function _circles3(COLORS memory _colors) internal pure returns (string memory) { return string.concat( //upper left circle | circle1 svg.circle( string.concat( svg.prop("cx", "91"), svg.prop("cy", "130"), svg.prop("r", "75"), svg.prop("fill", _colorCode2Hex(_colors.circle1)) ) ), //upper right half circle | circle2 svg.path( "M284 264 166 264 166 263C166 232 193 206 225 205C258 206 284 232 284 264C284 264 284 264 284 264Z", svg.prop("fill", _colorCode2Hex(_colors.circle2)) ), //lower right half circle | circle3 svg.path( "M284 323 166 323 166 323C166 290 193 265 225 264C258 265 284 290 284 323C284 323 284 323 284 323Z", svg.prop("fill", _colorCode2Hex(_colors.circle3)) ) ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
//SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import {utils, LibString} from "./Utils.sol"; /// @notice Core SVG utility library which helps us construct onchain SVG's with a simple, web-like API. /// @author Modified from (https://github.com/w1nt3r-eth/hot-chain-svg/blob/main/contracts/SVG.sol) by w1nt3r-eth. library svg { /* GLOBAL CONSTANTS */ string internal constant _SVG = 'xmlns="http://www.w3.org/2000/svg"'; string internal constant _HTML = 'xmlns="http://www.w3.org/1999/xhtml"'; string internal constant _XMLNS = "http://www.w3.org/2000/xmlns/ "; string internal constant _XLINK = "http://www.w3.org/1999/xlink "; /* MAIN ELEMENTS */ function g(string memory _props, string memory _children) internal pure returns (string memory) { return el("g", _props, _children); } function _svg(string memory _props, string memory _children) internal pure returns (string memory) { return el("svg", string.concat(_SVG, " ", _props), _children); } function style(string memory _title, string memory _props) internal pure returns (string memory) { return el("style", string.concat(".", _title, " ", _props)); } function path(string memory _d) internal pure returns (string memory) { return el("path", prop("d", _d, true)); } function path(string memory _d, string memory _props) internal pure returns (string memory) { return el("path", string.concat(prop("d", _d), _props)); } function path(string memory _d, string memory _props, string memory _children) internal pure returns (string memory) { return el("path", string.concat(prop("d", _d), _props), _children); } function text(string memory _props, string memory _children) internal pure returns (string memory) { return el("text", _props, _children); } function line(string memory _props) internal pure returns (string memory) { return el("line", _props); } function line(string memory _props, string memory _children) internal pure returns (string memory) { return el("line", _props, _children); } function circle(string memory _props) internal pure returns (string memory) { return el("circle", _props); } function circle(string memory _props, string memory _children) internal pure returns (string memory) { return el("circle", _props, _children); } function circle(string memory cx, string memory cy, string memory r) internal pure returns (string memory) { return el("circle", string.concat(prop("cx", cx), prop("cy", cy), prop("r", r, true))); } function circle(string memory cx, string memory cy, string memory r, string memory _children) internal pure returns (string memory) { return el("circle", string.concat(prop("cx", cx), prop("cy", cy), prop("r", r, true)), _children); } function circle(string memory cx, string memory cy, string memory r, string memory _props, string memory _children) internal pure returns (string memory) { return el("circle", string.concat(prop("cx", cx), prop("cy", cy), prop("r", r), _props), _children); } function ellipse(string memory _props) internal pure returns (string memory) { return el("ellipse", _props); } function ellipse(string memory _props, string memory _children) internal pure returns (string memory) { return el("ellipse", _props, _children); } function polygon(string memory _props) internal pure returns (string memory) { return el("polygon", _props); } function polygon(string memory _props, string memory _children) internal pure returns (string memory) { return el("polygon", _props, _children); } function polyline(string memory _props) internal pure returns (string memory) { return el("polyline", _props); } function polyline(string memory _props, string memory _children) internal pure returns (string memory) { return el("polyline", _props, _children); } function rect(string memory _props) internal pure returns (string memory) { return el("rect", _props); } function rect(string memory _props, string memory _children) internal pure returns (string memory) { return el("rect", _props, _children); } function filter(string memory _props, string memory _children) internal pure returns (string memory) { return el("filter", _props, _children); } function cdata(string memory _content) internal pure returns (string memory) { return string.concat("<![CDATA[", _content, "]]>"); } /* GRADIENTS */ function radialGradient(string memory _props, string memory _children) internal pure returns (string memory) { return el("radialGradient", _props, _children); } function linearGradient(string memory _props, string memory _children) internal pure returns (string memory) { return el("linearGradient", _props, _children); } function gradientStop(uint256 offset, string memory stopColor, string memory _props) internal pure returns (string memory) { return el( "stop", string.concat( prop("stop-color", stopColor), " ", prop("offset", string.concat(LibString.toString(offset), "%")), " ", _props ), utils.NULL ); } /* ANIMATION */ function animateTransform(string memory _props) internal pure returns (string memory) { return el("animateTransform", _props); } function animate(string memory _props) internal pure returns (string memory) { return el("animate", _props); } /* COMMON */ // A generic element, can be used to construct any SVG (or HTML) element function el(string memory _tag, string memory _props, string memory _children) internal pure returns (string memory) { return string.concat("<", _tag, " ", _props, ">", _children, "</", _tag, ">"); } // A generic element, can be used to construct SVG (or HTML) elements without children function el(string memory _tag, string memory _props) internal pure returns (string memory) { return string.concat("<", _tag, " ", _props, "/>"); } // an SVG attribute function prop(string memory _key, string memory _val) internal pure returns (string memory) { return string.concat(_key, "=", '"', _val, '" '); } function prop(string memory _key, string memory _val, bool last) internal pure returns (string memory) { if (last) { return string.concat(_key, "=", '"', _val, '"'); } else { return string.concat(_key, "=", '"', _val, '" '); } } }
//SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "lib/Solady/src/utils/LibString.sol"; library numUtils { function toLocale(string memory _wholeNumber) internal pure returns (string memory) { bytes memory b = bytes(_wholeNumber); uint256 len = b.length; if (len < 4) return _wholeNumber; uint256 numCommas = (len - 1) / 3; bytes memory result = new bytes(len + numCommas); uint256 j = result.length - 1; uint256 k = len; for (uint256 i = 0; i < len; i++) { result[j] = b[k - 1]; j = j > 1 ? j - 1 : 0; k--; if (k > 0 && (len - k) % 3 == 0) { result[j] = ","; j = j > 1 ? j - 1 : 0; } } return string(result); } // returns a string representation of a number with commas, where result = _value / 10 ** _divisor function toLocaleString(uint256 _value, uint8 _divisor, uint8 _precision) internal pure returns (string memory) { uint256 whole; uint256 fraction; if (_divisor > 0) { whole = _value / 10 ** _divisor; // check if the divisor is less than the precision if (_divisor <= _precision) { fraction = (_value % 10 ** _divisor); // adjust fraction to be the same as the precision fraction = fraction * 10 ** (_precision - _divisor); // if whole is zero, then add another zero to the fraction, special case if the value is 1 fraction = (whole == 0 && _value != 1) ? fraction * 10 : fraction; } else { fraction = (_value % 10 ** _divisor) / 10 ** (_divisor - _precision - 1); } } else { whole = _value; } string memory wholeStr = toLocale(LibString.toString(whole)); if (fraction == 0) { if (whole > 0 && _precision > 0) wholeStr = string.concat(wholeStr, "."); for (uint8 i = 0; i < _precision; i++) { wholeStr = string.concat(wholeStr, "0"); } return wholeStr; } string memory fractionStr = LibString.slice(LibString.toString(fraction), 0, _precision); // pad with leading zeros if (_precision > bytes(fractionStr).length) { uint256 len = _precision - bytes(fractionStr).length; string memory zeroStr = ""; for (uint8 i = 0; i < len; i++) { zeroStr = string.concat(zeroStr, "0"); } fractionStr = string.concat(zeroStr, fractionStr); } return string.concat(wholeStr, _precision > 0 ? "." : "", fractionStr); } } /// @notice Core utils used extensively to format CSS and numbers. /// @author Modified from (https://github.com/w1nt3r-eth/hot-chain-svg/blob/main/contracts/Utils.sol) by w1nt3r-eth. library utils { // used to simulate empty strings string internal constant NULL = ""; // formats a CSS variable line. includes a semicolon for formatting. function setCssVar(string memory _key, string memory _val) internal pure returns (string memory) { return string.concat("--", _key, ":", _val, ";"); } // formats getting a css variable function getCssVar(string memory _key) internal pure returns (string memory) { return string.concat("var(--", _key, ")"); } // formats getting a def URL function getDefURL(string memory _id) internal pure returns (string memory) { return string.concat("url(#", _id, ")"); } // formats rgba white with a specified opacity / alpha function white_a(uint256 _a) internal pure returns (string memory) { return rgba(255, 255, 255, _a); } // formats rgba black with a specified opacity / alpha function black_a(uint256 _a) internal pure returns (string memory) { return rgba(0, 0, 0, _a); } // formats generic rgba color in css function rgba(uint256 _r, uint256 _g, uint256 _b, uint256 _a) internal pure returns (string memory) { string memory formattedA = _a < 100 ? string.concat("0.", LibString.toString(_a)) : "1"; return string.concat( "rgba(", LibString.toString(_r), ",", LibString.toString(_g), ",", LibString.toString(_b), ",", formattedA, ")" ); } function cssBraces(string memory _attribute, string memory _value) internal pure returns (string memory) { return string.concat(" {", _attribute, ": ", _value, "}"); } function cssBraces(string[] memory _attributes, string[] memory _values) internal pure returns (string memory) { require(_attributes.length == _values.length, "Utils: Unbalanced Arrays"); uint256 len = _attributes.length; string memory results = " {"; for (uint256 i = 0; i < len; i++) { results = string.concat(results, _attributes[i], ": ", _values[i], "; "); } return string.concat(results, "}"); } //deals with integers (i.e. no decimals) function points(uint256[2][] memory pointsArray) internal pure returns (string memory) { require(pointsArray.length >= 3, "Utils: Array too short"); uint256 len = pointsArray.length - 1; string memory results = 'points="'; for (uint256 i = 0; i < len; i++) { results = string.concat( results, LibString.toString(pointsArray[i][0]), ",", LibString.toString(pointsArray[i][1]), " " ); } return string.concat( results, LibString.toString(pointsArray[len][0]), ",", LibString.toString(pointsArray[len][1]), '"' ); } // allows for a uniform precision to be applied to all points function points(uint256[2][] memory pointsArray, uint256 decimalPrecision) internal pure returns (string memory) { require(pointsArray.length >= 3, "Utils: Array too short"); uint256 len = pointsArray.length - 1; string memory results = 'points="'; for (uint256 i = 0; i < len; i++) { results = string.concat( results, toString(pointsArray[i][0], decimalPrecision), ",", toString(pointsArray[i][1], decimalPrecision), " " ); } return string.concat( results, toString(pointsArray[len][0], decimalPrecision), ",", toString(pointsArray[len][1], decimalPrecision), '"' ); } // checks if two strings are equal function stringsEqual(string memory _a, string memory _b) internal pure returns (bool) { return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b)); } // returns the length of a string in characters function utfStringLength(string memory _str) internal pure returns (uint256 length) { uint256 i = 0; bytes memory string_rep = bytes(_str); while (i < string_rep.length) { if (string_rep[i] >> 7 == 0) { i += 1; } else if (string_rep[i] >> 5 == bytes1(uint8(0x6))) { i += 2; } else if (string_rep[i] >> 4 == bytes1(uint8(0xE))) { i += 3; } else if (string_rep[i] >> 3 == bytes1(uint8(0x1E))) { i += 4; } //For safety else { i += 1; } length++; } } // allows the insertion of a decimal point in the returned string at precision function toString(uint256 value, uint256 precision) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } require(precision <= digits && precision > 0, "Utils: precision invalid"); precision == digits ? digits += 2 : digits++; //adds a space for the decimal point, 2 if it is the whole uint uint256 decimalPlacement = digits - precision - 1; bytes memory buffer = new bytes(digits); buffer[decimalPlacement] = 0x2E; // add the decimal point, ASCII 46/hex 2E if (decimalPlacement == 1) { buffer[0] = 0x30; } while (value != 0) { digits -= 1; if (digits != decimalPlacement) { buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } } return string(buffer); } }
//SPDX-License-Identifier: MIT pragma solidity 0.8.24; import "lib/Solady/src/utils/SSTORE2.sol"; contract FixedAssetReader { struct Asset { uint128 start; uint128 end; } address public immutable pointer; mapping(bytes4 => Asset) public assets; function readAsset(bytes4 _sig) public view returns (string memory) { return string(SSTORE2.read(pointer, uint256(assets[_sig].start), uint256(assets[_sig].end))); } constructor(address _pointer, bytes4[] memory _sigs, Asset[] memory _assets) { pointer = _pointer; require(_sigs.length == _assets.length, "FixedAssetReader: Invalid input"); for (uint256 i = 0; i < _sigs.length; i++) { assets[_sigs[i]] = _assets[i]; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for converting numbers into strings and other string operations. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol) /// /// @dev Note: /// For performance and bytecode compactness, most of the string operations are restricted to /// byte strings (7-bit ASCII), except where otherwise specified. /// Usage of byte string operations on charsets with runes spanning two or more bytes /// can lead to undefined behavior. library LibString { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The length of the output is too small to contain all the hex digits. error HexLengthInsufficient(); /// @dev The length of the string is more than 32 bytes. error TooBigForSmallString(); /// @dev The input string must be a 7-bit ASCII. error StringNot7BitASCII(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The constant returned when the `search` is not found in the string. uint256 internal constant NOT_FOUND = type(uint256).max; /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant ALPHANUMERIC_7_BIT_ASCII = 0x7fffffe07fffffe03ff000000000000; /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant LETTERS_7_BIT_ASCII = 0x7fffffe07fffffe0000000000000000; /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyz'. uint128 internal constant LOWERCASE_7_BIT_ASCII = 0x7fffffe000000000000000000000000; /// @dev Lookup for 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. uint128 internal constant UPPERCASE_7_BIT_ASCII = 0x7fffffe0000000000000000; /// @dev Lookup for '0123456789'. uint128 internal constant DIGITS_7_BIT_ASCII = 0x3ff000000000000; /// @dev Lookup for '0123456789abcdefABCDEF'. uint128 internal constant HEXDIGITS_7_BIT_ASCII = 0x7e0000007e03ff000000000000; /// @dev Lookup for '01234567'. uint128 internal constant OCTDIGITS_7_BIT_ASCII = 0xff000000000000; /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'. uint128 internal constant PRINTABLE_7_BIT_ASCII = 0x7fffffffffffffffffffffff00003e00; /// @dev Lookup for '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'. uint128 internal constant PUNCTUATION_7_BIT_ASCII = 0x78000001f8000001fc00fffe00000000; /// @dev Lookup for ' \t\n\r\x0b\x0c'. uint128 internal constant WHITESPACE_7_BIT_ASCII = 0x100003e00; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the base 10 decimal representation of `value`. function toString(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // The maximum value of a uint256 contains 78 digits (1 byte per digit), but // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned. // We will need 1 word for the trailing zeros padding, 1 word for the length, // and 3 words for a maximum of 78 digits. str := add(mload(0x40), 0x80) mstore(0x40, add(str, 0x20)) // Allocate the memory. mstore(str, 0) // Zeroize the slot after the string. let end := str // Cache the end of the memory to calculate the length later. let w := not(0) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 1)`. // Store the character to the pointer. // The ASCII index of the '0' character is 48. mstore8(str, add(48, mod(temp, 10))) temp := div(temp, 10) // Keep dividing `temp` until zero. if iszero(temp) { break } } let length := sub(end, str) str := sub(str, 0x20) // Move the pointer 32 bytes back to make room for the length. mstore(str, length) // Store the length. } } /// @dev Returns the base 10 decimal representation of `value`. function toString(int256 value) internal pure returns (string memory str) { if (value >= 0) return toString(uint256(value)); unchecked { str = toString(~uint256(value) + 1); } /// @solidity memory-safe-assembly assembly { // We still have some spare memory space on the left, // as we have allocated 3 words (96 bytes) for up to 78 digits. let length := mload(str) // Load the string length. mstore(str, 0x2d) // Store the '-' character. str := sub(str, 1) // Move back the string pointer by a byte. mstore(str, add(length, 1)) // Update the string length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HEXADECIMAL OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2 + 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) { str = toHexStringNoPrefix(value, length); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Store the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`, /// left-padded to an input length of `length` bytes. /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte, /// giving a total length of `length * 2` bytes. /// Reverts if `length` is too small for the output to contain all the digits. function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length. // We add 0x20 to the total and round down to a multiple of 0x20. // (0x20 + 0x20 + 0x02 + 0x20) = 0x62. str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f))) mstore(0x40, add(str, 0x20)) // Allocate the memory. mstore(str, 0) // Zeroize the slot after the string. let end := str // Cache the end to calculate the length later. // Store "0123456789abcdef" in scratch space. mstore(0x0f, 0x30313233343536373839616263646566) let start := sub(str, add(length, length)) let w := not(1) // Tsk. let temp := value // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for {} 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(xor(str, start)) { break } } if temp { mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`. revert(0x1c, 0x04) } let strLength := sub(end, str) str := sub(str, 0x20) mstore(str, strLength) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2 + 2` bytes. function toHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Store the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x". /// The output excludes leading "0" from the `toHexString` output. /// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`. function toMinimalHexString(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := add(mload(str), 2) // Compute the length. mstore(add(str, o), 0x3078) // Store the "0x" prefix, accounting for leading zero. str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Store the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output excludes leading "0" from the `toHexStringNoPrefix` output. /// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`. function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present. let strLength := mload(str) // Get the length. str := add(str, o) // Move the pointer, accounting for leading zero. mstore(str, sub(strLength, o)) // Store the length, accounting for leading zero. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. /// As address are 20 bytes long, the output will left-padded to have /// a length of `20 * 2` bytes. function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x40 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0. str := add(mload(0x40), 0x80) mstore(0x40, add(str, 0x20)) // Allocate the memory. mstore(str, 0) // Zeroize the slot after the string. let end := str // Cache the end to calculate the length later. mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. let w := not(1) // Tsk. // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let temp := value } 1 {} { str := add(str, w) // `sub(str, 2)`. mstore8(add(str, 1), mload(and(temp, 15))) mstore8(str, mload(and(shr(4, temp), 15))) temp := shr(8, temp) if iszero(temp) { break } } let strLength := sub(end, str) str := sub(str, 0x20) mstore(str, strLength) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte, /// and the alphabets are capitalized conditionally according to /// https://eips.ethereum.org/EIPS/eip-55 function toHexStringChecksummed(address value) internal pure returns (string memory str) { str = toHexString(value); /// @solidity memory-safe-assembly assembly { let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...` let o := add(str, 0x22) let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... ` let t := shl(240, 136) // `0b10001000 << 240` for { let i := 0 } 1 {} { mstore(add(i, i), mul(t, byte(i, hashed))) i := add(i, 1) if eq(i, 20) { break } } mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask))))) o := add(o, 0x20) mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask))))) } } /// @dev Returns the hexadecimal representation of `value`. /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte. function toHexString(address value) internal pure returns (string memory str) { str = toHexStringNoPrefix(value); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Store the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Store the length. } } /// @dev Returns the hexadecimal representation of `value`. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(address value) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { str := mload(0x40) // Allocate the memory. // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length, // 0x02 bytes for the prefix, and 0x28 bytes for the digits. // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80. mstore(0x40, add(str, 0x80)) mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. str := add(str, 2) mstore(str, 40) // Store the length. let o := add(str, 0x20) mstore(add(o, 40), 0) // Zeroize the slot after the string. value := shl(96, value) // We write the string from rightmost digit to leftmost digit. // The following is essentially a do-while loop that also handles the zero case. for { let i := 0 } 1 {} { let p := add(o, add(i, i)) let temp := byte(i, value) mstore8(add(p, 1), mload(and(temp, 15))) mstore8(p, mload(shr(4, temp))) i := add(i, 1) if eq(i, 20) { break } } } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexString(bytes memory raw) internal pure returns (string memory str) { str = toHexStringNoPrefix(raw); /// @solidity memory-safe-assembly assembly { let strLength := add(mload(str), 2) // Compute the length. mstore(str, 0x3078) // Store the "0x" prefix. str := sub(str, 2) // Move the pointer. mstore(str, strLength) // Store the length. } } /// @dev Returns the hex encoded string from the raw bytes. /// The output is encoded using 2 hexadecimal digits per byte. function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) { /// @solidity memory-safe-assembly assembly { let length := mload(raw) str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix. mstore(str, add(length, length)) // Store the length of the output. mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup. let o := add(str, 0x20) let end := add(raw, length) for {} iszero(eq(raw, end)) {} { raw := add(raw, 1) mstore8(add(o, 1), mload(and(mload(raw), 15))) mstore8(o, mload(and(shr(4, mload(raw)), 15))) o := add(o, 2) } mstore(o, 0) // Zeroize the slot after the string. mstore(0x40, add(o, 0x20)) // Allocate the memory. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RUNE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the number of UTF characters in the string. function runeCount(string memory s) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { if mload(s) { mstore(0x00, div(not(0), 255)) mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506) let o := add(s, 0x20) let end := add(o, mload(s)) for { result := 1 } 1 { result := add(result, 1) } { o := add(o, byte(0, mload(shr(250, mload(o))))) if iszero(lt(o, end)) { break } } } } } /// @dev Returns if this string is a 7-bit ASCII string. /// (i.e. all characters codes are in [0..127]) function is7BitASCII(string memory s) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let mask := shl(7, div(not(0), 255)) result := 1 let n := mload(s) if n { let o := add(s, 0x20) let end := add(o, n) let last := mload(end) mstore(end, 0) for {} 1 {} { if and(mask, mload(o)) { result := 0 break } o := add(o, 0x20) if iszero(lt(o, end)) { break } } mstore(end, last) } } } /// @dev Returns if this string is a 7-bit ASCII string, /// AND all characters are in the `allowed` lookup. /// Note: If `s` is empty, returns true regardless of `allowed`. function is7BitASCII(string memory s, uint128 allowed) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := 1 if mload(s) { let allowed_ := shr(128, shl(128, allowed)) let o := add(s, 0x20) let end := add(o, mload(s)) for {} 1 {} { result := and(result, shr(byte(0, mload(o)), allowed_)) o := add(o, 1) if iszero(and(result, lt(o, end))) { break } } } } } /// @dev Converts the bytes in the 7-bit ASCII string `s` to /// an allowed lookup for use in `is7BitASCII(s, allowed)`. /// To save runtime gas, you can cache the result in an immutable variable. function to7BitASCIIAllowedLookup(string memory s) internal pure returns (uint128 result) { /// @solidity memory-safe-assembly assembly { if mload(s) { let o := add(s, 0x20) let end := add(o, mload(s)) for {} 1 {} { result := or(result, shl(byte(0, mload(o)), 1)) o := add(o, 1) if iszero(lt(o, end)) { break } } if shr(128, result) { mstore(0x00, 0xc9807e0d) // `StringNot7BitASCII()`. revert(0x1c, 0x04) } } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* BYTE STRING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // For performance and bytecode compactness, byte string operations are restricted // to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets. // Usage of byte string operations on charsets with runes spanning two or more bytes // can lead to undefined behavior. /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`. function replace(string memory subject, string memory search, string memory replacement) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) let replacementLength := mload(replacement) subject := add(subject, 0x20) search := add(search, 0x20) replacement := add(replacement, 0x20) result := add(mload(0x40), 0x20) let subjectEnd := add(subject, subjectLength) if iszero(gt(searchLength, subjectLength)) { let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Copy the `replacement` one word at a time. for { let o := 0 } 1 {} { mstore(add(result, o), mload(add(replacement, o))) o := add(o, 0x20) if iszero(lt(o, replacementLength)) { break } } result := add(result, replacementLength) subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } mstore(result, t) result := add(result, 1) subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } } let resultRemainder := result result := add(mload(0x40), 0x20) let k := add(sub(resultRemainder, result), sub(subjectEnd, subject)) // Copy the rest of the string one word at a time. for {} lt(subject, subjectEnd) {} { mstore(resultRemainder, mload(subject)) resultRemainder := add(resultRemainder, 0x20) subject := add(subject, 0x20) } result := sub(result, 0x20) let last := add(add(result, 0x20), k) // Zeroize the slot after the string. mstore(last, 0) mstore(0x40, add(last, 0x20)) // Allocate the memory. mstore(result, k) // Store the length. } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for { let subjectLength := mload(subject) } 1 {} { if iszero(mload(search)) { if iszero(gt(from, subjectLength)) { result := from break } result := subjectLength break } let searchLength := mload(search) let subjectStart := add(subject, 0x20) result := not(0) // Initialize to `NOT_FOUND`. subject := add(subjectStart, from) let end := add(sub(add(subjectStart, subjectLength), searchLength), 1) let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(add(search, 0x20)) if iszero(and(lt(subject, end), lt(from, subjectLength))) { break } if iszero(lt(searchLength, 0x20)) { for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if iszero(shr(m, xor(mload(subject), s))) { if eq(keccak256(subject, searchLength), h) { result := sub(subject, subjectStart) break } } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } for {} 1 {} { if iszero(shr(m, xor(mload(subject), s))) { result := sub(subject, subjectStart) break } subject := add(subject, 1) if iszero(lt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from left to right. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function indexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = indexOf(subject, search, 0); } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left, starting from `from`. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search, uint256 from) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for {} 1 {} { result := not(0) // Initialize to `NOT_FOUND`. let searchLength := mload(search) if gt(searchLength, mload(subject)) { break } let w := result let fromMax := sub(mload(subject), searchLength) if iszero(gt(fromMax, from)) { from := fromMax } let end := add(add(subject, 0x20), w) subject := add(add(subject, 0x20), from) if iszero(gt(subject, end)) { break } // As this function is not too often used, // we shall simply use keccak256 for smaller bytecode size. for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} { if eq(keccak256(subject, searchLength), h) { result := sub(subject, add(end, 1)) break } subject := add(subject, w) // `sub(subject, 1)`. if iszero(gt(subject, end)) { break } } break } } } /// @dev Returns the byte index of the first location of `search` in `subject`, /// searching from right to left. /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found. function lastIndexOf(string memory subject, string memory search) internal pure returns (uint256 result) { result = lastIndexOf(subject, search, uint256(int256(-1))); } /// @dev Returns true if `search` is found in `subject`, false otherwise. function contains(string memory subject, string memory search) internal pure returns (bool) { return indexOf(subject, search) != NOT_FOUND; } /// @dev Returns whether `subject` starts with `search`. function startsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( iszero(gt(searchLength, mload(subject))), eq( keccak256(add(subject, 0x20), searchLength), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns whether `subject` ends with `search`. function endsWith(string memory subject, string memory search) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { let searchLength := mload(search) let subjectLength := mload(subject) // Whether `search` is not longer than `subject`. let withinRange := iszero(gt(searchLength, subjectLength)) // Just using keccak256 directly is actually cheaper. // forgefmt: disable-next-item result := and( withinRange, eq( keccak256( // `subject + 0x20 + max(subjectLength - searchLength, 0)`. add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))), searchLength ), keccak256(add(search, 0x20), searchLength) ) ) } } /// @dev Returns `subject` repeated `times`. function repeat(string memory subject, uint256 times) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(or(iszero(times), iszero(subjectLength))) { subject := add(subject, 0x20) result := mload(0x40) let output := add(result, 0x20) for {} 1 {} { // Copy the `subject` one word at a time. for { let o := 0 } 1 {} { mstore(add(output, o), mload(add(subject, o))) o := add(o, 0x20) if iszero(lt(o, subjectLength)) { break } } output := add(output, subjectLength) times := sub(times, 1) if iszero(times) { break } } mstore(output, 0) // Zeroize the slot after the string. let resultLength := sub(output, add(result, 0x20)) mstore(result, resultLength) // Store the length. mstore(0x40, add(result, add(resultLength, 0x40))) // Allocate the memory. } } } /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive). /// `start` and `end` are byte offsets. function slice(string memory subject, uint256 start, uint256 end) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) if iszero(gt(subjectLength, end)) { end := subjectLength } if iszero(gt(subjectLength, start)) { start := subjectLength } if lt(start, end) { result := mload(0x40) let resultLength := sub(end, start) mstore(result, resultLength) subject := add(subject, start) let w := not(0x1f) // Copy the `subject` one word at a time, backwards. for { let o := and(add(resultLength, 0x1f), w) } 1 {} { mstore(add(result, o), mload(add(subject, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(result, 0x20), resultLength), 0) mstore(0x40, add(result, add(resultLength, 0x40))) // Allocate the memory. } } } /// @dev Returns a copy of `subject` sliced from `start` to the end of the string. /// `start` is a byte offset. function slice(string memory subject, uint256 start) internal pure returns (string memory result) { result = slice(subject, start, uint256(int256(-1))); } /// @dev Returns all the indices of `search` in `subject`. /// The indices are byte offsets. function indicesOf(string memory subject, string memory search) internal pure returns (uint256[] memory result) { /// @solidity memory-safe-assembly assembly { let subjectLength := mload(subject) let searchLength := mload(search) if iszero(gt(searchLength, subjectLength)) { subject := add(subject, 0x20) search := add(search, 0x20) result := add(mload(0x40), 0x20) let subjectStart := subject let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1) let h := 0 if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) } let m := shl(3, sub(0x20, and(searchLength, 0x1f))) let s := mload(search) for {} 1 {} { let t := mload(subject) // Whether the first `searchLength % 32` bytes of // `subject` and `search` matches. if iszero(shr(m, xor(t, s))) { if h { if iszero(eq(keccak256(subject, searchLength), h)) { subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } continue } } // Append to `result`. mstore(result, sub(subject, subjectStart)) result := add(result, 0x20) // Advance `subject` by `searchLength`. subject := add(subject, searchLength) if searchLength { if iszero(lt(subject, subjectSearchEnd)) { break } continue } } subject := add(subject, 1) if iszero(lt(subject, subjectSearchEnd)) { break } } let resultEnd := result // Assign `result` to the free memory pointer. result := mload(0x40) // Store the length of `result`. mstore(result, shr(5, sub(resultEnd, add(result, 0x20)))) // Allocate memory for result. // We allocate one more word, so this array can be recycled for {split}. mstore(0x40, add(resultEnd, 0x20)) } } } /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string. function split(string memory subject, string memory delimiter) internal pure returns (string[] memory result) { uint256[] memory indices = indicesOf(subject, delimiter); /// @solidity memory-safe-assembly assembly { let w := not(0x1f) let indexPtr := add(indices, 0x20) let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1))) mstore(add(indicesEnd, w), mload(subject)) mstore(indices, add(mload(indices), 1)) let prevIndex := 0 for {} 1 {} { let index := mload(indexPtr) mstore(indexPtr, 0x60) if iszero(eq(index, prevIndex)) { let element := mload(0x40) let elementLength := sub(index, prevIndex) mstore(element, elementLength) // Copy the `subject` one word at a time, backwards. for { let o := and(add(elementLength, 0x1f), w) } 1 {} { mstore(add(element, o), mload(add(add(subject, prevIndex), o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } // Zeroize the slot after the string. mstore(add(add(element, 0x20), elementLength), 0) // Allocate memory for the length and the bytes, // rounded up to a multiple of 32. mstore(0x40, add(element, and(add(elementLength, 0x3f), w))) // Store the `element` into the array. mstore(indexPtr, element) } prevIndex := add(index, mload(delimiter)) indexPtr := add(indexPtr, 0x20) if iszero(lt(indexPtr, indicesEnd)) { break } } result := indices if iszero(mload(delimiter)) { result := add(indices, 0x20) mstore(result, sub(mload(indices), 2)) } } } /// @dev Returns a concatenated string of `a` and `b`. /// Cheaper than `string.concat()` and does not de-align the free memory pointer. function concat(string memory a, string memory b) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let w := not(0x1f) result := mload(0x40) let aLength := mload(a) // Copy `a` one word at a time, backwards. for { let o := and(add(aLength, 0x20), w) } 1 {} { mstore(add(result, o), mload(add(a, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let bLength := mload(b) let output := add(result, aLength) // Copy `b` one word at a time, backwards. for { let o := and(add(bLength, 0x20), w) } 1 {} { mstore(add(output, o), mload(add(b, o))) o := add(o, w) // `sub(o, 0x20)`. if iszero(o) { break } } let totalLength := add(aLength, bLength) let last := add(add(result, 0x20), totalLength) mstore(last, 0) // Zeroize the slot after the string. mstore(result, totalLength) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Returns a copy of the string in either lowercase or UPPERCASE. /// WARNING! This function is only compatible with 7-bit ASCII strings. function toCase(string memory subject, bool toUpper) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let length := mload(subject) if length { result := add(mload(0x40), 0x20) subject := add(subject, 1) let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff) let w := not(0) for { let o := length } 1 {} { o := add(o, w) let b := and(0xff, mload(add(subject, o))) mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20))) if iszero(o) { break } } result := mload(0x40) mstore(result, length) // Store the length. let last := add(add(result, 0x20), length) mstore(last, 0) // Zeroize the slot after the string. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } } /// @dev Returns a string from a small bytes32 string. /// `s` must be null-terminated, or behavior will be undefined. function fromSmallString(bytes32 s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) let n := 0 for {} byte(n, s) { n := add(n, 1) } {} // Scan for '\0'. mstore(result, n) // Store the length. let o := add(result, 0x20) mstore(o, s) // Store the bytes of the string. mstore(add(o, n), 0) // Zeroize the slot after the string. mstore(0x40, add(result, 0x40)) // Allocate the memory. } } /// @dev Returns the small string, with all bytes after the first null byte zeroized. function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { for {} byte(result, s) { result := add(result, 1) } {} // Scan for '\0'. mstore(0x00, s) mstore(result, 0x00) result := mload(0x00) } } /// @dev Returns the string as a normalized null-terminated small string. function toSmallString(string memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := mload(s) if iszero(lt(result, 33)) { mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`. revert(0x1c, 0x04) } result := shl(shl(3, sub(32, result)), mload(add(s, result))) } } /// @dev Returns a lowercased copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function lower(string memory subject) internal pure returns (string memory result) { result = toCase(subject, false); } /// @dev Returns an UPPERCASED copy of the string. /// WARNING! This function is only compatible with 7-bit ASCII strings. function upper(string memory subject) internal pure returns (string memory result) { result = toCase(subject, true); } /// @dev Escapes the string to be used within HTML tags. function escapeHTML(string memory s) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) // Store the bytes of the packed offsets and strides into the scratch space. // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6. mstore(0x1f, 0x900094) mstore(0x08, 0xc0000000a6ab) // Store ""&'<>" into the scratch space. mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) // Not in `["\"","'","&","<",">"]`. if iszero(and(shl(c, 1), 0x500000c400000000)) { mstore8(result, c) result := add(result, 1) continue } let t := shr(248, mload(c)) mstore(result, mload(and(t, 0x1f))) result := add(result, shr(5, t)) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes. function escapeJSON(string memory s, bool addDoubleQuotes) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { let end := add(s, mload(s)) result := add(mload(0x40), 0x20) if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } // Store "\\u0000" in scratch space. // Store "0123456789abcdef" in scratch space. // Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`. // into the scratch space. mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672) // Bitmask for detecting `["\"","\\"]`. let e := or(shl(0x22, 1), shl(0x5c, 1)) for {} iszero(eq(s, end)) {} { s := add(s, 1) let c := and(mload(s), 0xff) if iszero(lt(c, 0x20)) { if iszero(and(shl(c, 1), e)) { // Not in `["\"","\\"]`. mstore8(result, c) result := add(result, 1) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), c) result := add(result, 2) continue } if iszero(and(shl(c, 1), 0x3700)) { // Not in `["\b","\t","\n","\f","\d"]`. mstore8(0x1d, mload(shr(4, c))) // Hex value. mstore8(0x1e, mload(and(c, 15))) // Hex value. mstore(result, mload(0x19)) // "\\u00XX". result := add(result, 6) continue } mstore8(result, 0x5c) // "\\". mstore8(add(result, 1), mload(add(c, 8))) result := add(result, 2) } if addDoubleQuotes { mstore8(result, 34) result := add(1, result) } let last := result mstore(last, 0) // Zeroize the slot after the string. result := mload(0x40) mstore(result, sub(last, add(result, 0x20))) // Store the length. mstore(0x40, add(last, 0x20)) // Allocate the memory. } } /// @dev Escapes the string to be used within double-quotes in a JSON. function escapeJSON(string memory s) internal pure returns (string memory result) { result = escapeJSON(s, false); } /// @dev Returns whether `a` equals `b`. function eq(string memory a, string memory b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b))) } } /// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small string. function eqs(string memory a, bytes32 b) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { // These should be evaluated on compile time, as far as possible. let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`. let x := not(or(m, or(b, add(m, and(b, m))))) let r := shl(7, iszero(iszero(shr(128, x)))) r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x)))))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // forgefmt: disable-next-item result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))), xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20))))) } } /// @dev Packs a single string with its length into a single word. /// Returns `bytes32(0)` if the length is zero or greater than 31. function packOne(string memory a) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { // We don't need to zero right pad the string, // since this is our own custom non-standard packing scheme. result := mul( // Load the length and the bytes. mload(add(a, 0x1f)), // `length != 0 && length < 32`. Abuses underflow. // Assumes that the length is valid and within the block gas limit. lt(sub(mload(a), 1), 0x1f) ) } } /// @dev Unpacks a string packed using {packOne}. /// Returns the empty string if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packOne}, the output behavior is undefined. function unpackOne(bytes32 packed) internal pure returns (string memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) // Grab the free memory pointer. mstore(0x40, add(result, 0x40)) // Allocate 2 words (1 for the length, 1 for the bytes). mstore(result, 0) // Zeroize the length slot. mstore(add(result, 0x1f), packed) // Store the length and bytes. mstore(add(add(result, 0x20), mload(result)), 0) // Right pad with zeroes. } } /// @dev Packs two strings with their lengths into a single word. /// Returns `bytes32(0)` if combined length is zero or greater than 30. function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let aLength := mload(a) // We don't need to zero right pad the strings, // since this is our own custom non-standard packing scheme. result := mul( or( // Load the length and the bytes of `a` and `b`. shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))), mload(sub(add(b, 0x1e), aLength)) ), // `totalLength != 0 && totalLength < 31`. Abuses underflow. // Assumes that the lengths are valid and within the block gas limit. lt(sub(add(aLength, mload(b)), 1), 0x1e) ) } } /// @dev Unpacks strings packed using {packTwo}. /// Returns the empty strings if `packed` is `bytes32(0)`. /// If `packed` is not an output of {packTwo}, the output behavior is undefined. function unpackTwo(bytes32 packed) internal pure returns (string memory resultA, string memory resultB) { /// @solidity memory-safe-assembly assembly { resultA := mload(0x40) // Grab the free memory pointer. resultB := add(resultA, 0x40) // Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words. mstore(0x40, add(resultB, 0x40)) // Zeroize the length slots. mstore(resultA, 0) mstore(resultB, 0) // Store the lengths and bytes. mstore(add(resultA, 0x1f), packed) mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA)))) // Right pad with zeroes. mstore(add(add(resultA, 0x20), mload(resultA)), 0) mstore(add(add(resultB, 0x20), mload(resultB)), 0) } } /// @dev Directly returns `a` without copying. function directReturn(string memory a) internal pure { assembly { // Assumes that the string does not start from the scratch space. let retStart := sub(a, 0x20) let retUnpaddedSize := add(mload(a), 0x40) // Right pad with zeroes. Just in case the string is produced // by a method that doesn't zero right pad. mstore(add(retStart, retUnpaddedSize), 0) mstore(retStart, 0x20) // Store the return offset. // End the transaction, returning the string. return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize))) } } }
{ "remappings": [ "openzeppelin/=lib/V2-gov/lib/openzeppelin-contracts/", "@chimera/=lib/V2-gov/lib/chimera/src/", "@ensdomains/=lib/V2-gov/lib/v4-core/node_modules/@ensdomains/", "@openzeppelin/=lib/V2-gov/lib/v4-core/lib/openzeppelin-contracts/", "@openzeppelin/contracts/=lib/V2-gov/lib/openzeppelin-contracts/contracts/", "Solady/=lib/Solady/src/", "V2-gov/=lib/V2-gov/", "chimera/=lib/V2-gov/lib/chimera/src/", "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-gas-snapshot/=lib/V2-gov/lib/v4-core/lib/forge-gas-snapshot/src/", "forge-std/=lib/forge-std/src/", "hardhat/=lib/V2-gov/lib/v4-core/node_modules/hardhat/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solmate/=lib/V2-gov/lib/v4-core/lib/solmate/src/", "v4-core/=lib/V2-gov/lib/v4-core/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": false, "libraries": {} }
[{"inputs":[{"internalType":"contract IAddressesRegistry","name":"_addressesRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_borrowerOperationsAddress","type":"address"}],"name":"BorrowerOperationsAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_troveManagerAddress","type":"address"}],"name":"TroveManagerAddressChanged","type":"event"},{"inputs":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BatchId","name":"","type":"address"}],"name":"batches","outputs":[{"internalType":"uint256","name":"head","type":"uint256"},{"internalType":"uint256","name":"tail","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"borrowerOperationsAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"contains","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"findInsertPosition","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFirst","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"getNext","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"getPrev","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"insert","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"BatchId","name":"_batchId","type":"address"},{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"insertIntoBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"isBatchedNode","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isEmpty","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"BatchId","name":"_id","type":"address"}],"name":"isEmptyBatch","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nodes","outputs":[{"internalType":"uint256","name":"nextId","type":"uint256"},{"internalType":"uint256","name":"prevId","type":"uint256"},{"internalType":"BatchId","name":"batchId","type":"address"},{"internalType":"bool","name":"exists","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"uint256","name":"_newAnnualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"reInsert","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"BatchId","name":"_id","type":"address"},{"internalType":"uint256","name":"_newAnnualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"reInsertBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"remove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"}],"name":"removeFromBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"size","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"troveManager","outputs":[{"internalType":"contract ITroveManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"validInsertPosition","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60c060405234801562000010575f80fd5b5060405162001a6838038062001a6883398101604081905262000033916200020d565b5f808052600160209081527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb498290557fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb4a9190915560408051631ec1c84560e11b815290516001600160a01b03841692633d83908a92600480820193918290030181865afa158015620000c7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620000ed91906200020d565b6001600160a01b031660a0816001600160a01b031681525050806001600160a01b03166377553ad46040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000143573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200016991906200020d565b6001600160a01b0390811660805260a051604051911681527f143219c9e69b09e07e095fcc889b43d8f46ca892bba65f08dc3a0050869a56789060200160405180910390a16080516040516001600160a01b0390911681527f3ca631ffcd2a9b5d9ae18543fc82f58eb4ca33af9e6ab01b7a8e95331e6ed9859060200160405180910390a15062000232565b6001600160a01b03811681146200020a575f80fd5b50565b5f602082840312156200021e575f80fd5b81516200022b81620001f5565b9392505050565b60805160a0516117d5620002935f395f81816102cf0152818161050001528181610566015281816106bf0152818161089e0152818161096801528181610a680152610fde01525f81816103e601528181610c920152610fac01526117d55ff3fe608060405234801561000f575f80fd5b5060043610610148575f3560e01c80634d622831116100bf578063a3f4df7e11610079578063a3f4df7e146103a9578063b7f8cf9b146103e1578063c34052e014610408578063de8fa4311461041b578063e2ea265814610422578063f476125914610448575f80fd5b80634d6228311461031c57806362c4c5161461034b578063681fe70c14610373578063843aa0db1461037b57806394586b4e1461038e578063949d225d146103a1575f80fd5b80631e223143116101105780631e223143146102625780632dbf554c14610291578063353d67a0146102a457806336aa4c6a146102b75780633d83908a146102ca5780634cc8221514610309575f80fd5b80630364aefb1461014c57806307aba33d1461018a5780631037a5f4146101b75780631c403f59146101da5780631c53c280146101ef575b5f80fd5b61017561015a366004611565565b6001600160a01b03165f908152600260205260409020541590565b60405190151581526020015b60405180910390f35b6101a961019836600461157e565b5f9081526001602052604090205490565b604051908152602001610181565b6101a96101c536600461157e565b5f908152600160208190526040909120015490565b6101ed6101e8366004611595565b61045b565b005b6102316101fd36600461157e565b600160208190525f91825260409091208054918101546002909101546001600160a01b03811690600160a01b900460ff1684565b604051610181949392919093845260208401929092526001600160a01b031660408301521515606082015260800190565b5f805260016020527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49546101a9565b61017561029f36600461157e565b610537565b6101756102b23660046115cb565b610560565b6101ed6102c53660046115f4565b610597565b6102f17f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610181565b6101ed61031736600461157e565b610792565b5f805260016020527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb4a546101a9565b61035e6103593660046115cb565b610897565b60408051928352602083019190915201610181565b5f5415610175565b6101ed610389366004611636565b6108d1565b6101ed61039c366004611636565b6109c9565b6101a95f5481565b6103d46040518060400160405280600c81526020016b536f7274656454726f76657360a01b81525081565b6040516101819190611665565b6102f17f000000000000000000000000000000000000000000000000000000000000000081565b61017561041636600461157e565b610a97565b5f546101a9565b61035e610430366004611565565b60026020525f90815260409020805460019091015482565b6101ed61045636600461157e565b610ab5565b6001600160a01b0384165f908152600260209081526040918290208251808401909352805483526001015490820152610492610c87565b80516104fb5760405162461bcd60e51b815260206004820152602d60248201527f536f7274656454726f7665733a204c69737420646f6573206e6f7420636f6e7460448201526c0c2d2dc40e8d0ca40c4c2e8c6d609b1b60648201526084015b60405180910390fd5b6105307f0000000000000000000000000000000000000000000000000000000000000000825f01518360200151878787610d18565b5050505050565b5f8181526001602052604081206002015461055a906001600160a01b0316610db5565b92915050565b5f61058d7f0000000000000000000000000000000000000000000000000000000000000000858585610dcf565b90505b9392505050565b61059f610c87565b6105a885610a97565b156105c55760405162461bcd60e51b81526004016104f2906116b1565b8461062e5760405162461bcd60e51b815260206004820152603360248201527f536f7274656454726f7665733a205f74726f766549642063616e6e6f74206265604482015272081d1a19481c9bdbdd081b9bd91949dcc81251606a1b60648201526084016104f2565b610640846001600160a01b0316610db5565b61069a5760405162461bcd60e51b815260206004820152602560248201527f536f7274656454726f7665733a205f626174636849642063616e6e6f74206265604482015264207a65726f60d81b60648201526084016104f2565b6001600160a01b0384165f9081526002602052604090206001015480610707576106e87f00000000000000000000000000000000000000000000000000000000000000008788878787610f4a565b6001600160a01b0385165f908152600260205260409020869055610736565b5f8181526001602081905260408083208054908a90558984528184208084018690558190558352909120018690555b6001600160a01b0385165f81815260026020818152604080842060019081018c90558b855290915282200180546001600160a81b031916909217600160a01b179091558054819061078690611711565b90915550505050505050565b61079a610fa1565b6107a381610a97565b6107bf5760405162461bcd60e51b81526004016104f290611729565b6107c881610537565b1561083b5760405162461bcd60e51b815260206004820152603f60248201527f536f7274656454726f7665733a204d757374207573652072656d6f766546726f60448201527f6d4261746368282920746f2072656d6f76652062617463686564206e6f64650060648201526084016104f2565b5f81815260016020819052604080832080548184018054865283862082905580549186529285209093019290925583835282825582905560020180546001600160a81b03191690558054819061089090611773565b9091555050565b5f806108c57f0000000000000000000000000000000000000000000000000000000000000000868686611072565b91509150935093915050565b6108d9610c87565b6108e284610a97565b156108ff5760405162461bcd60e51b81526004016104f2906116b1565b836109635760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a205f69642063616e6e6f74206265207468652060448201526d1c9bdbdd081b9bd91949dcc8125160921b60648201526084016104f2565b6109917f00000000000000000000000000000000000000000000000000000000000000008586868686610f4a565b5f848152600160205260408120600201805460ff60a01b1916600160a01b179055805481906109bf90611711565b9091555050505050565b6109d1610c87565b6109da84610a97565b6109f65760405162461bcd60e51b81526004016104f290611729565b6109ff84610537565b15610a635760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a204d757374206e6f74207265496e736572742860448201526d292062617463686564206e6f646560901b60648201526084016104f2565b610a917f00000000000000000000000000000000000000000000000000000000000000008586868686610d18565b50505050565b5f90815260016020526040902060020154600160a01b900460ff1690565b610abd610fa1565b5f818152600160205260409020600201546001600160a01b0316610ae081610db5565b610b525760405162461bcd60e51b815260206004820152603a60248201527f536f7274656454726f7665733a204d757374207573652072656d6f766528292060448201527f746f2072656d6f7665206e6f6e2d62617463686564206e6f646500000000000060648201526084016104f2565b6001600160a01b0381165f90815260026020908152604091829020825180840190935280548084526001909101549183019190915283148015610b985750828160200151145b15610bc0576001600160a01b0382165f90815260026020526040812081815560010155610c29565b8051839003610bf4575f838152600160209081526040808320546001600160a01b0386168452600290925290912055610c29565b82816020015103610c29575f8381526001602081815260408084208301546001600160a01b0387168552600290925290922001555b5f83815260016020819052604080832080548184018054865283862082905580549186529285209093019290925585835282825582905560020180546001600160a81b031916905580548190610c7e90611773565b90915550505050565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610d165760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f7420426f727260448201526d6f7765724f7065726174696f6e7360901b60648201526084016104f2565b565b610d2486848484610dcf565b610d3a57610d3486848484611072565b90925090505b848114158015610d4a5750838214155b15610dad575f8481526001602081905260408083205488845281842083018054855282852082905554908452922001555b5f8281526001602081905260408083208890558783528083208201859055868352808320849055838352909120018490555b505050505050565b5f610dc8826001600160a01b0316611216565b1592915050565b5f828152600160205260408120600281015490546001600160a01b039091169083148015610e0d57505f838152600160208190526040909120015484145b8015610e4c57505f838152600160205260409020600201546001600160a01b038083169116141580610e4c5750610e4c816001600160a01b0316611216565b8015610ec75750831580610ec75750604051635ef3b8bf60e01b81526004810185905285906001600160a01b03881690635ef3b8bf90602401602060405180830381865afa158015610ea0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ec49190611788565b10155b8015610f405750821580610f405750604051635ef3b8bf60e01b8152600481018490526001600160a01b03871690635ef3b8bf90602401602060405180830381865afa158015610f19573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f3d9190611788565b85115b9695505050505050565b610f5686848484610dcf565b610d7b57610f6686848484611072565b5f8281526001602081905260408083208a90558983528083208201859055888352808320849055838352909120018690559092509050610dad565b336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614806110005750336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016145b610d165760405162461bcd60e51b815260206004820152603f60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f7420426f727260448201527f6f7765724f7065726174696f6e73206e6f722054726f76654d616e616765720060648201526084016104f2565b5f808361108d5761108486865f611227565b9150915061120d565b61109684610a97565b15806111085750604051635ef3b8bf60e01b81526004810185905285906001600160a01b03881690635ef3b8bf90602401602060405180830381865afa1580156110e2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111069190611788565b105b15611111575f93505b826111215761108486865f611270565b61112a83610a97565b158061119c5750604051635ef3b8bf60e01b8152600481018490526001600160a01b03871690635ef3b8bf90602401602060405180830381865afa158015611174573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111989190611788565b8511155b156111a5575f92505b831580156111b1575082155b156111c15761108486865f611227565b836111d95761108486866111d4866112b8565b611270565b826111f15761108486866111ec87611302565b611227565b61108486866111ff87611302565b611208876112b8565b61134f565b94509492505050565b5f6001600160a01b0382161561055a565b6040805180820182528281525f83815260016020908152928120549282019290925281905b6112578686836113da565b1561124c57805160209091015190969095509350505050565b6040805180820182525f838152600160208181529382200154825291810183905281905b61129f868683611491565b1561129457805160209091015190969095509350505050565b5f818152600160205260408120600201546001600160a01b03166112db81610db5565b6112e55782610590565b6001600160a01b03165f9081526002602052604090205492915050565b5f818152600160205260408120600201546001600160a01b031661132581610db5565b61132f5782610590565b6001600160a01b03165f9081526002602052604090206001015492915050565b6040805180820182528381525f848152600160208181528483205481850152845180860186528684528282529483209091015484528301849052918291905b6113998888846113da565b156113b157508051602090910151909250905061120d565b6113bc888883611491565b156113d557805f0151816020015193509350505061120d565b61138e565b5f808260200151148061145857506020820151604051635ef3b8bf60e01b815260048101919091526001600160a01b03851690635ef3b8bf90602401602060405180830381865afa158015611431573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114559190611788565b83115b1561146557506001610590565b6114728260200151611302565b8083525f90815260016020908152604090912054908301529392505050565b80515f90158061151057508151604051635ef3b8bf60e01b815284916001600160a01b03871691635ef3b8bf916114ce9160040190815260200190565b602060405180830381865afa1580156114e9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061150d9190611788565b10155b1561151d57506001610590565b8151611528906112b8565b60208084018290525f9182526001908190526040909120015482529392505050565b80356001600160a01b0381168114611560575f80fd5b919050565b5f60208284031215611575575f80fd5b6105908261154a565b5f6020828403121561158e575f80fd5b5035919050565b5f805f80608085870312156115a8575f80fd5b6115b18561154a565b966020860135965060408601359560600135945092505050565b5f805f606084860312156115dd575f80fd5b505081359360208301359350604090920135919050565b5f805f805f60a08688031215611608575f80fd5b853594506116186020870161154a565b94979496505050506040830135926060810135926080909101359150565b5f805f8060808587031215611649575f80fd5b5050823594602084013594506040840135936060013592509050565b5f602080835283518060208501525f5b8181101561169157858101830151858201604001528201611675565b505f604082860101526040601f19601f8301168501019250505092915050565b6020808252602c908201527f536f7274656454726f7665733a204c69737420616c726561647920636f6e746160408201526b696e7320746865206e6f646560a01b606082015260800190565b634e487b7160e01b5f52601160045260245ffd5b5f60018201611722576117226116fd565b5060010190565b6020808252602a908201527f536f7274656454726f7665733a204c69737420646f6573206e6f7420636f6e74604082015269185a5b881d1a19481a5960b21b606082015260800190565b5f81611781576117816116fd565b505f190190565b5f60208284031215611798575f80fd5b505191905056fea26469706673582212206b672f4c9039360430583dbef70fd6a10776845a18ff9c023785b1245ca63cca64736f6c63430008180033000000000000000000000000062a494967b691682b18f42854c990f97fe789a8
Deployed Bytecode
0x608060405234801561000f575f80fd5b5060043610610148575f3560e01c80634d622831116100bf578063a3f4df7e11610079578063a3f4df7e146103a9578063b7f8cf9b146103e1578063c34052e014610408578063de8fa4311461041b578063e2ea265814610422578063f476125914610448575f80fd5b80634d6228311461031c57806362c4c5161461034b578063681fe70c14610373578063843aa0db1461037b57806394586b4e1461038e578063949d225d146103a1575f80fd5b80631e223143116101105780631e223143146102625780632dbf554c14610291578063353d67a0146102a457806336aa4c6a146102b75780633d83908a146102ca5780634cc8221514610309575f80fd5b80630364aefb1461014c57806307aba33d1461018a5780631037a5f4146101b75780631c403f59146101da5780631c53c280146101ef575b5f80fd5b61017561015a366004611565565b6001600160a01b03165f908152600260205260409020541590565b60405190151581526020015b60405180910390f35b6101a961019836600461157e565b5f9081526001602052604090205490565b604051908152602001610181565b6101a96101c536600461157e565b5f908152600160208190526040909120015490565b6101ed6101e8366004611595565b61045b565b005b6102316101fd36600461157e565b600160208190525f91825260409091208054918101546002909101546001600160a01b03811690600160a01b900460ff1684565b604051610181949392919093845260208401929092526001600160a01b031660408301521515606082015260800190565b5f805260016020527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49546101a9565b61017561029f36600461157e565b610537565b6101756102b23660046115cb565b610560565b6101ed6102c53660046115f4565b610597565b6102f17f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f481565b6040516001600160a01b039091168152602001610181565b6101ed61031736600461157e565b610792565b5f805260016020527fa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb4a546101a9565b61035e6103593660046115cb565b610897565b60408051928352602083019190915201610181565b5f5415610175565b6101ed610389366004611636565b6108d1565b6101ed61039c366004611636565b6109c9565b6101a95f5481565b6103d46040518060400160405280600c81526020016b536f7274656454726f76657360a01b81525081565b6040516101819190611665565b6102f17f000000000000000000000000cd251e282c0ee7c8e3e687303f14c0facf8487c781565b61017561041636600461157e565b610a97565b5f546101a9565b61035e610430366004611565565b60026020525f90815260409020805460019091015482565b6101ed61045636600461157e565b610ab5565b6001600160a01b0384165f908152600260209081526040918290208251808401909352805483526001015490820152610492610c87565b80516104fb5760405162461bcd60e51b815260206004820152602d60248201527f536f7274656454726f7665733a204c69737420646f6573206e6f7420636f6e7460448201526c0c2d2dc40e8d0ca40c4c2e8c6d609b1b60648201526084015b60405180910390fd5b6105307f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f4825f01518360200151878787610d18565b5050505050565b5f8181526001602052604081206002015461055a906001600160a01b0316610db5565b92915050565b5f61058d7f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f4858585610dcf565b90505b9392505050565b61059f610c87565b6105a885610a97565b156105c55760405162461bcd60e51b81526004016104f2906116b1565b8461062e5760405162461bcd60e51b815260206004820152603360248201527f536f7274656454726f7665733a205f74726f766549642063616e6e6f74206265604482015272081d1a19481c9bdbdd081b9bd91949dcc81251606a1b60648201526084016104f2565b610640846001600160a01b0316610db5565b61069a5760405162461bcd60e51b815260206004820152602560248201527f536f7274656454726f7665733a205f626174636849642063616e6e6f74206265604482015264207a65726f60d81b60648201526084016104f2565b6001600160a01b0384165f9081526002602052604090206001015480610707576106e87f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f48788878787610f4a565b6001600160a01b0385165f908152600260205260409020869055610736565b5f8181526001602081905260408083208054908a90558984528184208084018690558190558352909120018690555b6001600160a01b0385165f81815260026020818152604080842060019081018c90558b855290915282200180546001600160a81b031916909217600160a01b179091558054819061078690611711565b90915550505050505050565b61079a610fa1565b6107a381610a97565b6107bf5760405162461bcd60e51b81526004016104f290611729565b6107c881610537565b1561083b5760405162461bcd60e51b815260206004820152603f60248201527f536f7274656454726f7665733a204d757374207573652072656d6f766546726f60448201527f6d4261746368282920746f2072656d6f76652062617463686564206e6f64650060648201526084016104f2565b5f81815260016020819052604080832080548184018054865283862082905580549186529285209093019290925583835282825582905560020180546001600160a81b03191690558054819061089090611773565b9091555050565b5f806108c57f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f4868686611072565b91509150935093915050565b6108d9610c87565b6108e284610a97565b156108ff5760405162461bcd60e51b81526004016104f2906116b1565b836109635760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a205f69642063616e6e6f74206265207468652060448201526d1c9bdbdd081b9bd91949dcc8125160921b60648201526084016104f2565b6109917f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f48586868686610f4a565b5f848152600160205260408120600201805460ff60a01b1916600160a01b179055805481906109bf90611711565b9091555050505050565b6109d1610c87565b6109da84610a97565b6109f65760405162461bcd60e51b81526004016104f290611729565b6109ff84610537565b15610a635760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a204d757374206e6f74207265496e736572742860448201526d292062617463686564206e6f646560901b60648201526084016104f2565b610a917f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f48586868686610d18565b50505050565b5f90815260016020526040902060020154600160a01b900460ff1690565b610abd610fa1565b5f818152600160205260409020600201546001600160a01b0316610ae081610db5565b610b525760405162461bcd60e51b815260206004820152603a60248201527f536f7274656454726f7665733a204d757374207573652072656d6f766528292060448201527f746f2072656d6f7665206e6f6e2d62617463686564206e6f646500000000000060648201526084016104f2565b6001600160a01b0381165f90815260026020908152604091829020825180840190935280548084526001909101549183019190915283148015610b985750828160200151145b15610bc0576001600160a01b0382165f90815260026020526040812081815560010155610c29565b8051839003610bf4575f838152600160209081526040808320546001600160a01b0386168452600290925290912055610c29565b82816020015103610c29575f8381526001602081815260408084208301546001600160a01b0387168552600290925290922001555b5f83815260016020819052604080832080548184018054865283862082905580549186529285209093019290925585835282825582905560020180546001600160a81b031916905580548190610c7e90611773565b90915550505050565b336001600160a01b037f000000000000000000000000cd251e282c0ee7c8e3e687303f14c0facf8487c71614610d165760405162461bcd60e51b815260206004820152602e60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f7420426f727260448201526d6f7765724f7065726174696f6e7360901b60648201526084016104f2565b565b610d2486848484610dcf565b610d3a57610d3486848484611072565b90925090505b848114158015610d4a5750838214155b15610dad575f8481526001602081905260408083205488845281842083018054855282852082905554908452922001555b5f8281526001602081905260408083208890558783528083208201859055868352808320849055838352909120018490555b505050505050565b5f610dc8826001600160a01b0316611216565b1592915050565b5f828152600160205260408120600281015490546001600160a01b039091169083148015610e0d57505f838152600160208190526040909120015484145b8015610e4c57505f838152600160205260409020600201546001600160a01b038083169116141580610e4c5750610e4c816001600160a01b0316611216565b8015610ec75750831580610ec75750604051635ef3b8bf60e01b81526004810185905285906001600160a01b03881690635ef3b8bf90602401602060405180830381865afa158015610ea0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ec49190611788565b10155b8015610f405750821580610f405750604051635ef3b8bf60e01b8152600481018490526001600160a01b03871690635ef3b8bf90602401602060405180830381865afa158015610f19573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f3d9190611788565b85115b9695505050505050565b610f5686848484610dcf565b610d7b57610f6686848484611072565b5f8281526001602081905260408083208a90558983528083208201859055888352808320849055838352909120018690559092509050610dad565b336001600160a01b037f000000000000000000000000cd251e282c0ee7c8e3e687303f14c0facf8487c71614806110005750336001600160a01b037f000000000000000000000000a8a2446696d9f3f49c39f020a5d6d34cbf3d81f416145b610d165760405162461bcd60e51b815260206004820152603f60248201527f536f7274656454726f7665733a2043616c6c6572206973206e6f7420426f727260448201527f6f7765724f7065726174696f6e73206e6f722054726f76654d616e616765720060648201526084016104f2565b5f808361108d5761108486865f611227565b9150915061120d565b61109684610a97565b15806111085750604051635ef3b8bf60e01b81526004810185905285906001600160a01b03881690635ef3b8bf90602401602060405180830381865afa1580156110e2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111069190611788565b105b15611111575f93505b826111215761108486865f611270565b61112a83610a97565b158061119c5750604051635ef3b8bf60e01b8152600481018490526001600160a01b03871690635ef3b8bf90602401602060405180830381865afa158015611174573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111989190611788565b8511155b156111a5575f92505b831580156111b1575082155b156111c15761108486865f611227565b836111d95761108486866111d4866112b8565b611270565b826111f15761108486866111ec87611302565b611227565b61108486866111ff87611302565b611208876112b8565b61134f565b94509492505050565b5f6001600160a01b0382161561055a565b6040805180820182528281525f83815260016020908152928120549282019290925281905b6112578686836113da565b1561124c57805160209091015190969095509350505050565b6040805180820182525f838152600160208181529382200154825291810183905281905b61129f868683611491565b1561129457805160209091015190969095509350505050565b5f818152600160205260408120600201546001600160a01b03166112db81610db5565b6112e55782610590565b6001600160a01b03165f9081526002602052604090205492915050565b5f818152600160205260408120600201546001600160a01b031661132581610db5565b61132f5782610590565b6001600160a01b03165f9081526002602052604090206001015492915050565b6040805180820182528381525f848152600160208181528483205481850152845180860186528684528282529483209091015484528301849052918291905b6113998888846113da565b156113b157508051602090910151909250905061120d565b6113bc888883611491565b156113d557805f0151816020015193509350505061120d565b61138e565b5f808260200151148061145857506020820151604051635ef3b8bf60e01b815260048101919091526001600160a01b03851690635ef3b8bf90602401602060405180830381865afa158015611431573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114559190611788565b83115b1561146557506001610590565b6114728260200151611302565b8083525f90815260016020908152604090912054908301529392505050565b80515f90158061151057508151604051635ef3b8bf60e01b815284916001600160a01b03871691635ef3b8bf916114ce9160040190815260200190565b602060405180830381865afa1580156114e9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061150d9190611788565b10155b1561151d57506001610590565b8151611528906112b8565b60208084018290525f9182526001908190526040909120015482529392505050565b80356001600160a01b0381168114611560575f80fd5b919050565b5f60208284031215611575575f80fd5b6105908261154a565b5f6020828403121561158e575f80fd5b5035919050565b5f805f80608085870312156115a8575f80fd5b6115b18561154a565b966020860135965060408601359560600135945092505050565b5f805f606084860312156115dd575f80fd5b505081359360208301359350604090920135919050565b5f805f805f60a08688031215611608575f80fd5b853594506116186020870161154a565b94979496505050506040830135926060810135926080909101359150565b5f805f8060808587031215611649575f80fd5b5050823594602084013594506040840135936060013592509050565b5f602080835283518060208501525f5b8181101561169157858101830151858201604001528201611675565b505f604082860101526040601f19601f8301168501019250505092915050565b6020808252602c908201527f536f7274656454726f7665733a204c69737420616c726561647920636f6e746160408201526b696e7320746865206e6f646560a01b606082015260800190565b634e487b7160e01b5f52601160045260245ffd5b5f60018201611722576117226116fd565b5060010190565b6020808252602a908201527f536f7274656454726f7665733a204c69737420646f6573206e6f7420636f6e74604082015269185a5b881d1a19481a5960b21b606082015260800190565b5f81611781576117816116fd565b505f190190565b5f60208284031215611798575f80fd5b505191905056fea26469706673582212206b672f4c9039360430583dbef70fd6a10776845a18ff9c023785b1245ca63cca64736f6c63430008180033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000062a494967b691682b18f42854c990f97fe789a8
-----Decoded View---------------
Arg [0] : _addressesRegistry (address): 0x062a494967B691682B18F42854C990f97fE789a8
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000062a494967b691682b18f42854c990f97fe789a8
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.