diff --git a/.github/workflows/run-full-regression-test.yml b/.github/workflows/run-full-regression-test.yml index 4db2b7c..f9a1513 100644 --- a/.github/workflows/run-full-regression-test.yml +++ b/.github/workflows/run-full-regression-test.yml @@ -50,7 +50,7 @@ jobs: echo SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS = ${{ vars.SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS }} >> .env echo SEPOLIA_DISPUTE_MODULE_ADDRESS = ${{ vars.SEPOLIA_DISPUTE_MODULE_ADDRESS }} >> .env echo SEPOLIA_IPASSET_REGISTRY_ADDRESS = ${{ vars.SEPOLIA_IPASSET_REGISTRY_ADDRESS }} >> .env - cat .env + echo SEPOLIA_LICENSE_TOKEN_ADDRESS = ${{ vars.SEPOLIA_LICENSE_TOKEN_ADDRESS }} >> .env - name: Run E2E Test in Sepolia run: | diff --git a/test/e2e/royalty.comRemixPIL.test.ts b/test/e2e/royalty.comRemixPIL.test.ts index c5902c3..43f8963 100644 --- a/test/e2e/royalty.comRemixPIL.test.ts +++ b/test/e2e/royalty.comRemixPIL.test.ts @@ -1,19 +1,14 @@ -import { privateKeyA, privateKeyB, privateKeyC, mintingFeeTokenAddress, accountC, clientC, accountB, chainId, clientA, accountA } from '../../config/config' -import { privateKeyA, privateKeyB, privateKeyC, mintingFeeTokenAddress, accountC, clientC, accountB, chainId, clientA, accountA } from '../../config/config' +import { privateKeyA, privateKeyB, privateKeyC, mintingFeeTokenAddress, accountC, accountB, accountA } from '../../config/config' import { getTotalRTSupply} from '../../utils/utils' -import { getRoyaltyVaultAddress, payRoyaltyOnBehalf, registerCommercialRemixPIL } from '../../utils/sdkUtils' +import { payRoyaltyOnBehalf, registerCommercialRemixPIL } from '../../utils/sdkUtils' import { mintNFTCreateRootIPandAttachPIL, mintNFTAndRegisterDerivative, checkRoyaltyTokensCollected, getSnapshotId,checkClaimableRevenue, claimRevenueByIPA, claimRevenueByEOA, transferTokenToEOA, transferTokenToEOAWithSig } from '../testUtils' import { expect } from 'chai' import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); -import { Address, Hex } from 'viem'; +import { Address } from 'viem'; import '../setup'; -import { AccessPermission, getPermissionSignature } from '@story-protocol/core-sdk' -import { coreMetadataModuleAbi } from '@story-protocol/core-sdk/dist/declarations/src/abi/generated' -import { AccessPermission, getPermissionSignature } from '@story-protocol/core-sdk' -import { coreMetadataModuleAbi } from '@story-protocol/core-sdk/dist/declarations/src/abi/generated' let ipIdA: Address; let ipIdB: Address; @@ -636,7 +631,207 @@ describe("SDK E2E Test - Royalty", function () { }); }); - describe.only("Commercial Remix PIL - Claim Minting Fee and Revenue by EOA2", function () { + describe("Commercial Remix PIL - Claim Minting Fee and Revenue by EOA2", function () { + const mintingFee = 600; + const payAmount = 2000; + const commercialRevShare = 10; + before("Register parent and derivative IP Assets", async function () { + // create license terms + const licenseTermsId = Number((await registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, true)).licenseTermsId); + + // root IP: ipIdA + ipIdA = await mintNFTCreateRootIPandAttachPIL("A", privateKeyA, licenseTermsId); + // ipIdB is ipIdA's derivative IP + ipIdB = await mintNFTAndRegisterDerivative("B", privateKeyB, [ipIdA], [licenseTermsId]); + // ipIdC is ipIdB's derivative IP + ipIdC = await mintNFTAndRegisterDerivative("C", privateKeyC, [ipIdB], [licenseTermsId]); + // ipIdD is ipIdC's derivative IP + ipIdD = await mintNFTAndRegisterDerivative("C", privateKeyC, [ipIdC], [licenseTermsId]); + }); + + step("Transfer token to EOA - ipIdC to ipIdA", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4) + await transferTokenToEOA("C", ipIdC, accountA.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("Transfer token to EOA - ipIdC to ipIdB", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4) + await transferTokenToEOA("C", ipIdC, accountB.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("Transfer token to EOA - ipIdC to ipIdC", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 2) + await transferTokenToEOA("C", ipIdC, accountC.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("ipIdD pay royalty on behalf to ipIdC", async function () { + const response = await expect( + payRoyaltyOnBehalf("C", ipIdC, ipIdD, mintingFeeTokenAddress, payAmount, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + }); + + step("ipIdA collect royalty tokens from ipIdB's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdB, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdA collect royalty tokens from ipIdC's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdC, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdA collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdB collect royalty tokens from ipIdC's vault account", async function () { + await checkRoyaltyTokensCollected("B", ipIdB, ipIdC, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdB collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("B", ipIdB, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdC collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("C", ipIdC, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("Capture snapshotId for ipIdC", async function () { + snapshotId1_ipIdC = await getSnapshotId("C", ipIdC); + }); + + step("Check claimable revenue A from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * commercialRevShare / 100); + await checkClaimableRevenue("A", ipIdC, ipIdA, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Check claimable revenue B from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * commercialRevShare / 100); + await checkClaimableRevenue("B", ipIdC, ipIdB, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Check claimable revenue C from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * (100 - 2 * commercialRevShare)/100 /4); + await checkClaimableRevenue("C", ipIdC, ipIdC, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Claim revenue by EOA A from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("A", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + + step("Claim revenue by EOA B from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("B", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + + step("Claim revenue by EOA C from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("C", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + }); + + describe("Commercial Remix PIL - Claim Minting Fee and Revenue by EOA1", function () { + const mintingFee = 600; + const payAmount = 2000; + const commercialRevShare = 10; + before("Register parent and derivative IP Assets", async function () { + // create license terms + const licenseTermsId = Number((await registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, true)).licenseTermsId); + + // root IP: ipIdA + ipIdA = await mintNFTCreateRootIPandAttachPIL("A", privateKeyA, licenseTermsId); + // ipIdB is ipIdA's derivative IP + ipIdB = await mintNFTAndRegisterDerivative("B", privateKeyB, [ipIdA], [licenseTermsId]); + // ipIdC is ipIdB's derivative IP + ipIdC = await mintNFTAndRegisterDerivative("C", privateKeyC, [ipIdB], [licenseTermsId]); + // ipIdD is ipIdC's derivative IP + ipIdD = await mintNFTAndRegisterDerivative("C", privateKeyC, [ipIdC], [licenseTermsId]); + }); + + step("ipIdA collect royalty tokens from ipIdB's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdB, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdA collect royalty tokens from ipIdC's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdC, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdA collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("A", ipIdA, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdB collect royalty tokens from ipIdC's vault account", async function () { + await checkRoyaltyTokensCollected("B", ipIdB, ipIdC, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdB collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("B", ipIdB, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("ipIdC collect royalty tokens from ipIdD's vault account", async function () { + await checkRoyaltyTokensCollected("C", ipIdC, ipIdD, BigInt(commercialRevShare/100 * TOTAL_RT_SUPPLY)); + }); + + step("Transfer token to EOA - ipIdC to ipIdA", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4) + await transferTokenToEOA("C", ipIdC, accountA.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("Transfer token to EOA - ipIdC to ipIdB", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4) + await transferTokenToEOA("C", ipIdC, accountB.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("Transfer token to EOA - ipIdC to ipIdC", async function () { + console.log((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 2) + await transferTokenToEOA("C", ipIdC, accountC.address, BigInt((100 - 2 * commercialRevShare)/100 * TOTAL_RT_SUPPLY / 4)); + }); + + step("ipIdD pay royalty on behalf to ipIdC", async function () { + const response = await expect( + payRoyaltyOnBehalf("C", ipIdC, ipIdD, mintingFeeTokenAddress, payAmount, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + }); + + step("Capture snapshotId for ipIdC", async function () { + snapshotId1_ipIdC = await getSnapshotId("C", ipIdC); + }); + + step("Check claimable revenue A from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * commercialRevShare / 100); + await checkClaimableRevenue("A", ipIdC, ipIdA, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Check claimable revenue B from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * commercialRevShare / 100); + await checkClaimableRevenue("B", ipIdC, ipIdB, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Check claimable revenue C from C", async function () { + const expectedClaimableRevenue = BigInt((mintingFee + payAmount) * (100 - 2 * commercialRevShare)/100 /4); + await checkClaimableRevenue("C", ipIdC, ipIdC, snapshotId1_ipIdC, expectedClaimableRevenue); + }); + + step("Claim revenue by EOA A from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("A", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + + step("Claim revenue by EOA B from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("B", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + + step("Claim revenue by EOA C from C", async function () { + const expectedClaimableToken = BigInt((mintingFee + payAmount) * ((100 - 2 * commercialRevShare) / 100) / 4); + await claimRevenueByEOA("C", [snapshotId1_ipIdC], ipIdC, expectedClaimableToken); + }); + }); + + describe("Commercial Remix PIL - Claim Minting Fee and Revenue by EOA2", function () { const mintingFee = 600; const payAmount = 2000; const commercialRevShare = 10;