Skip to content

feat(financial-templates): adds a new price feed for the DefiPulseTotalTVL synthetic tokens#2346

Merged
nicholaspai merged 7 commits intoUMAprotocol:masterfrom
bryanjcampbell1:master
Feb 19, 2021
Merged

feat(financial-templates): adds a new price feed for the DefiPulseTotalTVL synthetic tokens#2346
nicholaspai merged 7 commits intoUMAprotocol:masterfrom
bryanjcampbell1:master

Conversation

@bryanjcampbell1
Copy link
Copy Markdown
Contributor

@bryanjcampbell1 bryanjcampbell1 commented Dec 23, 2020

Title

feat(financial-templates): adds a new price feed for the DefiPulseTotalTVL synthetic tokens

Motivation

UMIP 24 introduces DefiPulseTotalTVL as a price id. The price feed suggested in this PR would allow for the creation of liquidation and dispute bots for the DefiPulseTotalTVL price id.

Summary

Adds the DefiPulseTotalTVLPriceFeed.js file to the financial-templates repo

Details

This price feed was modified from, and closely follows, the CryptoWatchPriceFeed. The cryptowatch api has been replaced with the DeFi Pulse Data API.

Issue(s)

Fixes the current lack of a price feed for the DefiPulseTotalTVL price id.

Copy link
Copy Markdown
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

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

This looks like a great starting point! I've left some nits on formatting and input validation.

You should try to write some unit tests the same way we have unit tests for the cryptoWatchPriceFeed which you can see here: https://github.com/UMAprotocol/protocol/blob/master/packages/financial-templates-lib/test/price-feed/CryptoWatchPriceFeed.js

Also, to get this feed 100% integrated into this repo we will need an integration made to the CreatePriceFeed file. You can see the similar setup in this file for CryptoWatch here:

This will also contain some input validation using the isMissingField method, specifically for the apiKey.

const { parseFixed } = require("@ethersproject/bignumber");

// An implementation of PriceFeedInterface that uses DefiPulse Data api to retrieve prices.
class DEFI_PULSE_TOTAL_TVL_PriceFeed extends PriceFeedInterface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: while the price feed is indeed called DEFI_PULSE_TOTAL_TVL This class should not be named like this. Ideally, it should be called DefiPulsePriceFeed I believe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using DefiPulseTotalPriceFeed so I can differentiate between it and the SUSHI/UNI TVL price feed in the future


let closestTime = {timestamp:0, value:0};

//go through all values and find time that that is the largest and still less than 'time'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: here (and in other places) it does not seem you've linted your code correctly. We normally have spaces after // in the comments. You should try running the linter with yarn lint-fix to address these formatting issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a config file with a preferred linter settings somewhere in the repo? Im getting Command "lint-fix" not found when running yarn lint-fix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did you install all the packages within the repo by running yarn in the root of the repo? it should work fine once you have done such.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. Thanks

this.logger = logger;
this.web3 = web3;

this.apiKey = apiKey;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you might want to verify that there is indeed an API key added in here. If there is not, then this price feed will error out. This differs from the CryptoWatchPriceFeed as in those feeds the API key is optional whereas here it is a requirement.

You can simply do this with an assert(apiKey, "requires apiKey for Defi Pulse"); after importing const assert = require("assert");

closestTime.value = val;

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

similar nit about formatting. Should be resolved once you run the linter.

`https://data-api.defipulse.com/api/v1/defipulse/api/MarketData?api-key=${this.apiKey}`;

