forked from debridge-finance/evm-sol-serializer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilder.sol
More file actions
48 lines (42 loc) · 1.26 KB
/
Builder.sol
File metadata and controls
48 lines (42 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.0;
import './ClaimOrderUnlockBuilder.sol';
import './InitWalletIfNeededBuilder.sol';
import './DlnOrderLib.sol';
library DlnBuilder {
function serializeClaimOrderUnlock(
uint64 initReward,
uint64 claimUnlockReward,
bytes32 unlockBeneficiary,
uint256 orderId,
DlnOrderLib.Order memory order
) internal view returns (bytes memory data) {
data = abi.encodePacked(
DlnInitWalletIfNeededBuilder.getSerializedInitWalletIfNeededExternalInstruction(
initReward,
unlockBeneficiary,
toBytes32(order.giveTokenAddress, 0)
),
DlnClaimOrderUnlockBuilder.getSerializedClaimOrderUnlockExternalInstruction(
claimUnlockReward,
unlockBeneficiary,
orderId,
getChainId(),
toBytes32(order.giveTokenAddress, 0)
)
);
}
function getChainId() private view returns (uint256 cid) {
assembly {
cid := chainid()
}
}
function toBytes32(bytes memory _bytes, uint256 _start) private pure returns (bytes32) {
require(_bytes.length >= _start + 32, 'toBytes32_outOfBounds');
bytes32 tempBytes32;
assembly {
tempBytes32 := mload(add(add(_bytes, 0x20), _start))
}
return tempBytes32;
}
}