@latticexyz/world-modules 2.0.12-type-resolutions-effc7ab1 → 2.0.12-type-resolutions-ad8cc987
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cache/solidity-files-cache.json +1 -1
- package/package.json +9 -8
- package/src/index.sol +25 -0
- package/src/interfaces/IBaseWorld.sol +16 -0
- package/src/interfaces/IERC20System.sol +33 -0
- package/src/interfaces/IERC721System.sol +43 -0
- package/src/interfaces/IPuppetFactorySystem.sol +15 -0
- package/src/interfaces/IUniqueEntitySystem.sol +13 -0
- package/src/interfaces/IUnstable_CallWithSignatureSystem.sol +20 -0
- package/src/modules/callwithsignature/ECDSA.sol +174 -0
- package/src/modules/callwithsignature/IERC1271.sol +17 -0
- package/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol +9 -0
- package/src/modules/callwithsignature/SignatureChecker.sol +50 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol +48 -0
- package/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol +36 -0
- package/src/modules/callwithsignature/constants.sol +10 -0
- package/src/modules/callwithsignature/getSignedMessageHash.sol +54 -0
- package/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol +199 -0
- package/src/modules/callwithsignature/validateCallWithSignature.sol +31 -0
- package/src/modules/erc20-puppet/ERC20Module.sol +88 -0
- package/src/modules/erc20-puppet/ERC20System.sol +286 -0
- package/src/modules/erc20-puppet/IERC20.sol +94 -0
- package/src/modules/erc20-puppet/IERC20Errors.sol +49 -0
- package/src/modules/erc20-puppet/IERC20Events.sol +18 -0
- package/src/modules/erc20-puppet/IERC20Mintable.sol +25 -0
- package/src/modules/erc20-puppet/constants.sol +20 -0
- package/src/modules/erc20-puppet/registerERC20.sol +35 -0
- package/src/modules/erc20-puppet/tables/Allowances.sol +208 -0
- package/src/modules/erc20-puppet/tables/ERC20Metadata.sol +604 -0
- package/src/modules/erc20-puppet/tables/ERC20Registry.sol +199 -0
- package/src/modules/erc20-puppet/tables/TotalSupply.sol +184 -0
- package/src/modules/erc20-puppet/utils.sol +30 -0
- package/src/modules/erc721-puppet/ERC721Module.sol +95 -0
- package/src/modules/erc721-puppet/ERC721System.sol +531 -0
- package/src/modules/erc721-puppet/IERC721.sol +120 -0
- package/src/modules/erc721-puppet/IERC721Errors.sol +61 -0
- package/src/modules/erc721-puppet/IERC721Events.sol +23 -0
- package/src/modules/erc721-puppet/IERC721Metadata.sol +27 -0
- package/src/modules/erc721-puppet/IERC721Mintable.sol +53 -0
- package/src/modules/erc721-puppet/IERC721Receiver.sol +28 -0
- package/src/modules/erc721-puppet/constants.sol +23 -0
- package/src/modules/erc721-puppet/libraries/LibString.sol +77 -0
- package/src/modules/erc721-puppet/registerERC721.sol +37 -0
- package/src/modules/erc721-puppet/tables/ERC721Metadata.sol +703 -0
- package/src/modules/erc721-puppet/tables/ERC721Registry.sol +199 -0
- package/src/modules/erc721-puppet/tables/OperatorApproval.sol +220 -0
- package/src/modules/erc721-puppet/tables/Owners.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenApproval.sol +196 -0
- package/src/modules/erc721-puppet/tables/TokenURI.sol +450 -0
- package/src/modules/erc721-puppet/utils.sol +38 -0
- package/src/modules/keysintable/KeysInTableHook.sol +141 -0
- package/src/modules/keysintable/KeysInTableModule.sol +110 -0
- package/src/modules/keysintable/constants.sol +7 -0
- package/src/modules/keysintable/getKeysInTable.sol +81 -0
- package/src/modules/keysintable/hasKey.sol +28 -0
- package/src/modules/keysintable/query.sol +200 -0
- package/src/modules/keysintable/tables/KeysInTable.sol +1638 -0
- package/src/modules/keysintable/tables/UsedKeysIndex.sol +414 -0
- package/src/modules/keyswithvalue/KeysWithValueHook.sol +158 -0
- package/src/modules/keyswithvalue/KeysWithValueModule.sol +103 -0
- package/src/modules/keyswithvalue/constants.sol +7 -0
- package/src/modules/keyswithvalue/getKeysWithValue.sol +58 -0
- package/src/modules/keyswithvalue/getTargetTableId.sol +32 -0
- package/src/modules/keyswithvalue/tables/KeysWithValue.sol +668 -0
- package/src/modules/puppet/Puppet.sol +80 -0
- package/src/modules/puppet/PuppetDelegationControl.sol +17 -0
- package/src/modules/puppet/PuppetFactorySystem.sol +25 -0
- package/src/modules/puppet/PuppetMaster.sol +19 -0
- package/src/modules/puppet/PuppetModule.sol +64 -0
- package/src/modules/puppet/constants.sol +23 -0
- package/src/modules/puppet/createPuppet.sol +24 -0
- package/src/modules/puppet/tables/PuppetRegistry.sol +199 -0
- package/src/modules/puppet/utils.sol +10 -0
- package/src/modules/std-delegations/CallboundDelegationControl.sol +64 -0
- package/src/modules/std-delegations/StandardDelegationsModule.sol +55 -0
- package/src/modules/std-delegations/SystemboundDelegationControl.sol +54 -0
- package/src/modules/std-delegations/TimeboundDelegationControl.sol +27 -0
- package/src/modules/std-delegations/constants.sol +21 -0
- package/src/modules/std-delegations/tables/CallboundDelegations.sol +287 -0
- package/src/modules/std-delegations/tables/SystemboundDelegations.sol +256 -0
- package/src/modules/std-delegations/tables/TimeboundDelegations.sol +211 -0
- package/src/modules/tokens/tables/Balances.sol +196 -0
- package/src/modules/uniqueentity/UniqueEntityModule.sol +73 -0
- package/src/modules/uniqueentity/UniqueEntitySystem.sol +18 -0
- package/src/modules/uniqueentity/constants.sol +13 -0
- package/src/modules/uniqueentity/getUniqueEntity.sol +26 -0
- package/src/modules/uniqueentity/tables/UniqueEntity.sol +238 -0
- package/src/modules/utils/ArrayLib.sol +55 -0
- package/src/utils/AccessControlLib.sol +55 -0
- package/src/utils/SystemSwitch.sol +80 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
|
3
|
+
pragma solidity >=0.8.24;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @dev Standard ERC20 Errors
|
7
|
+
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
|
8
|
+
*/
|
9
|
+
interface IERC20Errors {
|
10
|
+
/**
|
11
|
+
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
|
12
|
+
* @param sender Address whose tokens are being transferred.
|
13
|
+
* @param balance Current balance for the interacting account.
|
14
|
+
* @param needed Minimum amount required to perform a transfer.
|
15
|
+
*/
|
16
|
+
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @dev Indicates a failure with the token `sender`. Used in transfers.
|
20
|
+
* @param sender Address whose tokens are being transferred.
|
21
|
+
*/
|
22
|
+
error ERC20InvalidSender(address sender);
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @dev Indicates a failure with the token `receiver`. Used in transfers.
|
26
|
+
* @param receiver Address to which tokens are being transferred.
|
27
|
+
*/
|
28
|
+
error ERC20InvalidReceiver(address receiver);
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
|
32
|
+
* @param spender Address that may be allowed to operate on tokens without being their owner.
|
33
|
+
* @param allowance Amount of tokens a `spender` is allowed to operate with.
|
34
|
+
* @param needed Minimum amount required to perform a transfer.
|
35
|
+
*/
|
36
|
+
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
|
40
|
+
* @param approver Address initiating an approval operation.
|
41
|
+
*/
|
42
|
+
error ERC20InvalidApprover(address approver);
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
|
46
|
+
* @param spender Address that may be allowed to operate on tokens without being their owner.
|
47
|
+
*/
|
48
|
+
error ERC20InvalidSpender(address spender);
|
49
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
interface IERC20Events {
|
5
|
+
/**
|
6
|
+
* @dev Emitted when `value` tokens are moved from one account (`from`) to
|
7
|
+
* another (`to`).
|
8
|
+
*
|
9
|
+
* Note that `value` may be zero.
|
10
|
+
*/
|
11
|
+
event Transfer(address indexed from, address indexed to, uint256 value);
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
|
15
|
+
* a call to {approve}. `value` is the new allowance.
|
16
|
+
*/
|
17
|
+
event Approval(address indexed owner, address indexed spender, uint256 value);
|
18
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
|
3
|
+
|
4
|
+
pragma solidity >=0.8.24;
|
5
|
+
|
6
|
+
import { IERC20 } from "./IERC20.sol";
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @dev Extending the ERC20 standard with permissioned mint and burn functions.
|
10
|
+
*/
|
11
|
+
interface IERC20Mintable is IERC20 {
|
12
|
+
/**
|
13
|
+
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
|
14
|
+
*
|
15
|
+
* Emits a {Transfer} event with `from` set to the zero address.
|
16
|
+
*/
|
17
|
+
function mint(address account, uint256 value) external;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
|
21
|
+
*
|
22
|
+
* Emits a {Transfer} event with `to` set to the zero address.
|
23
|
+
*/
|
24
|
+
function burn(address account, uint256 value) external;
|
25
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
4
|
+
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
|
5
|
+
import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";
|
6
|
+
|
7
|
+
bytes14 constant MODULE_NAMESPACE = "erc20-puppet";
|
8
|
+
ResourceId constant MODULE_NAMESPACE_ID = ResourceId.wrap(
|
9
|
+
bytes32(abi.encodePacked(RESOURCE_NAMESPACE, MODULE_NAMESPACE))
|
10
|
+
);
|
11
|
+
|
12
|
+
bytes16 constant ALLOWANCES_NAME = "Allowances";
|
13
|
+
bytes16 constant BALANCES_NAME = "Balances";
|
14
|
+
bytes16 constant TOTAL_SUPPLY_NAME = "TotalSupply";
|
15
|
+
bytes16 constant METADATA_NAME = "Metadata";
|
16
|
+
bytes16 constant ERC20_SYSTEM_NAME = "ERC20System";
|
17
|
+
|
18
|
+
ResourceId constant ERC20_REGISTRY_TABLE_ID = ResourceId.wrap(
|
19
|
+
bytes32(abi.encodePacked(RESOURCE_TABLE, MODULE_NAMESPACE, bytes16("ERC20Registry")))
|
20
|
+
);
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
|
5
|
+
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
|
6
|
+
import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
|
7
|
+
|
8
|
+
import { ERC20Module } from "./ERC20Module.sol";
|
9
|
+
import { MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
|
10
|
+
import { IERC20Mintable } from "./IERC20Mintable.sol";
|
11
|
+
|
12
|
+
import { ERC20MetadataData } from "./tables/ERC20Metadata.sol";
|
13
|
+
import { ERC20Registry } from "./tables/ERC20Registry.sol";
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @notice Register a new ERC20 token with the given metadata in a given namespace
|
17
|
+
* @dev This function must be called within a Store context (i.e. using StoreSwitch.setStoreAddress())
|
18
|
+
*/
|
19
|
+
function registerERC20(
|
20
|
+
IBaseWorld world,
|
21
|
+
bytes14 namespace,
|
22
|
+
ERC20MetadataData memory metadata
|
23
|
+
) returns (IERC20Mintable token) {
|
24
|
+
// Get the ERC20 module
|
25
|
+
ERC20Module erc20Module = ERC20Module(NamespaceOwner.get(MODULE_NAMESPACE_ID));
|
26
|
+
if (address(erc20Module) == address(0)) {
|
27
|
+
erc20Module = new ERC20Module();
|
28
|
+
}
|
29
|
+
|
30
|
+
// Install the ERC20 module with the provided args
|
31
|
+
world.installModule(erc20Module, abi.encode(namespace, metadata));
|
32
|
+
|
33
|
+
// Return the newly created ERC20 token
|
34
|
+
token = IERC20Mintable(ERC20Registry.get(ERC20_REGISTRY_TABLE_ID, WorldResourceIdLib.encodeNamespace(namespace)));
|
35
|
+
}
|
@@ -0,0 +1,208 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
pragma solidity >=0.8.24;
|
3
|
+
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
5
|
+
|
6
|
+
// Import store internals
|
7
|
+
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
8
|
+
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
9
|
+
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
10
|
+
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
11
|
+
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
12
|
+
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
13
|
+
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
14
|
+
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
15
|
+
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
16
|
+
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
17
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
18
|
+
|
19
|
+
library Allowances {
|
20
|
+
FieldLayout constant _fieldLayout =
|
21
|
+
FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
|
22
|
+
|
23
|
+
// Hex-encoded key schema of (address, address)
|
24
|
+
Schema constant _keySchema = Schema.wrap(0x0028020061610000000000000000000000000000000000000000000000000000);
|
25
|
+
// Hex-encoded value schema of (uint256)
|
26
|
+
Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @notice Get the table's key field names.
|
30
|
+
* @return keyNames An array of strings with the names of key fields.
|
31
|
+
*/
|
32
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
33
|
+
keyNames = new string[](2);
|
34
|
+
keyNames[0] = "account";
|
35
|
+
keyNames[1] = "spender";
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @notice Get the table's value field names.
|
40
|
+
* @return fieldNames An array of strings with the names of value fields.
|
41
|
+
*/
|
42
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
43
|
+
fieldNames = new string[](1);
|
44
|
+
fieldNames[0] = "value";
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @notice Register the table with its config.
|
49
|
+
*/
|
50
|
+
function register(ResourceId _tableId) internal {
|
51
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @notice Register the table with its config.
|
56
|
+
*/
|
57
|
+
function _register(ResourceId _tableId) internal {
|
58
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @notice Get value.
|
63
|
+
*/
|
64
|
+
function getValue(ResourceId _tableId, address account, address spender) internal view returns (uint256 value) {
|
65
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
66
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
67
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
68
|
+
|
69
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
70
|
+
return (uint256(bytes32(_blob)));
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* @notice Get value.
|
75
|
+
*/
|
76
|
+
function _getValue(ResourceId _tableId, address account, address spender) internal view returns (uint256 value) {
|
77
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
78
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
79
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
80
|
+
|
81
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
82
|
+
return (uint256(bytes32(_blob)));
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @notice Get value.
|
87
|
+
*/
|
88
|
+
function get(ResourceId _tableId, address account, address spender) internal view returns (uint256 value) {
|
89
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
90
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
91
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
92
|
+
|
93
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
94
|
+
return (uint256(bytes32(_blob)));
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* @notice Get value.
|
99
|
+
*/
|
100
|
+
function _get(ResourceId _tableId, address account, address spender) internal view returns (uint256 value) {
|
101
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
102
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
103
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
104
|
+
|
105
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
106
|
+
return (uint256(bytes32(_blob)));
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* @notice Set value.
|
111
|
+
*/
|
112
|
+
function setValue(ResourceId _tableId, address account, address spender, uint256 value) internal {
|
113
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
114
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
115
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
116
|
+
|
117
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* @notice Set value.
|
122
|
+
*/
|
123
|
+
function _setValue(ResourceId _tableId, address account, address spender, uint256 value) internal {
|
124
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
125
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
126
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
127
|
+
|
128
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* @notice Set value.
|
133
|
+
*/
|
134
|
+
function set(ResourceId _tableId, address account, address spender, uint256 value) internal {
|
135
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
136
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
137
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
138
|
+
|
139
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* @notice Set value.
|
144
|
+
*/
|
145
|
+
function _set(ResourceId _tableId, address account, address spender, uint256 value) internal {
|
146
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
147
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
148
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
149
|
+
|
150
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* @notice Delete all data for given keys.
|
155
|
+
*/
|
156
|
+
function deleteRecord(ResourceId _tableId, address account, address spender) internal {
|
157
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
158
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
159
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
160
|
+
|
161
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @notice Delete all data for given keys.
|
166
|
+
*/
|
167
|
+
function _deleteRecord(ResourceId _tableId, address account, address spender) internal {
|
168
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
169
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
170
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
171
|
+
|
172
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
177
|
+
* @return The static data, encoded into a sequence of bytes.
|
178
|
+
*/
|
179
|
+
function encodeStatic(uint256 value) internal pure returns (bytes memory) {
|
180
|
+
return abi.encodePacked(value);
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @notice Encode all of a record's fields.
|
185
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
186
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
187
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
188
|
+
*/
|
189
|
+
function encode(uint256 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
190
|
+
bytes memory _staticData = encodeStatic(value);
|
191
|
+
|
192
|
+
EncodedLengths _encodedLengths;
|
193
|
+
bytes memory _dynamicData;
|
194
|
+
|
195
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
200
|
+
*/
|
201
|
+
function encodeKeyTuple(address account, address spender) internal pure returns (bytes32[] memory) {
|
202
|
+
bytes32[] memory _keyTuple = new bytes32[](2);
|
203
|
+
_keyTuple[0] = bytes32(uint256(uint160(account)));
|
204
|
+
_keyTuple[1] = bytes32(uint256(uint160(spender)));
|
205
|
+
|
206
|
+
return _keyTuple;
|
207
|
+
}
|
208
|
+
}
|