// 2. Send requests.
const [priceResponse] = await Promise.all([
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: no point in using Promise.all synthax here seeing you are only sending out one async call.

Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

This looks awesome! One comment about caching of historical data. It would also be great to see a few tests added to verify the behavior of this class!

Thanks for working on this!


// 1. Construct URLs.
const priceUrl =
`https://data-api.defipulse.com/api/v1/defipulse/api/MarketData?api-key=${this.apiKey}`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any way to get historical data from defi pulse? It seems as if this class is depending on caching historical data over time internally, but generally the bots expect to be able to immediately access historical data up to the lookback. Does DefiPulse offer any API for immediate historical data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a GetHistory endpoint. How should I go about using it? Call it from getCurrentPrice() and store it in state so it can be referenced in getHistoricalPrice(time)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Modifying the CryptoWatchPriceFeed tests now. I looked more into the historical endpoint but the timestamps are a full day apart. I imagine the bots need more precision than this. Also, are there preferred ranges for lookback period and minTimeBetweenUpdates? Defi pulse only updates their api hourly.

@smb2796 smb2796 requested review from chrismaree and mrice32 January 20, 2021 19:12
config.decimals, // This defaults to 18 unless supplied by user
config.ohlcPeriod // This defaults to 60 unless supplied by user
);
} else if (config.type === "uniswap") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why did you remove the existing uniswap feed? you should rather add your feed as another option rather than removing an existing feed that is used in production.


}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this file still needs to be linted

getTime,
minTimeBetweenUpdates
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this file also needs to be linted.


const apiKey = process.env.DEFIPULSE_API_KEY;

const lookback = 3600*24; //???????????????
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's up with this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was a note to myself that I was unclear about an appropriate lookback time. The API only changes at hourly intervals so the bots would run less frequently than others like cryptowatch.

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

I made significant changes to the way the price feed the historical record. I am no longer building it by caching as I was able to get hourly values from the api. I am a little confused about the unit test though. How should I structure the fake data to inject? Also, how do I run the test? I tried calling 'truffle test' in root but just got a '0 passing' result.

@chrismaree
Copy link
Copy Markdown
Member

I made significant changes to the way the price feed the historical record. I am no longer building it by caching as I was able to get hourly values from the api. I am a little confused about the unit test though. How should I structure the fake data to inject? Also, how do I run the test? I tried calling 'truffle test' in root but just got a '0 passing' result.

looks like you got the linter working, which is great!

To run your test file you should navigate to the financial-templates-lib directory then run:

yarn hardhat test ./test/price-feed/DefiPulseTotalPriceFeed.js 

seeing you also changed the create price feed you should also test:

yarn hardhat test ./test/price-feed/createPriceFeed.js 

I'll get your tests to run in CI now as well.

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 25, 2021

Coverage Status

Coverage remained the same at 93.261% when pulling 0d155b0 on bryanjcampbell1:master into 0b08724 on UMAprotocol:master.

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

Got the unit tests working! Do I need to worry about the git signoff errors? Running "git rebase HEAD~11 --signoff" returns "unknown option `signoff'"

Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

Looks awesome -- a few minor comments, but I think this is just about ready!!

}
}

const newPrice = this.web3.utils.toWei((mostRecent.tvlUSD / 1000000000).toFixed(6), "ether");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you provide a comment on what's happening here?

Also, do you think this should be a class function since you do the same operation in the getHistoricalPrice method?

}
}

const historicalPrice = this.web3.utils.toWei((closestTime.tvlUSD / 1000000000).toFixed(6), "ether");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this respect the decimals value that is passed in the constructor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed decimals from the constructor. The UMIP does specify 3 decimals of precision though so I made that change. What I want is that when tvlUSD = 24781234567, the token price to be $24.781 or 24781000000000000000 wei of the collateral token.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Am I understanding the price feed correctly? It should be returning a BN in wei correct?

}
}

