-
Notifications
You must be signed in to change notification settings - Fork 984
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: wallet router v2 #20631
feat: wallet router v2 #20631
Changes from all commits
04db308
0d3ad5e
843f5bb
ffca87d
ee37ba1
a93a4ce
fd144ed
8bd613b
d32a34a
b417ebe
d1cf96e
4854aec
784ef8a
ad24374
a9fdc3b
8551697
8dca5ce
8b0e6c9
6b3afa9
e43012a
b61cf72
537c706
75b31ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
[clojure.string :as string] | ||
[status-im.constants :as constants] | ||
[status-im.contexts.wallet.common.utils.networks :as network-utils] | ||
[status-im.contexts.wallet.send.utils :as send-utils] | ||
[utils.collection :as utils.collection] | ||
[utils.money :as money] | ||
[utils.number :as utils.number] | ||
|
@@ -188,3 +189,77 @@ | |
:removed-account-addresses removed-account-addresses | ||
:updated-keypairs-by-id updated-keypairs-by-id | ||
:updated-accounts-by-address updated-accounts-by-address})) | ||
|
||
(defn- rename-keys-to-kebab-case | ||
[m] | ||
(set/rename-keys m (zipmap (keys m) (map transforms/->kebab-case-keyword (keys m))))) | ||
|
||
(defn rpc->suggested-routes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this function as disguised as something more general. If I simply rename the bindings, the function can be readily moved to Also note that I used (defn recursive-kebab-case-keyword
[coll]
(cond
(map? coll)
(reduce-kv (fn [m k v]
(assoc m k (recursive-kebab-case-keyword v)))
{}
(update-keys coll ->kebab-case-keyword))
(vector? coll)
(map recursive-kebab-case-keyword coll)
:else coll)) This solution won't work with other types of data, like sets. Also the check with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ilmotta I already tried rewriting the We could try exploring a performant solution, but I honestly think it's going to be expensive to catch all cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it @ulisesmac 👍🏼 I benchmarked the recursive implementation from @BalogunofAfrica in this PR and it performs significantly better than In fact I think we shouldn't be doing recursive key transformations even with our own code because the hand-rolled code with raw maps (not using Also it's not like we need to rename keys all the time from status-go, usually we're careful with that nowadays because it's a breaking change. So we might be optimizing too much for ergonomics in a more sensitive part of the stack. I'm copying @cammellos and @flexsurfer just to see if they are okay with this. If not we should probably discuss on Discord and not here because there are already many comments. Thanks for the insights as usual @ulisesmac There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry for the late reply, I would be leaning towards avoiding dynamic transformation of keys, we had to remove them in at least 2/3 instances on performance grounds, so I would be wary of using them, albeit of course they provide a great dev experience |
||
[suggested-routes] | ||
(cond | ||
(map? suggested-routes) | ||
(into {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's known that processing maps as tuples is slow. Almost always the transformation can be done with |
||
(for [[k v] (rename-keys-to-kebab-case suggested-routes)] | ||
[k (rpc->suggested-routes v)])) | ||
|
||
(vector? suggested-routes) | ||
(map rpc->suggested-routes suggested-routes) | ||
|
||
:else suggested-routes)) | ||
|
||
(def ^:private precision 6) | ||
|
||
(defn new->old-route-path | ||
[new-path] | ||
(let [bonder-fees (:tx-bonder-fees new-path) | ||
token-fees (+ (money/wei->ether bonder-fees) | ||
(money/wei->ether | ||
(:tx-token-fees new-path)))] | ||
{:from (:from-chain new-path) | ||
:amount-in-locked (:amount-in-locked new-path) | ||
:amount-in (:amount-in new-path) | ||
:max-amount-in "0x0" | ||
:gas-fees {:gas-price "0" | ||
:base-fee (send-utils/convert-to-gwei (:tx-base-fee | ||
new-path) | ||
precision) | ||
:max-priority-fee-per-gas (send-utils/convert-to-gwei (:tx-priority-fee | ||
new-path) | ||
precision) | ||
:max-fee-per-gas-low (send-utils/convert-to-gwei | ||
(get-in | ||
new-path | ||
[:suggested-levels-for-max-fees-per-gas | ||
:low]) | ||
precision) | ||
:max-fee-per-gas-medium (send-utils/convert-to-gwei | ||
(get-in | ||
new-path | ||
[:suggested-levels-for-max-fees-per-gas | ||
:medium]) | ||
precision) | ||
:max-fee-per-gas-high (send-utils/convert-to-gwei | ||
(get-in | ||
new-path | ||
[:suggested-levels-for-max-fees-per-gas | ||
:high]) | ||
precision) | ||
:l-1-gas-fee (send-utils/convert-to-gwei (:tx-l-1-fee | ||
new-path) | ||
precision) | ||
:eip-1559-enabled true} | ||
:bridge-name (:processor-name new-path) | ||
:amount-out (:amount-out new-path) | ||
:approval-contract-address (:approval-contract-address new-path) | ||
:approval-required (:approval-required new-path) | ||
:estimated-time (:estimated-time new-path) | ||
:approval-gas-fees (* (money/wei->ether (get-in new-path | ||
[:suggested-levels-for-max-fees-per-gas | ||
:medium])) | ||
(:approval-gas-amount new-path)) | ||
:to (:to-chain new-path) | ||
:bonder-fees bonder-fees | ||
:approval-amount-required (:approval-amount-required new-path) | ||
;; :cost () ;; tbd not used on desktop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double comment |
||
:token-fees token-fees | ||
:gas-amount (:tx-gas-amount new-path)})) |
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 this implementation should live in
utils.transforms
.But the implementation can be faster and simpler.
(update-keys m ->kebab-case-keyword)
I would say we don't even need this utility function because the version with
update-keys
is quite nice already.I checked on a benchmark and
rename-keys
is significantly slower, unless the map of key transformations can be stored statically. But the version withupdate-keys
don't suffer from this problem, so it's equally fast in the specific case and faster in the general one.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.
cc @ulisesmac