forked from farcasterxyz/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bundler.sol
101 lines (87 loc) · 3.13 KB
/
Bundler.sol
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {IBundler} from "./interfaces/IBundler.sol";
import {IIdGateway} from "./interfaces/IIdGateway.sol";
import {IKeyGateway} from "./interfaces/IKeyGateway.sol";
import {TransferHelper} from "./libraries/TransferHelper.sol";
/**
* @title Farcaster Bundler
*
* @notice See https://github.com/farcasterxyz/contracts/blob/v3.1.0/docs/docs.md for an overview.
*
* @custom:security-contact [email protected]
*/
contract Bundler is IBundler {
using TransferHelper for address;
/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IBundler
*/
string public constant VERSION = "2023.11.15";
/*//////////////////////////////////////////////////////////////
IMMUTABLES
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IBundler
*/
IIdGateway public immutable idGateway;
/**
* @inheritdoc IBundler
*/
IKeyGateway public immutable keyGateway;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Configure the addresses of the IdGateway and KeyGateway contracts.
*
* @param _idGateway Address of the IdGateway contract
* @param _keyGateway Address of the KeyGateway contract
*/
constructor(address _idGateway, address _keyGateway) {
idGateway = IIdGateway(payable(_idGateway));
keyGateway = IKeyGateway(payable(_keyGateway));
}
/**
* @inheritdoc IBundler
*/
function price(uint256 extraStorage) external view returns (uint256) {
return idGateway.price(extraStorage);
}
/**
* @inheritdoc IBundler
*/
function register(
RegistrationParams calldata registerParams,
SignerParams[] calldata signerParams,
uint256 extraStorage
) external payable returns (uint256) {
(uint256 fid, uint256 overpayment) = idGateway.registerFor{value: msg.value}(
registerParams.to, registerParams.recovery, registerParams.deadline, registerParams.sig, extraStorage
);
uint256 signersLen = signerParams.length;
for (uint256 i; i < signersLen;) {
SignerParams calldata signer = signerParams[i];
keyGateway.addFor(
registerParams.to,
signer.keyType,
signer.key,
signer.metadataType,
signer.metadata,
signer.deadline,
signer.sig
);
// Safety: i can be incremented unchecked since it is bound by signerParams.length.
unchecked {
++i;
}
}
if (overpayment > 0) msg.sender.sendNative(overpayment);
return fid;
}
receive() external payable {
if (msg.sender != address(idGateway)) revert Unauthorized();
}
}