const historicalPrice = this.web3.utils.toWei((closestTime.tvlUSD / 1000000000).toFixed(3), "ether");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seeing you do this computation two times (this.web3.utils.toWei((closestTime.tvlUSD / 1000000000).toFixed(3), "ether");) you could consider refactoring this into a helper method within this feed that is called in two places. This way you could add a more detailed comment around the umip definition and help with code re-use.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, you should consider adding this.toWei within the constructor, the same way you pulled out this.toBN on line 31. Then, you wont need to call this.web3.utils.toWei(... and can rather refer to this.toWei

@chrismaree
Copy link
Copy Markdown
Member

Got the unit tests working! Do I need to worry about the git signoff errors? Running "git rebase HEAD~11 --signoff" returns "unknown option `signoff'"

you don't need to worry about the signoff part, we can set this from our side :)

Also looks like you need to lint again! normally we have a husky hook that should lint your code automatically whenever you commit. If you using something other than the console to commit it's possible this is not enabled.

I will re-run your tests through CI as well.

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

What should my next steps be? I have run the cryptowatch bots on google cloud compute but I'm not sure how to configure to use my price feed.

@mrice32
Copy link
Copy Markdown
Member

mrice32 commented Feb 1, 2021

@bryanjcampbell1 sorry that I'm just coming back to this PR. Side note/quick tip: once reviewers send a round of comments and you've responded and would like them to take another look, you can click the cycle button next to their names (see screenshot below) to request them again! This basically adds it back to each of our personal review queues so we see and come back to the PR. See our contributing guidelines for more info on our typical process: https://github.com/UMAprotocol/protocol/blob/master/CONTRIBUTING.md#prs.

I've gone ahead an re-requested myself and @chrismaree. Sorry for the delay!!

Screen Shot 2021-02-01 at 12 52 21 AM

@mrice32 mrice32 requested review from chrismaree and mrice32 February 1, 2021 05:55
@mrice32
Copy link
Copy Markdown
Member

mrice32 commented Feb 1, 2021

@bryanjcampbell1 @chrismaree Actually, you do need to signoff your commits. We need outside contributors to complete the DCO for legal reasons. It's how we show that you really agree to submit your code under the repo license and forgo your individual rights to the code.

// Return early if the last call was too recent.
if (this.lastUpdateTime !== undefined && this.lastUpdateTime + this.minTimeBetweenUpdates > currentTime) {
this.logger.debug({
at: "DEFI_PULSE_TOTAL_TVL_PriceFeed",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: you should make this at the same as the file name. I know this feed was previous all upper case like this but that's no longer the case.

Suggested change
at: "DEFI_PULSE_TOTAL_TVL_PriceFeed",
at: "DefiPulseTotalPriceFeed",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

}

this.logger.debug({
at: "DEFI_PULSE_TOTAL_TVL_PriceFeed",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
at: "DEFI_PULSE_TOTAL_TVL_PriceFeed",
at: "DefiPulseTotalPriceFeed",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -4677,6 +4677,15 @@
"@uma/common" "^1.1.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure why there is a diff here?

config.invertPrice // Not checked in config because this parameter just defaults to false.
config.invertPrice, // Not checked in config because this parameter just defaults to false.
config.poolDecimals,
config.priceFeedDecimals // This defaults to 18 unless supplied by user
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this showing up as a diff? I'm pretty sure this is what the actual UniswapPriceFeed looks like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My guess is that there are some merge issues, where these changes accidentally got removed in the merge process, but then were re-added in this branch to get the tests to pass.

@chrismaree
Copy link
Copy Markdown
Member

This looks really good to me and super close to being done!

note that you still need to add in an additional set of changes in the DefaultPriceFeedConfigs file: https://github.com/UMAprotocol/protocol/blob/master/packages/financial-templates-lib/src/price-feed/DefaultPriceFeedConfigs.js

Also, what is the intended collateral for this synthetic? importantly, if it has non 18 decimals you will also need to add it to packages/common/src/PriceIdentifierUtils.js which can be found here: https://github.com/UMAprotocol/protocol/blob/master/packages/common/src/PriceIdentifierUtils.js

This ensures that the decimals in the price requests returned by the dvm is scalled according to the collateral type defined for the specific synthetic.

let mockTime = 1611583300;
let networker;

const apiKey = process.env.DEFIPULSE_API_KEY;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unit tests should not rely on having this env set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to a test string

@chrismaree
Copy link
Copy Markdown
Member

I just tried to run your tests and they failed as follows:
image

Ideally, the tests should be independent of an API key and solely rely on injected data from networker. An option could be to set it to something within the unit tests so you get past the assert(apiKey, "requires apiKey for Defi Pulse"); and then test with the mocked data from the networker.

@mrice32 mrice32 changed the title Added DEFI_PULSE_TOTAL_TVL price feed feat(financial-templates): adds a new price feed for the DefiPulseTotalTVL synthetic tokens Feb 2, 2021
@mrice32
Copy link
Copy Markdown
Member

mrice32 commented Feb 2, 2021

@bryanjcampbell1 I updated the title to match the title in your description, just FYI!

@mrice32
Copy link
Copy Markdown
Member

mrice32 commented Feb 2, 2021

@bryanjcampbell1 Responding to this comment above (posting here because the comment is way up there and now outdated because you've made some updates :)): #2346 (comment):

  • @chrismaree is a decimals input value required or is it okay for the price feed to always use the same decimals value? I assume the latter?
  • @smb2796 it appears as if UMIP-24 does not specify a collateral decimals value. Should we amend it to add one? @bryanjcampbell1 what collateral are y'all planning to use? (not necessary if you're planning to use a currency with 18 decimals).

Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

Looks awesome!

// In an effort to make the token price affordable, the value of the token is the tvlUSD divided by 1 billion.
// We also cut off precision after 3 decimals to match the specified price step of .001

return this.toWei((_tvlUSD / 1000000000).toFixed(3), "ether");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit for readability:

Suggested change
return this.toWei((_tvlUSD / 1000000000).toFixed(3), "ether");
const billion = 1_000_000_000;
return this.toWei((_tvlUSD / billion).toFixed(3), "ether");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do most synths like this use USDC or TUSD? I had originally thought of using USDC (6 decimals).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any tips for signing off on old commits? Just set up a GPG keypair. Should be good signing off from here on.

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

What should I be using for my 'type' instead of 'medianizer'? I only have one source, the defipulse api, to get my value.

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

Could you recommend a way for me to signoff on my old commits? I tried following this but ended up overwriting signatures from Sean, Matt, ect. Spent at least 2 hours on this lol.

Yep! Note: please back up your branch before you do this: git checkout -b backup_branch. Then switch back to the branch you've been using.

This is what I'd recommend as a simple way around these issues. Note: I'm using upstream/master as your local reference to our master branch. Just swap it out with whatever branch you typically merge into your branch to pull in upstream changes. Note: please make sure that whatever local reference you're using to refer to our master branch (upstream/master in the example below) has already been merged into your branch. If not, you'll get weird changes in the final diff.

  • git reset upstream/master -- this destroys the git history on your branch and makes it match upstream/master, BUT it keeps all your changes as unstaged changes.
  • git add . stages all of the changes at once.
  • git commit -s -m "feat(financial-templates): adds a new price feed for the DefiPulseTotalTVL synthetic tokens" creates a single signed commit on your branch that contains all of your changes.
  • git push -f force overwrites the remote branch on github.

Note: make sure you backup everything in a place where you can retrieve it if something breaks in this process. Since you're wiping your git history on your branch, you could wind up accidentally wiping your changes, so be sure you have a way to start over if things go bad!

Thanks! This was a huge help!

Copy link
Copy Markdown
Member

@mrice32 mrice32 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 great! I left a few suggestions to make price feed decimals match how it works in the other price feeds. Please take a look. I haven't tested the suggestions, but I think they should work. You'll probably need to re-lint the repo, though, because they probably aren't formatted correctly. You can do this by committing the suggestions, running git pull, then running yarn lint-fix from the root of the repo, and then committing and pushing any changes.

networker,
getTime,
minTimeBetweenUpdates,
6 // Add arbitrary decimal conversion and prove this works.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
6 // Add arbitrary decimal conversion and prove this works.
decimals // Add arbitrary decimal conversion and prove this works.

Comment on lines +66 to +69
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611575900)).toString(), web3.utils.toWei("24.78"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), web3.utils.toWei("23.50"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), web3.utils.toWei("23.50"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579601)).toString(), web3.utils.toWei("22.25"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the decimals are specified as 6, shouldn't these be coming out as 24.78 * 10^6? Right now, it looks like they're coming out as 24.78 * 10^18. See my comment above for how to make the price feed to do what you expect here.

Suggested change
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611575900)).toString(), web3.utils.toWei("24.78"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), web3.utils.toWei("23.50"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), web3.utils.toWei("23.50"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579601)).toString(), web3.utils.toWei("22.25"));
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611575900)).toString(), parseFixed("24.78", decimals).toString());
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), parseFixed("23.50", decimals).toString());
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579500)).toString(), parseFixed("23.50", decimals).toString());
assert.equal((await defiPulseTotalPriceFeed.getHistoricalPrice(1611579601)).toString(), parseFixed("22.25", decimals).toString());

