コード例 #1
0
def _settle_u(_currency: address, _expiry: timestamp, _underlying: address,
              _strike_price: uint256, _currency_quantity: uint256,
              _from: address, _to: address):
    # validate currency
    assert CurrencyDao(self.daos[DAO_CURRENCY]).is_token_supported(_currency)
    # validate underlying
    assert CurrencyDao(self.daos[DAO_CURRENCY]).is_token_supported(_underlying)
    _loan_market_hash: bytes32 = self._loan_market_hash(
        _currency, _expiry, _underlying)
    assert MarketDao(self.daos[DAO_MARKET]).loan_markets__status(
        _loan_market_hash) == MarketDao(
            self.daos[DAO_MARKET]).LOAN_MARKET_STATUS_CLOSED()
    _shield_market_hash: bytes32 = self._shield_market_hash(
        _currency, _expiry, _underlying, _strike_price)
    assert self.registered_shield_markets[_shield_market_hash]
    _l_address: address = ZERO_ADDRESS
    _i_address: address = ZERO_ADDRESS
    _f_address: address = ZERO_ADDRESS
    _s_address: address = ZERO_ADDRESS
    _u_address: address = ZERO_ADDRESS
    _l_address, _i_address, _f_address, _s_address, _u_address = CurrencyDao(
        self.daos[DAO_CURRENCY]).mft_addresses(_currency)
    # mint _payout in l_currency
    _payout: uint256 = self._u_payoff(_currency, _expiry, _underlying,
                                      _strike_price)
    assert as_unitless_number(_payout) > 0
    # burn u_token from _from account
    assert_modifiable(
        MultiFungibleToken(
            MarketDao(self.daos[DAO_MARKET]).shield_markets__u_address(
                _shield_market_hash)).burn(
                    MarketDao(self.daos[DAO_MARKET]).shield_markets__u_id(
                        _shield_market_hash), _from,
                    as_unitless_number(_currency_quantity) * (10**18)))
    # mint l_token to _to account
    assert_modifiable(
        CurrencyDao(self.daos[DAO_CURRENCY]).mint_and_self_authorize_erc20(
            _l_address, _to,
            as_unitless_number(_payout) *
            as_unitless_number(_currency_quantity)))
コード例 #2
0
def avail_loan(
    _currency_address: address, _expiry: timestamp, _underlying_address: address, _strike_price: uint256,
    _currency_value: uint256
    ) -> bool:
    assert self.initialized
    assert not self.paused
    assert block.timestamp < _expiry
    # create position
    self._open_position(msg.sender, _currency_value,
        _currency_address, _expiry, _underlying_address, _strike_price)
    assert_modifiable(MarketDao(self.daos[DAO_MARKET]).open_position(
        msg.sender, _currency_value,
        _currency_address, _expiry, _underlying_address, _strike_price
    ))

    return True
コード例 #3
0
def close_liquidated_loan(_position_id: uint256) -> bool:
    assert self.initialized
    assert not self.paused
    assert block.timestamp > self.positions[_position_id].expiry
    self._lock_position(_position_id)
    # validate position currencies
    _currency_value_remaining: uint256 = as_unitless_number(self.positions[_position_id].currency_value) - as_unitless_number(self.positions[_position_id].repaid_value)
    assert_modifiable(MarketDao(self.daos[DAO_MARKET]).close_liquidated_position(
        self.positions[_position_id].borrower,
        _currency_value_remaining,
        self.positions[_position_id].currency,
        self.positions[_position_id].expiry,
        self.positions[_position_id].underlying,
        self.positions[_position_id].strike_price
    ))
    # liquidate position
    self._liquidate_position(_position_id)
    self._lock_position(_position_id)

    return True
コード例 #4
0
def repay_loan(_position_id: uint256, _pay_value: uint256) -> bool:
    assert self.initialized
    assert not self.paused
    assert block.timestamp < self.positions[_position_id].expiry
    # validate borrower
    assert self.positions[_position_id].borrower == msg.sender
    assert as_unitless_number(self.positions[_position_id].repaid_value) + as_unitless_number(_pay_value) <= as_unitless_number(self.positions[_position_id].currency_value)
    self._lock_position(_position_id)
    # validate position currencies
    assert_modifiable(MarketDao(self.daos[DAO_MARKET]).close_position(
        self.positions[_position_id].borrower,
        _pay_value,
        self.positions[_position_id].currency,
        self.positions[_position_id].expiry,
        self.positions[_position_id].underlying,
        self.positions[_position_id].strike_price
    ))
    # close position
    self._partial_or_complete_close_position(_position_id, _pay_value)
    self._unlock_position(_position_id)

    return True
コード例 #5
0
def _u_payoff(_currency: address, _expiry: timestamp, _underlying: address,
              _strike_price: uint256) -> uint256:
    return MarketDao(self.daos[DAO_MARKET]).u_payoff(_currency, _expiry,
                                                     _underlying,
                                                     _strike_price)