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

Adapter calculate and retrieve total spendable amount #385

Merged
merged 69 commits into from
May 17, 2021

Conversation

simzzz
Copy link
Contributor

@simzzz simzzz commented Mar 16, 2021

Implemented adapter.get_deposit(...)for the Ethereum and Dummy adapters, including an integration test.

Change Log:

  • adapter::EthereumAdapter - Added a get_deposit() function which calculates and returns total spendable amount, using the OUTPACE and ERC20 ABI's.
  • adapter::ethereum::Error - Added two new possible errors. The first being TokenNotWhitelisted which is returned when the function is called with a channel with a deposit asset not being in the config's whitelist. The second is InvalidDepositAsset which is used when a channel's deposit asset cannot be converted to Address. This error is here temporarily and I assume it will be gone soon when the channel_v5 replaces the old channel in the adapter.
  • dev.toml and prod.toml configs - Changed the structure of token_addr_whitelist from an array of strings, to an array with objects that contain address, min_token_units_for_deposit and precision.
  • primitives::adapter::Deposit - new struct representing the get_deposit() output. Added signature for get_deposit in the impl
  • primitives::channel_validator::asset_listed() - Changed asset_listed() function to work with the new token whitelist structure from String Vec to HashMap.
  • primitives::config - Changed token whitelist from String Vec to HashMap. Added a new struct called TokenInfo which represents the value for the token whitelist HashMap.

Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

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

Looks like you have great progress on the task already 🎉
Can you also make sure to include a list of the Changelog in PR so we can later add it to the CHANGELOG.md file.

primitives/src/adapter.rs Outdated Show resolved Hide resolved
primitives/src/channel_validator.rs Outdated Show resolved Hide resolved
primitives/src/config.rs Outdated Show resolved Hide resolved
adapter/src/ethereum/error.rs Outdated Show resolved Hide resolved
adapter/src/ethereum.rs Outdated Show resolved Hide resolved
adapter/src/ethereum.rs Outdated Show resolved Hide resolved
adapter/src/ethereum.rs Outdated Show resolved Hide resolved
@elpiel elpiel linked an issue Mar 17, 2021 that may be closed by this pull request
5 tasks
@elpiel
Copy link
Member

elpiel commented Mar 17, 2021

After some discussion with Ivo, we came to the following changes:
get_deposit(channel: &Channel, user: &Address) -> Deposit
struct Deposit { total: BigNum, pending: BigNum }

This could change in the future, as we will introduce the UnifiedNum and we have yet to see if we will use the full precision from the validator (BigNum) or directly work with the UnifiedNum from the Adapter onward.

@simzzz simzzz marked this pull request as ready for review March 26, 2021 12:01
@simzzz simzzz requested a review from elpiel March 26, 2021 12:02
Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

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

Can you also make sure to fix the gitmodule

adapter/src/ethereum.rs Show resolved Hide resolved
primitives/Cargo.toml Outdated Show resolved Hide resolved
primitives/src/config.rs Outdated Show resolved Hide resolved
primitives/src/config.rs Show resolved Hide resolved
@elpiel elpiel force-pushed the issue-380-adapter-total-spendable-amount branch from 6c3f3ae to f2b2fa2 Compare May 10, 2021 14:25
@elpiel
Copy link
Member

elpiel commented May 10, 2021

TODO:

  • get_deposit of Dummy adapter

@@ -20,11 +20,30 @@ ip_rate_limit = { type = 'ip', timeframe = 20000 }
sid_rate_limit = { type = 'sid', timeframe = 20000 }

ethereum_core_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
# TODO: Replace with real contract address
outpace_address = '0x333420fc6a897356e69b62417cd17ff012177d2b'
# TODO: Replace with real contract address
Copy link
Contributor

Choose a reason for hiding this comment

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

to make tests reproducible we can create a ganache snapshot of the required deployments and use it on startup

Copy link
Member

Choose a reason for hiding this comment

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

This is a cool idea for enhancement!
How can we do that?

@elpiel elpiel merged commit f8af066 into aip-61-adex-v5 May 17, 2021
@elpiel elpiel deleted the issue-380-adapter-total-spendable-amount branch May 17, 2021 08:14
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.

AIP #61 v5: Adapter - total spendable amount
3 participants