Skip to content

Commit

Permalink
Develop (#1213)
Browse files Browse the repository at this point in the history
* Feat/sdk common js (#1191)

* feat(fractions): added strategy and tests

* feat(tests): update tests and tweak strat

* feat(test): fix all the test and clean comms

* fix(dist): moar contracts

* fix(tweak): little cleanups

* chore(lint): fix lint errors

* fix(lint): updated foundry lint

* feat(test): uncomment unused tests

* feat(bugs): cjs build and import alpha.13

* fix(only): unexpected only in sdk test

* feat(abis): updated SDK abis and restored tests (#1193)

* feat(abis): updated SDK abis and restored tests

* chore(bump): viem in fe

* fix(test): add currency admin to test (#1197)

* fix build error - set output:export in next config (#1199)

* fix build error

* lock nextjs version to 13.x.x

* add placeholder for transfer fraction button (#1201)

* add placeholder for transfer fraction button

* remove unnecessary logic from transfer-fraction-button.tsx

* change next build back to next export (#1202)

remove unnecessary logic from transfer-fraction-button.tsx

* Feature/transfer fraction button (#1203)

* add transfer fraction button inside split fraction button

* add confirmation dialog when transferring fraction

* use override chain id in hypercert fetcher within plasmic

* add reading of transfer restrictions to transfer fraction button

* add override chain id functionality for plasmic editing (#1204)

* Bugfix/add override chain id for plasmit editing (#1205)

* add override chain id functionality for plasmic editing

* add override chain id to effect dependencies

* remove transfer fraction button from split fraction button (#1206)

* Bugfix/only show transfer button for fraction owned (#1207)

* only show transfer button for fractions owned

* only show transfer button for fractions owned

* Feat/more robust split transfer logic with hc strategy (#1208)

* feat(hc): split NFT HC flow

* feat(hc): hypercert order routing and validation

* fix(e2e): disable faulty E2E tests

* Feat/docs tests cleanup (#1210)

* feat(checks): checkValidityHC, error code, 0.8.17

* feat(validator): overvalidator HC tests

* fix(clean): remove hyperboard references

* fix(lint): pragma protocol tests

* fix(pragma): restore FeeManagerRoy.. pragma

* feat(docs): updated version

* feat(build): docs 1.0.0-alpha

* Feat/docs tests cleanup (#1211)

* feat(checks): checkValidityHC, error code, 0.8.17

* feat(validator): overvalidator HC tests

* fix(clean): remove hyperboard references

* fix(lint): pragma protocol tests

* fix(pragma): restore FeeManagerRoy.. pragma

* feat(docs): updated version

* feat(build): docs 1.0.0-alpha

* chore(docs): natspec tweaks

* Feat/docs tests cleanup (#1212)

* feat(checks): checkValidityHC, error code, 0.8.17

* feat(validator): overvalidator HC tests

* fix(clean): remove hyperboard references

* fix(lint): pragma protocol tests

* fix(pragma): restore FeeManagerRoy.. pragma

* feat(docs): updated version

* feat(build): docs 1.0.0-alpha

* chore(docs): natspec tweaks

* feat(docs): docs sidebar

---------

Co-authored-by: Jip Stavenuiter <[email protected]>
  • Loading branch information
bitbeckers and Jipperism authored Dec 5, 2023
1 parent 582af93 commit 197968d
Show file tree
Hide file tree
Showing 375 changed files with 38,459 additions and 1,061 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ env:

# Trigger the workflow when:
on:
push:
branches:
- main
- develop
# Or when a pull request event occurs for a pull request against one of the
# matched branches.
pull_request:
branches:
- main
- develop
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion contracts/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rules": {
"avoid-low-level-calls": "off",
"code-complexity": ["error", 12],
"compiler-version": ["error", ">=0.8.16"],
"compiler-version": ["error", "0.8.17"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"no-console": "off",
"no-empty-blocks": "off",
Expand Down
2 changes: 1 addition & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ const config: HardhatUserConfig = {
path: "./abi",
runOnCompile: true,
clear: true,
pretty: true,
only: [
"CurrencyManager",
"ExecutionManager",
"HypercertMinter",
"LooksRareProtocol",
"OrderValidatorV2A",
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hypercerts-org/contracts",
"description": "EVM compatible protocol for managing impact claims",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.7",
"author": {
"name": "Hypercerts Foundation",
"url": "https://github.com/hypercerts-org/hypercerts"
Expand Down Expand Up @@ -65,6 +65,7 @@
"rimraf": "^5.0.5",
"rollup": "^4.0.2",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.0",
"rollup-plugin-node-polyfills": "^0.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"HypercertsExchange": {
"HypercertExchange": {
"address": "0x89524d8a0B1D7742579A7d8AE46D7679a4de1198",
"fullNamespace": "LooksRareProtocol",
"args": [
Expand Down
8 changes: 6 additions & 2 deletions contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import TransferManagerAbi from "../abi/src/marketplace/TransferManager.sol/Trans
import StrategyCollectionOfferAbi from "../abi/src/marketplace/executionStrategies/StrategyCollectionOffer.sol/StrategyCollectionOffer.json";
import StrategyHypercertFractionOfferAbi from "../abi/src/marketplace/executionStrategies/StrategyHypercertFractionOffer.sol/StrategyHypercertFractionOffer.json";
import CreatorFeeManagerWithRoyaltiesAbi from "../abi/src/marketplace/CreatorFeeManagerWithRoyalties.sol/CreatorFeeManagerWithRoyalties.json";
import ExecutionManagerAbi from "../abi/src/marketplace/ExecutionManager.sol/ExecutionManager.json";

import {
ExecutionManager,
HypercertMinter,
IHypercertToken,
LooksRareProtocol as HypercertExchange,
Expand Down Expand Up @@ -37,7 +39,7 @@ export type DeploymentProtocol = {
};

export type DeploymentMarketplace = {
HypercertsExchange: `0x${string}`;
HypercertExchange: `0x${string}`;
TransferManager: `0x${string}`;
OrderValidatorV2A: `0x${string}`;
};
Expand All @@ -49,7 +51,7 @@ export type DeployedChains = keyof typeof DEPLOYMENTS.protocol;
const deployments = {
5: {
...DEPLOYMENTS.protocol["5"],
HypercertsExchange: DEPLOYMENTS.marketplace[5].HypercertsExchange.address,
HypercertExchange: DEPLOYMENTS.marketplace[5].HypercertExchange.address,
TransferManager: DEPLOYMENTS.marketplace[5].TransferManager.address,
OrderValidatorV2A: DEPLOYMENTS.marketplace[5].OrderValidator.address,
},
Expand All @@ -74,6 +76,7 @@ export { deployments, asDeployedChain };
// Abis
export {
CreatorFeeManagerWithRoyaltiesAbi,
ExecutionManagerAbi,
HypercertMinterAbi,
HypercertExchangeAbi,
OrderValidatorV2AAbi,
Expand All @@ -86,6 +89,7 @@ export {
// Interfaces
export type {
CreatorFeeManagerWithRoyalties,
ExecutionManager,
IHypercertExchange,
IHypercertToken,
HypercertExchange,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/marketplace/CreatorFeeManagerWithRebates.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {IERC2981} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {IERC2981} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/marketplace/ExecutionManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// Libraries
import {OrderStructs} from "./libraries/OrderStructs.sol";
Expand Down
80 changes: 51 additions & 29 deletions contracts/src/marketplace/LooksRareProtocol.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {SignatureCheckerCalldata} from "@looksrare/contracts-libs/contracts/SignatureCheckerCalldata.sol";
Expand Down Expand Up @@ -31,13 +31,13 @@ import {
// Direct dependencies
import {TransferSelectorNFT} from "./TransferSelectorNFT.sol";
import {BatchOrderTypehashRegistry} from "./BatchOrderTypehashRegistry.sol";
import {StrategyHypercertFractionOffer} from "./executionStrategies/StrategyHypercertFractionOffer.sol";

// Constants
import {MAX_CALLDATA_PROOF_LENGTH, ONE_HUNDRED_PERCENT_IN_BP} from "./constants/NumericConstants.sol";

// Enums
import {QuoteType} from "./enums/QuoteType.sol";
import {CollectionType} from "./enums/CollectionType.sol";

/**
* @title LooksRareProtocol
Expand Down Expand Up @@ -371,7 +371,7 @@ contract LooksRareProtocol is
_updateUserOrderNonce(isNonceInvalidated, signer, makerBid.orderNonce, orderHash);

// Taker action goes first
_transferNFT(makerBid.collection, makerBid.collectionType, msg.sender, signer, itemIds, amounts);
_executeTakerAskTakerAction(makerBid, takerAsk, msg.sender, signer, itemIds, amounts);

// Maker action goes second
_transferToAskRecipientAndCreatorIfAny(recipients, feeAmounts, makerBid.currency, signer);
Expand Down Expand Up @@ -444,32 +444,7 @@ contract LooksRareProtocol is
_transferToAskRecipientAndCreatorIfAny(recipients, feeAmounts, makerAsk.currency, sender);

// Maker action goes second
if (
(
strategyInfo[makerAsk.strategyId].selector
== StrategyHypercertFractionOffer.executeHypercertFractionStrategyWithTakerBid.selector
|| strategyInfo[makerAsk.strategyId].selector
== StrategyHypercertFractionOffer.executeHypercertFractionStrategyWithTakerBidWithAllowlist.selector
) && (IHypercertToken(makerAsk.collection).unitsOf(makerAsk.itemIds[0]) > amounts[0])
) {
_splitNFT(
makerAsk.collection,
makerAsk.collectionType,
signer,
takerBid.recipient == address(0) ? sender : takerBid.recipient,
itemIds,
amounts
);
} else {
_transferNFT(
makerAsk.collection,
makerAsk.collectionType,
signer,
takerBid.recipient == address(0) ? sender : takerBid.recipient,
itemIds,
amounts
);
}
_executeTakerBidMakerAction(makerAsk, takerBid, signer, sender, itemIds, amounts);

emit TakerBid(
NonceInvalidationParameters({
Expand All @@ -492,6 +467,53 @@ contract LooksRareProtocol is
return feeAmounts[2];
}

function _executeTakerAskTakerAction(
OrderStructs.Maker calldata makerBid,
OrderStructs.Taker calldata takerAsk,
address sender,
address recipient,
uint256[] memory itemIds,
uint256[] memory amounts
) internal {
if (makerBid.collectionType == CollectionType.Hypercert) {
_transferHypercertFraction(
makerBid.collection, makerBid.collectionType, makerBid.strategyId, sender, recipient, itemIds, amounts
);
} else {
_transferNFT(makerBid.collection, makerBid.collectionType, sender, recipient, itemIds, amounts);
}
}

function _executeTakerBidMakerAction(
OrderStructs.Maker calldata makerAsk,
OrderStructs.Taker calldata takerBid,
address sender,
address recipient,
uint256[] memory itemIds,
uint256[] memory amounts
) internal {
if (makerAsk.collectionType == CollectionType.Hypercert) {
_transferHypercertFraction(
makerAsk.collection,
makerAsk.collectionType,
makerAsk.strategyId,
sender,
takerBid.recipient == address(0) ? recipient : takerBid.recipient,
itemIds,
amounts
);
} else {
_transferNFT(
makerAsk.collection,
makerAsk.collectionType,
sender,
takerBid.recipient == address(0) ? recipient : takerBid.recipient,
itemIds,
amounts
);
}
}

/**
* @notice This function is internal and is used to pay the protocol fee and affiliate fee (if any).
* @param currency Currency address to transfer (address(0) is ETH)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/marketplace/NonceManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// Interfaces and errors
import {INonceManager} from "./interfaces/INonceManager.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/marketplace/ProtocolFeeRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {LowLevelERC20Transfer} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC20Transfer.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/marketplace/StrategyManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {CurrencyManager} from "./CurrencyManager.sol";
Expand Down
28 changes: 18 additions & 10 deletions contracts/src/marketplace/TransferManager.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity 0.8.17;

// LooksRare unopinionated libraries
import {OwnableTwoSteps} from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol";
Expand All @@ -12,6 +12,7 @@ import {LowLevelHypercertCaller} from "./libraries/LowLevelHypercertCaller.sol";
// Interfaces and errors
import {ITransferManager} from "./interfaces/ITransferManager.sol";
import {AmountInvalid, LengthsInvalid} from "./errors/SharedErrors.sol";
import {UnitAmountInvalid} from "./errors/HypercertErrors.sol";
import {IHypercertToken} from "../protocol/interfaces/IHypercertToken.sol";

// Libraries
Expand All @@ -22,15 +23,14 @@ import {CollectionType} from "./enums/CollectionType.sol";

/**
* @title TransferManager
* @notice This contract provides the transfer functions for ERC721/ERC1155/Hypercert/Hyperboard for contracts that
* @notice This contract provides the transfer functions for ERC721/ERC1155/Hypercert for contracts that
* require them.
* Collection type "0" refers to ERC721 transfer functions.
* Collection type "1" refers to ERC1155 transfer functions.
* Collection type "2" refers to Hypercert transfer functions.
* Collection type "3" refers to Hyperboard transfer functions.
* @dev "Safe" transfer functions for ERC721 are not implemented since they come with added gas costs
* to verify if the recipient is a contract as it requires verifying the receiver interface is valid.
* @author LooksRare protocol team (👀,💎)
* @author LooksRare protocol team (👀,💎); bitbeckers
*/
contract TransferManager is
ITransferManager,
Expand Down Expand Up @@ -176,13 +176,13 @@ contract TransferManager is
}

/**
* @notice This function transfers items for a single Hypercert.
* @notice This function splits and transfers a fraction of a hypercert.
* @param collection Collection address
* @param from Sender address
* @param to Recipient address
* @param itemIds Array of itemIds
* @param amounts Array of amounts
* @dev It does not allow batch transferring if from = msg.sender since native function should be used.
* @dev It does not allow batch transferring.
*/
function splitItemsHypercert(
address collection,
Expand All @@ -191,8 +191,6 @@ contract TransferManager is
uint256[] calldata itemIds,
uint256[] calldata amounts
) external {
IHypercertToken hypercert = IHypercertToken(collection);

if (itemIds.length != 1 || amounts.length != 1) {
revert LengthsInvalid();
}
Expand All @@ -202,10 +200,20 @@ contract TransferManager is
if (amounts[0] == 0) {
revert AmountInvalid();
}

uint256[] memory newAmounts = new uint256[](2);
newAmounts[0] = hypercert.unitsOf(itemIds[0]) - amounts[0];

//The new amount is the difference between the total amount and the amount being split.
//This will underflow if the amount being split is greater than the total amount.
newAmounts[0] = IHypercertToken(collection).unitsOf(itemIds[0]) - amounts[0];
newAmounts[1] = amounts[0];
_executeHypercertSplitFraction(collection, from, to, itemIds[0], newAmounts);

// If the new amount is 0, then the split is will revert but the whole fraction can be transferred.
if (newAmounts[0] == 0) {
_executeERC1155SafeTransferFrom(collection, from, to, itemIds[0], 1);
} else {
_executeHypercertSplitFraction(collection, to, itemIds[0], newAmounts);
}
}

/**
Expand Down
Loading

0 comments on commit 197968d

Please sign in to comment.