Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integrate call spread contract with Oracle API. #1928

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

Chris-Hibbert
Copy link
Contributor

No description provided.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need some more API updates. I'm not sure.

Comment on lines +147 to +154
E(terms.priceAuthority)
.priceAtTime(
terms.timer,
terms.expiration,
terms.underlyingAmount,
strikeBrand,
)
.then(quoteIssuer.getAmountOf)
Copy link
Member

@michaelfig michaelfig Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
E(terms.priceAuthority)
.priceAtTime(
terms.timer,
terms.expiration,
terms.underlyingAmount,
strikeBrand,
)
.then(quoteIssuer.getAmountOf)
E(quoteIssuer).getAmountOf(E(terms.priceAuthority)
.priceAtTime(
terms.timer,
terms.expiration,
terms.underlyingAmount,
strikeBrand,
))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the quoteAmount part of the { quoteAmount, quotePayment } that we discussed this morning so we don't have to do getAmountOf?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also then we don't need to know about quoteIssuer so we can drop that

Copy link
Contributor

@katelynsills katelynsills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove the quoteIssuer and rely on the quoteAmount only in this contract.

maths: { Collateral: collateralMath, Strike: strikeMath },
maths: { Collateral: collateralMath, Strike: strikeMath, Quote: quoteMath },
brands: { Strike: strikeBrand },
issuers: { Quote: quoteIssuer },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this contract need to use the quoteIssuer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not any more.

function payoffOptions(price) {
// either offer might be exercised late, so we pay the two seats separately.
function payoffOptions(priceQuoteAmount) {
const { Price: price } = quoteMath.getValue(priceQuoteAmount)[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think price is already lower case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup.

Comment on lines +147 to +154
E(terms.priceAuthority)
.priceAtTime(
terms.timer,
terms.expiration,
terms.underlyingAmount,
strikeBrand,
)
.then(quoteIssuer.getAmountOf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the quoteAmount part of the { quoteAmount, quotePayment } that we discussed this morning so we don't have to do getAmountOf?

Comment on lines +147 to +154
E(terms.priceAuthority)
.priceAtTime(
terms.timer,
terms.expiration,
terms.underlyingAmount,
strikeBrand,
)
.then(quoteIssuer.getAmountOf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also then we don't need to know about quoteIssuer so we can drop that

Comment on lines +42 to +63
function getRecentPrice(timer, desiredPriceBrand, underlyingAmount) {
const underlyingValue = underlyingAmountMath.getValue(underlyingAmount);
return E(timer)
.getCurrentTimestamp()
.then(now => {
const price = priceFromSchedule(now);
const strikePrice = strikeAmountMath.make(price * underlyingValue);
return quoteMint.mintPayment(
quote.make(
harden([
{
Asset: underlyingAmount,
Price: strikePrice,
timer,
timestamp: now,
},
]),
),
);
});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why define getRecentPrice when you only need priceAtTime to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the helper function.

@Chris-Hibbert
Copy link
Contributor Author

I'm going to merge this into the base PR and address comments once rather than try to keep 2 PRs synced.

@Chris-Hibbert Chris-Hibbert merged commit a0dd761 into 1829-callSpread Oct 28, 2020
@Chris-Hibbert Chris-Hibbert deleted the oracleIntegration branch October 28, 2020 16:50
@katelynsills
Copy link
Contributor

I'm going to merge this into the base PR and address comments once rather than try to keep 2 PRs synced.

sounds good!

Copy link
Contributor Author

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes made in base PR after merge. Thanks for the suggestions.

function payoffOptions(price) {
// either offer might be exercised late, so we pay the two seats separately.
function payoffOptions(priceQuoteAmount) {
const { Price: price } = quoteMath.getValue(priceQuoteAmount)[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup.

Comment on lines +42 to +63
function getRecentPrice(timer, desiredPriceBrand, underlyingAmount) {
const underlyingValue = underlyingAmountMath.getValue(underlyingAmount);
return E(timer)
.getCurrentTimestamp()
.then(now => {
const price = priceFromSchedule(now);
const strikePrice = strikeAmountMath.make(price * underlyingValue);
return quoteMint.mintPayment(
quote.make(
harden([
{
Asset: underlyingAmount,
Price: strikePrice,
timer,
timestamp: now,
},
]),
),
);
});
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the helper function.

maths: { Collateral: collateralMath, Strike: strikeMath },
maths: { Collateral: collateralMath, Strike: strikeMath, Quote: quoteMath },
brands: { Strike: strikeBrand },
issuers: { Quote: quoteIssuer },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not any more.

Chris-Hibbert added a commit that referenced this pull request Oct 29, 2020
* feat: a call spread option contract and tests.

Implementation of a fully collateralized call spread option, following Joe
Clark's description. This is a combination of a bought call option and a sold
call option at a higher strike price. The contracts are sold in pairs, and the
buyers of the two positions together invest the entire amount that will be
paid out.

This option is settled financially. Neither party is expected to have
ownership of the underlying asset at the start, and neither expects to take
delivery at closing.

zoe.startInstance() takes an issuerKeywordRecord that specifies the issuers
for the keywords Underlying, Strike, and Collateral. The payout uses
Collateral. The price oracle quotes the value of the Underlying in the same
units as the Strike prices.

creatorFacet has a method makeInvitationPair(), that takes terms
that specifies { expiration, underlyingAmount, priceAuthority, strikePrice1,
strikePrice2, settlementAmount, buyPercent }.
ownerFacet.makeInvitationPair() returns two invitations, which can be sold
separately. They settle when the priceAuthority announces the settlement amout
as of it's pre-programmed closing time.

closes: #1829

* fix: integrate call spread contract with Oracle API. (#1928)

* chore: cleanups from review

This includes changes from the base PR and the separate PR for the
updates to the oracle API.

* chore: more review clean-ups

extract calculation for testing purposes.
save the invitationIssuer as an issuer in the contract
exit contract when done.
use trade() rathern than reallocate()
some renaming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Zoe package: Zoe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants