Skip to main content

Unlock (v13)

The Unlock Interface*

Methods

__initializeOwnable

function __initializeOwnable(address sender) external nonpayable

Parameters

NameTypeDescription
senderaddressundefined

addLockTemplate

function addLockTemplate(address impl, uint16 version) external nonpayable

Add a PublicLock template to be used for future calls to createLock.

This is used to upgrade contract per version number

Parameters

NameTypeDescription
impladdressundefined
versionuint16undefined

chainId

function chainId() external view returns (uint256)

Returns

NameTypeDescription
_0uint256undefined

computeAvailableDiscountFor

function computeAvailableDiscountFor(address _purchaser, uint256 _keyPrice) external pure returns (uint256 discount, uint256 tokens)

[DEPRECATED] Call to this function has been removed from PublicLock > v9.

[DEPRECATED] Kept for backwards compatibility This function returns the discount available for a user, when purchasing a a key from a lock. This does not modify the state. It returns both the discount and the number of tokens consumed to grant that discount.

Parameters

NameTypeDescription
_purchaseraddressundefined
_keyPriceuint256undefined

Returns

NameTypeDescription
discountuint256undefined
tokensuint256undefined

configUnlock

function configUnlock(address _udt, address _weth, uint256 _estimatedGasForPurchase, string _symbol, string _URI, uint256 _chainId) external nonpayable

Allows the owner to update configuration variables

Parameters

NameTypeDescription
_udtaddressundefined
_wethaddressundefined
_estimatedGasForPurchaseuint256undefined
_symbolstringundefined
_URIstringundefined
_chainIduint256undefined

createLock

function createLock(uint256 _expirationDuration, address _tokenAddress, uint256 _keyPrice, uint256 _maxNumberOfKeys, string _lockName, bytes12) external nonpayable returns (address)

Create lock (legacy) This deploys a lock for a creator. It also keeps track of the deployed lock.

internally call createUpgradeableLock

Parameters

NameTypeDescription
_expirationDurationuint256the duration of the lock (pass 0 for unlimited duration)
_tokenAddressaddressset to the ERC20 token address, or 0 for ETH.
_keyPriceuint256the price of each key
_maxNumberOfKeysuint256the maximum numbers of keys to be edited
_lockNamestringthe name of the lock param _salt [deprec] -- kept only for backwards compatibility This may be implemented as a sequence ID or with RNG. It's used with create2 to know the lock's address before the transaction is mined.
_5bytes12undefined

Returns

NameTypeDescription
_0addressundefined

createUpgradeableLock

function createUpgradeableLock(bytes data) external nonpayable returns (address)

Create lock (default) This deploys a lock for a creator. It also keeps track of the deployed lock.

this call is passed as encoded function - for instance: bytes memory data = abi.encodeWithSignature( 'initialize(address,uint256,address,uint256,uint256,string)', msg.sender, _expirationDuration, _tokenAddress, _keyPrice, _maxNumberOfKeys, _lockName );

Parameters

NameTypeDescription
databytesbytes containing the call to initialize the lock template

Returns

NameTypeDescription
_0addressaddress of the create lock

createUpgradeableLockAtVersion

function createUpgradeableLockAtVersion(bytes data, uint16 _lockVersion) external nonpayable returns (address)

Create an upgradeable lock using a specific PublicLock version

Parameters

NameTypeDescription
databytesbytes containing the call to initialize the lock template (refer to createUpgradeableLock for more details)
_lockVersionuint16the version of the lock to use

Returns

NameTypeDescription
_0addressundefined

estimatedGasForPurchase

function estimatedGasForPurchase() external view returns (uint256)

Returns

NameTypeDescription
_0uint256undefined

getAdmin

function getAdmin() external view returns (address)

Returns the ProxyAdmin contract address that manages upgrades for the current Unlock contract.

this reads the address directly from storage, at the slot _ADMIN_SLOT defined by Open Zeppelin's EIP1967 Proxy implementation which corresponds to the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1

Returns

NameTypeDescription
_0addressundefined

getGlobalBaseTokenURI

function getGlobalBaseTokenURI() external view returns (string)

Redundant with globalBaseTokenURI() for backwards compatibility with v3 & v4 locks.

Returns

NameTypeDescription
_0stringundefined

getGlobalTokenSymbol

function getGlobalTokenSymbol() external view returns (string)

Redundant with globalTokenSymbol() for backwards compatibility with v3 & v4 locks.

Returns

NameTypeDescription
_0stringundefined

globalBaseTokenURI

function globalBaseTokenURI() external view returns (string)

Returns

NameTypeDescription
_0stringundefined

globalTokenSymbol

function globalTokenSymbol() external view returns (string)

Returns

NameTypeDescription
_0stringundefined

grossNetworkProduct

function grossNetworkProduct() external view returns (uint256)

Returns

NameTypeDescription
_0uint256undefined

initialize

function initialize(address _unlockOwner) external nonpayable

Parameters

NameTypeDescription
_unlockOwneraddressundefined

initializeProxyAdmin

function initializeProxyAdmin() external nonpayable

deploy a ProxyAdmin contract used to upgrade locks

isOwner

function isOwner() external view returns (bool)

Returns true if the caller is the current owner.

Returns

NameTypeDescription
_0boolundefined

locks

function locks(address) external view returns (bool deployed, uint256 totalSales, uint256 yieldedDiscountTokens)

Parameters

NameTypeDescription
_0addressundefined

Returns

NameTypeDescription
deployedboolundefined
totalSalesuint256undefined
yieldedDiscountTokensuint256undefined

networkBaseFee

function networkBaseFee() external view returns (uint256)

Helper to get the network mining basefee as introduced in EIP-1559

this helper can be wrapped in try/catch statement to avoid revert in networks where EIP-1559 is not implemented

Returns

NameTypeDescription
_0uint256undefined

owner

function owner() external view returns (address)

Returns the address of the current owner.

Returns

NameTypeDescription
_0addressundefined

postLockUpgrade

function postLockUpgrade() external nonpayable

Call executed by a lock after its version upgrade triggered by upgradeLock - PublicLock v12 > v13 (mainnet): migrate an existing Lock to another instance of the Unlock contract

The msg.sender will be the upgraded lock

protocolFee

function protocolFee() external view returns (uint256)

The fee (in basis points) collected by the protocol on each purchase / extension / renewal of a key

Returns

NameTypeDescription
_0uint256the protocol fee in basic point

proxyAdminAddress

function proxyAdminAddress() external view returns (address _proxyAdminAddress)

Retrieve the contract address of the proxy admin that manages the locks

Returns

NameTypeDescription
_proxyAdminAddressaddressthe address of the ProxyAdmin instance

publicLockAddress

function publicLockAddress() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

publicLockImpls

function publicLockImpls(uint16 _version) external view returns (address _implAddress)

Match lock templates addresses with version numbers

Parameters

NameTypeDescription
_versionuint16the number of the version of the template

Returns

NameTypeDescription
_implAddressaddressaddress of the lock templates

publicLockLatestVersion

function publicLockLatestVersion() external view returns (uint16 _version)

Retrieve the latest existing lock template version

Returns

NameTypeDescription
_versionuint16the version number of the latest template (used to deploy contracts)

publicLockVersions

function publicLockVersions(address _impl) external view returns (uint16)

Match version numbers with lock templates addresses

Parameters

NameTypeDescription
_impladdressthe address of the deployed template contract (PublicLock)

Returns

NameTypeDescription
_0uint16number of the version corresponding to this address

recordConsumedDiscount

function recordConsumedDiscount(uint256 _discount, uint256 _tokens) external view

[DEPRECATED] Call to this function has been removed from PublicLock > v9.

[DEPRECATED] Kept for backwards compatibility This function will keep track of consumed discounts by a given user. It will also grant discount tokens to the creator who is granting the discount based on the amount of discount and compensation rate. This function is invoked by a previously deployed lock only.

Parameters

NameTypeDescription
_discountuint256undefined
_tokensuint256undefined

recordKeyPurchase

function recordKeyPurchase(uint256 _value, address _referrer) external nonpayable

This function keeps track of the added GDP, as well as grants of discount tokens to the referrer, if applicable. The number of discount tokens granted is based on the value of the referral, the current growth rate and the lock's discount token distribution rate This function is invoked by a previously deployed lock only.

Parameters

NameTypeDescription
_valueuint256undefined
_referreraddressundefined

removeLock

function removeLock(address lock) external nonpayable

Removes a lock from the list of locks. This will prevent the lock from being able to receive governance tokens. The lock will still be able to sell its memberships.

This function is onlyOwner

Parameters

NameTypeDescription
lockaddressaddress of the lock to remove

renounceOwnership

function renounceOwnership() external nonpayable

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

resetTrackedValue

function resetTrackedValue(uint256 _grossNetworkProduct, uint256 _totalDiscountGranted) external nonpayable

Parameters

NameTypeDescription
_grossNetworkProductuint256undefined
_totalDiscountGranteduint256undefined

setLockTemplate

function setLockTemplate(address payable _publicLockAddress) external nonpayable

Upgrade the PublicLock template used for future calls to createLock.

This will initialize the template and revokeOwnership.

Parameters

NameTypeDescription
_publicLockAddressaddress payableundefined

setOracle

function setOracle(address _tokenAddress, address _oracleAddress) external nonpayable

allows the owner to set the oracle address to use for value conversions setting the _oracleAddress to address(0) removes support for the token

This will also call update to ensure at least one datapoint has been recorded.

Parameters

NameTypeDescription
_tokenAddressaddressundefined
_oracleAddressaddressundefined

setProtocolFee

function setProtocolFee(uint256 _protocolFee) external nonpayable

Set the fee collected by the protocol

Parameters

NameTypeDescription
_protocolFeeuint256fee (in basis points)

setSwapBurner

function setSwapBurner(address _swapBurnerAddress) external nonpayable

Set the UDT Swap and Burn contract address

Parameters

NameTypeDescription
_swapBurnerAddressaddressthe address of the SwapBurner contract instance

swapAndBurn

function swapAndBurn(address token, uint256 amount, uint24 poolFee) external nonpayable

Send tokens held by this contract to the UDT SwapBurner contract. The tokens sent to the contract are then swapped for UDT and UDT itself will be sent to a burner address. This function can be called by anyone (not only the contract owner) as a way to ensure decentralization.

Parameters

NameTypeDescription
tokenaddressthe address of the token (zero address for native) to swap and burn
amountuint256the amount of tokens to swap and burn
poolFeeuint24the poolFee of the token <> WETH/Wrapped Native asset to use for the swap

swapBurnerAddress

function swapBurnerAddress() external view returns (address)

The address of the UDT Swap and Burn contract

Returns

NameTypeDescription
_0addressundefined

totalDiscountGranted

function totalDiscountGranted() external view returns (uint256)

Returns

NameTypeDescription
_0uint256undefined

transferOwnership

function transferOwnership(address newOwner) external nonpayable

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

Parameters

NameTypeDescription
newOwneraddressundefined

transferTokens

function transferTokens(address token, address to, uint256 amount) external nonpayable

Function which transfers tokens held by the contract It handles both ERC20 and the base currency.

This function is onlyOwner

Parameters

NameTypeDescription
tokenaddressthe address of the token to transfer (pass the 0x0 address for the base currency)
toaddressthe address to transfer the tokens to
amountuint256the amount of tokens to transfer

udt

function udt() external view returns (address)

Returns

NameTypeDescription
_0addressundefined

uniswapOracles

function uniswapOracles(address) external view returns (address)

Parameters

NameTypeDescription
_0addressundefined

Returns

NameTypeDescription
_0addressundefined

unlockVersion

function unlockVersion() external pure returns (uint16)

Returns

NameTypeDescription
_0uint16undefined

upgradeLock

function upgradeLock(address payable lockAddress, uint16 version) external nonpayable returns (address)

Upgrade a lock to a specific version

only available for publicLockVersion > 10 (proxyAdmin /required)

Parameters

NameTypeDescription
lockAddressaddress payablethe existing lock address
versionuint16the version number you are targeting Likely implemented with OpenZeppelin TransparentProxy contract

Returns

NameTypeDescription
_0addressundefined

weth

function weth() external view returns (address)

Returns

NameTypeDescription
_0addressundefined