create(uint256) :
This function creates a new pair of tokens (long and short) for the sender. It takes in a parameter of the number of tokens to create, and calculates the amount of collateral needed to create the tokens. It then transfers the collateral from the sender to the contract, and mints the new tokens for the sender. Finally, it emits an event to signal that the tokens have been created. (autogenerated documentation)
redeem(uint256) :
This function allows users to redeem their tokens for collateral. It takes in a parameter of the amount of tokens to redeem and returns the amount of collateral that is returned. It first burns the same amount of tokens from both the long and short token contracts. It then calculates the amount of collateral to return by multiplying the amount of tokens to redeem by the collateral per pair. Finally, it transfers the collateral to the user and emits an event to log the redemption. (autogenerated documentation)
settle(uint256,uint256) :
This function allows a user to settle their position in a Synthetix contract. It requires two parameters, longTokensToRedeem and shortTokensToRedeem, which represent the amount of long and short tokens the user wishes to redeem. The function then checks if the current time is before the expiration timestamp, or if the expiration timestamp has passed. If the expiration timestamp has passed, the function calls the getExpirationPrice() function to get the settlement price. The function then burns the long and short tokens from the user's account and calculates the amount of collateral to be returned to the user. Finally, the function transfers the collateral to the user and emits a PositionSettled event. (autogenerated documentation)
requestEarlyExpiration(uint64) :
This function allows a user to request an early expiration of a contract. It requires that early expiration is enabled, that the proposed expiration timestamp is in the past, and that it is not 0. It then sets the earlyExpirationTimestamp to the proposed timestamp and requests an oracle price with the earlyExpirationAncillaryData. Finally, it emits an event to signal that the early expiration has been requested. (autogenerated documentation)
expire() :
This function is used to expire a contract. It is triggered when the expiration timestamp is reached. It calls the _requestOraclePrice() function to request the oracle price at the expiration timestamp, and then emits a ContractExpired event. (autogenerated documentation)
getPositionTokens(address) :
This function allows a user to view the amount of long and short tokens held by a given address (sponsor). It does this by calling the balanceOf() function on the longToken and shortToken contracts, passing in the sponsor address as an argument. The function then returns the amount of long and short tokens held by the sponsor address as two separate uint256 values. (autogenerated documentation)
getEarlyExpirationAncillaryData() :
This function is used to get the ancillary data associated with an early expiration. It appends a key-value pair to the custom ancillary data, with the key being "earlyExpiration" and the value being 1. This allows the contract to track whether or not the expiration is early. (autogenerated documentation)
ignoreEarlyExpirationPrice() :
This function returns the minimum possible integer value, which is used to indicate that the price of an asset has expired early. This is done by using the type() function to return the minimum possible integer value. (autogenerated documentation)
isContractEarlyExpired() :
This function checks if a contract has expired early. It does this by comparing the oracle price at the early expiration timestamp with the ignoreEarlyExpirationPrice(). If the two values are not equal, then the contract has expired early and the function returns true. (autogenerated documentation)
_getOraclePrice(uint64) :
This function is used to get the price of an asset from an oracle. It takes two parameters, a request timestamp and an ancillary data, and returns an int256 value representing the price. It does this by calling the _getOptimisticOracle() function, which returns an instance of the OptimisticOracle contract, and then calling the settleAndGetPrice() function on that instance, passing in the price identifier, the request timestamp, and the ancillary data. The settleAndGetPrice() function then returns the price of the asset as an int256 value. (autogenerated documentation)
_requestOraclePrice(uint64) :
This function is used to request a price from the Optimistic Oracle V2 Interface. It first transfers the proposer reward to the contract, and then approves the Optimistic Oracle V2 Interface to use the reward. It then calls the requestPrice function on the Optimistic Oracle V2 Interface, passing in the price identifier, the request timestamp, the request ancillary data, the collateral token, and the proposer reward. Finally, it sets the custom liveness time and the proposer bond on the Optimistic Oracle V2 Interface. (autogenerated documentation)
getExpirationPrice() :
This function is used to get the expiration price of a financial product. It first checks if the oracle has a price for the product at the expiration timestamp, and if so, it retrieves the price from the oracle. If not, it retrieves the price from the oracle at the early expiration timestamp, and checks that the price is not equal to the ignoreEarlyExpirationPrice. Finally, it calculates the expiryPercentLong and sets the receivedSettlementPrice to true. (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 it. (autogenerated documentation)
_getCollateralWhitelist() :
This function is an internal view function that returns an AddressWhitelistInterface object. It does this by using the finder contract to get the address of the CollateralWhitelist contract, which implements the AddressWhitelistInterface interface. This allows the function to access the methods and properties of the CollateralWhitelist contract. (autogenerated documentation)
_getOptimisticOracle() :
This function is an internal view function that returns an instance of the OptimisticOracleV2Interface. It does this by using the finder contract to get the address of the OptimisticOracleV2Interface and then returning an instance of it. (autogenerated documentation)