relevant tag icon
UMA Priceless Position Manager
copy icon
UMA
• version 1.0.0
Finance
Token
Utility
Fees
Audited

UMA Priceless Position Manager

Audited

Handles positions for multiple sponsors in an optimistic (i.e., priceless) way without relying on a price feed. On construction, deploys a new ERC20, managed by this contract, that is the synthetic token.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

UMA

Recent Use

🍞 0x8359 saved

Last Publish

11/5/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
requestTransferPosition() :
This function allows a user to request a transfer of their position in the contract. It first checks that the user has not already requested a transfer, and then sets a timestamp for when the transfer request will pass. This timestamp is set to the current time plus the withdrawal liveness, and must be before the expiration timestamp. Finally, an event is emitted to indicate that the transfer request has been made. (autogenerated documentation)
transferPositionPassedRequest(address) :
This function transfers a position from one sponsor to another. It requires that the new sponsor has not yet paid any fees, that the transfer request has been approved, and that the sender has no pending withdrawals. It then sets the transfer request timestamp to 0, transfers the position data from the sender to the new sponsor, and emits events to indicate the transfer has been completed. (autogenerated documentation)
cancelTransferPosition() :
This function allows a user to cancel a previously requested transfer of their position. It is only available before the expiration of the position and is non-reentrant, meaning it can only be called once. The function checks to make sure that a transfer position request has been made, and then emits an event to indicate that the request has been canceled. The transferPositionRequestPassTimestamp is then set to 0 to indicate that the request has been canceled. (autogenerated documentation)
depositTo(address) :
This function allows a sponsor to deposit collateral to the contract. It requires that the sponsor has no pending withdrawals, that the amount of collateral is greater than 0, and that the pre-expiration period has not passed. It then increments the collateral balances in the position data, emits a Deposit event, and transfers the collateral from the sender to the contract. (autogenerated documentation)
deposit() :
This function allows a user to deposit a certain amount of collateral into the contract. It works by taking in an argument of the amount of collateral to be deposited, and then calling the depositTo() function with the sender's address and the amount of collateral as arguments. This will add the collateral to the sender's balance in the contract. (autogenerated documentation)
withdraw() :
This function allows a user to withdraw collateral from their position in the contract. It requires that the user has not already made a pending withdrawal, that the amount of collateral they are withdrawing is greater than 0, and that the fees associated with the withdrawal are paid. It then decrements the user's collateral balance, emits a Withdrawal event, and transfers the withdrawn collateral to the user. (autogenerated documentation)
requestWithdrawal() :
This function allows a user to request a withdrawal of a specified amount of collateral from their position. It first checks that the amount is greater than 0 and less than or equal to the user's fee-adjusted collateral. It then sets the withdrawal request pass timestamp to the current time plus the withdrawal liveness, and checks that this timestamp is before the expiration timestamp. Finally, it sets the withdrawal request amount to the specified amount and emits an event. (autogenerated documentation)
withdrawPassedRequest() :
This function allows a user to withdraw their collateral from a position they have opened in the system. It first checks that the user has requested a withdrawal and that the request has passed the expiration time. It then calculates the amount to withdraw, taking into account any fees that may be applicable. It then decrements the user's collateral balance and resets the withdrawal request. Finally, it transfers the amount withdrawn to the user. (autogenerated documentation)
cancelWithdrawal() :
This function allows a user to cancel a withdrawal request they have previously made. It first checks to make sure that a withdrawal request has been made, and then emits an event to indicate that the request has been canceled. Finally, it resets the withdrawal request data in the position data storage. (autogenerated documentation)
create() :
This function creates a new position for a sponsor. It requires that the sponsor has sufficient collateral to cover the position, and that the position is above the minimum sponsor tokens. It then increments the collateral balances, sets the tokens outstanding, updates the total tokens outstanding, and transfers the collateral and mints the tokens. (autogenerated documentation)
repay() :
This function allows a sponsor to repay a portion of their outstanding tokens. It requires that the number of tokens to be repaid is less than or equal to the number of tokens outstanding, and that the new token count is greater than or equal to the minimum sponsor tokens. It then subtracts the number of tokens to be repaid from the total tokens outstanding, and emits a Repay event. Finally, it transfers the tokens to the contract and burns them. (autogenerated documentation)
redeem() :
This function allows a sponsor to redeem a portion of their position in the contract. The function takes in the number of tokens to redeem as an argument and calculates the fraction of the position that is being redeemed. It then calculates the amount of collateral that is being redeemed and adjusts the collateral balances accordingly. If the entire position is being redeemed, the position is deleted. The function then emits an event, transfers the collateral to the sponsor, and burns the tokens. (autogenerated documentation)
settleExpired() :
This function allows a sponsor to settle an expired position. It first checks that the position is expired and then retrieves the expiry price from the oracle. It then calculates the total redeemable collateral by multiplying the tokens to redeem by the expiry price. It then checks if there is any fee-adjusted collateral left in the position and adds it to the total redeemable collateral. It then calculates the payout by taking the minimum of the fee-adjusted collateral and the total redeemable collateral. It then removes the collateral from the position and transfers the tokens and collateral to the sponsor. Finally, it burns the tokens. (autogenerated documentation)
expire() :
This function is used to expire a contract. It can only be called when the contract is in the Open state and after the expiration timestamp has passed. It sets the contract state to ExpiredPriceRequested and then calls the _requestOraclePriceExpiration function to request the price from the oracle. Finally, it emits a ContractExpired event. (autogenerated documentation)
emergencyShutdown() :
This function is used to initiate an emergency shutdown of the contract. It can only be called by the Financial Contracts Admin address, and it sets the contract state to ExpiredPriceRequested. It also updates the expiration timestamp to the current time, and requests an Oracle price expiration. Finally, it emits an EmergencyShutdown event with the sender address, the old expiration timestamp, and the new expiration timestamp. (autogenerated documentation)
remargin() :
This function is an external override that is used to adjust the margin of a contract. It is non-reentrant, meaning that it cannot be called again until the current call has finished executing. It is also limited to being called only before the expiration of the contract. This function does not perform any operations, but simply returns without doing anything. (autogenerated documentation)
getCollateral(address) :
This function gets the collateral associated with a given address (the "sponsor"). It does this by first retrieving the raw collateral associated with the sponsor from the positions mapping, then adjusting the collateral for any fees, and finally adjusting the collateral for any pending regular fees. The adjusted collateral is then returned. (autogenerated documentation)
totalPositionCollateral() :
This function returns the total collateral held in all positions in the contract. It does this by first calculating the raw total position collateral, which is the sum of all the collateral held in each position. It then adjusts this amount for any fees that may have been applied, and finally returns the adjusted amount. (autogenerated documentation)
transformPrice(uint256) :
This function transforms a given price (in FixedPoint.Unsigned memory) based on the requestTime (in uint256). It works by calling the internal _transformPrice() function, which takes the given price and requestTime as parameters and returns the transformed price as a FixedPoint.Unsigned memory. (autogenerated documentation)
transformPriceIdentifier(uint256) :
This function is used to generate a unique identifier for a given price request. It takes a uint256 requestTime as an input and returns a bytes32 identifier. The identifier is generated by hashing the requestTime using the keccak256 algorithm. This ensures that the identifier is unique and cannot be reversed to reveal the original requestTime. (autogenerated documentation)
_reduceSponsorPosition(address) :
This function reduces the position of a sponsor in the system. It takes in the address of the sponsor, the amount of tokens to remove, the amount of collateral to remove, and the amount of withdrawal amount to remove. It then checks if the tokens to remove and the collateral to remove are equal to the tokens outstanding and the collateral in the position data. If so, it deletes the sponsor position. Otherwise, it decrements the collateral balances, sets the new token count, and subtracts the withdrawal amount from the withdrawal request amount. Finally, it subtracts the tokens to remove from the total tokens outstanding. (autogenerated documentation)
_deleteSponsorPosition(address) :
This function is used to delete a sponsor position from the system. It takes in the address of the sponsor as an argument and then retrieves the position data associated with that sponsor. It then subtracts the raw collateral associated with the position from the total raw collateral in the system and subtracts the tokens outstanding associated with the position from the total tokens outstanding in the system. It then deletes the position from the positions mapping and emits an EndedSponsorPosition event. Finally, it returns the difference between the starting global collateral and the fee adjusted collateral after the position has been deleted. (autogenerated documentation)
_pfc() :
This function is used to calculate the adjusted collateral for a given position. It takes the raw total position collateral as an input and returns the adjusted collateral as an output. The adjusted collateral is calculated by subtracting the fee from the raw total position collateral. (autogenerated documentation)
_getPositionData(address) :
This function is an internal view function that retrieves the PositionData storage associated with a given address (sponsor). It does this by accessing the positions mapping, which stores the PositionData associated with each address. The onlyCollateralizedPosition modifier ensures that only positions with collateral are returned. (autogenerated documentation)
_getIdentifierWhitelist() :
This function is an internal view function that returns an instance of the IdentifierWhitelistInterface. It does this by using the finder contract to get the address of the IdentifierWhitelistInterface and then returning an instance of that interface. (autogenerated documentation)
_getOracle() :
This function is an internal view function that returns an OracleInterface. It uses the finder contract to get the address of the Oracle contract and then returns an OracleInterface instance. This allows the contract to interact with the Oracle contract and access its functions. (autogenerated documentation)
_getOptimisticOracle() :
This function is an internal view function that returns an instance of the OptimisticOracleInterface. It does this by using the finder contract to get the address of the OptimisticOracleInterface contract and then returning an instance of that contract. (autogenerated documentation)
_getFinancialContractsAdminAddress() :
This function is used to retrieve the address of the Financial Contracts Admin contract. It does this by using the finder contract to look up the address of the OracleInterfaces.FinancialContractsAdmin interface. The finder contract is used to store the addresses of various contracts and interfaces, allowing them to be easily retrieved. (autogenerated documentation)
_requestOraclePriceExpiration(uint256) :
This function is used to request a price from the Optimistic Oracle for a given requested time. It first computes the reward for the Oracle, then increases the allowance of the Oracle to the reward amount. It then calls the requestPrice function on the Optimistic Oracle, passing in the requested time, ancillary data, the collateral currency, and the reward amount. Finally, it adjusts the cumulative fee multiplier with the reward and the PFC. (autogenerated documentation)
_getOraclePriceExpiration(uint256) :
This function is used to get the Oracle price expiration for a given requested time. It first checks if the OptimisticOracleInterface has a price for the requested time, and if so, it calls the settleAndGetPrice() function to get the Oracle price expiration. If the Oracle price expiration is less than 0, it is set to 0. Finally, the _transformPrice() function is called to transform the Oracle price expiration into a FixedPoint.Unsigned value. (autogenerated documentation)
_requestOraclePriceLiquidation(uint256) :
This function is used to request the price of a liquidation from an oracle. It takes in a requestedTime parameter, which is a uint256 representing the time for which the price should be requested. It then calls the _getOracle() function to get an instance of the OracleInterface, and then calls the requestPrice() function on that instance, passing in the requestedTime parameter transformed using the _transformPriceIdentifier() function. This requestPrice() function will then send a request to the oracle for the price of the liquidation at the requestedTime. (autogenerated documentation)
_getOraclePriceLiquidation(uint256) :
This function is used to get the liquidation price from an oracle. It takes in a requested time as an argument and uses it to get the price from the oracle. It then checks if the price is negative and sets it to 0 if it is. Finally, it transforms the price and returns it. (autogenerated documentation)
_resetWithdrawalRequest() :
This function is used to reset the withdrawal request amount and timestamp associated with a given position in the PositionData storage. It sets the withdrawal request amount to 0 and the withdrawal request pass timestamp to 0. This effectively clears any existing withdrawal request associated with the position. (autogenerated documentation)
_incrementCollateralBalances() :
This function is used to increment the collateral balances of a position and the total position collateral. It takes in two parameters, a PositionData storage reference and a FixedPoint.Unsigned memory collateralAmount. It then calls the _addCollateral function twice, once to add the collateralAmount to the positionData.rawCollateral and once to add the collateralAmount to the rawTotalPositionCollateral. Finally, it returns the new rawTotalPositionCollateral. (autogenerated documentation)
_decrementCollateralBalances() :
This function is used to decrement the collateral balances of a position. It takes in two parameters, a PositionData storage object and a FixedPoint.Unsigned memory collateralAmount. It first calls the _removeCollateral function to decrement the collateral balance of the positionData object, and then calls the _removeCollateral function again to decrement the rawTotalPositionCollateral balance. Finally, it returns the amount of collateral that was removed. (autogenerated documentation)
_decrementCollateralBalancesCheckGCR() :
This function is used to decrement the collateral balances of a position and check that the collateralization ratio (CR) of the position is still above the global collateralization ratio (GCR). It takes in a PositionData storage struct and a collateral amount as parameters. It first removes the collateral amount from the rawCollateral balance of the position. It then checks that the collateralization ratio of the position is still above the global collateralization ratio. Finally, it removes the collateral amount from the rawTotalPositionCollateral balance and returns the new balance. (autogenerated documentation)
_onlyOpenState() :
This function is an internal view function that checks if the contract state is Open. It uses the require() function to check if the contractState is equal to ContractState.Open. If it is not, then an error message is thrown. (autogenerated documentation)
_onlyPreExpiration() :
This function is an internal view function that checks if the current time is before the expiration timestamp. If it is, the function will continue to execute, otherwise it will throw an error. This function is used to ensure that certain operations can only be performed before the expiration timestamp. (autogenerated documentation)
_onlyPostExpiration() :
This function is an internal view function that checks if the current time is greater than the expiration timestamp. If it is, the function will continue to execute, otherwise it will throw an error. This function is used to ensure that the contract can only be called after the expiration timestamp has been reached. (autogenerated documentation)
_onlyCollateralizedPosition(address) :
This function checks if a position held by a given address (sponsor) has any collateral. It does this by calling the _getFeeAdjustedCollateral() function, which adjusts the raw collateral amount for any fees associated with the position. If the adjusted collateral amount is greater than 0, the function returns true, otherwise it returns false. (autogenerated documentation)
_positionHasNoPendingWithdrawal(address) :
This function checks if a given address (sponsor) has a pending withdrawal request. It does this by checking the withdrawalRequestPassTimestamp of the position data associated with the given address. If the timestamp is equal to 0, then there is no pending withdrawal request and the function returns true. Otherwise, the function throws an error. (autogenerated documentation)
_checkPositionCollateralization() :
This function checks the collateralization of a given position. It does this by calculating the fee-adjusted collateral (using the _getFeeAdjustedCollateral function) and comparing it to the amount of tokens outstanding. If the fee-adjusted collateral is greater than or equal to the amount of tokens outstanding, the function returns true, indicating that the position is sufficiently collateralized. (autogenerated documentation)
_checkCollateralization() :
This function checks whether the collateralization ratio of a given position is greater than the global collateralization ratio. It does this by calculating the global collateralization ratio using the _getCollateralizationRatio() function, and then calculating the collateralization ratio of the given position using the same function. It then compares the two values and returns a boolean indicating whether the given position's collateralization ratio is greater than the global collateralization ratio. (autogenerated documentation)
_getCollateralizationRatio() :
This function calculates the collateralization ratio of a given set of collateral and tokens. It does this by dividing the collateral by the number of tokens. If the number of tokens is 0, the ratio is returned as 0. (autogenerated documentation)
_getSyntheticDecimals(address) :
This function is used to get the decimals of a given ERC20 token. It first attempts to call the decimals() function of the token contract, and if successful, it returns the decimals value. If the call fails, it returns a default value of 18. (autogenerated documentation)
_transformPrice(uint256) :
This function is used to transform a given price using the financialProductLibrary contract. It takes in a FixedPoint.Unsigned memory price and a uint256 requestTime as parameters and returns a FixedPoint.Unsigned memory transformedPrice. It first checks if the financialProductLibrary is a contract, and if it is, it calls the transformPrice function of the financialProductLibrary contract, passing in the price and requestTime as parameters. If the call is successful, it returns the transformedPrice, otherwise it returns the original price. (autogenerated documentation)
_transformPriceIdentifier(uint256) :
This function is used to transform the price identifier of a financial product. It takes in a request time as an input and uses the financialProductLibrary contract to transform the price identifier. If the financialProductLibrary contract is not a contract, the original price identifier is returned. If the transformation is successful, the transformed identifier is returned, otherwise the original identifier is returned. (autogenerated documentation)
_getAncillaryData() :
This function is an internal view function that returns the address of the tokenCurrency. It does this by encoding the address of the tokenCurrency using the ABI encoding and then returning the packed data. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i uma-priceless-position-manager
copy icon

Recent Use

🍞 0x8359 saved

Last Publish

11/5/2022

Version

1.0.0

Creator

UMA

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.