Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…contracts into foundry-optimisation
  • Loading branch information
skimaharvey committed Nov 30, 2023
2 parents d099cac + 1bd2f5f commit 620f54a
Show file tree
Hide file tree
Showing 117 changed files with 3,352 additions and 531 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
bump-minor-pre-major: true
default-branch: main
changelog-types: '[{"type": "feat!","section":"BREAKING CHANGES","hidden": false},{"type": "refactor!","section":"BREAKING CHANGES","hidden": false},{"type": "build!","section":"BREAKING CHANGES","hidden": false},{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
command: manifest

# The logic below handles the npm publication.
# The `if` statements ensure that a publication only occurs when
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import {
ERC725YDataKeys,
PERMISSIONS,
ALL_PERMISSIONS,
LSP8_TOKEN_ID_TYPES,
LSP8_TOKEN_ID_SCHEMA,
LSP25_VERSION,
ErrorSelectors,
EventSigHashes,
Expand Down Expand Up @@ -121,7 +121,7 @@ import {
ImageMetadata,
LinkMetadata,
AssetMetadata,
} from "@lukso/lsp-smart-contracts/constants";
} from "@lukso/lsp-smart-contracts";
```

## Audits
Expand Down
38 changes: 29 additions & 9 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const INTERFACE_IDS = {
LSP1UniversalReceiverDelegate: '0xa245bbda',
LSP6KeyManager: '0x23f34c62',
LSP7DigitalAsset: '0xb3c4928f',
LSP8IdentifiableDigitalAsset: '0x59bf8640',
LSP8IdentifiableDigitalAsset: '0xecad9f75',
LSP9Vault: '0x28af17e6',
LSP11BasicSocialRecovery: '0x049a28f1',
LSP14Ownable2Step: '0x94be5999',
Expand Down Expand Up @@ -192,6 +192,9 @@ export const ERC725YDataKeys = {
// keccak256('LSP4TokenSymbol')
LSP4TokenSymbol: '0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756',

// keccak256('LSP4TokenType)
LSP4TokenType: '0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3',

// keccak256('LSP4Metadata')
LSP4Metadata: '0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e',

Expand Down Expand Up @@ -233,8 +236,7 @@ export const ERC725YDataKeys = {
'AddressPermissions:AllowedCalls': '0x4b80742de2bf393a64c70000',
},
LSP8: {
LSP8TokenIdType: '0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4',
LSP8MetadataTokenURI: '0x1339e76a390b7b9ec9010000',
LSP8TokenIdSchema: '0x341bc44e55234544c70af9d37b2cb8cc7ba74685b58526221de2cc977f469924',
LSP8TokenMetadataBaseURI: '0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843',
LSP8ReferenceContract: '0x708e7b881795f2e6b6c2752108c177ec89248458de3bf69d0d43480b3e5034e6',
},
Expand Down Expand Up @@ -390,19 +392,37 @@ export const LSP1_TYPE_IDS = {
'0xe32c7debcb817925ba4883fdbfc52797187f28f73f860641dab1a68d9b32902c',
};

// LSP4
// ----------

/**
* @dev list of LSP4 Token types to describe the type of token a digital asset contract represents.
* @see for details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-4-DigitalAsset-Metadata.md#lsp4tokentype
*/
export const LSP4_TOKEN_TYPES = {
TOKEN: 0,
NFT: 1,
COLLECTION: 2,
};

// LSP8
// ----------

/**
* @dev list of LSP8 Token ID types that can be used to create different types of NFTs.
* @see for details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md#lsp8tokenidtype
* @dev list of LSP8 Token ID Schemas that can be used to create different types of NFTs and represent each NFT identifiers differently.
* @see for details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md#lsp8tokenidschema
*/
export const LSP8_TOKEN_ID_TYPES = {
export const LSP8_TOKEN_ID_SCHEMA = {
NUMBER: 0,
STRING: 1,
UNIQUE_ID: 2,
HASH: 3,
ADDRESS: 4,
ADDRESS: 2,
UNIQUE_ID: 3,
HASH: 4,
MIXED_DEFAULT_NUMBER: 100,
MIXED_DEFAULT_STRING: 101,
MIXED_DEFAULT_ADDRESS: 102,
MIXED_DEFAULT_UNIQUE_ID: 103,
MIXED_DEFAULT_HASH: 104,
};

// LSP25
Expand Down
22 changes: 0 additions & 22 deletions contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";

// libraries
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {
ERC165Checker
Expand Down Expand Up @@ -874,25 +873,4 @@ abstract contract LSP0ERC725AccountCore is

return (address(bytes20(extensionData)), false);
}

/**
* @dev This function overrides the {ERC725YCore} internal {_setData} function to optimize gas usage by emitting only the first 256 bytes of the `dataValue`.
*
* @custom:events {DataChanged} event with only the first 256 bytes of {dataValue}.
*
* @param dataKey The key to store the data value under.
* @param dataValue The data value to be stored.
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
ERC725YCore._store[dataKey] = dataValue;
emit DataChanged(
dataKey,
dataValue.length <= 256
? dataValue
: BytesLib.slice(dataValue, 0, 256)
);
}
}
9 changes: 9 additions & 0 deletions contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

// Token types

uint256 constant _LSP4_TOKEN_TYPE_TOKEN = 0;
uint256 constant _LSP4_TOKEN_TYPE_NFT = 1;
uint256 constant _LSP4_TOKEN_TYPE_COLLECTION = 2;

// --- ERC725Y entries

// bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
Expand All @@ -15,6 +21,9 @@ bytes32 constant _LSP4_TOKEN_NAME_KEY = 0xdeba1e292f8ba88238e10ab3c7f88bd4be4fac
// keccak256('LSP4TokenSymbol')
bytes32 constant _LSP4_TOKEN_SYMBOL_KEY = 0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756;

// keccak256('LSP4TokenType')
bytes32 constant _LSP4_TOKEN_TYPE_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3;

// keccak256('LSP4Creators[]')
bytes32 constant _LSP4_CREATORS_ARRAY_KEY = 0x114bd03b3a46d48759680d81ebb2b414fda7d030a7105a851867accf1c2352e7;

Expand Down
54 changes: 20 additions & 34 deletions contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,60 @@ pragma solidity ^0.8.4;

// modules
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";

// libraries
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
import {LSP4DigitalAssetMetadataCore} from "./LSP4DigitalAssetMetadataCore.sol";

// constants
import {
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE,
_LSP4_TOKEN_NAME_KEY,
_LSP4_TOKEN_SYMBOL_KEY
_LSP4_TOKEN_SYMBOL_KEY,
_LSP4_TOKEN_TYPE_KEY
} from "./LSP4Constants.sol";

// errors
import {
LSP4TokenNameNotEditable,
LSP4TokenSymbolNotEditable
} from "./LSP4Errors.sol";

/**
* @title Implementation of a LSP4DigitalAssetMetadata contract that stores the **Token-Metadata** (`LSP4TokenName` and `LSP4TokenSymbol`) in its ERC725Y data store.
* @author Matthew Stevens
* @dev Standard Implementation of the LSP4 standard.
*/
abstract contract LSP4DigitalAssetMetadata is ERC725Y {
abstract contract LSP4DigitalAssetMetadata is
ERC725Y,
LSP4DigitalAssetMetadataCore
{
/**
* @notice Deploying a digital asset `name_` with the `symbol_` symbol.
*
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param initialOwner_ The owner of the token contract
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param initialOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
constructor(
string memory name_,
string memory symbol_,
address initialOwner_
address initialOwner_,
uint256 lsp4TokenType_
) ERC725Y(initialOwner_) {
// set data key SupportedStandards:LSP4DigitalAsset
super._setData(
ERC725YCore._setData(
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE
);

super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
ERC725YCore._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
ERC725YCore._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
ERC725YCore._setData(_LSP4_TOKEN_TYPE_KEY, abi.encode(lsp4TokenType_));
}

/**
* @dev The ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @dev Save gas by emitting the {DataChanged} event with only the first 256 bytes of dataValue
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
revert LSP4TokenNameNotEditable();
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
revert LSP4TokenSymbolNotEditable();
} else {
_store[dataKey] = dataValue;
emit DataChanged(
dataKey,
dataValue.length <= 256
? dataValue
: BytesLib.slice(dataValue, 0, 256)
);
}
) internal virtual override(ERC725YCore, LSP4DigitalAssetMetadataCore) {
LSP4DigitalAssetMetadataCore._setData(dataKey, dataValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

// modules
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";

// constants
import {
_LSP4_TOKEN_NAME_KEY,
_LSP4_TOKEN_SYMBOL_KEY,
_LSP4_TOKEN_TYPE_KEY
} from "./LSP4Constants.sol";

// errors
import {
LSP4TokenNameNotEditable,
LSP4TokenSymbolNotEditable,
LSP4TokenTypeNotEditable
} from "./LSP4Errors.sol";

/**
* @title Implementation of a LSP4DigitalAssetMetadata contract that stores the **Token-Metadata** (`LSP4TokenName` and `LSP4TokenSymbol`) in its ERC725Y data store.
* @author Matthew Stevens
* @dev Standard Implementation of the LSP4 standard.
*/
abstract contract LSP4DigitalAssetMetadataCore is ERC725YCore {
/**
* @dev The ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
* via this function once the digital asset contract has been deployed.
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
revert LSP4TokenNameNotEditable();
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
revert LSP4TokenSymbolNotEditable();
} else if (dataKey == _LSP4_TOKEN_TYPE_KEY) {
revert LSP4TokenTypeNotEditable();
} else {
_store[dataKey] = dataValue;

emit DataChanged(dataKey, dataValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,63 @@ import {
ERC725YInitAbstract
} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";

// libraries
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";

import {LSP4DigitalAssetMetadataCore} from "./LSP4DigitalAssetMetadataCore.sol";

// constants
import {
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE,
_LSP4_TOKEN_NAME_KEY,
_LSP4_TOKEN_SYMBOL_KEY
_LSP4_TOKEN_SYMBOL_KEY,
_LSP4_TOKEN_TYPE_KEY
} from "./LSP4Constants.sol";

// errors
import {
LSP4TokenNameNotEditable,
LSP4TokenSymbolNotEditable
} from "./LSP4Errors.sol";

/**
* @title Implementation of a LSP4DigitalAssetMetadata contract that stores the **Token-Metadata** (`LSP4TokenName` and `LSP4TokenSymbol`) in its ERC725Y data store.
* @author Matthew Stevens
* @dev Inheritable Proxy Implementation of the LSP4 standard.
*/
abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
abstract contract LSP4DigitalAssetMetadataInitAbstract is
LSP4DigitalAssetMetadataCore,
ERC725YInitAbstract
{
/**
* @notice Initializing a digital asset `name_` with the `symbol_` symbol.
*
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param initialOwner_ The owner of the token contract
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection)
*/
function _initialize(
string memory name_,
string memory symbol_,
address initialOwner_
address initialOwner_,
uint256 lsp4TokenType_
) internal virtual onlyInitializing {
ERC725YInitAbstract._initialize(initialOwner_);

// set data key SupportedStandards:LSP4DigitalAsset
super._setData(
ERC725YCore._setData(
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE
);

super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
ERC725YCore._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
ERC725YCore._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
ERC725YCore._setData(_LSP4_TOKEN_TYPE_KEY, abi.encode(lsp4TokenType_));
}

/**
* @dev the ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
* @dev The ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @dev Save gas by emitting the {DataChanged} event with only the first 256 bytes of dataValue
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
revert LSP4TokenNameNotEditable();
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
revert LSP4TokenSymbolNotEditable();
} else {
_store[dataKey] = dataValue;
emit DataChanged(
dataKey,
dataValue.length <= 256
? dataValue
: BytesLib.slice(dataValue, 0, 256)
);
}
) internal virtual override(ERC725YCore, LSP4DigitalAssetMetadataCore) {
LSP4DigitalAssetMetadataCore._setData(dataKey, dataValue);
}
}
Loading

0 comments on commit 620f54a

Please sign in to comment.