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

Connectors POC #861

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Connectors POC #861

merged 3 commits into from
Nov 2, 2022

Conversation

NunoAlexandre
Copy link
Contributor

@NunoAlexandre NunoAlexandre commented Jul 12, 2022

closes #955

To Do

  • Working version of AddPool on a testnet
  • Unit-test remote call encoding
  • Use xcm_transactor::transact_through_sovereign
    For our use case, we want the messages to be sent from the sovereign account but the account calling the outer connectors' extrinsic paying for the fees involved in the Transact execution. transact_through_sovereign seems to be the best fit here.
  • Extend XcmDomain
    The drawback here is that it makes it impossible to unit-test the remote call encoding since it would depend on T::Currency of sorts
  • Clean and simplify
  • Impl add_tranche and transfer ToDo's
  • Run complete test on testnet

@NunoAlexandre NunoAlexandre self-assigned this Jul 12, 2022
@hieronx hieronx added the crcl-cross-chain Circle cross-chain related. label Jul 12, 2022
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
@NunoAlexandre NunoAlexandre force-pushed the connectors branch 3 times, most recently from f41e83c to 08ac379 Compare August 23, 2022 06:18
@NunoAlexandre NunoAlexandre force-pushed the connectors branch 6 times, most recently from fd687bd to 3422c6b Compare September 6, 2022 12:47
@NunoAlexandre NunoAlexandre force-pushed the connectors branch 2 times, most recently from c046ff6 to f60e0b8 Compare September 14, 2022 08:16
Copy link
Contributor Author

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

Self review

pallets/connectors/Cargo.toml Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Show resolved Hide resolved
runtime/development/src/lib.rs Outdated Show resolved Hide resolved
@NunoAlexandre
Copy link
Contributor Author

@offerijns @mikiquantum cc @mustermeiszer we just have a few todos to complete here, I am opening this PR for review to start addressing your reviews. Keep in mind the scope of this PR and that we are keeping it on development for now. Thanks 🏄

@NunoAlexandre NunoAlexandre changed the title Connectors Connectors POC Sep 19, 2022
Copy link
Contributor Author

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

Leaving two notes on the 2 TODOs

pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +359 to +376
// TODO: Transfer to the domain account for bookkeeping
// T::Tokens::transfer(
// T::CurrencyId::Tranche(pool_id, tranche_id),
// &who,
// &DomainLocator {
// domain: address.domain,
// }
// .into_account_truncating(),
// amount,
// false,
// )?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is tricky since it needs to directly reference CurrencyId::Tranche, therefore breaking the genericness of the CurrencyId type. So either we make the type param be very strict on the cfg_types::CurrencyId enum type or we just reference it directly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am working on the currencyId enum anyways this week. We could make the TrancheCurrency a struct which connectors directly depends on and it will implement Into<CurrencyId>.

Other solution, we extend the PoolInspect trait and let it return TrancheCurrency and PoolCurrency for a pool, if it exists. Then you could simply use the returned Currency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes that would be nice @mustermeiszer 😃

Copy link
Collaborator

@mustermeiszer mustermeiszer Sep 21, 2022

Choose a reason for hiding this comment

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

Which one do you prefer? I am still in the process of making up my mind around the changes to CurrencyId.

I have two options in my head:

First - structured currency types that are wrapped in enums

// Also implements `Into<CurrencyId`
struct TrancheCurrency<PoolId, TrancheId> {
   pool_id: PoolId, 
   tranche_id: TrancheId
}

impl<PoolId, TrancheId> TrancheCurrency<PoolId, TrancheId> {
   const DECIMALS: u128 = ???; // Need to get this from the registry
   const SYMBOL: &str =  ???; //Need to get this from the registry
}

// Also implements `Into<CurrencyId`
struct KSM;

impl KSM {
   const DECIMALS: u128 = primitives::currency_decimals::KSM;
   const SYMBOL: &str =  &"KSM";
}

// Also implements `Into<CurrencyId`
struct AUSD;

impl AUSD {
   const DECIMALS: u128 = primitives::currency_decimals::AUSD;
   const SYMBOL: &str =  &"AUSD";
}

// Currencies that can. beused in a pool as a base currency
pub enum PoolCurrency {
   KSM(KSM),
   AUSD(AUSD)
}

