-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
There was a problem hiding this 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.
E(terms.priceAuthority) | ||
.priceAtTime( | ||
terms.timer, | ||
terms.expiration, | ||
terms.underlyingAmount, | ||
strikeBrand, | ||
) | ||
.then(quoteIssuer.getAmountOf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, | |
)) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this 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 }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup.
E(terms.priceAuthority) | ||
.priceAtTime( | ||
terms.timer, | ||
terms.expiration, | ||
terms.underlyingAmount, | ||
strikeBrand, | ||
) | ||
.then(quoteIssuer.getAmountOf) |
There was a problem hiding this comment.
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
?
E(terms.priceAuthority) | ||
.priceAtTime( | ||
terms.timer, | ||
terms.expiration, | ||
terms.underlyingAmount, | ||
strikeBrand, | ||
) | ||
.then(quoteIssuer.getAmountOf) |
There was a problem hiding this comment.
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
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, | ||
}, | ||
]), | ||
), | ||
); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I'm going to merge this into the base PR and address comments once rather than try to keep 2 PRs synced. |
sounds good! |
There was a problem hiding this 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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup.
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, | ||
}, | ||
]), | ||
), | ||
); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not any more.
* 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
No description provided.