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

Adopt dapp-oracle contracts into Zoe #1952

Merged
merged 9 commits into from
Nov 5, 2020
Merged

Conversation

michaelfig
Copy link
Member

@michaelfig michaelfig commented Oct 31, 2020

Closes #1944, Enables Agoric/dapp-oracle#11

This is a large chunk to swallow, but I'm happy to say it only required minor tweaks from what was in dapp-oracle to land it in Zoe with tests passing.

I'm mostly interested in getting a starting point, from which we can improve. Please review in as much detail as you'd like.

@michaelfig michaelfig added the Zoe package: Zoe label Oct 31, 2020
@michaelfig michaelfig self-assigned this Oct 31, 2020
@michaelfig michaelfig added this to the Chainlink Hackathon milestone Oct 31, 2020
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.

This is a review of oracle.js and test-oracle.js only. I will make a PR with the changes that I suggest - feel free to take from it as you wish.

Edit: PR for oracle.js here: #1953

packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/oracle.js Outdated Show resolved Hide resolved
@michaelfig
Copy link
Member Author

R4R.

Copy link
Contributor

@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.

I'm not sure I get all of this yet, but I'm catching on. Maybe the next time through I'll get the gestalt. Here are some questions and suggestions.

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 couldn't do as deep of a dive as I would have liked due to time constraints, but I think we should make the interface between the priceAuthority and the priceAggregator simpler so there are fewer back and forth calls. Also, the baseValueOut and baseValueIn I found confusing. I think we have to explain them a lot more, or use more familiar terms, like units.

Comment on lines +172 to +175
return createQuote(calcAmountOut => ({
amountIn,
amountOut: calcAmountOut(amountIn),
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems pretty complex for getting a quote amount and then minting a payment. Is there a reason not to take in a mint as one of the opts and do the minting within the priceAggregator? I understand we need to actually calculate the quoted amount, but can we make the API for that easier?

packages/zoe/src/contracts/priceAggregator.js Outdated Show resolved Hide resolved
packages/zoe/src/contracts/priceAggregator.js Outdated Show resolved Hide resolved
};

// Calculate the quote.
const quote = priceQuery(calcAmountOut, calcAmountIn);
Copy link
Contributor

Choose a reason for hiding this comment

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

The way in which the priceAuthority calls the priceAggregator which calls the priceAuthority (createQuote -> priceQuery -> calcAmountOut/calcAmountIn ) seems convoluted to me. Can we take in the mint and a function for getting the quoted amount as an argument in the price authority and move the code for producing a quote, given a mint, into some shared library?

packages/zoe/src/contracts/priceAggregator.js Show resolved Hide resolved
*
* @param {PriceQuoteValue} quote
*/
const authenticateQuote = async quote => {
Copy link
Contributor

Choose a reason for hiding this comment

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

When I think of authenticate I think of verifying something that someone has already made (minted). This is the minting. I think we should just call this mintQuote where a quote is made up of a quoteAmount and quotePayment

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 this should be in the priceAuthority code or be a shared library.

Comment on lines +190 to +192
await priceAuthorityAdmin.fireTriggers(
makeCreateQuote({ overrideValueOut: median, timestamp }),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this call.

};

// Authenticate the quote by minting it with our quote issuer, then publish.
const authenticatedQuote = await authenticateQuote([quote]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, we could potentially pass a promise for a quote. Why do we need to await?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the getPriceNotifier is lossy. We can fix that by deprecating it and introducing a new getQuoteNotifier, using @erights new lossy/lossless hybrid (such as was implemented for map-unum.js).

Copy link
Member

Choose a reason for hiding this comment

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

Cool!


pushResult(result);
await updateQuote(
[...oracleRecords].map(({ lastSample }) => lastSample),
Copy link
Contributor

Choose a reason for hiding this comment

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

huh, is this a "rolling median" where any time we get a response back from an oracle, we recalculate? That seems strange to me, but I don't know if I can see a downside directly. Would the alternative (waiting for responses from all the oracles) mean that one oracle could cause a liveness problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to explain this more.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It is hoped that people will replace this rolling median with more sophisticated ways of collation.

We should further distinguish the rolling median from the underlying sample collector. Adding an oracle to the collector should be able to provide a normalize method that knows how to interpret just that oracle's results (default to the parseInt normaliser that we currently have).

@michaelfig michaelfig merged commit 22253df into master Nov 5, 2020
@michaelfig michaelfig deleted the mfig/adopt-oracle-contracts branch November 5, 2020 19:43
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.

Move oracle and priceAggregator contracts into packages/zoe/src/contracts/
4 participants