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: broker can encode btc smart contract call #5329

Merged
merged 10 commits into from
Oct 22, 2024

Conversation

j4m1ef0rd
Copy link
Contributor

@j4m1ef0rd j4m1ef0rd commented Oct 14, 2024

Pull Request

Closes: PRO-1648

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

  • new broker_encodeBtcSmartContractCall rpc that will create an encoded btc start contract call with the given params.
  • Extended the SwapLimitsProvider trait to validate the dca and refund params.
    • Added an RPC to use this param validation so that the broker api can use it.

TODO

  • Documentation

@j4m1ef0rd j4m1ef0rd requested a review from msgmaxim October 14, 2024 04:55
@j4m1ef0rd j4m1ef0rd self-assigned this Oct 14, 2024
Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 22.28916% with 129 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (d59eac6) to head (d8661eb).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
api/lib/src/lib.rs 0% 53 Missing ⚠️
...ate-chain/traits/src/mocks/swap_limits_provider.rs 0% 26 Missing ⚠️
state-chain/custom-rpc/src/lib.rs 0% 23 Missing ⚠️
...ne/src/state_chain_observer/client/base_rpc_api.rs 0% 12 Missing ⚠️
state-chain/pallets/cf-swapping/src/lib.rs 69% 11 Missing ⚠️
state-chain/runtime/src/lib.rs 50% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #5329    +/-   ##
======================================
- Coverage     71%     71%    -0%     
======================================
  Files        490     492     +2     
  Lines      85209   85614   +405     
  Branches   85209   85614   +405     
======================================
+ Hits       60659   60917   +258     
- Misses     21837   21964   +127     
- Partials    2713    2733    +20     

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

api/lib/src/lib.rs Outdated Show resolved Hide resolved
api/bin/chainflip-broker-api/src/main.rs Outdated Show resolved Hide resolved
api/bin/chainflip-broker-api/src/main.rs Outdated Show resolved Hide resolved
api/lib/src/lib.rs Show resolved Hide resolved
api/lib/src/lib.rs Outdated Show resolved Hide resolved
api/lib/src/lib.rs Outdated Show resolved Hide resolved
@j4m1ef0rd j4m1ef0rd marked this pull request as draft October 15, 2024 05:31
api/lib/src/lib.rs Outdated Show resolved Hide resolved
@j4m1ef0rd j4m1ef0rd marked this pull request as ready for review October 17, 2024 05:23
@j4m1ef0rd j4m1ef0rd requested a review from dandanlen October 17, 2024 05:48
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.

Some minor comments, looking good.

api/lib/src/lib.rs Outdated Show resolved Hide resolved
api/lib/src/lib.rs Outdated Show resolved Hide resolved
api/lib/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@msgmaxim msgmaxim left a comment

Choose a reason for hiding this comment

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

Looks good (apart from things that Dan already commented on)

@j4m1ef0rd j4m1ef0rd requested a review from dandanlen October 21, 2024 06:09
@dandanlen
Copy link
Collaborator

Adding the broker fees is a nice idea but we should not just silently ignore them - better to return an error message for now.

@dandanlen
Copy link
Collaborator

Adding the broker fees is a nice idea but we should not just silently ignore them - better to return an error message for now.

☝️ Will add this and then merge, thanks @j4m1ef0rd

@dandanlen
Copy link
Collaborator

Actually, I'll also rename the params so that they match request_swap_deposit_address as closely as possible - will make documentation much easier.

@j4m1ef0rd j4m1ef0rd added this pull request to the merge queue Oct 21, 2024
Merged via the queue into main with commit df8771a Oct 22, 2024
48 of 49 checks passed
@j4m1ef0rd j4m1ef0rd deleted the feat/broker-btc-smart-contract-call branch October 22, 2024 00:13
@CumpsD
Copy link

CumpsD commented Oct 22, 2024

@CumpsD
Copy link

CumpsD commented Oct 22, 2024

Out of curiosity, how are refunds handled in this way? Since there is no refund address, where do you get it from?

@j4m1ef0rd
Copy link
Contributor Author

Out of curiosity, how are refunds handled in this way? Since there is no refund address, where do you get it from?

The refund address is stored in the 3rd output of the bitcoin transaction. Will be explained in the docs.

but here you got affiliate_fees.unwrap_or_default()

We would just unwrao_or_default in the next function. Does not really matter at what point it becomes non optional. You're right, we should be consistent.

Any reason you didnt keep this consistent with the order of

At first it was because I wanted to put the optional params at the end also some of the params where different, so it could not be exactly the same, but Dan changed it. So now there is no reason they are not consistent 😅.

@dandanlen
Copy link
Collaborator

Re. consistency:

I tried to keep it as consistent as possible.

There are some necessary differences between requesting a deposit channel vs. requesting a transaction payload.

The specific reason for the change in order in this case is that retry_duration and min_output_amount are non-optional and replace Option<RefundParameters> from the first method. As @j4m1ef0rd mentioned, we keep optional parameters to the end because when passing the parameters in an array, having optional params in the middle of the array creates some weird ambiguities (should it be null? should it be left out? etc.).

Unifying this would have required changing the original api so I opted not to (for now). My main concern was for naming.

In general, however, I would highly recommend using on object rather than an array for passing the parameters, then the order is a non-issue.

@CumpsD
Copy link

CumpsD commented Oct 22, 2024

Object it is! thanks

syan095 added a commit that referenced this pull request Oct 23, 2024
* origin/main:
  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)
  chore: Prune historical values in Validator pallet (#5292)
  feat: expose deposit transaction hash from ingress-egress-tracker (#5320)

# Conflicts:
#	Cargo.lock
#	engine/src/witness/btc/smart_contract.rs
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants