Skip to content

Commit

Permalink
Merge pull request #97 from Tapioca-DAO/CU-85ztxzhp0-airdropped-amount
Browse files Browse the repository at this point in the history
CU-85ztxzhp0: decode & send the exact value for payable methods
  • Loading branch information
0xRektora authored Oct 6, 2023
2 parents 2958800 + b499163 commit 346e9f9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
22 changes: 15 additions & 7 deletions contracts/tOFT/modules/BaseTOFTMarketModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -182,15 +183,18 @@ 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,
toAddress,
_ld2sd(amount),
borrowParams,
withdrawParams,
approvals
approvals,
airdropAmount
);

_checkGasLimit(
Expand Down Expand Up @@ -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,
(
Expand All @@ -236,7 +241,8 @@ contract BaseTOFTMarketModule is TOFTCommon {
uint64,
ITapiocaOFT.IBorrowParams,
ICommonData.IWithdrawParams,
ICommonData.IApproval[]
ICommonData.IApproval[],
uint256
)
);

Expand All @@ -256,7 +262,8 @@ contract BaseTOFTMarketModule is TOFTCommon {
_to,
borrowParams,
withdrawParams,
approvals
approvals,
airdropAmount
)
);

Expand All @@ -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);
Expand All @@ -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}(
Expand Down
23 changes: 14 additions & 9 deletions contracts/tOFT/modules/BaseTOFTOptionsModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -209,15 +212,17 @@ contract BaseTOFTOptionsModule is TOFTCommon {
memory optionsData,
ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData
memory tapSendData,
ICommonData.IApproval[] memory approvals
ICommonData.IApproval[] memory approvals,
uint256 airdropAmount
) = abi.decode(
_payload,
(
uint16,
uint64,
ITapiocaOptionsBrokerCrossChain.IExerciseOptionsData,
ITapiocaOptionsBrokerCrossChain.IExerciseLZSendTapData,
ICommonData.IApproval[]
ICommonData.IApproval[],
uint256
)
);

Expand Down Expand Up @@ -249,7 +254,8 @@ contract BaseTOFTOptionsModule is TOFTCommon {
optionsData.target,
tapSendData,
optionsData.paymentTokenAmount,
approvals
approvals,
airdropAmount
)
);

Expand Down Expand Up @@ -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);
Expand All @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion docs/tOFT/modules/BaseTOFTMarketModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docs/tOFT/modules/BaseTOFTOptionsModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gitsub_tapioca-sdk
Submodule gitsub_tapioca-sdk updated 40 files
+2 βˆ’2 src/artifacts/tap-token/AOTAP.json
+2 βˆ’2 src/artifacts/tap-token/AirdropBroker.json
+0 βˆ’340 src/artifacts/tap-token/FakeTapOFT.json
+2 βˆ’2 src/artifacts/tap-token/OTAP.json
+2 βˆ’2 src/artifacts/tap-token/TapOFT.json
+3 βˆ’48 src/artifacts/tap-token/TapiocaOptionBroker.json
+54 βˆ’14 src/artifacts/tap-token/TapiocaOptionLiquidityProvision.json
+2 βˆ’2 src/artifacts/tap-token/TwTAP.json
+2 βˆ’2 src/artifacts/tapiocaz/BaseTOFT.json
+2 βˆ’2 src/artifacts/tapiocaz/BaseTOFTMarketModule.json
+2 βˆ’2 src/artifacts/tapiocaz/BaseTOFTOptionsModule.json
+2 βˆ’2 src/artifacts/tapiocaz/BaseTOFTStrategyModule.json
+2 βˆ’2 src/artifacts/tapiocaz/TapiocaOFT.json
+2 βˆ’2 src/artifacts/tapiocaz/TapiocaWrapper.json
+2 βˆ’2 src/artifacts/tapiocaz/mTapiocaOFT.json
+20 βˆ’42 src/global__db
+0 βˆ’1 src/typechain/tap-token/factories/governance/index.ts
+0 βˆ’396 src/typechain/tap-token/factories/governance/mocks/FakeTapOFT__factory.ts
+0 βˆ’4 src/typechain/tap-token/factories/governance/mocks/index.ts
+1 βˆ’1 src/typechain/tap-token/factories/governance/twTAP.sol/TwTAP__factory.ts
+1 βˆ’1 src/typechain/tap-token/factories/option-airdrop/AirdropBroker__factory.ts
+1 βˆ’1 src/typechain/tap-token/factories/option-airdrop/aoTAP.sol/AOTAP__factory.ts
+2 βˆ’47 src/typechain/tap-token/factories/options/TapiocaOptionBroker__factory.ts
+53 βˆ’13 src/typechain/tap-token/factories/options/TapiocaOptionLiquidityProvision__factory.ts
+1 βˆ’1 src/typechain/tap-token/factories/options/oTAP.sol/OTAP__factory.ts
+1 βˆ’1 src/typechain/tap-token/factories/tokens/TapOFT__factory.ts
+0 βˆ’2 src/typechain/tap-token/governance/index.ts
+0 βˆ’1,049 src/typechain/tap-token/governance/mocks/FakeTapOFT.ts
+0 βˆ’4 src/typechain/tap-token/governance/mocks/index.ts
+0 βˆ’9 src/typechain/tap-token/hardhat.d.ts
+0 βˆ’2 src/typechain/tap-token/index.ts
+2 βˆ’155 src/typechain/tap-token/options/TapiocaOptionBroker.ts
+147 βˆ’34 src/typechain/tap-token/options/TapiocaOptionLiquidityProvision.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/TapiocaWrapper__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/BaseTOFT__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/MTapiocaOFT__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/TapiocaOFT__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/modules/BaseTOFTMarketModule__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/modules/BaseTOFTOptionsModule__factory.ts
+1 βˆ’1 src/typechain/tapiocaz/factories/tOFT/modules/BaseTOFTStrategyModule__factory.ts
2 changes: 1 addition & 1 deletion tapioca-periph

0 comments on commit 346e9f9

Please sign in to comment.