[200 SigmaUSD] Newtypes for pool, refresh, oracle, etc. tokens
Motivation
To employ type checks in API where Token is expected now.
Implementation details
Make newtype for each token type and use them instead of Token and TokenId throughout the codebase. Each newtype checked ctor should check the token id against the one loaded from the config.
Do you mean something like this?
for example,
fn display_update_diff(
old_oracle_config: &OracleConfig,
new_oracle_config: &OracleConfig,
old_pool_box: PoolBoxWrapper,
new_reward_tokens: Option<Token>,
) {
let new_tokens = new_reward_tokens.unwrap_or_else(|| old_pool_box.reward_token());
let new_pool_contract = PoolContract::new(PoolContractInputs::from((
&new_oracle_config.pool_contract_parameters,
&new_oracle_config.token_ids,
)))
.unwrap();
...
after this issue
fn display_update_diff(
old_oracle_config: &OracleConfig,
new_oracle_config: &OracleConfig,
old_pool_box: PoolBoxWrapper,
new_reward_tokens: Option<RewardToken>,
) {
let new_tokens = new_reward_tokens.unwrap_or_else(|| old_pool_box.reward_token());
let new_pool_contract = PoolContract::new(PoolContractInputs::from((
&new_oracle_config.pool_contract_parameters,
&new_oracle_config.token_ids,
)))
.unwrap();
...
Yes. Ideally, I'd want the newtype RewardToken to use instead of Token. But given that it's only the token id that differentiates new token types, I'm thinking of making a new polymorphic Token type and using it instead of Token. Something like:
struct SpecToken<T: TokenIdKind> {
id: T,
amount: TokenAmount
}
trait TokenIdKind {};
struct RewardTokenId(TokenId);
impl TokenIdKind for RewardTokenId {};
and use it as new_reward_token: Option<SpecToken<RewardTokenId>.
And when we now use TokenId, use RewardTokenId directly.
@hanbu97 Hi, are you interested in working on this? I'd like to take this issue if it's available
@SethDusek Sure, go ahead. I interested in it but do not figure out clearly how to work it out. Thank you.
Done in #164. The bounty is sent. Thank you!