// The currencies one can invest into 
pub enum InvestmentId {
   Tranche(TrancheCurrency<PoolId, TrancheId>)
}

// The overarching CurrencyId enum that is only used by pallets
// that need knowledge of all currencies, e.g. orml_tokens
//
// MUST NOT be differentiate between runtimes, but could be
mod altair {
   enum CurrencyId {
     KSM(KSM),
     AUSD(AUSD),
     TrancheCurrency(TrancheCurrency)
   }
}

Second - Do not use structured currencies but rather have the enums convert it

// Currencies that can. beused in a pool as a base currency
pub enum PoolCurrency {
   KSM,
   AUSD
}

impl Into<CurrencyId> for PoolCurrency {
...
}

// The currencies one can invest into 
pub enum InvestmentId {
   Tranche(TrancheCurrency<PoolId, TrancheId>)
}

impl Into<CurrencyId> for InvestmentId {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mustermeiszer do you mind creating an issue to discuss this? 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI the first option was implemented in #995

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks! @mustermeiszer I might ping you on this one :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@NunoAlexandre do we still want to address this TODO here? I think it should be possible now that #995 was merged

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

I am not sure, at which state we are with this. One thing I noticed is that the actual transfer to the local domain address is commented out. Is this intended even for the dev environment?

The only thing I think is wrong is that we allow anybody who has the PoolRole::TrancheInvestor to add a Domain as a tranche investor to a pool. But maybe I am misunderstanding the logic or this is intended. Could you clarify that @NunoAlexandre

if this is good, I would approve. ^^

pallets/connectors/Cargo.toml Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/message.rs Show resolved Hide resolved
pallets/connectors/src/message.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
@mikiquantum mikiquantum changed the base branch from parachain to main September 23, 2022 23:00
pallets/connectors/src/lib.rs Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
) -> DispatchResult {
let who = ensure_signed(origin.clone())?;

ensure!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm wrong, but I think the get_tranche_token_price method would fail on line https://github.com/centrifuge/centrifuge-chain/blob/main/pallets/pools/src/impls.rs#L48 as well if the pool_id or tranche_id was invalid. So it might be more efficient to remove T::PoolInspect::tranche_exists, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm yeah, if we do that we should change the error MissingPrice to something more general, otherwise it will sound like only the price of an non-existing tranche is missing. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense, not entirely sure what the ideal naming is though. Any suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, we need to check whether the tranche token exists in add_tranche whilst not needing to fetch the tranche price. This means that we need to have an error variant for TrancheNotFound for this case.

So I just renamed MissingPrice to MissingTranchePrice to be more specific it's Tranche-related and left a richer doc comment on what this error can mean.

pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +359 to +376
// TODO: Transfer to the domain account for bookkeeping
// T::Tokens::transfer(
// T::CurrencyId::Tranche(pool_id, tranche_id),
// &who,
// &DomainLocator {
// domain: address.domain,
// }
// .into_account_truncating(),
// amount,
// false,
// )?;
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI the first option was implemented in #995

@NunoAlexandre
Copy link
Contributor Author

@offerijns thanks a lot for the review 🚀 I will go through it later today!

@NunoAlexandre
Copy link
Contributor Author

@offerijns this is pretty much ready but now that we merged the 0.9.29 I need to update our forks of the Moonbeam repos and it's not looking pretty. On it 🏃

Copy link
Contributor

@hieronx hieronx left a comment

Choose a reason for hiding this comment

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

Just wondering if we want to address fixing the transfers in this PR. Besides that, everything is looking great! 🔥

Comment on lines +359 to +376
// TODO: Transfer to the domain account for bookkeeping
// T::Tokens::transfer(
// T::CurrencyId::Tranche(pool_id, tranche_id),
// &who,
// &DomainLocator {
// domain: address.domain,
// }
// .into_account_truncating(),
// amount,
// false,
// )?;
Copy link
Contributor

Choose a reason for hiding this comment

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

@NunoAlexandre do we still want to address this TODO here? I think it should be possible now that #995 was merged

pallets/connectors/src/lib.rs Show resolved Hide resolved
@NunoAlexandre NunoAlexandre merged commit f93e208 into main Nov 2, 2022
@NunoAlexandre NunoAlexandre deleted the connectors branch November 2, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-cross-chain Circle cross-chain related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Connectors POC
5 participants