Skip to content

Commit

Permalink
feat: add poc contracts & subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
antho31 committed Nov 25, 2024
1 parent 4e7fc81 commit 5b37bbe
Show file tree
Hide file tree
Showing 29 changed files with 8,273 additions and 678 deletions.
544 changes: 544 additions & 0 deletions packages/hardhat/contracts/VisibilityCredits.sol

Large diffs are not rendered by default.

416 changes: 416 additions & 0 deletions packages/hardhat/contracts/VisibilityServices.sol

Large diffs are not rendered by default.

87 changes: 0 additions & 87 deletions packages/hardhat/contracts/YourContract.sol

This file was deleted.

118 changes: 118 additions & 0 deletions packages/hardhat/contracts/interfaces/IVisibilityCredits.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IVisibilityCredits {
struct CreditsTradeEvent {
address from;
string visibilityId;
uint256 amount;
bool isBuy;
uint256 tradeCost;
uint256 creatorFee;
uint256 protocolFee;
uint256 referrerFee;
address referrer;
uint256 newTotalSupply;
uint256 newCurrentPrice;
}

event CreatorFeeClaimed(address indexed creator, uint256 amount);

event CreatorVisibilitySet(string visibilityId, address creator);

event CreditsTrade(CreditsTradeEvent tradeEvent);

event CreditsTransfer(
string visibilityId,
address indexed from,
address indexed to,
uint256 amount
);

error InvalidAddress();
error InvalidCreator();
error InvalidAmount();
error InvalidFeeParams();
error NotEnoughEthSent();
error NotEnoughCreditsOwned();

function buyCredits(
string calldata visibilityId,
uint256 amount,
address referrer
) external payable;

function sellCredits(
string calldata visibilityId,
uint256 amount,
address referrer
) external;

function claimCreatorFee(string calldata visibilityId) external;

function setCreatorVisibility(
string calldata visibilityId,
address creator
) external;

function transferCredits(
string calldata visibilityId,
address from,
address to,
uint256 amount
) external;

function updateTreasury(address treasury) external;

function getVisibility(
string calldata visibilityId
)
external
view
returns (
address creator,
uint256 totalSupply,
uint256 claimableFeeBalance
);

function getVisibilityCreditBalance(
string calldata visibilityId,
address account
) external view returns (uint256);

function getVisibilityCurrentPrice(
string calldata visibilityId
) external view returns (uint256);

function getVisibilityKey(
string calldata visibilityId
) external pure returns (bytes32);

function buyCostWithFees(
string calldata visibilityId,
uint256 amount,
address referrer
)
external
returns (
uint256 totalCost,
uint256 tradeCost,
uint256 creatorFee,
uint256 protocolFee,
uint256 referrerFee
);

function sellCostWithFees(
string calldata visibilityId,
uint256 amount,
address referrer
)
external
returns (
uint256 reimbourcement,
uint256 tradeCost,
uint256 creatorFee,
uint256 protocolFee,
uint256 referrerFee
);
}
55 changes: 45 additions & 10 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DeployFunction } from "hardhat-deploy/types";
import { Contract } from "ethers";

/**
* Deploys a contract named "YourContract" using the deployer account and
* Deploys contracts using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const deployment: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
Expand All @@ -22,23 +22,58 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

await deploy("YourContract", {
const deployerBalance = await hre.ethers.provider.getBalance(deployer);
console.log(
"Ready to deploy to ",
hre.network.name,
"with deployer : ",
deployer,
"Balance: ",
deployerBalance.toString(),
);

await deploy("VisibilityCredits", {
from: deployer,
// Contract constructor arguments
args: [deployer],
args: [deployer, deployer],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const yourContract = await hre.ethers.getContract<Contract>("YourContract", deployer);
console.log("👋 Initial greeting:", await yourContract.greeting());
const visibilityCredits = await hre.ethers.getContract<Contract>("VisibilityCredits", deployer);

const visibilityCreditsAddress = await visibilityCredits.getAddress();

console.log("VisibilityCredits deployed to:", visibilityCreditsAddress);

await deploy("VisibilityServices", {
from: deployer,
args: [visibilityCreditsAddress, deployer],
log: true,
autoMine: true,
});

const visibilityServices = await hre.ethers.getContract<Contract>("VisibilityServices", deployer);

const visibilityServicesAddress = await visibilityServices.getAddress();
console.log("VisibilityServices deployed to:", visibilityServicesAddress);

/*
await hre.run("verify:verify", {
address: visibilityCreditsAddress,
constructorArguments: [deployer, deployer],
});
await hre.run("verify:verify", {
address: visibilityServicesAddress,
constructorArguments: [visibilityCreditsAddress, deployer],
});
*/
};

export default deployYourContract;
export default deployment;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
deployYourContract.tags = ["YourContract"];
// deployYourContract.tags = ["YourContract"];
Loading

0 comments on commit 5b37bbe

Please sign in to comment.