PricelessPositionManager

Financial contract with priceless position management.

Functions

onlyPreExpiration() modifier

MODIFIERS

==== onlyPostExpiration() modifier

==== onlyCollateralizedPosition(address sponsor) modifier

==== onlyOpenState() modifier

==== noPendingWithdrawal(address sponsor) modifier

==== fees() modifier

MODIFIERS

nonReentrant() modifier

Prevents a contract from calling itself, directly or indirectly. Calling a nonReentrant function from another nonReentrant function is not supported. It is possible to prevent this from happening by making the nonReentrant function external, and make it call a private function that does the actual work.

nonReentrantView() modifier

Designed to prevent a view-only method from being re-entered during a call to a nonReentrant() state-changing method.

onlyIfTest() modifier

Reverts if not running in test mode.

constructor(uint256 _expirationTimestamp, uint256 _withdrawalLiveness, address _collateralAddress, address _finderAddress, bytes32 _priceIdentifier, string _syntheticName, string _syntheticSymbol, address _tokenFactoryAddress, struct FixedPoint.Unsigned _minSponsorTokens, address _timerAddress) public

Construct the PricelessPositionManager

Parameters:

  • _expirationTimestamp: unix timestamp of when the contract will expire.

  • _withdrawalLiveness: liveness delay, in seconds, for pending withdrawals.

  • _collateralAddress: ERC20 token used as collateral for all positions.

  • _finderAddress: UMA protocol Finder used to discover other protocol contracts.

  • _priceIdentifier: registered in the DVM for the synthetic.

  • _syntheticName: name for the token contract that will be deployed.

  • _syntheticSymbol: symbol for the token contract that will be deployed.

  • _tokenFactoryAddress: deployed UMA token factory to create the synthetic token.

  • _minSponsorTokens: minimum amount of collateral that must exist at any time in a position.

  • _timerAddress: Contract that stores the current time in a testing environment. Must be set to 0x0 for production environments that use live time.

requestTransferPosition() public

Requests to transfer ownership of the caller’s current position to a new sponsor address. Once the request liveness is passed, the sponsor can execute the transfer and specify the new sponsor.

The liveness length is the same as the withdrawal liveness.

transferPositionPassedRequest(address newSponsorAddress) public

After a passed transfer position request (i.e., by a call to requestTransferPosition and waiting withdrawalLiveness), transfers ownership of the caller’s current position to newSponsorAddress.

Transferring positions can only occur if the recipient does not already have a position.

Parameters:

  • newSponsorAddress: is the address to which the position will be transferred.

cancelTransferPosition() external

Cancels a pending transfer position request.

depositTo(address sponsor, struct FixedPoint.Unsigned collateralAmount) public

Transfers collateralAmount of collateralCurrency into the specified sponsor’s position.

Increases the collateralization level of a position after creation. This contract must be approved to spend at least collateralAmount of collateralCurrency.

Parameters:

  • sponsor: the sponsor to credit the deposit to.

  • collateralAmount: total amount of collateral tokens to be sent to the sponsor’s position.

deposit(struct FixedPoint.Unsigned collateralAmount) public

Transfers collateralAmount of collateralCurrency into the caller’s position.

Increases the collateralization level of a position after creation. This contract must be approved to spend at least collateralAmount of collateralCurrency.

Parameters:

  • collateralAmount: total amount of collateral tokens to be sent to the sponsor’s position.

withdraw(struct FixedPoint.Unsigned collateralAmount) → struct FixedPoint.Unsigned amountWithdrawn public

Transfers collateralAmount of collateralCurrency from the sponsor’s position to the sponsor.

Reverts if the withdrawal puts this position’s collateralization ratio below the global collateralization ratio. In that case, use requestWithdrawal. Might not withdraw the full requested amount to account for precision loss.

Parameters:

  • collateralAmount: is the amount of collateral to withdraw.

requestWithdrawal(struct FixedPoint.Unsigned collateralAmount) public

