|
10 | 10 | [status-im.contexts.wallet.send.utils :as send-utils]
|
11 | 11 | [taoensso.timbre :as log]
|
12 | 12 | [utils.address :as address]
|
13 |
| - [utils.hex :as utils.hex] |
14 | 13 | [utils.money :as money]
|
15 | 14 | [utils.number]
|
16 | 15 | [utils.re-frame :as rf]))
|
|
582 | 581 | [{:ms 20
|
583 | 582 | :dispatch [:wallet/clean-up-transaction-flow]}]]]})))
|
584 | 583 |
|
585 |
| -(defn- transaction-data |
586 |
| - [{:keys [from-address to-address token-address route data eth-transfer?]}] |
587 |
| - (let [{:keys [amount-in gas-amount gas-fees]} route |
588 |
| - eip-1559-enabled? (:eip-1559-enabled gas-fees) |
589 |
| - {:keys [gas-price max-fee-per-gas-medium |
590 |
| - max-priority-fee-per-gas]} gas-fees] |
591 |
| - (cond-> {:From from-address |
592 |
| - :To (or token-address to-address) |
593 |
| - :Gas (money/to-hex gas-amount) |
594 |
| - :Value (when eth-transfer? amount-in) |
595 |
| - :Nonce nil |
596 |
| - :Input "" |
597 |
| - :Data (or data "0x")} |
598 |
| - eip-1559-enabled? (assoc |
599 |
| - :TxType "0x02" |
600 |
| - :MaxFeePerGas |
601 |
| - (money/to-hex |
602 |
| - (money/->wei |
603 |
| - :gwei |
604 |
| - max-fee-per-gas-medium)) |
605 |
| - :MaxPriorityFeePerGas |
606 |
| - (money/to-hex |
607 |
| - (money/->wei |
608 |
| - :gwei |
609 |
| - max-priority-fee-per-gas))) |
610 |
| - (not eip-1559-enabled?) (assoc :TxType "0x00" |
611 |
| - :GasPrice |
612 |
| - (money/to-hex |
613 |
| - (money/->wei |
614 |
| - :gwei |
615 |
| - gas-price)))))) |
616 |
| - |
617 |
| -(defn- approval-path |
618 |
| - [{:keys [route from-address to-address token-address]}] |
619 |
| - (let [{:keys [from]} route |
620 |
| - from-chain-id (:chain-id from) |
621 |
| - approval-amount-required (:approval-amount-required route) |
622 |
| - approval-amount-required-sanitized (-> approval-amount-required |
623 |
| - (utils.hex/normalize-hex) |
624 |
| - (native-module/hex-to-number)) |
625 |
| - approval-contract-address (:approval-contract-address route) |
626 |
| - data (native-module/encode-function-call |
627 |
| - constants/contract-function-signature-erc20-approve |
628 |
| - [approval-contract-address |
629 |
| - approval-amount-required-sanitized]) |
630 |
| - tx-data (transaction-data {:from-address from-address |
631 |
| - :to-address to-address |
632 |
| - :token-address token-address |
633 |
| - :route route |
634 |
| - :data data |
635 |
| - :eth-transfer? false})] |
636 |
| - {:BridgeName constants/bridge-name-transfer |
637 |
| - :ChainID from-chain-id |
638 |
| - :TransferTx tx-data})) |
639 |
| - |
640 |
| -(defn- transaction-path |
641 |
| - [{:keys [from-address to-address token-id token-address route data eth-transfer?]}] |
642 |
| - (let [{:keys [bridge-name amount-in bonder-fees from |
643 |
| - to]} route |
644 |
| - tx-data (transaction-data {:from-address from-address |
645 |
| - :to-address to-address |
646 |
| - :token-address token-address |
647 |
| - :route route |
648 |
| - :data data |
649 |
| - :eth-transfer? eth-transfer?}) |
650 |
| - to-chain-id (:chain-id to) |
651 |
| - from-chain-id (:chain-id from)] |
652 |
| - (cond-> {:BridgeName bridge-name |
653 |
| - :ChainID from-chain-id} |
654 |
| - |
655 |
| - (= bridge-name constants/bridge-name-erc-721-transfer) |
656 |
| - (assoc :ERC721TransferTx |
657 |
| - (assoc tx-data |
658 |
| - :Recipient to-address |
659 |
| - :TokenID token-id |
660 |
| - :ChainID to-chain-id)) |
661 |
| - |
662 |
| - (= bridge-name constants/bridge-name-erc-1155-transfer) |
663 |
| - (assoc :ERC1155TransferTx |
664 |
| - (assoc tx-data |
665 |
| - :Recipient to-address |
666 |
| - :TokenID token-id |
667 |
| - :ChainID to-chain-id |
668 |
| - :Amount amount-in)) |
669 |
| - |
670 |
| - (= bridge-name constants/bridge-name-transfer) |
671 |
| - (assoc :TransferTx tx-data) |
672 |
| - |
673 |
| - (= bridge-name constants/bridge-name-hop) |
674 |
| - (assoc :HopTx |
675 |
| - (assoc tx-data |
676 |
| - :ChainID from-chain-id |
677 |
| - :ChainIDTo to-chain-id |
678 |
| - :Symbol token-id |
679 |
| - :Recipient to-address |
680 |
| - :Amount amount-in |
681 |
| - :BonderFee bonder-fees)) |
682 |
| - |
683 |
| - (not (or (= bridge-name constants/bridge-name-erc-721-transfer) |
684 |
| - (= bridge-name constants/bridge-name-transfer) |
685 |
| - (= bridge-name constants/bridge-name-hop))) |
686 |
| - (assoc :CbridgeTx |
687 |
| - (assoc tx-data |
688 |
| - :ChainID to-chain-id |
689 |
| - :Symbol token-id |
690 |
| - :Recipient to-address |
691 |
| - :Amount amount-in))))) |
692 |
| - |
693 |
| -(defn- multi-transaction-command |
694 |
| - [{:keys [from-address to-address from-asset to-asset amount-out multi-transaction-type] |
695 |
| - :or {multi-transaction-type constants/multi-transaction-type-unknown}}] |
696 |
| - {:fromAddress from-address |
697 |
| - :toAddress to-address |
698 |
| - :fromAsset from-asset |
699 |
| - :toAsset to-asset |
700 |
| - :fromAmount amount-out |
701 |
| - :type multi-transaction-type}) |
702 |
| - |
703 | 584 | (rf/reg-event-fx :wallet/send-transaction
|
704 | 585 | (fn [{:keys [db]} [sha3-pwd]]
|
705 | 586 | (let [routes (get-in db [:wallet :ui :send :route])
|
|
731 | 612 | (native-module/encode-transfer
|
732 | 613 | (address/normalized-hex to-address)
|
733 | 614 | (:amount-in route)))
|
734 |
| - base-path (transaction-path |
| 615 | + base-path (utils/transaction-path |
735 | 616 | {:to-address to-address
|
736 | 617 | :from-address from-address
|
737 | 618 | :route route
|
|
743 | 624 | :data data
|
744 | 625 | :eth-transfer? eth-transfer?})]
|
745 | 626 | (if approval-required?
|
746 |
| - [(approval-path {:route route |
747 |
| - :token-address token-address |
748 |
| - :from-address from-address |
749 |
| - :to-address to-address}) |
| 627 | + [(utils/approval-path {:route route |
| 628 | + :token-address token-address |
| 629 | + :from-address from-address |
| 630 | + :to-address to-address}) |
750 | 631 | base-path]
|
751 | 632 | [base-path]))))
|
752 | 633 | routes)
|
753 | 634 | request-params
|
754 |
| - [(multi-transaction-command |
| 635 | + [(utils/multi-transaction-command |
755 | 636 | {:from-address from-address
|
756 | 637 | :to-address to-address
|
757 | 638 | :from-asset token-id
|
|
0 commit comments