-
Notifications
You must be signed in to change notification settings - Fork 375
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
cEUR ContractKit support #7257
cEUR ContractKit support #7257
Conversation
…StableTokenEURWrapper
…, currently writing tests for alias functions in exchange
…r/ceur-contractkit-master
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.
Ok, after reading it, I have a few questions/suggestions about the implementation.
Why don't we just create a StableTokenWrapper, that could handle every StableToken in it. Same with the exchange one.
In a way, the wrappers are things that we create to make everything easier. At least in my opinion, we shouldn't think the StableTokenWrapper as only the usd one, but all the stables.
To give you an example, the logic of searching for every balance could be part of the StableTokenWrapper.
Yes, today we have a wording problem, and the StableToken it means cUsd in our chain, but we could abstract the user from that.
What do you think about having a StableTokenWrapper, that basically switches between the stableTokens?
we could have something like:
const stable = kit.contracts.getStableToken()
stable.transfer(StableToken.cEUR, to, value)
And in that stable wrapper have something like:
transfer(st: StableToken, to: string, value: string | number)=> CeloTransactionObject<boolean> = proxySend(
this.kit,
this.contractMap[st].methods.transfer
)
even we could overload the transfer to have the same but without the first parameter to asume that is cusd
transfer(to: string, value: string | number)=> CeloTransactionObject<boolean> = proxySend(
this.kit,
this.contractMap[StableToken.cUSD].methods.transfer
)
AND in this same wrapper, for example, have the function that gathers all the stable token balances
We could maintain a wrapper per stable, but could be transparent for the user. The user knows that the StableTokenWrapper will handle everything, and internally we are the ones switching. And as is an internal wrapper, we could call the StableTokencUSDWrapper, the one that includes the generated StableToken
I think that this could make everything easier when we add a new stable, and will group the functions that collect info for every one of those (same with the exchange)
Don't know what you think about it, but it's adding a new layer to your actual work in this PR (nothing will be wasted, haha)
@@ -117,6 +123,9 @@ export class WrapperCache { | |||
getExchange() { | |||
return this.getContract(CeloContract.Exchange) | |||
} | |||
getExchangeEUR() { |
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.
Same as the StableToken comment
@gastonponti thanks for the review!
Personally I like the 1 wrapper instance : 1 contract relationship that (to my understanding) we've kept throughout contractkit. Because StableToken (cUSD) and StableTokenEUR (cEUR) are different contracts, I think it'd be confusing to have a single wrapper be able to reference both contracts. It'd probably involve a bigger refactor due to I do really like your suggestion of something like:
That way we keep the 1:1 wrapper/contract relationship, and as we add future stabletokens we don't need to add |
Agree. I think that we added a lot of methods in these two (stable and exchange) thinking that would be easier to read, instead of thinking about the better solution for N of those stables. I would keep it as aliases, and encourage to use the others, until we could eventually deprecate them. Also agree on the Wrapper 1:1 but I also keep finding useful a way to handle all the stables at once. Maybe could be a helper or another class, that could keep your selected stable coins, and let you do stuff like show all the balances, or try to pay this X tx with one of these stables in a order [cUsd, cEur, cXXX] and send the tx from the first stable that could be cover the cost (I don't know, there are probably a lot of possible interactions between stables, and we should have something for that) |
And even knowing that this could be part of a different feature, I'm already seeing those kind of interactions that you added in the kit. So maybe extract it into some helper could be a really good first step |
…r/ceur-contractkit-master
…r/ceur-contractkit-master
…r/ceur-contractkit-master
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.
Nice work! So much clearer. Really like this approach.
I've added a little concern about the naming of a type, but is up to you 😄
LGTM
CELO = 'CELO', | ||
} | ||
|
||
export type CeloToken = StableToken | 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.
(sorry missed to add the concern, haha)
Basically is the name collision between this type and the one in base (even that we know that the other will be deprecated). This could eventually bring some confusion.
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.
Just changed to CeloTokenType
…r/ceur-contractkit-master
Description
Adds StableTokenEUR and ExchangeEUR wrappers.
Erc20Wrapper
, which wraps the required functions of ERC20 tokens found in theIERC20
interfaceCeloTokenWrapper
, which extendsErc20Wrapper
and wraps functions in theICeloToken
interface. AlthoughICeloToken
itself doesn't extendIERC20
, it's intended to be used alongsideIERC20
, and havingCeloTokenWrapper
extendErc20Wrapper
is easier to get around TypeScript not supporting multiple inheritance (egclass StableTokenEURWrapper extends CeloTokenWrapper, Erc20Wrapper
isn't possible)StableTokenWrapper
is used for both cUSD and cEUR.ExchangeWrapper
is used for both cUSD and cEUR. Dollar-specific functions still exist but are deprecated and the generic functions are preferred.CeloTokens
, a helper class for interacting with CELO & stable tokensOther changes
@celo/typechain-target-web3-v1-celo
to properly generate TS files for interfacesstableTokenEUR
to migration overrides for tests to workI did not update
packages/sdk/base/src/currencies.ts
to include cEUR as only Valora relies upon that, and adding cEUR there caused a bunch of build issues that can only be resolved with code changes to support cEUR in Valora.Tested
Related issues
Backwards compatibility
See Other Changes