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(custom-rpc): improve environment RPC #4154

Merged
merged 21 commits into from
Oct 26, 2023
Merged

feat(custom-rpc): improve environment RPC #4154

merged 21 commits into from
Oct 26, 2023

Conversation

acdibble
Copy link
Contributor

Pull Request

Closes WEB-472
Closes WEB-402

Checklist

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

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

We never used the old environment RPC so I just gutted it and replaced it with useful stuff.

I tried to group the information in the RPC by pallet and created individual RPCs for each of those pallets.

@acdibble acdibble requested a review from a team as a code owner October 23, 2023 13:50
@acdibble acdibble requested review from niklasnatter and zoheb391 and removed request for a team October 23, 2023 13:50
@linear
Copy link

linear bot commented Oct 23, 2023

WEB-402 Get minimum swap amount from RPC instead of hardcoding them

Right now we hardcode the minimum deposit amount and minimum swap amount in the code of the SDK:

https://github.com/chainflip-io/chainflip-sdk-monorepo/blob/e86942354eda52d844f2f62d68586a113e1d7341/packages/shared/src/consts.ts#L4-L33

These value will get outdated eventually and it will need a new version of the npm package to update them. Instead, we should fetch the amounts from the backend which reads them from the state chain using an RPC call. The backend already supports reading the values via the cf_min_swap_amount method:

#3805

WEB-472 Add tax to the custom RPC

@codecov
Copy link

codecov bot commented Oct 23, 2023

Codecov Report

Merging #4154 (84b7b52) into main (9ef3413) will decrease coverage by 0%.
The diff coverage is 50%.

@@          Coverage Diff           @@
##            main   #4154    +/-   ##
======================================
- Coverage     72%     72%    -0%     
======================================
  Files        378     379     +1     
  Lines      61335   61477   +142     
  Branches   61335   61477   +142     
======================================
+ Hits       43993   44053    +60     
- Misses     15068   15122    +54     
- Partials    2274    2302    +28     
Files Coverage Δ
state-chain/runtime/src/runtime_apis.rs 85% <100%> (+1%) ⬆️
utilities/src/with_std.rs 72% <ø> (ø)
state-chain/chains/src/address.rs 62% <0%> (-2%) ⬇️
utilities/src/with_std/rpc.rs 79% <79%> (ø)
state-chain/runtime/src/lib.rs 35% <12%> (-1%) ⬇️
state-chain/custom-rpc/src/lib.rs 23% <50%> (+1%) ⬆️

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -246,6 +246,7 @@ impl ToHumanreadableAddress for PolkadotAccountId {

#[cfg(feature = "std")]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

@acdibble Note this type is also used in get_open_swap_channels in the LP Api...

@AlastairHolmes I can't remember if we decided on anything regarding this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel the untagged is a bad idea (Because of the deserialization danger), and that we should instead of the ChainMap solution we discussed.

Copy link
Contributor

Choose a reason for hiding this comment

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

And I'd prefer not using it and waiting until we introduce the ChainMap, which can alternatively don't pretty quickly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess using an unimplemented Deserialize is ok, for now. But the ChainMap I think is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we discussed it in person a bit and there's no use case for deserializing a human-readable address using this because more context is required besides the address itself. Even if we could parse addresses using this deserialization method, we would still have to convert it to another type before it can be used with any other methods (or change those methods' signatures to accept this type).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or if we do have a use case for it it's outside the scope of this PR since currently we only ever serialize this type.

@dandanlen dandanlen mentioned this pull request Oct 24, 2023
2 tasks
{
match self {
// JS numbers are 64-bit floats, so we need to use a string for numbers larger than 2^53
&Self::Number(n) if n >= 2u64.pow(53) => U256::from(n).serialize(serializer),
Copy link
Collaborator

@dandanlen dandanlen Oct 26, 2023

Choose a reason for hiding this comment

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

This should probably be raised as an issue with parity 😅 ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was thinking the same, but not sure if it would be too breaking.

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.

Just a couple of nitpicky comments. LGTM.

utilities/src/with_std/rpc.rs Show resolved Hide resolved
utilities/src/with_std/rpc.rs Show resolved Hide resolved
@acdibble acdibble merged commit ed0baff into main Oct 26, 2023
42 checks passed
@acdibble acdibble deleted the feat/environment-rpc branch October 26, 2023 15:25
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.

None yet

3 participants