Skip to content

Commit eac760d

Browse files
committed
add copy agent
1 parent d96ecd9 commit eac760d

File tree

3 files changed

+99
-31
lines changed

3 files changed

+99
-31
lines changed

src/Blueprint.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ contract Blueprint is Initializable, OwnableUpgradeable, BlueprintCore {
1414
event SetWorkerAdmin(address workerAdmin);
1515
event UpdateWorker(address workerAddress, bool isTrusted);
1616
event CreditReward(address indexed userAddress, uint256 amount);
17+
event SetGlobalPlatformFee(uint256 fee, uint256 factor);
1718

1819
modifier isAdmin() {
1920
// slither-disable-next-line timestamp
@@ -126,4 +127,12 @@ contract Blueprint is Initializable, OwnableUpgradeable, BlueprintCore {
126127

127128
emit CreditReward(userAddress, amount);
128129
}
130+
// 6 %。= 6 / 100 means fee =6 and baseFactor = 100
131+
function setGlobalPlatformFee(uint256 fee,uint256 baseFactor) public isAdmin {
132+
// base factor should be greater or equal than 10
133+
require(baseFactor >= 10, "Base factor should be greater than or equal to 10");
134+
require(fee <= baseFactor, "Fee cannot be greater than factor");
135+
platformCopyAgentFee = fee;
136+
emit SetGlobalPlatformFee(fee, baseFactor);
137+
}
129138
}

src/BlueprintCore.sol

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

src/BlueprintV7.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.26;
3+
4+
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5+
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
6+
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
7+
import "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
8+
import "./Blueprint.sol";
9+
10+
contract BlueprintV6 is Initializable, UUPSUpgradeable, OwnableUpgradeable, Blueprint {
11+
string public constant SIGNING_DOMAIN = "nation.fun";
12+
13+
/// @custom:oz-upgrades-validate-as-initializer
14+
function initialize() public reinitializer(7) {
15+
VERSION = "7.0.0";
16+
// __Ownable_init(msg.sender); is called inside this now for chain init
17+
__Blueprint_init(SIGNING_DOMAIN, VERSION);
18+
__UUPSUpgradeable_init();
19+
}
20+
21+
// The _authorizeUpgrade function is required by the UUPSUpgradeable contract
22+
23+
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
24+
}

0 commit comments

Comments
 (0)