await defiPulseTotalPriceFeed.update();

// Should return the current price in the data.
assert.equal(defiPulseTotalPriceFeed.getCurrentPrice().toString(), web3.utils.toWei("25.1"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
assert.equal(defiPulseTotalPriceFeed.getCurrentPrice().toString(), web3.utils.toWei("25.1"));
assert.equal(defiPulseTotalPriceFeed.getCurrentPrice().toString(), parseFixed("25.1", decimals).toString());

@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

Accepted changes and ran through linter!

Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

I made a few small commits because I didn't realize you had manually made some of the changes I suggested -- then I had to undo them haha. But I think it looks good now!

LGTM assuming @chrismaree approves as well!

Copy link
Copy Markdown
Member

@chrismaree chrismaree 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 so close to being ready. I have 2 nits and questions on some small spots.

Also, please add a test to validate non-18 decimals works as expected. Once this is done I think you good to go!

networker,
getTime,
config.minTimeBetweenUpdates,
config.decimals
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: for consistency please keep this as

Suggested change
config.decimals
config.priceFeedDecimals

assert.equal(defiPulseTotalPriceFeed.getLastUpdateTime(), undefined);
});

it("Basic historical price", async function() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ye, please add a test for this :)

…alTVL synthetic tokens

Signed-off-by: bryanjcampbell1 <bryanjcampbell1@gmail.com>
@bryanjcampbell1
Copy link
Copy Markdown
Contributor Author

