@@ -111,6 +111,10 @@ contract BlueprintCore is Initializable, EIP712, Payment {
111111 // deployment request id to project id mapping
112112 mapping (bytes32 => bytes32 ) public requestIDToProjectID;
113113
114+ // agent copy fee mapping
115+ uint256 public platformCopyAgentFee;
116+ mapping (bytes32 => mapping (address => uint256 )) public copyAgentFeeMp;
117+
114118 event CreateProjectID (bytes32 indexed projectID , address walletAddress );
115119 event RequestProposal (
116120 bytes32 indexed projectID ,
@@ -149,7 +153,7 @@ contract BlueprintCore is Initializable, EIP712, Payment {
149153 bytes32 indexed projectID , bytes32 indexed requestID , string base64DeploymentProof
150154 );
151155
152- event UpdateDeploymentConfigs (
156+ event DeploymentConfigUpdate (
153157 bytes32 indexed projectID ,
154158 bytes32 indexed requestID ,
155159 address workerAddress ,
@@ -173,6 +177,10 @@ contract BlueprintCore is Initializable, EIP712, Payment {
173177 uint256 amount
174178 );
175179
180+ event SetCopyAgentFee (bytes32 indexed agentRequestID , address userAddress , address tokenAddress , uint256 fee );
181+
182+ event CopyAgentRequest (bytes32 indexed copyID , bytes32 indexed originalAgentRequestID , address userAddress );
183+
176184 modifier newProject (bytes32 projectId ) {
177185 // check project id
178186 // slither-disable-next-line incorrect-equality,timestamp
@@ -207,6 +215,8 @@ contract BlueprintCore is Initializable, EIP712, Payment {
207215 function __BlueprintCore_init (string memory name , string memory version ) internal onlyInitializing {
208216 __EIP712_custom_init (name, version);
209217 // (if you ever add state, initialize it here)
218+ // default factor
219+ factor = 1000 ; // 100% factor
210220 }
211221 // slither-disable-end naming-convention
212222
@@ -436,35 +446,6 @@ contract BlueprintCore is Initializable, EIP712, Payment {
436446 requestID = createAgent (signerAddr, projectId, base64Proposal, privateWorkerAddress, serverURL, 0 , tokenAddress);
437447 }
438448
439- function createAgentWithNFT (
440- bytes32 projectId ,
441- string memory base64Proposal ,
442- address privateWorkerAddress ,
443- string memory serverURL ,
444- uint256 tokenId
445- ) public returns (bytes32 requestID ) {
446- requestID =
447- createAgent (msg .sender , projectId, base64Proposal, privateWorkerAddress, serverURL, tokenId, address (0 ));
448- }
449-
450- function createAgentWithSigWithNFT (
451- bytes32 projectId ,
452- string memory base64Proposal ,
453- address privateWorkerAddress ,
454- string memory serverURL ,
455- bytes memory signature ,
456- uint256 tokenId
457- ) public returns (bytes32 requestID ) {
458- // get EIP712 hash digest
459- bytes32 digest =
460- getCreateAgentWithNFTDigest (projectId, base64Proposal, serverURL, privateWorkerAddress, tokenId);
461-
462- // get signer address
463- address signerAddr = getSignerAddress (digest, signature);
464-
465- requestID =
466- createAgent (signerAddr, projectId, base64Proposal, privateWorkerAddress, serverURL, tokenId, address (0 ));
467- }
468449
469450 function resetDeployment (
470451 address userAddress ,
@@ -654,7 +635,7 @@ contract BlueprintCore is Initializable, EIP712, Payment {
654635 bytes32 updateHash =
655636 keccak256 (abi.encodePacked (block .timestamp , userAddress, requestID, updatedBase64Config, block .chainid ));
656637
657- emit UpdateDeploymentConfigs (
638+ emit DeploymentConfigUpdate (
658639 projectId, requestID, requestDeploymentStatus[requestID].deployWorkerAddr, updateHash, updatedBase64Config
659640 );
660641 }
@@ -693,6 +674,60 @@ contract BlueprintCore is Initializable, EIP712, Payment {
693674 userNonceMp[owner]++ ;
694675 }
695676
677+ // set copy agent fee, this can be called by owner only
678+ function setCopyAgentFee (
679+ bytes32 agentRequestID ,
680+ address tokenAddress ,
681+ uint256 fee
682+ ) public payable {
683+ require (fee > 0 , "Fee must be greater than 0 " );
684+ require (paymentAddressEnableMp[tokenAddress], "Invalid token address " );
685+ // check if it owner of requestID
686+ require (deploymentOwners[agentRequestID] == msg .sender , "Only deployment owner can update config " );
687+
688+ // set copy agent fee
689+ copyAgentFeeMp[agentRequestID][tokenAddress] = fee;
690+
691+ emit SetCopyAgentFee (agentRequestID, msg .sender , tokenAddress, fee);
692+ }
693+
694+ // create copy agent request, copyID and originalAgentRequestID is needed, they are different
695+ function createCopyAgentRequest (bytes32 copyID , bytes32 originalAgentRequestID , address tokenAddress )
696+ public
697+ payable
698+ {
699+ // validate original agent request id from deploymentOwners map
700+ require (deploymentOwners[originalAgentRequestID] != address (0 ), "Invalid original agent request ID " );
701+ // pay copy agent fee and then emit an event
702+ // fee * platformCopyAgentFee / factor goes to fee collection wallet address, while remain fee goes to original agent owner
703+ uint256 fee = copyAgentFeeMp[originalAgentRequestID][tokenAddress];
704+ require (fee > 0 , "Copy agent fee must be greater than 0 " );
705+ // only ERC20 nation token is supported
706+ require (paymentAddressEnableMp[tokenAddress], "Invalid token address " );
707+
708+ // pay with token
709+ uint256 collectionWalletFee = fee * platformCopyAgentFee / factor;
710+ uint256 creatorFee = fee - platformCopyAgentFee;
711+
712+ // platform fee
713+ payWithERC20 (
714+ tokenAddress,
715+ collectionWalletFee,
716+ msg .sender ,
717+ feeCollectionWalletAddress
718+ );
719+
720+ // creator fee
721+ payWithERC20 (
722+ tokenAddress,
723+ creatorFee,
724+ msg .sender ,
725+ deploymentOwners[originalAgentRequestID]
726+ );
727+
728+ emit CopyAgentRequest (copyID, originalAgentRequestID, msg .sender );
729+ }
730+
696731 // set worker public key
697732 function setWorkerPublicKey (bytes calldata publicKey ) public isTrustedWorker {
698733 require (publicKey.length > 0 , "Public key cannot be empty " );
0 commit comments