Skip to content
This repository has been archived by the owner on Apr 20, 2022. It is now read-only.

Read streaming fees from on-chain via set.js #380

Merged
merged 15 commits into from
Sep 21, 2021

Conversation

rootulp
Copy link
Contributor

@rootulp rootulp commented Sep 13, 2021

Description

Previously all streaming fees were hard-coded in productTokens.ts example. This change reads streaming fees for all products from on-chain. This helps us future-proof in-case streaming fees for existing products are modified. This also sets up infrastructure to read other data from set.js which will be helpful for future PRs.

Motivation

Google doc

Smoke test for reviewers

  1. Pull this PR locally
  2. yarn start
  3. Connect Metamask wallet
  4. Observe streaming fees for all products are the same as before this change

`yarn start` works now. Had to build set.js locally with
SetProtocol PR 76. So this PR will be blocked on upgrading to a release
of set.js with that change.
- Add ethers as a dep
- Need `resolutions` block to resolve error
Prettier should really handle this for us
@rootulp

This comment has been minimized.

@0xModene 0xModene self-requested a review September 13, 2021 19:30
Copy link
Contributor

@controtie controtie 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 the super details comments as usual! :D

I think we definitely want to read the quantities on chain here.

  1. Set eventually wants to deprecate its APIs and go pretty decentralized
  2. Set runs a scraper bot in the background to update it's DB with set positions. If we're doing something like issuance/redemption we need to be pretty sure the position's we're reading are accurate.

I added a comment re: fetching streaming fee quantities on-chain. This info probably isn't included in the docs. Sorry about that!

src/contexts/Set/getSetDetails.ts Outdated Show resolved Hide resolved
@rootulp

This comment has been minimized.

@rootulp rootulp changed the title Read DPI component quantities from on-chain via set.js Read DPI and MVI streaming fee from on-chain via set.js Sep 16, 2021
I had to update the contract addresses in .env and .env.prod to get this
to work
"@ethersproject/bignumber": "5.4.1",
"@ethersproject/hdnode": "5.4.0",
"@ethersproject/transactions": "5.4.0",
"@ethersproject/providers": "5.4.5"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these resolutions were necessary to resolve a build error. It's possible these can be removed after upgrading existing dependencies.

@@ -9,7 +9,7 @@ export interface ProductToken {
image: string
coingeckoId: string
tokensetsId: string
fees: any | undefined
fees: { streamingFee: string } | undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Proposal for a refactor that is out of scope for this PR:
Modify IndexToken to not be of type ProductToken but instead pick a subset of props (all props excluding fees) b/c all other product tokens have fees. Then we can make this field:

  fees: { streamingFee: string }

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this idea. There are some other small bits with how it's currently set up I would also like to change. We may need to discuss this soon.

@rootulp rootulp marked this pull request as ready for review September 17, 2021 02:08
@rootulp rootulp changed the title Read DPI and MVI streaming fee from on-chain via set.js Read streaming fees from on-chain via set.js Sep 17, 2021
Copy link
Contributor

@0xModene 0xModene left a comment

Choose a reason for hiding this comment

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

only small nits: in many of the files you're importing you're importing '../../constants~' but you don't have to. Can you double check all your files and change anything with a leading ../ to just 'constants' or 'utils' etc?

this looks great otherwise, looking forward to getting this in

src/contexts/StreamingFee/StreamingFeeContext.ts Outdated Show resolved Hide resolved
src/hooks/useStreamingFee.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@0xModene 0xModene left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@controtie controtie left a comment

Choose a reason for hiding this comment

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

My apologies for taking so long to review these changes. I notice the PR changed from reading token allocations of products on-chain to reading streaming fees on-chain. Is this meant to be a small bite on the way to reading token allocations on-chain?

PR looks mostly good besides the minor import clean up!

import useWallet from "../../hooks/useWallet"
import { bedTokenAddress, btc2xfliTokenAddress, dpiTokenAddress, eth2xfliTokenAddress, mviTokenAddress } from "constants/ethContractAddresses"
import { convertToPercentage } from "../../utils/ethersBigNumber"
import StreamingFeeContext from "./StreamingFeeContext"
Copy link
Contributor

Choose a reason for hiding this comment

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

Per Modene's comment cleaning up these imports to be absolute + ordering (external packages at the top of the file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do. With regards to ordering, if we're going to to enforce this manually (i.e. without the help of a linter) then I propose we draft a style guide and link it from the README of this package. I can take a first stab at this with this rule if we feel strongly about it.

On the other hand, I like projects where lint --fix automatically formats the code according to all team style guide code conventions. Prettier / ESLint are a solid step towards this. With regards to import ordering, we could enforce something like https://eslint.org/docs/rules/sort-imports

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm all for an auto linter/prettifier!

src/views/MVI/MVI.tsx Outdated Show resolved Hide resolved
@rootulp
Copy link
Contributor Author

rootulp commented Sep 21, 2021

Is this meant to be a small bite on the way to reading token allocations on-chain?

Yep

Copy link
Contributor

@controtie controtie left a comment

Choose a reason for hiding this comment

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

Looks good!
Noting that we should make a PR to display mint/redeem fees on BTC/ETH2x-FLI in the future. Not sure those are exposed by set.js atm though.

@controtie controtie merged commit 206b79e into IndexCoop:master Sep 21, 2021
@rootulp
Copy link
Contributor Author

rootulp commented Sep 21, 2021

Noting that we should make a PR to display mint/redeem fees on BTC/ETH2x-FLI in the future. Not sure those are exposed by set.js atm though.

Added to google doc

@rootulp rootulp deleted the rp/set-js branch September 21, 2021 21:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants