From b49916391fb091caaaccc7b4516df83744452068 Mon Sep 17 00:00:00 2001 From: cryptotechmaker Date: Fri, 22 Sep 2023 12:24:34 +0300 Subject: [PATCH] CU-85ztxzhp0: decode & send the exact value for payable methods --- .../tOFT/modules/BaseTOFTMarketModule.sol | 22 ++++++++++++------ .../tOFT/modules/BaseTOFTOptionsModule.sol | 23 +++++++++++-------- docs/tOFT/modules/BaseTOFTMarketModule.md | 3 ++- docs/tOFT/modules/BaseTOFTOptionsModule.md | 3 ++- gitsub_tapioca-sdk | 2 +- tapioca-periph | 2 +- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/contracts/tOFT/modules/BaseTOFTMarketModule.sol b/contracts/tOFT/modules/BaseTOFTMarketModule.sol index 50fc8c01..9e2374f7 100644 --- a/contracts/tOFT/modules/BaseTOFTMarketModule.sol +++ b/contracts/tOFT/modules/BaseTOFTMarketModule.sol @@ -110,6 +110,7 @@ contract BaseTOFTMarketModule is TOFTCommon { bytes32 toAddress = LzLib.addressToBytes32(to); (removeParams.amount, ) = _removeDust(removeParams.amount); + bytes memory lzPayload = abi.encode( PT_MARKET_REMOVE_COLLATERAL, from, @@ -182,7 +183,9 @@ contract BaseTOFTMarketModule is TOFTCommon { (uint256 amount, ) = _removeDust(borrowParams.amount); _debitFrom(_from, lzEndpoint.getChainId(), toAddress, amount); - + (, , uint256 airdropAmount, ) = LzLib.decodeAdapterParams( + airdropAdapterParams + ); bytes memory lzPayload = abi.encode( PT_YB_SEND_SGL_BORROW, _from, @@ -190,7 +193,8 @@ contract BaseTOFTMarketModule is TOFTCommon { _ld2sd(amount), borrowParams, withdrawParams, - approvals + approvals, + airdropAmount ); _checkGasLimit( @@ -226,7 +230,8 @@ contract BaseTOFTMarketModule is TOFTCommon { uint64 amountSD, ITapiocaOFT.IBorrowParams memory borrowParams, ICommonData.IWithdrawParams memory withdrawParams, - ICommonData.IApproval[] memory approvals + ICommonData.IApproval[] memory approvals, + uint256 airdropAmount ) = abi.decode( _payload, ( @@ -236,7 +241,8 @@ contract BaseTOFTMarketModule is TOFTCommon { uint64, ITapiocaOFT.IBorrowParams, ICommonData.IWithdrawParams, - ICommonData.IApproval[] + ICommonData.IApproval[], + uint256 ) ); @@ -256,7 +262,8 @@ contract BaseTOFTMarketModule is TOFTCommon { _to, borrowParams, withdrawParams, - approvals + approvals, + airdropAmount ) ); @@ -280,7 +287,8 @@ contract BaseTOFTMarketModule is TOFTCommon { bytes32 _to, ITapiocaOFT.IBorrowParams memory borrowParams, ICommonData.IWithdrawParams memory withdrawParams, - ICommonData.IApproval[] memory approvals + ICommonData.IApproval[] memory approvals, + uint256 airdropAmount ) public payable { if (approvals.length > 0) { _callApproval(approvals); @@ -290,7 +298,7 @@ contract BaseTOFTMarketModule is TOFTCommon { approve(address(borrowParams.marketHelper), borrowParams.amount); uint256 gas = withdrawParams.withdraw - ? (msg.value > 0 ? msg.value : address(this).balance) + ? (msg.value > 0 ? msg.value : airdropAmount) : 0; IMagnetar(borrowParams.marketHelper) .depositAddCollateralAndBorrowFromMarket{value: gas}( diff --git a/contracts/tOFT/modules/BaseTOFTOptionsModule.sol b/contracts/tOFT/modules/BaseTOFTOptionsModule.sol index 2f8951d9..030c5030 100644 --- a/contracts/tOFT/modules/BaseTOFTOptionsModule.sol +++ b/contracts/tOFT/modules/BaseTOFTOptionsModule.sol @@ -125,13 +125,16 @@ contract BaseTOFTOptionsModule is TOFTCommon { toAddress, paymentTokenAmount ); - + (, , uint256 airdropAmount, ) = LzLib.decodeAdapterParams( + adapterParams + ); bytes memory lzPayload = abi.encode( PT_TAP_EXERCISE, _ld2sd(paymentTokenAmount), optionsData, tapSendData, - approvals + approvals, + airdropAmount ); _checkGasLimit( @@ -209,7 +212,8 @@ contract BaseTOFTOptionsModule is TOFTCommon { memory optionsData, ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData memory tapSendData, - ICommonData.IApproval[] memory approvals + ICommonData.IApproval[] memory approvals, + uint256 airdropAmount ) = abi.decode( _payload, ( @@ -217,7 +221,8 @@ contract BaseTOFTOptionsModule is TOFTCommon { uint64, ITapiocaOptionsBrokerCrossChain.IExerciseOptionsData, ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData, - ICommonData.IApproval[] + ICommonData.IApproval[], + uint256 ) ); @@ -249,7 +254,8 @@ contract BaseTOFTOptionsModule is TOFTCommon { optionsData.target, tapSendData, optionsData.paymentTokenAmount, - approvals + approvals, + airdropAmount ) ); @@ -287,7 +293,8 @@ contract BaseTOFTOptionsModule is TOFTCommon { ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData memory tapSendData, uint256 paymentTokenAmount, - ICommonData.IApproval[] memory approvals + ICommonData.IApproval[] memory approvals, + uint256 airdropAmount ) public { if (approvals.length > 0) { _callApproval(approvals); @@ -313,9 +320,7 @@ contract BaseTOFTOptionsModule is TOFTCommon { } } if (tapSendData.withdrawOnAnotherChain) { - ISendFrom(tapSendData.tapOftAddress).sendFrom{ - value: address(this).balance - }( + ISendFrom(tapSendData.tapOftAddress).sendFrom{value: airdropAmount}( address(this), tapSendData.lzDstChainId, LzLib.addressToBytes32(from), diff --git a/docs/tOFT/modules/BaseTOFTMarketModule.md b/docs/tOFT/modules/BaseTOFTMarketModule.md index e8c4e9e2..e91aba7f 100644 --- a/docs/tOFT/modules/BaseTOFTMarketModule.md +++ b/docs/tOFT/modules/BaseTOFTMarketModule.md @@ -186,7 +186,7 @@ function borrow(address module, uint16 _srcChainId, bytes _srcAddress, uint64 _n ### borrowInternal ```solidity -function borrowInternal(bytes32 _to, ITapiocaOFT.IBorrowParams borrowParams, ICommonData.IWithdrawParams withdrawParams, ICommonData.IApproval[] approvals) external payable +function borrowInternal(bytes32 _to, ITapiocaOFT.IBorrowParams borrowParams, ICommonData.IWithdrawParams withdrawParams, ICommonData.IApproval[] approvals, uint256 airdropAmount) external payable ``` @@ -201,6 +201,7 @@ function borrowInternal(bytes32 _to, ITapiocaOFT.IBorrowParams borrowParams, ICo | borrowParams | ITapiocaOFT.IBorrowParams | undefined | | withdrawParams | ICommonData.IWithdrawParams | undefined | | approvals | ICommonData.IApproval[] | undefined | +| airdropAmount | uint256 | undefined | ### callOnOFTReceived diff --git a/docs/tOFT/modules/BaseTOFTOptionsModule.md b/docs/tOFT/modules/BaseTOFTOptionsModule.md index cceb4734..79493b63 100644 --- a/docs/tOFT/modules/BaseTOFTOptionsModule.md +++ b/docs/tOFT/modules/BaseTOFTOptionsModule.md @@ -380,7 +380,7 @@ function exercise(address module, uint16 _srcChainId, bytes _srcAddress, uint64 ### exerciseInternal ```solidity -function exerciseInternal(address from, uint256 oTAPTokenID, address paymentToken, uint256 tapAmount, address target, ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData tapSendData, uint256 paymentTokenAmount, ICommonData.IApproval[] approvals) external nonpayable +function exerciseInternal(address from, uint256 oTAPTokenID, address paymentToken, uint256 tapAmount, address target, ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData tapSendData, uint256 paymentTokenAmount, ICommonData.IApproval[] approvals, uint256 airdropAmount) external nonpayable ``` @@ -399,6 +399,7 @@ function exerciseInternal(address from, uint256 oTAPTokenID, address paymentToke | tapSendData | ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData | undefined | | paymentTokenAmount | uint256 | undefined | | approvals | ICommonData.IApproval[] | undefined | +| airdropAmount | uint256 | undefined | ### exerciseOption diff --git a/gitsub_tapioca-sdk b/gitsub_tapioca-sdk index b89632da..4c8402a7 160000 --- a/gitsub_tapioca-sdk +++ b/gitsub_tapioca-sdk @@ -1 +1 @@ -Subproject commit b89632da490d13ab7dffe3ed5a26bc1e456861ea +Subproject commit 4c8402a78b2488090e4de9569d7d335a4986ca1d diff --git a/tapioca-periph b/tapioca-periph index 7b2f6354..3e1b24ea 160000 --- a/tapioca-periph +++ b/tapioca-periph @@ -1 +1 @@ -Subproject commit 7b2f635426c888b11a80a93a5a3d1f0a5f28bc73 +Subproject commit 3e1b24ea9fabf1cf032dac68a3b0a645fa608019