Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(integration): replace mock ERC20 with Wrapped IP token (WIP) #190

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@openzeppelin/contracts-upgradeable": "5.2.0",
"@story-protocol/protocol-core": "github:storyprotocol/protocol-core-v1#v1.3.1",
"erc6551": "^0.3.1",
"solady": "^0.0.281"
"solady": "^0.0.281",
"wip": "github:piplabs/wip#main"
}
}
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
@storyprotocol/script/=node_modules/@story-protocol/protocol-core/script/foundry/
@storyprotocol/test/=node_modules/@story-protocol/protocol-core/test/foundry/
@solady/=node_modules/solady/
solady/tokens/=node_modules/solady/src/tokens/
@wip/=node_modules/wip/src/
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
2 changes: 1 addition & 1 deletion script/deployment/StoryNFT.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ILicenseRegistry } from "@storyprotocol/core/interfaces/registries/ILic
import { DeployHelper } from "../utils/DeployHelper.sol";

contract StoryNFT is DeployHelper {
address internal CREATE3_DEPLOYER = 0x384a891dFDE8180b054f04D66379f16B7a678Ad6;
address internal CREATE3_DEPLOYER = 0x9fBB3DF7C40Da2e5A0dE984fFE2CCB7C47cd0ABf;
uint256 private constant CREATE3_DEFAULT_SEED = 1234567890;
constructor() DeployHelper(CREATE3_DEPLOYER) {}

Expand Down
8 changes: 0 additions & 8 deletions script/utils/StoryProtocolPeripheryAddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ contract StoryProtocolPeripheryAddressManager is Script {
address internal royaltyTokenDistributionWorkflowsAddr;
address internal spgNftBeaconAddr;
address internal spgNftImplAddr;
address internal defaultOrgStoryNftTemplateAddr;
address internal defaultOrgStoryNftBeaconAddr;
address internal orgNftAddr;
address internal orgStoryNftFactoryAddr;

function _readStoryProtocolPeripheryAddresses() internal {
string memory root = vm.projectRoot();
Expand All @@ -35,9 +31,5 @@ contract StoryProtocolPeripheryAddressManager is Script {
royaltyTokenDistributionWorkflowsAddr = json.readAddress(".main.RoyaltyTokenDistributionWorkflows");
spgNftBeaconAddr = json.readAddress(".main.SPGNFTBeacon");
spgNftImplAddr = json.readAddress(".main.SPGNFTImpl");
defaultOrgStoryNftTemplateAddr = json.readAddress(".main.DefaultOrgStoryNFTTemplate");
defaultOrgStoryNftBeaconAddr = json.readAddress(".main.DefaultOrgStoryNFTBeacon");
orgNftAddr = json.readAddress(".main.OrgNFT");
orgStoryNftFactoryAddr = json.readAddress(".main.OrgStoryNFTFactory");
}
}
18 changes: 8 additions & 10 deletions script/utils/upgrades/UpgradeHelper.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ contract UpgradeHelper is
SPGNFT internal spgNftImpl;
UpgradeableBeacon internal spgNftBeacon;

// TODO: change these four addresses when upgrading Story NFTs
address public orgNftAddr = address(0x1);
address public orgStoryNftFactoryAddr = address(0x2);
address public defaultOrgStoryNftBeaconAddr = address(0x3);
address public defaultOrgStoryNftTemplateAddr = address(0x4);

constructor() JsonDeploymentHandler("main") {}

function run() public virtual {
Expand Down Expand Up @@ -73,7 +79,7 @@ contract UpgradeHelper is
}

function _writeAllAddresses() internal {
string[] memory contractKeys = new string[](12);
string[] memory contractKeys = new string[](8);
contractKeys[0] = "DerivativeWorkflows";
contractKeys[1] = "GroupingWorkflows";
contractKeys[2] = "LicenseAttachmentWorkflows";
Expand All @@ -82,12 +88,8 @@ contract UpgradeHelper is
contractKeys[5] = "RoyaltyTokenDistributionWorkflows";
contractKeys[6] = "SPGNFTBeacon";
contractKeys[7] = "SPGNFTImpl";
contractKeys[8] = "DefaultOrgStoryNFTTemplate";
contractKeys[9] = "DefaultOrgStoryNFTBeacon";
contractKeys[10] = "OrgNFT";
contractKeys[11] = "OrgStoryNFTFactory";

address[] memory addresses = new address[](12);
address[] memory addresses = new address[](8);
addresses[0] = derivativeWorkflowsAddr;
addresses[1] = groupingWorkflowsAddr;
addresses[2] = licenseAttachmentWorkflowsAddr;
Expand All @@ -96,10 +98,6 @@ contract UpgradeHelper is
addresses[5] = royaltyTokenDistributionWorkflowsAddr;
addresses[6] = spgNftBeaconAddr;
addresses[7] = spgNftImplAddr;
addresses[8] = defaultOrgStoryNftTemplateAddr;
addresses[9] = defaultOrgStoryNftBeaconAddr;
addresses[10] = orgNftAddr;
addresses[11] = orgStoryNftFactoryAddr;

for (uint256 i = 0; i < contractKeys.length; i++) {
_writeAddress(contractKeys[i], addresses[i]);
Expand Down
10 changes: 5 additions & 5 deletions test/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity 0.8.26;
import { console2 } from "forge-std/console2.sol";
import { Script } from "forge-std/Script.sol";
import { Test } from "forge-std/Test.sol";
import { SUSD } from "@storyprotocol/test/mocks/token/SUSD.sol";
import { WIP } from "@wip/WIP.sol";
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import { AccessPermission } from "@storyprotocol/core/lib/AccessPermission.sol";
import { IAccessController } from "@storyprotocol/core/interfaces/access/IAccessController.sol";
Expand Down Expand Up @@ -59,8 +59,8 @@ contract BaseIntegration is Test, Script, StoryProtocolCoreAddressManager, Story
RoyaltyWorkflows internal royaltyWorkflows;
RoyaltyTokenDistributionWorkflows internal royaltyTokenDistributionWorkflows;

/// @dev Story USD
SUSD internal StoryUSD = SUSD(0xF2104833d386a2734a4eB3B8ad6FC6812F29E38E);
/// @dev Wrapped IP token
WIP internal wrappedIP = WIP(payable(0x1514000000000000000000000000000000000000));

/// @dev Test data
string internal testCollectionName;
Expand Down Expand Up @@ -116,8 +116,8 @@ contract BaseIntegration is Test, Script, StoryProtocolCoreAddressManager, Story
testBaseURI = "https://test.com/";
testContractURI = "https://test-contract-uri.com/";
testMaxSupply = 100_000;
testMintFee = 10 * 10 ** StoryUSD.decimals(); // 10 SUSD
testMintFeeToken = address(StoryUSD);
testMintFee = 1 * 10 ** wrappedIP.decimals(); // 1 WIP
testMintFeeToken = address(wrappedIP);
testIpMetadata = WorkflowStructs.IPMetadata({
ipMetadataURI: "test-ip-uri",
ipMetadataHash: "test-ip-hash",
Expand Down
40 changes: 20 additions & 20 deletions test/integration/workflows/DerivativeIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ contract DerivativeIntegration is BaseIntegration {
private
logTest("test_DerivativeIntegration_mintAndRegisterIpAndMakeDerivative")
{
StoryUSD.mint(testSender, testMintFee * 2);
StoryUSD.approve(address(spgNftContract), testMintFee); // for nft minting fee
StoryUSD.approve(derivativeWorkflowsAddr, testMintFee); // for derivative minting fee
wrappedIP.deposit{ value: testMintFee * 2 }(); // wrapping native IP
wrappedIP.approve(address(spgNftContract), testMintFee); // for nft minting fee
wrappedIP.approve(derivativeWorkflowsAddr, testMintFee); // for derivative minting fee
(address childIpId, uint256 childTokenId) = derivativeWorkflows.mintAndRegisterIpAndMakeDerivative({
spgNftContract: address(spgNftContract),
derivData: WorkflowStructs.MakeDerivative({
Expand Down Expand Up @@ -87,8 +87,8 @@ contract DerivativeIntegration is BaseIntegration {
private
logTest("test_DerivativeIntegration_registerIpAndMakeDerivative")
{
StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee); // for nft minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee); // for nft minting fee

uint256 childTokenId = spgNftContract.mint({
to: testSender,
Expand All @@ -112,8 +112,8 @@ contract DerivativeIntegration is BaseIntegration {
signerSk: testSenderSk
});

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(derivativeWorkflowsAddr, testMintFee); // for derivative minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(derivativeWorkflowsAddr, testMintFee); // for derivative minting fee
derivativeWorkflows.registerIpAndMakeDerivative({
nftContract: address(spgNftContract),
tokenId: childTokenId,
Expand Down Expand Up @@ -157,8 +157,8 @@ contract DerivativeIntegration is BaseIntegration {
private
logTest("test_DerivativeIntegration_mintAndRegisterIpAndMakeDerivativeWithLicenseTokens")
{
StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(royaltyModuleAddr, testMintFee); // for license token minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(royaltyModuleAddr, testMintFee); // for license token minting fee
uint256 startLicenseTokenId = licensingModule.mintLicenseTokens({
licensorIpId: parentIpIds[0],
licenseTemplate: parentLicenseTemplate,
Expand All @@ -176,8 +176,8 @@ contract DerivativeIntegration is BaseIntegration {
uint256[] memory licenseTokenIds = new uint256[](1);
licenseTokenIds[0] = startLicenseTokenId;

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee); // for nft minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee); // for nft minting fee
(address childIpId, uint256 childTokenId) = derivativeWorkflows
.mintAndRegisterIpAndMakeDerivativeWithLicenseTokens({
spgNftContract: address(spgNftContract),
Expand Down Expand Up @@ -213,8 +213,8 @@ contract DerivativeIntegration is BaseIntegration {
private
logTest("test_DerivativeIntegration_registerIpAndMakeDerivativeWithLicenseTokens")
{
StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee); // for nft minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee); // for nft minting fee
uint256 childTokenId = spgNftContract.mint({
to: testSender,
nftMetadataURI: testIpMetadata.nftMetadataURI,
Expand All @@ -225,8 +225,8 @@ contract DerivativeIntegration is BaseIntegration {

uint256 deadline = block.timestamp + 1000;

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(royaltyModuleAddr, testMintFee); // for license token minting fee
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(royaltyModuleAddr, testMintFee); // for license token minting fee
uint256 startLicenseTokenId = licensingModule.mintLicenseTokens({
licensorIpId: parentIpIds[0],
licenseTemplate: parentLicenseTemplate,
Expand Down Expand Up @@ -315,9 +315,9 @@ contract DerivativeIntegration is BaseIntegration {
);
}

StoryUSD.mint(testSender, testMintFee * numCalls * 2);
StoryUSD.approve(address(spgNftContract), testMintFee * numCalls);
StoryUSD.approve(derivativeWorkflowsAddr, testMintFee * numCalls);
wrappedIP.deposit{ value: testMintFee * numCalls * 2 }();
wrappedIP.approve(address(spgNftContract), testMintFee * numCalls);
wrappedIP.approve(derivativeWorkflowsAddr, testMintFee * numCalls);

bytes[] memory results = derivativeWorkflows.multicall(data);

Expand Down Expand Up @@ -385,8 +385,8 @@ contract DerivativeIntegration is BaseIntegration {
})
);

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee);
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee);
address parentIpId;
(parentIpId, , parentLicenseTermIds) = licenseAttachmentWorkflows.mintAndRegisterIpAndAttachPILTerms({
spgNftContract: address(spgNftContract),
Expand Down
57 changes: 30 additions & 27 deletions test/integration/workflows/GroupingIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ contract GroupingIntegration is BaseIntegration {
signerSk: testSenderSk
});

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee);
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee);
(address ipId, uint256 tokenId) = groupingWorkflows.mintAndRegisterIpAndAttachLicenseAndAddToGroup({
spgNftContract: address(spgNftContract),
groupId: groupId,
Expand Down Expand Up @@ -99,8 +99,8 @@ contract GroupingIntegration is BaseIntegration {
private
logTest("test_GroupingIntegration_registerIpAndAttachLicenseAndAddToGroup")
{
StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee);
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee);
uint256 tokenId = spgNftContract.mint({
to: testSender,
nftMetadataURI: testIpMetadata.nftMetadataURI,
Expand Down Expand Up @@ -228,8 +228,8 @@ contract GroupingIntegration is BaseIntegration {
uint256[] memory licenseTermsIds = new uint256[](1);
licenseTermsIds[0] = testLicensesData[0].licenseTermsId;

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee);
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee);
(address ipId1, ) = derivativeWorkflows.mintAndRegisterIpAndMakeDerivative({
spgNftContract: address(spgNftContract),
derivData: WorkflowStructs.MakeDerivative({
Expand All @@ -246,8 +246,8 @@ contract GroupingIntegration is BaseIntegration {
allowDuplicates: true
});

StoryUSD.mint(testSender, testMintFee);
StoryUSD.approve(address(spgNftContract), testMintFee);
wrappedIP.deposit{ value: testMintFee }();
wrappedIP.approve(address(spgNftContract), testMintFee);
(address ipId2, ) = derivativeWorkflows.mintAndRegisterIpAndMakeDerivative({
spgNftContract: address(spgNftContract),
derivData: WorkflowStructs.MakeDerivative({
Expand All @@ -264,20 +264,20 @@ contract GroupingIntegration is BaseIntegration {
allowDuplicates: true
});

uint256 amount1 = 1_000 * 10 ** StoryUSD.decimals(); // 1,000 tokens
StoryUSD.mint(testSender, amount1);
StoryUSD.approve(address(royaltyModule), amount1);
royaltyModule.payRoyaltyOnBehalf(ipId1, testSender, address(StoryUSD), amount1);
IGraphAwareRoyaltyPolicy(royaltyPolicyLRPAddr).transferToVault(ipId1, newGroupId, address(StoryUSD));
uint256 amount1 = 1 * 10 ** wrappedIP.decimals(); // 1 token
wrappedIP.deposit{ value: amount1 }();
wrappedIP.approve(address(royaltyModule), amount1);
royaltyModule.payRoyaltyOnBehalf(ipId1, testSender, address(wrappedIP), amount1);
IGraphAwareRoyaltyPolicy(royaltyPolicyLRPAddr).transferToVault(ipId1, newGroupId, address(wrappedIP));

uint256 amount2 = 10_000 * 10 ** StoryUSD.decimals(); // 10,000 tokens
StoryUSD.mint(testSender, amount2);
StoryUSD.approve(address(royaltyModule), amount2);
royaltyModule.payRoyaltyOnBehalf(ipId2, testSender, address(StoryUSD), amount2);
IGraphAwareRoyaltyPolicy(royaltyPolicyLRPAddr).transferToVault(ipId2, newGroupId, address(StoryUSD));
uint256 amount2 = 2 * 10 ** wrappedIP.decimals(); // 2 tokens
wrappedIP.deposit{ value: amount2 }();
wrappedIP.approve(address(royaltyModule), amount2);
royaltyModule.payRoyaltyOnBehalf(ipId2, testSender, address(wrappedIP), amount2);
IGraphAwareRoyaltyPolicy(royaltyPolicyLRPAddr).transferToVault(ipId2, newGroupId, address(wrappedIP));

address[] memory royaltyTokens = new address[](1);
royaltyTokens[0] = address(StoryUSD);
royaltyTokens[0] = address(wrappedIP);

uint256[] memory collectedRoyalties = groupingWorkflows.collectRoyaltiesAndClaimReward(
newGroupId,
Expand All @@ -293,7 +293,10 @@ contract GroupingIntegration is BaseIntegration {

// check each member IP received the reward in their IP royalty vault
for (uint256 i = 0; i < ipIds.length; i++) {
assertEq(StoryUSD.balanceOf(royaltyModule.ipRoyaltyVaults(ipIds[i])), collectedRoyalties[0] / ipIds.length);
assertEq(
wrappedIP.balanceOf(royaltyModule.ipRoyaltyVaults(ipIds[i])),
collectedRoyalties[0] / ipIds.length
);
}
}

Expand Down Expand Up @@ -338,8 +341,8 @@ contract GroupingIntegration is BaseIntegration {
);
}

StoryUSD.mint(testSender, testMintFee * numCalls);
StoryUSD.approve(address(spgNftContract), testMintFee * numCalls);
wrappedIP.deposit{ value: testMintFee * numCalls }();
wrappedIP.approve(address(spgNftContract), testMintFee * numCalls);

// batch call `mintAndRegisterIpAndAttachLicenseAndAddToGroup`
bytes[] memory results = groupingWorkflows.multicall(data);
Expand Down Expand Up @@ -367,8 +370,8 @@ contract GroupingIntegration is BaseIntegration {
{
uint256 numCalls = 10;

StoryUSD.mint(testSender, testMintFee * numCalls);
StoryUSD.approve(address(spgNftContract), testMintFee * numCalls);
wrappedIP.deposit{ value: testMintFee * numCalls }();
wrappedIP.approve(address(spgNftContract), testMintFee * numCalls);
// mint a NFT from the spgNftContract
uint256[] memory tokenIds = new uint256[](numCalls);
for (uint256 i = 0; i < numCalls; i++) {
Expand Down Expand Up @@ -474,7 +477,7 @@ contract GroupingIntegration is BaseIntegration {
mintingFee: 0,
commercialRevShare: revShare,
royaltyPolicy: royaltyPolicyLRPAddr,
currencyToken: address(StoryUSD)
currencyToken: address(wrappedIP)
})
),
licensingConfig: Licensing.LicensingConfig({
Expand Down Expand Up @@ -549,8 +552,8 @@ contract GroupingIntegration is BaseIntegration {
);
}

StoryUSD.mint(testSender, testMintFee * numIps);
StoryUSD.approve(address(spgNftContract), testMintFee * numIps);
wrappedIP.deposit{ value: testMintFee * numIps }();
wrappedIP.approve(address(spgNftContract), testMintFee * numIps);

// batch call `mintAndRegisterIp`
bytes[] memory results = registrationWorkflows.multicall(data);
Expand Down
Loading
Loading