Skip to main content

CapitalLedger

CapitalLedger​

Deployment on Ethereum mainnet:

https://etherscan.io/address/0x94e0bC3aedA93434B848C49752cfC58B1e7c5029

Track Capital held by owners and ensure the Capital has been accounted for.

ZeroDeposit​

error ZeroDeposit()

Thrown when attempting to deposit nothing

InvalidWithdrawAmount​

error InvalidWithdrawAmount(uint256 requested, uint256 max)

Thrown when withdrawing an invalid amount for a position

InvalidOwnerIndex​

error InvalidOwnerIndex()

Thrown when depositing from address(0)

IndexGreaterThanTokenSupply​

error IndexGreaterThanTokenSupply()

Thrown when querying token supply with an index greater than the supply

Position​

struct Position {
address owner;
uint256 ownedIndex;
address assetAddress;
uint256 usdcEquivalent;
uint256 depositTimestamp;
}

ERC721Data​

struct ERC721Data {
uint256 assetTokenId;
}

positions​

mapping(uint256 => struct CapitalLedger.Position) positions

Data for positions in the vault. Always has a corresponding entry at the same index in ERC20Data or ERC721 data, but never both.

owners​

mapping(address => uint256[]) owners

totals​

mapping(address => struct UserEpochTotal) totals

Total held by each user, while being aware of the deposit epoch

positionCounter​

uint256 positionCounter

erc721Datas​

mapping(uint256 => struct CapitalLedger.ERC721Data) erc721Datas

ERC721 data corresponding to positions, data has the same index as its corresponding position.

constructor​

constructor(contract Context _context) public

Construct the contract

depositERC721​

function depositERC721(address owner, address assetAddress, uint256 assetTokenId) external returns (uint256)

Account for a deposit of id for the ERC721 asset at assetAddress.

reverts with InvalidAssetType if assetAddress is not an ERC721

Parameters​

NameTypeDescription
owneraddressaddress that owns the position
assetAddressaddressaddress of the ERC20 address
assetTokenIduint256id of the ERC721 asset to add

Return Values​

NameTypeDescription
[0]uint256id of the newly created position

erc721IdOf​

function erc721IdOf(uint256 positionId) public view returns (uint256)

Get the id of the ERC721 asset held by position id. Pair this with assetAddressOf to get the address & id of the nft.

reverts with InvalidAssetType if assetAddress is not an ERC721

Parameters​

NameTypeDescription
positionIduint256id of the position

Return Values​

NameTypeDescription
[0]uint256id of the underlying ERC721 asset

withdraw​

function withdraw(uint256 positionId) external

Completely withdraw a position

Parameters​

NameTypeDescription
positionIduint256id of the position

harvest​

function harvest(uint256 positionId) external

Harvests the associated rewards, interest, and other accrued assets associated with the asset token. For example, if given a PoolToken asset, this will collect the GFI rewards (if available), redeemable interest, and redeemable principal, and send that to the owner.

Parameters​

NameTypeDescription
positionIduint256id of the position

assetAddressOf​

function assetAddressOf(uint256 positionId) public view returns (address)

Get the asset address of the position. Example: For an ERC721 position, this returns the address of that ERC721 contract.

Parameters​

NameTypeDescription
positionIduint256id of the position

Return Values​

NameTypeDescription
[0]addressasset address of the position

ownerOf​

function ownerOf(uint256 positionId) public view returns (address)

Get the owner of a given position.

Parameters​

NameTypeDescription
positionIduint256id of the position

Return Values​

NameTypeDescription
[0]addressowner of the position

totalsOf​

function totalsOf(address addr) external view returns (uint256 eligibleAmount, uint256 totalAmount)

Get the USDC value of owners positions, reporting what is currently eligible and the total amount.

this is used by Membership to determine how much is eligible in the current epoch vs the next epoch.

Parameters​

NameTypeDescription
addraddress

Return Values​

NameTypeDescription
eligibleAmountuint256USDC value of positions eligible for rewards
totalAmountuint256total USDC value of positions

totalSupply​

function totalSupply() public view returns (uint256)

Total number of positions in the ledger

Return Values​

NameTypeDescription
[0]uint256number of positions in the ledger

balanceOf​

function balanceOf(address addr) external view returns (uint256)

Get the number of capital positions held by an address

Parameters​

NameTypeDescription
addraddressaddress

Return Values​

NameTypeDescription
[0]uint256positions held by address

tokenOfOwnerByIndex​

function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256)

Returns a position ID owned by owner at a given index of its position list

use with {balanceOf} to enumerate all of owner's positions

Parameters​

NameTypeDescription
owneraddressowner of the positions
indexuint256index of the owner's balance to get the position ID of

Return Values​

NameTypeDescription
[0]uint256position id

tokenByIndex​

function tokenByIndex(uint256 index) external view returns (uint256)

Returns a position ID at a given index of all the positions stored by the contract. use with {totalSupply} to enumerate all positions

Parameters​

NameTypeDescription
indexuint256index to get the position ID at

Return Values​

NameTypeDescription
[0]uint256position id

onERC721Received​

function onERC721Received(address, address, uint256, bytes) external pure returns (bytes4)

_Whenever an {IERC721} tokenId token is transferred to this contract via {IERC721-safeTransferFrom} by operator from from, this function is called.

It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.

The selector can be obtained in Solidity with IERC721.onERC721Received.selector._

_mintPosition​

function _mintPosition(address owner, address assetAddress, uint256 usdcEquivalent) private returns (uint256 positionId)

_kick​

function _kick(uint256 positionId) internal

Update the USDC equivalent value of the position, based on the current, point-in-time valuation of the underlying asset.

Parameters​

NameTypeDescription
positionIduint256id of the position