✔️How to create a bank

You can create a new custom Bank using the BankFactory contract. This process involves calling the createBank function and specifying various parameters to configure the initial settings of the Bank.

Function Signature

function createBank(
    IERC20 asset,
    string memory name,
    string memory symbol,
    uint256 initialFee,
    address initialFeeRecipient,
    uint256 minDelay,
    IBank.BankType bankType
) external returns (Bank)

Parameters

Parameter
Type
Description

asset

IERC20

The address of the base asset (token) to be used in the Bank

name

string

The name of the Bank

symbol

string

The symbol of the Bank

initialFee

uint256

Initial fee setting (max 1000, which represents 10%)

initialFeeRecipient

address

The initial address to receive fees

minDelay

uint256

Minimum delay for timelock operations (in seconds)

bankType

IBank.BankType

Type of the Bank (Public or Private)

Returns

  • Bank: The address of the newly created Bank contract

Usage Example (using ethers.js)

const BankFactory = // Initialize BankFactory contract instance

// Prepare parameters
const asset = "0x..."; // Base asset token address
const name = "My Bank";
const symbol = "MBNK";
const initialFee = 100; // 1% fee
const initialFeeRecipient = "0x..."; // Fee recipient address
const minDelay = 86400; // 1 day
const bankType = 0; // 0: Public, 1: Private

// Create Bank
const tx = await BankFactory.createBank(
    asset,
    name,
    symbol,
    initialFee,
    initialFeeRecipient,
    minDelay,
    bankType
);

const receipt = await tx.wait();

// Extract new Bank address from event
const bankCreatedEvent = receipt.events.find(e => e.event === 'BankCreated');
const newBankAddress = bankCreatedEvent.args.bank;
console.log(`New Bank created at: ${newBankAddress}`);

Important Notes

  • initialFee should be a value between 0 and 1000 (0% - 10%).

  • minDelay should be set carefully. Too short may pose security risks, while too long may cause operational inconvenience. (minimum: 600 seconds)

  • If creating a Private Bank (type: 1), subsequent whitelist management will be necessary.

  • After creating the Bank, you need to add the required Markets and set allocations.

Event

A BankCreated event is emitted when a Bank is created:

event BankCreated(
    address indexed bank,
    address indexed asset,
    string name,
    string symbol
);

You can monitor this event to track the creation of new Banks.

After creating a Bank, you can use its address to perform additional setup and management operations.

Last updated