-
Notifications
You must be signed in to change notification settings - Fork 3
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
chore: deployment scripts #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,11 @@ interface IERC1155 { | |
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata) external; | ||
} | ||
|
||
/// @dev Only `owner` has a privilege, but the `sender` was provided. | ||
/// @param sender Sender address. | ||
/// @param owner Required sender address as an owner. | ||
error OwnerOnly(address sender, address owner); | ||
|
||
/// @dev Value overflow. | ||
/// @param provided Overflow value. | ||
/// @param max Maximum possible value. | ||
|
@@ -34,35 +39,29 @@ error Overflow(uint256 provided, uint256 max); | |
error NoDepositAllowed(uint256 amount); | ||
|
||
contract BalanceTrackerNvmSubscription is BalanceTrackerBase { | ||
event SubscriptionSet(address indexed token, uint256 indexed tokenId); | ||
event WithdrawSubscription(address indexed account, address indexed token, uint256 indexed tokenId, uint256 amount); | ||
event RequesterCreditsRedeemed(address indexed account, uint256 amount); | ||
|
||
// TODO: setup, taken from subscription? | ||
uint256 public constant NVM_FEE = 100; | ||
|
||
// Subscription NFT | ||
address public immutable subscriptionNFT; | ||
address public subscriptionNFT; | ||
// Subscription token Id | ||
uint256 public immutable subscriptionTokenId; | ||
uint256 public subscriptionTokenId; | ||
|
||
// Temporary owner address | ||
address public owner; | ||
|
||
// TODO Do we manage subscription fee via buyBackBurner as well or in-place? | ||
/// @dev BalanceTrackerSubscription constructor. | ||
/// @param _mechMarketplace Mech marketplace address. | ||
/// @param _buyBackBurner Buy back burner address. | ||
/// @param _subscriptionNFT Subscription NFT address. | ||
/// @param _subscriptionTokenId Subscription token Id. | ||
constructor(address _mechMarketplace, address _buyBackBurner, address _subscriptionNFT, uint256 _subscriptionTokenId) | ||
constructor(address _mechMarketplace, address _buyBackBurner) | ||
BalanceTrackerBase(_mechMarketplace, _buyBackBurner) | ||
{ | ||
if (_subscriptionNFT == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
if (_subscriptionTokenId == 0) { | ||
revert ZeroValue(); | ||
} | ||
|
||
subscriptionNFT = _subscriptionNFT; | ||
subscriptionTokenId = _subscriptionTokenId; | ||
Comment on lines
-56
to
-65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subscription is set separately as it needs to be tied to this contract address |
||
owner = msg.sender; | ||
} | ||
|
||
/// @dev Adjusts initial requester balance accounting for max request delivery rate (credit). | ||
|
@@ -130,6 +129,26 @@ contract BalanceTrackerNvmSubscription is BalanceTrackerBase { | |
return 0; | ||
} | ||
|
||
/// @dev Process mech payment. | ||
/// @param mech Mech address. | ||
/// @return mechPayment Mech payment. | ||
function _processPayment(address mech) internal virtual override returns (uint256 mechPayment, uint256) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as the understanding goes, all the fees are already accounted for when the subscription is paid for and mech gets its cleared cut. |
||
// Get mech balance | ||
mechPayment = mapMechBalances[mech]; | ||
// Check for zero value | ||
if (mechPayment == 0) { | ||
revert ZeroValue(); | ||
} | ||
|
||
// Clear balances | ||
mapMechBalances[mech] = 0; | ||
|
||
// Process withdraw | ||
_withdraw(mech, mechPayment); | ||
|
||
return (mechPayment, 0); | ||
} | ||
|
||
/// @dev Withdraws funds. | ||
/// @param account Account address. | ||
/// @param amount Token amount. | ||
|
@@ -140,6 +159,31 @@ contract BalanceTrackerNvmSubscription is BalanceTrackerBase { | |
emit WithdrawSubscription(msg.sender, subscriptionNFT, subscriptionTokenId, amount); | ||
} | ||
|
||
/// @dev Sets subscription. | ||
/// @param _subscriptionNFT Subscription NFT address. | ||
/// @param _subscriptionTokenId Subscription token Id. | ||
function setSubscription(address _subscriptionNFT, uint256 _subscriptionTokenId) external { | ||
// Check for ownership | ||
if (msg.sender != owner) { | ||
revert OwnerOnly(msg.sender, owner); | ||
} | ||
|
||
if (_subscriptionNFT == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
||
if (_subscriptionTokenId == 0) { | ||
revert ZeroValue(); | ||
} | ||
|
||
subscriptionNFT = _subscriptionNFT; | ||
subscriptionTokenId = _subscriptionTokenId; | ||
|
||
owner = address(0); | ||
|
||
emit SubscriptionSet(_subscriptionNFT, _subscriptionTokenId); | ||
} | ||
|
||
/// @dev Redeem requester credits. | ||
/// @param requester Requester address. | ||
function redeemRequesterCredits(address requester) external { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*global process*/ | ||
|
||
const { ethers } = require("hardhat"); | ||
const { LedgerSigner } = require("@anders-t/ethers-ledger"); | ||
|
||
async function main() { | ||
const fs = require("fs"); | ||
const globalsFile = "globals.json"; | ||
const dataFromJSON = fs.readFileSync(globalsFile, "utf8"); | ||
let parsedData = JSON.parse(dataFromJSON); | ||
const useLedger = parsedData.useLedger; | ||
const derivationPath = parsedData.derivationPath; | ||
const providerName = parsedData.providerName; | ||
const gasPriceInGwei = parsedData.gasPriceInGwei; | ||
const mechMarketplaceAddress = parsedData.mechMarketplaceAddress; | ||
const fee = parsedData.fee; | ||
const minResponseTimeout = parsedData.minResponseTimeout; | ||
const maxResponseTimeout = parsedData.maxResponseTimeout; | ||
|
||
let networkURL = parsedData.networkURL; | ||
if (providerName === "polygon") { | ||
if (!process.env.ALCHEMY_API_KEY_MATIC) { | ||
console.log("set ALCHEMY_API_KEY_MATIC env variable"); | ||
} | ||
networkURL += process.env.ALCHEMY_API_KEY_MATIC; | ||
} else if (providerName === "polygonMumbai") { | ||
if (!process.env.ALCHEMY_API_KEY_MUMBAI) { | ||
console.log("set ALCHEMY_API_KEY_MUMBAI env variable"); | ||
return; | ||
} | ||
networkURL += process.env.ALCHEMY_API_KEY_MUMBAI; | ||
} | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(networkURL); | ||
const signers = await ethers.getSigners(); | ||
|
||
let EOA; | ||
if (useLedger) { | ||
EOA = new LedgerSigner(provider, derivationPath); | ||
} else { | ||
EOA = signers[0]; | ||
} | ||
// EOA address | ||
const deployer = await EOA.getAddress(); | ||
console.log("EOA is:", deployer); | ||
|
||
// Assemble the mech marketplace proxy data | ||
const mechMarketplace = await ethers.getContractAt("MechMarketplace", mechMarketplaceAddress); | ||
const proxyPayload = mechMarketplace.interface.encodeFunctionData("initialize", [fee, minResponseTimeout, maxResponseTimeout]); | ||
|
||
// Transaction signing and execution | ||
console.log("4. EOA to deploy Mech Marketplace Proxy"); | ||
console.log("You are signing the following transaction: MechMarketplaceProxy.connect(EOA).deploy()"); | ||
const gasPrice = ethers.utils.parseUnits(gasPriceInGwei, "gwei"); | ||
const MechMarketplaceProxy = await ethers.getContractFactory("MechMarketplaceProxy"); | ||
const mechMarketplaceProxy = await MechMarketplaceProxy.connect(EOA).deploy(mechMarketplaceAddress, proxyPayload, | ||
{ gasPrice }); | ||
// In case when gas calculation is not working correctly on Arbitrum | ||
//const gasLimit = 60000000; | ||
const result = await mechMarketplaceProxy.deployed(); | ||
|
||
// Transaction details | ||
console.log("Contract deployment: MechMarketplaceProxy"); | ||
console.log("Contract address:", mechMarketplaceProxy.address); | ||
console.log("Transaction:", result.deployTransaction.hash); | ||
|
||
// Wait for half a minute for the transaction completion | ||
await new Promise(r => setTimeout(r, 30000)); | ||
|
||
// Writing updated parameters back to the JSON file | ||
parsedData.mechMarketplaceProxyAddress = mechMarketplaceProxy.address; | ||
fs.writeFileSync(globalsFile, JSON.stringify(parsedData)); | ||
|
||
// Contract verification | ||
if (parsedData.contractVerification) { | ||
const execSync = require("child_process").execSync; | ||
execSync("npx hardhat verify --constructor-args scripts/deployment/verify_04_mech_marketplace_proxy.js --network " + providerName + " " + mechMarketplaceProxy.address, { encoding: "utf-8" }); | ||
} | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary ownership is dropped when the subscription is set