-
Notifications
You must be signed in to change notification settings - Fork 15
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: on chain swaps #5595
base: main
Are you sure you want to change the base?
feat: on chain swaps #5595
Conversation
8d4b190
to
a876c17
Compare
@@ -89,57 +89,6 @@ impl<T: Config> UncheckedOnRuntimeUpgrade for Migration<T> { | |||
} | |||
|
|||
fn on_runtime_upgrade() -> Weight { | |||
crate::SwapRequests::<T>::translate_values::<old::SwapRequest<T>, _>(|old_swap_requests| { |
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 need to branch 1.8 and remove this migration (unless we want this PR in 1.8, in which case I can fix this migration properly).
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
I think, for now at least, we probably do need to restrict this to LPs - LPs are likely to be the only parties with enough funds anyway.
); | ||
}, | ||
SwapOutputAction::CreditOnChain { account_id } => { | ||
// TODO: a new event for when LP is credited after 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.
An event would make sense... we have an event for SwapExecuted, why not for SwapFailed?
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.
I added CreditedOnChain
and RefundedOnChain
events.
We could also add SwapFailed
though this isn't relevant to this PR and maybe should be discussed a little first? (e.g. do we emit one alongside every SwapRescheduled
or only when finally refunding?)
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.
Yes I agree, not part of this, PR, was just curious as to why we don't already have it - if we have an event for when a swap request succeeds, why not for when one fails? Did we just forget this or was there a reason?
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.
Did we just forget this or was there a reason?
No reason IIRC other than needing some discussion. Because the frontend can use egress/refund events for this purpose, this hasn't been a priority. We should do it.
482c012
to
8154860
Compare
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.
Now that the extrinsic is lp-specific, I would suggest refactoring such internal_swap
is an interface method on SwapRequestHandler
, and moving the extrinsic, account check, refund address check and sweep to the lp pallet.
Then the lp pallet can depend on the swapping interface rather than the swapping pallet depending on the lp and pools interfaces. This is more in line with how things are currently structured, with lp-specific calls and checks in the lp pallet. The swapping pallet has accumulated enough responsibilities already.
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.
Btw. I noticed we already have a type AccountOrAddress in the lp pallet, it's very similar to RefundDestination
, would be good to merge/deduplicate these.
4fffb16
to
2fab474
Compare
2fab474
to
d464d68
Compare
/// zero becomes more valuable relative to asset one the price's literal value goes up, and vice | ||
/// versa. This ratio is represented as a fixed point number with `PRICE_FRACTIONAL_BITS` fractional | ||
/// bits. | ||
pub type Price = U256; |
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.
I've mentioned this many times - i'm not a fan of exposing a type alias like this as a 'primitive' when it's loaded with so much meaning...
I guess this is better than duplicating the definition though, so 🤷
Created PRO-2044 to address this once and for all.
min_price, | ||
}), | ||
dca_params, | ||
SwapOrigin::OnChainAccount(account_id), |
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.
nit: It might have been a bit cleaner to define a trait method like internal_swap_request(..)
, then all these types like SwapOrigin
, SwapRequestType
, SwapOutputAction
and RefundDestination
(even RefundParametersExtended
?) could remain internal to the swapping pallet rather than leaking them in the public interface. And we would not have to pass empty broker fees (which makes little sense for an internal swap anyway).
PRO-1998
Summary
SwapRequestType
(part of SwapRequests storage) where I replaced the output address withSwapOutputAction
that has two variants (Egress
- for "traditional" swaps, andCreditOnChain
- for on chain swaps). Added migration for this.Breaking changes
SwapRequested
event:Regular
variant now can contain account_id instead of output_address.refund_desitnation
(instead ofrefund_address
), which can be either an address (as before) or an account_id (in case of an internal swap).Discussion
Do we need new events for when an account is credited as a result of a swap?
- Currently we are expecting the following sequence of events:
Presumably we want new events for internal swaps to match
SwapEgressScheduled
andRefundEgressScheduled
.