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

LPv2: ForeignInvestments changes #1895

Merged
merged 36 commits into from
Jul 15, 2024
Merged

LPv2: ForeignInvestments changes #1895

merged 36 commits into from
Jul 15, 2024

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Jul 1, 2024

Description

Required changes in pallet-foreign-investments for LPv2

Checkout the sequence diagrams before reviewing this: https://centrifuge.hackmd.io/H4v-SV0zRuCxC29kxoqOgQ

Changes and Descriptions

  • Modify decrease by cancel
    • This allows big simplifications if we know that no more increases/decreases can occur from a cancel if request until the Fulfilled cancel msg is sent.
  • Remove the no longer used collect_* and investment() and redemption() methods from ForeignInvestment trait.
  • Remove the remaining amount from output messages.
  • The correlation has been simplified. We no longer need to store both foreign and pool amounts to correlate. We know that the previous correlation.pool_amount always matches to T::Investment::investment() so we only need to store the foreign amount. The correlation is only done in just one point in the code: in post_collect(), so we no longer need a correlation struct to handle any case generically. We can just simplify for the one needed case.
  • Swapping calls and hooks are now called in entities.rs, leaving the impl.rs file much more readable.
  • Unify hooks into the same new trait ForeignInvestmentHooks
  • Remove pallet-swaps
    • We no longer need to apply a swap over an existent inverse swap. From now on we only need to create, increase, and cancel a swap. That means that most valuable parts from pallet-swap are no longer used, so we can just drop that pallet and handle the order-book direclty from foreign-investment again. Also, not having pallet-swaps makes easy the deal with different ratios in opposite swaps.

Blocked by #1892

