-
Notifications
You must be signed in to change notification settings - Fork 369
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
Added adapters mappings and helpers #10910
Added adapters mappings and helpers #10910
Conversation
…-org/celo-monorepo into martinvol/feeCurrenciesWithAdapters
function getAdaptor(address underlyingToken) public view returns(address){ | ||
address result = adapters[underlyingToken]; | ||
return (result != address(0))? result: underlyingToken; | ||
} |
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.
in this case the if i call getAdaptor with an random address the random address will be returned.
from what we said last night we wanted to restrict to valid ones right?
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.
It's actually hard to check now if something is or not a whitelisted gas fee address as it's an array and not a mapping. You'll get that but it doesn't mean anything.
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.
fair enough.
In that case Id argue it should return address(0) when nothing is found. The method is getAdapter() so it returning null when either address is wrong or when address does not need work is intuitive.
@@ -20,10 +20,17 @@ contract FeeCurrencyWhitelist is | |||
{ | |||
// Array of all the tokens enabled | |||
address[] public whitelist; | |||
// it is not enforce that underlyingTokens in the same order as their underlying | |||
// whitelisted address | |||
address[] public underlyingTokens; |
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.
We could make this AddressSet which would allow to add underlyingTokens directly in setAdaptor rather than have special method for it
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.
This will not work if we want to have multiple adapters for one token ..
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'd rather not update this to 0.8 and leave as is
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.
The problem with current approach is that it is rather manual.
You can setAdapter and you can forget to setUnderlyingToken which will result in inconsistent behaviour. If we will introduce AddressSet instead of array, then we can remove setUnderlyingToken
and instead set the underlying token in setAdapter
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 can make setAdapter also set the underlying token, so it's one call and there's no chance for error.
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 regarding this will not work for more than a token, yes, that's correct. But in reality I don't see how we could have more than one adaptor for a token,
} | ||
|
||
// removed with address zero | ||
function setAdaptor(address token, address adaptor) external onlyOwner { |
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.
We should also be able to remove Adapter
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.
you can set it to zero
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.
it is not the same though ... it will not remove it from the storage
Does this whole PR makes sense??? To me, before this PR, FeeCurrencyAdapter was not a concern of the protocol, nor the protocol needed to know ANYTHING about it. But now we're coupling both. I'm not sure this is a good idea, IMO. What's the benefit? You can always get the FeeCurrency and check if it implements some method liks "isAdapter()" or "getUnderlyingAsset()"... |
Expanding on before: To me the problem is that this PR or the design behind it breaks what it was a nice decoupled interface. Before No part of the system was "aware" of With the change on this PR, we break that. Now the To make a analogy, in some OO programing or strict type programming language, you would have a In the future, if you wanted to remove the notion of Adapter, without this PR it was just a matter of deregistering feeCurrencies by governance. No code, and nor traces would have remained. With this PR, you actually have the notion inside the The way this is typically solve on programming language with strong types is to "ask" wether an interface implements some other type. Basically an Actually, this check would be stronger than what the current PR does, since the PR is "saving" the mapping as defined by governance. So governance is the one telling "this is the fee adaper for X"... but that's not a trustless guarantee.. there's no code checking that. |
@@ -20,10 +20,17 @@ contract FeeCurrencyWhitelist is | |||
{ |
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 should update interface as well.
return (result != address(0)) ? result : underlyingToken; | ||
} | ||
|
||
function removeAdapter(address token) external onlyOwner { |
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.
this should be called when creating the whitelist, not on-by-one
some thoughts in case they are helpful I was thinking about how I might go about building a tool that autoselects the best fee currency to use for a transaction.
alternatively I might be building an app like minipay and choose only to support 1 feeCurrency. In which case id
|
One question on this. Ive always had to supply the ABI for the contract i'm interacting with. IE I need to know if the contract has a getFeeAdapter method. i cant ask the contract. Is there some technique i'm not aware of here? (for other programing languages what you are describing is definitely something id do. |
yes, that's the way i though about that.. and for that you don't need any of this.. only for (4), since you need to know if they are 'the same contract' and you have 2 diff addresses. But for that you can do what i suggested |
Think something like smalltalk or python... what happens if you call a method that it's not defined? It fails with some exception. Solidity behaves the same way. Any "call" to a smart contract, it's actually sending a "message" to the smart contract address, which always executes the same bytecode. That bytecode parses the messages and "routes" the message to the correct method on the bytecode, but if it does not find that it fails. You could check how the Proxy pattern works on solidity. |
Description
Added primitives to easily answer this questions:
Other changes
Describe any minor or "drive-by" changes here.
Tested
An explanation of how the changes were tested or an explanation as to why they don't need to be.
Related issues
Backwards compatibility
Brief explanation of why these changes are/are not backwards compatible.
Documentation
The set of community facing docs that have been added/modified because of this change