Starts a withdrawal request that, if passed, allows the sponsor to withdraw` from their position.

The request will be pending for withdrawalLiveness, during which the position can be liquidated.

Parameters:

  • collateralAmount: the amount of collateral requested to withdraw

withdrawPassedRequest() → struct FixedPoint.Unsigned amountWithdrawn external

After a passed withdrawal request (i.e., by a call to requestWithdrawal and waiting withdrawalLiveness), withdraws positionData.withdrawalRequestAmount of collateral currency.

Might not withdraw the full requested amount in order to account for precision loss or if the full requested amount exceeds the collateral in the position (due to paying fees).

cancelWithdrawal() external

Cancels a pending withdrawal request.

create(struct FixedPoint.Unsigned collateralAmount, struct FixedPoint.Unsigned numTokens) public

Creates tokens by creating a new position or by augmenting an existing position. Pulls collateralAmount into the sponsor’s position and mints numTokens of tokenCurrency.

Reverts if minting these tokens would put the position’s collateralization ratio below the global collateralization ratio. This contract must be approved to spend at least collateralAmount of collateralCurrency.

Parameters:

  • collateralAmount: is the number of collateral tokens to collateralize the position with

  • numTokens: is the number of tokens to mint from the position.

redeem(struct FixedPoint.Unsigned numTokens) → struct FixedPoint.Unsigned amountWithdrawn public

Burns numTokens of tokenCurrency and sends back the proportional amount of collateralCurrency.

Can only be called by a token sponsor. Might not redeem the full proportional amount of collateral in order to account for precision loss. This contract must be approved to spend at least numTokens of tokenCurrency.

Parameters:

  • numTokens: is the number of tokens to be burnt for a commensurate amount of collateral.

settleExpired() → struct FixedPoint.Unsigned amountWithdrawn external

After a contract has passed expiry all token holders can redeem their tokens for underlying at the prevailing price defined by the DVM from the expire function.

This burns all tokens from the caller of tokenCurrency and sends back the proportional amount of collateralCurrency. Might not redeem the full proportional amount of collateral in order to account for precision loss. This contract must be approved to spend tokenCurrency at least up to the caller’s full balance.

expire() external

Locks contract state in expired and requests oracle price.

this function can only be called once the contract is expired and can’t be re-called.

emergencyShutdown() external

Premature contract settlement under emergency circumstances.

Only the governor can call this function as they are permissioned within the FinancialContractAdmin. Upon emergency shutdown, the contract settlement time is set to the shutdown time. This enables withdrawal to occur via the standard settleExpired function. Contract state is set to ExpiredPriceRequested which prevents re-entry into this function or the expire function. No fees are paid when calling emergencyShutdown as the governor who would call the function would also receive the fees.

remargin() external

Theoretically supposed to pay fees and move money between margin accounts to make sure they reflect the NAV of the contract. However, this functionality doesn’t apply to this contract.

This is supposed to be implemented by any contract that inherits AdministrateeInterface and callable only by the Governor contract. This method is therefore minimally implemented in this contract and does nothing.

getCollateral(address sponsor) → struct FixedPoint.Unsigned collateralAmount external

Accessor method for a sponsor’s collateral.

This is necessary because the struct returned by the positions() method shows rawCollateral, which isn’t a user-readable value.

Parameters:

  • sponsor: address whose collateral amount is retrieved.

totalPositionCollateral() → struct FixedPoint.Unsigned totalCollateral external

Accessor method for the total collateral stored within the PricelessPositionManager.

_reduceSponsorPosition(address sponsor, struct FixedPoint.Unsigned tokensToRemove, struct FixedPoint.Unsigned collateralToRemove, struct FixedPoint.Unsigned withdrawalAmountToRemove) internal

INTERNAL FUNCTIONS

==== _deleteSponsorPosition(address sponsor) → struct FixedPoint.Unsigned internal

==== _pfc() → struct FixedPoint.Unsigned internal

==== _getPositionData(address sponsor) → struct PricelessPositionManager.PositionData internal

==== _getIdentifierWhitelist() → contract IdentifierWhitelistInterface internal

==== _getOracle() → contract OracleInterface internal

==== _getFinancialContractsAdminAddress() → address internal

==== _requestOraclePrice(uint256 requestedTime) internal

==== _getOraclePrice(uint256 requestedTime) → struct FixedPoint.Unsigned internal

==== _resetWithdrawalRequest(struct PricelessPositionManager.PositionData positionData) internal

==== _incrementCollateralBalances(struct PricelessPositionManager.PositionData positionData, struct FixedPoint.Unsigned collateralAmount) → struct FixedPoint.Unsigned internal

==== _decrementCollateralBalances(struct PricelessPositionManager.PositionData positionData, struct FixedPoint.Unsigned collateralAmount) → struct FixedPoint.Unsigned internal

==== _decrementCollateralBalancesCheckGCR(struct PricelessPositionManager.PositionData positionData, struct FixedPoint.Unsigned collateralAmount) → struct FixedPoint.Unsigned internal

==== _onlyOpenState() internal

==== _onlyPreExpiration() internal

==== _onlyPostExpiration() internal

==== _onlyCollateralizedPosition(address sponsor) internal

==== _positionHasNoPendingWithdrawal(address sponsor) internal

==== payRegularFees() → struct FixedPoint.Unsigned totalPaid public

Pays UMA DVM regular fees (as a % of the collateral pool) to the Store contract.

These must be paid periodically for the life of the contract. If the contract has not paid its regular fee in a week or more then a late penalty is applied which is sent to the caller. If the amount of fees owed are greater than the pfc, then this will pay as much as possible from the available collateral. An event is only fired if the fees charged are greater than 0.

==== pfc() → struct FixedPoint.Unsigned public

Gets the current profit from corruption for this contract in terms of the collateral currency.

This is equivalent to the collateral pool available from which to pay fees. Therefore, derived contracts are expected to implement this so that pay-fee methods can correctly compute the owed fees as a % of PfC.

==== _payFinalFees(address payer, struct FixedPoint.Unsigned amount) internal

INTERNAL FUNCTIONS

_getStore() → contract StoreInterface internal

_computeFinalFees() → struct FixedPoint.Unsigned finalFees internal

_getFeeAdjustedCollateral(struct FixedPoint.Unsigned rawCollateral) → struct FixedPoint.Unsigned collateral internal

_convertToRawCollateral(struct FixedPoint.Unsigned collateral) → struct FixedPoint.Unsigned rawCollateral internal

_removeCollateral(struct FixedPoint.Unsigned rawCollateral, struct FixedPoint.Unsigned collateralToRemove) → struct FixedPoint.Unsigned removedCollateral internal

_addCollateral(struct FixedPoint.Unsigned rawCollateral, struct FixedPoint.Unsigned collateralToAdd) → struct FixedPoint.Unsigned addedCollateral internal

_adjustCumulativeFeeMultiplier(struct FixedPoint.Unsigned amount, struct FixedPoint.Unsigned currentPfc) internal

_preEntranceCheck() internal

_preEntranceSet() internal

_postEntranceReset() internal

setCurrentTime(uint256 time) external

Sets the current time.

Will revert if not running in test mode.

Parameters:

  • time: timestamp to set current Testable time to.

getCurrentTime() → uint256 public

Gets the current time. Will return the last time set in setCurrentTime if running in test mode. Otherwise, it will return the block timestamp.

RequestTransferPosition(address oldSponsor) event

EVENTS

==== RequestTransferPositionExecuted(address oldSponsor, address newSponsor) event

==== RequestTransferPositionCanceled(address oldSponsor) event

==== Deposit(address sponsor, uint256 collateralAmount) event

==== Withdrawal(address sponsor, uint256 collateralAmount) event

==== RequestWithdrawal(address sponsor, uint256 collateralAmount) event

==== RequestWithdrawalExecuted(address sponsor, uint256 collateralAmount) event

==== RequestWithdrawalCanceled(address sponsor, uint256 collateralAmount) event

==== PositionCreated(address sponsor, uint256 collateralAmount, uint256 tokenAmount) event

==== NewSponsor(address sponsor) event

==== EndedSponsorPosition(address sponsor) event

==== Redeem(address sponsor, uint256 collateralAmount, uint256 tokenAmount) event

==== ContractExpired(address caller) event

==== SettleExpiredPosition(address caller, uint256 collateralReturned, uint256 tokensBurned) event

==== EmergencyShutdown(address caller, uint256 originalExpirationTimestamp, uint256 shutdownTimestamp) event

==== RegularFeesPaid(uint256 regularFee, uint256 lateFee) event

EVENTS

FinalFeesPaid(uint256 amount) event

© UMA Project 2018-2019