Skip to content

Solidity API

BondingPair

Diamond facet implementing a bonding curve token pair for automated market making

Provides functionality for a two-asset bonding curve within the Diamond architecture Implements swap, buy, and transfer operations with constant product formula (k=x*y) Uses ReentrancyGuard to prevent reentrancy attacks All core implementation details delegated to BondingPairInternal

init

solidity
function init(address account, address _counterPartyAsset, uint256 _supply, uint256 _purchaseAmount, struct IPropsBaseFacet.Hook[] _hooks, address[] _approvedDiamonds) external

Initializes the bonding pair with initial liquidity and configuration

Sets up the bonding pool with initial supply and purchase amount Can only be called once by the diamond owner or factory

Parameters

NameTypeDescription
accountaddressAddress that provides the initial liquidity
_counterPartyAssetaddressAddress of the second token in the pair
_supplyuint256Initial supply of the primary token (this contract)
_purchaseAmountuint256Initial amount of counter-party asset to add as liquidity
_hooksstruct IPropsBaseFacet.Hook[]Array of Hook structs defining callback functions for various operations
_approvedDiamondsaddress[]Array of addresses that are approved to interact with this contract

buy

solidity
function buy(uint256 amountIn, address to) external

Buys tokens using the bonding curve formula

Calculates the output amount based on the bonding curve and transfers tokens Protected against reentrancy and can only be called by the diamond

Parameters

NameTypeDescription
amountInuint256Amount of counter-party asset to spend
toaddressAddress to receive the purchased tokens

mint

solidity
function mint(uint256 reserve0, uint256 reserve1) public returns (bool)

Mints liquidity tokens

Placeholder for minting liquidity tokens based on reserves Currently returns true without action Can only be called by the diamond

Parameters

NameTypeDescription
reserve0uint256Amount of token0 in reserve
reserve1uint256Amount of token1 in reserve

Return Values

NameTypeDescription
[0]boolBoolean indicating success

swap

solidity
function swap(uint256 amount0In, uint256 amount0Out, uint256 amount1In, uint256 amount1Out) public returns (bool)

Performs a swap between the paired tokens

Executes a token swap based on input/output amounts Can only be called by the diamond

Parameters

NameTypeDescription
amount0Inuint256Amount of token0 being sent to the pair
amount0Outuint256Amount of token0 being withdrawn from the pair
amount1Inuint256Amount of token1 being sent to the pair
amount1Outuint256Amount of token1 being withdrawn from the pair

Return Values

NameTypeDescription
[0]boolBoolean indicating success

approval

solidity
function approval(address _user, address _token, uint256 amount) public returns (bool)

Handles token approvals for users

Sets approval for a user to spend tokens Can only be called by the diamond

Parameters

NameTypeDescription
_useraddressAddress of the user granting approval
_tokenaddressAddress of the token being approved
amountuint256Amount of tokens approved to spend

Return Values

NameTypeDescription
[0]boolBoolean indicating success

transferAsset

solidity
function transferAsset(address recipient, uint256 amount) public

Transfers counter-party assets to a recipient

Transfers asset tokens from sender to recipient Can only be called by the diamond

Parameters

NameTypeDescription
recipientaddressAddress to receive the assets
amountuint256Amount of asset tokens to transfer

transferTo

solidity
function transferTo(address recipient, uint256 amount) public

Transfers primary tokens to a recipient

Transfers primary (this contract's) tokens to recipient Can only be called by the diamond

Parameters

NameTypeDescription
recipientaddressAddress to receive the tokens
amountuint256Amount of tokens to transfer

getReserves

solidity
function getReserves() public view returns (uint256, uint256)

Gets the current reserves of both tokens in the pair

Returns the current balances of both tokens in the pool

Return Values

NameTypeDescription
[0]uint256reserve0 Balance of token0 in the pool
[1]uint256reserve1 Balance of token1 in the pool

kLast

solidity
function kLast() public view returns (uint256)

Gets the last recorded k value (constant product)

Returns the product of reserves (reserve0 * reserve1)

Return Values

NameTypeDescription
[0]uint256The last recorded product of reserves

price0Last

solidity
function price0Last() public view returns (uint256)

Gets the last recorded price of token0

Returns the last price at which token0 was traded

Return Values

NameTypeDescription
[0]uint256The last price of token0

price1Last

solidity
function price1Last() public view returns (uint256)

Gets the last recorded price of token1

Returns the last price at which token1 was traded

Return Values

NameTypeDescription
[0]uint256The last price of token1

balance

solidity
function balance() public view returns (uint256)

Gets the balance of primary tokens in the pool

Returns the current balance of the primary token

Return Values

NameTypeDescription
[0]uint256The balance of primary tokens

assetBalance

solidity
function assetBalance() public view returns (uint256)

Gets the balance of counter-party asset tokens in the pool

Returns the current balance of the counter-party asset

Return Values

NameTypeDescription
[0]uint256The balance of counter-party assets