Skip to main content
We represent the protocol smart contract functionality using the OpenAPI spec, where writes map to POST and reads to GET. For simplicity, we sometimes refer to the user positions as “tokens”, even though they are not represented as tokens/ERC20s.
The “Based Protocol”, a set of smart contracts implementing the Based Markets system, uses an ERC-20 token called “Based Credits”. Based Credits is a standard 6-decimal ERC-20 implemented as a fork of the EUROe Smart Contracts. Based Credits can be minted, burned, and managed by the Based Multi-Sig. Based Credits are used in favour of stablecoins to limit the risks and impact of potential security incidents to users. By limiting the amount of stablecoins available in the Exchanger at any given time, the total value at risk can be restricted to the stablecoin TVL of the exchanger. Additionally, the exchanger allows for an improved user experience over depositing & withdrawing of funds and enables certain unique ecosystem benefits. The role of the Exchanger (USDC) within the greater Based smart contract system (simplified)

Functions

The exchanger contract implements the following functions:
  • Callable by anyone
    • exchangeToCredits(uint256 amount): called by the Based app end-user to exchange the supported stablecoin to Based Credits in a 1:1 ratio
    • exchangeFromCredits(uint256 amount, address recipient): called by the Based app end-user as part of the withdrawal process from the app to exchange Based Credits to the supported stablecoin and send them to the intended withdrawal address
  • Callable by ADMIN role
    • sweep(address token, uint256 amount): moves the given amount of the given ERC-20 token to the treasury address (can be used to both manage risk (the supported stablecoin/Based Credits in the smart contract) and to withdraw any tokens mistakenly sent to the contract)
    • pause(): pauses all day-to-day (non-admin and non-treasury) functions
    • unpause(): unpauses (undoes the pause())
  • Callable TREASURY role only
    • changeTreasury(address newTreasury): changes the treasury and “super-admin” address, revoking all roles of the old treasury and adding the DEFAULT_ADMIN_ROLE and ADMIN_ROLE to the newTreasury
    • addAdmin(address newAdmin): adds a new admin
    • removeAdmin(address adminToRemove): removes an existing admin
Depositing Based Credits and the supported stablecoin into the Exchanger happens through a standard ERC20 transfer() or transferFrom() instruction, depending on the counterparty wallet type.

Roles

  • DEFAULT_ADMIN_ROLE: (“treasury”) the “superadmin” of the contract and the recipient of sweeped funds. This can be only one address at a time.
  • ADMIN_ROLE: (“admin”) day-to-day admin of the contract that can be invoked quickly if needed.

Events

Events are emitted for any write function. pause() and unpause() event emissions are inherited from OZ’s Pausable.

Implementation

The smart contract utilises OpenZeppelin’s Access Control to implement the role-based access. The smart contract is implemented as non-upgradable & immutable, except for privileged functions, to reduce the potential attack surfaces. If an update is required, a new smart contract implementing the new code will be deployed.
I