Factory Contract
Deploys and registers vault contracts. Validates all parameters against the Globals contract before deployment.
Source: contracts/factory/
Source Modules
contract.rs
Constructor, set_vault_wasm_hash, create_vault, queries, inline GlobalsClient
storage.rs
Data keys (globals, wasm_hash, 3-index vault registry), getters/setters
errors.rs
#[contracterror] enum (11 variants)
events.rs
VaultDeployed, WasmHashUpdated events
test.rs
3 tests
How It Works
Governor deploys the Factory with a Globals address and an initial vault WASM hash
When a Pool Manager calls
create_vault(params, salt), the factory:Validates the manager is approved and active (via
GlobalsClient)Checks the manager is not delinquent (
is_delinquent— blocked if any vault defaulted)Checks the manager's credit limit (
outstanding + principal ≤ max_credit)Validates the lending token is whitelisted
Validates interest rate, loan term, principal, and split ratio against global settings
Locks manager collateral via
GlobalsClient::lock_collateralIncrements outstanding principal via
GlobalsClient::increment_outstandingDeploys a new vault contract using
e.deployer().with_current_contract(salt).deploy_v2(wasm_hash, (globals, params))Registers the vault in three indexes: all vaults, per-manager, per-borrower
The governor can update the vault WASM hash via
set_vault_wasm_hash(for future vault template upgrades)
Functions
Constructor
Initialise factory with admin, globals reference, and vault template hash.
Admin Actions
set_vault_wasm_hash(caller, new_hash)
Update the vault WASM template
Vault Creation
create_vault(params: VaultParams, salt)
Deploy a new vault with full validation
VaultParams:
Queries
get_globals()
Globals contract address
get_vault_wasm_hash()
Current vault template hash
get_vault_count()
Total deployed vaults
get_all_vaults()
List of all vault addresses
get_manager_vaults(manager)
Vaults created by a specific manager
get_borrower_vaults(borrower)
Vaults for a specific borrower
Validation Checks
The Factory performs extensive validation before deploying a vault:
Manager approved
ManagerNotApproved (3)
Manager must be active in Globals
Not delinquent
ManagerDelinquent (10)
Manager must have no uncleared defaults
Credit limit
CreditLimitExceeded (11)
outstanding + principal ≤ max_credit
Asset whitelisted
AssetNotSupported (4)
Token must be whitelisted in Globals
Interest rate
InvalidRate (5)
Must exceed global minimum
Loan term
InvalidTerm (6)
Must be within global min/max
Principal
InvalidPrincipal (7)
Must be within global min/max
Split ratio
InvalidSplitRatio (8)
Must be 1–99
Collateral
InsufficientCollateral (9)
Manager must have enough available collateral
Events
VaultDeployed
vault address, manager, borrower, principal
Vault created
WasmHashUpdated
new hash
Template updated
Last updated