Appearance
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) externalInitializes 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
| Name | Type | Description |
|---|---|---|
| account | address | Address that provides the initial liquidity |
| _counterPartyAsset | address | Address of the second token in the pair |
| _supply | uint256 | Initial supply of the primary token (this contract) |
| _purchaseAmount | uint256 | Initial amount of counter-party asset to add as liquidity |
| _hooks | struct IPropsBaseFacet.Hook[] | Array of Hook structs defining callback functions for various operations |
| _approvedDiamonds | address[] | Array of addresses that are approved to interact with this contract |
buy
solidity
function buy(uint256 amountIn, address to) externalBuys 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
| Name | Type | Description |
|---|---|---|
| amountIn | uint256 | Amount of counter-party asset to spend |
| to | address | Address 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
| Name | Type | Description |
|---|---|---|
| reserve0 | uint256 | Amount of token0 in reserve |
| reserve1 | uint256 | Amount of token1 in reserve |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | Boolean 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
| Name | Type | Description |
|---|---|---|
| amount0In | uint256 | Amount of token0 being sent to the pair |
| amount0Out | uint256 | Amount of token0 being withdrawn from the pair |
| amount1In | uint256 | Amount of token1 being sent to the pair |
| amount1Out | uint256 | Amount of token1 being withdrawn from the pair |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | Boolean 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
| Name | Type | Description |
|---|---|---|
| _user | address | Address of the user granting approval |
| _token | address | Address of the token being approved |
| amount | uint256 | Amount of tokens approved to spend |
Return Values
| Name | Type | Description |
|---|---|---|
| [0] | bool | Boolean indicating success |
transferAsset
solidity
function transferAsset(address recipient, uint256 amount) publicTransfers counter-party assets to a recipient
Transfers asset tokens from sender to recipient Can only be called by the diamond
Parameters
| Name | Type | Description |
|---|---|---|
| recipient | address | Address to receive the assets |
| amount | uint256 | Amount of asset tokens to transfer |
transferTo
solidity
function transferTo(address recipient, uint256 amount) publicTransfers primary tokens to a recipient
Transfers primary (this contract's) tokens to recipient Can only be called by the diamond
Parameters
| Name | Type | Description |
|---|---|---|
| recipient | address | Address to receive the tokens |
| amount | uint256 | Amount 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | reserve0 Balance of token0 in the pool |
| [1] | uint256 | reserve1 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The 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
| Name | Type | Description |
|---|---|---|
| [0] | uint256 | The balance of counter-party assets |