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

feat: add/update contract swaps parameters #5343

Merged
merged 6 commits into from
Oct 24, 2024
Merged

Conversation

msgmaxim
Copy link
Contributor

@msgmaxim msgmaxim commented Oct 22, 2024

Pull Request

Closes: PRO-1731, PRO-1732

  • Added missing parameters (FoK, DCA, Boost) to contract swap extrinsics (contract_swap_request and contract_ccm_swap_request); these parameters are now passed into the swapping pallet and will be used if provided. (fyi @albert-llimos)

  • Made some parameters more consistent (and to make sure we don't have to assert/convert when passing them further):

    • from type changed Asset -> TargetChainAsset<T, I>
    • deposit_amount type changed AssetAmount -> <T::TargetChain as Chain>::ChainAmount
  • Contract swaps now validate DCA/FoK parameters and enforce minimum deposit amount

  • Most code in both extrinsics is the same, so I factored it out into process_contract_swap_request

BREAKING CHANGES (fyi @acdibble)

  • DepositIgnored event: deposit_address is now optional; this to be able to ignore deposits made directly into our valut.
  • CcmFailed was emitted on invalid destination address in case ccm parameters were provided. I made it more consistent with non-ccm contract swaps where we just log a warning, which also made the code simpler. (CcmFailed is still emitted when a deposit/swap fails for ccm-sepcific reason.) As such, I also removed the CcmFailReason::InvalidDestinationAddress variant.

Discussion:

  • Can we not just make (another) breaking change and replace both extrinsics with one (simply contract_swap_request) that supports both CCM and non-CCM by acception an optional ccm_deposit_metadata parameter?
  • CcmFailed seems odd. We don't really have any other events for when other parameters are invalid. Is it used anywhere? Can we simplify code by removing it and replacing it with a warning (like we do for other parameters).

@albert-llimos
Copy link
Contributor

Can we not just make (another) breaking change and replace both extrinsics with one (simply contract_swap_request) that supports both CCM and non-CCM by acception an optional ccm_deposit_metadata parameter?

That makes sense to me. Especially when we implement the changes in CCM swaps, regular swaps and CCM swaps will be almost identical for the majority of the swap flow. So I'd be in favor of doing it if the breaking change is not annoying to handle on upgrade.

state-chain/cf-integration-tests/src/swapping.rs Outdated Show resolved Hide resolved
@@ -1147,76 +1132,30 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::contract_ccm_swap_request())]
pub fn contract_ccm_swap_request(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah let's just merge these. They can only be called via witnessing so for backwards-compatibility / to avoid migration headaches, we could keep and deprecate the old ones and add a new one. Then we can remove the new one at a later release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't we already broken compatibility by adding new parameters?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed - I guess we did 😅

But given that we are now aware of this, let's avoid breaking - it's easy to do.

state-chain/pallets/cf-ingress-egress/src/lib.rs Outdated Show resolved Hide resolved
@dandanlen
Copy link
Collaborator

dandanlen commented Oct 22, 2024

CcmFailed seems odd.

This is/was to communicate (visibly) that something went wrong, without returning an error, because returning an error in the extrinsic rolls back the state, and we don't want to do that in a witnessed transaction.

If anything, we should emit a failure event for the address decoding too.

A cleaner approach might be to create an Error enum and return that from process_contract_swap_request (then we can write the code a bit more concisely/idiomatically), and log that error in an event, say SwapRequestFailed { swap_origin: SwapOrigin, reason: SwapRequestError, .. }.

@dandanlen dandanlen changed the title Feat: add/update contract swaps parameters feat: add/update contract swaps parameters Oct 23, 2024
@@ -1139,6 +1141,7 @@ pub mod pallet {
deposit_metadata: CcmDepositMetadata,
tx_hash: TransactionHash,
deposit_details: Box<<T::TargetChain as Chain>::DepositDetails>,
broker_fees: Beneficiaries<T::AccountId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in the ticket below, and more particularly on the comment, we'll need to pass the accounts and commission/fees for both the broker and the affiliates. Do we use this parameter for both (e.g. first account is the broker) or we separate them?
This also runs into what I recently discussed with @dandanlen on whether we should make passing the brokerId mandatory for Vault swaps.
https://linear.app/chainflip/issue/PRO-1743/support-for-brokeraffiliate-fees-via-vault-swaps
https://linear.app/chainflip/issue/PRO-1743/support-for-brokeraffiliate-fees-via-vault-swaps#comment-338490a3
I'm not sure there is an easy answer for whether it should be mandatory but it can make sense to separate them here just for flexibility in the future. That's either by having two separate parameters or by this broker_fees having two separate parameters.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this approach is fine for now - we don't need to worry too much about breaking changes here because it only really affects us (it's a witnessed call), and isn't something that is exposed externally.

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 77.33333% with 85 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (dc8bf3e) to head (2ff3128).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
state-chain/pallets/cf-ingress-egress/src/lib.rs 74% 24 Missing and 7 partials ⚠️
engine/src/witness/eth.rs 0% 26 Missing ⚠️
engine/src/witness/arb.rs 0% 22 Missing ⚠️
state-chain/runtime/src/lib.rs 0% 0 Missing and 4 partials ⚠️
...ate-chain/traits/src/mocks/swap_limits_provider.rs 82% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5343    +/-   ##
======================================
- Coverage     71%     71%    -0%     
======================================
  Files        495     495            
  Lines      86335   86286    -49     
  Branches   86335   86286    -49     
======================================
- Hits       61623   61509   -114     
- Misses     21951   22009    +58     
- Partials    2761    2768     +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dandanlen dandanlen left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@dandanlen dandanlen added this pull request to the merge queue Oct 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Oct 24, 2024
@dandanlen
Copy link
Collaborator

Sorry that commit should be Merge branch 'main'.... not sure what happened there.

@dandanlen dandanlen added this pull request to the merge queue Oct 24, 2024
Merged via the queue into main with commit 12ac79c Oct 24, 2024
48 of 49 checks passed
@dandanlen dandanlen deleted the feat/contract-swap-clean-up branch October 24, 2024 17:06
syan095 added a commit that referenced this pull request Oct 29, 2024
…waps-close-accounts

* origin/main: (44 commits)
  fix: expire all previous epochs (#5279)
  feat: add/update contract swaps parameters (#5343)
  chore: add address to solana logging (#5353)
  fix: ignore dust underflows in order fills rpc (#5352)
  chore: consistent naming prewitnessed (#5351)
  feat: engine-runner verifies gpg signature of old dylib when downloaded (#5339)
  feat: tainted transaction reporting (#5310)
  bug: change_utxo not always present (#5340)
  feat: structured error return types for rpcs (#5346)
  chore: unify dependencies to root cargo.toml (#5333)
  feat: Submit a slot number alongside nonce (#5297)
  chore: use node version from `.nvmrc` 📌 (#5336)
  chore: add engine account_info logging (#5347)
  chore: replace manual scale encoding for ts-scale (#5335)
  chore: more consistent params in Broker API (#5342)
  feat: broker can encode btc smart contract call (#5329)
  chore: localnet recreate script can use defaults (#5338)
  feat: witnessing btc smart contract swaps (#5331)
  feat: Solana CCM fallback (#5316)
  fix: scale types for pending ceremonies (#5286)
  ...

# Conflicts:
#	Cargo.lock
#	state-chain/chains/src/sol/api.rs
#	state-chain/pallets/cf-broadcast/src/migrations.rs
#	state-chain/pallets/cf-environment/Cargo.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants