Skip to content

Solidity API

ITradeableShares

Tradeable shares is a non-transferable, but buyable/sellable fungible token-like asset, which is sold/bought solely by the shares contract at the predefined by the bonding curve function price

The shares is bound to its "subject" – an NFT; the NFT owner gets the subject fee emerging in every buy/sell operation

SharesSubject

Shares subject is an NFT defined by its ERC-721 contract address and NFT ID Shares subject is an NFT the liquidity is embedded to

solidity
struct SharesSubject {
  address tokenAddress;
  uint256 tokenId;
}

Trade

solidity
event Trade(address beneficiary, address issuer, bool isBuy, uint256 sharesAmount, uint256 paidAmount, uint256 feeAmount, uint256 supply)

_Fired in buyShares and sellShares functions, this event logs the entire trading activity happening on the curve

Trader, that is the buyer or seller, depending on the operation type is the transaction sender_

Parameters

NameTypeDescription
beneficiaryaddressthe address which receives shares or funds, usually this is the trader itself
issueraddresssubject issuer, usually an owner of the NFT defined by the subject
isBuybooltrue if the event comes from the buyShares and represents the buy operation, false if the event comes from the sellShares and represents the sell operation
sharesAmountuint256amount of the shares bought or sold (see isBuy)
paidAmountuint256amount of ETH spent or gained by the buyer or seller; this is implementation dependent and can represent an amount of ERC-20 payment token
feeAmountuint256amount of all the fees paid, if any
supplyuint256total shares supply after the operation

getSharesSubject

solidity
function getSharesSubject() external view returns (struct ITradeableShares.SharesSubject)

Shares subject, usually defined as NFT (ERC-721 contract address + NFT ID)

Immutable, client applications may cache this value

Return Values

NameTypeDescription
[0]struct ITradeableShares.SharesSubjectShares subject as a SharesSubject struct, this is an NFT if all currently known implementations

getFeePercent

solidity
function getFeePercent() external view returns (uint256)

Cumulative fee percent, applied to all the buy and sell operations; the fee percent is defined with the 18 decimals, 10^18 corresponds to 100%

The fee can be combined from multiple fees which are sent to the various destinations

Immutable, client applications may cache this value

Return Values

NameTypeDescription
[0]uint256protocol fee percent with the 18 decimals (10^18 is 100%)

getSharesIssuer

solidity
function getSharesIssuer() external view returns (address nftOwner)

Shares issuer, the receiver of the shares fees

Mutable, changes (potentially frequently and unpredictably) when the NFT owner changes; subject to the front-run attacks, off-chain client applications must not rely on this address in anyway

Return Values

NameTypeDescription
nftOwneraddresssubject issuer, the owner of the NFT

getSharesBalance

solidity
function getSharesBalance(address holder) external view returns (uint256 balance)

Shares balance of the given holder; this function is similar to ERC20.balanceOf()

Parameters

NameTypeDescription
holderaddressthe address to check the balance for

Return Values

NameTypeDescription
balanceuint256number of shares the holder has

getSharesSupply

solidity
function getSharesSupply() external view returns (uint256 supply)

Total amount of the shares in existence, the sum of all individual shares balances; this function is similar to ERC20.totalSupply()

Return Values

NameTypeDescription
supplyuint256total shares supply

getBuyPrice

solidity
function getBuyPrice(uint256 supply, uint256 amount) external pure returns (uint256)

The price of the amount of shares to buy calculated based on the specified total shares supply

Parameters

NameTypeDescription
supplyuint256total shares supply
amountuint256number of shares to buy

Return Values

NameTypeDescription
[0]uint256the price of the shares to buy

getSellPrice

solidity
function getSellPrice(uint256 supply, uint256 amount) external pure returns (uint256)

The price of the amount of shares to sell calculated based on the specified total shares supply

Parameters

NameTypeDescription
supplyuint256total shares supply
amountuint256number of shares to sell

Return Values

NameTypeDescription
[0]uint256the price of the shares to sell

getBuyPriceAfterFee

solidity
function getBuyPriceAfterFee(uint256 supply, uint256 amount, uint256 protocolFeePercent, uint256 holdersFeePercent, uint256 subjectFeePercent) external pure returns (uint256)

The price of the amount of shares to buy, including all fees; calculated based on the specified total shares supply and fees percentages

Parameters

NameTypeDescription
supplyuint256total shares supply
amountuint256number of shares to buy
protocolFeePercentuint256protocol fee percent
holdersFeePercentuint256shares holders fee percent
subjectFeePercentuint256protocol fee percent

Return Values

NameTypeDescription
[0]uint256the price of the shares to buy

getSellPriceAfterFee

solidity
function getSellPriceAfterFee(uint256 supply, uint256 amount, uint256 protocolFeePercent, uint256 holdersFeePercent, uint256 subjectFeePercent) external pure returns (uint256)

The price of the amount of shares to sell, including all fees; calculated based on the specified total shares supply and fees percentages

Parameters

NameTypeDescription
supplyuint256total shares supply
amountuint256number of shares to sell
protocolFeePercentuint256protocol fee percent
holdersFeePercentuint256shares holders fee percent
subjectFeePercentuint256protocol fee percent

Return Values

NameTypeDescription
[0]uint256the price of the shares to sell

getBuyPrice

solidity
function getBuyPrice(uint256 amount) external view returns (uint256)

Current price of the amount of shares to buy; calculated based on the current total shares supply

Parameters

NameTypeDescription
amountuint256number of shares to buy

Return Values

NameTypeDescription
[0]uint256the price of the shares to buy

getSellPrice

solidity
function getSellPrice(uint256 amount) external view returns (uint256)

Current price of the amount of shares to sell; calculated based on the current total shares supply

Parameters

NameTypeDescription
amountuint256number of shares to sell

Return Values

NameTypeDescription
[0]uint256the price of the shares to sell

getBuyPriceAfterFee

solidity
function getBuyPriceAfterFee(uint256 amount) external view returns (uint256)

Current price of the amount of shares to buy, including all fees; calculated based on the current total shares supply and fees percentages

Parameters

NameTypeDescription
amountuint256number of shares to buy

Return Values

NameTypeDescription
[0]uint256the price of the shares to buy

getSellPriceAfterFee

solidity
function getSellPriceAfterFee(uint256 amount) external view returns (uint256)

Current price of the amount of shares to sell, including all fees; calculated based on the current total shares supply and fees percentages

Parameters

NameTypeDescription
amountuint256number of shares to sell

Return Values

NameTypeDescription
[0]uint256the price of the shares to sell

buyShares

solidity
function buyShares(uint256 amount) external payable

Buy amount of shares. Sender has to supply getBuyPriceAfterFee(amount) ETH. First share can be bought only by current subject issuer.

Depending on the implementation, ERC-20 token payment may be required instead of ETH. In such a case, implementation must through if ETH is sent, effectively overriding the function definition as non-payable

Parameters

NameTypeDescription
amountuint256amount of the shares to buy

buySharesTo

solidity
function buySharesTo(uint256 amount, address beneficiary) external payable

Buy amount of shares in the favor of the address specified (beneficiary). Sender has to supply getBuyPriceAfterFee(amount) ETH. First share can be bought only by current subject issuer.

Depending on the implementation, ERC-20 token payment may be required instead of ETH. In such a case, implementation must through if ETH is sent, effectively overriding the function definition as non-payable

Parameters

NameTypeDescription
amountuint256amount of the shares to buy
beneficiaryaddressan address receiving the shares

sellShares

solidity
function sellShares(uint256 amount) external

Sell amount of shares. Sender gets getSellPriceAfterFee(amount) of ETH. Last share cannot be sold.

Depending on the implementation, ERC-20 token may be payed instead of ETH.

Parameters

NameTypeDescription
amountuint256amount of the shares to sell

sellSharesTo

solidity
function sellSharesTo(uint256 amount, address payable beneficiary) external

Sell amount of shares in the favor of the address specified (beneficiary). The beneficiary gets getSellPriceAfterFee(amount) of ETH. Last share cannot be sold.

Depending on the implementation, ERC-20 token may be payed instead of ETH.

Parameters

NameTypeDescription
amountuint256amount of the shares to sell
beneficiaryaddress payablean address receiving the funds from the sale

getTradeVolume

solidity
function getTradeVolume() external view returns (uint256)

Cumulative value of all trades; allows to derive cumulative fees paid

This value cannot decrease over time; it can increase or remain constant if no trades are happening

Return Values

NameTypeDescription
[0]uint256Sum of the modulo of all trading operations