-
Notifications
You must be signed in to change notification settings - Fork 14
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: Affiliate Broker Registration and Lookup for Vault Swaps #5389
Conversation
fac7b30
to
b49bf8b
Compare
b49bf8b
to
9d13dce
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5389 +/- ##
======================================
- Coverage 72% 71% -0%
======================================
Files 487 489 +2
Lines 86183 86508 +325
Branches 86183 86508 +325
======================================
+ Hits 61633 61768 +135
- Misses 21636 21828 +192
+ Partials 2914 2912 -2 ☔ View full report in Codecov by Sentry. |
Yes, I'll get that done. |
state-chain/primitives/src/lib.rs
Outdated
pub type AffiliateShortId = u8; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use define_wrapper_type
now to make this a bit more type-safe.
engine/src/witness/btc/deposits.rs
Outdated
// TODO: provide broker id (along with broker fees) in the call | ||
for (_maybe_broker_id, vault_address) in vault_addresses { | ||
for (maybe_broker_id, vault_address) in vault_addresses { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO comment can be removed now?
b0d12dd
to
613a581
Compare
Addressed all comments now @dandanlen. I also added a check that primary broker is registered as a broker. I chose to just ignore broker fields if the broker is unknown (after emitting a new event), which seems like a reasonable fallback behaviour. If we decide to refund instead, I think this can probably done separately. |
For now I'd use the fallback as there doesn't seem to be any strong argument (or anyone) pushing for refunding instead. The current behavior sounds good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
// In case the entry not found, we ignore the entry, but process the | ||
// swap (to avoid having to refund it). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Self::deposit_event(Event::<T, I>::UnknownPrimaryBroker { | ||
broker_id: primary_broker, | ||
}); | ||
Default::default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a Linear issue to deal with this ie. what to do as fallback? We should probably store the data somewhere so we can reject the deposit / trigger a swap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we already do trigger a swap. We can consider refunding of course, but I figured this needs some discussion first. Storing which data are you talking about tough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed I've opened a triage issue PRO-1804
I think we might be able to take the same path as we do for transaction screening.
Pull Request
Closes: PRO-1750, PRO-1751
Summary
Brokers can register affiliates through the swapping pallet to assign them short ids. Brokers are expected to provide short id that they want to use (rather than SC deciding on their behalf), which also means that they can overwrite existing entries if they want (this can be useful since we only support 256 entries). The new
AffiliateRegistrationUpdated
event includes (among other things)Option<AccountId>
for the entry that is being replaced (most likely to be used as a sanity check to see that they haven't overwritten anything).vault_swap_request
extrinsic now takesOption<(Beneficiary<T::AccountId>, Affiliates<AffiliateShortId>)>
where the primary broker is AccountId and affiliate brokers are "short ids" (u8
). Short affialite ids are converted to fullAccountId
s using affiliate registry (added a new trait for this).BTC witnesser now passes decoded broker id and affiliate short ids into the
vault_swap_request
call. This hasn't been done for other chains, but should be trivial to add ones primary broker id can be decoded there (I believe @albert-llimos is working on this).A small refactor in the testing/mock code: moved
mock_eth
andmock_btc
under the newmocks
module so that they can share code in a more sensible way (they now share the newMockAffiliateRegistry
, which I didn't put undercf_traits
sincie it is unlikely that it will be used by any other pallet).