-
Notifications
You must be signed in to change notification settings - Fork 987
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: approve token transactions on swap #21076
Conversation
Jenkins BuildsClick to see older builds (39)
|
5b2f7df
to
ad1fa0b
Compare
94723fb
to
4da2d50
Compare
@@ -8,9 +8,17 @@ | |||
(rf/reg-event-fx | |||
:wallet/pending-transaction-status-changed-received | |||
(fn [{:keys [db]} [{:keys [message]}]] | |||
(let [details (transforms/json->clj message) | |||
tx-hash (:hash details)] | |||
{:db (update-in db [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1)}))) |
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.
:blocks
param was not used, and also it didn't make much sense to hardcode it to 1
. Ideally, if we need it in the future, we should listen to transaction events and update the value accordingly, but for now it is not needed.
(money/->wei | ||
:gwei | ||
max-fee-per-gas-medium)) | ||
:MaxPriorityFeePerGas | ||
(money/to-hex | ||
(money/->wei | ||
:gwei | ||
max-priority-fee-per-gas))) | ||
(not eip-1559-enabled?) (assoc :TxType "0x00" | ||
:GasPrice | ||
(money/to-hex | ||
(money/->wei | ||
:gwei | ||
gas-price)))))) | ||
|
||
(defn approval-path | ||
[{:keys [route from-address to-address token-address]}] | ||
(let [{:keys [from]} route | ||
from-chain-id (:chain-id from) | ||
approval-amount-required (:approval-amount-required route) | ||
approval-amount-required-sanitized (-> approval-amount-required | ||
(utils.hex/normalize-hex) | ||
(native-module/hex-to-number)) | ||
approval-contract-address (:approval-contract-address route) | ||
data (native-module/encode-function-call | ||
constants/contract-function-signature-erc20-approve | ||
[approval-contract-address | ||
approval-amount-required-sanitized]) | ||
tx-data (transaction-data {:from-address from-address | ||
:to-address to-address | ||
:token-address token-address | ||
:route route | ||
:data data | ||
:eth-transfer? false})] | ||
{:BridgeName constants/bridge-name-transfer | ||
:ChainID from-chain-id | ||
:TransferTx tx-data})) | ||
|
||
(defn transaction-path | ||
[{:keys [from-address to-address token-id token-address route data eth-transfer?]}] | ||
(let [{:keys [bridge-name amount-in bonder-fees from | ||
to]} route | ||
tx-data (transaction-data {:from-address from-address | ||
:to-address to-address | ||
:token-address token-address | ||
:route route | ||
:data data | ||
:eth-transfer? eth-transfer?}) | ||
to-chain-id (:chain-id to) | ||
from-chain-id (:chain-id from)] | ||
(cond-> {:BridgeName bridge-name | ||
:ChainID from-chain-id} | ||
|
||
(= bridge-name constants/bridge-name-erc-721-transfer) | ||
(assoc :ERC721TransferTx | ||
(assoc tx-data | ||
:Recipient to-address | ||
:TokenID token-id | ||
:ChainID to-chain-id)) | ||
|
||
(= bridge-name constants/bridge-name-erc-1155-transfer) | ||
(assoc :ERC1155TransferTx | ||
(assoc tx-data | ||
:Recipient to-address | ||
:TokenID token-id | ||
:ChainID to-chain-id | ||
:Amount amount-in)) | ||
|
||
(= bridge-name constants/bridge-name-transfer) | ||
(assoc :TransferTx tx-data) | ||
|
||
(= bridge-name constants/bridge-name-hop) | ||
(assoc :HopTx | ||
(assoc tx-data | ||
:ChainID from-chain-id | ||
:ChainIDTo to-chain-id | ||
:Symbol token-id | ||
:Recipient to-address | ||
:Amount amount-in | ||
:BonderFee bonder-fees)) | ||
|
||
(not (or (= bridge-name constants/bridge-name-erc-721-transfer) | ||
(= bridge-name constants/bridge-name-transfer) | ||
(= bridge-name constants/bridge-name-hop))) | ||
(assoc :CbridgeTx | ||
(assoc tx-data | ||
:ChainID to-chain-id | ||
:Symbol token-id | ||
:Recipient to-address | ||
:Amount amount-in))))) | ||
|
||
(defn multi-transaction-command | ||
[{:keys [from-address to-address from-asset to-asset amount-out multi-transaction-type] | ||
:or {multi-transaction-type constants/multi-transaction-type-unknown}}] | ||
{:fromAddress from-address | ||
:toAddress to-address | ||
:fromAsset from-asset | ||
:toAsset to-asset | ||
:fromAmount amount-out | ||
:type multi-transaction-type}) |
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.
Moved functions to utils file
(money/to-hex | ||
(money/->wei | ||
:gwei | ||
gas-price)))))) |
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.
maybe it makes sense to replace cond
with a simple if
here for better readability?
ad1fa0b
to
23eeb62
Compare
49888c6
to
37c70c8
Compare
23eeb62
to
ad7f1ce
Compare
ad7f1ce
to
e95962f
Compare
37c70c8
to
11156eb
Compare
e95962f
to
46bec86
Compare
11156eb
to
4c7487f
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.
Nice work 🚀, it would be great also to see events-test and utils-test files as there are many important funcs here.
Already tested by @VolodLytvynenko on #21134 |
703b6aa
to
a2b1a3c
Compare
4321942
to
51487f6
Compare
100% of end-end tests have passed
Passed tests (7)Click to expandClass TestWalletMultipleDevice:
Class TestWalletOneDevice:
Class TestCommunityMultipleDeviceMerged:
Class TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityOneDeviceMerged:
|
Thank you @briansztamfater! E2E have passed. PR is ready for merge. |
a2b1a3c
to
59a257d
Compare
Signed-off-by: Brian Sztamfater <[email protected]>
51487f6
to
fbe2bfc
Compare
fixes #20343
Summary
This PR implements Approve transctions for ERC20 tokens when getting a Swap Proposal that needs the pay token to be approved before proceeding.
In the video below, an example of Approving 8 DAI on Mainnet
approvetxswap.mp4
Platforms
Functional
Non-functional
Steps to test
status: ready