@chrismaree Matt helped me modify the test for "Basic historical price" so that it would work for arbitrary decimals. Please let me know if you are looking for something else!

Signed-off-by: bryanjcampbell1 <bryanjcampbell1@gmail.com>
Copy link
Copy Markdown
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

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

Thanks for replying to all the changes and updating your PR accordingly! this is pretty awesome, I'm looking forward to seeing this on main net 🚀

@chrismaree
Copy link
Copy Markdown
Member

I'm running your test in CI again.

} else if (config.type === "defipulsetvl") {
const requiredFields = ["lookback", "minTimeBetweenUpdates"];

if (isMissingField(config, config.apiKey, requiredFields, logger)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't you add the apiKey to requiredFields?


async getHistoricalPrice(time) {
if (this.lastUpdateTime === undefined) {
throw new Error(`${this.uuid}: undefined lastUpdateTime`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see that you've defined this.uuid in the constructor

this.web3 = web3;

this.apiKey = apiKey;
assert(apiKey, "requires apiKey for Defi Pulse");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of asserting it here, I recommend adding apiKey to the requiredFields array in CreatePriceFeed

Copy link
Copy Markdown
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

I left some comments that once resolved are good to merge

Signed-off-by: bryanjcampbell1 <bryanjcampbell1@gmail.com>
Merge branch 'master' of https://github.com/bryanjcampbell1/protocol into bryanjcampbell1/master

async getHistoricalPrice(time) {
if (this.lastUpdateTime === undefined) {
throw new Error("undefined lastUpdateTime");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you follow this this.uuid pattern and add a uuid class param that makes the Error slightly more descriptive please? Sorry and thanks!

@daywiss
Copy link
Copy Markdown
Contributor

daywiss commented Feb 17, 2021

@bryanjcampbell1 looks like there is just one outstanding issue and this can go in!

nicholaspai and others added 2 commits February 18, 2021 16:25
Signed-off-by: Nick Pai <npai.nyc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants