Skip to content
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

CU-85ztxzhp0: decode & send the exact value for payable methods #97

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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