mirror of
https://github.com/placeholder-soft/gifted-contracts-v2.git
synced 2026-01-12 15:23:44 +08:00
chore: format files
This commit is contained in:
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
@@ -7,57 +7,42 @@ import "../interfaces/IERC6551Registry.sol";
|
||||
import "./lib/ERC6551BytecodeLib.sol";
|
||||
|
||||
contract ERC6551Registry is IERC6551Registry {
|
||||
error InitializationFailed();
|
||||
error InitializationFailed();
|
||||
|
||||
function createAccount(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 salt,
|
||||
bytes calldata initData
|
||||
) external returns (address) {
|
||||
bytes memory code = ERC6551BytecodeLib.getCreationCode(
|
||||
implementation,
|
||||
chainId,
|
||||
tokenContract,
|
||||
tokenId,
|
||||
salt
|
||||
);
|
||||
function createAccount(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 salt,
|
||||
bytes calldata initData
|
||||
) external returns (address) {
|
||||
bytes memory code = ERC6551BytecodeLib.getCreationCode(implementation, chainId, tokenContract, tokenId, salt);
|
||||
|
||||
address _account = Create2.computeAddress(bytes32(salt), keccak256(code));
|
||||
address _account = Create2.computeAddress(bytes32(salt), keccak256(code));
|
||||
|
||||
if (_account.code.length != 0) return _account;
|
||||
if (_account.code.length != 0) return _account;
|
||||
|
||||
emit AccountCreated(_account, implementation, chainId, tokenContract, tokenId, salt);
|
||||
emit AccountCreated(_account, implementation, chainId, tokenContract, tokenId, salt);
|
||||
|
||||
_account = Create2.deploy(0, bytes32(salt), code);
|
||||
_account = Create2.deploy(0, bytes32(salt), code);
|
||||
|
||||
if (initData.length != 0) {
|
||||
(bool success, ) = _account.call(initData);
|
||||
if (!success) revert InitializationFailed();
|
||||
}
|
||||
|
||||
return _account;
|
||||
if (initData.length != 0) {
|
||||
(bool success,) = _account.call(initData);
|
||||
if (!success) revert InitializationFailed();
|
||||
}
|
||||
|
||||
function account(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 salt
|
||||
) external view returns (address) {
|
||||
bytes32 bytecodeHash = keccak256(
|
||||
ERC6551BytecodeLib.getCreationCode(
|
||||
implementation,
|
||||
chainId,
|
||||
tokenContract,
|
||||
tokenId,
|
||||
salt
|
||||
)
|
||||
);
|
||||
return _account;
|
||||
}
|
||||
|
||||
return Create2.computeAddress(bytes32(salt), bytecodeHash);
|
||||
}
|
||||
function account(address implementation, uint256 chainId, address tokenContract, uint256 tokenId, uint256 salt)
|
||||
external
|
||||
view
|
||||
returns (address)
|
||||
{
|
||||
bytes32 bytecodeHash =
|
||||
keccak256(ERC6551BytecodeLib.getCreationCode(implementation, chainId, tokenContract, tokenId, salt));
|
||||
|
||||
return Create2.computeAddress(bytes32(salt), bytecodeHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,54 +5,39 @@ import "@openzeppelin/contracts/utils/Create2.sol";
|
||||
import "./ERC6551BytecodeLib.sol";
|
||||
|
||||
library ERC6551AccountLib {
|
||||
function computeAddress(
|
||||
address registry,
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 _salt
|
||||
) internal pure returns (address) {
|
||||
bytes32 bytecodeHash = keccak256(
|
||||
ERC6551BytecodeLib.getCreationCode(
|
||||
implementation,
|
||||
chainId,
|
||||
tokenContract,
|
||||
tokenId,
|
||||
_salt
|
||||
)
|
||||
);
|
||||
function computeAddress(
|
||||
address registry,
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 _salt
|
||||
) internal pure returns (address) {
|
||||
bytes32 bytecodeHash =
|
||||
keccak256(ERC6551BytecodeLib.getCreationCode(implementation, chainId, tokenContract, tokenId, _salt));
|
||||
|
||||
return Create2.computeAddress(bytes32(_salt), bytecodeHash, registry);
|
||||
return Create2.computeAddress(bytes32(_salt), bytecodeHash, registry);
|
||||
}
|
||||
|
||||
function token() internal view returns (uint256, address, uint256) {
|
||||
bytes memory footer = new bytes(0x60);
|
||||
|
||||
assembly {
|
||||
// copy 0x60 bytes from end of footer
|
||||
extcodecopy(address(), add(footer, 0x20), 0x4d, 0xad)
|
||||
}
|
||||
|
||||
function token()
|
||||
internal
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
address,
|
||||
uint256
|
||||
)
|
||||
{
|
||||
bytes memory footer = new bytes(0x60);
|
||||
return abi.decode(footer, (uint256, address, uint256));
|
||||
}
|
||||
|
||||
assembly {
|
||||
// copy 0x60 bytes from end of footer
|
||||
extcodecopy(address(), add(footer, 0x20), 0x4d, 0xad)
|
||||
}
|
||||
function salt() internal view returns (uint256) {
|
||||
bytes memory footer = new bytes(0x20);
|
||||
|
||||
return abi.decode(footer, (uint256, address, uint256));
|
||||
assembly {
|
||||
// copy 0x20 bytes from beginning of footer
|
||||
extcodecopy(address(), add(footer, 0x20), 0x2d, 0x4d)
|
||||
}
|
||||
|
||||
function salt() internal view returns (uint256) {
|
||||
bytes memory footer = new bytes(0x20);
|
||||
|
||||
assembly {
|
||||
// copy 0x20 bytes from beginning of footer
|
||||
extcodecopy(address(), add(footer, 0x20), 0x2d, 0x4d)
|
||||
}
|
||||
|
||||
return abi.decode(footer, (uint256));
|
||||
}
|
||||
return abi.decode(footer, (uint256));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
library ERC6551BytecodeLib {
|
||||
function getCreationCode(
|
||||
address implementation_,
|
||||
uint256 chainId_,
|
||||
address tokenContract_,
|
||||
uint256 tokenId_,
|
||||
uint256 salt_
|
||||
) internal pure returns (bytes memory) {
|
||||
return
|
||||
abi.encodePacked(
|
||||
hex"3d60ad80600a3d3981f3363d3d373d3d3d363d73",
|
||||
implementation_,
|
||||
hex"5af43d82803e903d91602b57fd5bf3",
|
||||
abi.encode(salt_, chainId_, tokenContract_, tokenId_)
|
||||
);
|
||||
}
|
||||
function getCreationCode(
|
||||
address implementation_,
|
||||
uint256 chainId_,
|
||||
address tokenContract_,
|
||||
uint256 tokenId_,
|
||||
uint256 salt_
|
||||
) internal pure returns (bytes memory) {
|
||||
return abi.encodePacked(
|
||||
hex"3d60ad80600a3d3981f3363d3d373d3d3d363d73",
|
||||
implementation_,
|
||||
hex"5af43d82803e903d91602b57fd5bf3",
|
||||
abi.encode(salt_, chainId_, tokenContract_, tokenId_)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,20 @@
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
interface IERC6551AccountProxy {
|
||||
function implementation() external view returns (address);
|
||||
function implementation() external view returns (address);
|
||||
}
|
||||
|
||||
/// @dev the ERC-165 identifier for this interface is `0xeff4d378`
|
||||
interface IERC6551Account {
|
||||
event TransactionExecuted(address indexed target, uint256 indexed value, bytes data);
|
||||
event TransactionExecuted(address indexed target, uint256 indexed value, bytes data);
|
||||
|
||||
receive() external payable;
|
||||
receive() external payable;
|
||||
|
||||
function executeCall(
|
||||
address to,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
) external payable returns (bytes memory);
|
||||
function executeCall(address to, uint256 value, bytes calldata data) external payable returns (bytes memory);
|
||||
|
||||
function token()
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId
|
||||
);
|
||||
function token() external view returns (uint256 chainId, address tokenContract, uint256 tokenId);
|
||||
|
||||
function owner() external view returns (address);
|
||||
function owner() external view returns (address);
|
||||
|
||||
function nonce() external view returns (uint256);
|
||||
function nonce() external view returns (uint256);
|
||||
}
|
||||
|
||||
@@ -2,29 +2,21 @@
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
interface IERC6551Registry {
|
||||
event AccountCreated(
|
||||
address account,
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 salt
|
||||
);
|
||||
event AccountCreated(
|
||||
address account, address implementation, uint256 chainId, address tokenContract, uint256 tokenId, uint256 salt
|
||||
);
|
||||
|
||||
function createAccount(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 seed,
|
||||
bytes calldata initData
|
||||
) external returns (address);
|
||||
function createAccount(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 seed,
|
||||
bytes calldata initData
|
||||
) external returns (address);
|
||||
|
||||
function account(
|
||||
address implementation,
|
||||
uint256 chainId,
|
||||
address tokenContract,
|
||||
uint256 tokenId,
|
||||
uint256 salt
|
||||
) external view returns (address);
|
||||
function account(address implementation, uint256 chainId, address tokenContract, uint256 tokenId, uint256 salt)
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ pragma solidity ^0.8.20;
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
interface IWETH is IERC20 {
|
||||
function deposit() external payable;
|
||||
function withdraw(uint256) external;
|
||||
function deposit() external payable;
|
||||
function withdraw(uint256) external;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user