Skip to main content

LongShortPair

LongShortPair#

Uses a combination of long and short tokens to tokenize the bounded price exposure to a given identifier.

Functions#

constructor(struct LongShortPair.ConstructorParams params) (public)

Construct the LongShortPair

Parameters:#

  • params: Constructor params used to initialize the LSP. Key-valued object with the following structure:
    • pairName: Name of the long short pair contract.
    • expirationTimestamp: Unix timestamp of when the contract will expire.
    • collateralPerPair: How many units of collateral are required to mint one pair of synthetic tokens.
    • priceIdentifier: Price identifier, registered in the DVM for the long short pair.
    • longToken: Token used as long in the LSP. Mint and burn rights needed by this contract.
    • shortToken: Token used as short in the LSP. Mint and burn rights needed by this contract.
    • collateralToken: Collateral token used to back LSP synthetics.
    • financialProductLibrary: Contract providing settlement payout logic.
    • customAncillaryData: Custom ancillary data to be passed along with the price request to the OO.
    • prepaidProposerReward: Preloaded reward to incentivize settlement price proposals.
    • optimisticOracleLivenessTime: OO liveness time for price requests.
    • optimisticOracleProposerBond: OO proposer bond for price requests.
    • finder: DVM finder to find other UMA ecosystem contracts.
    • timerAddress: Timer used to synchronize contract time in testing. Set to 0x000... in production.
create(uint256 tokensToCreate) โ†’ uint256 collateralUsed (public)

Creates a pair of long and short tokens equal in number to tokensToCreate. Pulls the required collateral amount into this contract, defined by the collateralPerPair value.

The caller must approve this contract to transfer tokensToCreate * collateralPerPair amount of collateral.

Parameters:#

  • tokensToCreate: number of long and short synthetic tokens to create.
redeem(uint256 tokensToRedeem) โ†’ uint256 collateralReturned (public)

Redeems a pair of long and short tokens equal in number to tokensToRedeem. Returns the commensurate amount of collateral to the caller for the pair of tokens, defined by the collateralPerPair value.

This contract must have the Burner role for the longToken and shortToken in order to call burnFrom. The caller does not need to approve this contract to transfer any amount of tokensToRedeem since long and short tokens are burned, rather than transferred, from the caller.

Parameters:#

  • tokensToRedeem: number of long and short synthetic tokens to redeem.
settle(uint256 longTokensToRedeem, uint256 shortTokensToRedeem) โ†’ uint256 collateralReturned (public)

Settle long and/or short tokens in for collateral at a rate informed by the contract settlement.

Uses financialProductLibrary to compute the redemption rate between long and short tokens. This contract must have the Burner role for the longToken and shortToken in order to call burnFrom. The caller does not need to approve this contract to transfer any amount of tokensToRedeem since long and short tokens are burned, rather than transferred, from the caller.

Parameters:#

  • longTokensToRedeem: number of long tokens to settle.
  • shortTokensToRedeem: number of short tokens to settle.
expire() (public)
getPositionTokens(address sponsor) โ†’ uint256, uint256 (public)

Returns the number of long and short tokens a sponsor wallet holds.

Parameters:#

  • sponsor: address of the sponsor to query.
_getOraclePriceExpiration(uint256 requestedTime) โ†’ int256 (internal)
_requestOraclePriceExpiration() (internal)
_getIdentifierWhitelist() โ†’ contract IdentifierWhitelistInterface (internal)
_getCollateralWhitelist() โ†’ contract AddressWhitelistInterface (internal)
_getOptimisticOracle() โ†’ contract OptimisticOracleInterface (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.

Events#

TokensCreated(address sponsor, uint256 collateralUsed, uint256 tokensMinted)
TokensRedeemed(address sponsor, uint256 collateralReturned, uint256 tokensRedeemed)
ContractExpired(address caller)
PositionSettled(address sponsor, uint256 collateralReturned, uint256 longTokens, uint256 shortTokens)

Modifiers#

preExpiration()
postExpiration()
onlyOpenState()
nonReentrant()

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 making it call a private function that does the actual state modification.

nonReentrantView()

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

onlyIfTest()

Reverts if not running in test mode.