Skip to content

Locker

User-facing entry point. Atomic lock-and-issue: pulls DIEM, stakes it, mints DD, mints PT20 or PT721, all in one transaction.

contracts/src/platforms/venice/Locker.sol

Inherits

Ownable2Step, ReentrancyGuard, Pausable

Immutables

NameTypeSource
diemIDIEMRead from vault.diem() in constructor
vaultVeniceStakingVaultconstructor arg
kDiemkDIEMconstructor arg
pt721PT721constructor arg
pt20FactoryPT20Factoryconstructor arg

Mutable state

NameTypeMutability
ddMinterDDMinter7-day timelocked rotation
pendingDdMinterDDMinterrotation buffer
ddMinterEffectiveAtuint64rotation effective-at

User functions

solidity
function lock(uint256 amount, uint64 maturity, address recipient)
    external nonReentrant whenNotPaused
    returns (address pt, uint256 ptShares, uint256 ddMinted);

function lockPT721(uint256 amount, uint64 maturity, address recipient)
    external nonReentrant whenNotPaused
    returns (uint256 tokenId, uint256 ddMinted);

Common requirements

  • amount > 0
  • recipient != address(0)
  • maturity > block.timestamp
  • DD constraints enforced by DDMinter: amount ≥ minLockAmount, maturity ≤ now + maxLockHorizon.

lock extra

  • DateUtils.isFirstOfMonth(maturity) enforced.
  • Result pt is the PT20Factory.getOrCreate(maturity) address.

lockPT721 extra

  • maturity can be any future timestamp.

Admin functions

solidity
function proposeDdMinter(address ddMinter_) external onlyOwner;
function activateDdMinter() external;            // permissionless after 7d
function cancelDdMinterChange() external onlyOwner;
function pause() external onlyOwner;
function unpause() external onlyOwner;

proposeDdMinter cross-checks DDMinter(_).locker() == address(this) || == address(0).

Events

solidity
event PT20Locked(address indexed payer, address indexed recipient, uint64 indexed maturity,
             uint256 amount, address pt, uint256 ptShares, uint256 ddMinted);
event PT721Locked(address indexed payer, address indexed recipient, uint64 indexed maturity,
             uint256 amount, uint256 tokenId, uint256 ddMinted);
event DdMinterProposed(address indexed ddMinter, uint64 effectiveAt);
event DdMinterActivated(address indexed ddMinter);
event DdMinterChangeCancelled();

Errors

ZeroAddress, ZeroAmount, MaturityInPast, MaturityNotFirstOfMonth,
NoPending, TooEarly, WiringMismatch

Atomicity guarantees

A lock call either completes all of {DIEM transfer, vault stake, kDIEM mint, DD mint, PT20/PT721 deposit} or reverts the whole transaction. There is no partial state where, e.g., DIEM is staked but PT20 is not minted.

Gas

lock first time for a maturity (deploys PT20): ~750k gas. lock reuse of existing PT20: ~250k gas. lockPT721: ~250k gas.

Released under the MIT License.