✔️How to create a market
To create a new market in the Bank contract, you need to call the createMarket
function. This function requires specific parameters and a transaction fee. Follow these steps to create a market:
Function Signature
function createMarket(MarketConfigs memory marketConfigs) external payable returns (uint256)
Parameters
The createMarket
function takes a single parameter of type MarketConfigs
, which is a struct containing the following fields:
loanToken
address
The address of the ERC20 token used for loans in this market
collateralToken
address
The address of the ERC20 token used as collateral in this market
oracle
address
The address of the price oracle contract for this market
irm
address
The address of the Interest Rate Model contract for this market
lltv
uint256
The Liquidation Loan-to-Value ratio for this market (in WAD, e.g., 0.8 * 1e18 for 80%)
Market Creation Fee
The createMarket
function is payable
, which means you need to send ETH along with the transaction. The required amount is stored in the marketCreationFee
variable of the Bank contract. Make sure to include this fee when calling the function.
Steps to Create a Market
Prepare the
MarketConfigs
struct with the necessary parameters.Determine the current
marketCreationFee
by calling themarketCreationFee()
function on the Bank contract.Call the
createMarket
function with the preparedMarketConfigs
and include themarketCreationFee
as the transaction value.
Example (using ethers.js)
const Bank = // ... initialize Bank contract instance
// Prepare MarketConfigs
const marketConfigs = {
loanToken: "0x...", // Address of the loan token
collateralToken: "0x...", // Address of the collateral token
oracle: "0x...", // Address of the price oracle
irm: "0x...", // Address of the Interest Rate Model
lltv: ethers.utils.parseUnits("0.8", 18) // 80% LLTV
}
// Get the market creation fee
const marketCreationFee = await Bank.marketCreationFee()
// Create the market
const tx = await Bank.createMarket(marketConfigs, { value: marketCreationFee })
const receipt = await tx.wait()
// Get the new market ID from the event
const event = receipt.events.find(e => e.event === 'CreateMarket')
const newMarketId = event.args.id
console.log(`New market created with ID: ${newMarketId}`)
Important Notes
Ensure that the oracle and IRM addresses are valid and compatible with the Bank contract.
The IRM (Interest Rate Model) must be registered with the Bank contract before creating a market. Use the
registerIrm
function to register a new IRM if needed.The LLTV (Liquidation Loan-to-Value) ratio should be set carefully as it affects the risk parameters of the market.
Make sure you have sufficient ETH to cover the
marketCreationFee
.
After successfully creating a market, you can use the returned market ID for other operations such as supplying assets, borrowing, or managing collateral within that specific market.
Last updated