@lemunozm lemunozm added I8-enhancement An additional feature. I6-refactoring Code needs refactoring. labels Jul 1, 2024
@lemunozm lemunozm self-assigned this Jul 1, 2024
///
/// NOTE: If the investment was (partially) processed, the unprocessed
/// amount is only updated upon collecting.
fn investment(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only used this to know how much we need to cancel, so it is no longer needed

@lemunozm lemunozm force-pushed the lpv2/fi-cancelation branch 3 times, most recently from 9e1ad60 to a9670f6 Compare July 10, 2024 05:45
@lemunozm lemunozm changed the base branch from feat/lp-v2 to lpv2/message-reorder July 10, 2024 05:45
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

This definitely improves comprehensibility of foreign investments by orders of magnitude 🎉 I have quite an amount of questions.

I will create a branch which combines both our changes in order to continue working on the ITs which need the fulfilled changes on our side.

pallets/foreign-investments/src/entities.rs Outdated Show resolved Hide resolved
pallets/foreign-investments/src/entities.rs Show resolved Hide resolved
pallets/foreign-investments/src/entities.rs Show resolved Hide resolved
pallets/foreign-investments/src/entities.rs Outdated Show resolved Hide resolved
Comment on lines +235 to +239
collected
.amount_payment
.ensure_mul(self.foreign_amount.into())?
.ensure_div(pool_amount_before_collecting)
.unwrap_or(self.foreign_amount.into())
.into()
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. For other reviewers here's a simple example to put some face to these lines:

Say

  • self.foreign_amount = 1000 F
  • collected.amount_payment = 100 P
  • invested = 400 P --> pool_amount_before_collecting = 500 P

Then collected_foreign_amount = 1000F * 100P / 500P = 200F which makes sense because 1000F = 500P

pallets/foreign-investments/src/tests.rs Show resolved Hide resolved
pallets/foreign-investments/src/tests.rs Show resolved Hide resolved
pallets/foreign-investments/src/tests.rs Show resolved Hide resolved
pallets/foreign-investments/src/tests.rs Show resolved Hide resolved
pallets/foreign-investments/src/tests.rs Show resolved Hide resolved
@lemunozm
Copy link
Contributor Author

Thanks a lot for your super deep review @wischli!!

I will create a branch which combines both our changes in order to continue working on the ITs which need the fulfilled changes on our side.

Before doing this, if you want, to avoid extra branches, we can

  • merge this into your branch
  • merge your branch (even with the failing tests) into feat/lp-v2 and later merge this as another PR on that branch.

@lemunozm lemunozm marked this pull request as ready for review July 11, 2024 11:13
@lemunozm lemunozm requested a review from hieronx as a code owner July 11, 2024 11:13
@wischli
Copy link
Contributor

wischli commented Jul 11, 2024

Thanks a lot for your super deep review @wischli!!

Thanks for answering all my questions so quickly! IMO, this branch can be merged to the feature branch indeed.

I will create a branch which combines both our changes in order to continue working on the ITs which need the fulfilled changes on our side.

Before doing this, if you want, to avoid extra branches, we can

  • merge this into your branch
  • merge your branch (even with the failing tests) into feat/lp-v2 and later merge this as another PR on that branch.

I would prefer this because I can imagine that fixing all Solidity ITs won't happen in the near future. Especially, if minor Solidity code changes might be required, which could be the case.

Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

I'm fine with merging this into my branch. The few clippy complaints can be fixed by me then.

@lemunozm lemunozm changed the base branch from lpv2/message-reorder to feat/lp-v2 July 12, 2024 13:46
@lemunozm
Copy link
Contributor Author

CI for this is still blocked, I'm gonna merge @wischli

@lemunozm lemunozm merged commit 5f0f06a into feat/lp-v2 Jul 15, 2024
2 of 10 checks passed
lemunozm added a commit that referenced this pull request Aug 1, 2024
* feat: LPv2 message reorder (#1892)

* wip: add new msgs + reorder

* refactor: apply renaming

* fix: ITs

* feat: UpdateRestriction message

* fix: cancel_unprocessed_investment IT

* fix: fmt

* fix: clippy

* tests: reanchor solidity to reorder branch

* feat: apply hook to AddTranche msg

* tests: fix pool_management ITs

* wip: fix lp investments

* fmt

* fix: Tranche namespace

* refactor: remove fulfilled from FulfilledRedeemRequest

* chore: update lp submodule

* minor cleanup

* chore: update lp submodule

* chore: add missing cleanup

* fixes + ignore failing tests

* fmt

* tests: fix message indices

* ignore failing tests (#1910)

* LPv2: ForeignInvestments changes (#1895)

* add uts (#1905)

* main changes for FI

* fix correlation precission

* minor renames

* update investment UTs

* update redemption UTs

* miscelaneous UTs

* minor renames

* simplify correlation and embed to the only needed place

* doc change

* remove unused bound

* swapping calls into entities.rs file

* merge SwapDone methods into FulfilledSwapHook

* fix events

* working without pallet-swaps

* remove boilerplate for removing entries

* minor msg change

* minor simplification

* correct fulfilled sum after last collect

* check OrderIdToSwapId storage

* sending the message inside Info closure is not really a problem

* send msgs from the entities

* remove same currency check in impl.rs

* unify hooks

* remove pallet-swaps

* minor fmt

* add docs

* add architecture diagram

* return cancelled foreign amount from FI interface

* update liquidity-pools

* add messages to diagram

* implement hooks

* fix runtimes

* adapt integration-tests

* fix docs

* fix clippy

* fix clippy

* fix tests after merge

* fix foreign investment tests (#1918)

* ignore failing tests (#1919)

* fix previous merge

* LP v2: fix integration tests (#1915)

* chore: update submodule to latest `main` 6d7f242c0dd83b1b5a4f6d506370a1f3ecbef9ce

* wip: fix ITs

* chore: update submodule

* fix: remove sender param from `Transfer*` messages

* chore: cleanup

* docs: setup evm

* fix: msg tests

* fix: more ITs

* fix: missing refactor after rebase

* chore: update submodule to 223a0f36edabc675f8c74c47b20e366178df7ca3

* chore: improvements

* fmt

* Apply suggestions from code review

* chore: bump spec_version

* fmt: taplo

* LPv2: Batch Message serialization (#1920)

* custo serialize/deserialize for batch

* compiling solution

* serialization/deserialization working for batch message

* remove gmpf changes

* add batch nested protection

* faster serialization for submessages

* correct termination

* add tests for deserialize batch of batch

* add into_iter

* remove unused Box and add pack methods

* fix non_std compilation

* non_std

* fix max_encoded_len recursion issue

* fix submodules

* reduce batch limit

* feat: add domain hook storage (#1928)

* refactor: add domain hook address storage

* tests: add gateway lp admin account checks

* refactor: use GetByKey

* fix: outboundq mock

* refactor: hook 20 bytes instead of 32

* fix cargo fmt

* Feat/lp v2 gateway queue (#1930)

* pallets: Add LP Gateway queue pallet

* lp-gateway-queue: Add benchmarks

* integration-tests: Add LP gateway tests

* docs: Update LP gateway queue entry

* lp-gateway-queue: Use default weight for PostDispatchInfo

* lp-gateway-queue: Add DEFAULT_WEIGHT_REF_TIME const, extract message processing logic, use BaseArithmetic for nonce

* runtime: Add defensive weights for LP gateway queue

* lint: Obey

* taplo: Obey

* pallet: Use DispatchResult for extrinsics

* runtime: Update benchmarks and weight info

* benchmarks: Add default for Message type (wip)

* pallet: Add Default bound to Message type

* lp-v2: fix message fields (#1933)

* fix: add remark call to borrow proxy

* fix: add missing message fields

* chore: bump to v0.13.3

* chore: update submodule

* chore: enable fixed tests

---------

Co-authored-by: Frederik Gartenmeister <mustermeiszer@posteo.de>

* refactor: cleanup my leftovers (#1935)

* LPv2: Bump-up foreign investment. Fix failing investment ITs  (#1934)

* increase version for foreign investments

* fix investment issue

* fix solidity call for transfers_tokens

* fix tests

* minimize required tranche investors for IT

* fix docs

* fix docs

* docs: fix hyperlink

* refactor: enable ITs for centrifuge + dev runtimes (#1938)

* fix: enable ITs for centrifuge + dev runtimes

* fmt

* fix: revert some centrifuge ITs

* fmt

* revert centrifuge addition to ITs

---------

Co-authored-by: William Freudenberger <w.freude@icloud.com>

---------

Co-authored-by: William Freudenberger <w.freude@icloud.com>
Co-authored-by: Cosmin Damian <17934949+cdamian@users.noreply.github.com>
Co-authored-by: Frederik Gartenmeister <mustermeiszer@posteo.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I6-refactoring Code needs refactoring. I8-enhancement An additional feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants