SarStorage
Diamond storage library for Stock Appreciation Rights functionality
Uses deterministic storage slots to avoid storage collisions with IssuedAsset
State Variables
SAR_STORAGE_POSITION
bytes32 constant SAR_STORAGE_POSITION = keccak256("capsign.storage.sar");
Functions
layout
Get the SAR storage layout
function layout() internal pure returns (Layout storage l);
Returns
l
Layout
The storage layout struct
initializeSarStorage
Initialize the SAR storage with default values
function initializeSarStorage() internal;
createSARTokenInternal
Create a new SAR token
function createSARTokenInternal(bytes32 tokenId, address holder, uint96 quantity, uint96 basePrice) internal;
Parameters
tokenId
bytes32
The unique token ID
holder
address
The holder address
quantity
uint96
The number of SAR units
basePrice
uint96
The base price for appreciation calculation
invalidateSARTokenInternal
Invalidate a SAR token
function invalidateSARTokenInternal(bytes32 tokenId) internal;
Parameters
tokenId
bytes32
The token ID to invalidate
getSARTokenInternal
Get SAR token information
function getSARTokenInternal(bytes32 tokenId) internal view returns (SARToken memory);
Parameters
tokenId
bytes32
The token ID
Returns
<none>
SARToken
The SAR token struct
isSARTokenValidInternal
Check if a SAR token is valid
function isSARTokenValidInternal(bytes32 tokenId) internal view returns (bool);
Parameters
tokenId
bytes32
The token ID
Returns
<none>
bool
True if valid
getHolderSARsInternal
Get all SAR tokens for a holder
function getHolderSARsInternal(address holder) internal view returns (bytes32[] memory);
Parameters
holder
address
The holder address
Returns
<none>
bytes32[]
Array of token IDs
getHolderSARCountInternal
Get the number of SAR tokens for a holder
function getHolderSARCountInternal(address holder) internal view returns (uint256);
Parameters
holder
address
The holder address
Returns
<none>
uint256
The count of SAR tokens
calculateAppreciationInternal
Calculate appreciation for a SAR token
function calculateAppreciationInternal(bytes32 tokenId, uint96 currentPrice) internal view returns (uint256);
Parameters
tokenId
bytes32
The token ID
currentPrice
uint96
The current price
Returns
<none>
uint256
The appreciation amount (quantity * (currentPrice - basePrice))
generateSARTokenIdInternal
Generate a SAR token ID
function generateSARTokenIdInternal(address holder, uint96 quantity, uint96 basePrice)
internal
view
returns (bytes32);
Parameters
holder
address
The holder address
quantity
uint96
The quantity
basePrice
uint96
The base price
Returns
<none>
bytes32
The generated token ID
isSarInitialized
Check if SAR is initialized
function isSarInitialized() internal view returns (bool);
Returns
<none>
bool
True if initialized
updateSARTokenHolderInternal
Update SAR token holder (for transfers)
function updateSARTokenHolderInternal(bytes32 tokenId, address newHolder) internal;
Parameters
tokenId
bytes32
The token ID
newHolder
address
The new holder address
getHolderTotalQuantityInternal
Get total quantity of SARs for a holder
function getHolderTotalQuantityInternal(address holder) internal view returns (uint256);
Parameters
holder
address
The holder address
Returns
<none>
uint256
The total quantity
getHolderTotalAppreciationInternal
Get total appreciation for a holder at current price
function getHolderTotalAppreciationInternal(address holder, uint96 currentPrice) internal view returns (uint256);
Parameters
holder
address
The holder address
currentPrice
uint96
The current price
Returns
<none>
uint256
The total appreciation
Structs
SARToken
struct SARToken {
bool isValid;
address holder;
uint96 quantity;
uint96 basePrice;
}
Layout
struct Layout {
mapping(bytes32 => SARToken) sarTokens;
mapping(address => bytes32[]) holderSARs;
bool sarInitialized;
}
Last updated
Was this helpful?